gtk/plugins/docklet/docklet.c

changeset 14253
b63ebf84c42b
parent 13245
3c026039efc5
child 14743
2324d3eee038
equal deleted inserted replaced
14252:d10dda2777a9 14253:b63ebf84c42b
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 #include "version.h"
34
35 #include "gtkaccount.h"
36 #include "gtkblist.h"
37 #include "gtkconv.h"
38 #include "gtkft.h"
39 #include "gtkplugin.h"
40 #include "gtkprefs.h"
41 #include "gtksavedstatuses.h"
42 #include "gtksound.h"
43 #include "gtkutils.h"
44 #include "gaimstock.h"
45 #include "docklet.h"
46
47 #include "gaim.h"
48 #include "gtkdialogs.h"
49
50 #define DOCKLET_PLUGIN_ID "gtk-docklet"
51
52 #ifndef DOCKLET_TOOLTIP_LINE_LIMIT
53 #define DOCKLET_TOOLTIP_LINE_LIMIT 5
54 #endif
55
56 /* globals */
57 GaimPlugin *handle = NULL;
58 static struct docklet_ui_ops *ui_ops = NULL;
59 static DockletStatus status = DOCKLET_STATUS_OFFLINE;
60 static gboolean enable_join_chat = FALSE;
61 static guint docklet_blinking_timer = 0;
62 static gboolean visibility_manager = FALSE;
63
64 /**************************************************************************
65 * docklet status and utility functions
66 **************************************************************************/
67 static gboolean
68 docklet_blink_icon()
69 {
70 static gboolean blinked = FALSE;
71 gboolean ret = FALSE; /* by default, don't keep blinking */
72
73 blinked = !blinked;
74
75 switch (status) {
76 case DOCKLET_STATUS_ONLINE_PENDING:
77 case DOCKLET_STATUS_AWAY_PENDING:
78 if (blinked) {
79 if (ui_ops && ui_ops->blank_icon)
80 ui_ops->blank_icon();
81 } else {
82 if (ui_ops && ui_ops->update_icon)
83 ui_ops->update_icon(status);
84 }
85 ret = TRUE; /* keep blinking */
86 break;
87 default:
88 docklet_blinking_timer = 0;
89 blinked = FALSE;
90 break;
91 }
92
93 return ret;
94 }
95
96 static GList *
97 get_pending_list(guint max)
98 {
99 const char *im = gaim_prefs_get_string("/plugins/gtk/docklet/blink_im");
100 const char *chat = gaim_prefs_get_string("/plugins/gtk/docklet/blink_chat");
101 GList *l_im = NULL;
102 GList *l_chat = NULL;
103
104 if (im != NULL && strcmp(im, "always") == 0) {
105 l_im = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM,
106 GAIM_UNSEEN_TEXT,
107 FALSE, max);
108 } else if (im != NULL && strcmp(im, "hidden") == 0) {
109 l_im = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM,
110 GAIM_UNSEEN_TEXT,
111 TRUE, max);
112 }
113
114 if (chat != NULL && strcmp(chat, "always") == 0) {
115 l_chat = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_CHAT,
116 GAIM_UNSEEN_TEXT,
117 FALSE, max);
118 } else if (chat != NULL && strcmp(chat, "nick") == 0) {
119 l_chat = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_CHAT,
120 GAIM_UNSEEN_NICK,
121 FALSE, max);
122 }
123
124 if (l_im != NULL && l_chat != NULL)
125 return g_list_concat(l_im, l_chat);
126 else if (l_im != NULL)
127 return l_im;
128 else
129 return l_chat;
130 }
131
132 static gboolean
133 docklet_update_status()
134 {
135 GList *convs;
136 GList *l;
137 int count;
138 DockletStatus newstatus = DOCKLET_STATUS_OFFLINE;
139 gboolean pending = FALSE;
140
141 /* determine if any ims have unseen messages */
142 convs = get_pending_list(DOCKLET_TOOLTIP_LINE_LIMIT);
143
144 if (convs != NULL) {
145 pending = TRUE;
146
147 /* set tooltip if messages are pending */
148 if (ui_ops->set_tooltip) {
149 GString *tooltip_text = g_string_new("");
150 for (l = convs, count = 0 ; l != NULL ; l = l->next, count++) {
151 if (GAIM_IS_GTK_CONVERSATION(l->data)) {
152 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION((GaimConversation *)l->data);
153 if (count == DOCKLET_TOOLTIP_LINE_LIMIT - 1)
154 g_string_append(tooltip_text, _("Right-click for more unread messages...\n"));
155 else
156 g_string_append_printf(tooltip_text,
157 ngettext("%d unread message from %s\n", "%d unread messages from %s\n", gtkconv->unseen_count),
158 gtkconv->unseen_count,
159 gtk_label_get_text(GTK_LABEL(gtkconv->tab_label)));
160 }
161 }
162
163 /* get rid of the last newline */
164 if (tooltip_text->len > 0)
165 tooltip_text = g_string_truncate(tooltip_text, tooltip_text->len - 1);
166
167 ui_ops->set_tooltip(tooltip_text->str);
168
169 g_string_free(tooltip_text, TRUE);
170 }
171
172 g_list_free(convs);
173
174 } else if (ui_ops->set_tooltip) {
175 ui_ops->set_tooltip(NULL);
176 }
177
178 /* iterate through all accounts and determine which
179 * status to show in the tray icon based on the following
180 * ranks (highest encountered rank will be used):
181 *
182 * 1) OFFLINE
183 * 2) ONLINE
184 * 3) ONLINE_PENDING
185 * 4) AWAY
186 * 5) AWAY_PENDING
187 * 6) CONNECTING
188 */
189 for(l = gaim_accounts_get_all(); l != NULL; l = l->next) {
190 DockletStatus tmpstatus = DOCKLET_STATUS_OFFLINE;
191
192 GaimAccount *account = (GaimAccount*)l->data;
193 GaimStatus *account_status;
194
195 if (!gaim_account_get_enabled(account, GAIM_GTK_UI))
196 continue;
197
198 if (gaim_account_is_disconnected(account))
199 continue;
200
201 account_status = gaim_account_get_active_status(account);
202
203 if (gaim_account_is_connecting(account)) {
204 tmpstatus = DOCKLET_STATUS_CONNECTING;
205 } else if (gaim_status_is_online(account_status)) {
206 if (!gaim_status_is_available(account_status)) {
207 if (pending)
208 tmpstatus = DOCKLET_STATUS_AWAY_PENDING;
209 else
210 tmpstatus = DOCKLET_STATUS_AWAY;
211 }
212 else {
213 if (pending)
214 tmpstatus = DOCKLET_STATUS_ONLINE_PENDING;
215 else
216 tmpstatus = DOCKLET_STATUS_ONLINE;
217 }
218 }
219
220 if (tmpstatus > newstatus)
221 newstatus = tmpstatus;
222 }
223
224 /* update the icon if we changed status */
225 if (status != newstatus) {
226 status = newstatus;
227
228 if (ui_ops && ui_ops->update_icon)
229 ui_ops->update_icon(status);
230
231 /* and schedule the blinker function if messages are pending */
232 if ((status == DOCKLET_STATUS_ONLINE_PENDING
233 || status == DOCKLET_STATUS_AWAY_PENDING)
234 && docklet_blinking_timer == 0) {
235 docklet_blinking_timer = g_timeout_add(500, docklet_blink_icon, &handle);
236 }
237 }
238
239 return FALSE; /* for when we're called by the glib idle handler */
240 }
241
242 static gboolean
243 online_account_supports_chat()
244 {
245 GList *c = NULL;
246 c = gaim_connections_get_all();
247
248 while(c != NULL) {
249 GaimConnection *gc = c->data;
250 GaimPluginProtocolInfo *prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
251 if (prpl_info != NULL && prpl_info->chat_info != NULL)
252 return TRUE;
253 c = c->next;
254 }
255
256 return FALSE;
257 }
258
259 /**************************************************************************
260 * callbacks and signal handlers
261 **************************************************************************/
262 static void
263 gaim_quit_cb()
264 {
265 /* TODO: confirm quit while pending */
266 }
267
268 static void
269 docklet_update_status_cb(void *data)
270 {
271 docklet_update_status();
272 }
273
274 static void
275 docklet_prefs_cb(const char *name, GaimPrefType type,
276 gconstpointer val, gpointer data)
277 {
278 docklet_update_status();
279 }
280
281 static void
282 docklet_conv_updated_cb(GaimConversation *conv, GaimConvUpdateType type)
283 {
284 if (type == GAIM_CONV_UPDATE_UNSEEN)
285 docklet_update_status();
286 }
287
288 static void
289 docklet_signed_on_cb(GaimConnection *gc)
290 {
291 if (!enable_join_chat) {
292 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info != NULL)
293 enable_join_chat = TRUE;
294 }
295 docklet_update_status();
296 }
297
298 static void
299 docklet_signed_off_cb(GaimConnection *gc)
300 {
301 if (enable_join_chat) {
302 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info != NULL)
303 enable_join_chat = online_account_supports_chat();
304 }
305 docklet_update_status();
306 }
307
308 /**************************************************************************
309 * docklet pop-up menu
310 **************************************************************************/
311 static void
312 docklet_toggle_mute(GtkWidget *toggle, void *data)
313 {
314 gaim_prefs_set_bool("/gaim/gtk/sound/mute", GTK_CHECK_MENU_ITEM(toggle)->active);
315 }
316
317 static void
318 docklet_toggle_blist(GtkWidget *toggle, void *data)
319 {
320 gaim_blist_set_visible(GTK_CHECK_MENU_ITEM(toggle)->active);
321 }
322
323 #ifdef _WIN32
324 /* This is a workaround for a bug in windows GTK+. Clicking outside of the
325 menu does not get rid of it, so instead we get rid of it as soon as the
326 pointer leaves the menu. */
327 static gboolean
328 hide_docklet_menu(gpointer data)
329 {
330 if (data != NULL) {
331 gtk_menu_popdown(GTK_MENU(data));
332 }
333 return FALSE;
334 }
335
336 static gboolean
337 docklet_menu_leave_enter(GtkWidget *menu, GdkEventCrossing *event, void *data)
338 {
339 static guint hide_docklet_timer = 0;
340 if (event->type == GDK_LEAVE_NOTIFY && event->detail == GDK_NOTIFY_ANCESTOR) {
341 gaim_debug(GAIM_DEBUG_INFO, "docklet", "menu leave-notify-event\n");
342 /* Add some slop so that the menu doesn't annoyingly disappear when mousing around */
343 if (hide_docklet_timer == 0) {
344 hide_docklet_timer = gaim_timeout_add(500,
345 hide_docklet_menu, menu);
346 }
347 } else if (event->type == GDK_ENTER_NOTIFY && event->detail == GDK_NOTIFY_ANCESTOR) {
348 gaim_debug(GAIM_DEBUG_INFO, "docklet", "menu enter-notify-event\n");
349 if (hide_docklet_timer != 0) {
350 /* Cancel the hiding if we reenter */
351
352 gaim_timeout_remove(hide_docklet_timer);
353 hide_docklet_timer = 0;
354 }
355 }
356 return FALSE;
357 }
358 #endif
359
360 static void
361 show_custom_status_editor_cb(GtkMenuItem *menuitem, gpointer user_data)
362 {
363 GaimSavedStatus *saved_status;
364 saved_status = gaim_savedstatus_get_current();
365 gaim_gtk_status_editor_show(FALSE,
366 gaim_savedstatus_is_transient(saved_status) ? saved_status : NULL);
367 }
368
369 static void
370 activate_status_primitive_cb(GtkMenuItem *menuitem, gpointer user_data)
371 {
372 GaimStatusPrimitive primitive;
373 GaimSavedStatus *saved_status;
374
375 primitive = GPOINTER_TO_INT(user_data);
376
377 /* Try to lookup an already existing transient saved status */
378 saved_status = gaim_savedstatus_find_transient_by_type_and_message(primitive, NULL);
379
380 /* Create a new transient saved status if we weren't able to find one */
381 if (saved_status == NULL)
382 saved_status = gaim_savedstatus_new(NULL, primitive);
383
384 /* Set the status for each account */
385 gaim_savedstatus_activate(saved_status);
386 }
387
388 static void
389 activate_saved_status_cb(GtkMenuItem *menuitem, gpointer user_data)
390 {
391 time_t creation_time;
392 GaimSavedStatus *saved_status;
393
394 creation_time = GPOINTER_TO_INT(user_data);
395 saved_status = gaim_savedstatus_find_by_creation_time(creation_time);
396 if (saved_status != NULL)
397 gaim_savedstatus_activate(saved_status);
398 }
399
400 static GtkWidget *
401 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)
402 {
403 GtkWidget *menuitem;
404 GdkPixbuf *pixbuf;
405 GtkWidget *image;
406
407 menuitem = gtk_image_menu_item_new_with_mnemonic(str);
408
409 if (menu)
410 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
411
412 if (sf)
413 g_signal_connect(G_OBJECT(menuitem), "activate", sf, data);
414
415 pixbuf = gaim_gtk_create_gaim_icon_with_status(primitive, 0.5);
416 image = gtk_image_new_from_pixbuf(pixbuf);
417 g_object_unref(pixbuf);
418 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image);
419
420 gtk_widget_show_all(menuitem);
421
422 return menuitem;
423 }
424
425 static GtkWidget *
426 docklet_status_submenu()
427 {
428 GtkWidget *submenu, *menuitem;
429 GList *popular_statuses, *cur;
430
431 submenu = gtk_menu_new();
432 menuitem = gtk_menu_item_new_with_label(_("Change Status"));
433 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu);
434
435 new_menu_item_with_gaim_icon(submenu, _("Available"),
436 GAIM_STATUS_AVAILABLE, G_CALLBACK(activate_status_primitive_cb),
437 GINT_TO_POINTER(GAIM_STATUS_AVAILABLE), 0, 0, NULL);
438
439 new_menu_item_with_gaim_icon(submenu, _("Away"),
440 GAIM_STATUS_AWAY, G_CALLBACK(activate_status_primitive_cb),
441 GINT_TO_POINTER(GAIM_STATUS_AWAY), 0, 0, NULL);
442
443 new_menu_item_with_gaim_icon(submenu, _("Invisible"),
444 GAIM_STATUS_INVISIBLE, G_CALLBACK(activate_status_primitive_cb),
445 GINT_TO_POINTER(GAIM_STATUS_INVISIBLE), 0, 0, NULL);
446
447 new_menu_item_with_gaim_icon(submenu, _("Offline"),
448 GAIM_STATUS_OFFLINE, G_CALLBACK(activate_status_primitive_cb),
449 GINT_TO_POINTER(GAIM_STATUS_OFFLINE), 0, 0, NULL);
450
451 popular_statuses = gaim_savedstatuses_get_popular(6);
452 if (popular_statuses != NULL)
453 gaim_separator(submenu);
454 for (cur = popular_statuses; cur != NULL; cur = cur->next)
455 {
456 GaimSavedStatus *saved_status = cur->data;
457 time_t creation_time = gaim_savedstatus_get_creation_time(saved_status);
458 new_menu_item_with_gaim_icon(submenu,
459 gaim_savedstatus_get_title(saved_status),
460 gaim_savedstatus_get_type(saved_status), G_CALLBACK(activate_saved_status_cb),
461 GINT_TO_POINTER(creation_time), 0, 0, NULL);
462 }
463 g_list_free(popular_statuses);
464
465 gaim_separator(submenu);
466
467 new_menu_item_with_gaim_icon(submenu, _("New..."), GAIM_STATUS_AVAILABLE, G_CALLBACK(show_custom_status_editor_cb), NULL, 0, 0, NULL);
468 new_menu_item_with_gaim_icon(submenu, _("Saved..."), GAIM_STATUS_AVAILABLE, G_CALLBACK(gaim_gtk_status_window_show), NULL, 0, 0, NULL);
469
470 return menuitem;
471 }
472
473 static void
474 docklet_menu() {
475 static GtkWidget *menu = NULL;
476 GtkWidget *menuitem;
477
478 if (menu) {
479 gtk_widget_destroy(menu);
480 }
481
482 menu = gtk_menu_new();
483
484 menuitem = gtk_check_menu_item_new_with_label(_("Show Buddy List"));
485 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), gaim_prefs_get_bool("/gaim/gtk/blist/list_visible"));
486 g_signal_connect(G_OBJECT(menuitem), "toggled", G_CALLBACK(docklet_toggle_blist), NULL);
487 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
488
489 menuitem = gtk_menu_item_new_with_label(_("Unread Messages"));
490
491 if (status == DOCKLET_STATUS_ONLINE_PENDING || status == DOCKLET_STATUS_AWAY_PENDING) {
492 GtkWidget *submenu = gtk_menu_new();
493 GList *l = get_pending_list(0);
494 if (l == NULL) {
495 gtk_widget_set_sensitive(menuitem, FALSE);
496 gaim_debug_warning("docklet",
497 "status indicates messages pending, but no conversations with unseen messages were found.");
498 } else {
499 gaim_gtk_conversations_fill_menu(submenu, l);
500 g_list_free(l);
501 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu);
502 }
503 } else {
504 gtk_widget_set_sensitive(menuitem, FALSE);
505 }
506 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
507
508 gaim_separator(menu);
509
510 menuitem = gaim_new_item_from_stock(menu, _("New Message..."), GAIM_STOCK_IM, G_CALLBACK(gaim_gtkdialogs_im), NULL, 0, 0, NULL);
511 if (status == DOCKLET_STATUS_OFFLINE)
512 gtk_widget_set_sensitive(menuitem, FALSE);
513
514 menuitem = docklet_status_submenu();
515 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
516
517 gaim_separator(menu);
518
519 gaim_new_item_from_stock(menu, _("Accounts"), GAIM_STOCK_ACCOUNTS, G_CALLBACK(gaim_gtk_accounts_window_show), NULL, 0, 0, NULL);
520 gaim_new_item_from_stock(menu, _("Plugins"), GAIM_STOCK_PLUGIN, G_CALLBACK(gaim_gtk_plugin_dialog_show), NULL, 0, 0, NULL);
521 gaim_new_item_from_stock(menu, _("Preferences"), GTK_STOCK_PREFERENCES, G_CALLBACK(gaim_gtk_prefs_show), NULL, 0, 0, NULL);
522
523 gaim_separator(menu);
524
525 menuitem = gtk_check_menu_item_new_with_label(_("Mute Sounds"));
526 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), gaim_prefs_get_bool("/gaim/gtk/sound/mute"));
527 if (!strcmp(gaim_prefs_get_string("/gaim/gtk/sound/method"), "none"))
528 gtk_widget_set_sensitive(GTK_WIDGET(menuitem), FALSE);
529 g_signal_connect(G_OBJECT(menuitem), "toggled", G_CALLBACK(docklet_toggle_mute), NULL);
530 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
531
532 gaim_separator(menu);
533
534 /* TODO: need a submenu to change status, this needs to "link"
535 * to the status in the buddy list gtkstatusbox
536 */
537
538 gaim_new_item_from_stock(menu, _("Quit"), GTK_STOCK_QUIT, G_CALLBACK(gaim_core_quit), NULL, 0, 0, NULL);
539
540 #ifdef _WIN32
541 g_signal_connect(menu, "leave-notify-event", G_CALLBACK(docklet_menu_leave_enter), NULL);
542 g_signal_connect(menu, "enter-notify-event", G_CALLBACK(docklet_menu_leave_enter), NULL);
543 #endif
544 gtk_widget_show_all(menu);
545 gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
546 ui_ops->position_menu,
547 NULL, 0, gtk_get_current_event_time());
548 }
549
550 /**************************************************************************
551 * public api for ui_ops
552 **************************************************************************/
553 void
554 docklet_clicked(int button_type)
555 {
556 switch (button_type) {
557 case 1:
558 if (status == DOCKLET_STATUS_ONLINE_PENDING || status == DOCKLET_STATUS_AWAY_PENDING) {
559 GList *l = get_pending_list(1);
560 if (l != NULL) {
561 gaim_gtkconv_present_conversation((GaimConversation *)l->data);
562 g_list_free(l);
563 }
564 } else {
565 gaim_gtk_blist_toggle_visibility();
566 }
567 break;
568 case 3:
569 docklet_menu();
570 break;
571 }
572 }
573
574 void
575 docklet_embedded()
576 {
577 if (!visibility_manager) {
578 gaim_gtk_blist_visibility_manager_add();
579 visibility_manager = TRUE;
580 }
581 docklet_update_status();
582 if (ui_ops && ui_ops->update_icon)
583 ui_ops->update_icon(status);
584 }
585
586 void
587 docklet_remove()
588 {
589 if (visibility_manager) {
590 gaim_gtk_blist_visibility_manager_remove();
591 visibility_manager = FALSE;
592 }
593 }
594
595 void
596 docklet_unload()
597 {
598 gaim_plugin_unload(handle);
599 }
600
601 void
602 docklet_set_ui_ops(struct docklet_ui_ops *ops)
603 {
604 ui_ops = ops;
605 }
606
607 /**************************************************************************
608 * plugin glue
609 **************************************************************************/
610 static gboolean
611 plugin_load(GaimPlugin *plugin)
612 {
613 void *conn_handle = gaim_connections_get_handle();
614 void *conv_handle = gaim_conversations_get_handle();
615 void *accounts_handle = gaim_accounts_get_handle();
616 void *core_handle = gaim_get_core();
617
618 gaim_debug(GAIM_DEBUG_INFO, "docklet", "plugin loaded\n");
619
620 handle = plugin;
621
622 docklet_ui_init();
623 if (ui_ops && ui_ops->create)
624 ui_ops->create();
625 gaim_signal_connect(conn_handle, "signed-on",
626 plugin, GAIM_CALLBACK(docklet_signed_on_cb), NULL);
627 gaim_signal_connect(conn_handle, "signed-off",
628 plugin, GAIM_CALLBACK(docklet_signed_off_cb), NULL);
629 gaim_signal_connect(accounts_handle, "account-status-changed",
630 plugin, GAIM_CALLBACK(docklet_update_status_cb), NULL);
631 gaim_signal_connect(conv_handle, "received-im-msg",
632 plugin, GAIM_CALLBACK(docklet_update_status_cb), NULL);
633 gaim_signal_connect(conv_handle, "conversation-created",
634 plugin, GAIM_CALLBACK(docklet_update_status_cb), NULL);
635 gaim_signal_connect(conv_handle, "deleting-conversation",
636 plugin, GAIM_CALLBACK(docklet_update_status_cb), NULL);
637 gaim_signal_connect(conv_handle, "conversation-updated",
638 plugin, GAIM_CALLBACK(docklet_conv_updated_cb), NULL);
639
640 gaim_signal_connect(core_handle, "quitting",
641 plugin, GAIM_CALLBACK(gaim_quit_cb), NULL);
642
643 gaim_prefs_connect_callback(plugin, "/plugins/gtk/docklet/blink_im",
644 docklet_prefs_cb, NULL);
645 gaim_prefs_connect_callback(plugin, "/plugins/gtk/docklet/blink_chat",
646 docklet_prefs_cb, NULL);
647
648 enable_join_chat = online_account_supports_chat();
649
650 return TRUE;
651 }
652
653 static gboolean
654 plugin_unload(GaimPlugin *plugin)
655 {
656 if (ui_ops && ui_ops->destroy)
657 ui_ops->destroy();
658
659 /* remove callbacks */
660 gaim_signals_disconnect_by_handle(handle);
661 gaim_prefs_disconnect_by_handle(handle);
662
663 gaim_debug(GAIM_DEBUG_INFO, "docklet", "plugin unloaded\n");
664
665 return TRUE;
666 }
667
668 static GtkWidget *
669 plugin_config_frame(GaimPlugin *plugin)
670 {
671 GtkWidget *frame;
672 GtkWidget *vbox;
673 GtkSizeGroup *sg;
674 GtkWidget *dd;
675
676 frame = gtk_vbox_new(FALSE, 18);
677 gtk_container_set_border_width(GTK_CONTAINER(frame), 12);
678
679 vbox = gaim_gtk_make_frame(frame, _("Blink tray icon for unread..."));
680 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
681
682 dd = gaim_gtk_prefs_dropdown(vbox, _("_Instant Messages:"),
683 GAIM_PREF_STRING, "/plugins/gtk/docklet/blink_im",
684 _("Never"), "never",
685 _("In hidden conversations"), "hidden",
686 _("Always"), "always",
687 NULL);
688 gtk_size_group_add_widget(sg, dd);
689
690 dd = gaim_gtk_prefs_dropdown(vbox, _("C_hat Messages:"),
691 GAIM_PREF_STRING, "/plugins/gtk/docklet/blink_chat",
692 _("Never"), "never",
693 _("When my nick is said"), "nick",
694 _("Always"), "always",
695 NULL);
696 gtk_size_group_add_widget(sg, dd);
697
698 gtk_widget_show_all(frame);
699 return frame;
700 }
701
702 static GaimGtkPluginUiInfo ui_info =
703 {
704 plugin_config_frame,
705 0 /* page_num (Reserved) */
706 };
707
708 static GaimPluginInfo info =
709 {
710 GAIM_PLUGIN_MAGIC,
711 GAIM_MAJOR_VERSION,
712 GAIM_MINOR_VERSION,
713 GAIM_PLUGIN_STANDARD, /**< type */
714 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */
715 0, /**< flags */
716 NULL, /**< dependencies */
717 GAIM_PRIORITY_DEFAULT, /**< priority */
718
719 DOCKLET_PLUGIN_ID, /**< id */
720 N_("System Tray Icon"), /**< name */
721 VERSION, /**< version */
722 /** summary */
723 N_("Displays an icon for Gaim in the system tray."),
724 /** description */
725 N_("Displays a system tray icon (in GNOME, KDE, or Windows for example) "
726 "to show the current status of Gaim, allow fast access to commonly "
727 "used functions, and to toggle display of the buddy list. "
728 "Also provides options to blink for unread messages."),
729 /** author */
730 "Robert McQueen <robot101@debian.org>"
731 "\n\t\t\tCasey Harkins <charkins@users.sf.net>",
732 GAIM_WEBSITE, /**< homepage */
733
734 plugin_load, /**< load */
735 plugin_unload, /**< unload */
736 NULL, /**< destroy */
737
738 &ui_info, /**< ui_info */
739 NULL, /**< extra_info */
740 NULL,
741 NULL
742 };
743
744 static void
745 plugin_init(GaimPlugin *plugin)
746 {
747 gaim_prefs_add_none("/plugins/gtk/docklet");
748 gaim_prefs_add_string("/plugins/gtk/docklet/blink_im", "hidden");
749 gaim_prefs_add_string("/plugins/gtk/docklet/blink_chat", "never");
750 }
751
752 GAIM_INIT_PLUGIN(docklet, plugin_init, info)

mercurial