Change the oscar capabilities variable to be a guint64 everywhere instead
[pidgin-git.git] / pidgin / gtkdocklet-gtk.c
blob98beb64387432b173b337d94273053d5b1813381
1 /*
2 * System tray icon (aka docklet) plugin for Purple
4 * Copyright (C) 2007 Anders Hasselqvist
5 *
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
19 * 02111-1307, USA.
22 #include "internal.h"
23 #include "pidgin.h"
24 #include "debug.h"
25 #include "prefs.h"
26 #include "pidginstock.h"
27 #include "gtkdocklet.h"
29 /* globals */
30 GtkStatusIcon *docklet = NULL;
32 static void
33 docklet_gtk_status_activated_cb(GtkStatusIcon *status_icon, gpointer user_data)
35 pidgin_docklet_clicked(1);
38 static void
39 docklet_gtk_status_clicked_cb(GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data)
41 pidgin_docklet_clicked(button);
44 static void
45 docklet_gtk_status_update_icon(PurpleStatusPrimitive status, gboolean connecting, gboolean pending)
47 const gchar *icon_name = NULL;
49 switch (status) {
50 case PURPLE_STATUS_OFFLINE:
51 icon_name = PIDGIN_STOCK_TRAY_OFFLINE;
52 break;
53 case PURPLE_STATUS_AWAY:
54 icon_name = PIDGIN_STOCK_TRAY_AWAY;
55 break;
56 case PURPLE_STATUS_UNAVAILABLE:
57 icon_name = PIDGIN_STOCK_TRAY_BUSY;
58 break;
59 case PURPLE_STATUS_EXTENDED_AWAY:
60 icon_name = PIDGIN_STOCK_TRAY_XA;
61 break;
62 case PURPLE_STATUS_INVISIBLE:
63 icon_name = PIDGIN_STOCK_TRAY_INVISIBLE;
64 break;
65 default:
66 icon_name = PIDGIN_STOCK_TRAY_AVAILABLE;
67 break;
70 if (pending)
71 icon_name = PIDGIN_STOCK_TRAY_PENDING;
72 if (connecting)
73 icon_name = PIDGIN_STOCK_TRAY_CONNECT;
75 if (icon_name) {
76 gtk_status_icon_set_from_icon_name(docklet, icon_name);
80 static void
81 docklet_gtk_status_set_tooltip(gchar *tooltip)
83 if (tooltip) {
84 gtk_status_icon_set_tooltip(docklet, tooltip);
85 } else {
86 gtk_status_icon_set_tooltip(docklet, NULL);
90 static void
91 docklet_gtk_status_position_menu(GtkMenu *menu,
92 int *x, int *y, gboolean *push_in,
93 gpointer user_data)
95 gtk_status_icon_position_menu(menu, x, y, push_in, docklet);
98 static void
99 docklet_gtk_status_destroy(void)
101 g_return_if_fail(docklet != NULL);
103 pidgin_docklet_remove();
105 g_object_unref(G_OBJECT(docklet));
106 docklet = NULL;
108 purple_debug_info("docklet", "GTK+ destroyed\n");
111 static void
112 docklet_gtk_status_create(gboolean recreate)
114 if (docklet) {
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");
133 static void
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,
144 NULL,
145 docklet_gtk_status_set_tooltip,
146 docklet_gtk_status_position_menu
149 void
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");