Mercurial > pidgin.yaz
annotate gtk/gtkdocklet.c @ 14873:3a23706f9f4b
[gaim-migrate @ 17642]
Show icon pref. No way to change it yet (other than your editor)
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Wed, 01 Nov 2006 00:57:39 +0000 |
parents | dd000ac4d148 |
children | 51c51d89c114 |
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 } else if (!visibility_manager) { | |
131 return FALSE; | |
132 } | |
133 } | |
134 | |
14681 | 135 if (convs != NULL) { |
136 pending = TRUE; | |
137 | |
138 /* set tooltip if messages are pending */ | |
139 if (ui_ops->set_tooltip) { | |
140 GString *tooltip_text = g_string_new(""); | |
141 for (l = convs, count = 0 ; l != NULL ; l = l->next, count++) { | |
142 if (GAIM_IS_GTK_CONVERSATION(l->data)) { | |
143 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION((GaimConversation *)l->data); | |
144 if (count == DOCKLET_TOOLTIP_LINE_LIMIT - 1) | |
145 g_string_append(tooltip_text, _("Right-click for more unread messages...\n")); | |
146 else | |
147 g_string_append_printf(tooltip_text, | |
148 ngettext("%d unread message from %s\n", "%d unread messages from %s\n", gtkconv->unseen_count), | |
149 gtkconv->unseen_count, | |
150 gtk_label_get_text(GTK_LABEL(gtkconv->tab_label))); | |
151 } | |
152 } | |
153 | |
154 /* get rid of the last newline */ | |
155 if (tooltip_text->len > 0) | |
156 tooltip_text = g_string_truncate(tooltip_text, tooltip_text->len - 1); | |
157 | |
158 ui_ops->set_tooltip(tooltip_text->str); | |
159 | |
160 g_string_free(tooltip_text, TRUE); | |
161 } | |
162 | |
163 g_list_free(convs); | |
164 | |
165 } else if (ui_ops->set_tooltip) { | |
166 ui_ops->set_tooltip(NULL); | |
167 } | |
168 | |
169 /* iterate through all accounts and determine which | |
170 * status to show in the tray icon based on the following | |
171 * ranks (highest encountered rank will be used): | |
172 * | |
173 * 1) OFFLINE | |
174 * 2) ONLINE | |
175 * 3) ONLINE_PENDING | |
176 * 4) AWAY | |
177 * 5) AWAY_PENDING | |
178 * 6) CONNECTING | |
179 */ | |
180 for(l = gaim_accounts_get_all(); l != NULL; l = l->next) { | |
181 DockletStatus tmpstatus = DOCKLET_STATUS_OFFLINE; | |
182 | |
183 GaimAccount *account = (GaimAccount*)l->data; | |
184 GaimStatus *account_status; | |
185 | |
186 if (!gaim_account_get_enabled(account, GAIM_GTK_UI)) | |
187 continue; | |
188 | |
189 if (gaim_account_is_disconnected(account)) | |
190 continue; | |
191 | |
192 account_status = gaim_account_get_active_status(account); | |
193 | |
194 if (gaim_account_is_connecting(account)) { | |
195 tmpstatus = DOCKLET_STATUS_CONNECTING; | |
196 } else if (gaim_status_is_online(account_status)) { | |
197 if (!gaim_status_is_available(account_status)) { | |
198 if (pending) | |
199 tmpstatus = DOCKLET_STATUS_AWAY_PENDING; | |
200 else | |
201 tmpstatus = DOCKLET_STATUS_AWAY; | |
202 } | |
203 else { | |
204 if (pending) | |
205 tmpstatus = DOCKLET_STATUS_ONLINE_PENDING; | |
206 else | |
207 tmpstatus = DOCKLET_STATUS_ONLINE; | |
208 } | |
209 } | |
210 | |
211 if (tmpstatus > newstatus) | |
212 newstatus = tmpstatus; | |
213 } | |
214 | |
215 /* update the icon if we changed status */ | |
216 if (status != newstatus) { | |
217 status = newstatus; | |
218 | |
219 if (ui_ops && ui_ops->update_icon) | |
220 ui_ops->update_icon(status); | |
221 | |
222 /* and schedule the blinker function if messages are pending */ | |
14813 | 223 if (gaim_prefs_get_bool("/gaim/gtk/docklet/blink") && |
224 (status == DOCKLET_STATUS_ONLINE_PENDING | |
225 || status == DOCKLET_STATUS_AWAY_PENDING) | |
226 && docklet_blinking_timer == 0) { | |
14681 | 227 docklet_blinking_timer = g_timeout_add(500, docklet_blink_icon, NULL); |
228 } | |
229 } | |
230 | |
231 return FALSE; /* for when we're called by the glib idle handler */ | |
232 } | |
233 | |
234 static gboolean | |
235 online_account_supports_chat() | |
236 { | |
237 GList *c = NULL; | |
238 c = gaim_connections_get_all(); | |
239 | |
240 while(c != NULL) { | |
241 GaimConnection *gc = c->data; | |
242 GaimPluginProtocolInfo *prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
243 if (prpl_info != NULL && prpl_info->chat_info != NULL) | |
244 return TRUE; | |
245 c = c->next; | |
246 } | |
247 | |
248 return FALSE; | |
249 } | |
250 | |
251 /************************************************************************** | |
252 * callbacks and signal handlers | |
253 **************************************************************************/ | |
14683
a8c2af13b96d
[gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14681
diff
changeset
|
254 #if 0 |
14681 | 255 static void |
256 gaim_quit_cb() | |
257 { | |
258 /* TODO: confirm quit while pending */ | |
259 } | |
14683
a8c2af13b96d
[gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14681
diff
changeset
|
260 #endif |
14681 | 261 |
262 static void | |
263 docklet_update_status_cb(void *data) | |
264 { | |
265 docklet_update_status(); | |
266 } | |
267 | |
268 static void | |
269 docklet_conv_updated_cb(GaimConversation *conv, GaimConvUpdateType type) | |
270 { | |
271 if (type == GAIM_CONV_UPDATE_UNSEEN) | |
272 docklet_update_status(); | |
273 } | |
274 | |
275 static void | |
276 docklet_signed_on_cb(GaimConnection *gc) | |
277 { | |
278 if (!enable_join_chat) { | |
279 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info != NULL) | |
280 enable_join_chat = TRUE; | |
281 } | |
282 docklet_update_status(); | |
283 } | |
284 | |
285 static void | |
286 docklet_signed_off_cb(GaimConnection *gc) | |
287 { | |
288 if (enable_join_chat) { | |
289 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info != NULL) | |
290 enable_join_chat = online_account_supports_chat(); | |
291 } | |
292 docklet_update_status(); | |
293 } | |
294 | |
295 /************************************************************************** | |
296 * docklet pop-up menu | |
297 **************************************************************************/ | |
298 static void | |
299 docklet_toggle_mute(GtkWidget *toggle, void *data) | |
300 { | |
301 gaim_prefs_set_bool("/gaim/gtk/sound/mute", GTK_CHECK_MENU_ITEM(toggle)->active); | |
302 } | |
303 | |
304 static void | |
14813 | 305 docklet_toggle_blink(GtkWidget *toggle, void *data) |
306 { | |
307 gaim_prefs_set_bool("/gaim/gtk/docklet/blink", GTK_CHECK_MENU_ITEM(toggle)->active); | |
308 } | |
309 | |
310 static void | |
14681 | 311 docklet_toggle_blist(GtkWidget *toggle, void *data) |
312 { | |
313 gaim_blist_set_visible(GTK_CHECK_MENU_ITEM(toggle)->active); | |
314 } | |
315 | |
316 #ifdef _WIN32 | |
317 /* This is a workaround for a bug in windows GTK+. Clicking outside of the | |
318 menu does not get rid of it, so instead we get rid of it as soon as the | |
319 pointer leaves the menu. */ | |
320 static gboolean | |
321 hide_docklet_menu(gpointer data) | |
322 { | |
323 if (data != NULL) { | |
324 gtk_menu_popdown(GTK_MENU(data)); | |
325 } | |
326 return FALSE; | |
327 } | |
328 | |
329 static gboolean | |
330 docklet_menu_leave_enter(GtkWidget *menu, GdkEventCrossing *event, void *data) | |
331 { | |
332 static guint hide_docklet_timer = 0; | |
333 if (event->type == GDK_LEAVE_NOTIFY && event->detail == GDK_NOTIFY_ANCESTOR) { | |
334 gaim_debug(GAIM_DEBUG_INFO, "docklet", "menu leave-notify-event\n"); | |
335 /* Add some slop so that the menu doesn't annoyingly disappear when mousing around */ | |
336 if (hide_docklet_timer == 0) { | |
337 hide_docklet_timer = gaim_timeout_add(500, | |
338 hide_docklet_menu, menu); | |
339 } | |
340 } else if (event->type == GDK_ENTER_NOTIFY && event->detail == GDK_NOTIFY_ANCESTOR) { | |
341 gaim_debug(GAIM_DEBUG_INFO, "docklet", "menu enter-notify-event\n"); | |
342 if (hide_docklet_timer != 0) { | |
343 /* Cancel the hiding if we reenter */ | |
344 | |
345 gaim_timeout_remove(hide_docklet_timer); | |
346 hide_docklet_timer = 0; | |
347 } | |
348 } | |
349 return FALSE; | |
350 } | |
351 #endif | |
352 | |
353 static void | |
354 show_custom_status_editor_cb(GtkMenuItem *menuitem, gpointer user_data) | |
355 { | |
356 GaimSavedStatus *saved_status; | |
357 saved_status = gaim_savedstatus_get_current(); | |
358 gaim_gtk_status_editor_show(FALSE, | |
359 gaim_savedstatus_is_transient(saved_status) ? saved_status : NULL); | |
360 } | |
361 | |
362 static void | |
363 activate_status_primitive_cb(GtkMenuItem *menuitem, gpointer user_data) | |
364 { | |
365 GaimStatusPrimitive primitive; | |
366 GaimSavedStatus *saved_status; | |
367 | |
368 primitive = GPOINTER_TO_INT(user_data); | |
369 | |
370 /* Try to lookup an already existing transient saved status */ | |
371 saved_status = gaim_savedstatus_find_transient_by_type_and_message(primitive, NULL); | |
372 | |
373 /* Create a new transient saved status if we weren't able to find one */ | |
374 if (saved_status == NULL) | |
375 saved_status = gaim_savedstatus_new(NULL, primitive); | |
376 | |
377 /* Set the status for each account */ | |
378 gaim_savedstatus_activate(saved_status); | |
379 } | |
380 | |
381 static void | |
382 activate_saved_status_cb(GtkMenuItem *menuitem, gpointer user_data) | |
383 { | |
384 time_t creation_time; | |
385 GaimSavedStatus *saved_status; | |
386 | |
387 creation_time = GPOINTER_TO_INT(user_data); | |
388 saved_status = gaim_savedstatus_find_by_creation_time(creation_time); | |
389 if (saved_status != NULL) | |
390 gaim_savedstatus_activate(saved_status); | |
391 } | |
392 | |
393 static GtkWidget * | |
394 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) | |
395 { | |
396 GtkWidget *menuitem; | |
397 GdkPixbuf *pixbuf; | |
398 GtkWidget *image; | |
399 | |
400 menuitem = gtk_image_menu_item_new_with_mnemonic(str); | |
401 | |
402 if (menu) | |
403 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
404 | |
405 if (sf) | |
406 g_signal_connect(G_OBJECT(menuitem), "activate", sf, data); | |
407 | |
408 pixbuf = gaim_gtk_create_gaim_icon_with_status(primitive, 0.5); | |
409 image = gtk_image_new_from_pixbuf(pixbuf); | |
410 g_object_unref(pixbuf); | |
411 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); | |
412 | |
413 gtk_widget_show_all(menuitem); | |
414 | |
415 return menuitem; | |
416 } | |
417 | |
418 static GtkWidget * | |
419 docklet_status_submenu() | |
420 { | |
421 GtkWidget *submenu, *menuitem; | |
422 GList *popular_statuses, *cur; | |
423 | |
424 submenu = gtk_menu_new(); | |
425 menuitem = gtk_menu_item_new_with_label(_("Change Status")); | |
426 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); | |
427 | |
428 new_menu_item_with_gaim_icon(submenu, _("Available"), | |
429 GAIM_STATUS_AVAILABLE, G_CALLBACK(activate_status_primitive_cb), | |
430 GINT_TO_POINTER(GAIM_STATUS_AVAILABLE), 0, 0, NULL); | |
431 | |
432 new_menu_item_with_gaim_icon(submenu, _("Away"), | |
433 GAIM_STATUS_AWAY, G_CALLBACK(activate_status_primitive_cb), | |
434 GINT_TO_POINTER(GAIM_STATUS_AWAY), 0, 0, NULL); | |
435 | |
436 new_menu_item_with_gaim_icon(submenu, _("Invisible"), | |
437 GAIM_STATUS_INVISIBLE, G_CALLBACK(activate_status_primitive_cb), | |
438 GINT_TO_POINTER(GAIM_STATUS_INVISIBLE), 0, 0, NULL); | |
439 | |
440 new_menu_item_with_gaim_icon(submenu, _("Offline"), | |
441 GAIM_STATUS_OFFLINE, G_CALLBACK(activate_status_primitive_cb), | |
442 GINT_TO_POINTER(GAIM_STATUS_OFFLINE), 0, 0, NULL); | |
443 | |
444 popular_statuses = gaim_savedstatuses_get_popular(6); | |
445 if (popular_statuses != NULL) | |
446 gaim_separator(submenu); | |
447 for (cur = popular_statuses; cur != NULL; cur = cur->next) | |
448 { | |
449 GaimSavedStatus *saved_status = cur->data; | |
450 time_t creation_time = gaim_savedstatus_get_creation_time(saved_status); | |
451 new_menu_item_with_gaim_icon(submenu, | |
452 gaim_savedstatus_get_title(saved_status), | |
453 gaim_savedstatus_get_type(saved_status), G_CALLBACK(activate_saved_status_cb), | |
454 GINT_TO_POINTER(creation_time), 0, 0, NULL); | |
455 } | |
456 g_list_free(popular_statuses); | |
457 | |
458 gaim_separator(submenu); | |
459 | |
460 new_menu_item_with_gaim_icon(submenu, _("New..."), GAIM_STATUS_AVAILABLE, G_CALLBACK(show_custom_status_editor_cb), NULL, 0, 0, NULL); | |
461 new_menu_item_with_gaim_icon(submenu, _("Saved..."), GAIM_STATUS_AVAILABLE, G_CALLBACK(gaim_gtk_status_window_show), NULL, 0, 0, NULL); | |
462 | |
463 return menuitem; | |
464 } | |
465 | |
466 static void | |
467 docklet_menu() { | |
468 static GtkWidget *menu = NULL; | |
469 GtkWidget *menuitem; | |
470 | |
471 if (menu) { | |
472 gtk_widget_destroy(menu); | |
473 } | |
474 | |
475 menu = gtk_menu_new(); | |
476 | |
477 menuitem = gtk_check_menu_item_new_with_label(_("Show Buddy List")); | |
478 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), gaim_prefs_get_bool("/gaim/gtk/blist/list_visible")); | |
479 g_signal_connect(G_OBJECT(menuitem), "toggled", G_CALLBACK(docklet_toggle_blist), NULL); | |
480 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
481 | |
482 menuitem = gtk_menu_item_new_with_label(_("Unread Messages")); | |
483 | |
484 if (status == DOCKLET_STATUS_ONLINE_PENDING || status == DOCKLET_STATUS_AWAY_PENDING) { | |
485 GtkWidget *submenu = gtk_menu_new(); | |
486 GList *l = get_pending_list(0); | |
487 if (l == NULL) { | |
488 gtk_widget_set_sensitive(menuitem, FALSE); | |
489 gaim_debug_warning("docklet", | |
490 "status indicates messages pending, but no conversations with unseen messages were found."); | |
491 } else { | |
492 gaim_gtk_conversations_fill_menu(submenu, l); | |
493 g_list_free(l); | |
494 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); | |
495 } | |
496 } else { | |
497 gtk_widget_set_sensitive(menuitem, FALSE); | |
498 } | |
499 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
500 | |
501 gaim_separator(menu); | |
502 | |
503 menuitem = gaim_new_item_from_stock(menu, _("New Message..."), GAIM_STOCK_IM, G_CALLBACK(gaim_gtkdialogs_im), NULL, 0, 0, NULL); | |
504 if (status == DOCKLET_STATUS_OFFLINE) | |
505 gtk_widget_set_sensitive(menuitem, FALSE); | |
506 | |
507 menuitem = docklet_status_submenu(); | |
508 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
509 | |
510 gaim_separator(menu); | |
511 | |
512 gaim_new_item_from_stock(menu, _("Accounts"), GAIM_STOCK_ACCOUNTS, G_CALLBACK(gaim_gtk_accounts_window_show), NULL, 0, 0, NULL); | |
513 gaim_new_item_from_stock(menu, _("Plugins"), GAIM_STOCK_PLUGIN, G_CALLBACK(gaim_gtk_plugin_dialog_show), NULL, 0, 0, NULL); | |
514 gaim_new_item_from_stock(menu, _("Preferences"), GTK_STOCK_PREFERENCES, G_CALLBACK(gaim_gtk_prefs_show), NULL, 0, 0, NULL); | |
515 | |
516 gaim_separator(menu); | |
517 | |
518 menuitem = gtk_check_menu_item_new_with_label(_("Mute Sounds")); | |
519 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), gaim_prefs_get_bool("/gaim/gtk/sound/mute")); | |
520 if (!strcmp(gaim_prefs_get_string("/gaim/gtk/sound/method"), "none")) | |
521 gtk_widget_set_sensitive(GTK_WIDGET(menuitem), FALSE); | |
522 g_signal_connect(G_OBJECT(menuitem), "toggled", G_CALLBACK(docklet_toggle_mute), NULL); | |
523 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
14813 | 524 |
525 menuitem = gtk_check_menu_item_new_with_label(_("Blink on new message")); | |
526 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), gaim_prefs_get_bool("/gaim/gtk/docklet/blink")); | |
527 g_signal_connect(G_OBJECT(menuitem), "toggled", G_CALLBACK(docklet_toggle_blink), NULL); | |
528 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
14681 | 529 |
530 gaim_separator(menu); | |
531 | |
532 /* TODO: need a submenu to change status, this needs to "link" | |
533 * to the status in the buddy list gtkstatusbox | |
534 */ | |
535 | |
536 gaim_new_item_from_stock(menu, _("Quit"), GTK_STOCK_QUIT, G_CALLBACK(gaim_core_quit), NULL, 0, 0, NULL); | |
537 | |
538 #ifdef _WIN32 | |
539 g_signal_connect(menu, "leave-notify-event", G_CALLBACK(docklet_menu_leave_enter), NULL); | |
540 g_signal_connect(menu, "enter-notify-event", G_CALLBACK(docklet_menu_leave_enter), NULL); | |
541 #endif | |
542 gtk_widget_show_all(menu); | |
543 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, | |
544 ui_ops->position_menu, | |
545 NULL, 0, gtk_get_current_event_time()); | |
546 } | |
547 | |
548 /************************************************************************** | |
549 * public api for ui_ops | |
550 **************************************************************************/ | |
551 void | |
552 gaim_gtk_docklet_clicked(int button_type) | |
553 { | |
554 switch (button_type) { | |
555 case 1: | |
556 if (status == DOCKLET_STATUS_ONLINE_PENDING || status == DOCKLET_STATUS_AWAY_PENDING) { | |
557 GList *l = get_pending_list(1); | |
558 if (l != NULL) { | |
559 gaim_gtkconv_present_conversation((GaimConversation *)l->data); | |
560 g_list_free(l); | |
561 } | |
562 } else { | |
563 gaim_gtk_blist_toggle_visibility(); | |
564 } | |
565 break; | |
566 case 3: | |
567 docklet_menu(); | |
568 break; | |
569 } | |
570 } | |
571 | |
572 void | |
573 gaim_gtk_docklet_embedded() | |
574 { | |
575 if (!visibility_manager) { | |
14873 | 576 if (strcmp(gaim_prefs_get_string("/gaim/gtk/docklet/show"),"pending")) |
577 gaim_gtk_blist_visibility_manager_add(); | |
14681 | 578 visibility_manager = TRUE; |
579 } | |
580 docklet_update_status(); | |
581 if (ui_ops && ui_ops->update_icon) | |
582 ui_ops->update_icon(status); | |
583 } | |
584 | |
585 void | |
586 gaim_gtk_docklet_remove() | |
587 { | |
588 if (visibility_manager) { | |
589 gaim_gtk_blist_visibility_manager_remove(); | |
14873 | 590 if (docklet_blinking_timer) { |
591 g_source_remove(docklet_blinking_timer); | |
592 docklet_blinking_timer = 0; | |
593 } | |
14681 | 594 visibility_manager = FALSE; |
14873 | 595 status = DOCKLET_STATUS_OFFLINE; |
14681 | 596 } |
597 } | |
598 | |
599 void | |
600 gaim_gtk_docklet_set_ui_ops(struct docklet_ui_ops *ops) | |
601 { | |
602 ui_ops = ops; | |
603 } | |
604 | |
605 void* | |
606 gaim_gtk_docklet_get_handle() | |
607 { | |
608 static int i; | |
609 return &i; | |
610 } | |
611 | |
14683
a8c2af13b96d
[gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14681
diff
changeset
|
612 void |
14681 | 613 gaim_gtk_docklet_init() |
614 { | |
615 void *conn_handle = gaim_connections_get_handle(); | |
616 void *conv_handle = gaim_conversations_get_handle(); | |
617 void *accounts_handle = gaim_accounts_get_handle(); | |
618 void *docklet_handle = gaim_gtk_docklet_get_handle(); | |
14813 | 619 |
620 gaim_prefs_add_none("/gaim/gtk/docklet"); | |
621 gaim_prefs_add_bool("/gaim/gtk/docklet/blink", FALSE); | |
622 gaim_prefs_add_string("/gaim/gtk/docklet/show", "always"); | |
14681 | 623 |
624 docklet_ui_init(); | |
14873 | 625 if (!strcmp(gaim_prefs_get_string("/gaim/gtk/docklet/show"), "always") && ui_ops && ui_ops->create) |
14681 | 626 ui_ops->create(); |
14873 | 627 |
14681 | 628 gaim_signal_connect(conn_handle, "signed-on", |
14683
a8c2af13b96d
[gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14681
diff
changeset
|
629 docklet_handle, GAIM_CALLBACK(docklet_signed_on_cb), NULL); |
14681 | 630 gaim_signal_connect(conn_handle, "signed-off", |
631 docklet_handle, GAIM_CALLBACK(docklet_signed_off_cb), NULL); | |
632 gaim_signal_connect(accounts_handle, "account-status-changed", | |
633 docklet_handle, GAIM_CALLBACK(docklet_update_status_cb), NULL); | |
634 gaim_signal_connect(conv_handle, "received-im-msg", | |
635 docklet_handle, GAIM_CALLBACK(docklet_update_status_cb), NULL); | |
636 gaim_signal_connect(conv_handle, "conversation-created", | |
637 docklet_handle, GAIM_CALLBACK(docklet_update_status_cb), NULL); | |
638 gaim_signal_connect(conv_handle, "deleting-conversation", | |
639 docklet_handle, GAIM_CALLBACK(docklet_update_status_cb), NULL); | |
640 gaim_signal_connect(conv_handle, "conversation-updated", | |
641 docklet_handle, GAIM_CALLBACK(docklet_conv_updated_cb), NULL); | |
14683
a8c2af13b96d
[gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14681
diff
changeset
|
642 #if 0 |
a8c2af13b96d
[gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14681
diff
changeset
|
643 gaim_signal_connect(gaim_get_core(), "quitting", |
a8c2af13b96d
[gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14681
diff
changeset
|
644 docklet_handle, GAIM_CALLBACK(gaim_quit_cb), NULL); |
a8c2af13b96d
[gaim-migrate @ 17435]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14681
diff
changeset
|
645 #endif |
14681 | 646 |
647 enable_join_chat = online_account_supports_chat(); | |
648 } | |
649 | |
650 void | |
651 gaim_gtk_docklet_uninit() | |
652 { | |
14873 | 653 if (visibility_manager && ui_ops && ui_ops->destroy) |
14681 | 654 ui_ops->destroy(); |
655 } |