Mercurial > pidgin.yaz
annotate gtk/gtkdocklet.c @ 15005:5e07a6f8eb33
[gaim-migrate @ 17784]
SF Patch #1571670 from zdeqb
"Perl bindings for the functions in core.h and some
bindings for the functions in privacy.h."
I made the following changes:
1. I chose to export gaim_get_core() as Gaim::get_core instead of Gaim::Core::get_core.
2. I don't see any reason to require Perl code to pass bogus values just because C requires them. So, I changed Gaim::Core::quit_cb to NOT take an argument, and to pass NULL to gaim_core_quit_cb().
3. I fixed a typo.
4. I cleaned up some spacing issues.
I noticed that Core.c didn't get created from Core.xs until I re-ran configure. Maybe there's no way to avoid this?
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sun, 19 Nov 2006 19:58:45 +0000 |
parents | 621e798f435c |
children | b188da596c46 |
rev | line source |
---|---|
14681 | 1 /* |
2 * System tray icon (aka docklet) plugin for Gaim | |
3 * | |
4 * Copyright (C) 2002-3 Robert McQueen <robot101@debian.org> | |
5 * Copyright (C) 2003 Herman Bloggs <hermanator12002@yahoo.com> | |
6 * Inspired by a similar plugin by: | |
7 * John (J5) Palmieri <johnp@martianrock.com> | |
8 * | |
9 * This program is free software; you can redistribute it and/or | |
10 * modify it under the terms of the GNU General Public License as | |
11 * published by the Free Software Foundation; either version 2 of the | |
12 * License, or (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 * General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
22 * 02111-1307, USA. | |
23 */ | |
24 #include "internal.h" | |
25 #include "gtkgaim.h" | |
26 | |
27 #include "core.h" | |
28 #include "conversation.h" | |
29 #include "debug.h" | |
30 #include "prefs.h" | |
31 #include "signals.h" | |
32 #include "sound.h" | |
33 | |
34 #include "gtkaccount.h" | |
35 #include "gtkblist.h" | |
36 #include "gtkconv.h" | |
37 #include "gtkplugin.h" | |
38 #include "gtkprefs.h" | |
39 #include "gtksavedstatuses.h" | |
40 #include "gtksound.h" | |
41 #include "gtkutils.h" | |
42 #include "gaimstock.h" | |
43 #include "gtkdocklet.h" | |
44 #include "gtkdialogs.h" | |
45 | |
46 #ifndef DOCKLET_TOOLTIP_LINE_LIMIT | |
47 #define DOCKLET_TOOLTIP_LINE_LIMIT 5 | |
48 #endif | |
49 | |
50 /* globals */ | |
51 static struct docklet_ui_ops *ui_ops = NULL; | |
52 static DockletStatus status = DOCKLET_STATUS_OFFLINE; | |
53 static gboolean enable_join_chat = FALSE; | |
54 static guint docklet_blinking_timer = 0; | |
55 static gboolean visibility_manager = FALSE; | |
56 | |
57 /************************************************************************** | |
58 * docklet status and utility functions | |
59 **************************************************************************/ | |
60 static gboolean | |
61 docklet_blink_icon() | |
62 { | |
63 static gboolean blinked = FALSE; | |
64 gboolean ret = FALSE; /* by default, don't keep blinking */ | |
65 | |
66 blinked = !blinked; | |
67 | |
68 switch (status) { | |
69 case DOCKLET_STATUS_ONLINE_PENDING: | |
70 case DOCKLET_STATUS_AWAY_PENDING: | |
71 if (blinked) { | |
72 if (ui_ops && ui_ops->blank_icon) | |
73 ui_ops->blank_icon(); | |
74 } else { | |
75 if (ui_ops && ui_ops->update_icon) | |
76 ui_ops->update_icon(status); | |
77 } | |
78 ret = TRUE; /* keep blinking */ | |
79 break; | |
80 default: | |
81 docklet_blinking_timer = 0; | |
82 blinked = FALSE; | |
83 break; | |
84 } | |
85 | |
86 return ret; | |
87 } | |
88 | |
89 static GList * | |
90 get_pending_list(guint max) | |
91 { | |
92 GList *l_im = NULL; | |
93 GList *l_chat = NULL; | |
94 | |
14751 | 95 l_im = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM, |
96 GAIM_UNSEEN_TEXT, | |
97 FALSE, max); | |
14681 | 98 |
14751 | 99 l_chat = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_CHAT, |
100 GAIM_UNSEEN_NICK, | |
101 FALSE, max); | |
14681 | 102 |
103 if (l_im != NULL && l_chat != NULL) | |
104 return g_list_concat(l_im, l_chat); | |
105 else if (l_im != NULL) | |
106 return l_im; | |
107 else | |
108 return l_chat; | |
109 } | |
110 | |
111 static gboolean | |
112 docklet_update_status() | |
113 { | |
14813 | 114 GList *convs = NULL; |
14681 | 115 GList *l; |
116 int count; | |
117 DockletStatus newstatus = DOCKLET_STATUS_OFFLINE; | |
118 gboolean pending = FALSE; | |
119 | |
120 /* determine if any ims have unseen messages */ | |
121 convs = get_pending_list(DOCKLET_TOOLTIP_LINE_LIMIT); | |
122 | |
14873 | 123 if (!strcmp(gaim_prefs_get_string("/gaim/gtk/docklet/show"), "pending")) { |
124 if (convs && ui_ops->create && !visibility_manager) { | |
125 ui_ops->create(); | |
126 return FALSE; | |
127 } else if (!convs && ui_ops->destroy && visibility_manager) { | |
128 ui_ops->destroy(); | |
129 return FALSE; | |
130 } | |
131 } | |
132 | |
14885 | 133 if (!visibility_manager) |
134 return FALSE; | |
135 | |
14681 | 136 if (convs != NULL) { |
137 pending = TRUE; | |
138 | |
139 /* set tooltip if messages are pending */ | |
140 if (ui_ops->set_tooltip) { | |
141 GString *tooltip_text = g_string_new(""); | |
142 for (l = convs, count = 0 ; l != NULL ; l = l->next, count++) { | |
143 if (GAIM_IS_GTK_CONVERSATION(l->data)) { | |
144 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION((GaimConversation *)l->data); | |
145 if (count == DOCKLET_TOOLTIP_LINE_LIMIT - 1) | |
146 g_string_append(tooltip_text, _("Right-click for more unread messages...\n")); | |
147 else | |
148 g_string_append_printf(tooltip_text, | |
149 ngettext("%d unread message from %s\n", "%d unread messages from %s\n", gtkconv->unseen_count), | |
150 gtkconv->unseen_count, | |
151 gtk_label_get_text(GTK_LABEL(gtkconv->tab_label))); | |
152 } | |
153 } | |
154 | |
155 /* get rid of the last newline */ | |
156 if (tooltip_text->len > 0) | |
157 tooltip_text = g_string_truncate(tooltip_text, tooltip_text->len - 1); | |
158 | |
159 ui_ops->set_tooltip(tooltip_text->str); | |
160 | |
161 g_string_free(tooltip_text, TRUE); | |
162 } | |
163 | |
164 g_list_free(convs); | |
165 | |
166 } else if (ui_ops->set_tooltip) { | |
167 ui_ops->set_tooltip(NULL); | |
168 } | |
169 | |
170 /* iterate through all accounts and determine which | |
171 * status to show in the tray icon based on the following | |
172 * ranks (highest encountered rank will be used): | |
173 * | |
174 * 1) OFFLINE | |
175 * 2) ONLINE | |
176 * 3) ONLINE_PENDING | |
177 * 4) AWAY | |
178 * 5) AWAY_PENDING | |
179 * 6) CONNECTING | |
180 */ | |
181 for(l = gaim_accounts_get_all(); l != NULL; l = l->next) { | |
182 DockletStatus tmpstatus = DOCKLET_STATUS_OFFLINE; | |
183 | |
184 GaimAccount *account = (GaimAccount*)l->data; | |
185 GaimStatus *account_status; | |
186 | |
187 if (!gaim_account_get_enabled(account, GAIM_GTK_UI)) | |
188 continue; | |
189 | |
190 if (gaim_account_is_disconnected(account)) | |
191 continue; | |
192 | |
193 account_status = gaim_account_get_active_status(account); | |
194 | |
195 if (gaim_account_is_connecting(account)) { | |
196 tmpstatus = DOCKLET_STATUS_CONNECTING; | |
197 } else if (gaim_status_is_online(account_status)) { | |
198 if (!gaim_status_is_available(account_status)) { | |
199 if (pending) | |
200 tmpstatus = DOCKLET_STATUS_AWAY_PENDING; | |
201 else | |
202 tmpstatus = DOCKLET_STATUS_AWAY; | |
203 } | |
204 else { | |
205 if (pending) | |
206 tmpstatus = DOCKLET_STATUS_ONLINE_PENDING; | |
207 else | |
208 tmpstatus = DOCKLET_STATUS_ONLINE; | |
209 } | |
210 } | |
211 | |
212 if (tmpstatus > newstatus) | |
213 newstatus = tmpstatus; | |
214 } | |
215 | |
216 /* update the icon if we changed status */ | |
217 if (status != newstatus) { | |
218 status = newstatus; | |
219 | |
220 if (ui_ops && ui_ops->update_icon) | |
221 ui_ops->update_icon(status); | |
222 | |
223 /* and schedule the blinker function if messages are pending */ | |
14813 | 224 if (gaim_prefs_get_bool("/gaim/gtk/docklet/blink") && |
225 (status == DOCKLET_STATUS_ONLINE_PENDING | |
226 || status == DOCKLET_STATUS_AWAY_PENDING) | |
227 && docklet_blinking_timer == 0) { | |
14681 | 228 docklet_blinking_timer = g_timeout_add(500, docklet_blink_icon, NULL); |
229 } | |
230 } | |
231 | |
232 return FALSE; /* for when we're called by the glib idle handler */ | |
233 } | |
234 | |
235 static gboolean | |
236 online_account_supports_chat() | |
237 { | |
238 GList *c = NULL; | |
239 c = gaim_connections_get_all(); | |
240 | |
241 while(c != NULL) { | |
242 GaimConnection *gc = c->data; | |
243 GaimPluginProtocolInfo *prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
244 if (prpl_info != NULL && prpl_info->chat_info != NULL) | |
245 return TRUE; | |
246 c = c->next; | |
247 } | |
248 | |
249 return FALSE; | |
250 } | |
251 | |
252 /************************************************************************** | |
253 * callbacks and signal handlers | |
254 **************************************************************************/ | |
14683
a8c2af13b96d
[gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14681
diff
changeset
|
255 #if 0 |
14681 | 256 static void |
257 gaim_quit_cb() | |
258 { | |
259 /* TODO: confirm quit while pending */ | |
260 } | |
14683
a8c2af13b96d
[gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14681
diff
changeset
|
261 #endif |
14681 | 262 |
263 static void | |
264 docklet_update_status_cb(void *data) | |
265 { | |
266 docklet_update_status(); | |
267 } | |
268 | |
269 static void | |
270 docklet_conv_updated_cb(GaimConversation *conv, GaimConvUpdateType type) | |
271 { | |
272 if (type == GAIM_CONV_UPDATE_UNSEEN) | |
273 docklet_update_status(); | |
274 } | |
275 | |
276 static void | |
277 docklet_signed_on_cb(GaimConnection *gc) | |
278 { | |
279 if (!enable_join_chat) { | |
280 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info != NULL) | |
281 enable_join_chat = TRUE; | |
282 } | |
283 docklet_update_status(); | |
284 } | |
285 | |
286 static void | |
287 docklet_signed_off_cb(GaimConnection *gc) | |
288 { | |
289 if (enable_join_chat) { | |
290 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info != NULL) | |
291 enable_join_chat = online_account_supports_chat(); | |
292 } | |
293 docklet_update_status(); | |
294 } | |
295 | |
14885 | 296 static void |
297 docklet_show_pref_changed_cb(const char *name, GaimPrefType type, | |
298 gconstpointer value, gpointer data) | |
299 { | |
300 const char *val = value; | |
301 if (!strcmp(val, "always")) { | |
302 if (!visibility_manager && ui_ops->create) | |
303 ui_ops->create(); | |
304 } else if (!strcmp(val, "never")) { | |
305 if (visibility_manager && ui_ops->destroy) | |
306 ui_ops->destroy(); | |
307 } else { | |
308 docklet_update_status(); | |
309 } | |
310 | |
311 } | |
312 | |
14681 | 313 /************************************************************************** |
314 * docklet pop-up menu | |
315 **************************************************************************/ | |
316 static void | |
317 docklet_toggle_mute(GtkWidget *toggle, void *data) | |
318 { | |
319 gaim_prefs_set_bool("/gaim/gtk/sound/mute", GTK_CHECK_MENU_ITEM(toggle)->active); | |
320 } | |
321 | |
322 static void | |
14813 | 323 docklet_toggle_blink(GtkWidget *toggle, void *data) |
324 { | |
325 gaim_prefs_set_bool("/gaim/gtk/docklet/blink", GTK_CHECK_MENU_ITEM(toggle)->active); | |
326 } | |
327 | |
328 static void | |
14681 | 329 docklet_toggle_blist(GtkWidget *toggle, void *data) |
330 { | |
331 gaim_blist_set_visible(GTK_CHECK_MENU_ITEM(toggle)->active); | |
332 } | |
333 | |
334 #ifdef _WIN32 | |
335 /* This is a workaround for a bug in windows GTK+. Clicking outside of the | |
336 menu does not get rid of it, so instead we get rid of it as soon as the | |
337 pointer leaves the menu. */ | |
338 static gboolean | |
339 hide_docklet_menu(gpointer data) | |
340 { | |
341 if (data != NULL) { | |
342 gtk_menu_popdown(GTK_MENU(data)); | |
343 } | |
344 return FALSE; | |
345 } | |
346 | |
347 static gboolean | |
348 docklet_menu_leave_enter(GtkWidget *menu, GdkEventCrossing *event, void *data) | |
349 { | |
350 static guint hide_docklet_timer = 0; | |
351 if (event->type == GDK_LEAVE_NOTIFY && event->detail == GDK_NOTIFY_ANCESTOR) { | |
352 gaim_debug(GAIM_DEBUG_INFO, "docklet", "menu leave-notify-event\n"); | |
353 /* Add some slop so that the menu doesn't annoyingly disappear when mousing around */ | |
354 if (hide_docklet_timer == 0) { | |
355 hide_docklet_timer = gaim_timeout_add(500, | |
356 hide_docklet_menu, menu); | |
357 } | |
358 } else if (event->type == GDK_ENTER_NOTIFY && event->detail == GDK_NOTIFY_ANCESTOR) { | |
359 gaim_debug(GAIM_DEBUG_INFO, "docklet", "menu enter-notify-event\n"); | |
360 if (hide_docklet_timer != 0) { | |
361 /* Cancel the hiding if we reenter */ | |
362 | |
363 gaim_timeout_remove(hide_docklet_timer); | |
364 hide_docklet_timer = 0; | |
365 } | |
366 } | |
367 return FALSE; | |
368 } | |
369 #endif | |
370 | |
371 static void | |
372 show_custom_status_editor_cb(GtkMenuItem *menuitem, gpointer user_data) | |
373 { | |
374 GaimSavedStatus *saved_status; | |
375 saved_status = gaim_savedstatus_get_current(); | |
376 gaim_gtk_status_editor_show(FALSE, | |
377 gaim_savedstatus_is_transient(saved_status) ? saved_status : NULL); | |
378 } | |
379 | |
380 static void | |
381 activate_status_primitive_cb(GtkMenuItem *menuitem, gpointer user_data) | |
382 { | |
383 GaimStatusPrimitive primitive; | |
384 GaimSavedStatus *saved_status; | |
385 | |
386 primitive = GPOINTER_TO_INT(user_data); | |
387 | |
388 /* Try to lookup an already existing transient saved status */ | |
389 saved_status = gaim_savedstatus_find_transient_by_type_and_message(primitive, NULL); | |
390 | |
391 /* Create a new transient saved status if we weren't able to find one */ | |
392 if (saved_status == NULL) | |
393 saved_status = gaim_savedstatus_new(NULL, primitive); | |
394 | |
395 /* Set the status for each account */ | |
396 gaim_savedstatus_activate(saved_status); | |
397 } | |
398 | |
399 static void | |
400 activate_saved_status_cb(GtkMenuItem *menuitem, gpointer user_data) | |
401 { | |
402 time_t creation_time; | |
403 GaimSavedStatus *saved_status; | |
404 | |
405 creation_time = GPOINTER_TO_INT(user_data); | |
406 saved_status = gaim_savedstatus_find_by_creation_time(creation_time); | |
407 if (saved_status != NULL) | |
408 gaim_savedstatus_activate(saved_status); | |
409 } | |
410 | |
411 static GtkWidget * | |
412 new_menu_item_with_gaim_icon(GtkWidget *menu, const char *str, GaimStatusPrimitive primitive, GtkSignalFunc sf, gpointer data, guint accel_key, guint accel_mods, char *mod) | |
413 { | |
414 GtkWidget *menuitem; | |
415 GdkPixbuf *pixbuf; | |
416 GtkWidget *image; | |
417 | |
418 menuitem = gtk_image_menu_item_new_with_mnemonic(str); | |
419 | |
420 if (menu) | |
421 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
422 | |
423 if (sf) | |
424 g_signal_connect(G_OBJECT(menuitem), "activate", sf, data); | |
425 | |
426 pixbuf = gaim_gtk_create_gaim_icon_with_status(primitive, 0.5); | |
427 image = gtk_image_new_from_pixbuf(pixbuf); | |
428 g_object_unref(pixbuf); | |
429 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); | |
430 | |
431 gtk_widget_show_all(menuitem); | |
432 | |
433 return menuitem; | |
434 } | |
435 | |
436 static GtkWidget * | |
437 docklet_status_submenu() | |
438 { | |
439 GtkWidget *submenu, *menuitem; | |
440 GList *popular_statuses, *cur; | |
441 | |
442 submenu = gtk_menu_new(); | |
443 menuitem = gtk_menu_item_new_with_label(_("Change Status")); | |
444 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); | |
445 | |
446 new_menu_item_with_gaim_icon(submenu, _("Available"), | |
447 GAIM_STATUS_AVAILABLE, G_CALLBACK(activate_status_primitive_cb), | |
448 GINT_TO_POINTER(GAIM_STATUS_AVAILABLE), 0, 0, NULL); | |
449 | |
450 new_menu_item_with_gaim_icon(submenu, _("Away"), | |
451 GAIM_STATUS_AWAY, G_CALLBACK(activate_status_primitive_cb), | |
452 GINT_TO_POINTER(GAIM_STATUS_AWAY), 0, 0, NULL); | |
453 | |
454 new_menu_item_with_gaim_icon(submenu, _("Invisible"), | |
455 GAIM_STATUS_INVISIBLE, G_CALLBACK(activate_status_primitive_cb), | |
456 GINT_TO_POINTER(GAIM_STATUS_INVISIBLE), 0, 0, NULL); | |
457 | |
458 new_menu_item_with_gaim_icon(submenu, _("Offline"), | |
459 GAIM_STATUS_OFFLINE, G_CALLBACK(activate_status_primitive_cb), | |
460 GINT_TO_POINTER(GAIM_STATUS_OFFLINE), 0, 0, NULL); | |
461 | |
462 popular_statuses = gaim_savedstatuses_get_popular(6); | |
463 if (popular_statuses != NULL) | |
464 gaim_separator(submenu); | |
465 for (cur = popular_statuses; cur != NULL; cur = cur->next) | |
466 { | |
467 GaimSavedStatus *saved_status = cur->data; | |
468 time_t creation_time = gaim_savedstatus_get_creation_time(saved_status); | |
469 new_menu_item_with_gaim_icon(submenu, | |
470 gaim_savedstatus_get_title(saved_status), | |
471 gaim_savedstatus_get_type(saved_status), G_CALLBACK(activate_saved_status_cb), | |
472 GINT_TO_POINTER(creation_time), 0, 0, NULL); | |
473 } | |
474 g_list_free(popular_statuses); | |
475 | |
476 gaim_separator(submenu); | |
477 | |
478 new_menu_item_with_gaim_icon(submenu, _("New..."), GAIM_STATUS_AVAILABLE, G_CALLBACK(show_custom_status_editor_cb), NULL, 0, 0, NULL); | |
479 new_menu_item_with_gaim_icon(submenu, _("Saved..."), GAIM_STATUS_AVAILABLE, G_CALLBACK(gaim_gtk_status_window_show), NULL, 0, 0, NULL); | |
480 | |
481 return menuitem; | |
482 } | |
483 | |
484 static void | |
485 docklet_menu() { | |
486 static GtkWidget *menu = NULL; | |
487 GtkWidget *menuitem; | |
488 | |
489 if (menu) { | |
490 gtk_widget_destroy(menu); | |
491 } | |
492 | |
493 menu = gtk_menu_new(); | |
494 | |
495 menuitem = gtk_check_menu_item_new_with_label(_("Show Buddy List")); | |
496 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), gaim_prefs_get_bool("/gaim/gtk/blist/list_visible")); | |
497 g_signal_connect(G_OBJECT(menuitem), "toggled", G_CALLBACK(docklet_toggle_blist), NULL); | |
498 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
499 | |
500 menuitem = gtk_menu_item_new_with_label(_("Unread Messages")); | |
501 | |
502 if (status == DOCKLET_STATUS_ONLINE_PENDING || status == DOCKLET_STATUS_AWAY_PENDING) { | |
503 GtkWidget *submenu = gtk_menu_new(); | |
504 GList *l = get_pending_list(0); | |
505 if (l == NULL) { | |
506 gtk_widget_set_sensitive(menuitem, FALSE); | |
507 gaim_debug_warning("docklet", | |
508 "status indicates messages pending, but no conversations with unseen messages were found."); | |
509 } else { | |
510 gaim_gtk_conversations_fill_menu(submenu, l); | |
511 g_list_free(l); | |
512 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); | |
513 } | |
514 } else { | |
515 gtk_widget_set_sensitive(menuitem, FALSE); | |
516 } | |
517 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
518 | |
519 gaim_separator(menu); | |
520 | |
521 menuitem = gaim_new_item_from_stock(menu, _("New Message..."), GAIM_STOCK_IM, G_CALLBACK(gaim_gtkdialogs_im), NULL, 0, 0, NULL); | |
522 if (status == DOCKLET_STATUS_OFFLINE) | |
523 gtk_widget_set_sensitive(menuitem, FALSE); | |
524 | |
525 menuitem = docklet_status_submenu(); | |
526 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
527 | |
528 gaim_separator(menu); | |
529 | |
530 gaim_new_item_from_stock(menu, _("Accounts"), GAIM_STOCK_ACCOUNTS, G_CALLBACK(gaim_gtk_accounts_window_show), NULL, 0, 0, NULL); | |
531 gaim_new_item_from_stock(menu, _("Plugins"), GAIM_STOCK_PLUGIN, G_CALLBACK(gaim_gtk_plugin_dialog_show), NULL, 0, 0, NULL); | |
532 gaim_new_item_from_stock(menu, _("Preferences"), GTK_STOCK_PREFERENCES, G_CALLBACK(gaim_gtk_prefs_show), NULL, 0, 0, NULL); | |
533 | |
534 gaim_separator(menu); | |
535 | |
536 menuitem = gtk_check_menu_item_new_with_label(_("Mute Sounds")); | |
537 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), gaim_prefs_get_bool("/gaim/gtk/sound/mute")); | |
538 if (!strcmp(gaim_prefs_get_string("/gaim/gtk/sound/method"), "none")) | |
539 gtk_widget_set_sensitive(GTK_WIDGET(menuitem), FALSE); | |
540 g_signal_connect(G_OBJECT(menuitem), "toggled", G_CALLBACK(docklet_toggle_mute), NULL); | |
541 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
14813 | 542 |
543 menuitem = gtk_check_menu_item_new_with_label(_("Blink on new message")); | |
544 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), gaim_prefs_get_bool("/gaim/gtk/docklet/blink")); | |
545 g_signal_connect(G_OBJECT(menuitem), "toggled", G_CALLBACK(docklet_toggle_blink), NULL); | |
546 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
14681 | 547 |
548 gaim_separator(menu); | |
549 | |
550 /* TODO: need a submenu to change status, this needs to "link" | |
551 * to the status in the buddy list gtkstatusbox | |
552 */ | |
553 | |
554 gaim_new_item_from_stock(menu, _("Quit"), GTK_STOCK_QUIT, G_CALLBACK(gaim_core_quit), NULL, 0, 0, NULL); | |
555 | |
556 #ifdef _WIN32 | |
557 g_signal_connect(menu, "leave-notify-event", G_CALLBACK(docklet_menu_leave_enter), NULL); | |
558 g_signal_connect(menu, "enter-notify-event", G_CALLBACK(docklet_menu_leave_enter), NULL); | |
559 #endif | |
560 gtk_widget_show_all(menu); | |
561 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, | |
562 ui_ops->position_menu, | |
563 NULL, 0, gtk_get_current_event_time()); | |
564 } | |
565 | |
566 /************************************************************************** | |
567 * public api for ui_ops | |
568 **************************************************************************/ | |
569 void | |
570 gaim_gtk_docklet_clicked(int button_type) | |
571 { | |
572 switch (button_type) { | |
573 case 1: | |
574 if (status == DOCKLET_STATUS_ONLINE_PENDING || status == DOCKLET_STATUS_AWAY_PENDING) { | |
575 GList *l = get_pending_list(1); | |
576 if (l != NULL) { | |
577 gaim_gtkconv_present_conversation((GaimConversation *)l->data); | |
578 g_list_free(l); | |
579 } | |
580 } else { | |
581 gaim_gtk_blist_toggle_visibility(); | |
582 } | |
583 break; | |
584 case 3: | |
585 docklet_menu(); | |
586 break; | |
587 } | |
588 } | |
589 | |
590 void | |
591 gaim_gtk_docklet_embedded() | |
592 { | |
593 if (!visibility_manager) { | |
14873 | 594 if (strcmp(gaim_prefs_get_string("/gaim/gtk/docklet/show"),"pending")) |
595 gaim_gtk_blist_visibility_manager_add(); | |
14681 | 596 visibility_manager = TRUE; |
597 } | |
598 docklet_update_status(); | |
599 if (ui_ops && ui_ops->update_icon) | |
600 ui_ops->update_icon(status); | |
601 } | |
602 | |
603 void | |
604 gaim_gtk_docklet_remove() | |
605 { | |
606 if (visibility_manager) { | |
14892 | 607 if (strcmp(gaim_prefs_get_string("/gaim/gtk/docklet/show"),"pending")) |
608 gaim_gtk_blist_visibility_manager_remove(); | |
14873 | 609 if (docklet_blinking_timer) { |
610 g_source_remove(docklet_blinking_timer); | |
611 docklet_blinking_timer = 0; | |
612 } | |
14681 | 613 visibility_manager = FALSE; |
14873 | 614 status = DOCKLET_STATUS_OFFLINE; |
14681 | 615 } |
616 } | |
617 | |
618 void | |
619 gaim_gtk_docklet_set_ui_ops(struct docklet_ui_ops *ops) | |
620 { | |
621 ui_ops = ops; | |
622 } | |
623 | |
624 void* | |
625 gaim_gtk_docklet_get_handle() | |
626 { | |
627 static int i; | |
628 return &i; | |
629 } | |
630 | |
14683
a8c2af13b96d
[gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14681
diff
changeset
|
631 void |
14681 | 632 gaim_gtk_docklet_init() |
633 { | |
634 void *conn_handle = gaim_connections_get_handle(); | |
635 void *conv_handle = gaim_conversations_get_handle(); | |
636 void *accounts_handle = gaim_accounts_get_handle(); | |
637 void *docklet_handle = gaim_gtk_docklet_get_handle(); | |
14813 | 638 |
639 gaim_prefs_add_none("/gaim/gtk/docklet"); | |
640 gaim_prefs_add_bool("/gaim/gtk/docklet/blink", FALSE); | |
641 gaim_prefs_add_string("/gaim/gtk/docklet/show", "always"); | |
14885 | 642 gaim_prefs_connect_callback(docklet_handle, "/gaim/gtk/docklet/show", |
643 docklet_show_pref_changed_cb, NULL); | |
14681 | 644 |
645 docklet_ui_init(); | |
14873 | 646 if (!strcmp(gaim_prefs_get_string("/gaim/gtk/docklet/show"), "always") && ui_ops && ui_ops->create) |
14681 | 647 ui_ops->create(); |
14873 | 648 |
14681 | 649 gaim_signal_connect(conn_handle, "signed-on", |
14683
a8c2af13b96d
[gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14681
diff
changeset
|
650 docklet_handle, GAIM_CALLBACK(docklet_signed_on_cb), NULL); |
14681 | 651 gaim_signal_connect(conn_handle, "signed-off", |
652 docklet_handle, GAIM_CALLBACK(docklet_signed_off_cb), NULL); | |
653 gaim_signal_connect(accounts_handle, "account-status-changed", | |
654 docklet_handle, GAIM_CALLBACK(docklet_update_status_cb), NULL); | |
655 gaim_signal_connect(conv_handle, "received-im-msg", | |
656 docklet_handle, GAIM_CALLBACK(docklet_update_status_cb), NULL); | |
657 gaim_signal_connect(conv_handle, "conversation-created", | |
658 docklet_handle, GAIM_CALLBACK(docklet_update_status_cb), NULL); | |
659 gaim_signal_connect(conv_handle, "deleting-conversation", | |
660 docklet_handle, GAIM_CALLBACK(docklet_update_status_cb), NULL); | |
661 gaim_signal_connect(conv_handle, "conversation-updated", | |
662 docklet_handle, GAIM_CALLBACK(docklet_conv_updated_cb), NULL); | |
14683
a8c2af13b96d
[gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14681
diff
changeset
|
663 #if 0 |
a8c2af13b96d
[gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14681
diff
changeset
|
664 gaim_signal_connect(gaim_get_core(), "quitting", |
a8c2af13b96d
[gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14681
diff
changeset
|
665 docklet_handle, GAIM_CALLBACK(gaim_quit_cb), NULL); |
a8c2af13b96d
[gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14681
diff
changeset
|
666 #endif |
14681 | 667 |
668 enable_join_chat = online_account_supports_chat(); | |
669 } | |
670 | |
671 void | |
672 gaim_gtk_docklet_uninit() | |
673 { | |
14873 | 674 if (visibility_manager && ui_ops && ui_ops->destroy) |
14681 | 675 ui_ops->destroy(); |
676 } |