diff options
author | Eric Polino <aluink@pidgin.im> | 2007-07-11 21:10:09 +0000 |
---|---|---|
committer | Eric Polino <aluink@pidgin.im> | 2007-07-11 21:10:09 +0000 |
commit | f325d666d886af7b593156b9ed1c0e4902006ff8 (patch) | |
tree | 66b7498dcf2bcaef4e06661883459a901eedae92 | |
parent | c51650479f462c0d983fabb5bcf939f25cd58eea (diff) | |
parent | 944c43dc33d6157de56c5ec921d406ac70990cea (diff) | |
download | pidgin-f325d666d886af7b593156b9ed1c0e4902006ff8.tar.gz |
merge of '399da3ec358f36fbb08d9c507f0f63706792da06'
and '85033822cf93567e492a434659b4d07964d9e9c7'
-rw-r--r-- | finch/gntsound.c | 124 | ||||
-rw-r--r-- | finch/gntsound.h | 40 | ||||
-rw-r--r-- | libpurple/prefs.c | 33 | ||||
-rw-r--r-- | libpurple/prefs.h | 5 |
4 files changed, 88 insertions, 114 deletions
diff --git a/finch/gntsound.c b/finch/gntsound.c index 85a38cc28a..9ccbe86119 100644 --- a/finch/gntsound.c +++ b/finch/gntsound.c @@ -74,13 +74,12 @@ typedef struct { GntWidget *profiles; } SoundPrefDialog; -SoundPrefDialog *pref_dialog; +static SoundPrefDialog *pref_dialog; #define PLAY_SOUND_TIMEOUT 15000 static guint mute_login_sounds_timeout = 0; static gboolean mute_login_sounds = FALSE; -static gchar * pref_string = NULL; #ifdef USE_GSTREAMER static gboolean gst_init_failed; @@ -113,8 +112,9 @@ finch_sound_get_active_profile() static gchar * make_pref(const char *name) { - g_free(pref_string); - pref_string = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s%s",finch_sound_get_active_profile(),name); + static char pref_string[512]; + g_snprintf(pref_string, sizeof(pref_string), + FINCH_PREFS_ROOT "/sound/profiles/%s%s", finch_sound_get_active_profile(), name); return pref_string; } @@ -191,10 +191,9 @@ im_msg_received_cb(PurpleAccount *account, char *sender, if (flags & PURPLE_MESSAGE_DELAYED) return; - if (conv==NULL){ + if (conv==NULL) { purple_sound_play_event(PURPLE_SOUND_FIRST_RECEIVE, account); - } - else{ + } else { play_conv_event(conv, event); } } @@ -274,10 +273,10 @@ account_signon_cb(PurpleConnection *gc, gpointer data) if (mute_login_sounds_timeout != 0) g_source_remove(mute_login_sounds_timeout); mute_login_sounds = TRUE; - mute_login_sounds_timeout = purple_timeout_add(10000, unmute_login_sounds_cb, NULL); + mute_login_sounds_timeout = purple_timeout_add_seconds(10, unmute_login_sounds_cb, NULL); } -void * +static void * finch_sound_get_handle() { static int handle; @@ -290,38 +289,39 @@ finch_sound_get_handle() static void load_profile(const char *name, PurplePrefType type, gconstpointer val, gpointer null) { - if(!purple_prefs_exists(make_pref(""))){ - purple_prefs_add_none(make_pref("")); - purple_prefs_add_none(make_pref("/enabled")); - purple_prefs_add_none(make_pref("/file")); - purple_prefs_add_bool(make_pref("/enabled/login"), TRUE); - purple_prefs_add_path(make_pref("/file/login"), ""); - purple_prefs_add_bool(make_pref("/enabled/logout"), TRUE); - purple_prefs_add_path(make_pref("/file/logout"), ""); - purple_prefs_add_bool(make_pref("/enabled/im_recv"), TRUE); - purple_prefs_add_path(make_pref("/file/im_recv"), ""); - purple_prefs_add_bool(make_pref("/enabled/first_im_recv"), FALSE); - purple_prefs_add_path(make_pref("/file/first_im_recv"), ""); - purple_prefs_add_bool(make_pref("/enabled/send_im"), TRUE); - purple_prefs_add_path(make_pref("/file/send_im"), ""); - purple_prefs_add_bool(make_pref("/enabled/join_chat"), FALSE); - purple_prefs_add_path(make_pref("/file/join_chat"), ""); - purple_prefs_add_bool(make_pref("/enabled/left_chat"), FALSE); - purple_prefs_add_path(make_pref("/file/left_chat"), ""); - purple_prefs_add_bool(make_pref("/enabled/send_chat_msg"), FALSE); - purple_prefs_add_path(make_pref("/file/send_chat_msg"), ""); - purple_prefs_add_bool(make_pref("/enabled/chat_msg_recv"), FALSE); - purple_prefs_add_path(make_pref("/file/chat_msg_recv"), ""); - purple_prefs_add_bool(make_pref("/enabled/nick_said"), FALSE); - purple_prefs_add_path(make_pref("/file/nick_said"), ""); - purple_prefs_add_bool(make_pref("/enabled/pounce_default"), TRUE); - purple_prefs_add_path(make_pref("/file/pounce_default"), ""); - purple_prefs_add_bool(make_pref("/conv_focus"), TRUE); - purple_prefs_add_bool(make_pref("/mute"), FALSE); - purple_prefs_add_path(make_pref("/command"), ""); - purple_prefs_add_string(make_pref("/method"), "automatic"); - purple_prefs_add_int(make_pref("/volume"), 50); - } + if(purple_prefs_exists(make_pref(""))) + return; + + purple_prefs_add_none(make_pref("")); + purple_prefs_add_none(make_pref("/enabled")); + purple_prefs_add_none(make_pref("/file")); + purple_prefs_add_bool(make_pref("/enabled/login"), TRUE); + purple_prefs_add_path(make_pref("/file/login"), ""); + purple_prefs_add_bool(make_pref("/enabled/logout"), TRUE); + purple_prefs_add_path(make_pref("/file/logout"), ""); + purple_prefs_add_bool(make_pref("/enabled/im_recv"), TRUE); + purple_prefs_add_path(make_pref("/file/im_recv"), ""); + purple_prefs_add_bool(make_pref("/enabled/first_im_recv"), FALSE); + purple_prefs_add_path(make_pref("/file/first_im_recv"), ""); + purple_prefs_add_bool(make_pref("/enabled/send_im"), TRUE); + purple_prefs_add_path(make_pref("/file/send_im"), ""); + purple_prefs_add_bool(make_pref("/enabled/join_chat"), FALSE); + purple_prefs_add_path(make_pref("/file/join_chat"), ""); + purple_prefs_add_bool(make_pref("/enabled/left_chat"), FALSE); + purple_prefs_add_path(make_pref("/file/left_chat"), ""); + purple_prefs_add_bool(make_pref("/enabled/send_chat_msg"), FALSE); + purple_prefs_add_path(make_pref("/file/send_chat_msg"), ""); + purple_prefs_add_bool(make_pref("/enabled/chat_msg_recv"), FALSE); + purple_prefs_add_path(make_pref("/file/chat_msg_recv"), ""); + purple_prefs_add_bool(make_pref("/enabled/nick_said"), FALSE); + purple_prefs_add_path(make_pref("/file/nick_said"), ""); + purple_prefs_add_bool(make_pref("/enabled/pounce_default"), TRUE); + purple_prefs_add_path(make_pref("/file/pounce_default"), ""); + purple_prefs_add_bool(make_pref("/conv_focus"), TRUE); + purple_prefs_add_bool(make_pref("/mute"), FALSE); + purple_prefs_add_path(make_pref("/command"), ""); + purple_prefs_add_string(make_pref("/method"), "automatic"); + purple_prefs_add_int(make_pref("/volume"), 50); } static void @@ -597,24 +597,29 @@ finch_sound_play_event(PurpleSoundEventID event) GList * finch_sound_get_profiles() { - return purple_prefs_get_children_names(FINCH_PREFS_ROOT "/sound/profiles"); + GList *list = NULL, *iter; + iter = purple_prefs_get_children_names(FINCH_PREFS_ROOT "/sound/profiles"); + while (iter) { + list = g_list_append(list, g_strdup(strrchr(iter->data, '/') + 1)); + g_free(iter->data); + iter = g_list_delete_link(iter, iter); + } + return list; } static gboolean profile_exists(const char *name) { - GList *itr = NULL; - for(itr = finch_sound_get_profiles();itr;itr = itr->next){ - if(!strcmp(itr->data,name)) - return TRUE; - } - return FALSE; + char *str = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s", name); + gboolean ret = purple_prefs_exists(str); + g_free(str); + return ret; } void finch_sound_set_active_profile(const char *name) { - if(profile_exists(name)){ + if(profile_exists(name)) { purple_prefs_set_string(FINCH_PREFS_ROOT "/sound/actprofile",name); } } @@ -703,7 +708,7 @@ pref_load_cb(GntWidget *button, gpointer null) static void pref_save_cb(GntWidget *button, gpointer null) { - + /* XXX: */ } static void @@ -764,26 +769,25 @@ reload_pref_window(GntComboBox *box, gpointer oldkey, gpointer newkey, gpointer gchar *filepref; const char * profile = finch_sound_get_active_profile(); - boolpref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s",profile,event->pref); - filepref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s",profile,event->pref); event->file = g_strdup(purple_prefs_get_path(filepref)); - if(event->label == NULL){ + g_free(filepref); + if (event->label == NULL) { continue; } + boolpref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s",profile,event->pref); gnt_tree_change_text(GNT_TREE(pref_dialog->events),GINT_TO_POINTER(i),0,event->label); gnt_tree_change_text(GNT_TREE(pref_dialog->events),GINT_TO_POINTER(i),1,event->file[0] ? g_path_get_basename(event->file) : "(default)"); gnt_tree_set_choice(GNT_TREE(pref_dialog->events),GINT_TO_POINTER(i),purple_prefs_get_bool(boolpref)); g_free(boolpref); - g_free(filepref); } } void finch_sounds_show_all(void) { - GntWidget *box; GntWidget *cmbox; GntWidget *slider; + GntWidget *box, *cmbox, *slider; GntWidget *entry; GntWidget *chkbox; GntWidget *button; @@ -794,7 +798,7 @@ finch_sounds_show_all(void) GList *itr,*list; gint i; - if(pref_dialog){ + if(pref_dialog) { gnt_window_present(pref_dialog->window); return; } @@ -817,6 +821,7 @@ finch_sounds_show_all(void) gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"custom",_("Command")); gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"nosound",_("No Sound")); + /* Sound method */ label = gnt_label_new_with_format(_("Sound Method"),GNT_TEXT_FLAG_BOLD); gnt_box_add_widget(GNT_BOX(win),label); box = gnt_hbox_new(TRUE); @@ -836,6 +841,7 @@ finch_sounds_show_all(void) gnt_box_add_widget(GNT_BOX(win), gnt_line_new(FALSE)); + /* Sound options */ gnt_box_add_widget(GNT_BOX(win),gnt_label_new_with_format(_("Sound Options"),GNT_TEXT_FLAG_BOLD)); pref_dialog->conv_focus = chkbox = gnt_check_box_new(_("Sounds when conversation has focus")); gnt_box_add_widget(GNT_BOX(win),chkbox); @@ -865,8 +871,9 @@ finch_sounds_show_all(void) gnt_box_add_widget(GNT_BOX(box),label); gnt_box_add_widget(GNT_BOX(win),box); - gnt_box_add_widget(GNT_BOX(win), gnt_line_new(FALSE)); + gnt_box_add_widget(GNT_BOX(win), gnt_hline_new()); + /* Sound events */ gnt_box_add_widget(GNT_BOX(win),gnt_label_new_with_format(_("Sound Events"),GNT_TEXT_FLAG_BOLD)); pref_dialog->events = tree = gnt_tree_new_with_columns(2); gnt_tree_set_column_titles(GNT_TREE(tree),_("Event"),_("File")); @@ -901,10 +908,12 @@ finch_sounds_show_all(void) gnt_box_add_widget(GNT_BOX(win), gnt_line_new(FALSE)); + /* Sound profiles */ gnt_box_add_widget(GNT_BOX(win),gnt_label_new_with_format(_("Profiles"),GNT_TEXT_FLAG_BOLD)); box = gnt_hbox_new(FALSE); pref_dialog->profiles = cmbox = gnt_combo_box_new(); list = itr = finch_sound_get_profiles(); + gnt_tree_set_hash_fns(GNT_TREE(GNT_COMBO_BOX(cmbox)->dropdown), g_str_hash, g_str_equal, g_free); for(;itr;itr = itr->next){ gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),itr->data,itr->data); } @@ -957,3 +966,4 @@ finch_sound_get_ui_ops(void) { return &sound_ui_ops; } + diff --git a/finch/gntsound.h b/finch/gntsound.h index 93f6e5620f..688d2ad47b 100644 --- a/finch/gntsound.h +++ b/finch/gntsound.h @@ -28,52 +28,37 @@ #include "sound.h" /**********************************************************************/ -/** @name GNT Sound API */ +/** @name GNT Sound API */ /**********************************************************************/ /*@{*/ /** -* Get the prefs option for an event. -* -* @param event The event. -* @return The option. -*/ -const char *finch_sound_get_event_option(PurpleSoundEventID event); - -/** -* Get the label for an event. -* -* @param event The event. -* @return The label. -*/ -const char *finch_sound_get_event_label(PurpleSoundEventID event); - -/* * Get the name of the active sound profile. * - * @return the name + * @return The name of the profile */ const char *finch_sound_get_active_profile(void); /** * Set the active profile. If the profile doesn't exist, nothing is changed. * - * + * @param name The name of the profile */ void finch_sound_set_active_profile(const char *name); /** * Get a list of available sound profiles. * - * @return A list of strings denoting sound profile names. Free this list when you're done with it. + * @return A list of strings denoting sound profile names. + * Caller must free the list (but not the data). */ GList *finch_sound_get_profiles(void); /** -* Gets GNT sound UI ops. -* -* @return The UI operations structure. -*/ + * Gets GNT sound UI ops. + * + * @return The UI operations structure. + */ PurpleSoundUiOps *finch_sound_get_ui_ops(void); /** @@ -81,13 +66,6 @@ PurpleSoundUiOps *finch_sound_get_ui_ops(void); */ void finch_sounds_show_all(void); -/** -* Get the handle for the GNT sound system. -* -* @return The handle to the sound system -*/ -void *finch_sound_get_handle(void); - /*@}*/ #endif diff --git a/libpurple/prefs.c b/libpurple/prefs.c index c9515ef09e..212adf32da 100644 --- a/libpurple/prefs.c +++ b/libpurple/prefs.c @@ -35,7 +35,6 @@ #include "prefs.h" #include "debug.h" #include "util.h" -#include "xmlnode.h" #ifdef _WIN32 #include "win32dep.h" @@ -127,7 +126,6 @@ pref_to_xmlnode(xmlnode *parent, struct purple_pref *pref) xmlnode_set_attrib(node, "name", pref->name); /* Set the type of this node (if type == PURPLE_PREF_NONE then do nothing) */ - /* XXX: Why aren't we using a switch here? */ if (pref->type == PURPLE_PREF_INT) { xmlnode_set_attrib(node, "type", "int"); snprintf(buf, sizeof(buf), "%d", pref->value.integer); @@ -1327,35 +1325,22 @@ purple_prefs_disconnect_by_handle(void *handle) disco_callback_helper_handle(&prefs, handle); } -static xmlnode* -single_pref_to_xmlnode(const struct purple_pref *pref) -{ - xmlnode *node; - struct purple_pref *child; - - node = xmlnode_new("pref"); - xmlnode_set_attrib(node,"name",pref->name); - - for(child = pref->first_child; child != NULL; child = child->sibling) - pref_to_xmlnode(node, child); - - return node; -} - GList * purple_prefs_get_children_names(const char *name) { - struct purple_pref *pref = find_pref(name); - xmlnode * node = single_pref_to_xmlnode(pref); - xmlnode * child = node->child; GList * list = NULL; + struct purple_pref *pref = find_pref(name), *child; + char sep[2] = "\0\0";; + + if (pref == NULL) + return NULL; - for(child = node->child;child;child = child->next){ - list = g_list_append(list,xmlnode_get_attrib(child,"name")); + if (name[strlen(name) - 1] != '/') + sep[0] = '/'; + for (child = pref->first_child; child; child = child->sibling) { + list = g_list_append(list, g_strdup_printf("%s%s%s", name, sep, child->name)); } - xmlnode_free(node); return list; - } void diff --git a/libpurple/prefs.h b/libpurple/prefs.h index 1fd63e24d7..51f34335a0 100644 --- a/libpurple/prefs.h +++ b/libpurple/prefs.h @@ -285,8 +285,9 @@ GList *purple_prefs_get_path_list(const char *name); * Returns a list of children for a pref * * @param name The parent pref - * @return A list of strings denoting the names of the children, NULL if there are no children or if pref doesn't exist. Be sure to free this list when your done with it. - * + * @return A list of newly allocated strings denoting the names of the children. + * Returns @c NULL if there are no children or if pref doesn't exist. + * The caller must free all the strings and the list. */ GList *purple_prefs_get_children_names(const char *name); |