Mercurial > pidgin
comparison finch/gntsound.c @ 19163:1e4630ee4b2a
Fix some crashes when adding new profiles with the same name.
And a lot of whitespace fixes.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Fri, 13 Jul 2007 11:53:44 +0000 |
parents | e1678c435944 |
children | 738404d087ff |
comparison
equal
deleted
inserted
replaced
19162:e1678c435944 | 19163:1e4630ee4b2a |
---|---|
139 char *nick = NULL; | 139 char *nick = NULL; |
140 char *name = NULL; | 140 char *name = NULL; |
141 gboolean ret = FALSE; | 141 gboolean ret = FALSE; |
142 chat = purple_conversation_get_chat_data(conv); | 142 chat = purple_conversation_get_chat_data(conv); |
143 | 143 |
144 if (chat==NULL) | 144 if (chat == NULL) |
145 return ret; | 145 return ret; |
146 | 146 |
147 nick = g_strdup(purple_normalize(conv->account, chat->nick)); | 147 nick = g_strdup(purple_normalize(conv->account, chat->nick)); |
148 name = g_strdup(purple_normalize(conv->account, aname)); | 148 name = g_strdup(purple_normalize(conv->account, aname)); |
149 | 149 |
194 PurpleMessageFlags flags, PurpleSoundEventID event) | 194 PurpleMessageFlags flags, PurpleSoundEventID event) |
195 { | 195 { |
196 if (flags & PURPLE_MESSAGE_DELAYED) | 196 if (flags & PURPLE_MESSAGE_DELAYED) |
197 return; | 197 return; |
198 | 198 |
199 if (conv==NULL) { | 199 if (conv == NULL) { |
200 purple_sound_play_event(PURPLE_SOUND_FIRST_RECEIVE, account); | 200 purple_sound_play_event(PURPLE_SOUND_FIRST_RECEIVE, account); |
201 } else { | 201 } else { |
202 play_conv_event(conv, event); | 202 play_conv_event(conv, event); |
203 } | 203 } |
204 } | 204 } |
292 | 292 |
293 /* This gets called when the active profile changes */ | 293 /* This gets called when the active profile changes */ |
294 static void | 294 static void |
295 initialize_profile(const char *name, PurplePrefType type, gconstpointer val, gpointer null) | 295 initialize_profile(const char *name, PurplePrefType type, gconstpointer val, gpointer null) |
296 { | 296 { |
297 if(purple_prefs_exists(make_pref(""))) | 297 if (purple_prefs_exists(make_pref(""))) |
298 return; | 298 return; |
299 | 299 |
300 purple_prefs_add_none(make_pref("")); | 300 purple_prefs_add_none(make_pref("")); |
301 purple_prefs_add_none(make_pref("/enabled")); | 301 purple_prefs_add_none(make_pref("/enabled")); |
302 purple_prefs_add_none(make_pref("/file")); | 302 purple_prefs_add_none(make_pref("/file")); |
474 return; | 474 return; |
475 } | 475 } |
476 | 476 |
477 esc_filename = g_shell_quote(filename); | 477 esc_filename = g_shell_quote(filename); |
478 | 478 |
479 if(strstr(sound_cmd, "%s")) | 479 if (strstr(sound_cmd, "%s")) |
480 command = purple_strreplace(sound_cmd, "%s", esc_filename); | 480 command = purple_strreplace(sound_cmd, "%s", esc_filename); |
481 else | 481 else |
482 command = g_strdup_printf("%s %s", sound_cmd, esc_filename); | 482 command = g_strdup_printf("%s %s", sound_cmd, esc_filename); |
483 | 483 |
484 if(!g_spawn_command_line_async(command, &error)) { | 484 if (!g_spawn_command_line_async(command, &error)) { |
485 purple_debug_error("gntsound", "sound command could not be launched: %s\n", error->message); | 485 purple_debug_error("gntsound", "sound command could not be launched: %s\n", error->message); |
486 g_error_free(error); | 486 g_error_free(error); |
487 } | 487 } |
488 | 488 |
489 g_free(esc_filename); | 489 g_free(esc_filename); |
583 file_pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s", finch_sound_get_active_profile(), sounds[event].pref); | 583 file_pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s", finch_sound_get_active_profile(), sounds[event].pref); |
584 | 584 |
585 /* check NULL for sounds that don't have an option, ie buddy pounce */ | 585 /* check NULL for sounds that don't have an option, ie buddy pounce */ |
586 if (purple_prefs_get_bool(enable_pref)) { | 586 if (purple_prefs_get_bool(enable_pref)) { |
587 char *filename = g_strdup(purple_prefs_get_path(file_pref)); | 587 char *filename = g_strdup(purple_prefs_get_path(file_pref)); |
588 if(!filename || !strlen(filename)) { | 588 if (!filename || !strlen(filename)) { |
589 g_free(filename); | 589 g_free(filename); |
590 /* XXX Consider creating a constant for "sounds/purple" to be shared with Pidgin */ | 590 /* XXX Consider creating a constant for "sounds/purple" to be shared with Pidgin */ |
591 filename = g_build_filename(DATADIR, "sounds", "purple", sounds[event].def, NULL); | 591 filename = g_build_filename(DATADIR, "sounds", "purple", sounds[event].def, NULL); |
592 } | 592 } |
593 | 593 |
618 { | 618 { |
619 purple_prefs_set_string(FINCH_PREFS_ROOT "/sound/actprofile", name); | 619 purple_prefs_set_string(FINCH_PREFS_ROOT "/sound/actprofile", name); |
620 } | 620 } |
621 | 621 |
622 gboolean | 622 gboolean |
623 finch_sound_profile_exists(const char *name){ | 623 finch_sound_profile_exists(const char *name) { |
624 gchar * tmp; | 624 gchar * tmp; |
625 gboolean ret = purple_prefs_exists(tmp = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s", name)); | 625 gboolean ret = purple_prefs_exists(tmp = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s", name)); |
626 g_free(tmp); | 626 g_free(tmp); |
627 return ret; | 627 return ret; |
628 } | 628 } |
636 purple_prefs_set_path(make_pref("/command"), gnt_entry_get_text(GNT_ENTRY(pref_dialog->command))); | 636 purple_prefs_set_path(make_pref("/command"), gnt_entry_get_text(GNT_ENTRY(pref_dialog->command))); |
637 purple_prefs_set_bool(make_pref("/conv_focus"), gnt_check_box_get_checked(GNT_CHECK_BOX(pref_dialog->conv_focus))); | 637 purple_prefs_set_bool(make_pref("/conv_focus"), gnt_check_box_get_checked(GNT_CHECK_BOX(pref_dialog->conv_focus))); |
638 purple_prefs_set_int("/purple/sound/while_status", GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(pref_dialog->while_status)))); | 638 purple_prefs_set_int("/purple/sound/while_status", GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(pref_dialog->while_status)))); |
639 purple_prefs_set_int(make_pref("/volume"), gnt_slider_get_value(GNT_SLIDER(pref_dialog->volume))); | 639 purple_prefs_set_int(make_pref("/volume"), gnt_slider_get_value(GNT_SLIDER(pref_dialog->volume))); |
640 | 640 |
641 for(itr = gnt_tree_get_rows(GNT_TREE(pref_dialog->events));itr;itr = itr->next){ | 641 for (itr = gnt_tree_get_rows(GNT_TREE(pref_dialog->events)); itr; itr = itr->next) { |
642 FinchSoundEvent * event = &sounds[GPOINTER_TO_INT(itr->data)]; | 642 FinchSoundEvent * event = &sounds[GPOINTER_TO_INT(itr->data)]; |
643 char * filepref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s", finch_sound_get_active_profile(), event->pref); | 643 char * filepref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s", finch_sound_get_active_profile(), event->pref); |
644 char * boolpref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s", finch_sound_get_active_profile(), event->pref); | 644 char * boolpref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s", finch_sound_get_active_profile(), event->pref); |
645 purple_prefs_set_bool(boolpref, gnt_tree_get_choice(GNT_TREE(pref_dialog->events), itr->data)); | 645 purple_prefs_set_bool(boolpref, gnt_tree_get_choice(GNT_TREE(pref_dialog->events), itr->data)); |
646 purple_prefs_set_path(filepref, event->file ? event->file : ""); | 646 purple_prefs_set_path(filepref, event->file ? event->file : ""); |
727 | 727 |
728 static void | 728 static void |
729 release_pref_dialog(GntBindable *data, gpointer null) | 729 release_pref_dialog(GntBindable *data, gpointer null) |
730 { | 730 { |
731 GList * itr; | 731 GList * itr; |
732 for(itr = gnt_tree_get_rows(GNT_TREE(pref_dialog->events));itr;itr = itr->next){ | 732 for (itr = gnt_tree_get_rows(GNT_TREE(pref_dialog->events)); itr; itr = itr->next) { |
733 PurpleSoundEventID id = GPOINTER_TO_INT(itr->data); | 733 PurpleSoundEventID id = GPOINTER_TO_INT(itr->data); |
734 FinchSoundEvent * e = &sounds[id]; | 734 FinchSoundEvent * e = &sounds[id]; |
735 g_free(e->file); | 735 g_free(e->file); |
736 } | 736 } |
737 if (pref_dialog->selector) | 737 if (pref_dialog->selector) |
755 | 755 |
756 gnt_combo_box_set_selected(GNT_COMBO_BOX(pref_dialog->while_status), GINT_TO_POINTER(purple_prefs_get_int("/purple" "/sound/while_status"))); | 756 gnt_combo_box_set_selected(GNT_COMBO_BOX(pref_dialog->while_status), GINT_TO_POINTER(purple_prefs_get_int("/purple" "/sound/while_status"))); |
757 | 757 |
758 gnt_slider_set_value(GNT_SLIDER(pref_dialog->volume), CLAMP(purple_prefs_get_int(make_pref("/volume")), 0, 100)); | 758 gnt_slider_set_value(GNT_SLIDER(pref_dialog->volume), CLAMP(purple_prefs_get_int(make_pref("/volume")), 0, 100)); |
759 | 759 |
760 for(i = 0;i < PURPLE_NUM_SOUNDS;i++){ | 760 for (i = 0; i < PURPLE_NUM_SOUNDS; i++) { |
761 FinchSoundEvent * event = &sounds[i]; | 761 FinchSoundEvent * event = &sounds[i]; |
762 gchar *boolpref; | 762 gchar *boolpref; |
763 gchar *filepref; | 763 gchar *filepref; |
764 const char * profile = finch_sound_get_active_profile(); | 764 const char * profile = finch_sound_get_active_profile(); |
765 | 765 |
788 } | 788 } |
789 | 789 |
790 static void | 790 static void |
791 reload_pref_window(const char *profile) | 791 reload_pref_window(const char *profile) |
792 { | 792 { |
793 if(!strcmp(profile, finch_sound_get_active_profile())) | 793 if (!strcmp(profile, finch_sound_get_active_profile())) |
794 return; | 794 return; |
795 load_pref_window(profile); | 795 load_pref_window(profile); |
796 | |
797 } | 796 } |
798 | 797 |
799 static void | 798 static void |
800 prof_del_cb(GntWidget *button, gpointer null) | 799 prof_del_cb(GntWidget *button, gpointer null) |
801 { | 800 { |
802 | 801 |
803 gchar * profile = gnt_tree_get_selection_data(GNT_TREE(pref_dialog->profiles)); | 802 gchar * profile = gnt_tree_get_selection_data(GNT_TREE(pref_dialog->profiles)); |
804 gchar * pref; | 803 gchar * pref; |
805 | 804 |
806 if(!strcmp(profile, DEFAULT_PROFILE)) | 805 if (!strcmp(profile, DEFAULT_PROFILE)) |
807 return; | 806 return; |
808 | 807 |
809 pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s", profile); | 808 pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s", profile); |
810 purple_prefs_remove(pref); | 809 purple_prefs_remove(pref); |
811 g_free(pref); | 810 g_free(pref); |
812 | 811 |
813 if(!strcmp(pref_dialog->original_profile, profile)){ | 812 if (!strcmp(pref_dialog->original_profile, profile)) { |
814 g_free(pref_dialog->original_profile); | 813 g_free(pref_dialog->original_profile); |
815 pref_dialog->original_profile = g_strdup(DEFAULT_PROFILE); | 814 pref_dialog->original_profile = g_strdup(DEFAULT_PROFILE); |
816 } | 815 } |
817 | 816 |
818 gnt_tree_remove(GNT_TREE(pref_dialog->profiles), profile); | 817 gnt_tree_remove(GNT_TREE(pref_dialog->profiles), profile); |
823 static void | 822 static void |
824 prof_add_cb(GntButton *button, GntEntry * entry) | 823 prof_add_cb(GntButton *button, GntEntry * entry) |
825 { | 824 { |
826 const char * profile = gnt_entry_get_text(entry); | 825 const char * profile = gnt_entry_get_text(entry); |
827 GntTreeRow * row; | 826 GntTreeRow * row; |
828 if(!finch_sound_profile_exists(profile)){ | 827 if (!finch_sound_profile_exists(profile)) { |
829 gpointer key = g_strdup(profile); | 828 gpointer key = g_strdup(profile); |
830 row = gnt_tree_create_row(GNT_TREE(pref_dialog->profiles), profile); | 829 row = gnt_tree_create_row(GNT_TREE(pref_dialog->profiles), profile); |
831 gnt_tree_add_row_after(GNT_TREE(pref_dialog->profiles), key, | 830 gnt_tree_add_row_after(GNT_TREE(pref_dialog->profiles), key, |
832 row, | 831 row, |
833 NULL, NULL); | 832 NULL, NULL); |
834 gnt_entry_set_text(entry, ""); | 833 gnt_entry_set_text(entry, ""); |
835 gnt_tree_set_selected(GNT_TREE(pref_dialog->profiles), key); | 834 gnt_tree_set_selected(GNT_TREE(pref_dialog->profiles), key); |
836 } | 835 finch_sound_set_active_profile(key); |
837 | 836 } else |
838 reload_pref_window(profile); | 837 reload_pref_window(profile); |
839 | |
840 } | 838 } |
841 | 839 |
842 static void | 840 static void |
843 prof_load_cb(GntTree *tree, gpointer oldkey, gpointer newkey, gpointer null) | 841 prof_load_cb(GntTree *tree, gpointer oldkey, gpointer newkey, gpointer null) |
844 { | 842 { |
864 GntWidget *win; | 862 GntWidget *win; |
865 | 863 |
866 gint i; | 864 gint i; |
867 GList *itr, *list; | 865 GList *itr, *list; |
868 | 866 |
869 if(pref_dialog) { | 867 if (pref_dialog) { |
870 gnt_window_present(pref_dialog->window); | 868 gnt_window_present(pref_dialog->window); |
871 return; | 869 return; |
872 } | 870 } |
873 | 871 |
874 pref_dialog = g_new0(SoundPrefDialog, 1); | 872 pref_dialog = g_new0(SoundPrefDialog, 1); |
894 gnt_tree_set_hash_fns(GNT_TREE(tree), g_str_hash, g_str_equal, g_free); | 892 gnt_tree_set_hash_fns(GNT_TREE(tree), g_str_hash, g_str_equal, g_free); |
895 gnt_tree_set_compare_func(GNT_TREE(tree), (GCompareFunc)g_ascii_strcasecmp); | 893 gnt_tree_set_compare_func(GNT_TREE(tree), (GCompareFunc)g_ascii_strcasecmp); |
896 g_signal_connect(G_OBJECT(tree), "selection-changed", G_CALLBACK(prof_load_cb), NULL); | 894 g_signal_connect(G_OBJECT(tree), "selection-changed", G_CALLBACK(prof_load_cb), NULL); |
897 | 895 |
898 itr = list = finch_sound_get_profiles(); | 896 itr = list = finch_sound_get_profiles(); |
899 for(;itr;itr = itr->next){ | 897 for (; itr; itr = itr->next) { |
900 gnt_tree_add_row_after(GNT_TREE(tree), itr->data, gnt_tree_create_row(GNT_TREE(tree), itr->data), NULL, NULL); | 898 gnt_tree_add_row_after(GNT_TREE(tree), itr->data, gnt_tree_create_row(GNT_TREE(tree), itr->data), NULL, NULL); |
901 } | 899 } |
902 g_list_free(list); | 900 g_list_free(list); |
903 | 901 |
904 gnt_box_add_widget(GNT_BOX(box), tree); | 902 gnt_box_add_widget(GNT_BOX(box), tree); |
990 gnt_box_add_widget(GNT_BOX(win), gnt_label_new_with_format(_("Sound Events"), GNT_TEXT_FLAG_BOLD)); | 988 gnt_box_add_widget(GNT_BOX(win), gnt_label_new_with_format(_("Sound Events"), GNT_TEXT_FLAG_BOLD)); |
991 pref_dialog->events = tree = gnt_tree_new_with_columns(2); | 989 pref_dialog->events = tree = gnt_tree_new_with_columns(2); |
992 gnt_tree_set_column_titles(GNT_TREE(tree), _("Event"), _("File")); | 990 gnt_tree_set_column_titles(GNT_TREE(tree), _("Event"), _("File")); |
993 gnt_tree_set_show_title(GNT_TREE(tree), TRUE); | 991 gnt_tree_set_show_title(GNT_TREE(tree), TRUE); |
994 | 992 |
995 for(i = 0;i < PURPLE_NUM_SOUNDS;i++){ | 993 for (i = 0; i < PURPLE_NUM_SOUNDS; i++) { |
996 FinchSoundEvent * event = &sounds[i]; | 994 FinchSoundEvent * event = &sounds[i]; |
997 | 995 |
998 if(event->label == NULL){ | 996 if (event->label == NULL) { |
999 continue; | 997 continue; |
1000 } | 998 } |
1001 | 999 |
1002 gnt_tree_add_choice(GNT_TREE(tree), GINT_TO_POINTER(i), | 1000 gnt_tree_add_choice(GNT_TREE(tree), GINT_TO_POINTER(i), |
1003 gnt_tree_create_row(GNT_TREE(tree), "", ""), | 1001 gnt_tree_create_row(GNT_TREE(tree), "", ""), |