Mercurial > pidgin
comparison pidgin/gtkdocklet.c @ 16938:06f6768b6e29
Now that the docklet icon is based on the status from status selector, it
isn't necessary to have a separate DockletStatus enum/typedef to track the
status. This replaces usage of DockletStatus with PurpleStatusPrimitive.
This requires tracking connecting and pending flags separately and
passing them on to the ui_ops implementation with the status.
Removed an old TODO comment that has already been implemented.
author | Casey Harkins <charkins@pidgin.im> |
---|---|
date | Tue, 08 May 2007 02:38:55 +0000 |
parents | b668951121d8 |
children | 4ca97b26a8fb 526cc36424ab |
comparison
equal
deleted
inserted
replaced
16934:2fffd9d72b8f | 16938:06f6768b6e29 |
---|---|
47 #define DOCKLET_TOOLTIP_LINE_LIMIT 5 | 47 #define DOCKLET_TOOLTIP_LINE_LIMIT 5 |
48 #endif | 48 #endif |
49 | 49 |
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 PurpleStatusPrimitive status = PURPLE_STATUS_OFFLINE; |
53 static gboolean pending = FALSE; | |
54 static gboolean connecting = FALSE; | |
53 static gboolean enable_join_chat = FALSE; | 55 static gboolean enable_join_chat = FALSE; |
54 static guint docklet_blinking_timer = 0; | 56 static guint docklet_blinking_timer = 0; |
55 static gboolean visible = FALSE; | 57 static gboolean visible = FALSE; |
56 static gboolean visibility_manager = FALSE; | 58 static gboolean visibility_manager = FALSE; |
57 | 59 |
64 static gboolean blinked = FALSE; | 66 static gboolean blinked = FALSE; |
65 gboolean ret = FALSE; /* by default, don't keep blinking */ | 67 gboolean ret = FALSE; /* by default, don't keep blinking */ |
66 | 68 |
67 blinked = !blinked; | 69 blinked = !blinked; |
68 | 70 |
69 switch (status) { | 71 if(pending && !connecting) { |
70 case DOCKLET_STATUS_PENDING: | 72 if (blinked) { |
71 if (blinked) { | 73 if (ui_ops && ui_ops->blank_icon) |
72 if (ui_ops && ui_ops->blank_icon) | 74 ui_ops->blank_icon(); |
73 ui_ops->blank_icon(); | 75 } else { |
74 } else { | 76 pidgin_docklet_update_icon(); |
75 if (ui_ops && ui_ops->update_icon) | 77 } |
76 ui_ops->update_icon(status); | 78 ret = TRUE; /* keep blinking */ |
77 } | 79 } else { |
78 ret = TRUE; /* keep blinking */ | 80 docklet_blinking_timer = 0; |
79 break; | 81 blinked = FALSE; |
80 default: | |
81 docklet_blinking_timer = 0; | |
82 blinked = FALSE; | |
83 break; | |
84 } | 82 } |
85 | 83 |
86 return ret; | 84 return ret; |
87 } | 85 } |
88 | 86 |
112 docklet_update_status() | 110 docklet_update_status() |
113 { | 111 { |
114 GList *convs, *l; | 112 GList *convs, *l; |
115 int count; | 113 int count; |
116 PurpleSavedStatus *saved_status; | 114 PurpleSavedStatus *saved_status; |
117 PurpleStatusPrimitive prim; | 115 PurpleStatusPrimitive newstatus = PURPLE_STATUS_OFFLINE; |
118 DockletStatus newstatus = DOCKLET_STATUS_OFFLINE; | 116 gboolean newpending = FALSE, newconnecting = FALSE; |
119 gboolean pending = FALSE, connecting = FALSE; | |
120 | 117 |
121 /* get the current savedstatus */ | 118 /* get the current savedstatus */ |
122 saved_status = purple_savedstatus_get_current(); | 119 saved_status = purple_savedstatus_get_current(); |
123 | 120 |
124 /* determine if any ims have unseen messages */ | 121 /* determine if any ims have unseen messages */ |
139 g_list_free(convs); | 136 g_list_free(convs); |
140 return FALSE; | 137 return FALSE; |
141 } | 138 } |
142 | 139 |
143 if (convs != NULL) { | 140 if (convs != NULL) { |
144 pending = TRUE; | 141 newpending = TRUE; |
145 | 142 |
146 /* set tooltip if messages are pending */ | 143 /* set tooltip if messages are pending */ |
147 if (ui_ops->set_tooltip) { | 144 if (ui_ops->set_tooltip) { |
148 GString *tooltip_text = g_string_new(""); | 145 GString *tooltip_text = g_string_new(""); |
149 for (l = convs, count = 0 ; l != NULL ; l = l->next, count++) { | 146 for (l = convs, count = 0 ; l != NULL ; l = l->next, count++) { |
188 if (purple_account_is_disconnected(account)) | 185 if (purple_account_is_disconnected(account)) |
189 continue; | 186 continue; |
190 | 187 |
191 account_status = purple_account_get_active_status(account); | 188 account_status = purple_account_get_active_status(account); |
192 if (purple_account_is_connecting(account)) | 189 if (purple_account_is_connecting(account)) |
193 connecting = TRUE; | 190 newconnecting = TRUE; |
194 } | 191 } |
195 | 192 |
196 prim = purple_savedstatus_get_type(saved_status); | 193 newstatus = purple_savedstatus_get_type(saved_status); |
197 if (pending) | |
198 newstatus = DOCKLET_STATUS_PENDING; | |
199 else if (connecting) | |
200 newstatus = DOCKLET_STATUS_CONNECTING; | |
201 else if (prim == PURPLE_STATUS_UNAVAILABLE) | |
202 newstatus = DOCKLET_STATUS_BUSY; | |
203 else if (prim == PURPLE_STATUS_AWAY) | |
204 newstatus = DOCKLET_STATUS_AWAY; | |
205 else if (prim == PURPLE_STATUS_EXTENDED_AWAY) | |
206 newstatus = DOCKLET_STATUS_XA; | |
207 else if (prim == PURPLE_STATUS_OFFLINE) | |
208 newstatus = DOCKLET_STATUS_OFFLINE; | |
209 else if (prim == PURPLE_STATUS_INVISIBLE) | |
210 newstatus = DOCKLET_STATUS_INVISIBLE; | |
211 else | |
212 newstatus = DOCKLET_STATUS_AVAILABLE; | |
213 | 194 |
214 /* update the icon if we changed status */ | 195 /* update the icon if we changed status */ |
215 if (status != newstatus) { | 196 if (status != newstatus || pending!=newpending || connecting!=newconnecting) { |
216 status = newstatus; | 197 status = newstatus; |
217 | 198 pending = newpending; |
218 if (ui_ops && ui_ops->update_icon) | 199 connecting = newconnecting; |
219 ui_ops->update_icon(status); | 200 |
201 pidgin_docklet_update_icon(); | |
220 | 202 |
221 /* and schedule the blinker function if messages are pending */ | 203 /* and schedule the blinker function if messages are pending */ |
222 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/docklet/blink") && | 204 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/docklet/blink") |
223 status == DOCKLET_STATUS_PENDING | 205 && pending && !connecting && docklet_blinking_timer == 0) { |
224 && docklet_blinking_timer == 0) { | |
225 docklet_blinking_timer = g_timeout_add(500, docklet_blink_icon, NULL); | 206 docklet_blinking_timer = g_timeout_add(500, docklet_blink_icon, NULL); |
226 } | 207 } |
227 } | 208 } |
228 | 209 |
229 return FALSE; /* for when we're called by the glib idle handler */ | 210 return FALSE; /* for when we're called by the glib idle handler */ |
508 g_signal_connect(G_OBJECT(menuitem), "toggled", G_CALLBACK(docklet_toggle_blist), NULL); | 489 g_signal_connect(G_OBJECT(menuitem), "toggled", G_CALLBACK(docklet_toggle_blist), NULL); |
509 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | 490 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
510 | 491 |
511 menuitem = gtk_menu_item_new_with_label(_("Unread Messages")); | 492 menuitem = gtk_menu_item_new_with_label(_("Unread Messages")); |
512 | 493 |
513 if (status == DOCKLET_STATUS_PENDING) { | 494 if (pending) { |
514 GtkWidget *submenu = gtk_menu_new(); | 495 GtkWidget *submenu = gtk_menu_new(); |
515 GList *l = get_pending_list(0); | 496 GList *l = get_pending_list(0); |
516 if (l == NULL) { | 497 if (l == NULL) { |
517 gtk_widget_set_sensitive(menuitem, FALSE); | 498 gtk_widget_set_sensitive(menuitem, FALSE); |
518 purple_debug_warning("docklet", | 499 purple_debug_warning("docklet", |
528 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | 509 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
529 | 510 |
530 pidgin_separator(menu); | 511 pidgin_separator(menu); |
531 | 512 |
532 menuitem = pidgin_new_item_from_stock(menu, _("New Message..."), PIDGIN_STOCK_TOOLBAR_MESSAGE_NEW, G_CALLBACK(pidgin_dialogs_im), NULL, 0, 0, NULL); | 513 menuitem = pidgin_new_item_from_stock(menu, _("New Message..."), PIDGIN_STOCK_TOOLBAR_MESSAGE_NEW, G_CALLBACK(pidgin_dialogs_im), NULL, 0, 0, NULL); |
533 if (status == DOCKLET_STATUS_OFFLINE) | 514 if (status == PURPLE_STATUS_OFFLINE) |
534 gtk_widget_set_sensitive(menuitem, FALSE); | 515 gtk_widget_set_sensitive(menuitem, FALSE); |
535 | 516 |
536 menuitem = docklet_status_submenu(); | 517 menuitem = docklet_status_submenu(); |
537 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | 518 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
538 | 519 |
555 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/docklet/blink")); | 536 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/docklet/blink")); |
556 g_signal_connect(G_OBJECT(menuitem), "toggled", G_CALLBACK(docklet_toggle_blink), NULL); | 537 g_signal_connect(G_OBJECT(menuitem), "toggled", G_CALLBACK(docklet_toggle_blink), NULL); |
557 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | 538 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
558 | 539 |
559 pidgin_separator(menu); | 540 pidgin_separator(menu); |
560 | |
561 /* TODO: need a submenu to change status, this needs to "link" | |
562 * to the status in the buddy list gtkstatusbox | |
563 */ | |
564 | 541 |
565 pidgin_new_item_from_stock(menu, _("Quit"), GTK_STOCK_QUIT, G_CALLBACK(purple_core_quit), NULL, 0, 0, NULL); | 542 pidgin_new_item_from_stock(menu, _("Quit"), GTK_STOCK_QUIT, G_CALLBACK(purple_core_quit), NULL, 0, 0, NULL); |
566 | 543 |
567 #ifdef _WIN32 | 544 #ifdef _WIN32 |
568 g_signal_connect(menu, "leave-notify-event", G_CALLBACK(docklet_menu_leave_enter), NULL); | 545 g_signal_connect(menu, "leave-notify-event", G_CALLBACK(docklet_menu_leave_enter), NULL); |
576 | 553 |
577 /************************************************************************** | 554 /************************************************************************** |
578 * public api for ui_ops | 555 * public api for ui_ops |
579 **************************************************************************/ | 556 **************************************************************************/ |
580 void | 557 void |
558 pidgin_docklet_update_icon() | |
559 { | |
560 if (ui_ops && ui_ops->update_icon) | |
561 ui_ops->update_icon(status, connecting, pending); | |
562 } | |
563 | |
564 void | |
581 pidgin_docklet_clicked(int button_type) | 565 pidgin_docklet_clicked(int button_type) |
582 { | 566 { |
583 switch (button_type) { | 567 switch (button_type) { |
584 case 1: | 568 case 1: |
585 if (status == DOCKLET_STATUS_PENDING) { | 569 if (pending) { |
586 GList *l = get_pending_list(1); | 570 GList *l = get_pending_list(1); |
587 if (l != NULL) { | 571 if (l != NULL) { |
588 purple_conversation_present((PurpleConversation *)l->data); | 572 purple_conversation_present((PurpleConversation *)l->data); |
589 g_list_free(l); | 573 g_list_free(l); |
590 } | 574 } |
606 pidgin_blist_visibility_manager_add(); | 590 pidgin_blist_visibility_manager_add(); |
607 visibility_manager = TRUE; | 591 visibility_manager = TRUE; |
608 } | 592 } |
609 visible = TRUE; | 593 visible = TRUE; |
610 docklet_update_status(); | 594 docklet_update_status(); |
611 if (ui_ops && ui_ops->update_icon) | 595 pidgin_docklet_update_icon(); |
612 ui_ops->update_icon(status); | |
613 } | 596 } |
614 | 597 |
615 void | 598 void |
616 pidgin_docklet_remove() | 599 pidgin_docklet_remove() |
617 { | 600 { |
623 if (docklet_blinking_timer) { | 606 if (docklet_blinking_timer) { |
624 g_source_remove(docklet_blinking_timer); | 607 g_source_remove(docklet_blinking_timer); |
625 docklet_blinking_timer = 0; | 608 docklet_blinking_timer = 0; |
626 } | 609 } |
627 visible = FALSE; | 610 visible = FALSE; |
628 status = DOCKLET_STATUS_OFFLINE; | 611 status = PURPLE_STATUS_OFFLINE; |
629 } | 612 } |
630 } | 613 } |
631 | 614 |
632 void | 615 void |
633 pidgin_docklet_set_ui_ops(struct docklet_ui_ops *ops) | 616 pidgin_docklet_set_ui_ops(struct docklet_ui_ops *ops) |