Mercurial > pidgin
comparison finch/gntsound.c @ 19132:1b942e21ec1b
Some more work to the sound prefs
Added: Events, still can't reset
author | Eric Polino <aluink@pidgin.im> |
---|---|
date | Thu, 05 Jul 2007 02:34:30 +0000 |
parents | 5da541d974a4 |
children | 0e4eeb6f6284 |
comparison
equal
deleted
inserted
replaced
19131:5da541d974a4 | 19132:1b942e21ec1b |
---|---|
50 #include "gntentry.h" | 50 #include "gntentry.h" |
51 #include "gntcheckbox.h" | 51 #include "gntcheckbox.h" |
52 #include "gntline.h" | 52 #include "gntline.h" |
53 #include "gntslider.h" | 53 #include "gntslider.h" |
54 #include "gnttree.h" | 54 #include "gnttree.h" |
55 | 55 #include "gntfilesel.h" |
56 struct finch_sound_event { | 56 |
57 typedef struct { | |
57 char *label; | 58 char *label; |
58 char *pref; | 59 char *pref; |
59 char *def; | 60 char *def; |
60 }; | 61 PurpleSoundEventID id; |
62 } FinchSoundEvent; | |
63 | |
64 typedef struct { | |
65 FinchSoundEvent *event; | |
66 char *file; | |
67 } FinchSoundPrefEvent; | |
61 | 68 |
62 typedef struct { | 69 typedef struct { |
63 GntWidget *method; | 70 GntWidget *method; |
64 GntWidget *command; | 71 GntWidget *command; |
65 GntWidget *conv_focus; | 72 GntWidget *conv_focus; |
78 | 85 |
79 #ifdef USE_GSTREAMER | 86 #ifdef USE_GSTREAMER |
80 static gboolean gst_init_failed; | 87 static gboolean gst_init_failed; |
81 #endif /* USE_GSTREAMER */ | 88 #endif /* USE_GSTREAMER */ |
82 | 89 |
83 static struct finch_sound_event sounds[PURPLE_NUM_SOUNDS] = { | 90 static FinchSoundEvent sounds[PURPLE_NUM_SOUNDS] = { |
84 {N_("Buddy logs in"), "login", "login.wav"}, | 91 {N_("Buddy logs in"), "login", "login.wav",PURPLE_SOUND_BUDDY_ARRIVE}, |
85 {N_("Buddy logs out"), "logout", "logout.wav"}, | 92 {N_("Buddy logs out"), "logout", "logout.wav",PURPLE_SOUND_BUDDY_LEAVE}, |
86 {N_("Message received"), "im_recv", "receive.wav"}, | 93 {N_("Message received"), "im_recv", "receive.wav",PURPLE_SOUND_RECEIVE}, |
87 {N_("Message received begins conversation"), "first_im_recv", "receive.wav"}, | 94 {N_("Message received begins conversation"), "first_im_recv", "receive.wav",PURPLE_SOUND_FIRST_RECEIVE}, |
88 {N_("Message sent"), "send_im", "send.wav"}, | 95 {N_("Message sent"), "send_im", "send.wav",PURPLE_SOUND_SEND}, |
89 {N_("Person enters chat"), "join_chat", "login.wav"}, | 96 {N_("Person enters chat"), "join_chat", "login.wav",PURPLE_SOUND_CHAT_JOIN}, |
90 {N_("Person leaves chat"), "left_chat", "logout.wav"}, | 97 {N_("Person leaves chat"), "left_chat", "logout.wav",PURPLE_SOUND_CHAT_LEAVE}, |
91 {N_("You talk in chat"), "send_chat_msg", "send.wav"}, | 98 {N_("You talk in chat"), "send_chat_msg", "send.wav",PURPLE_SOUND_CHAT_YOU_SAY}, |
92 {N_("Others talk in chat"), "chat_msg_recv", "receive.wav"}, | 99 {N_("Others talk in chat"), "chat_msg_recv", "receive.wav",PURPLE_SOUND_CHAT_SAY}, |
93 /* this isn't a terminator, it's the buddy pounce default sound event ;-) */ | 100 /* this isn't a terminator, it's the buddy pounce default sound event ;-) */ |
94 {NULL, "pounce_default", "alert.wav"}, | 101 {NULL, "pounce_default", "alert.wav",PURPLE_SOUND_POUNCE_DEFAULT}, |
95 {N_("Someone says your screen name in chat"), "nick_said", "alert.wav"} | 102 {N_("Someone says your screen name in chat"), "nick_said", "alert.wav",PURPLE_SOUND_CHAT_NICK} |
96 }; | 103 }; |
97 | 104 |
98 static gboolean | 105 static gboolean |
99 unmute_login_sounds_cb(gpointer data) | 106 unmute_login_sounds_cb(gpointer data) |
100 { | 107 { |
581 purple_prefs_set_bool(FINCH_PREFS_ROOT "/sound/conv_focus",gnt_check_box_get_checked(GNT_CHECK_BOX(pref_dialog->conv_focus))); | 588 purple_prefs_set_bool(FINCH_PREFS_ROOT "/sound/conv_focus",gnt_check_box_get_checked(GNT_CHECK_BOX(pref_dialog->conv_focus))); |
582 purple_prefs_set_int("/purple/sound/while_status",GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(pref_dialog->while_status)))); | 589 purple_prefs_set_int("/purple/sound/while_status",GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(pref_dialog->while_status)))); |
583 purple_prefs_set_int(FINCH_PREFS_ROOT "/sound/volume",gnt_slider_get_value(GNT_SLIDER(pref_dialog->volume))); | 590 purple_prefs_set_int(FINCH_PREFS_ROOT "/sound/volume",gnt_slider_get_value(GNT_SLIDER(pref_dialog->volume))); |
584 | 591 |
585 for(i = 0;i < PURPLE_NUM_SOUNDS;i++){ | 592 for(i = 0;i < PURPLE_NUM_SOUNDS;i++){ |
586 const gchar * option = finch_sound_get_event_option(i); | 593 GList * itr = gnt_tree_get_rows(GNT_TREE(pref_dialog->events)); |
587 gchar *pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/enabled/%s", | 594 for(;itr;itr = itr->next){ |
588 option); | 595 FinchSoundPrefEvent * event = itr->data; |
589 gboolean choice = gnt_tree_get_choice(GNT_TREE(pref_dialog->events),GINT_TO_POINTER(g_str_hash(option))); | 596 char * pref = g_strdup_printf("%s/sound/file/%s",FINCH_PREFS_ROOT,event->event->pref); |
590 purple_prefs_set_bool(pref,choice); | 597 if(event->file) |
591 g_free(pref); | 598 purple_prefs_set_path(pref,event->file); |
599 g_free(pref); | |
600 } | |
592 } | 601 } |
593 gnt_widget_destroy(GNT_WIDGET(win)); | 602 gnt_widget_destroy(GNT_WIDGET(win)); |
594 } | 603 } |
595 static void | 604 static void |
596 cancel_cb(GntWidget *button, gpointer win) | 605 file_cb(GntWidget *w, gpointer data) |
597 { | 606 { |
598 gnt_widget_destroy(GNT_WIDGET(win)); | 607 GntFileSel *sel = GNT_FILE_SEL(data); |
608 const char * file = gnt_file_sel_get_selected_file(sel); | |
609 FinchSoundPrefEvent * event = gnt_tree_get_selection_data(GNT_TREE(pref_dialog->events)); | |
610 | |
611 if(event->file) | |
612 g_free(event->file); | |
613 event->file = g_strdup(file); | |
614 | |
615 gnt_widget_destroy(GNT_WIDGET(data)); | |
616 } | |
617 | |
618 static void | |
619 test_cb(GntWidget *button, gpointer null) | |
620 { | |
621 FinchSoundPrefEvent * event = gnt_tree_get_selection_data(GNT_TREE(pref_dialog->events)); | |
622 char *pref; | |
623 gboolean temp_value; | |
624 | |
625 pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/enabled/%s", | |
626 event->event->pref); | |
627 | |
628 temp_value = purple_prefs_get_bool(pref); | |
629 | |
630 if (!temp_value) purple_prefs_set_bool(pref, TRUE); | |
631 | |
632 purple_sound_play_event(event->event->id, NULL); | |
633 | |
634 if (!temp_value) purple_prefs_set_bool(pref, FALSE); | |
635 | |
636 g_free(pref); | |
637 } | |
638 | |
639 static void | |
640 reset_cb(GntWidget *button,gpointer null) | |
641 { | |
642 | |
643 } | |
644 | |
645 static void | |
646 choose_cb(GntWidget *button, gpointer null) | |
647 { | |
648 GntWidget *w = gnt_file_sel_new(); | |
649 | |
650 GntFileSel *sel = GNT_FILE_SEL(w); | |
651 gnt_file_sel_set_current_location(sel,purple_home_dir()); | |
652 | |
653 g_signal_connect_swapped(G_OBJECT(sel->cancel),"activate",G_CALLBACK(gnt_widget_destroy),sel); | |
654 g_signal_connect(G_OBJECT(sel->select),"activate",G_CALLBACK(file_cb),sel); | |
655 | |
656 gnt_widget_show(w); | |
599 } | 657 } |
600 | 658 |
601 static void | 659 static void |
602 release_pref_dialog(GntBindable *data, gpointer null) | 660 release_pref_dialog(GntBindable *data, gpointer null) |
603 { | 661 { |
662 GList * itr; | |
663 for(itr = gnt_tree_get_rows(GNT_TREE(pref_dialog->events));itr;itr = itr->next){ | |
664 FinchSoundPrefEvent * e = (FinchSoundPrefEvent *)itr->data; | |
665 g_free(e->file); | |
666 } | |
604 g_free(pref_dialog); | 667 g_free(pref_dialog); |
605 pref_dialog = NULL; | 668 pref_dialog = NULL; |
606 } | 669 } |
607 | 670 |
608 void | 671 void |
633 gnt_box_set_pad(GNT_BOX(win),0); | 696 gnt_box_set_pad(GNT_BOX(win),0); |
634 gnt_box_set_fill(GNT_BOX(win),FALSE); | 697 gnt_box_set_fill(GNT_BOX(win),FALSE); |
635 gnt_box_set_toplevel(GNT_BOX(win), TRUE); | 698 gnt_box_set_toplevel(GNT_BOX(win), TRUE); |
636 gnt_box_set_title(GNT_BOX(win),_("Sound Preferences")); | 699 gnt_box_set_title(GNT_BOX(win),_("Sound Preferences")); |
637 gnt_box_set_fill(GNT_BOX(win),TRUE); | 700 gnt_box_set_fill(GNT_BOX(win),TRUE); |
638 gnt_box_set_alignment(GNT_BOX(win),GNT_ALIGN_MID); | 701 gnt_box_set_alignment(GNT_BOX(win),GNT_ALIGN_LEFT); |
639 | 702 |
640 pref_dialog->method = cmbox = gnt_combo_box_new(); | 703 pref_dialog->method = cmbox = gnt_combo_box_new(); |
641 gnt_tree_set_hash_fns(GNT_TREE(GNT_COMBO_BOX(cmbox)->dropdown), g_str_hash, g_str_equal, NULL); | 704 gnt_tree_set_hash_fns(GNT_TREE(GNT_COMBO_BOX(cmbox)->dropdown), g_str_hash, g_str_equal, NULL); |
642 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"automatic",_("Automatic")); | 705 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"automatic",_("Automatic")); |
643 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"alsa","ALSA"); | 706 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"alsa","ALSA"); |
644 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"esd","ESD"); | 707 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"esd","ESD"); |
645 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"beep",_("Console Beep")); | 708 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"beep",_("Console Beep")); |
646 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"custom",_("Command")); | 709 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"custom",_("Command")); |
647 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"nosound",_("No Sound")); | 710 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"nosound",_("No Sound")); |
648 buf = g_strdup(purple_prefs_get_string(FINCH_PREFS_ROOT "/sound/method")); | 711 buf = g_strdup(purple_prefs_get_string(FINCH_PREFS_ROOT "/sound/method")); |
649 purple_debug_warning("method","%s",buf); | |
650 gnt_combo_box_set_selected(GNT_COMBO_BOX(cmbox),buf); | 712 gnt_combo_box_set_selected(GNT_COMBO_BOX(cmbox),buf); |
651 g_free(buf); | 713 g_free(buf); |
652 | 714 |
653 label = gnt_label_new_with_format(_("Sound Method"),GNT_TEXT_FLAG_BOLD); | 715 label = gnt_label_new_with_format(_("Sound Method"),GNT_TEXT_FLAG_BOLD); |
654 gnt_box_add_widget(GNT_BOX(win),label); | 716 gnt_box_add_widget(GNT_BOX(win),label); |
703 | 765 |
704 gnt_box_add_widget(GNT_BOX(win), gnt_line_new(FALSE)); | 766 gnt_box_add_widget(GNT_BOX(win), gnt_line_new(FALSE)); |
705 | 767 |
706 gnt_box_add_widget(GNT_BOX(win),gnt_label_new_with_format(_("Sound Events"),GNT_TEXT_FLAG_BOLD)); | 768 gnt_box_add_widget(GNT_BOX(win),gnt_label_new_with_format(_("Sound Events"),GNT_TEXT_FLAG_BOLD)); |
707 | 769 |
708 pref_dialog->events = tree = gnt_tree_new_with_columns(1); | 770 pref_dialog->events = tree = gnt_tree_new_with_columns(2); |
709 gnt_tree_set_column_titles(GNT_TREE(tree),_("Play"),_("Event")); | 771 gnt_tree_set_hash_fns(GNT_TREE(tree),NULL,NULL,g_free); |
772 gnt_tree_set_column_titles(GNT_TREE(tree),_("Event"),_("File")); | |
710 gnt_tree_set_show_title(GNT_TREE(tree),TRUE); | 773 gnt_tree_set_show_title(GNT_TREE(tree),TRUE); |
711 fprintf(stderr,"got here\n"); | |
712 | 774 |
713 for(i = 0;i < PURPLE_NUM_SOUNDS;i++){ | 775 for(i = 0;i < PURPLE_NUM_SOUNDS;i++){ |
714 const gchar *option = finch_sound_get_event_option(i); | 776 FinchSoundPrefEvent * event = g_new0(FinchSoundPrefEvent,1); |
715 gchar *pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/enabled/%s", | 777 gchar *boolpref; |
716 option); | 778 gchar *filepref; |
717 const gchar *label = finch_sound_get_event_label(i); | 779 |
718 | 780 event->event = &sounds[i]; |
719 gnt_tree_add_choice(GNT_TREE(tree), GINT_TO_POINTER(g_str_hash(option)), | 781 boolpref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/enabled/%s", event->event->pref); |
720 gnt_tree_create_row(GNT_TREE(tree),_(label)), | 782 |
783 filepref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/file/%s", event->event->pref); | |
784 event->file = g_strdup(purple_prefs_get_path(filepref)); | |
785 if(event->event->label == NULL){ | |
786 continue; | |
787 } | |
788 | |
789 gnt_tree_add_choice(GNT_TREE(tree), event, | |
790 gnt_tree_create_row(GNT_TREE(tree),event->event->label,event->file[0] ? g_path_get_basename(event->file) : ""), | |
721 NULL, NULL); | 791 NULL, NULL); |
722 gnt_tree_set_choice(GNT_TREE(tree),GINT_TO_POINTER(g_str_hash(option)),purple_prefs_get_bool(pref)); | 792 gnt_tree_set_choice(GNT_TREE(tree),event,purple_prefs_get_bool(boolpref)); |
723 g_free(pref); | 793 g_free(boolpref); |
724 } | 794 g_free(filepref); |
725 | 795 } |
796 | |
797 gnt_tree_adjust_columns(GNT_TREE(tree)); | |
726 gnt_box_add_widget(GNT_BOX(win),tree); | 798 gnt_box_add_widget(GNT_BOX(win),tree); |
727 | 799 |
728 box = gnt_hbox_new(TRUE); | 800 box = gnt_hbox_new(TRUE); |
729 button = gnt_button_new("Test"); | 801 button = gnt_button_new("Test"); |
802 g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(test_cb),NULL); | |
730 gnt_box_add_widget(GNT_BOX(box),button); | 803 gnt_box_add_widget(GNT_BOX(box),button); |
731 button = gnt_button_new("Reset"); | 804 button = gnt_button_new("Reset"); |
805 g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(reset_cb),NULL); | |
732 gnt_box_add_widget(GNT_BOX(box),button); | 806 gnt_box_add_widget(GNT_BOX(box),button); |
733 button = gnt_button_new("Choose..."); | 807 button = gnt_button_new("Choose..."); |
808 g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(choose_cb),NULL); | |
734 gnt_box_add_widget(GNT_BOX(box),button); | 809 gnt_box_add_widget(GNT_BOX(box),button); |
735 gnt_box_add_widget(GNT_BOX(win),box); | 810 gnt_box_add_widget(GNT_BOX(win),box); |
736 | 811 |
737 box = gnt_hbox_new(TRUE); | 812 box = gnt_hbox_new(TRUE); |
738 gnt_box_set_pad(GNT_BOX(box),0); | 813 gnt_box_set_pad(GNT_BOX(box),0); |
739 gnt_box_set_fill(GNT_BOX(box),TRUE); | 814 gnt_box_set_fill(GNT_BOX(box),TRUE); |
740 button = gnt_button_new("Save"); | 815 button = gnt_button_new("Save"); |
741 g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(save_cb),win); | 816 g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(save_cb),win); |
742 gnt_box_add_widget(GNT_BOX(box),button); | 817 gnt_box_add_widget(GNT_BOX(box),button); |
743 button = gnt_button_new("Cancel"); | 818 button = gnt_button_new("Cancel"); |
744 g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(cancel_cb),win); | 819 g_signal_connect_swapped(G_OBJECT(button),"activate",G_CALLBACK(gnt_widget_destroy),win); |
745 gnt_box_add_widget(GNT_BOX(box),button); | 820 gnt_box_add_widget(GNT_BOX(box),button); |
746 gnt_box_add_widget(GNT_BOX(win),box); | 821 gnt_box_add_widget(GNT_BOX(win),box); |
747 | 822 |
748 | 823 |
749 g_signal_connect(G_OBJECT(win),"destroy",G_CALLBACK(release_pref_dialog),NULL); | 824 g_signal_connect(G_OBJECT(win),"destroy",G_CALLBACK(release_pref_dialog),NULL); |