comparison plugins/docklet/docklet.c @ 12472:065005e5f536

[gaim-migrate @ 14782] SF Patch #1373967 from charkins "This patch requires #1372898 to be applied first. It adds two 3-way preferences to the docklet plugin to determine when the tray icon should blink. One pref is for unread IM messages, the other for unread chat messages. The options for each: im: never, when hidden, always chat: never, when nick said, always I've set the defaults to match the 1.x behavior (when hidden for im, never for chat)." This patch provided a function used by a previous patch. I undid my (now incorrect) changes there. I modified this to have a limit to the number of tooltips to display. I also tweaked the preference strings a bit. So, blame me if those things are wrong. ;) committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Mon, 12 Dec 2005 20:38:10 +0000
parents 011efeb86b8d
children 572d6d5da418
comparison
equal deleted inserted replaced
12471:011efeb86b8d 12472:065005e5f536
46 #include "gaim.h" 46 #include "gaim.h"
47 #include "gtkdialogs.h" 47 #include "gtkdialogs.h"
48 48
49 #define DOCKLET_PLUGIN_ID "gtk-docklet" 49 #define DOCKLET_PLUGIN_ID "gtk-docklet"
50 50
51 #ifndef DOCKLET_TOOLTIP_LINE_LIMIT
52 #define DOCKLET_TOOLTIP_LINE_LIMIT 5
53 #endif
54
51 /* globals */ 55 /* globals */
52 GaimPlugin *handle = NULL; 56 GaimPlugin *handle = NULL;
53 static struct docklet_ui_ops *ui_ops = NULL; 57 static struct docklet_ui_ops *ui_ops = NULL;
54 static DockletStatus status = DOCKLET_STATUS_OFFLINE; 58 static DockletStatus status = DOCKLET_STATUS_OFFLINE;
55 static gboolean enable_join_chat = FALSE; 59 static gboolean enable_join_chat = FALSE;
85 } 89 }
86 90
87 return ret; 91 return ret;
88 } 92 }
89 93
94 static GList *
95 get_pending_list(guint max)
96 {
97 const char *im = gaim_prefs_get_string("/plugins/gtk/docklet/blink_im");
98 const char *chat = gaim_prefs_get_string("/plugins/gtk/docklet/blink_chat");
99 GList *l_im = NULL;
100 GList *l_chat = NULL;
101
102 if (im != NULL && strcmp(im, "always") == 0) {
103 l_im = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM,
104 GAIM_UNSEEN_TEXT,
105 FALSE, max);
106 } else if (im != NULL && strcmp(im, "hidden") == 0) {
107 l_im = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM,
108 GAIM_UNSEEN_TEXT,
109 TRUE, max);
110 }
111
112 if (chat != NULL && strcmp(chat, "always") == 0) {
113 l_chat = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_CHAT,
114 GAIM_UNSEEN_TEXT,
115 FALSE, max);
116 } else if (chat != NULL && strcmp(chat, "nick") == 0) {
117 l_chat = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_CHAT,
118 GAIM_UNSEEN_NICK,
119 FALSE, max);
120 }
121
122 if (l_im != NULL && l_chat != NULL)
123 return g_list_concat(l_im, l_chat);
124 else if (l_im != NULL)
125 return l_im;
126 else
127 return l_chat;
128 }
129
90 static gboolean 130 static gboolean
91 docklet_update_status() 131 docklet_update_status()
92 { 132 {
133 GList *convs;
93 GList *l; 134 GList *l;
94 GList *convs; 135 int count;
95 DockletStatus newstatus = DOCKLET_STATUS_OFFLINE; 136 DockletStatus newstatus = DOCKLET_STATUS_OFFLINE;
96 gboolean pending = FALSE; 137 gboolean pending = FALSE;
97 138
98 /* determine if any ims have unseen messages */ 139 /* determine if any ims have unseen messages */
99 convs = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM, 140 convs = get_pending_list(DOCKLET_TOOLTIP_LINE_LIMIT);
100 GAIM_UNSEEN_TEXT, FALSE, 1); 141
101 if (convs != NULL) { 142 if (convs != NULL) {
102 pending = TRUE; 143 pending = TRUE;
103 144
104 /* set tooltip if messages are pending */ 145 /* set tooltip if messages are pending */
105 if (ui_ops->set_tooltip) { 146 if (ui_ops->set_tooltip) {
106 GString *tooltip_text = g_string_new(""); 147 GString *tooltip_text = g_string_new("");
107 for (l = convs ; l != NULL ; l = l->next) { 148 for (l = convs, count = 0 ; l != NULL ; l = l->next, count++) {
108 if (GAIM_IS_GTK_CONVERSATION(l->data)) { 149 if (GAIM_IS_GTK_CONVERSATION(l->data)) {
109 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION((GaimConversation *)l->data); 150 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION((GaimConversation *)l->data);
110 g_string_append_printf(tooltip_text, 151 if (count == DOCKLET_TOOLTIP_LINE_LIMIT - 1)
152 g_string_append(tooltip_text, _("Right-click for more unread messages...\n"));
153 else
154 g_string_append_printf(tooltip_text,
111 ngettext("%d unread message from %s\n", "%d unread messages from %s\n", gtkconv->unseen_count), 155 ngettext("%d unread message from %s\n", "%d unread messages from %s\n", gtkconv->unseen_count),
112 gtkconv->unseen_count, 156 gtkconv->unseen_count,
113 gtk_label_get_text(GTK_LABEL(gtkconv->tab_label))); 157 gtk_label_get_text(GTK_LABEL(gtkconv->tab_label)));
114 } 158 }
115 } 159 }
228 */ 272 */
229 docklet_update_status(); 273 docklet_update_status();
230 } 274 }
231 275
232 static void 276 static void
277 docklet_prefs_cb(const char *name, GaimPrefType type,
278 gpointer val, gpointer data)
279 {
280 docklet_update_status();
281 }
282
283 static void
233 docklet_conv_updated_cb(GaimConversation *conv, GaimConvUpdateType type) 284 docklet_conv_updated_cb(GaimConversation *conv, GaimConvUpdateType type)
234 { 285 {
235 if (type == GAIM_CONV_UPDATE_UNSEEN) 286 if (type == GAIM_CONV_UPDATE_UNSEEN)
236 docklet_update_status(); 287 docklet_update_status();
237 } 288 }
326 377
327 menuitem = gtk_menu_item_new_with_label(_("Unread Messages")); 378 menuitem = gtk_menu_item_new_with_label(_("Unread Messages"));
328 379
329 if (status == DOCKLET_STATUS_ONLINE_PENDING || status == DOCKLET_STATUS_AWAY_PENDING) { 380 if (status == DOCKLET_STATUS_ONLINE_PENDING || status == DOCKLET_STATUS_AWAY_PENDING) {
330 GtkWidget *submenu = gtk_menu_new(); 381 GtkWidget *submenu = gtk_menu_new();
331 GList *l = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM, GAIM_UNSEEN_TEXT, FALSE, 0); 382 GList *l = get_pending_list(0);
332 if (l == NULL) { 383 if (l == NULL) {
333 gtk_widget_set_sensitive(menuitem, FALSE); 384 gtk_widget_set_sensitive(menuitem, FALSE);
334 gaim_debug_warning("docklet", 385 gaim_debug_warning("docklet",
335 "status indicates messages pending, but no conversations with unseen messages were found."); 386 "status indicates messages pending, but no conversations with unseen messages were found.");
336 } else { 387 } else {
394 docklet_clicked(int button_type) 445 docklet_clicked(int button_type)
395 { 446 {
396 switch (button_type) { 447 switch (button_type) {
397 case 1: 448 case 1:
398 if (status==DOCKLET_STATUS_ONLINE_PENDING || status==DOCKLET_STATUS_AWAY_PENDING) { 449 if (status==DOCKLET_STATUS_ONLINE_PENDING || status==DOCKLET_STATUS_AWAY_PENDING) {
399 GList *l = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM, 450 GList *l = get_pending_list(1);
400 GAIM_UNSEEN_TEXT, FALSE, 1);
401 if (l != NULL) { 451 if (l != NULL) {
402 gaim_gtkconv_present_conversation((GaimConversation *)l->data); 452 gaim_gtkconv_present_conversation((GaimConversation *)l->data);
403 g_list_free(l); 453 g_list_free(l);
404 } 454 }
405 } else { 455 } else {
476 plugin, GAIM_CALLBACK(docklet_conv_updated_cb), NULL); 526 plugin, GAIM_CALLBACK(docklet_conv_updated_cb), NULL);
477 527
478 gaim_signal_connect(core_handle, "quitting", 528 gaim_signal_connect(core_handle, "quitting",
479 plugin, GAIM_CALLBACK(gaim_quit_cb), NULL); 529 plugin, GAIM_CALLBACK(gaim_quit_cb), NULL);
480 530
531 gaim_prefs_connect_callback(plugin, "/plugins/gtk/docklet/blink_im",
532 docklet_prefs_cb, NULL);
533 gaim_prefs_connect_callback(plugin, "/plugins/gtk/docklet/blink_chat",
534 docklet_prefs_cb, NULL);
535
481 enable_join_chat = online_account_supports_chat(); 536 enable_join_chat = online_account_supports_chat();
482 537
483 return TRUE; 538 return TRUE;
484 } 539 }
485 540
489 if (ui_ops && ui_ops->destroy) 544 if (ui_ops && ui_ops->destroy)
490 ui_ops->destroy(); 545 ui_ops->destroy();
491 546
492 /* remove callbacks */ 547 /* remove callbacks */
493 gaim_signals_disconnect_by_handle(handle); 548 gaim_signals_disconnect_by_handle(handle);
549 gaim_prefs_disconnect_by_handle(handle);
494 550
495 gaim_debug(GAIM_DEBUG_INFO, "docklet", "plugin unloaded\n"); 551 gaim_debug(GAIM_DEBUG_INFO, "docklet", "plugin unloaded\n");
496 552
497 return TRUE; 553 return TRUE;
498 } 554 }
555
556 static GtkWidget *
557 plugin_config_frame(GaimPlugin *plugin)
558 {
559 GtkWidget *frame;
560 GtkWidget *vbox;
561 GtkSizeGroup *sg;
562 GtkWidget *dd;
563
564 frame = gtk_vbox_new(FALSE, 18);
565 gtk_container_set_border_width(GTK_CONTAINER(frame), 12);
566
567 vbox = gaim_gtk_make_frame(frame, _("Blink tray icon for unread..."));
568 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
569
570 dd = gaim_gtk_prefs_dropdown(vbox, _("_Instant Messages:"),
571 GAIM_PREF_STRING, "/plugins/gtk/docklet/blink_im",
572 _("Never"), "never",
573 _("In hidden conversations"), "hidden",
574 _("Always"), "always",
575 NULL);
576 gtk_size_group_add_widget(sg, dd);
577
578 dd = gaim_gtk_prefs_dropdown(vbox, _("C_hat Messages:"),
579 GAIM_PREF_STRING, "/plugins/gtk/docklet/blink_chat",
580 _("Never"), "never",
581 _("When my nick is said"), "nick",
582 _("Always"), "always",
583 NULL);
584 gtk_size_group_add_widget(sg, dd);
585
586 gtk_widget_show_all(frame);
587 return frame;
588 }
589
590 static GaimGtkPluginUiInfo ui_info =
591 {
592 plugin_config_frame
593 };
499 594
500 static GaimPluginInfo info = 595 static GaimPluginInfo info =
501 { 596 {
502 GAIM_PLUGIN_MAGIC, 597 GAIM_PLUGIN_MAGIC,
503 GAIM_MAJOR_VERSION, 598 GAIM_MAJOR_VERSION,
524 619
525 plugin_load, /**< load */ 620 plugin_load, /**< load */
526 plugin_unload, /**< unload */ 621 plugin_unload, /**< unload */
527 NULL, /**< destroy */ 622 NULL, /**< destroy */
528 623
529 NULL, /**< ui_info */ 624 &ui_info, /**< ui_info */
530 NULL, /**< extra_info */ 625 NULL, /**< extra_info */
531 NULL, 626 NULL,
532 NULL 627 NULL
533 }; 628 };
534 629
535 static void 630 static void
536 plugin_init(GaimPlugin *plugin) 631 plugin_init(GaimPlugin *plugin)
537 { 632 {
633 gaim_prefs_add_none("/plugins/gtk/docklet");
634 gaim_prefs_add_string("/plugins/gtk/docklet/blink_im", "hidden");
635 gaim_prefs_add_string("/plugins/gtk/docklet/blink_chat", "never");
538 } 636 }
539 637
540 GAIM_INIT_PLUGIN(docklet, plugin_init, info) 638 GAIM_INIT_PLUGIN(docklet, plugin_init, info)