Mercurial > pidgin.yaz
comparison gtk/gtkdocklet.c @ 15016:9dcd88cd7dee
[gaim-migrate @ 17797]
Don't allow the buddy list to get lost when switching "Show system tray icon" to "On Unread messages"
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Tue, 21 Nov 2006 02:24:19 +0000 |
parents | b188da596c46 |
children |
comparison
equal
deleted
inserted
replaced
15015:f54c3349a7aa | 15016:9dcd88cd7dee |
---|---|
50 /* globals */ | 50 /* globals */ |
51 static struct docklet_ui_ops *ui_ops = NULL; | 51 static struct docklet_ui_ops *ui_ops = NULL; |
52 static DockletStatus status = DOCKLET_STATUS_OFFLINE; | 52 static DockletStatus status = DOCKLET_STATUS_OFFLINE; |
53 static gboolean enable_join_chat = FALSE; | 53 static gboolean enable_join_chat = FALSE; |
54 static guint docklet_blinking_timer = 0; | 54 static guint docklet_blinking_timer = 0; |
55 static gboolean visible = FALSE; | |
55 static gboolean visibility_manager = FALSE; | 56 static gboolean visibility_manager = FALSE; |
56 | 57 |
57 /************************************************************************** | 58 /************************************************************************** |
58 * docklet status and utility functions | 59 * docklet status and utility functions |
59 **************************************************************************/ | 60 **************************************************************************/ |
91 { | 92 { |
92 GList *l_im = NULL; | 93 GList *l_im = NULL; |
93 GList *l_chat = NULL; | 94 GList *l_chat = NULL; |
94 | 95 |
95 l_im = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM, | 96 l_im = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM, |
96 GAIM_UNSEEN_TEXT, | 97 GAIM_UNSEEN_TEXT, |
97 FALSE, max); | 98 FALSE, max); |
98 | 99 |
99 l_chat = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_CHAT, | 100 l_chat = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_CHAT, |
100 GAIM_UNSEEN_NICK, | 101 GAIM_UNSEEN_NICK, |
101 FALSE, max); | 102 FALSE, max); |
102 | 103 |
103 if (l_im != NULL && l_chat != NULL) | 104 if (l_im != NULL && l_chat != NULL) |
104 return g_list_concat(l_im, l_chat); | 105 return g_list_concat(l_im, l_chat); |
105 else if (l_im != NULL) | 106 else if (l_im != NULL) |
106 return l_im; | 107 return l_im; |
109 } | 110 } |
110 | 111 |
111 static gboolean | 112 static gboolean |
112 docklet_update_status() | 113 docklet_update_status() |
113 { | 114 { |
114 GList *convs = NULL; | 115 GList *convs, *l; |
115 GList *l; | |
116 int count; | 116 int count; |
117 DockletStatus newstatus = DOCKLET_STATUS_OFFLINE; | 117 DockletStatus newstatus = DOCKLET_STATUS_OFFLINE; |
118 gboolean pending = FALSE; | 118 gboolean pending = FALSE; |
119 | 119 |
120 /* determine if any ims have unseen messages */ | 120 /* determine if any ims have unseen messages */ |
121 convs = get_pending_list(DOCKLET_TOOLTIP_LINE_LIMIT); | 121 convs = get_pending_list(DOCKLET_TOOLTIP_LINE_LIMIT); |
122 | 122 |
123 if (!strcmp(gaim_prefs_get_string("/gaim/gtk/docklet/show"), "pending")) { | 123 if (!strcmp(gaim_prefs_get_string("/gaim/gtk/docklet/show"), "pending")) { |
124 if (convs && ui_ops->create && !visibility_manager) { | 124 if (convs && ui_ops->create && !visible) { |
125 g_list_free(convs); | 125 g_list_free(convs); |
126 ui_ops->create(); | 126 ui_ops->create(); |
127 return FALSE; | 127 return FALSE; |
128 } else if (!convs && ui_ops->destroy && visibility_manager) { | 128 } else if (!convs && ui_ops->destroy && visible) { |
129 ui_ops->destroy(); | 129 ui_ops->destroy(); |
130 return FALSE; | 130 return FALSE; |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 if (!visibility_manager) { | 134 if (!visible) { |
135 g_list_free(convs); | 135 g_list_free(convs); |
136 return FALSE; | 136 return FALSE; |
137 } | 137 } |
138 | 138 |
139 if (convs != NULL) { | 139 if (convs != NULL) { |
222 | 222 |
223 if (ui_ops && ui_ops->update_icon) | 223 if (ui_ops && ui_ops->update_icon) |
224 ui_ops->update_icon(status); | 224 ui_ops->update_icon(status); |
225 | 225 |
226 /* and schedule the blinker function if messages are pending */ | 226 /* and schedule the blinker function if messages are pending */ |
227 if (gaim_prefs_get_bool("/gaim/gtk/docklet/blink") && | 227 if (gaim_prefs_get_bool("/gaim/gtk/docklet/blink") && |
228 (status == DOCKLET_STATUS_ONLINE_PENDING | 228 (status == DOCKLET_STATUS_ONLINE_PENDING |
229 || status == DOCKLET_STATUS_AWAY_PENDING) | 229 || status == DOCKLET_STATUS_AWAY_PENDING) |
230 && docklet_blinking_timer == 0) { | 230 && docklet_blinking_timer == 0) { |
231 docklet_blinking_timer = g_timeout_add(500, docklet_blink_icon, NULL); | 231 docklet_blinking_timer = g_timeout_add(500, docklet_blink_icon, NULL); |
232 } | 232 } |
233 } | 233 } |
234 | 234 |
235 return FALSE; /* for when we're called by the glib idle handler */ | 235 return FALSE; /* for when we're called by the glib idle handler */ |
236 } | 236 } |
254 | 254 |
255 /************************************************************************** | 255 /************************************************************************** |
256 * callbacks and signal handlers | 256 * callbacks and signal handlers |
257 **************************************************************************/ | 257 **************************************************************************/ |
258 #if 0 | 258 #if 0 |
259 static void | 259 static void |
260 gaim_quit_cb() | 260 gaim_quit_cb() |
261 { | 261 { |
262 /* TODO: confirm quit while pending */ | 262 /* TODO: confirm quit while pending */ |
263 } | 263 } |
264 #endif | 264 #endif |
265 | 265 |
300 docklet_show_pref_changed_cb(const char *name, GaimPrefType type, | 300 docklet_show_pref_changed_cb(const char *name, GaimPrefType type, |
301 gconstpointer value, gpointer data) | 301 gconstpointer value, gpointer data) |
302 { | 302 { |
303 const char *val = value; | 303 const char *val = value; |
304 if (!strcmp(val, "always")) { | 304 if (!strcmp(val, "always")) { |
305 if (!visibility_manager && ui_ops->create) | 305 if (ui_ops->create) { |
306 ui_ops->create(); | 306 if (!visible) |
307 ui_ops->create(); | |
308 else if (!visibility_manager) { | |
309 gaim_gtk_blist_visibility_manager_add(); | |
310 visibility_manager = TRUE; | |
311 } | |
312 } | |
307 } else if (!strcmp(val, "never")) { | 313 } else if (!strcmp(val, "never")) { |
308 if (visibility_manager && ui_ops->destroy) | 314 if (visible && ui_ops->destroy) |
309 ui_ops->destroy(); | 315 ui_ops->destroy(); |
310 } else { | 316 } else { |
317 if (visibility_manager) { | |
318 gaim_gtk_blist_visibility_manager_remove(); | |
319 visibility_manager = FALSE; | |
320 } | |
311 docklet_update_status(); | 321 docklet_update_status(); |
312 } | 322 } |
313 | 323 |
314 } | 324 } |
315 | 325 |
336 | 346 |
337 #ifdef _WIN32 | 347 #ifdef _WIN32 |
338 /* This is a workaround for a bug in windows GTK+. Clicking outside of the | 348 /* This is a workaround for a bug in windows GTK+. Clicking outside of the |
339 menu does not get rid of it, so instead we get rid of it as soon as the | 349 menu does not get rid of it, so instead we get rid of it as soon as the |
340 pointer leaves the menu. */ | 350 pointer leaves the menu. */ |
341 static gboolean | 351 static gboolean |
342 hide_docklet_menu(gpointer data) | 352 hide_docklet_menu(gpointer data) |
343 { | 353 { |
344 if (data != NULL) { | 354 if (data != NULL) { |
345 gtk_menu_popdown(GTK_MENU(data)); | 355 gtk_menu_popdown(GTK_MENU(data)); |
346 } | 356 } |
540 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), gaim_prefs_get_bool("/gaim/gtk/sound/mute")); | 550 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), gaim_prefs_get_bool("/gaim/gtk/sound/mute")); |
541 if (!strcmp(gaim_prefs_get_string("/gaim/gtk/sound/method"), "none")) | 551 if (!strcmp(gaim_prefs_get_string("/gaim/gtk/sound/method"), "none")) |
542 gtk_widget_set_sensitive(GTK_WIDGET(menuitem), FALSE); | 552 gtk_widget_set_sensitive(GTK_WIDGET(menuitem), FALSE); |
543 g_signal_connect(G_OBJECT(menuitem), "toggled", G_CALLBACK(docklet_toggle_mute), NULL); | 553 g_signal_connect(G_OBJECT(menuitem), "toggled", G_CALLBACK(docklet_toggle_mute), NULL); |
544 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | 554 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
545 | 555 |
546 menuitem = gtk_check_menu_item_new_with_label(_("Blink on new message")); | 556 menuitem = gtk_check_menu_item_new_with_label(_("Blink on new message")); |
547 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), gaim_prefs_get_bool("/gaim/gtk/docklet/blink")); | 557 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), gaim_prefs_get_bool("/gaim/gtk/docklet/blink")); |
548 g_signal_connect(G_OBJECT(menuitem), "toggled", G_CALLBACK(docklet_toggle_blink), NULL); | 558 g_signal_connect(G_OBJECT(menuitem), "toggled", G_CALLBACK(docklet_toggle_blink), NULL); |
549 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | 559 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
550 | 560 |
551 gaim_separator(menu); | 561 gaim_separator(menu); |
552 | 562 |
553 /* TODO: need a submenu to change status, this needs to "link" | 563 /* TODO: need a submenu to change status, this needs to "link" |
554 * to the status in the buddy list gtkstatusbox | 564 * to the status in the buddy list gtkstatusbox |
555 */ | 565 */ |
556 | 566 |
557 gaim_new_item_from_stock(menu, _("Quit"), GTK_STOCK_QUIT, G_CALLBACK(gaim_core_quit), NULL, 0, 0, NULL); | 567 gaim_new_item_from_stock(menu, _("Quit"), GTK_STOCK_QUIT, G_CALLBACK(gaim_core_quit), NULL, 0, 0, NULL); |
558 | 568 |
560 g_signal_connect(menu, "leave-notify-event", G_CALLBACK(docklet_menu_leave_enter), NULL); | 570 g_signal_connect(menu, "leave-notify-event", G_CALLBACK(docklet_menu_leave_enter), NULL); |
561 g_signal_connect(menu, "enter-notify-event", G_CALLBACK(docklet_menu_leave_enter), NULL); | 571 g_signal_connect(menu, "enter-notify-event", G_CALLBACK(docklet_menu_leave_enter), NULL); |
562 #endif | 572 #endif |
563 gtk_widget_show_all(menu); | 573 gtk_widget_show_all(menu); |
564 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, | 574 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, |
565 ui_ops->position_menu, | 575 ui_ops->position_menu, |
566 NULL, 0, gtk_get_current_event_time()); | 576 NULL, 0, gtk_get_current_event_time()); |
567 } | 577 } |
568 | 578 |
569 /************************************************************************** | 579 /************************************************************************** |
570 * public api for ui_ops | 580 * public api for ui_ops |
571 **************************************************************************/ | 581 **************************************************************************/ |
591 } | 601 } |
592 | 602 |
593 void | 603 void |
594 gaim_gtk_docklet_embedded() | 604 gaim_gtk_docklet_embedded() |
595 { | 605 { |
596 if (!visibility_manager) { | 606 if (!visibility_manager |
597 if (strcmp(gaim_prefs_get_string("/gaim/gtk/docklet/show"),"pending")) | 607 && strcmp(gaim_prefs_get_string("/gaim/gtk/docklet/show"), "pending")) { |
598 gaim_gtk_blist_visibility_manager_add(); | 608 gaim_gtk_blist_visibility_manager_add(); |
599 visibility_manager = TRUE; | 609 visibility_manager = TRUE; |
600 } | 610 } |
611 visible = TRUE; | |
601 docklet_update_status(); | 612 docklet_update_status(); |
602 if (ui_ops && ui_ops->update_icon) | 613 if (ui_ops && ui_ops->update_icon) |
603 ui_ops->update_icon(status); | 614 ui_ops->update_icon(status); |
604 } | 615 } |
605 | 616 |
606 void | 617 void |
607 gaim_gtk_docklet_remove() | 618 gaim_gtk_docklet_remove() |
608 { | 619 { |
609 if (visibility_manager) { | 620 if (visible) { |
610 if (strcmp(gaim_prefs_get_string("/gaim/gtk/docklet/show"),"pending")) | 621 if (visibility_manager) { |
611 gaim_gtk_blist_visibility_manager_remove(); | 622 gaim_gtk_blist_visibility_manager_remove(); |
623 visibility_manager = FALSE; | |
624 } | |
612 if (docklet_blinking_timer) { | 625 if (docklet_blinking_timer) { |
613 g_source_remove(docklet_blinking_timer); | 626 g_source_remove(docklet_blinking_timer); |
614 docklet_blinking_timer = 0; | 627 docklet_blinking_timer = 0; |
615 } | 628 } |
616 visibility_manager = FALSE; | 629 visible = FALSE; |
617 status = DOCKLET_STATUS_OFFLINE; | 630 status = DOCKLET_STATUS_OFFLINE; |
618 } | 631 } |
619 } | 632 } |
620 | 633 |
621 void | 634 void |
636 { | 649 { |
637 void *conn_handle = gaim_connections_get_handle(); | 650 void *conn_handle = gaim_connections_get_handle(); |
638 void *conv_handle = gaim_conversations_get_handle(); | 651 void *conv_handle = gaim_conversations_get_handle(); |
639 void *accounts_handle = gaim_accounts_get_handle(); | 652 void *accounts_handle = gaim_accounts_get_handle(); |
640 void *docklet_handle = gaim_gtk_docklet_get_handle(); | 653 void *docklet_handle = gaim_gtk_docklet_get_handle(); |
641 | 654 |
642 gaim_prefs_add_none("/gaim/gtk/docklet"); | 655 gaim_prefs_add_none("/gaim/gtk/docklet"); |
643 gaim_prefs_add_bool("/gaim/gtk/docklet/blink", FALSE); | 656 gaim_prefs_add_bool("/gaim/gtk/docklet/blink", FALSE); |
644 gaim_prefs_add_string("/gaim/gtk/docklet/show", "always"); | 657 gaim_prefs_add_string("/gaim/gtk/docklet/show", "always"); |
645 gaim_prefs_connect_callback(docklet_handle, "/gaim/gtk/docklet/show", | 658 gaim_prefs_connect_callback(docklet_handle, "/gaim/gtk/docklet/show", |
646 docklet_show_pref_changed_cb, NULL); | 659 docklet_show_pref_changed_cb, NULL); |
647 | 660 |
648 docklet_ui_init(); | 661 docklet_ui_init(); |
649 if (!strcmp(gaim_prefs_get_string("/gaim/gtk/docklet/show"), "always") && ui_ops && ui_ops->create) | 662 if (!strcmp(gaim_prefs_get_string("/gaim/gtk/docklet/show"), "always") && ui_ops && ui_ops->create) |
650 ui_ops->create(); | 663 ui_ops->create(); |
651 | 664 |
652 gaim_signal_connect(conn_handle, "signed-on", | 665 gaim_signal_connect(conn_handle, "signed-on", |
653 docklet_handle, GAIM_CALLBACK(docklet_signed_on_cb), NULL); | 666 docklet_handle, GAIM_CALLBACK(docklet_signed_on_cb), NULL); |
654 gaim_signal_connect(conn_handle, "signed-off", | 667 gaim_signal_connect(conn_handle, "signed-off", |
655 docklet_handle, GAIM_CALLBACK(docklet_signed_off_cb), NULL); | 668 docklet_handle, GAIM_CALLBACK(docklet_signed_off_cb), NULL); |
656 gaim_signal_connect(accounts_handle, "account-status-changed", | 669 gaim_signal_connect(accounts_handle, "account-status-changed", |
672 } | 685 } |
673 | 686 |
674 void | 687 void |
675 gaim_gtk_docklet_uninit() | 688 gaim_gtk_docklet_uninit() |
676 { | 689 { |
677 if (visibility_manager && ui_ops && ui_ops->destroy) | 690 if (visible && ui_ops && ui_ops->destroy) |
678 ui_ops->destroy(); | 691 ui_ops->destroy(); |
679 } | 692 } |