2 * System tray icon (aka docklet) plugin for Purple
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>
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA
28 #include "conversation.h"
34 #include "gtkaccount.h"
37 #include "gtkplugin.h"
39 #include "gtksavedstatuses.h"
41 #include "gtkstatusbox.h"
43 #include "pidginstock.h"
44 #include "gtkdocklet.h"
45 #include "gtkdialogs.h"
47 #ifndef DOCKLET_TOOLTIP_LINE_LIMIT
48 #define DOCKLET_TOOLTIP_LINE_LIMIT 5
52 static struct docklet_ui_ops
*ui_ops
= NULL
;
53 static PurpleStatusPrimitive status
= PURPLE_STATUS_OFFLINE
;
54 static gboolean pending
= FALSE
;
55 static gboolean connecting
= FALSE
;
56 static gboolean enable_join_chat
= FALSE
;
57 static guint docklet_blinking_timer
= 0;
58 static gboolean visible
= FALSE
;
59 static gboolean visibility_manager
= FALSE
;
61 /**************************************************************************
62 * docklet status and utility functions
63 **************************************************************************/
65 docklet_blink_icon(gpointer data
)
67 static gboolean blinked
= FALSE
;
68 gboolean ret
= FALSE
; /* by default, don't keep blinking */
72 if(pending
&& !connecting
) {
74 if (ui_ops
&& ui_ops
->blank_icon
)
77 pidgin_docklet_update_icon();
79 ret
= TRUE
; /* keep blinking */
81 docklet_blinking_timer
= 0;
89 get_pending_list(guint max
)
93 l_im
= pidgin_conversations_find_unseen_list(PURPLE_CONV_TYPE_IM
,
97 /* Short circuit if we have our information already */
98 if (max
== 1 && l_im
!= NULL
)
101 l_chat
= pidgin_conversations_find_unseen_list(PURPLE_CONV_TYPE_CHAT
,
105 if (l_im
!= NULL
&& l_chat
!= NULL
)
106 return g_list_concat(l_im
, l_chat
);
107 else if (l_im
!= NULL
)
114 docklet_update_status(void)
118 PurpleSavedStatus
*saved_status
;
119 PurpleStatusPrimitive newstatus
= PURPLE_STATUS_OFFLINE
;
120 gboolean newpending
= FALSE
, newconnecting
= FALSE
;
122 /* get the current savedstatus */
123 saved_status
= purple_savedstatus_get_current();
125 /* determine if any ims have unseen messages */
126 convs
= get_pending_list(DOCKLET_TOOLTIP_LINE_LIMIT
);
128 if (!strcmp(purple_prefs_get_string(PIDGIN_PREFS_ROOT
"/docklet/show"), "pending")) {
129 if (convs
&& ui_ops
->create
&& !visible
) {
133 } else if (!convs
&& ui_ops
->destroy
&& visible
) {
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 PurpleConversation
*conv
= (PurpleConversation
*)l
->data
;
152 PidginConversation
*gtkconv
= PIDGIN_CONVERSATION(conv
);
154 if (count
== DOCKLET_TOOLTIP_LINE_LIMIT
- 1) {
155 g_string_append(tooltip_text
, _("Right-click for more unread messages...\n"));
157 g_string_append_printf(tooltip_text
,
158 ngettext("%d unread message from %s\n", "%d unread messages from %s\n", gtkconv
->unseen_count
),
159 gtkconv
->unseen_count
,
160 purple_conversation_get_title(conv
));
162 g_string_append_printf(tooltip_text
,
163 ngettext("%d unread message from %s\n", "%d unread messages from %s\n",
164 GPOINTER_TO_INT(purple_conversation_get_data(conv
, "unseen-count"))),
165 GPOINTER_TO_INT(purple_conversation_get_data(conv
, "unseen-count")),
166 purple_conversation_get_title(conv
));
170 /* get rid of the last newline */
171 if (tooltip_text
->len
> 0)
172 tooltip_text
= g_string_truncate(tooltip_text
, tooltip_text
->len
- 1);
174 ui_ops
->set_tooltip(tooltip_text
->str
);
176 g_string_free(tooltip_text
, TRUE
);
181 } else if (ui_ops
->set_tooltip
) {
182 char *tooltip_text
= g_strconcat(PIDGIN_NAME
, " - ",
183 purple_savedstatus_get_title(saved_status
), NULL
);
184 ui_ops
->set_tooltip(tooltip_text
);
185 g_free(tooltip_text
);
188 for(l
= purple_accounts_get_all(); l
!= NULL
; l
= l
->next
) {
190 PurpleAccount
*account
= (PurpleAccount
*)l
->data
;
191 PurpleStatus
*account_status
;
193 if (!purple_account_get_enabled(account
, PIDGIN_UI
))
196 if (purple_account_is_disconnected(account
))
199 account_status
= purple_account_get_active_status(account
);
200 if (purple_account_is_connecting(account
))
201 newconnecting
= TRUE
;
204 newstatus
= purple_savedstatus_get_type(saved_status
);
206 /* update the icon if we changed status */
207 if (status
!= newstatus
|| pending
!=newpending
|| connecting
!=newconnecting
) {
209 pending
= newpending
;
210 connecting
= newconnecting
;
212 pidgin_docklet_update_icon();
214 /* and schedule the blinker function if messages are pending */
215 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT
"/docklet/blink")
216 && pending
&& !connecting
&& docklet_blinking_timer
== 0) {
217 docklet_blinking_timer
= g_timeout_add(500, docklet_blink_icon
, NULL
);
221 return FALSE
; /* for when we're called by the glib idle handler */
225 online_account_supports_chat(void)
228 c
= purple_connections_get_all();
231 PurpleConnection
*gc
= c
->data
;
232 PurplePluginProtocolInfo
*prpl_info
= PURPLE_PLUGIN_PROTOCOL_INFO(gc
->prpl
);
233 if (prpl_info
!= NULL
&& prpl_info
->chat_info
!= NULL
)
241 /**************************************************************************
242 * callbacks and signal handlers
243 **************************************************************************/
248 /* TODO: confirm quit while pending */
253 docklet_update_status_cb(void *data
)
255 docklet_update_status();
259 docklet_conv_updated_cb(PurpleConversation
*conv
, PurpleConvUpdateType type
)
261 if (type
== PURPLE_CONV_UPDATE_UNSEEN
)
262 docklet_update_status();
266 docklet_signed_on_cb(PurpleConnection
*gc
)
268 if (!enable_join_chat
) {
269 if (PURPLE_PLUGIN_PROTOCOL_INFO(gc
->prpl
)->chat_info
!= NULL
)
270 enable_join_chat
= TRUE
;
272 docklet_update_status();
276 docklet_signed_off_cb(PurpleConnection
*gc
)
278 if (enable_join_chat
) {
279 if (PURPLE_PLUGIN_PROTOCOL_INFO(gc
->prpl
)->chat_info
!= NULL
)
280 enable_join_chat
= online_account_supports_chat();
282 docklet_update_status();
286 docklet_show_pref_changed_cb(const char *name
, PurplePrefType type
,
287 gconstpointer value
, gpointer data
)
289 const char *val
= value
;
290 if (!strcmp(val
, "always")) {
291 if (ui_ops
->create
) {
294 else if (!visibility_manager
) {
295 pidgin_blist_visibility_manager_add();
296 visibility_manager
= TRUE
;
299 } else if (!strcmp(val
, "never")) {
300 if (visible
&& ui_ops
->destroy
)
303 if (visibility_manager
) {
304 pidgin_blist_visibility_manager_remove();
305 visibility_manager
= FALSE
;
307 docklet_update_status();
312 /**************************************************************************
313 * docklet pop-up menu
314 **************************************************************************/
316 docklet_toggle_mute(GtkWidget
*toggle
, void *data
)
318 purple_prefs_set_bool(PIDGIN_PREFS_ROOT
"/sound/mute", GTK_CHECK_MENU_ITEM(toggle
)->active
);
322 docklet_toggle_blink(GtkWidget
*toggle
, void *data
)
324 purple_prefs_set_bool(PIDGIN_PREFS_ROOT
"/docklet/blink", GTK_CHECK_MENU_ITEM(toggle
)->active
);
328 docklet_toggle_blist(GtkWidget
*toggle
, void *data
)
330 purple_blist_set_visible(GTK_CHECK_MENU_ITEM(toggle
)->active
);
334 /* This is a workaround for a bug in windows GTK+. Clicking outside of the
335 menu does not get rid of it, so instead we get rid of it as soon as the
336 pointer leaves the menu. */
338 hide_docklet_menu(gpointer data
)
341 gtk_menu_popdown(GTK_MENU(data
));
347 docklet_menu_leave_enter(GtkWidget
*menu
, GdkEventCrossing
*event
, void *data
)
349 static guint hide_docklet_timer
= 0;
351 if (event
->type
== GDK_LEAVE_NOTIFY
&& (event
->detail
== GDK_NOTIFY_ANCESTOR
||
352 event
->detail
== GDK_NOTIFY_UNKNOWN
)) {
353 purple_debug(PURPLE_DEBUG_INFO
, "docklet", "menu leave-notify-event\n");
354 /* Add some slop so that the menu doesn't annoyingly disappear when mousing around */
355 if (hide_docklet_timer
== 0) {
356 hide_docklet_timer
= purple_timeout_add(500,
357 hide_docklet_menu
, menu
);
359 } else if (event
->type
== GDK_ENTER_NOTIFY
&& event
->detail
== GDK_NOTIFY_ANCESTOR
) {
360 purple_debug(PURPLE_DEBUG_INFO
, "docklet", "menu enter-notify-event\n");
361 if (hide_docklet_timer
!= 0) {
362 /* Cancel the hiding if we reenter */
364 purple_timeout_remove(hide_docklet_timer
);
365 hide_docklet_timer
= 0;
372 /* There is a lot of code here for handling the status submenu, much of
373 * which is duplicated from the gtkstatusbox. It'd be nice to add API
374 * somewhere to simplify this (either in the statusbox, or in libpurple).
377 show_custom_status_editor_cb(GtkMenuItem
*menuitem
, gpointer user_data
)
379 PurpleSavedStatus
*saved_status
;
380 saved_status
= purple_savedstatus_get_current();
382 if (purple_savedstatus_get_type(saved_status
) == PURPLE_STATUS_AVAILABLE
)
383 saved_status
= purple_savedstatus_new(NULL
, PURPLE_STATUS_AWAY
);
385 pidgin_status_editor_show(FALSE
,
386 purple_savedstatus_is_transient(saved_status
) ? saved_status
: NULL
);
389 static PurpleSavedStatus
*
390 create_transient_status(PurpleStatusPrimitive primitive
, PurpleStatusType
*status_type
)
392 PurpleSavedStatus
*saved_status
= purple_savedstatus_new(NULL
, primitive
);
394 if(status_type
!= NULL
) {
395 GList
*tmp
, *active_accts
= purple_accounts_get_all_active();
396 for (tmp
= active_accts
; tmp
!= NULL
; tmp
= tmp
->next
) {
397 purple_savedstatus_set_substatus(saved_status
,
398 (PurpleAccount
*) tmp
->data
, status_type
, NULL
);
400 g_list_free(active_accts
);
407 activate_status_account_cb(GtkMenuItem
*menuitem
, gpointer user_data
)
409 PurpleStatusType
*status_type
;
410 PurpleStatusPrimitive primitive
;
411 PurpleSavedStatus
*saved_status
= NULL
;
412 GList
*iter
= purple_savedstatuses_get_all();
413 GList
*tmp
, *active_accts
= purple_accounts_get_all_active();
415 status_type
= (PurpleStatusType
*)user_data
;
416 primitive
= purple_status_type_get_primitive(status_type
);
418 for (; iter
!= NULL
; iter
= iter
->next
) {
419 PurpleSavedStatus
*ss
= iter
->data
;
420 if ((purple_savedstatus_get_type(ss
) == primitive
) && purple_savedstatus_is_transient(ss
) &&
421 purple_savedstatus_has_substatuses(ss
))
423 gboolean found
= FALSE
;
424 /* The currently enabled accounts must have substatuses for all the active accts */
425 for(tmp
= active_accts
; tmp
!= NULL
; tmp
= tmp
->next
) {
426 PurpleAccount
*acct
= tmp
->data
;
427 PurpleSavedStatusSub
*sub
= purple_savedstatus_get_substatus(ss
, acct
);
429 const PurpleStatusType
*sub_type
= purple_savedstatus_substatus_get_type(sub
);
430 const char *subtype_status_id
= purple_status_type_get_id(sub_type
);
431 if (subtype_status_id
&& !strcmp(subtype_status_id
,
432 purple_status_type_get_id(status_type
)))
443 g_list_free(active_accts
);
445 /* Create a new transient saved status if we weren't able to find one */
446 if (saved_status
== NULL
)
447 saved_status
= create_transient_status(primitive
, status_type
);
449 /* Set the status for each account */
450 purple_savedstatus_activate(saved_status
);
454 activate_status_primitive_cb(GtkMenuItem
*menuitem
, gpointer user_data
)
456 PurpleStatusPrimitive primitive
;
457 PurpleSavedStatus
*saved_status
;
459 primitive
= GPOINTER_TO_INT(user_data
);
461 /* Try to lookup an already existing transient saved status */
462 saved_status
= purple_savedstatus_find_transient_by_type_and_message(primitive
, NULL
);
464 /* Create a new transient saved status if we weren't able to find one */
465 if (saved_status
== NULL
)
466 saved_status
= create_transient_status(primitive
, NULL
);
468 /* Set the status for each account */
469 purple_savedstatus_activate(saved_status
);
473 activate_saved_status_cb(GtkMenuItem
*menuitem
, gpointer user_data
)
475 time_t creation_time
;
476 PurpleSavedStatus
*saved_status
;
478 creation_time
= GPOINTER_TO_INT(user_data
);
479 saved_status
= purple_savedstatus_find_by_creation_time(creation_time
);
480 if (saved_status
!= NULL
)
481 purple_savedstatus_activate(saved_status
);
485 new_menu_item_with_status_icon(GtkWidget
*menu
, const char *str
, PurpleStatusPrimitive primitive
, GCallback cb
, gpointer data
, guint accel_key
, guint accel_mods
, char *mod
)
491 menuitem
= gtk_image_menu_item_new_with_label(str
);
494 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), menuitem
);
497 g_signal_connect(G_OBJECT(menuitem
), "activate", cb
, data
);
499 pixbuf
= pidgin_create_status_icon(primitive
, menu
, PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL
);
500 image
= gtk_image_new_from_pixbuf(pixbuf
);
501 g_object_unref(pixbuf
);
502 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem
), image
);
504 gtk_widget_show_all(menuitem
);
510 add_account_statuses(GtkWidget
*menu
, PurpleAccount
*account
)
514 for (l
= purple_account_get_status_types(account
); l
!= NULL
; l
= l
->next
) {
515 PurpleStatusType
*status_type
= (PurpleStatusType
*)l
->data
;
516 PurpleStatusPrimitive prim
;
518 if (!purple_status_type_is_user_settable(status_type
))
521 prim
= purple_status_type_get_primitive(status_type
);
523 new_menu_item_with_status_icon(menu
,
524 purple_status_type_get_name(status_type
),
525 prim
, G_CALLBACK(activate_status_account_cb
),
526 status_type
, 0, 0, NULL
);
531 docklet_status_submenu(void)
533 GtkWidget
*submenu
, *menuitem
;
534 GList
*popular_statuses
, *cur
;
535 PidginStatusBox
*statusbox
= NULL
;
537 submenu
= gtk_menu_new();
538 menuitem
= gtk_menu_item_new_with_mnemonic(_("_Change Status"));
539 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem
), submenu
);
541 if(pidgin_blist_get_default_gtk_blist() != NULL
) {
542 statusbox
= PIDGIN_STATUS_BOX(pidgin_blist_get_default_gtk_blist()->statusbox
);
545 if(statusbox
&& statusbox
->account
!= NULL
) {
546 add_account_statuses(submenu
, statusbox
->account
);
547 } else if(statusbox
&& statusbox
->token_status_account
!= NULL
) {
548 add_account_statuses(submenu
, statusbox
->token_status_account
);
550 new_menu_item_with_status_icon(submenu
, _("Available"),
551 PURPLE_STATUS_AVAILABLE
, G_CALLBACK(activate_status_primitive_cb
),
552 GINT_TO_POINTER(PURPLE_STATUS_AVAILABLE
), 0, 0, NULL
);
554 new_menu_item_with_status_icon(submenu
, _("Away"),
555 PURPLE_STATUS_AWAY
, G_CALLBACK(activate_status_primitive_cb
),
556 GINT_TO_POINTER(PURPLE_STATUS_AWAY
), 0, 0, NULL
);
558 new_menu_item_with_status_icon(submenu
, _("Do not disturb"),
559 PURPLE_STATUS_UNAVAILABLE
, G_CALLBACK(activate_status_primitive_cb
),
560 GINT_TO_POINTER(PURPLE_STATUS_UNAVAILABLE
), 0, 0, NULL
);
562 new_menu_item_with_status_icon(submenu
, _("Invisible"),
563 PURPLE_STATUS_INVISIBLE
, G_CALLBACK(activate_status_primitive_cb
),
564 GINT_TO_POINTER(PURPLE_STATUS_INVISIBLE
), 0, 0, NULL
);
566 new_menu_item_with_status_icon(submenu
, _("Offline"),
567 PURPLE_STATUS_OFFLINE
, G_CALLBACK(activate_status_primitive_cb
),
568 GINT_TO_POINTER(PURPLE_STATUS_OFFLINE
), 0, 0, NULL
);
571 popular_statuses
= purple_savedstatuses_get_popular(6);
572 if (popular_statuses
!= NULL
)
573 pidgin_separator(submenu
);
574 for (cur
= popular_statuses
; cur
!= NULL
; cur
= cur
->next
)
576 PurpleSavedStatus
*saved_status
= cur
->data
;
577 time_t creation_time
= purple_savedstatus_get_creation_time(saved_status
);
578 new_menu_item_with_status_icon(submenu
,
579 purple_savedstatus_get_title(saved_status
),
580 purple_savedstatus_get_type(saved_status
), G_CALLBACK(activate_saved_status_cb
),
581 GINT_TO_POINTER(creation_time
), 0, 0, NULL
);
583 g_list_free(popular_statuses
);
585 pidgin_separator(submenu
);
587 pidgin_new_item_from_stock(submenu
, _("New..."), NULL
, G_CALLBACK(show_custom_status_editor_cb
), NULL
, 0, 0, NULL
);
588 pidgin_new_item_from_stock(submenu
, _("Saved..."), NULL
, G_CALLBACK(pidgin_status_window_show
), NULL
, 0, 0, NULL
);
596 plugin_act(GtkObject
*obj
, PurplePluginAction
*pam
)
598 if (pam
&& pam
->callback
)
603 build_plugin_actions(GtkWidget
*menu
, PurplePlugin
*plugin
,
607 PurplePluginAction
*action
= NULL
;
610 actions
= PURPLE_PLUGIN_ACTIONS(plugin
, context
);
612 for (l
= actions
; l
!= NULL
; l
= l
->next
)
616 action
= (PurplePluginAction
*) l
->data
;
617 action
->plugin
= plugin
;
618 action
->context
= context
;
620 menuitem
= gtk_menu_item_new_with_label(action
->label
);
621 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), menuitem
);
623 g_signal_connect(G_OBJECT(menuitem
), "activate",
624 G_CALLBACK(plugin_act
), action
);
625 g_object_set_data_full(G_OBJECT(menuitem
), "plugin_action",
627 (GDestroyNotify
)purple_plugin_action_free
);
628 gtk_widget_show(menuitem
);
631 pidgin_separator(menu
);
634 g_list_free(actions
);
639 docklet_plugin_actions(GtkWidget
*menu
)
641 GtkWidget
*menuitem
, *submenu
;
642 PurplePlugin
*plugin
= NULL
;
646 g_return_if_fail(menu
!= NULL
);
648 /* Add a submenu for each plugin with custom actions */
649 for (l
= purple_plugins_get_loaded(); l
; l
= l
->next
) {
650 plugin
= (PurplePlugin
*) l
->data
;
652 if (PURPLE_IS_PROTOCOL_PLUGIN(plugin
))
655 if (!PURPLE_PLUGIN_HAS_ACTIONS(plugin
))
658 menuitem
= gtk_image_menu_item_new_with_label(_(plugin
->info
->name
));
659 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), menuitem
);
661 submenu
= gtk_menu_new();
662 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem
), submenu
);
664 build_plugin_actions(submenu
, plugin
, NULL
);
669 pidgin_separator(menu
);
675 static GtkWidget
*menu
= NULL
;
679 gtk_widget_destroy(menu
);
682 menu
= gtk_menu_new();
684 menuitem
= gtk_check_menu_item_new_with_mnemonic(_("Show Buddy _List"));
685 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem
), purple_prefs_get_bool(PIDGIN_PREFS_ROOT
"/blist/list_visible"));
686 g_signal_connect(G_OBJECT(menuitem
), "toggled", G_CALLBACK(docklet_toggle_blist
), NULL
);
687 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), menuitem
);
689 menuitem
= gtk_menu_item_new_with_mnemonic(_("_Unread Messages"));
692 GtkWidget
*submenu
= gtk_menu_new();
693 GList
*l
= get_pending_list(0);
695 gtk_widget_set_sensitive(menuitem
, FALSE
);
696 purple_debug_warning("docklet",
697 "status indicates messages pending, but no conversations with unseen messages were found.");
699 pidgin_conversations_fill_menu(submenu
, l
);
701 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem
), submenu
);
704 gtk_widget_set_sensitive(menuitem
, FALSE
);
706 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), menuitem
);
708 pidgin_separator(menu
);
710 menuitem
= pidgin_new_item_from_stock(menu
, _("New _Message..."), PIDGIN_STOCK_TOOLBAR_MESSAGE_NEW
, G_CALLBACK(pidgin_dialogs_im
), NULL
, 0, 0, NULL
);
711 if (status
== PURPLE_STATUS_OFFLINE
)
712 gtk_widget_set_sensitive(menuitem
, FALSE
);
714 menuitem
= pidgin_new_item_from_stock(menu
, _("Join Chat..."), PIDGIN_STOCK_CHAT
,
715 G_CALLBACK(pidgin_blist_joinchat_show
), NULL
, 0, 0, NULL
);
716 if (status
== PURPLE_STATUS_OFFLINE
)
717 gtk_widget_set_sensitive(menuitem
, FALSE
);
719 menuitem
= docklet_status_submenu();
720 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), menuitem
);
722 pidgin_separator(menu
);
724 pidgin_new_item_from_stock(menu
, _("_Accounts"), NULL
, G_CALLBACK(pidgin_accounts_window_show
), NULL
, 0, 0, NULL
);
725 pidgin_new_item_from_stock(menu
, _("Plu_gins"), PIDGIN_STOCK_TOOLBAR_PLUGINS
, G_CALLBACK(pidgin_plugin_dialog_show
), NULL
, 0, 0, NULL
);
726 pidgin_new_item_from_stock(menu
, _("Pr_eferences"), GTK_STOCK_PREFERENCES
, G_CALLBACK(pidgin_prefs_show
), NULL
, 0, 0, NULL
);
728 pidgin_separator(menu
);
730 menuitem
= gtk_check_menu_item_new_with_mnemonic(_("Mute _Sounds"));
731 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem
), purple_prefs_get_bool(PIDGIN_PREFS_ROOT
"/sound/mute"));
732 if (!strcmp(purple_prefs_get_string(PIDGIN_PREFS_ROOT
"/sound/method"), "none"))
733 gtk_widget_set_sensitive(GTK_WIDGET(menuitem
), FALSE
);
734 g_signal_connect(G_OBJECT(menuitem
), "toggled", G_CALLBACK(docklet_toggle_mute
), NULL
);
735 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), menuitem
);
737 menuitem
= gtk_check_menu_item_new_with_mnemonic(_("_Blink on New Message"));
738 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem
), purple_prefs_get_bool(PIDGIN_PREFS_ROOT
"/docklet/blink"));
739 g_signal_connect(G_OBJECT(menuitem
), "toggled", G_CALLBACK(docklet_toggle_blink
), NULL
);
740 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), menuitem
);
742 pidgin_separator(menu
);
744 /* add plugin actions */
745 docklet_plugin_actions(menu
);
747 pidgin_new_item_from_stock(menu
, _("_Quit"), GTK_STOCK_QUIT
, G_CALLBACK(purple_core_quit
), NULL
, 0, 0, NULL
);
750 g_signal_connect(menu
, "leave-notify-event", G_CALLBACK(docklet_menu_leave_enter
), NULL
);
751 g_signal_connect(menu
, "enter-notify-event", G_CALLBACK(docklet_menu_leave_enter
), NULL
);
753 gtk_widget_show_all(menu
);
754 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
,
755 ui_ops
->position_menu
,
756 NULL
, 0, gtk_get_current_event_time());
759 /**************************************************************************
760 * public api for ui_ops
761 **************************************************************************/
763 pidgin_docklet_update_icon()
765 if (ui_ops
&& ui_ops
->update_icon
)
766 ui_ops
->update_icon(status
, connecting
, pending
);
770 pidgin_docklet_clicked(int button_type
)
772 switch (button_type
) {
775 GList
*l
= get_pending_list(1);
777 pidgin_conv_present_conversation((PurpleConversation
*)l
->data
);
781 pidgin_blist_toggle_visibility();
791 pidgin_docklet_embedded()
793 if (!visibility_manager
794 && strcmp(purple_prefs_get_string(PIDGIN_PREFS_ROOT
"/docklet/show"), "pending")) {
795 pidgin_blist_visibility_manager_add();
796 visibility_manager
= TRUE
;
799 docklet_update_status();
800 pidgin_docklet_update_icon();
804 pidgin_docklet_remove()
807 if (visibility_manager
) {
808 pidgin_blist_visibility_manager_remove();
809 visibility_manager
= FALSE
;
811 if (docklet_blinking_timer
) {
812 g_source_remove(docklet_blinking_timer
);
813 docklet_blinking_timer
= 0;
816 status
= PURPLE_STATUS_OFFLINE
;
821 pidgin_docklet_set_ui_ops(struct docklet_ui_ops
*ops
)
827 pidgin_docklet_get_handle()
834 pidgin_docklet_init()
836 void *conn_handle
= purple_connections_get_handle();
837 void *conv_handle
= purple_conversations_get_handle();
838 void *accounts_handle
= purple_accounts_get_handle();
839 void *status_handle
= purple_savedstatuses_get_handle();
840 void *docklet_handle
= pidgin_docklet_get_handle();
842 purple_prefs_add_none(PIDGIN_PREFS_ROOT
"/docklet");
843 purple_prefs_add_bool(PIDGIN_PREFS_ROOT
"/docklet/blink", FALSE
);
844 purple_prefs_add_string(PIDGIN_PREFS_ROOT
"/docklet/show", "always");
845 purple_prefs_connect_callback(docklet_handle
, PIDGIN_PREFS_ROOT
"/docklet/show",
846 docklet_show_pref_changed_cb
, NULL
);
849 if (!strcmp(purple_prefs_get_string(PIDGIN_PREFS_ROOT
"/docklet/show"), "always") && ui_ops
&& ui_ops
->create
)
852 purple_signal_connect(conn_handle
, "signed-on",
853 docklet_handle
, PURPLE_CALLBACK(docklet_signed_on_cb
), NULL
);
854 purple_signal_connect(conn_handle
, "signed-off",
855 docklet_handle
, PURPLE_CALLBACK(docklet_signed_off_cb
), NULL
);
856 purple_signal_connect(accounts_handle
, "account-connecting",
857 docklet_handle
, PURPLE_CALLBACK(docklet_update_status_cb
), NULL
);
858 purple_signal_connect(conv_handle
, "received-im-msg",
859 docklet_handle
, PURPLE_CALLBACK(docklet_update_status_cb
), NULL
);
860 purple_signal_connect(conv_handle
, "conversation-created",
861 docklet_handle
, PURPLE_CALLBACK(docklet_update_status_cb
), NULL
);
862 purple_signal_connect(conv_handle
, "deleting-conversation",
863 docklet_handle
, PURPLE_CALLBACK(docklet_update_status_cb
), NULL
);
864 purple_signal_connect(conv_handle
, "conversation-updated",
865 docklet_handle
, PURPLE_CALLBACK(docklet_conv_updated_cb
), NULL
);
866 purple_signal_connect(status_handle
, "savedstatus-changed",
867 docklet_handle
, PURPLE_CALLBACK(docklet_update_status_cb
), NULL
);
869 purple_signal_connect(purple_get_core(), "quitting",
870 docklet_handle
, PURPLE_CALLBACK(purple_quit_cb
), NULL
);
873 enable_join_chat
= online_account_supports_chat();
877 pidgin_docklet_uninit()
879 if (visible
&& ui_ops
&& ui_ops
->destroy
)