Mercurial > pidgin.yaz
comparison pidgin/gtkdocklet-gtk.c @ 29627:6652fdb8baf5
Apparently, I only just imagined adding this file.
Refs #2629.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sun, 08 Nov 2009 23:36:28 +0000 |
parents | |
children | 87e124c52a47 |
comparison
equal
deleted
inserted
replaced
29626:1446436616d4 | 29627:6652fdb8baf5 |
---|---|
1 /* | |
2 * System tray icon (aka docklet) plugin for Purple | |
3 * | |
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. | |
10 * | |
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. | |
15 * | |
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. | |
20 */ | |
21 | |
22 #include "internal.h" | |
23 #include "pidgin.h" | |
24 #include "debug.h" | |
25 #include "prefs.h" | |
26 #include "pidginstock.h" | |
27 #include "gtkdocklet.h" | |
28 | |
29 #if GTK_CHECK_VERSION(2,10,0) | |
30 | |
31 /* globals */ | |
32 GtkStatusIcon *docklet = NULL; | |
33 | |
34 static void | |
35 docklet_gtk_status_activated_cb(GtkStatusIcon *status_icon, gpointer user_data) | |
36 { | |
37 purple_debug_info("docklet", "button clicked %d\n", 1); | |
38 | |
39 pidgin_docklet_clicked(1); | |
40 } | |
41 | |
42 static void | |
43 docklet_gtk_status_clicked_cb(GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data) | |
44 { | |
45 purple_debug_info("docklet", "button clicked %d\n", button); | |
46 | |
47 pidgin_docklet_clicked(button); | |
48 } | |
49 | |
50 static void | |
51 docklet_gtk_status_update_icon(PurpleStatusPrimitive status, gboolean connecting, gboolean pending) | |
52 { | |
53 const gchar *icon_name = NULL; | |
54 | |
55 switch (status) { | |
56 case PURPLE_STATUS_OFFLINE: | |
57 icon_name = PIDGIN_STOCK_TRAY_OFFLINE; | |
58 break; | |
59 case PURPLE_STATUS_AWAY: | |
60 icon_name = PIDGIN_STOCK_TRAY_AWAY; | |
61 break; | |
62 case PURPLE_STATUS_UNAVAILABLE: | |
63 icon_name = PIDGIN_STOCK_TRAY_BUSY; | |
64 break; | |
65 case PURPLE_STATUS_EXTENDED_AWAY: | |
66 icon_name = PIDGIN_STOCK_TRAY_XA; | |
67 break; | |
68 case PURPLE_STATUS_INVISIBLE: | |
69 icon_name = PIDGIN_STOCK_TRAY_INVISIBLE; | |
70 break; | |
71 default: | |
72 icon_name = PIDGIN_STOCK_TRAY_AVAILABLE; | |
73 break; | |
74 } | |
75 | |
76 if (pending) | |
77 icon_name = PIDGIN_STOCK_TRAY_PENDING; | |
78 if (connecting) | |
79 icon_name = PIDGIN_STOCK_TRAY_CONNECT; | |
80 | |
81 if (icon_name) { | |
82 gtk_status_icon_set_from_stock(docklet, icon_name); | |
83 } | |
84 } | |
85 | |
86 static void | |
87 docklet_gtk_status_set_tooltip(gchar *tooltip) | |
88 { | |
89 if (tooltip) { | |
90 gtk_status_icon_set_tooltip(docklet, tooltip); | |
91 } else { | |
92 gtk_status_icon_set_tooltip(docklet, NULL); | |
93 } | |
94 } | |
95 | |
96 static void | |
97 docklet_gtk_status_position_menu(GtkMenu *menu, | |
98 int *x, int *y, gboolean *push_in, | |
99 gpointer user_data) | |
100 { | |
101 gtk_status_icon_position_menu(menu, x, y, push_in, docklet); | |
102 } | |
103 | |
104 static void | |
105 docklet_gtk_status_destroy(void) | |
106 { | |
107 g_return_if_fail(docklet != NULL); | |
108 | |
109 pidgin_docklet_remove(); | |
110 | |
111 g_object_unref(G_OBJECT(docklet)); | |
112 docklet = NULL; | |
113 | |
114 purple_debug_info("docklet", "destroyed\n"); | |
115 } | |
116 | |
117 static void | |
118 docklet_gtk_status_create(gboolean recreate) | |
119 { | |
120 if (docklet) { | |
121 /* if this is being called when a tray icon exists, it's because | |
122 something messed up. try destroying it before we proceed, | |
123 although docklet_refcount may be all hosed. hopefully won't happen. */ | |
124 purple_debug_warning("docklet", "trying to create icon but it already exists?\n"); | |
125 docklet_gtk_status_destroy(); | |
126 } | |
127 | |
128 docklet = gtk_status_icon_new(); | |
129 g_return_if_fail(docklet != NULL); | |
130 | |
131 g_signal_connect(G_OBJECT(docklet), "activate", G_CALLBACK(docklet_gtk_status_activated_cb), NULL); | |
132 g_signal_connect(G_OBJECT(docklet), "popup-menu", G_CALLBACK(docklet_gtk_status_clicked_cb), NULL); | |
133 | |
134 pidgin_docklet_embedded(); | |
135 gtk_status_icon_set_visible(docklet, TRUE); | |
136 purple_debug_info("docklet", "created\n"); | |
137 } | |
138 | |
139 static void | |
140 docklet_gtk_status_create_ui_op(void) | |
141 { | |
142 docklet_gtk_status_create(FALSE); | |
143 } | |
144 | |
145 static struct docklet_ui_ops ui_ops = | |
146 { | |
147 docklet_gtk_status_create_ui_op, | |
148 docklet_gtk_status_destroy, | |
149 docklet_gtk_status_update_icon, | |
150 NULL, | |
151 docklet_gtk_status_set_tooltip, | |
152 docklet_gtk_status_position_menu | |
153 }; | |
154 | |
155 void | |
156 docklet_ui_init(void) | |
157 { | |
158 pidgin_docklet_set_ui_ops(&ui_ops); | |
159 } | |
160 | |
161 #endif /* GTK_CHECK_VERSION(2,10,0) */ | |
162 |