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