2 * System tray icon (aka docklet) plugin for Purple
4 * Copyright (C) 2007 Anders Hasselqvist
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 #include "pidginstock.h"
27 #include "gtkdocklet.h"
30 GtkStatusIcon
*docklet
= NULL
;
33 docklet_gtk_status_activated_cb(GtkStatusIcon
*status_icon
, gpointer user_data
)
35 pidgin_docklet_clicked(1);
39 docklet_gtk_status_clicked_cb(GtkStatusIcon
*status_icon
, guint button
, guint activate_time
, gpointer user_data
)
41 pidgin_docklet_clicked(button
);
45 docklet_gtk_status_update_icon(PurpleStatusPrimitive status
, gboolean connecting
, gboolean pending
)
47 const gchar
*icon_name
= NULL
;
50 case PURPLE_STATUS_OFFLINE
:
51 icon_name
= PIDGIN_STOCK_TRAY_OFFLINE
;
53 case PURPLE_STATUS_AWAY
:
54 icon_name
= PIDGIN_STOCK_TRAY_AWAY
;
56 case PURPLE_STATUS_UNAVAILABLE
:
57 icon_name
= PIDGIN_STOCK_TRAY_BUSY
;
59 case PURPLE_STATUS_EXTENDED_AWAY
:
60 icon_name
= PIDGIN_STOCK_TRAY_XA
;
62 case PURPLE_STATUS_INVISIBLE
:
63 icon_name
= PIDGIN_STOCK_TRAY_INVISIBLE
;
66 icon_name
= PIDGIN_STOCK_TRAY_AVAILABLE
;
71 icon_name
= PIDGIN_STOCK_TRAY_PENDING
;
73 icon_name
= PIDGIN_STOCK_TRAY_CONNECT
;
76 gtk_status_icon_set_from_icon_name(docklet
, icon_name
);
81 docklet_gtk_status_set_tooltip(gchar
*tooltip
)
84 gtk_status_icon_set_tooltip(docklet
, tooltip
);
86 gtk_status_icon_set_tooltip(docklet
, NULL
);
91 docklet_gtk_status_position_menu(GtkMenu
*menu
,
92 int *x
, int *y
, gboolean
*push_in
,
95 gtk_status_icon_position_menu(menu
, x
, y
, push_in
, docklet
);
99 docklet_gtk_status_destroy(void)
101 g_return_if_fail(docklet
!= NULL
);
103 pidgin_docklet_remove();
105 g_object_unref(G_OBJECT(docklet
));
108 purple_debug_info("docklet", "GTK+ destroyed\n");
112 docklet_gtk_status_create(gboolean recreate
)
115 /* if this is being called when a tray icon exists, it's because
116 something messed up. try destroying it before we proceed,
117 although docklet_refcount may be all hosed. hopefully won't happen. */
118 purple_debug_warning("docklet", "trying to create icon but it already exists?\n");
119 docklet_gtk_status_destroy();
122 docklet
= gtk_status_icon_new();
123 g_return_if_fail(docklet
!= NULL
);
125 g_signal_connect(G_OBJECT(docklet
), "activate", G_CALLBACK(docklet_gtk_status_activated_cb
), NULL
);
126 g_signal_connect(G_OBJECT(docklet
), "popup-menu", G_CALLBACK(docklet_gtk_status_clicked_cb
), NULL
);
128 pidgin_docklet_embedded();
129 gtk_status_icon_set_visible(docklet
, TRUE
);
130 purple_debug_info("docklet", "GTK+ created\n");
134 docklet_gtk_status_create_ui_op(void)
136 docklet_gtk_status_create(FALSE
);
139 static struct docklet_ui_ops ui_ops
=
141 docklet_gtk_status_create_ui_op
,
142 docklet_gtk_status_destroy
,
143 docklet_gtk_status_update_icon
,
145 docklet_gtk_status_set_tooltip
,
146 docklet_gtk_status_position_menu
150 docklet_ui_init(void)
152 pidgin_docklet_set_ui_ops(&ui_ops
);
153 gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(),
154 DATADIR G_DIR_SEPARATOR_S
"pixmaps" G_DIR_SEPARATOR_S
"pidgin" G_DIR_SEPARATOR_S
"tray");