3 * Finch is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
31 #endif /* USE_GSTREAMER */
42 #include "gntwindow.h"
43 #include "gntcombobox.h"
47 #include "gntwidget.h"
49 #include "gntcheckbox.h"
52 #include "gntfilesel.h"
55 PurpleSoundEventID id
;
65 GntWidget
*conv_focus
;
66 GntWidget
*while_status
;
72 GntWidget
*new_profile
;
73 gchar
* original_profile
;
76 #define DEFAULT_PROFILE "default"
78 static SoundPrefDialog
*pref_dialog
;
80 #define PLAY_SOUND_TIMEOUT 15000
82 static guint mute_login_sounds_timeout
= 0;
83 static gboolean mute_login_sounds
= FALSE
;
86 static gboolean gst_init_failed
;
87 #endif /* USE_GSTREAMER */
89 static FinchSoundEvent sounds
[PURPLE_NUM_SOUNDS
] = {
90 {PURPLE_SOUND_BUDDY_ARRIVE
, N_("Buddy logs in"), "login", "login.wav", NULL
},
91 {PURPLE_SOUND_BUDDY_LEAVE
, N_("Buddy logs out"), "logout", "logout.wav", NULL
},
92 {PURPLE_SOUND_RECEIVE
, N_("Message received"), "im_recv", "receive.wav", NULL
},
93 {PURPLE_SOUND_FIRST_RECEIVE
, N_("Message received begins conversation"), "first_im_recv", "receive.wav", NULL
},
94 {PURPLE_SOUND_SEND
, N_("Message sent"), "send_im", "send.wav", NULL
},
95 {PURPLE_SOUND_CHAT_JOIN
, N_("Person enters chat"), "join_chat", "login.wav", NULL
},
96 {PURPLE_SOUND_CHAT_LEAVE
, N_("Person leaves chat"), "left_chat", "logout.wav", NULL
},
97 {PURPLE_SOUND_CHAT_YOU_SAY
, N_("You talk in chat"), "send_chat_msg", "send.wav", NULL
},
98 {PURPLE_SOUND_CHAT_SAY
, N_("Others talk in chat"), "chat_msg_recv", "receive.wav", NULL
},
99 {PURPLE_SOUND_POUNCE_DEFAULT
, NULL
, "pounce_default", "alert.wav", NULL
},
100 {PURPLE_SOUND_CHAT_NICK
, N_("Someone says your username in chat"), "nick_said", "alert.wav", NULL
},
101 {PURPLE_SOUND_GOT_ATTENTION
, N_("Attention received"), "got_attention", "alert.wav", NULL
}
105 finch_sound_get_active_profile()
107 return purple_prefs_get_string(FINCH_PREFS_ROOT
"/sound/actprofile");
110 /* This method creates a pref name based on the current active profile.
111 * So if "Home" is the current active profile the pref name
112 * [FINCH_PREFS_ROOT "/sound/profiles/Home/$NAME"] is created.
115 make_pref(const char *name
)
117 static char pref_string
[512];
118 g_snprintf(pref_string
, sizeof(pref_string
),
119 FINCH_PREFS_ROOT
"/sound/profiles/%s%s", finch_sound_get_active_profile(), name
);
125 unmute_login_sounds_cb(gpointer data
)
127 mute_login_sounds
= FALSE
;
128 mute_login_sounds_timeout
= 0;
133 chat_nick_matches_name(PurpleChatConversation
*chat
, const char *aname
)
137 gboolean ret
= FALSE
;
138 PurpleAccount
*account
;
143 account
= purple_conversation_get_account(PURPLE_CONVERSATION(chat
));
144 nick
= g_strdup(purple_normalize(account
, purple_chat_conversation_get_nick(chat
)));
145 name
= g_strdup(purple_normalize(account
, aname
));
147 if (g_utf8_collate(nick
, name
) == 0)
157 * play a sound event for a conversation, honoring make_sound flag
158 * of conversation and checking for focus if conv_focus pref is set
161 play_conv_event(PurpleConversation
*conv
, PurpleSoundEventID event
)
163 /* If we should not play the sound for some reason, then exit early */
169 gntconv
= FINCH_CONV(conv
);
171 has_focus
= purple_conversation_has_focus(conv
);
173 if ((gntconv
->flags
& FINCH_CONV_NO_SOUND
) ||
174 (has_focus
&& !purple_prefs_get_bool(make_pref("/conv_focus"))))
180 purple_sound_play_event(event
, conv
? purple_conversation_get_account(conv
) : NULL
);
184 buddy_state_cb(PurpleBuddy
*buddy
, PurpleSoundEventID event
)
186 purple_sound_play_event(event
, purple_buddy_get_account(buddy
));
190 im_msg_received_cb(PurpleAccount
*account
, char *sender
,
191 char *message
, PurpleConversation
*conv
,
192 PurpleMessageFlags flags
, PurpleSoundEventID event
)
194 if (flags
& PURPLE_MESSAGE_DELAYED
)
198 purple_sound_play_event(PURPLE_SOUND_FIRST_RECEIVE
, account
);
200 play_conv_event(conv
, event
);
205 im_msg_sent_cb(PurpleAccount
*account
, PurpleMessage
*msg
,
206 PurpleSoundEventID event
)
208 PurpleIMConversation
*im
= purple_conversations_find_im_with_account(
209 purple_message_get_recipient(msg
), account
);
210 play_conv_event(PURPLE_CONVERSATION(im
), event
);
214 chat_user_join_cb(PurpleChatConversation
*chat
, const char *name
,
215 PurpleChatUserFlags flags
, gboolean new_arrival
,
216 PurpleSoundEventID event
)
218 if (new_arrival
&& !chat_nick_matches_name(chat
, name
))
219 play_conv_event(PURPLE_CONVERSATION(chat
), event
);
223 chat_user_left_cb(PurpleChatConversation
*chat
, const char *name
,
224 const char *reason
, PurpleSoundEventID event
)
226 if (!chat_nick_matches_name(chat
, name
))
227 play_conv_event(PURPLE_CONVERSATION(chat
), event
);
231 chat_msg_sent_cb(PurpleAccount
*account
, PurpleMessage
*msg
, int id
,
232 PurpleSoundEventID event
)
234 PurpleConnection
*conn
= purple_account_get_connection(account
);
235 PurpleChatConversation
*chat
= NULL
;
238 chat
= purple_conversations_find_chat(conn
, id
);
240 play_conv_event(PURPLE_CONVERSATION(chat
), event
);
244 chat_msg_received_cb(PurpleAccount
*account
, char *sender
,
245 char *message
, PurpleChatConversation
*chat
,
246 PurpleMessageFlags flags
, PurpleSoundEventID event
)
248 if (flags
& PURPLE_MESSAGE_DELAYED
)
251 g_return_if_fail(chat
!= NULL
);
253 if (purple_chat_conversation_is_ignored_user(chat
, sender
))
256 if (chat_nick_matches_name(chat
, sender
))
259 if (flags
& PURPLE_MESSAGE_NICK
|| purple_utf8_has_word(message
, purple_chat_conversation_get_nick(chat
)))
260 play_conv_event(PURPLE_CONVERSATION(chat
), PURPLE_SOUND_CHAT_NICK
);
262 play_conv_event(PURPLE_CONVERSATION(chat
), event
);
266 got_attention_cb(PurpleAccount
*account
, const char *who
,
267 PurpleConversation
*conv
, guint type
, PurpleSoundEventID event
)
269 play_conv_event(conv
, event
);
274 * We mute sounds for the 10 seconds after you log in so that
275 * you don't get flooded with sounds when the blist shows all
276 * your buddies logging in.
279 account_signon_cb(PurpleConnection
*gc
, gpointer data
)
281 if (mute_login_sounds_timeout
!= 0)
282 g_source_remove(mute_login_sounds_timeout
);
283 mute_login_sounds
= TRUE
;
284 mute_login_sounds_timeout
= purple_timeout_add_seconds(10, unmute_login_sounds_cb
, NULL
);
288 finch_sound_get_handle(void)
296 /* This gets called when the active profile changes */
298 initialize_profile(const char *name
, PurplePrefType type
, gconstpointer val
, gpointer null
)
300 FinchSoundEvent
*event
;
301 if (purple_prefs_exists(make_pref("")))
304 purple_prefs_add_none(make_pref(""));
305 purple_prefs_add_none(make_pref("/enabled"));
306 purple_prefs_add_none(make_pref("/file"));
308 for (event
= sounds
; event
- sounds
< PURPLE_NUM_SOUNDS
; event
++) {
310 g_snprintf(pref
, sizeof(pref
), "/enabled/%s", event
->pref
);
311 purple_prefs_add_bool(make_pref(pref
), FALSE
);
312 g_snprintf(pref
, sizeof(pref
), "/file/%s", event
->pref
);
313 purple_prefs_add_path(make_pref(pref
), "");
316 purple_prefs_add_bool(make_pref("/conv_focus"), FALSE
);
317 purple_prefs_add_bool(make_pref("/mute"), FALSE
);
318 purple_prefs_add_path(make_pref("/command"), "");
319 purple_prefs_add_string(make_pref("/method"), "automatic");
323 update_profiles(void)
325 GList
*list
= finch_sound_get_profiles();
326 for (; list
; list
= g_list_delete_link(list
, list
)) {
329 /* got_attention was added in libpurple 2.7.0 */
330 g_snprintf(pname
, sizeof(pname
), FINCH_PREFS_ROOT
"/sound/profiles/%s%s",
331 (char *)list
->data
, "/enabled/got_attention");
332 purple_prefs_add_bool(pname
, FALSE
);
333 g_snprintf(pname
, sizeof(pname
), FINCH_PREFS_ROOT
"/sound/profiles/%s%s",
334 (char *)list
->data
, "/file/got_attention");
335 purple_prefs_add_path(pname
, "");
342 finch_sound_init(void)
344 void *gnt_sound_handle
= finch_sound_get_handle();
345 void *blist_handle
= purple_blist_get_handle();
346 void *conv_handle
= purple_conversations_get_handle();
348 GError
*error
= NULL
;
351 purple_signal_connect(purple_connections_get_handle(), "signed-on",
352 gnt_sound_handle
, PURPLE_CALLBACK(account_signon_cb
),
355 purple_prefs_add_none(FINCH_PREFS_ROOT
"/sound");
356 purple_prefs_add_string(FINCH_PREFS_ROOT
"/sound/actprofile", DEFAULT_PROFILE
);
357 purple_prefs_add_none(FINCH_PREFS_ROOT
"/sound/profiles");
359 purple_prefs_connect_callback(gnt_sound_handle
, FINCH_PREFS_ROOT
"/sound/actprofile", initialize_profile
, NULL
);
360 purple_prefs_trigger_callback(FINCH_PREFS_ROOT
"/sound/actprofile");
364 purple_debug_info("sound", "Initializing sound output drivers.\n");
365 #if (GST_VERSION_MAJOR > 0 || \
366 (GST_VERSION_MAJOR == 0 && GST_VERSION_MINOR > 10) || \
367 (GST_VERSION_MAJOR == 0 && GST_VERSION_MINOR == 10 && GST_VERSION_MICRO >= 10))
368 gst_registry_fork_set_enabled(FALSE
);
370 if ((gst_init_failed
= !gst_init_check(NULL
, NULL
, &error
))) {
371 purple_notify_error(NULL
, _("GStreamer Failure"),
372 _("GStreamer failed to initialize."),
373 error
? error
->message
: "", NULL
);
379 #endif /* USE_GSTREAMER */
381 purple_signal_connect(blist_handle
, "buddy-signed-on",
382 gnt_sound_handle
, PURPLE_CALLBACK(buddy_state_cb
),
383 GINT_TO_POINTER(PURPLE_SOUND_BUDDY_ARRIVE
));
384 purple_signal_connect(blist_handle
, "buddy-signed-off",
385 gnt_sound_handle
, PURPLE_CALLBACK(buddy_state_cb
),
386 GINT_TO_POINTER(PURPLE_SOUND_BUDDY_LEAVE
));
387 purple_signal_connect(conv_handle
, "received-im-msg",
388 gnt_sound_handle
, PURPLE_CALLBACK(im_msg_received_cb
),
389 GINT_TO_POINTER(PURPLE_SOUND_RECEIVE
));
390 purple_signal_connect(conv_handle
, "sent-im-msg",
391 gnt_sound_handle
, PURPLE_CALLBACK(im_msg_sent_cb
),
392 GINT_TO_POINTER(PURPLE_SOUND_SEND
));
393 purple_signal_connect(conv_handle
, "chat-user-joined",
394 gnt_sound_handle
, PURPLE_CALLBACK(chat_user_join_cb
),
395 GINT_TO_POINTER(PURPLE_SOUND_CHAT_JOIN
));
396 purple_signal_connect(conv_handle
, "chat-user-left",
397 gnt_sound_handle
, PURPLE_CALLBACK(chat_user_left_cb
),
398 GINT_TO_POINTER(PURPLE_SOUND_CHAT_LEAVE
));
399 purple_signal_connect(conv_handle
, "sent-chat-msg",
400 gnt_sound_handle
, PURPLE_CALLBACK(chat_msg_sent_cb
),
401 GINT_TO_POINTER(PURPLE_SOUND_CHAT_YOU_SAY
));
402 purple_signal_connect(conv_handle
, "received-chat-msg",
403 gnt_sound_handle
, PURPLE_CALLBACK(chat_msg_received_cb
),
404 GINT_TO_POINTER(PURPLE_SOUND_CHAT_SAY
));
405 purple_signal_connect(conv_handle
, "got-attention",
406 gnt_sound_handle
, PURPLE_CALLBACK(got_attention_cb
),
407 GINT_TO_POINTER(PURPLE_SOUND_GOT_ATTENTION
));
413 finch_sound_uninit(void)
416 if (!gst_init_failed
)
420 purple_signals_disconnect_by_handle(finch_sound_get_handle());
423 #if defined(USE_GSTREAMER) && !defined(_WIN32)
425 bus_call (GstBus
*bus
, GstMessage
*msg
, gpointer data
)
427 GstElement
*play
= data
;
430 switch (GST_MESSAGE_TYPE (msg
)) {
431 case GST_MESSAGE_ERROR
:
432 gst_message_parse_error(msg
, &err
, NULL
);
433 purple_debug_error("gstreamer", "%s\n", err
->message
);
435 /* fall-through and clean up */
436 case GST_MESSAGE_EOS
:
437 gst_element_set_state(play
, GST_STATE_NULL
);
438 gst_object_unref(GST_OBJECT(play
));
441 case GST_MESSAGE_WARNING
:
442 gst_message_parse_warning(msg
, &err
, NULL
);
443 purple_debug_warning("gstreamer", "%s\n", err
->message
);
454 finch_sound_play_file(const char *filename
)
457 #if defined(USE_GSTREAMER) && !defined(_WIN32)
459 GstElement
*sink
= NULL
;
460 GstElement
*play
= NULL
;
463 if (purple_prefs_get_bool(make_pref("/mute")))
466 method
= purple_prefs_get_string(make_pref("/method"));
468 if (!strcmp(method
, "nosound")) {
470 } else if (!strcmp(method
, "beep")) {
475 if (!g_file_test(filename
, G_FILE_TEST_EXISTS
)) {
476 purple_debug_error("gntsound", "sound file (%s) does not exist.\n", filename
);
481 if (!strcmp(method
, "custom")) {
482 const char *sound_cmd
;
485 GError
*error
= NULL
;
487 sound_cmd
= purple_prefs_get_path(make_pref("/command"));
489 if (!sound_cmd
|| *sound_cmd
== '\0') {
490 purple_debug_error("gntsound",
491 "'Command' sound method has been chosen, "
492 "but no command has been set.");
496 esc_filename
= g_shell_quote(filename
);
498 if (strstr(sound_cmd
, "%s"))
499 command
= purple_strreplace(sound_cmd
, "%s", esc_filename
);
501 command
= g_strdup_printf("%s %s", sound_cmd
, esc_filename
);
503 if (!g_spawn_command_line_async(command
, &error
)) {
504 purple_debug_error("gntsound", "sound command could not be launched: %s\n", error
->message
);
508 g_free(esc_filename
);
513 if (gst_init_failed
) /* Perhaps do beep instead? */
515 if (!strcmp(method
, "automatic")) {
516 if (purple_running_gnome()) {
517 sink
= gst_element_factory_make("gconfaudiosink", "sink");
520 sink
= gst_element_factory_make("autoaudiosink", "sink");
522 purple_debug_error("sound", "Unable to create GStreamer audiosink.\n");
525 } else if (!strcmp(method
, "esd")) {
526 sink
= gst_element_factory_make("esdsink", "sink");
528 purple_debug_error("sound", "Unable to create GStreamer audiosink.\n");
531 } else if (!strcmp(method
, "alsa")) {
532 sink
= gst_element_factory_make("alsasink", "sink");
534 purple_debug_error("sound", "Unable to create GStreamer audiosink.\n");
538 purple_debug_error("sound", "Unknown sound method '%s'\n", method
);
542 play
= gst_element_factory_make("playbin", "play");
548 uri
= g_strdup_printf("file://%s", filename
);
550 g_object_set(G_OBJECT(play
), "uri", uri
,
551 "audio-sink", sink
, NULL
);
553 bus
= gst_pipeline_get_bus(GST_PIPELINE(play
));
554 gst_bus_add_watch(bus
, bus_call
, play
);
556 gst_element_set_state(play
, GST_STATE_PLAYING
);
558 gst_object_unref(bus
);
561 #else /* USE_GSTREAMER */
564 #endif /* USE_GSTREAMER */
566 purple_debug_info("sound", "Playing %s\n", filename
);
569 wchar_t *wc_filename
= g_utf8_to_utf16(filename
,
570 -1, NULL
, NULL
, NULL
);
571 if (!PlaySoundW(wc_filename
, NULL
, SND_ASYNC
| SND_FILENAME
))
572 purple_debug(PURPLE_DEBUG_ERROR
, "sound", "Error playing sound.\n");
579 finch_sound_play_event(PurpleSoundEventID event
)
583 if ((event
== PURPLE_SOUND_BUDDY_ARRIVE
) && mute_login_sounds
)
586 if (event
>= PURPLE_NUM_SOUNDS
||
587 event
>= G_N_ELEMENTS(sounds
)) {
588 purple_debug_error("sound", "got request for unknown sound: %d\n", event
);
592 enable_pref
= g_strdup_printf(FINCH_PREFS_ROOT
"/sound/profiles/%s/enabled/%s",
593 finch_sound_get_active_profile(),
595 file_pref
= g_strdup_printf(FINCH_PREFS_ROOT
"/sound/profiles/%s/file/%s", finch_sound_get_active_profile(), sounds
[event
].pref
);
597 /* check NULL for sounds that don't have an option, ie buddy pounce */
598 if (purple_prefs_get_bool(enable_pref
)) {
599 char *filename
= g_strdup(purple_prefs_get_path(file_pref
));
600 if (!filename
|| *filename
== '\0') {
602 filename
= g_build_filename(PURPLE_DATADIR
,
603 "sounds", "purple", sounds
[event
].def
, NULL
);
606 purple_sound_play_file(filename
, NULL
);
615 finch_sound_get_profiles()
617 GList
*list
= NULL
, *iter
;
618 iter
= purple_prefs_get_children_names(FINCH_PREFS_ROOT
"/sound/profiles");
620 list
= g_list_append(list
, g_strdup(strrchr(iter
->data
, '/') + 1));
622 iter
= g_list_delete_link(iter
, iter
);
627 /* This will also create it if it doesn't exist */
629 finch_sound_set_active_profile(const char *name
)
631 purple_prefs_set_string(FINCH_PREFS_ROOT
"/sound/actprofile", name
);
635 finch_sound_profile_exists(const char *name
)
638 gboolean ret
= purple_prefs_exists(tmp
= g_strdup_printf(FINCH_PREFS_ROOT
"/sound/profiles/%s", name
));
644 save_cb(GntWidget
*button
, gpointer win
)
648 purple_prefs_set_string(make_pref("/method"), gnt_combo_box_get_selected_data(GNT_COMBO_BOX(pref_dialog
->method
)));
649 purple_prefs_set_path(make_pref("/command"), gnt_entry_get_text(GNT_ENTRY(pref_dialog
->command
)));
650 purple_prefs_set_bool(make_pref("/conv_focus"), gnt_check_box_get_checked(GNT_CHECK_BOX(pref_dialog
->conv_focus
)));
651 purple_prefs_set_int("/purple/sound/while_status", GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(pref_dialog
->while_status
))));
653 for (itr
= gnt_tree_get_rows(GNT_TREE(pref_dialog
->events
)); itr
; itr
= itr
->next
) {
654 FinchSoundEvent
* event
= &sounds
[GPOINTER_TO_INT(itr
->data
)];
655 char * filepref
= g_strdup_printf(FINCH_PREFS_ROOT
"/sound/profiles/%s/file/%s", finch_sound_get_active_profile(), event
->pref
);
656 char * boolpref
= g_strdup_printf(FINCH_PREFS_ROOT
"/sound/profiles/%s/enabled/%s", finch_sound_get_active_profile(), event
->pref
);
657 purple_prefs_set_bool(boolpref
, gnt_tree_get_choice(GNT_TREE(pref_dialog
->events
), itr
->data
));
658 purple_prefs_set_path(filepref
, event
->file
? event
->file
: "");
662 gnt_widget_destroy(GNT_WIDGET(win
));
666 file_cb(GntFileSel
*w
, const char *path
, const char *file
, gpointer data
)
668 FinchSoundEvent
*event
= data
;
671 event
->file
= g_strdup(path
);
673 gnt_tree_change_text(GNT_TREE(pref_dialog
->events
), GINT_TO_POINTER(event
->id
), 1, file
);
674 gnt_tree_set_choice(GNT_TREE(pref_dialog
->events
), GINT_TO_POINTER(event
->id
), TRUE
);
676 gnt_widget_destroy(GNT_WIDGET(w
));
680 test_cb(GntWidget
*button
, gpointer null
)
682 PurpleSoundEventID id
= GPOINTER_TO_INT(gnt_tree_get_selection_data(GNT_TREE(pref_dialog
->events
)));
683 FinchSoundEvent
* event
= &sounds
[id
];
684 char *enabled
, *file
, *tmpfile
;
687 enabled
= g_strdup_printf(FINCH_PREFS_ROOT
"/sound/profiles/%s/enabled/%s",
688 finch_sound_get_active_profile(), event
->pref
);
689 file
= g_strdup_printf(FINCH_PREFS_ROOT
"/sound/profiles/%s/file/%s",
690 finch_sound_get_active_profile(), event
->pref
);
692 temp_value
= purple_prefs_get_bool(enabled
);
693 tmpfile
= g_strdup(purple_prefs_get_path(file
));
695 purple_prefs_set_path(file
, event
->file
);
696 if (!temp_value
) purple_prefs_set_bool(enabled
, TRUE
);
698 purple_sound_play_event(id
, NULL
);
700 if (!temp_value
) purple_prefs_set_bool(enabled
, FALSE
);
701 purple_prefs_set_path(file
, tmpfile
);
709 reset_cb(GntWidget
*button
, gpointer null
)
711 /* Don't dereference this pointer ! */
712 gpointer key
= gnt_tree_get_selection_data(GNT_TREE(pref_dialog
->events
));
714 FinchSoundEvent
* event
= &sounds
[GPOINTER_TO_INT(key
)];
717 gnt_tree_change_text(GNT_TREE(pref_dialog
->events
), key
, 1, _("(default)"));
722 choose_cb(GntWidget
*button
, gpointer null
)
724 GntWidget
*w
= gnt_file_sel_new();
725 GntFileSel
*sel
= GNT_FILE_SEL(w
);
726 PurpleSoundEventID id
= GPOINTER_TO_INT(gnt_tree_get_selection_data(GNT_TREE(pref_dialog
->events
)));
727 FinchSoundEvent
* event
= &sounds
[id
];
730 gnt_box_set_title(GNT_BOX(w
), _("Select Sound File ..."));
731 gnt_file_sel_set_current_location(sel
,
732 (event
&& event
->file
) ? (path
= g_path_get_dirname(event
->file
))
733 : purple_home_dir());
735 g_signal_connect_swapped(G_OBJECT(sel
->cancel
), "activate", G_CALLBACK(gnt_widget_destroy
), sel
);
736 g_signal_connect(G_OBJECT(sel
), "file_selected", G_CALLBACK(file_cb
), event
);
737 g_signal_connect_swapped(G_OBJECT(sel
), "destroy", G_CALLBACK(g_nullify_pointer
), &pref_dialog
->selector
);
739 /* If there's an already open file-selector, close that one. */
740 if (pref_dialog
->selector
)
741 gnt_widget_destroy(pref_dialog
->selector
);
743 pref_dialog
->selector
= w
;
750 release_pref_dialog(GntBindable
*data
, gpointer null
)
753 for (itr
= gnt_tree_get_rows(GNT_TREE(pref_dialog
->events
)); itr
; itr
= itr
->next
) {
754 PurpleSoundEventID id
= GPOINTER_TO_INT(itr
->data
);
755 FinchSoundEvent
* e
= &sounds
[id
];
759 if (pref_dialog
->selector
)
760 gnt_widget_destroy(pref_dialog
->selector
);
761 g_free(pref_dialog
->original_profile
);
767 load_pref_window(const char * profile
)
771 finch_sound_set_active_profile(profile
);
773 gnt_combo_box_set_selected(GNT_COMBO_BOX(pref_dialog
->method
), (gchar
*)purple_prefs_get_string(make_pref("/method")));
775 gnt_entry_set_text(GNT_ENTRY(pref_dialog
->command
), purple_prefs_get_path(make_pref("/command")));
777 gnt_check_box_set_checked(GNT_CHECK_BOX(pref_dialog
->conv_focus
), purple_prefs_get_bool(make_pref("/conv_focus")));
779 gnt_combo_box_set_selected(GNT_COMBO_BOX(pref_dialog
->while_status
), GINT_TO_POINTER(purple_prefs_get_int("/purple" "/sound/while_status")));
781 for (i
= 0; i
< PURPLE_NUM_SOUNDS
; i
++) {
782 FinchSoundEvent
* event
= &sounds
[i
];
784 gchar
*filepref
, *basename
= NULL
;
785 const char * profile
= finch_sound_get_active_profile();
787 filepref
= g_strdup_printf(FINCH_PREFS_ROOT
"/sound/profiles/%s/file/%s", profile
, event
->pref
);
790 event
->file
= g_strdup(purple_prefs_get_path(filepref
));
793 if (event
->label
== NULL
) {
797 boolpref
= g_strdup_printf(FINCH_PREFS_ROOT
"/sound/profiles/%s/enabled/%s", profile
, event
->pref
);
799 gnt_tree_change_text(GNT_TREE(pref_dialog
->events
), GINT_TO_POINTER(i
), 0, event
->label
);
800 gnt_tree_change_text(GNT_TREE(pref_dialog
->events
), GINT_TO_POINTER(i
), 1,
801 event
->file
[0] ? (basename
= g_path_get_basename(event
->file
)) : _("(default)"));
804 gnt_tree_set_choice(GNT_TREE(pref_dialog
->events
), GINT_TO_POINTER(i
), purple_prefs_get_bool(boolpref
));
809 gnt_tree_set_selected(GNT_TREE(pref_dialog
->profiles
), (gchar
*)finch_sound_get_active_profile());
811 gnt_widget_draw(pref_dialog
->window
);
815 reload_pref_window(const char *profile
)
817 if (!strcmp(profile
, finch_sound_get_active_profile()))
819 load_pref_window(profile
);
823 prof_del_cb(GntWidget
*button
, gpointer null
)
825 const char * profile
= gnt_entry_get_text(GNT_ENTRY(pref_dialog
->new_profile
));
828 if (!strcmp(profile
, DEFAULT_PROFILE
))
831 pref
= g_strdup_printf(FINCH_PREFS_ROOT
"/sound/profiles/%s", profile
);
832 purple_prefs_remove(pref
);
835 if (!strcmp(pref_dialog
->original_profile
, profile
)) {
836 g_free(pref_dialog
->original_profile
);
837 pref_dialog
->original_profile
= g_strdup(DEFAULT_PROFILE
);
840 if(!strcmp(profile
, finch_sound_get_active_profile()))
841 reload_pref_window(DEFAULT_PROFILE
);
843 gnt_tree_remove(GNT_TREE(pref_dialog
->profiles
), (gchar
*) profile
);
847 prof_add_cb(GntButton
*button
, GntEntry
* entry
)
849 const char * profile
= gnt_entry_get_text(entry
);
851 if (!finch_sound_profile_exists(profile
)) {
852 gpointer key
= g_strdup(profile
);
853 row
= gnt_tree_create_row(GNT_TREE(pref_dialog
->profiles
), profile
);
854 gnt_tree_add_row_after(GNT_TREE(pref_dialog
->profiles
), key
,
857 gnt_entry_set_text(entry
, "");
858 gnt_tree_set_selected(GNT_TREE(pref_dialog
->profiles
), key
);
859 finch_sound_set_active_profile(key
);
861 reload_pref_window(profile
);
865 prof_load_cb(GntTree
*tree
, gpointer oldkey
, gpointer newkey
, gpointer null
)
867 reload_pref_window(newkey
);
871 cancel_cb(GntButton
*button
, gpointer win
)
873 finch_sound_set_active_profile(pref_dialog
->original_profile
);
874 gnt_widget_destroy(GNT_WIDGET(win
));
878 finch_sounds_show_all(void)
880 GntWidget
*box
, *tmpbox
, *splitbox
, *cmbox
;
892 gnt_window_present(pref_dialog
->window
);
896 pref_dialog
= g_new0(SoundPrefDialog
, 1);
898 pref_dialog
->original_profile
= g_strdup(finch_sound_get_active_profile());
900 pref_dialog
->window
= win
= gnt_window_box_new(FALSE
, TRUE
);
901 gnt_box_set_pad(GNT_BOX(win
), 0);
902 gnt_box_set_toplevel(GNT_BOX(win
), TRUE
);
903 gnt_box_set_title(GNT_BOX(win
), _("Sound Preferences"));
904 gnt_box_set_fill(GNT_BOX(win
), TRUE
);
905 gnt_box_set_alignment(GNT_BOX(win
), GNT_ALIGN_MID
);
908 splitbox
= gnt_hbox_new(FALSE
);
909 gnt_box_set_pad(GNT_BOX(splitbox
), 0);
910 gnt_box_set_alignment(GNT_BOX(splitbox
), GNT_ALIGN_TOP
);
912 box
= gnt_vbox_new(FALSE
);
913 gnt_box_set_pad(GNT_BOX(box
), 0);
914 gnt_box_add_widget(GNT_BOX(box
), gnt_label_new_with_format(_("Profiles"), GNT_TEXT_FLAG_BOLD
));
915 pref_dialog
->profiles
= tree
= gnt_tree_new();
916 gnt_tree_set_hash_fns(GNT_TREE(tree
), g_str_hash
, g_str_equal
, g_free
);
917 gnt_tree_set_compare_func(GNT_TREE(tree
), (GCompareFunc
)g_ascii_strcasecmp
);
918 g_signal_connect(G_OBJECT(tree
), "selection-changed", G_CALLBACK(prof_load_cb
), NULL
);
920 itr
= list
= finch_sound_get_profiles();
921 for (; itr
; itr
= itr
->next
) {
922 /* Do not free itr->data. It's the stored as a key for the tree, and will
923 * be freed when the tree is destroyed. */
924 gnt_tree_add_row_after(GNT_TREE(tree
), itr
->data
,
925 gnt_tree_create_row(GNT_TREE(tree
), itr
->data
), NULL
, NULL
);
929 gnt_box_add_widget(GNT_BOX(box
), tree
);
931 pref_dialog
->new_profile
= entry
= gnt_entry_new("");
932 gnt_box_add_widget(GNT_BOX(box
), entry
);
934 tmpbox
= gnt_hbox_new(FALSE
);
935 button
= gnt_button_new("Add");
936 g_signal_connect(G_OBJECT(button
), "activate", G_CALLBACK(prof_add_cb
), entry
);
937 gnt_box_add_widget(GNT_BOX(tmpbox
), button
);
938 button
= gnt_button_new("Delete");
939 g_signal_connect(G_OBJECT(button
), "activate", G_CALLBACK(prof_del_cb
), NULL
);
940 gnt_box_add_widget(GNT_BOX(tmpbox
), button
);
941 gnt_box_add_widget(GNT_BOX(box
), tmpbox
);
942 gnt_box_add_widget(GNT_BOX(splitbox
), box
);
944 gnt_box_add_widget(GNT_BOX(splitbox
), gnt_vline_new());
948 box
= gnt_vbox_new(FALSE
);
949 gnt_box_set_pad(GNT_BOX(box
), 0);
951 pref_dialog
->method
= cmbox
= gnt_combo_box_new();
952 gnt_tree_set_hash_fns(GNT_TREE(GNT_COMBO_BOX(cmbox
)->dropdown
), g_str_hash
, g_str_equal
, NULL
);
953 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox
), "automatic", _("Automatic"));
954 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox
), "alsa", "ALSA");
955 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox
), "esd", "ESD");
956 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox
), "beep", _("Console Beep"));
957 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox
), "custom", _("Command"));
958 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox
), "nosound", _("No Sound"));
960 label
= gnt_label_new_with_format(_("Sound Method"), GNT_TEXT_FLAG_BOLD
);
961 gnt_box_add_widget(GNT_BOX(box
), label
);
962 tmpbox
= gnt_hbox_new(TRUE
);
963 gnt_box_set_fill(GNT_BOX(tmpbox
), FALSE
);
964 gnt_box_set_pad(GNT_BOX(tmpbox
), 0);
965 gnt_box_add_widget(GNT_BOX(tmpbox
), gnt_label_new(_("Method: ")));
966 gnt_box_add_widget(GNT_BOX(tmpbox
), cmbox
);
967 gnt_box_add_widget(GNT_BOX(box
), tmpbox
);
969 tmpbox
= gnt_hbox_new(TRUE
);
970 gnt_box_set_pad(GNT_BOX(tmpbox
), 0);
971 gnt_box_set_fill(GNT_BOX(tmpbox
), FALSE
);
972 gnt_box_add_widget(GNT_BOX(tmpbox
), gnt_label_new(_("Sound Command\n(%s for filename)")));
973 pref_dialog
->command
= entry
= gnt_entry_new("");
974 gnt_box_add_widget(GNT_BOX(tmpbox
), entry
);
975 gnt_box_add_widget(GNT_BOX(box
), tmpbox
);
977 gnt_box_add_widget(GNT_BOX(box
), gnt_line_new(FALSE
));
980 gnt_box_add_widget(GNT_BOX(box
), gnt_label_new_with_format(_("Sound Options"), GNT_TEXT_FLAG_BOLD
));
981 pref_dialog
->conv_focus
= chkbox
= gnt_check_box_new(_("Sounds when conversation has focus"));
982 gnt_box_add_widget(GNT_BOX(box
), chkbox
);
984 tmpbox
= gnt_hbox_new(TRUE
);
985 gnt_box_set_pad(GNT_BOX(tmpbox
), 0);
986 gnt_box_set_fill(GNT_BOX(tmpbox
), FALSE
);
987 gnt_box_add_widget(GNT_BOX(tmpbox
), gnt_label_new("Enable Sounds:"));
988 pref_dialog
->while_status
= cmbox
= gnt_combo_box_new();
989 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox
), GINT_TO_POINTER(3), _("Always"));
990 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox
), GINT_TO_POINTER(1), _("Only when available"));
991 gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox
), GINT_TO_POINTER(2), _("Only when not available"));
992 gnt_box_add_widget(GNT_BOX(tmpbox
), cmbox
);
993 gnt_box_add_widget(GNT_BOX(box
), tmpbox
);
995 gnt_box_add_widget(GNT_BOX(splitbox
), box
);
997 gnt_box_add_widget(GNT_BOX(win
), splitbox
);
999 gnt_box_add_widget(GNT_BOX(win
), gnt_hline_new());
1002 gnt_box_add_widget(GNT_BOX(win
), gnt_label_new_with_format(_("Sound Events"), GNT_TEXT_FLAG_BOLD
));
1003 pref_dialog
->events
= tree
= gnt_tree_new_with_columns(2);
1004 gnt_tree_set_column_titles(GNT_TREE(tree
), _("Event"), _("File"));
1005 gnt_tree_set_show_title(GNT_TREE(tree
), TRUE
);
1007 for (i
= 0; i
< PURPLE_NUM_SOUNDS
; i
++) {
1008 FinchSoundEvent
* event
= &sounds
[i
];
1010 if (event
->label
== NULL
) {
1014 gnt_tree_add_choice(GNT_TREE(tree
), GINT_TO_POINTER(i
),
1015 gnt_tree_create_row(GNT_TREE(tree
), event
->label
, event
->def
),
1019 gnt_tree_adjust_columns(GNT_TREE(tree
));
1020 gnt_box_add_widget(GNT_BOX(win
), tree
);
1022 box
= gnt_hbox_new(FALSE
);
1023 button
= gnt_button_new(_("Test"));
1024 g_signal_connect(G_OBJECT(button
), "activate", G_CALLBACK(test_cb
), NULL
);
1025 gnt_box_add_widget(GNT_BOX(box
), button
);
1026 button
= gnt_button_new(_("Reset"));
1027 g_signal_connect(G_OBJECT(button
), "activate", G_CALLBACK(reset_cb
), NULL
);
1028 gnt_box_add_widget(GNT_BOX(box
), button
);
1029 button
= gnt_button_new(_("Choose..."));
1030 g_signal_connect(G_OBJECT(button
), "activate", G_CALLBACK(choose_cb
), NULL
);
1031 gnt_box_add_widget(GNT_BOX(box
), button
);
1032 gnt_box_add_widget(GNT_BOX(win
), box
);
1034 gnt_box_add_widget(GNT_BOX(win
), gnt_line_new(FALSE
));
1036 /* Add new stuff before this */
1037 box
= gnt_hbox_new(FALSE
);
1038 gnt_box_set_fill(GNT_BOX(box
), TRUE
);
1039 button
= gnt_button_new(_("Save"));
1040 g_signal_connect(G_OBJECT(button
), "activate", G_CALLBACK(save_cb
), win
);
1041 gnt_box_add_widget(GNT_BOX(box
), button
);
1042 button
= gnt_button_new(_("Cancel"));
1043 g_signal_connect(G_OBJECT(button
), "activate", G_CALLBACK(cancel_cb
), win
);
1044 gnt_box_add_widget(GNT_BOX(box
), button
);
1045 gnt_box_add_widget(GNT_BOX(win
), box
);
1047 g_signal_connect(G_OBJECT(win
), "destroy", G_CALLBACK(release_pref_dialog
), NULL
);
1049 load_pref_window(finch_sound_get_active_profile());
1051 gnt_widget_show(win
);
1054 gboolean
finch_sound_is_enabled(void)
1056 const char *pref
= make_pref("/method");
1057 const char *method
= purple_prefs_get_string(pref
);
1061 if (strcmp(method
, "nosound") == 0)
1067 static PurpleSoundUiOps sound_ui_ops
=
1071 finch_sound_play_file
,
1072 finch_sound_play_event
,
1080 finch_sound_get_ui_ops(void)
1082 return &sound_ui_ops
;