Wed, 11 Jul 2007 19:40:49 +0000
Cleaned up a few missing NULL checks in GntWM
Put a few comments about a warning and other potential NULL checks missing.
| 18155 | 1 | /** |
| 2 | * @file gntsound.c GNT Sound API | |
| 3 | * @ingroup finch | |
| 4 | * | |
| 5 | * finch | |
| 6 | * | |
| 7 | * Finch is the legal property of its developers, whose names are too numerous | |
| 8 | * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 9 | * source distribution. | |
| 10 | * | |
| 11 | * This program is free software; you can redistribute it and/or modify | |
| 12 | * it under the terms of the GNU General Public License as published by | |
| 13 | * the Free Software Foundation; either version 2 of the License, or | |
| 14 | * (at your option) any later version. | |
| 15 | * | |
| 16 | * This program is distributed in the hope that it will be useful, | |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 | * GNU General Public License for more details. | |
| 20 | * | |
| 21 | * You should have received a copy of the GNU General Public License | |
| 22 | * along with this program; if not, write to the Free Software | |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 24 | */ | |
| 25 | #include "internal.h" | |
| 26 | #include "finch.h" | |
| 27 | ||
| 28 | #ifdef _WIN32 | |
| 29 | #include <windows.h> | |
| 30 | #include <mmsystem.h> | |
| 31 | #endif | |
| 32 | ||
| 33 | #ifdef USE_GSTREAMER | |
| 34 | #include <gst/gst.h> | |
| 35 | #endif /* USE_GSTREAMER */ | |
| 36 | ||
| 37 | #include "debug.h" | |
| 38 | #include "notify.h" | |
| 39 | #include "prefs.h" | |
| 40 | #include "sound.h" | |
| 41 | #include "util.h" | |
| 42 | ||
|
18294
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
43 | #include "gntbox.h" |
|
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
44 | #include "gntwindow.h" |
|
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
45 | #include "gntcombobox.h" |
|
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
46 | #include "gntlabel.h" |
| 18155 | 47 | #include "gntconv.h" |
| 48 | #include "gntsound.h" | |
|
18294
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
49 | #include "gntwidget.h" |
|
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
50 | #include "gntentry.h" |
|
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
51 | #include "gntcheckbox.h" |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
52 | #include "gntline.h" |
|
18432
8fd3963b9ce0
Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents:
18296
diff
changeset
|
53 | #include "gntslider.h" |
|
18439
5b6c9a328910
Fixed Cancel button callback
Eric Polino <aluink@pidgin.im>
parents:
18438
diff
changeset
|
54 | #include "gnttree.h" |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
55 | #include "gntfilesel.h" |
| 18155 | 56 | |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
57 | typedef struct { |
|
18678
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
58 | PurpleSoundEventID id; |
| 18155 | 59 | char *label; |
| 60 | char *pref; | |
| 61 | char *def; | |
|
18616
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
62 | char *file; |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
63 | } FinchSoundEvent; |
| 18155 | 64 | |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
65 | typedef struct { |
|
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
66 | GntWidget *method; |
|
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
67 | GntWidget *command; |
|
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
68 | GntWidget *conv_focus; |
|
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
69 | GntWidget *while_status; |
|
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
70 | GntWidget *volume; |
|
18439
5b6c9a328910
Fixed Cancel button callback
Eric Polino <aluink@pidgin.im>
parents:
18438
diff
changeset
|
71 | GntWidget *events; |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
72 | GntWidget *window; |
|
18680
1e8e7b2d644e
Fix a potential crash if the file-selector window is closed after the pref-window.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18679
diff
changeset
|
73 | GntWidget *selector; |
| 18683 | 74 | GntWidget *profiles; |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
75 | } SoundPrefDialog; |
|
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
76 | |
| 18435 | 77 | SoundPrefDialog *pref_dialog; |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
78 | |
| 18155 | 79 | #define PLAY_SOUND_TIMEOUT 15000 |
| 80 | ||
| 81 | static guint mute_login_sounds_timeout = 0; | |
| 82 | static gboolean mute_login_sounds = FALSE; | |
| 18683 | 83 | static gchar * pref_string = NULL; |
| 18155 | 84 | |
| 85 | #ifdef USE_GSTREAMER | |
| 86 | static gboolean gst_init_failed; | |
| 87 | #endif /* USE_GSTREAMER */ | |
| 88 | ||
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
89 | static FinchSoundEvent sounds[PURPLE_NUM_SOUNDS] = { |
|
18678
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
90 | {PURPLE_SOUND_BUDDY_ARRIVE, N_("Buddy logs in"), "login", "login.wav",NULL}, |
|
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
91 | {PURPLE_SOUND_BUDDY_LEAVE, N_("Buddy logs out"), "logout", "logout.wav",NULL}, |
|
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
92 | {PURPLE_SOUND_RECEIVE, N_("Message received"), "im_recv", "receive.wav",NULL}, |
|
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
93 | {PURPLE_SOUND_FIRST_RECEIVE,N_("Message received begins conversation"), "first_im_recv", "receive.wav",NULL}, |
|
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
94 | {PURPLE_SOUND_SEND, N_("Message sent"), "send_im", "send.wav",NULL}, |
|
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
95 | {PURPLE_SOUND_CHAT_JOIN, N_("Person enters chat"), "join_chat", "login.wav",NULL}, |
|
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
96 | {PURPLE_SOUND_CHAT_LEAVE, N_("Person leaves chat"), "left_chat", "logout.wav",NULL}, |
|
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
97 | {PURPLE_SOUND_CHAT_YOU_SAY, N_("You talk in chat"), "send_chat_msg", "send.wav",NULL}, |
|
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
98 | {PURPLE_SOUND_CHAT_SAY, N_("Others talk in chat"), "chat_msg_recv", "receive.wav",NULL}, |
|
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
99 | {PURPLE_SOUND_POUNCE_DEFAULT, NULL, "pounce_default", "alert.wav",NULL}, |
|
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
100 | {PURPLE_SOUND_CHAT_NICK, N_("Someone says your screen name in chat"), "nick_said", "alert.wav",NULL} |
| 18155 | 101 | }; |
| 102 | ||
| 18683 | 103 | const char * |
| 104 | finch_sound_get_active_profile() | |
| 105 | { | |
| 106 | return purple_prefs_get_string(FINCH_PREFS_ROOT "/sound/actprofile"); | |
| 107 | } | |
| 108 | ||
| 109 | /* This method creates a pref name based on the current active profile. | |
| 110 | * So if "Home" is the current active profile the pref name | |
| 111 | * [FINCH_PREFS_ROOT "/sound/profiles/Home/$NAME"] is created. | |
| 112 | */ | |
| 113 | static gchar * | |
| 114 | make_pref(const char *name) | |
| 115 | { | |
| 116 | g_free(pref_string); | |
| 117 | pref_string = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s%s",finch_sound_get_active_profile(),name); | |
| 118 | return pref_string; | |
| 119 | } | |
| 120 | ||
| 121 | ||
| 18155 | 122 | static gboolean |
| 123 | unmute_login_sounds_cb(gpointer data) | |
| 124 | { | |
| 125 | mute_login_sounds = FALSE; | |
| 126 | mute_login_sounds_timeout = 0; | |
| 127 | return FALSE; | |
| 128 | } | |
| 129 | ||
| 130 | static gboolean | |
| 131 | chat_nick_matches_name(PurpleConversation *conv, const char *aname) | |
| 132 | { | |
| 133 | PurpleConvChat *chat = NULL; | |
| 134 | char *nick = NULL; | |
| 135 | char *name = NULL; | |
| 136 | gboolean ret = FALSE; | |
| 137 | chat = purple_conversation_get_chat_data(conv); | |
| 138 | ||
| 139 | if (chat==NULL) | |
| 140 | return ret; | |
| 141 | ||
| 142 | nick = g_strdup(purple_normalize(conv->account, chat->nick)); | |
| 143 | name = g_strdup(purple_normalize(conv->account, aname)); | |
| 144 | ||
| 145 | if (g_utf8_collate(nick, name) == 0) | |
| 146 | ret = TRUE; | |
| 147 | ||
| 148 | g_free(nick); | |
| 149 | g_free(name); | |
| 150 | ||
| 151 | return ret; | |
| 152 | } | |
| 153 | ||
| 154 | /* | |
| 155 | * play a sound event for a conversation, honoring make_sound flag | |
| 156 | * of conversation and checking for focus if conv_focus pref is set | |
| 157 | */ | |
| 158 | static void | |
| 159 | play_conv_event(PurpleConversation *conv, PurpleSoundEventID event) | |
| 160 | { | |
| 161 | /* If we should not play the sound for some reason, then exit early */ | |
| 162 | if (conv != NULL) | |
| 163 | { | |
| 164 | FinchConv *gntconv; | |
| 165 | gboolean has_focus; | |
| 166 | ||
| 167 | gntconv = FINCH_CONV(conv); | |
| 168 | ||
| 169 | has_focus = purple_conversation_has_focus(conv); | |
| 170 | ||
| 18683 | 171 | if (has_focus && !purple_prefs_get_bool(make_pref("/conv_focus"))) |
| 18155 | 172 | { |
| 173 | return; | |
| 174 | } | |
| 175 | } | |
| 176 | ||
| 177 | purple_sound_play_event(event, conv ? purple_conversation_get_account(conv) : NULL); | |
| 178 | } | |
| 179 | ||
| 180 | static void | |
| 181 | buddy_state_cb(PurpleBuddy *buddy, PurpleSoundEventID event) | |
| 182 | { | |
| 183 | purple_sound_play_event(event, purple_buddy_get_account(buddy)); | |
| 184 | } | |
| 185 | ||
| 186 | static void | |
| 187 | im_msg_received_cb(PurpleAccount *account, char *sender, | |
| 188 | char *message, PurpleConversation *conv, | |
| 189 | PurpleMessageFlags flags, PurpleSoundEventID event) | |
| 190 | { | |
| 191 | if (flags & PURPLE_MESSAGE_DELAYED) | |
| 192 | return; | |
| 193 | ||
| 194 | if (conv==NULL){ | |
| 195 | purple_sound_play_event(PURPLE_SOUND_FIRST_RECEIVE, account); | |
| 196 | } | |
| 197 | else{ | |
| 198 | play_conv_event(conv, event); | |
| 199 | } | |
| 200 | } | |
| 201 | ||
| 202 | static void | |
| 203 | im_msg_sent_cb(PurpleAccount *account, const char *receiver, | |
| 204 | const char *message, PurpleSoundEventID event) | |
| 205 | { | |
| 206 | PurpleConversation *conv = purple_find_conversation_with_account( | |
| 207 | PURPLE_CONV_TYPE_ANY, receiver, account); | |
| 208 | play_conv_event(conv, event); | |
| 209 | } | |
| 210 | ||
| 211 | static void | |
| 212 | chat_buddy_join_cb(PurpleConversation *conv, const char *name, | |
| 213 | PurpleConvChatBuddyFlags flags, gboolean new_arrival, | |
| 214 | PurpleSoundEventID event) | |
| 215 | { | |
| 216 | if (new_arrival && !chat_nick_matches_name(conv, name)) | |
| 217 | play_conv_event(conv, event); | |
| 218 | } | |
| 219 | ||
| 220 | static void | |
| 221 | chat_buddy_left_cb(PurpleConversation *conv, const char *name, | |
| 222 | const char *reason, PurpleSoundEventID event) | |
| 223 | { | |
| 224 | if (!chat_nick_matches_name(conv, name)) | |
| 225 | play_conv_event(conv, event); | |
| 226 | } | |
| 227 | ||
| 228 | static void | |
| 229 | chat_msg_sent_cb(PurpleAccount *account, const char *message, | |
| 230 | int id, PurpleSoundEventID event) | |
| 231 | { | |
| 232 | PurpleConnection *conn = purple_account_get_connection(account); | |
| 233 | PurpleConversation *conv = NULL; | |
| 234 | ||
| 235 | if (conn!=NULL) | |
| 236 | conv = purple_find_chat(conn,id); | |
| 237 | ||
| 238 | play_conv_event(conv, event); | |
| 239 | } | |
| 240 | ||
| 241 | static void | |
| 242 | chat_msg_received_cb(PurpleAccount *account, char *sender, | |
| 243 | char *message, PurpleConversation *conv, | |
| 244 | PurpleMessageFlags flags, PurpleSoundEventID event) | |
| 245 | { | |
| 246 | PurpleConvChat *chat; | |
| 247 | ||
| 248 | if (flags & PURPLE_MESSAGE_DELAYED) | |
| 249 | return; | |
| 250 | ||
| 251 | chat = purple_conversation_get_chat_data(conv); | |
| 252 | g_return_if_fail(chat != NULL); | |
| 253 | ||
| 254 | if (purple_conv_chat_is_user_ignored(chat, sender)) | |
| 255 | return; | |
| 256 | ||
| 257 | if (chat_nick_matches_name(conv, sender)) | |
| 258 | return; | |
| 259 | ||
| 260 | if (flags & PURPLE_MESSAGE_NICK || purple_utf8_has_word(message, chat->nick)) | |
| 261 | play_conv_event(conv, PURPLE_SOUND_CHAT_NICK); | |
| 262 | else | |
| 263 | play_conv_event(conv, event); | |
| 264 | } | |
| 265 | ||
| 266 | /* | |
| 267 | * We mute sounds for the 10 seconds after you log in so that | |
| 268 | * you don't get flooded with sounds when the blist shows all | |
| 269 | * your buddies logging in. | |
| 270 | */ | |
| 271 | static void | |
| 272 | account_signon_cb(PurpleConnection *gc, gpointer data) | |
| 273 | { | |
| 274 | if (mute_login_sounds_timeout != 0) | |
| 275 | g_source_remove(mute_login_sounds_timeout); | |
| 276 | mute_login_sounds = TRUE; | |
| 277 | mute_login_sounds_timeout = purple_timeout_add(10000, unmute_login_sounds_cb, NULL); | |
| 278 | } | |
| 279 | ||
| 280 | void * | |
| 281 | finch_sound_get_handle() | |
| 282 | { | |
| 283 | static int handle; | |
| 284 | ||
| 285 | return &handle; | |
| 286 | } | |
| 287 | ||
| 18683 | 288 | |
| 289 | /* This gets called when the active profile changes */ | |
| 290 | static void | |
| 291 | load_profile(const char *name, PurplePrefType type, gconstpointer val, gpointer null) | |
| 292 | { | |
| 293 | if(!purple_prefs_exists(make_pref(""))){ | |
| 294 | purple_prefs_add_none(make_pref("")); | |
| 295 | purple_prefs_add_none(make_pref("/enabled")); | |
| 296 | purple_prefs_add_none(make_pref("/file")); | |
| 297 | purple_prefs_add_bool(make_pref("/enabled/login"), TRUE); | |
| 298 | purple_prefs_add_path(make_pref("/file/login"), ""); | |
| 299 | purple_prefs_add_bool(make_pref("/enabled/logout"), TRUE); | |
| 300 | purple_prefs_add_path(make_pref("/file/logout"), ""); | |
| 301 | purple_prefs_add_bool(make_pref("/enabled/im_recv"), TRUE); | |
| 302 | purple_prefs_add_path(make_pref("/file/im_recv"), ""); | |
| 303 | purple_prefs_add_bool(make_pref("/enabled/first_im_recv"), FALSE); | |
| 304 | purple_prefs_add_path(make_pref("/file/first_im_recv"), ""); | |
| 305 | purple_prefs_add_bool(make_pref("/enabled/send_im"), TRUE); | |
| 306 | purple_prefs_add_path(make_pref("/file/send_im"), ""); | |
| 307 | purple_prefs_add_bool(make_pref("/enabled/join_chat"), FALSE); | |
| 308 | purple_prefs_add_path(make_pref("/file/join_chat"), ""); | |
| 309 | purple_prefs_add_bool(make_pref("/enabled/left_chat"), FALSE); | |
| 310 | purple_prefs_add_path(make_pref("/file/left_chat"), ""); | |
| 311 | purple_prefs_add_bool(make_pref("/enabled/send_chat_msg"), FALSE); | |
| 312 | purple_prefs_add_path(make_pref("/file/send_chat_msg"), ""); | |
| 313 | purple_prefs_add_bool(make_pref("/enabled/chat_msg_recv"), FALSE); | |
| 314 | purple_prefs_add_path(make_pref("/file/chat_msg_recv"), ""); | |
| 315 | purple_prefs_add_bool(make_pref("/enabled/nick_said"), FALSE); | |
| 316 | purple_prefs_add_path(make_pref("/file/nick_said"), ""); | |
| 317 | purple_prefs_add_bool(make_pref("/enabled/pounce_default"), TRUE); | |
| 318 | purple_prefs_add_path(make_pref("/file/pounce_default"), ""); | |
| 319 | purple_prefs_add_bool(make_pref("/conv_focus"), TRUE); | |
| 320 | purple_prefs_add_bool(make_pref("/mute"), FALSE); | |
| 321 | purple_prefs_add_path(make_pref("/command"), ""); | |
| 322 | purple_prefs_add_string(make_pref("/method"), "automatic"); | |
| 323 | purple_prefs_add_int(make_pref("/volume"), 50); | |
| 324 | } | |
| 325 | } | |
| 326 | ||
| 18155 | 327 | static void |
| 328 | finch_sound_init(void) | |
| 329 | { | |
| 330 | void *gnt_sound_handle = finch_sound_get_handle(); | |
| 331 | void *blist_handle = purple_blist_get_handle(); | |
| 332 | void *conv_handle = purple_conversations_get_handle(); | |
| 333 | #ifdef USE_GSTREAMER | |
| 334 | GError *error = NULL; | |
| 335 | #endif | |
| 336 | ||
| 337 | purple_signal_connect(purple_connections_get_handle(), "signed-on", | |
| 338 | gnt_sound_handle, PURPLE_CALLBACK(account_signon_cb), | |
| 339 | NULL); | |
| 340 | ||
| 341 | purple_prefs_add_none(FINCH_PREFS_ROOT "/sound"); | |
| 18683 | 342 | purple_prefs_add_string(FINCH_PREFS_ROOT "/sound/actprofile", "default"); |
| 343 | purple_prefs_add_none(FINCH_PREFS_ROOT "/sound/profiles"); | |
| 18155 | 344 | |
| 18683 | 345 | purple_prefs_connect_callback(gnt_sound_handle,FINCH_PREFS_ROOT "/sound/actprofile",load_profile,NULL); |
| 346 | purple_prefs_trigger_callback(FINCH_PREFS_ROOT "/sound/actprofile"); | |
| 347 | ||
| 348 | ||
| 18155 | 349 | #ifdef USE_GSTREAMER |
| 350 | purple_debug_info("sound", "Initializing sound output drivers.\n"); | |
| 351 | if ((gst_init_failed = !gst_init_check(NULL, NULL, &error))) { | |
| 352 | purple_notify_error(NULL, _("GStreamer Failure"), | |
| 353 | _("GStreamer failed to initialize."), | |
| 354 | error ? error->message : ""); | |
| 355 | if (error) { | |
| 356 | g_error_free(error); | |
| 357 | error = NULL; | |
| 358 | } | |
| 359 | } | |
| 360 | #endif /* USE_GSTREAMER */ | |
| 361 | ||
| 362 | purple_signal_connect(blist_handle, "buddy-signed-on", | |
| 363 | gnt_sound_handle, PURPLE_CALLBACK(buddy_state_cb), | |
| 364 | GINT_TO_POINTER(PURPLE_SOUND_BUDDY_ARRIVE)); | |
| 365 | purple_signal_connect(blist_handle, "buddy-signed-off", | |
| 366 | gnt_sound_handle, PURPLE_CALLBACK(buddy_state_cb), | |
| 367 | GINT_TO_POINTER(PURPLE_SOUND_BUDDY_LEAVE)); | |
| 368 | purple_signal_connect(conv_handle, "received-im-msg", | |
| 369 | gnt_sound_handle, PURPLE_CALLBACK(im_msg_received_cb), | |
| 370 | GINT_TO_POINTER(PURPLE_SOUND_RECEIVE)); | |
| 371 | purple_signal_connect(conv_handle, "sent-im-msg", | |
| 372 | gnt_sound_handle, PURPLE_CALLBACK(im_msg_sent_cb), | |
| 373 | GINT_TO_POINTER(PURPLE_SOUND_SEND)); | |
| 374 | purple_signal_connect(conv_handle, "chat-buddy-joined", | |
| 375 | gnt_sound_handle, PURPLE_CALLBACK(chat_buddy_join_cb), | |
| 376 | GINT_TO_POINTER(PURPLE_SOUND_CHAT_JOIN)); | |
| 377 | purple_signal_connect(conv_handle, "chat-buddy-left", | |
| 378 | gnt_sound_handle, PURPLE_CALLBACK(chat_buddy_left_cb), | |
| 379 | GINT_TO_POINTER(PURPLE_SOUND_CHAT_LEAVE)); | |
| 380 | purple_signal_connect(conv_handle, "sent-chat-msg", | |
| 381 | gnt_sound_handle, PURPLE_CALLBACK(chat_msg_sent_cb), | |
| 382 | GINT_TO_POINTER(PURPLE_SOUND_CHAT_YOU_SAY)); | |
| 383 | purple_signal_connect(conv_handle, "received-chat-msg", | |
| 384 | gnt_sound_handle, PURPLE_CALLBACK(chat_msg_received_cb), | |
| 385 | GINT_TO_POINTER(PURPLE_SOUND_CHAT_SAY)); | |
| 386 | } | |
| 387 | ||
| 388 | static void | |
| 389 | finch_sound_uninit(void) | |
| 390 | { | |
| 391 | #ifdef USE_GSTREAMER | |
| 392 | if (!gst_init_failed) | |
| 393 | gst_deinit(); | |
| 394 | #endif | |
| 395 | ||
| 396 | purple_signals_disconnect_by_handle(finch_sound_get_handle()); | |
| 397 | } | |
| 398 | ||
| 399 | #ifdef USE_GSTREAMER | |
| 400 | static gboolean | |
| 401 | bus_call (GstBus *bus, GstMessage *msg, gpointer data) | |
| 402 | { | |
| 403 | GstElement *play = data; | |
| 404 | GError *err = NULL; | |
| 405 | ||
| 406 | switch (GST_MESSAGE_TYPE (msg)) { | |
| 407 | case GST_MESSAGE_EOS: | |
| 408 | gst_element_set_state(play, GST_STATE_NULL); | |
| 409 | gst_object_unref(GST_OBJECT(play)); | |
| 410 | break; | |
| 411 | case GST_MESSAGE_ERROR: | |
| 412 | gst_message_parse_error(msg, &err, NULL); | |
| 413 | purple_debug_error("gstreamer", err->message); | |
| 414 | g_error_free(err); | |
| 415 | break; | |
| 416 | case GST_MESSAGE_WARNING: | |
| 417 | gst_message_parse_warning(msg, &err, NULL); | |
| 418 | purple_debug_warning("gstreamer", err->message); | |
| 419 | g_error_free(err); | |
| 420 | break; | |
| 421 | default: | |
| 422 | break; | |
| 423 | } | |
| 424 | return TRUE; | |
| 425 | } | |
| 426 | #endif | |
| 427 | ||
| 428 | static void | |
| 429 | finch_sound_play_file(const char *filename) | |
| 430 | { | |
| 431 | const char *method; | |
| 432 | #ifdef USE_GSTREAMER | |
| 433 | float volume; | |
| 434 | char *uri; | |
| 435 | GstElement *sink = NULL; | |
| 436 | GstElement *play = NULL; | |
| 437 | GstBus *bus = NULL; | |
| 438 | #endif | |
| 18683 | 439 | if (purple_prefs_get_bool(make_pref("/mute"))) |
| 18155 | 440 | return; |
| 441 | ||
| 18683 | 442 | method = purple_prefs_get_string(make_pref("/method")); |
| 18155 | 443 | |
| 444 | if (!strcmp(method, "none")) { | |
| 445 | return; | |
| 446 | } else if (!strcmp(method, "beep")) { | |
| 447 | beep(); | |
| 448 | return; | |
| 449 | } | |
| 450 | ||
| 451 | if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { | |
| 452 | purple_debug_error("gntsound", "sound file (%s) does not exist.\n", filename); | |
| 453 | return; | |
| 454 | } | |
| 455 | ||
| 456 | #ifndef _WIN32 | |
| 457 | if (!strcmp(method, "custom")) { | |
| 458 | const char *sound_cmd; | |
| 459 | char *command; | |
| 460 | char *esc_filename; | |
| 461 | GError *error = NULL; | |
| 462 | ||
| 18683 | 463 | sound_cmd = purple_prefs_get_path(make_pref("/command")); |
| 18155 | 464 | |
| 465 | if (!sound_cmd || *sound_cmd == '\0') { | |
| 466 | purple_debug_error("gntsound", | |
| 467 | "'Command' sound method has been chosen, " | |
| 468 | "but no command has been set."); | |
| 469 | return; | |
| 470 | } | |
| 471 | ||
| 472 | esc_filename = g_shell_quote(filename); | |
| 473 | ||
| 474 | if(strstr(sound_cmd, "%s")) | |
| 475 | command = purple_strreplace(sound_cmd, "%s", esc_filename); | |
| 476 | else | |
| 477 | command = g_strdup_printf("%s %s", sound_cmd, esc_filename); | |
| 478 | ||
| 479 | if(!g_spawn_command_line_async(command, &error)) { | |
| 480 | purple_debug_error("gntsound", "sound command could not be launched: %s\n", error->message); | |
| 481 | g_error_free(error); | |
| 482 | } | |
| 483 | ||
| 484 | g_free(esc_filename); | |
| 485 | g_free(command); | |
| 486 | return; | |
| 487 | } | |
| 488 | #ifdef USE_GSTREAMER | |
| 489 | if (gst_init_failed) /* Perhaps do beep instead? */ | |
| 490 | return; | |
| 18683 | 491 | volume = (float)(CLAMP(purple_prefs_get_int(make_pref("/volume")),0,100)) / 50; |
| 18155 | 492 | if (!strcmp(method, "automatic")) { |
| 493 | if (purple_running_gnome()) { | |
| 494 | sink = gst_element_factory_make("gconfaudiosink", "sink"); | |
| 495 | } | |
| 496 | if (!sink) | |
| 497 | sink = gst_element_factory_make("autoaudiosink", "sink"); | |
| 498 | if (!sink) { | |
| 499 | purple_debug_error("sound", "Unable to create GStreamer audiosink.\n"); | |
| 500 | return; | |
| 501 | } | |
| 502 | } else if (!strcmp(method, "esd")) { | |
| 503 | sink = gst_element_factory_make("esdsink", "sink"); | |
| 504 | if (!sink) { | |
| 505 | purple_debug_error("sound", "Unable to create GStreamer audiosink.\n"); | |
| 506 | return; | |
| 507 | } | |
| 508 | } else if (!strcmp(method, "alsa")) { | |
| 509 | sink = gst_element_factory_make("alsasink", "sink"); | |
| 510 | if (!sink) { | |
| 511 | purple_debug_error("sound", "Unable to create GStreamer audiosink.\n"); | |
| 512 | return; | |
| 513 | } | |
| 514 | } else { | |
| 515 | purple_debug_error("sound", "Unknown sound method '%s'\n", method); | |
| 516 | return; | |
| 517 | } | |
| 518 | ||
| 519 | play = gst_element_factory_make("playbin", "play"); | |
| 520 | ||
| 521 | if (play == NULL) { | |
| 522 | return; | |
| 523 | } | |
| 524 | ||
| 525 | uri = g_strdup_printf("file://%s", filename); | |
| 526 | ||
| 527 | g_object_set(G_OBJECT(play), "uri", uri, | |
| 528 | "volume", volume, | |
| 529 | "audio-sink", sink, NULL); | |
| 530 | ||
| 531 | bus = gst_pipeline_get_bus(GST_PIPELINE(play)); | |
| 532 | gst_bus_add_watch(bus, bus_call, play); | |
| 533 | ||
| 534 | gst_element_set_state(play, GST_STATE_PLAYING); | |
| 535 | ||
| 536 | gst_object_unref(bus); | |
| 537 | g_free(uri); | |
| 538 | ||
| 539 | #else /* USE_GSTREAMER */ | |
| 540 | beep(); | |
| 541 | return; | |
| 542 | #endif /* USE_GSTREAMER */ | |
| 543 | #else /* _WIN32 */ | |
| 544 | purple_debug_info("sound", "Playing %s\n", filename); | |
| 545 | ||
| 546 | if (G_WIN32_HAVE_WIDECHAR_API ()) { | |
| 547 | wchar_t *wc_filename = g_utf8_to_utf16(filename, | |
| 548 | -1, NULL, NULL, NULL); | |
| 549 | if (!PlaySoundW(wc_filename, NULL, SND_ASYNC | SND_FILENAME)) | |
| 550 | purple_debug(PURPLE_DEBUG_ERROR, "sound", "Error playing sound.\n"); | |
| 551 | g_free(wc_filename); | |
| 552 | } else { | |
| 553 | char *l_filename = g_locale_from_utf8(filename, | |
| 554 | -1, NULL, NULL, NULL); | |
| 555 | if (!PlaySoundA(l_filename, NULL, SND_ASYNC | SND_FILENAME)) | |
| 556 | purple_debug(PURPLE_DEBUG_ERROR, "sound", "Error playing sound.\n"); | |
| 557 | g_free(l_filename); | |
| 558 | } | |
| 559 | #endif /* _WIN32 */ | |
| 560 | } | |
| 561 | ||
| 562 | static void | |
| 563 | finch_sound_play_event(PurpleSoundEventID event) | |
| 564 | { | |
| 565 | char *enable_pref; | |
| 566 | char *file_pref; | |
| 567 | if ((event == PURPLE_SOUND_BUDDY_ARRIVE) && mute_login_sounds) | |
| 568 | return; | |
| 569 | ||
| 570 | if (event >= PURPLE_NUM_SOUNDS) { | |
| 571 | purple_debug_error("sound", "got request for unknown sound: %d\n", event); | |
| 572 | return; | |
| 573 | } | |
| 574 | ||
| 18683 | 575 | enable_pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s", |
| 576 | finch_sound_get_active_profile(), | |
| 18155 | 577 | sounds[event].pref); |
| 18683 | 578 | file_pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s", finch_sound_get_active_profile(),sounds[event].pref); |
| 18155 | 579 | |
| 580 | /* check NULL for sounds that don't have an option, ie buddy pounce */ | |
| 581 | if (purple_prefs_get_bool(enable_pref)) { | |
| 582 | char *filename = g_strdup(purple_prefs_get_path(file_pref)); | |
| 583 | if(!filename || !strlen(filename)) { | |
| 584 | g_free(filename); | |
| 18292 | 585 | /* XXX Consider creating a constant for "sounds/purple" to be shared with Pidgin */ |
| 586 | filename = g_build_filename(DATADIR, "sounds", "purple", sounds[event].def, NULL); | |
| 18155 | 587 | } |
| 588 | ||
| 589 | purple_sound_play_file(filename, NULL); | |
| 590 | g_free(filename); | |
| 591 | } | |
| 592 | ||
| 593 | g_free(enable_pref); | |
| 594 | g_free(file_pref); | |
| 595 | } | |
| 596 | ||
| 18683 | 597 | GList * |
| 598 | finch_sound_get_profiles() | |
| 599 | { | |
| 600 | return purple_prefs_get_children_names(FINCH_PREFS_ROOT "/sound/profiles"); | |
| 601 | } | |
| 602 | ||
| 603 | static gboolean | |
| 604 | profile_exists(const char *name) | |
| 605 | { | |
| 606 | GList *itr = NULL; | |
| 607 | for(itr = finch_sound_get_profiles();itr;itr = itr->next){ | |
| 608 | if(!strcmp(itr->data,name)) | |
| 609 | return TRUE; | |
| 610 | } | |
| 611 | return FALSE; | |
| 612 | } | |
| 613 | ||
| 614 | void | |
| 615 | finch_sound_set_active_profile(const char *name) | |
| 616 | { | |
| 617 | if(profile_exists(name)){ | |
| 618 | purple_prefs_set_string(FINCH_PREFS_ROOT "/sound/actprofile",name); | |
| 619 | } | |
| 620 | } | |
| 621 | ||
| 622 | ||
|
18438
972b13b06ba0
Cleaned up a few poorly written "activate" callbacks.
Eric Polino <aluink@pidgin.im>
parents:
18437
diff
changeset
|
623 | static void |
|
972b13b06ba0
Cleaned up a few poorly written "activate" callbacks.
Eric Polino <aluink@pidgin.im>
parents:
18437
diff
changeset
|
624 | save_cb(GntWidget *button, gpointer win) |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
625 | { |
|
18616
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
626 | GList * itr; |
|
18439
5b6c9a328910
Fixed Cancel button callback
Eric Polino <aluink@pidgin.im>
parents:
18438
diff
changeset
|
627 | |
| 18683 | 628 | purple_prefs_set_string(make_pref("/method"), gnt_combo_box_get_selected_data(GNT_COMBO_BOX(pref_dialog->method))); |
| 629 | purple_prefs_set_path(make_pref("/command"), gnt_entry_get_text(GNT_ENTRY(pref_dialog->command))); | |
| 630 | purple_prefs_set_bool(make_pref("/conv_focus"),gnt_check_box_get_checked(GNT_CHECK_BOX(pref_dialog->conv_focus))); | |
| 18437 | 631 | purple_prefs_set_int("/purple/sound/while_status",GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(pref_dialog->while_status)))); |
| 18683 | 632 | purple_prefs_set_int(make_pref("/volume"),gnt_slider_get_value(GNT_SLIDER(pref_dialog->volume))); |
| 18437 | 633 | |
|
18616
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
634 | for(itr = gnt_tree_get_rows(GNT_TREE(pref_dialog->events));itr;itr = itr->next){ |
|
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
635 | FinchSoundEvent * event = &sounds[GPOINTER_TO_INT(itr->data)]; |
| 18683 | 636 | char * filepref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s",finch_sound_get_active_profile(),event->pref); |
| 637 | char * boolpref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s",finch_sound_get_active_profile(),event->pref); | |
|
18616
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
638 | purple_prefs_set_bool(boolpref,gnt_tree_get_choice(GNT_TREE(pref_dialog->events),itr->data)); |
|
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
639 | purple_prefs_set_path(filepref,event->file ? event->file : ""); |
|
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
640 | g_free(filepref); |
| 18618 | 641 | g_free(boolpref); |
|
18439
5b6c9a328910
Fixed Cancel button callback
Eric Polino <aluink@pidgin.im>
parents:
18438
diff
changeset
|
642 | } |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
643 | gnt_widget_destroy(GNT_WIDGET(win)); |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
644 | } |
|
18678
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
645 | |
|
18438
972b13b06ba0
Cleaned up a few poorly written "activate" callbacks.
Eric Polino <aluink@pidgin.im>
parents:
18437
diff
changeset
|
646 | static void |
|
18678
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
647 | file_cb(GntFileSel *w, const char *path, const char *file, gpointer data) |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
648 | { |
|
18678
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
649 | FinchSoundEvent *event = data; |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
650 | |
|
18616
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
651 | g_free(event->file); |
|
18678
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
652 | event->file = g_strdup(path); |
|
18620
8e8d99ffa1f6
Made the display of files for sound events cleaner
Eric Polino <aluink@pidgin.im>
parents:
18618
diff
changeset
|
653 | |
|
18678
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
654 | gnt_tree_change_text(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(event->id), 1, file); |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
655 | |
|
18678
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
656 | gnt_widget_destroy(GNT_WIDGET(w)); |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
657 | } |
|
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
658 | |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
659 | static void |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
660 | test_cb(GntWidget *button, gpointer null) |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
661 | { |
|
18616
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
662 | PurpleSoundEventID id = GPOINTER_TO_INT(gnt_tree_get_selection_data(GNT_TREE(pref_dialog->events))); |
|
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
663 | FinchSoundEvent * event = &sounds[id]; |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
664 | char *pref; |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
665 | gboolean temp_value; |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
666 | |
| 18683 | 667 | pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s",finch_sound_get_active_profile(), |
|
18616
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
668 | event->pref); |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
669 | |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
670 | temp_value = purple_prefs_get_bool(pref); |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
671 | |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
672 | if (!temp_value) purple_prefs_set_bool(pref, TRUE); |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
673 | |
|
18616
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
674 | purple_sound_play_event(id, NULL); |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
675 | |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
676 | if (!temp_value) purple_prefs_set_bool(pref, FALSE); |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
677 | |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
678 | g_free(pref); |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
679 | } |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
680 | |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
681 | static void |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
682 | reset_cb(GntWidget *button,gpointer null) |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
683 | { |
|
18616
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
684 | /* Don't dereference this pointer ! */ |
|
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
685 | gpointer key = gnt_tree_get_selection_data(GNT_TREE(pref_dialog->events)); |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
686 | |
|
18616
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
687 | FinchSoundEvent * event = &sounds[GPOINTER_TO_INT(key)]; |
|
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
688 | g_free(event->file); |
|
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
689 | event->file = NULL; |
|
18620
8e8d99ffa1f6
Made the display of files for sound events cleaner
Eric Polino <aluink@pidgin.im>
parents:
18618
diff
changeset
|
690 | gnt_tree_change_text(GNT_TREE(pref_dialog->events),key,1,"(default)"); |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
691 | } |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
692 | |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
693 | static void |
|
18687
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
694 | prof_del_cb(GntWidget *button, gpointer null) |
| 18683 | 695 | { |
|
18687
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
696 | const gchar * value = gnt_entry_get_text(GNT_ENTRY(pref_dialog->profiles)); |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
697 | gchar * pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s",value); |
| 18683 | 698 | |
|
18687
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
699 | if(purple_prefs_exists(pref)) |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
700 | purple_prefs_remove(pref); |
| 18683 | 701 | |
|
18687
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
702 | g_free(pref); |
| 18683 | 703 | } |
| 704 | ||
| 705 | static void | |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
706 | choose_cb(GntWidget *button, gpointer null) |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
707 | { |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
708 | GntWidget *w = gnt_file_sel_new(); |
|
18678
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
709 | GntFileSel *sel = GNT_FILE_SEL(w); |
|
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
710 | PurpleSoundEventID id = GPOINTER_TO_INT(gnt_tree_get_selection_data(GNT_TREE(pref_dialog->events))); |
|
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
711 | FinchSoundEvent * event = &sounds[id]; |
|
18680
1e8e7b2d644e
Fix a potential crash if the file-selector window is closed after the pref-window.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18679
diff
changeset
|
712 | char *path = NULL; |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
713 | |
|
18678
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
714 | gnt_file_sel_set_current_location(sel, |
|
18680
1e8e7b2d644e
Fix a potential crash if the file-selector window is closed after the pref-window.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18679
diff
changeset
|
715 | (event && event->file) ? (path = g_path_get_dirname(event->file)) |
|
1e8e7b2d644e
Fix a potential crash if the file-selector window is closed after the pref-window.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18679
diff
changeset
|
716 | : purple_home_dir()); |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
717 | |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
718 | g_signal_connect_swapped(G_OBJECT(sel->cancel),"activate",G_CALLBACK(gnt_widget_destroy),sel); |
|
18678
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
719 | g_signal_connect(G_OBJECT(sel), "file_selected", G_CALLBACK(file_cb), event); |
|
18680
1e8e7b2d644e
Fix a potential crash if the file-selector window is closed after the pref-window.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18679
diff
changeset
|
720 | g_signal_connect_swapped(G_OBJECT(sel), "destroy", G_CALLBACK(g_nullify_pointer), &pref_dialog->selector); |
|
1e8e7b2d644e
Fix a potential crash if the file-selector window is closed after the pref-window.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18679
diff
changeset
|
721 | |
|
1e8e7b2d644e
Fix a potential crash if the file-selector window is closed after the pref-window.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18679
diff
changeset
|
722 | /* If there's an already open file-selector, close that one. */ |
|
1e8e7b2d644e
Fix a potential crash if the file-selector window is closed after the pref-window.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18679
diff
changeset
|
723 | if (pref_dialog->selector) |
|
1e8e7b2d644e
Fix a potential crash if the file-selector window is closed after the pref-window.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18679
diff
changeset
|
724 | gnt_widget_destroy(pref_dialog->selector); |
|
1e8e7b2d644e
Fix a potential crash if the file-selector window is closed after the pref-window.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18679
diff
changeset
|
725 | |
|
1e8e7b2d644e
Fix a potential crash if the file-selector window is closed after the pref-window.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18679
diff
changeset
|
726 | pref_dialog->selector = w; |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
727 | |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
728 | gnt_widget_show(w); |
|
18680
1e8e7b2d644e
Fix a potential crash if the file-selector window is closed after the pref-window.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18679
diff
changeset
|
729 | g_free(path); |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
730 | } |
|
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
731 | |
| 18435 | 732 | static void |
| 733 | release_pref_dialog(GntBindable *data, gpointer null) | |
|
18432
8fd3963b9ce0
Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents:
18296
diff
changeset
|
734 | { |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
735 | GList * itr; |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
736 | for(itr = gnt_tree_get_rows(GNT_TREE(pref_dialog->events));itr;itr = itr->next){ |
|
18616
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
737 | PurpleSoundEventID id = GPOINTER_TO_INT(itr->data); |
|
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
738 | FinchSoundEvent * e = &sounds[id]; |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
739 | g_free(e->file); |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
740 | } |
|
18680
1e8e7b2d644e
Fix a potential crash if the file-selector window is closed after the pref-window.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18679
diff
changeset
|
741 | if (pref_dialog->selector) |
|
1e8e7b2d644e
Fix a potential crash if the file-selector window is closed after the pref-window.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18679
diff
changeset
|
742 | gnt_widget_destroy(pref_dialog->selector); |
| 18435 | 743 | g_free(pref_dialog); |
| 744 | pref_dialog = NULL; | |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
745 | } |
|
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
746 | |
| 18683 | 747 | static void |
|
18687
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
748 | reload_pref_window(const char * newkey) |
| 18683 | 749 | { |
| 750 | gint i; | |
| 751 | purple_prefs_set_string(FINCH_PREFS_ROOT "/sound/actprofile",(gchar *)newkey); | |
| 752 | gnt_combo_box_set_selected(GNT_COMBO_BOX(pref_dialog->method),(gchar *)purple_prefs_get_string(make_pref("/method"))); | |
| 753 | gnt_entry_set_text(GNT_ENTRY(pref_dialog->command),purple_prefs_get_path(make_pref("/command"))); | |
| 754 | gnt_check_box_set_checked(GNT_CHECK_BOX(pref_dialog->conv_focus),purple_prefs_get_bool(make_pref("/conv_focus"))); | |
| 755 | 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_slider_set_value(GNT_SLIDER(pref_dialog->volume),CLAMP(purple_prefs_get_int(make_pref("/volume")),0,100)); | |
| 757 | for(i = 0;i < PURPLE_NUM_SOUNDS;i++){ | |
| 758 | FinchSoundEvent * event = &sounds[i]; | |
| 759 | gchar *boolpref; | |
| 760 | gchar *filepref; | |
| 761 | const char * profile = finch_sound_get_active_profile(); | |
| 762 | ||
| 763 | boolpref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s",profile,event->pref); | |
| 764 | ||
| 765 | filepref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s",profile,event->pref); | |
| 766 | event->file = g_strdup(purple_prefs_get_path(filepref)); | |
| 767 | if(event->label == NULL){ | |
| 768 | continue; | |
| 769 | } | |
| 770 | ||
| 771 | gnt_tree_change_text(GNT_TREE(pref_dialog->events),GINT_TO_POINTER(i),0,event->label); | |
| 772 | gnt_tree_change_text(GNT_TREE(pref_dialog->events),GINT_TO_POINTER(i),1,event->file[0] ? g_path_get_basename(event->file) : "(default)"); | |
| 773 | gnt_tree_set_choice(GNT_TREE(pref_dialog->events),GINT_TO_POINTER(i),purple_prefs_get_bool(boolpref)); | |
| 774 | g_free(boolpref); | |
| 775 | g_free(filepref); | |
| 776 | } | |
| 777 | } | |
| 778 | ||
|
18687
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
779 | static void |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
780 | profile_text_load(GntEntry *entry, gpointer null) |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
781 | { |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
782 | const char * profile = gnt_entry_get_text(entry); |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
783 | gchar * pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s",profile); |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
784 | if(purple_prefs_exists(pref)) |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
785 | reload_pref_window(profile); |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
786 | g_free(pref); |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
787 | } |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
788 | |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
789 | static void |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
790 | profile_text_completion(GntEntry *entry, gpointer val1, gpointer val2, gpointer null) |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
791 | { |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
792 | profile_text_load(entry,null); |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
793 | } |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
794 | |
|
18294
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
795 | void |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
796 | finch_sounds_show_all(void) |
|
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
797 | { |
| 18683 | 798 | GntWidget *box; GntWidget *cmbox; GntWidget *slider; |
|
18294
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
799 | GntWidget *entry; |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
800 | GntWidget *chkbox; |
|
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
801 | GntWidget *button; |
|
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
802 | GntWidget *label; |
|
18439
5b6c9a328910
Fixed Cancel button callback
Eric Polino <aluink@pidgin.im>
parents:
18438
diff
changeset
|
803 | GntWidget *tree; |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
804 | GntWidget *win; |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
805 | |
| 18683 | 806 | GList *itr,*list; |
|
18439
5b6c9a328910
Fixed Cancel button callback
Eric Polino <aluink@pidgin.im>
parents:
18438
diff
changeset
|
807 | gint i; |
|
18434
48c2aa1fc3a9
Made sound_pref_data a pointer
Eric Polino <aluink@pidgin.im>
parents:
18433
diff
changeset
|
808 | |
| 18435 | 809 | if(pref_dialog){ |
| 810 | gnt_window_present(pref_dialog->window); | |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
811 | return; |
|
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
812 | } |
|
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
813 | |
| 18435 | 814 | pref_dialog = g_new0(SoundPrefDialog,1); |
|
18294
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
815 | |
| 18435 | 816 | pref_dialog->window = win = gnt_window_box_new(FALSE,TRUE); |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
817 | gnt_box_set_pad(GNT_BOX(win),0); |
|
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
818 | gnt_box_set_toplevel(GNT_BOX(win), TRUE); |
|
18679
c81c8ce38789
Mark some strings for translation.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18678
diff
changeset
|
819 | gnt_box_set_title(GNT_BOX(win), _("Sound Preferences")); |
|
c81c8ce38789
Mark some strings for translation.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18678
diff
changeset
|
820 | gnt_box_set_fill(GNT_BOX(win), TRUE); |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
821 | gnt_box_set_alignment(GNT_BOX(win),GNT_ALIGN_LEFT); |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
822 | |
| 18435 | 823 | pref_dialog->method = cmbox = gnt_combo_box_new(); |
| 18437 | 824 | gnt_tree_set_hash_fns(GNT_TREE(GNT_COMBO_BOX(cmbox)->dropdown), g_str_hash, g_str_equal, NULL); |
|
18294
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
825 | gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"automatic",_("Automatic")); |
|
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
826 | gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"alsa","ALSA"); |
|
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
827 | gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"esd","ESD"); |
|
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
828 | gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"beep",_("Console Beep")); |
|
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
829 | gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"custom",_("Command")); |
|
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
830 | gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"nosound",_("No Sound")); |
|
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
831 | |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
832 | label = gnt_label_new_with_format(_("Sound Method"),GNT_TEXT_FLAG_BOLD); |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
833 | gnt_box_add_widget(GNT_BOX(win),label); |
|
18294
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
834 | box = gnt_hbox_new(TRUE); |
|
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
835 | gnt_box_set_fill(GNT_BOX(box),FALSE); |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
836 | gnt_box_set_pad(GNT_BOX(box),0); |
|
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
837 | gnt_box_add_widget(GNT_BOX(box),gnt_label_new(_("Method: "))); |
|
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
838 | gnt_box_add_widget(GNT_BOX(box),cmbox); |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
839 | gnt_box_add_widget(GNT_BOX(win),box); |
|
18294
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
840 | |
|
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
841 | box = gnt_hbox_new(TRUE); |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
842 | gnt_box_set_pad(GNT_BOX(box),0); |
|
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
843 | gnt_box_set_fill(GNT_BOX(box),FALSE); |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
844 | gnt_box_add_widget(GNT_BOX(box),gnt_label_new(_("Sound Command\n(%s for filename)"))); |
| 18683 | 845 | pref_dialog->command = entry = gnt_entry_new(""); |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
846 | gnt_box_add_widget(GNT_BOX(box),entry); |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
847 | gnt_box_add_widget(GNT_BOX(win),box); |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
848 | |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
849 | gnt_box_add_widget(GNT_BOX(win), gnt_line_new(FALSE)); |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
850 | |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
851 | gnt_box_add_widget(GNT_BOX(win),gnt_label_new_with_format(_("Sound Options"),GNT_TEXT_FLAG_BOLD)); |
| 18437 | 852 | pref_dialog->conv_focus = chkbox = gnt_check_box_new(_("Sounds when conversation has focus")); |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
853 | gnt_box_add_widget(GNT_BOX(win),chkbox); |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
854 | |
|
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
855 | box = gnt_hbox_new(TRUE); |
|
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
856 | gnt_box_set_pad(GNT_BOX(box),0); |
|
18294
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
857 | gnt_box_set_fill(GNT_BOX(box),FALSE); |
|
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
858 | gnt_box_add_widget(GNT_BOX(box),gnt_label_new("Enable Sounds:")); |
| 18435 | 859 | pref_dialog->while_status = cmbox = gnt_combo_box_new(); |
| 18437 | 860 | gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),GINT_TO_POINTER(3),_("Always")); |
| 861 | gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),GINT_TO_POINTER(1),_("Only when available")); | |
| 862 | gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),GINT_TO_POINTER(2),_("Only when not available")); | |
|
18294
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
863 | gnt_box_add_widget(GNT_BOX(box),cmbox); |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
864 | gnt_box_add_widget(GNT_BOX(win),box); |
|
18294
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
865 | |
|
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
866 | box = gnt_hbox_new(TRUE); |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
867 | gnt_box_set_pad(GNT_BOX(box),0); |
|
18294
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
868 | gnt_box_set_fill(GNT_BOX(box),FALSE); |
| 18437 | 869 | gnt_box_add_widget(GNT_BOX(box),gnt_label_new(_("Volume(0-100):"))); |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
870 | |
| 18435 | 871 | pref_dialog->volume = slider = gnt_slider_new(FALSE,100,0); |
|
18432
8fd3963b9ce0
Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents:
18296
diff
changeset
|
872 | gnt_slider_set_step(GNT_SLIDER(slider),5); |
|
8fd3963b9ce0
Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents:
18296
diff
changeset
|
873 | label = gnt_label_new(""); |
|
8fd3963b9ce0
Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents:
18296
diff
changeset
|
874 | gnt_slider_reflect_label(GNT_SLIDER(slider),GNT_LABEL(label)); |
|
8fd3963b9ce0
Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents:
18296
diff
changeset
|
875 | gnt_box_set_pad(GNT_BOX(box),1); |
|
8fd3963b9ce0
Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents:
18296
diff
changeset
|
876 | gnt_box_add_widget(GNT_BOX(box),slider); |
|
8fd3963b9ce0
Changed the volume changer to a GntSlider.
Eric Polino <aluink@pidgin.im>
parents:
18296
diff
changeset
|
877 | gnt_box_add_widget(GNT_BOX(box),label); |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
878 | gnt_box_add_widget(GNT_BOX(win),box); |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
879 | |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
880 | gnt_box_add_widget(GNT_BOX(win), gnt_line_new(FALSE)); |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
881 | |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
882 | gnt_box_add_widget(GNT_BOX(win),gnt_label_new_with_format(_("Sound Events"),GNT_TEXT_FLAG_BOLD)); |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
883 | pref_dialog->events = tree = gnt_tree_new_with_columns(2); |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
884 | gnt_tree_set_column_titles(GNT_TREE(tree),_("Event"),_("File")); |
|
18439
5b6c9a328910
Fixed Cancel button callback
Eric Polino <aluink@pidgin.im>
parents:
18438
diff
changeset
|
885 | gnt_tree_set_show_title(GNT_TREE(tree),TRUE); |
|
5b6c9a328910
Fixed Cancel button callback
Eric Polino <aluink@pidgin.im>
parents:
18438
diff
changeset
|
886 | |
|
5b6c9a328910
Fixed Cancel button callback
Eric Polino <aluink@pidgin.im>
parents:
18438
diff
changeset
|
887 | for(i = 0;i < PURPLE_NUM_SOUNDS;i++){ |
|
18616
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
888 | FinchSoundEvent * event = &sounds[i]; |
| 18683 | 889 | |
|
18616
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
890 | if(event->label == NULL){ |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
891 | continue; |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
892 | } |
|
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
893 | |
|
18616
ce2f681adadf
merged FinchSoundPrefEvent with FinchSoundEvent and removed id from FSE
Eric Polino <aluink@pidgin.im>
parents:
18440
diff
changeset
|
894 | gnt_tree_add_choice(GNT_TREE(tree), GINT_TO_POINTER(i), |
| 18683 | 895 | gnt_tree_create_row(GNT_TREE(tree),"",""), |
|
18439
5b6c9a328910
Fixed Cancel button callback
Eric Polino <aluink@pidgin.im>
parents:
18438
diff
changeset
|
896 | NULL, NULL); |
|
5b6c9a328910
Fixed Cancel button callback
Eric Polino <aluink@pidgin.im>
parents:
18438
diff
changeset
|
897 | } |
|
5b6c9a328910
Fixed Cancel button callback
Eric Polino <aluink@pidgin.im>
parents:
18438
diff
changeset
|
898 | |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
899 | gnt_tree_adjust_columns(GNT_TREE(tree)); |
|
18439
5b6c9a328910
Fixed Cancel button callback
Eric Polino <aluink@pidgin.im>
parents:
18438
diff
changeset
|
900 | gnt_box_add_widget(GNT_BOX(win),tree); |
|
5b6c9a328910
Fixed Cancel button callback
Eric Polino <aluink@pidgin.im>
parents:
18438
diff
changeset
|
901 | |
|
18678
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
902 | box = gnt_hbox_new(FALSE); |
|
18679
c81c8ce38789
Mark some strings for translation.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18678
diff
changeset
|
903 | button = gnt_button_new(_("Test")); |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
904 | g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(test_cb),NULL); |
|
18439
5b6c9a328910
Fixed Cancel button callback
Eric Polino <aluink@pidgin.im>
parents:
18438
diff
changeset
|
905 | gnt_box_add_widget(GNT_BOX(box),button); |
|
18679
c81c8ce38789
Mark some strings for translation.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18678
diff
changeset
|
906 | button = gnt_button_new(_("Reset")); |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
907 | g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(reset_cb),NULL); |
|
18439
5b6c9a328910
Fixed Cancel button callback
Eric Polino <aluink@pidgin.im>
parents:
18438
diff
changeset
|
908 | gnt_box_add_widget(GNT_BOX(box),button); |
|
18679
c81c8ce38789
Mark some strings for translation.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18678
diff
changeset
|
909 | button = gnt_button_new(_("Choose...")); |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
910 | g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(choose_cb),NULL); |
|
18439
5b6c9a328910
Fixed Cancel button callback
Eric Polino <aluink@pidgin.im>
parents:
18438
diff
changeset
|
911 | gnt_box_add_widget(GNT_BOX(box),button); |
|
5b6c9a328910
Fixed Cancel button callback
Eric Polino <aluink@pidgin.im>
parents:
18438
diff
changeset
|
912 | gnt_box_add_widget(GNT_BOX(win),box); |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
913 | |
| 18683 | 914 | gnt_box_add_widget(GNT_BOX(win), gnt_line_new(FALSE)); |
| 915 | ||
| 916 | gnt_box_add_widget(GNT_BOX(win),gnt_label_new_with_format(_("Profiles"),GNT_TEXT_FLAG_BOLD)); | |
| 917 | box = gnt_hbox_new(FALSE); | |
|
18687
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
918 | pref_dialog->profiles = entry = gnt_entry_new(""); |
| 18683 | 919 | list = itr = finch_sound_get_profiles(); |
| 920 | for(;itr;itr = itr->next){ | |
|
18687
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
921 | gnt_entry_add_suggest(GNT_ENTRY(entry),itr->data); |
| 18683 | 922 | } |
| 923 | g_list_free(list); | |
|
18687
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
924 | g_signal_connect(G_OBJECT(entry),"text_changed",G_CALLBACK(profile_text_load),NULL); |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
925 | g_signal_connect(G_OBJECT(entry),"completion",G_CALLBACK(profile_text_completion),NULL); |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
926 | g_signal_connect(G_OBJECT(entry),"activate",G_CALLBACK(profile_text_load),NULL); |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
927 | gnt_box_add_widget(GNT_BOX(box),entry); |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
928 | button = gnt_button_new("Delete"); |
|
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
929 | g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(prof_del_cb),NULL); |
| 18683 | 930 | gnt_box_add_widget(GNT_BOX(box),button); |
| 931 | gnt_box_add_widget(GNT_BOX(win),box); | |
| 932 | ||
| 933 | /* Add new stuff before this */ | |
|
18678
2fc084ec99cd
Fix a potential bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18620
diff
changeset
|
934 | box = gnt_hbox_new(FALSE); |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
935 | gnt_box_set_pad(GNT_BOX(box),0); |
|
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
936 | gnt_box_set_fill(GNT_BOX(box),TRUE); |
|
18679
c81c8ce38789
Mark some strings for translation.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18678
diff
changeset
|
937 | button = gnt_button_new(_("Save")); |
| 18437 | 938 | g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(save_cb),win); |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
939 | gnt_box_add_widget(GNT_BOX(box),button); |
|
18679
c81c8ce38789
Mark some strings for translation.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
18678
diff
changeset
|
940 | button = gnt_button_new(_("Cancel")); |
|
18440
9d1e67686dfb
Some more work to the sound prefs
Eric Polino <aluink@pidgin.im>
parents:
18439
diff
changeset
|
941 | g_signal_connect_swapped(G_OBJECT(button),"activate",G_CALLBACK(gnt_widget_destroy),win); |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
942 | gnt_box_add_widget(GNT_BOX(box),button); |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
943 | gnt_box_add_widget(GNT_BOX(win),box); |
|
18294
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
944 | |
| 18435 | 945 | g_signal_connect(G_OBJECT(win),"destroy",G_CALLBACK(release_pref_dialog),NULL); |
|
18295
bd26c37841f8
Added more to the Sounds Preferences
Eric Polino <aluink@pidgin.im>
parents:
18294
diff
changeset
|
946 | |
|
18687
ab74f830abfd
Cleaned up a few missing NULL checks in GntWM
Eric Polino <aluink@pidgin.im>
parents:
18686
diff
changeset
|
947 | reload_pref_window(finch_sound_get_active_profile()); |
| 18683 | 948 | |
|
18296
9461f264ee5f
Created SoundPrefDialog to store dialog data.
Eric Polino <aluink@pidgin.im>
parents:
18295
diff
changeset
|
949 | gnt_widget_show(win); |
|
18294
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
950 | |
|
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
951 | } |
|
8186bc6ffbb4
Added Sounds to the actions list
Eric Polino <aluink@pidgin.im>
parents:
18292
diff
changeset
|
952 | |
| 18155 | 953 | static PurpleSoundUiOps sound_ui_ops = |
| 954 | { | |
| 955 | finch_sound_init, | |
| 956 | finch_sound_uninit, | |
| 957 | finch_sound_play_file, | |
| 958 | finch_sound_play_event, | |
| 959 | NULL, | |
| 960 | NULL, | |
| 961 | NULL, | |
| 962 | NULL | |
| 963 | }; | |
| 964 | ||
| 965 | PurpleSoundUiOps * | |
| 966 | finch_sound_get_ui_ops(void) | |
| 967 | { | |
| 968 | return &sound_ui_ops; | |
| 969 | } |