# HG changeset patch # User Sadrul Habib Chowdhury # Date 1186839273 0 # Node ID 6902517cdfe67d57169e7d19b205d87fb46c58b2 # Parent 772670b9e9f8026d9274f05f52219ad4dc46161b Fix a couple of memory leaks. Set a title for the file selection dialog. Make the 'Test' button work without having to save first. diff -r 772670b9e9f8 -r 6902517cdfe6 finch/gntsound.c --- a/finch/gntsound.c Sat Aug 11 13:04:36 2007 +0000 +++ b/finch/gntsound.c Sat Aug 11 13:34:33 2007 +0000 @@ -660,6 +660,7 @@ event->file = g_strdup(path); gnt_tree_change_text(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(event->id), 1, file); + gnt_tree_set_choice(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(event->id), TRUE); gnt_widget_destroy(GNT_WIDGET(w)); } @@ -669,21 +670,28 @@ { PurpleSoundEventID id = GPOINTER_TO_INT(gnt_tree_get_selection_data(GNT_TREE(pref_dialog->events))); FinchSoundEvent * event = &sounds[id]; - char *pref; + char *enabled, *file, *tmpfile; gboolean temp_value; - pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s", finch_sound_get_active_profile(), - event->pref); + enabled = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s", + finch_sound_get_active_profile(), event->pref); + file = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s", + finch_sound_get_active_profile(), event->pref); - temp_value = purple_prefs_get_bool(pref); + temp_value = purple_prefs_get_bool(enabled); + tmpfile = g_strdup(purple_prefs_get_string(file)); - if (!temp_value) purple_prefs_set_bool(pref, TRUE); + purple_prefs_set_string(file, event->file); + if (!temp_value) purple_prefs_set_bool(enabled, TRUE); purple_sound_play_event(id, NULL); - if (!temp_value) purple_prefs_set_bool(pref, FALSE); + if (!temp_value) purple_prefs_set_bool(enabled, FALSE); + purple_prefs_set_string(file, tmpfile); - g_free(pref); + g_free(enabled); + g_free(file); + g_free(tmpfile); } static void @@ -708,6 +716,7 @@ FinchSoundEvent * event = &sounds[id]; char *path = NULL; + gnt_box_set_title(GNT_BOX(w), _("Select Sound File ...")); gnt_file_sel_set_current_location(sel, (event && event->file) ? (path = g_path_get_dirname(event->file)) : purple_home_dir()); @@ -734,6 +743,7 @@ PurpleSoundEventID id = GPOINTER_TO_INT(itr->data); FinchSoundEvent * e = &sounds[id]; g_free(e->file); + e->file = NULL; } if (pref_dialog->selector) gnt_widget_destroy(pref_dialog->selector); @@ -761,11 +771,12 @@ for (i = 0; i < PURPLE_NUM_SOUNDS; i++) { FinchSoundEvent * event = &sounds[i]; gchar *boolpref; - gchar *filepref; + gchar *filepref, *basename = NULL; const char * profile = finch_sound_get_active_profile(); filepref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s", profile, event->pref); + g_free(event->file); event->file = g_strdup(purple_prefs_get_path(filepref)); g_free(filepref); @@ -776,7 +787,9 @@ 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_change_text(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), 1, + event->file[0] ? (basename = g_path_get_basename(event->file)) : _("(default)")); + g_free(basename); gnt_tree_set_choice(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), purple_prefs_get_bool(boolpref));