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