# HG changeset patch # User Eric Polino # Date 1184188209 0 # Node ID 3266c971527e0965f4de65d644e560427200b004 # Parent f65c287e466e2f500f5cc3404f3da620aa907b5f# Parent 58743fae0db2da9cb192a338257ca18d02635f2e merge of '16890deaaff10687d4bb05f2ee33efeac224027b' and 'be171823c0e7310de39e80aead1e59befce30c01' diff -r 58743fae0db2 -r 3266c971527e finch/gntsound.c --- a/finch/gntsound.c Wed Jul 11 20:03:24 2007 +0000 +++ b/finch/gntsound.c Wed Jul 11 21:10:09 2007 +0000 @@ -74,13 +74,12 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ static void pref_save_cb(GntWidget *button, gpointer null) { - + /* XXX: */ } static void @@ -764,26 +769,25 @@ 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 @@ GList *itr,*list; gint i; - if(pref_dialog){ + if(pref_dialog) { gnt_window_present(pref_dialog->window); return; } @@ -817,6 +821,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ { return &sound_ui_ops; } + diff -r 58743fae0db2 -r 3266c971527e finch/gntsound.h --- a/finch/gntsound.h Wed Jul 11 20:03:24 2007 +0000 +++ b/finch/gntsound.h Wed Jul 11 21:10:09 2007 +0000 @@ -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 @@ */ 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 -r 58743fae0db2 -r 3266c971527e libpurple/prefs.c --- a/libpurple/prefs.c Wed Jul 11 20:03:24 2007 +0000 +++ b/libpurple/prefs.c Wed Jul 11 21:10:09 2007 +0000 @@ -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 @@ 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 @@ 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 -r 58743fae0db2 -r 3266c971527e libpurple/prefs.h --- a/libpurple/prefs.h Wed Jul 11 20:03:24 2007 +0000 +++ b/libpurple/prefs.h Wed Jul 11 21:10:09 2007 +0000 @@ -285,8 +285,9 @@ * 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);