Mercurial > pidgin
comparison finch/gntsound.c @ 19184:6902517cdfe6
Fix a couple of memory leaks.
Set a title for the file selection dialog.
Make the 'Test' button work without having to save first.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sat, 11 Aug 2007 13:34:33 +0000 |
parents | 772670b9e9f8 |
children | cdb0fbe5de7b |
comparison
equal
deleted
inserted
replaced
19183:772670b9e9f8 | 19184:6902517cdfe6 |
---|---|
658 | 658 |
659 g_free(event->file); | 659 g_free(event->file); |
660 event->file = g_strdup(path); | 660 event->file = g_strdup(path); |
661 | 661 |
662 gnt_tree_change_text(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(event->id), 1, file); | 662 gnt_tree_change_text(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(event->id), 1, file); |
663 gnt_tree_set_choice(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(event->id), TRUE); | |
663 | 664 |
664 gnt_widget_destroy(GNT_WIDGET(w)); | 665 gnt_widget_destroy(GNT_WIDGET(w)); |
665 } | 666 } |
666 | 667 |
667 static void | 668 static void |
668 test_cb(GntWidget *button, gpointer null) | 669 test_cb(GntWidget *button, gpointer null) |
669 { | 670 { |
670 PurpleSoundEventID id = GPOINTER_TO_INT(gnt_tree_get_selection_data(GNT_TREE(pref_dialog->events))); | 671 PurpleSoundEventID id = GPOINTER_TO_INT(gnt_tree_get_selection_data(GNT_TREE(pref_dialog->events))); |
671 FinchSoundEvent * event = &sounds[id]; | 672 FinchSoundEvent * event = &sounds[id]; |
672 char *pref; | 673 char *enabled, *file, *tmpfile; |
673 gboolean temp_value; | 674 gboolean temp_value; |
674 | 675 |
675 pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s", finch_sound_get_active_profile(), | 676 enabled = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s", |
676 event->pref); | 677 finch_sound_get_active_profile(), event->pref); |
677 | 678 file = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s", |
678 temp_value = purple_prefs_get_bool(pref); | 679 finch_sound_get_active_profile(), event->pref); |
679 | 680 |
680 if (!temp_value) purple_prefs_set_bool(pref, TRUE); | 681 temp_value = purple_prefs_get_bool(enabled); |
682 tmpfile = g_strdup(purple_prefs_get_string(file)); | |
683 | |
684 purple_prefs_set_string(file, event->file); | |
685 if (!temp_value) purple_prefs_set_bool(enabled, TRUE); | |
681 | 686 |
682 purple_sound_play_event(id, NULL); | 687 purple_sound_play_event(id, NULL); |
683 | 688 |
684 if (!temp_value) purple_prefs_set_bool(pref, FALSE); | 689 if (!temp_value) purple_prefs_set_bool(enabled, FALSE); |
685 | 690 purple_prefs_set_string(file, tmpfile); |
686 g_free(pref); | 691 |
692 g_free(enabled); | |
693 g_free(file); | |
694 g_free(tmpfile); | |
687 } | 695 } |
688 | 696 |
689 static void | 697 static void |
690 reset_cb(GntWidget *button, gpointer null) | 698 reset_cb(GntWidget *button, gpointer null) |
691 { | 699 { |
706 GntFileSel *sel = GNT_FILE_SEL(w); | 714 GntFileSel *sel = GNT_FILE_SEL(w); |
707 PurpleSoundEventID id = GPOINTER_TO_INT(gnt_tree_get_selection_data(GNT_TREE(pref_dialog->events))); | 715 PurpleSoundEventID id = GPOINTER_TO_INT(gnt_tree_get_selection_data(GNT_TREE(pref_dialog->events))); |
708 FinchSoundEvent * event = &sounds[id]; | 716 FinchSoundEvent * event = &sounds[id]; |
709 char *path = NULL; | 717 char *path = NULL; |
710 | 718 |
719 gnt_box_set_title(GNT_BOX(w), _("Select Sound File ...")); | |
711 gnt_file_sel_set_current_location(sel, | 720 gnt_file_sel_set_current_location(sel, |
712 (event && event->file) ? (path = g_path_get_dirname(event->file)) | 721 (event && event->file) ? (path = g_path_get_dirname(event->file)) |
713 : purple_home_dir()); | 722 : purple_home_dir()); |
714 | 723 |
715 g_signal_connect_swapped(G_OBJECT(sel->cancel), "activate", G_CALLBACK(gnt_widget_destroy), sel); | 724 g_signal_connect_swapped(G_OBJECT(sel->cancel), "activate", G_CALLBACK(gnt_widget_destroy), sel); |
732 GList * itr; | 741 GList * itr; |
733 for (itr = gnt_tree_get_rows(GNT_TREE(pref_dialog->events)); itr; itr = itr->next) { | 742 for (itr = gnt_tree_get_rows(GNT_TREE(pref_dialog->events)); itr; itr = itr->next) { |
734 PurpleSoundEventID id = GPOINTER_TO_INT(itr->data); | 743 PurpleSoundEventID id = GPOINTER_TO_INT(itr->data); |
735 FinchSoundEvent * e = &sounds[id]; | 744 FinchSoundEvent * e = &sounds[id]; |
736 g_free(e->file); | 745 g_free(e->file); |
746 e->file = NULL; | |
737 } | 747 } |
738 if (pref_dialog->selector) | 748 if (pref_dialog->selector) |
739 gnt_widget_destroy(pref_dialog->selector); | 749 gnt_widget_destroy(pref_dialog->selector); |
740 g_free(pref_dialog); | 750 g_free(pref_dialog); |
741 pref_dialog = NULL; | 751 pref_dialog = NULL; |
759 gnt_slider_set_value(GNT_SLIDER(pref_dialog->volume), CLAMP(purple_prefs_get_int(make_pref("/volume")), 0, 100)); | 769 gnt_slider_set_value(GNT_SLIDER(pref_dialog->volume), CLAMP(purple_prefs_get_int(make_pref("/volume")), 0, 100)); |
760 | 770 |
761 for (i = 0; i < PURPLE_NUM_SOUNDS; i++) { | 771 for (i = 0; i < PURPLE_NUM_SOUNDS; i++) { |
762 FinchSoundEvent * event = &sounds[i]; | 772 FinchSoundEvent * event = &sounds[i]; |
763 gchar *boolpref; | 773 gchar *boolpref; |
764 gchar *filepref; | 774 gchar *filepref, *basename = NULL; |
765 const char * profile = finch_sound_get_active_profile(); | 775 const char * profile = finch_sound_get_active_profile(); |
766 | 776 |
767 filepref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s", profile, event->pref); | 777 filepref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s", profile, event->pref); |
768 | 778 |
779 g_free(event->file); | |
769 event->file = g_strdup(purple_prefs_get_path(filepref)); | 780 event->file = g_strdup(purple_prefs_get_path(filepref)); |
770 | 781 |
771 g_free(filepref); | 782 g_free(filepref); |
772 if (event->label == NULL) { | 783 if (event->label == NULL) { |
773 continue; | 784 continue; |
774 } | 785 } |
775 | 786 |
776 boolpref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s", profile, event->pref); | 787 boolpref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s", profile, event->pref); |
777 | 788 |
778 gnt_tree_change_text(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), 0, event->label); | 789 gnt_tree_change_text(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), 0, event->label); |
779 gnt_tree_change_text(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), 1, event->file[0] ? g_path_get_basename(event->file) : _("(default)")); | 790 gnt_tree_change_text(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), 1, |
791 event->file[0] ? (basename = g_path_get_basename(event->file)) : _("(default)")); | |
792 g_free(basename); | |
780 | 793 |
781 gnt_tree_set_choice(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), purple_prefs_get_bool(boolpref)); | 794 gnt_tree_set_choice(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), purple_prefs_get_bool(boolpref)); |
782 | 795 |
783 g_free(boolpref); | 796 g_free(boolpref); |
784 } | 797 } |