Mercurial > pidgin
annotate plugins/docklet/docklet.c @ 5022:7e5f449de3b8
[gaim-migrate @ 5358]
.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sat, 05 Apr 2003 04:22:33 +0000 |
parents | a701ef925850 |
children | 8e55a4d362a3 |
rev | line source |
---|---|
4093 | 1 /* System tray icon (aka docklet) plugin for Gaim |
3510 | 2 * Copyright (C) 2002 Robert McQueen <robot101@debian.org> |
3 * Inspired by a similar plugin by: | |
4 * John (J5) Palmieri <johnp@martianrock.com> | |
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 /* todo (in order of importance): | |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
23 - check removing the icon factory actually frees the icons |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
24 - unify the queue so we can have a global away without the dialog |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
25 - handle and update tooltips to show your current accounts/queued messages? |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
26 - show a count of queued messages in the unified queue |
3510 | 27 - dernyi's account status menu in the right click |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
28 - optional pop up notices when GNOME2's system-tray-applet supports it */ |
3510 | 29 |
30 /* includes */ | |
31 #include <gtk/gtk.h> | |
32 #include "gaim.h" | |
4561 | 33 #include "sound.h" |
3510 | 34 #include "eggtrayicon.h" |
4729 | 35 #include "gtklist.h" |
3510 | 36 |
3867 | 37 #ifndef GAIM_PLUGINS |
38 #define GAIM_PLUGINS | |
39 #endif | |
40 | |
3510 | 41 /* types */ |
42 enum docklet_status { | |
4157 | 43 offline, |
44 offline_connecting, | |
3510 | 45 online, |
4157 | 46 online_connecting, |
47 online_pending, | |
3510 | 48 away, |
4157 | 49 away_pending |
3510 | 50 }; |
51 | |
52 /* functions */ | |
4093 | 53 static gboolean docklet_create(); |
4157 | 54 static gboolean docklet_update_status(); |
4093 | 55 void gaim_plugin_remove(); |
3510 | 56 |
57 /* globals */ | |
3513 | 58 static EggTrayIcon *docklet = NULL; |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
59 static GtkWidget *image = NULL; |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
60 static GtkIconFactory *icon_factory = NULL; |
3510 | 61 static enum docklet_status status; |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
62 static enum docklet_status icon; |
3510 | 63 |
3554 | 64 static void docklet_toggle_mute(GtkWidget *toggle, void *data) { |
4561 | 65 gaim_sound_set_mute(GTK_CHECK_MENU_ITEM(toggle)->active); |
3510 | 66 } |
67 | |
3554 | 68 static void docklet_toggle_queue(GtkWidget *widget, void *data) { |
69 away_options ^= OPT_AWAY_QUEUE_UNREAD; | |
70 save_prefs(); | |
3510 | 71 } |
3570 | 72 |
73 /* static void docklet_toggle_blist_show(GtkWidget *widget, void *data) { | |
74 blist_options ^= OPT_BLIST_APP_BUDDY_SHOW; | |
75 save_prefs(); | |
76 } */ | |
77 | |
3554 | 78 static void docklet_flush_queue() { |
3570 | 79 if (unread_message_queue) { |
4274 | 80 purge_away_queue(&unread_message_queue); |
3570 | 81 } |
3510 | 82 } |
83 | |
84 static void docklet_menu(GdkEventButton *event) { | |
3513 | 85 static GtkWidget *menu = NULL; |
3512 | 86 GtkWidget *entry; |
3510 | 87 |
88 if (menu) { | |
89 gtk_widget_destroy(menu); | |
90 } | |
91 | |
92 menu = gtk_menu_new(); | |
93 | |
4157 | 94 switch (status) { |
95 case offline: | |
96 case offline_connecting: | |
4567 | 97 entry = gtk_menu_item_new_with_label(_("Auto-login")); |
98 g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(auto_login), NULL); | |
4635 | 99 gtk_menu_shell_append(GTK_MENU_SHELL(menu), entry); |
4567 | 100 break; |
101 default: | |
102 gaim_new_item_from_stock(menu, _("New Message.."), GTK_STOCK_CONVERT, G_CALLBACK(show_im_dialog), NULL, 0, 0, NULL); | |
103 gaim_new_item_from_stock(menu, _("Join A Chat..."), GTK_STOCK_JUMP_TO, G_CALLBACK(join_chat), NULL, 0, 0, NULL); | |
104 break; | |
105 } | |
106 | |
107 switch (status) { | |
108 case offline: | |
109 case offline_connecting: | |
4157 | 110 break; |
111 case online: | |
112 case online_connecting: | |
113 case online_pending: { | |
3510 | 114 GtkWidget *docklet_awaymenu; |
115 GSList *awy = NULL; | |
116 struct away_message *a = NULL; | |
117 | |
118 docklet_awaymenu = gtk_menu_new(); | |
119 awy = away_messages; | |
120 | |
121 while (awy) { | |
122 a = (struct away_message *)awy->data; | |
123 | |
124 entry = gtk_menu_item_new_with_label(a->name); | |
3554 | 125 g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(do_away_message), a); |
4635 | 126 gtk_menu_shell_append(GTK_MENU_SHELL(docklet_awaymenu), entry); |
3510 | 127 |
128 awy = g_slist_next(awy); | |
129 } | |
130 | |
4157 | 131 if (away_messages) |
132 gaim_separator(docklet_awaymenu); | |
3510 | 133 |
134 entry = gtk_menu_item_new_with_label(_("New...")); | |
3554 | 135 g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(create_away_mess), NULL); |
4635 | 136 gtk_menu_shell_append(GTK_MENU_SHELL(docklet_awaymenu), entry); |
3510 | 137 |
138 entry = gtk_menu_item_new_with_label(_("Away")); | |
3512 | 139 gtk_menu_item_set_submenu(GTK_MENU_ITEM(entry), docklet_awaymenu); |
4635 | 140 gtk_menu_shell_append(GTK_MENU_SHELL(menu), entry); |
4157 | 141 } break; |
142 case away: | |
143 case away_pending: | |
3510 | 144 entry = gtk_menu_item_new_with_label(_("Back")); |
3554 | 145 g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(do_im_back), NULL); |
4635 | 146 gtk_menu_shell_append(GTK_MENU_SHELL(menu), entry); |
4157 | 147 break; |
3510 | 148 } |
149 | |
4567 | 150 gaim_separator(menu); |
151 | |
152 entry = gtk_check_menu_item_new_with_label(_("Mute Sounds")); | |
153 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(entry), gaim_sound_get_mute()); | |
154 g_signal_connect(G_OBJECT(entry), "toggled", G_CALLBACK(docklet_toggle_mute), NULL); | |
4635 | 155 gtk_menu_shell_append(GTK_MENU_SHELL(menu), entry); |
4567 | 156 |
4698 | 157 gaim_new_item_from_stock(menu, _("File Transfers..."), GTK_STOCK_REVERT_TO_SAVED, G_CALLBACK(gaim_show_xfer_dialog), NULL, 0, 0, NULL); |
4567 | 158 gaim_new_item_from_pixbuf(menu, _("Accounts..."), "accounts-menu.png", G_CALLBACK(account_editor), NULL, 0, 0, NULL); |
159 gaim_new_item_from_stock(menu, _("Preferences..."), GTK_STOCK_PREFERENCES, G_CALLBACK(show_prefs), NULL, 0, 0, NULL); | |
160 | |
161 gaim_separator(menu); | |
162 | |
4157 | 163 switch (status) { |
164 case offline: | |
165 case offline_connecting: | |
166 break; | |
167 default: | |
168 entry = gtk_menu_item_new_with_label(_("Signoff")); | |
169 g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(signoff_all), NULL); | |
4635 | 170 gtk_menu_shell_append(GTK_MENU_SHELL(menu), entry); |
4157 | 171 break; |
172 } | |
173 | |
174 gaim_new_item_from_stock(menu, _("Quit"), GTK_STOCK_QUIT, G_CALLBACK(do_quit), NULL, 0, 0, 0); | |
3510 | 175 |
176 gtk_widget_show_all(menu); | |
177 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, event->time); | |
178 } | |
179 | |
180 static void docklet_clicked(GtkWidget *button, GdkEventButton *event, void *data) { | |
3939 | 181 if (event->type != GDK_BUTTON_PRESS) |
182 return; | |
183 | |
3510 | 184 switch (event->button) { |
185 case 1: | |
3517 | 186 if (unread_message_queue) { |
3570 | 187 docklet_flush_queue(); |
3517 | 188 docklet_update_status(); |
3570 | 189 } else { |
4698 | 190 gaim_gtk_blist_docklet_toggle(); |
3554 | 191 } |
3510 | 192 break; |
193 case 2: | |
194 break; | |
195 case 3: | |
196 docklet_menu(event); | |
197 break; | |
198 } | |
199 } | |
200 | |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
201 static void docklet_update_icon() { |
4250
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
202 const gchar *icon_name = NULL; |
3510 | 203 |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
204 switch (icon) { |
4157 | 205 case offline: |
4250
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
206 icon_name = "gaim-docklet-offline"; |
4157 | 207 break; |
208 case offline_connecting: | |
209 case online_connecting: | |
4250
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
210 icon_name = "gaim-docklet-connect"; |
4157 | 211 break; |
3510 | 212 case online: |
4250
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
213 icon_name = "gaim-docklet-online"; |
3510 | 214 break; |
4157 | 215 case online_pending: |
4250
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
216 icon_name = "gaim-docklet-msgunread"; |
4157 | 217 break; |
3510 | 218 case away: |
4250
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
219 icon_name = "gaim-docklet-away"; |
3510 | 220 break; |
221 case away_pending: | |
4250
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
222 icon_name = "gaim-docklet-msgpend"; |
3510 | 223 break; |
224 } | |
225 | |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
226 gtk_image_set_from_stock(GTK_IMAGE(image), icon_name, GTK_ICON_SIZE_LARGE_TOOLBAR); |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
227 } |
3510 | 228 |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
229 static gboolean docklet_blink_icon() { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
230 if (status == online_pending) { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
231 if (status == icon) { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
232 /* last icon was the right one... let's change it */ |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
233 icon = online; |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
234 } else { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
235 /* last icon was the wrong one, change it back */ |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
236 icon = online_pending; |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
237 } |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
238 } else if (status == away_pending) { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
239 if (status == icon) { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
240 /* last icon was the right one... let's change it */ |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
241 icon = away; |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
242 } else { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
243 /* last icon was the wrong one, change it back */ |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
244 icon = away_pending; |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
245 } |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
246 } else { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
247 /* no messages, stop blinking */ |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
248 return FALSE; |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
249 } |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
250 |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
251 docklet_update_icon(); |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
252 |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
253 return TRUE; /* keep blinking */ |
3510 | 254 } |
255 | |
4157 | 256 static gboolean docklet_update_status() { |
3510 | 257 enum docklet_status oldstatus; |
258 | |
259 oldstatus = status; | |
260 | |
261 if (connections) { | |
3517 | 262 if (unread_message_queue) { |
4157 | 263 status = online_pending; |
3517 | 264 } else if (awaymessage) { |
3510 | 265 if (message_queue) { |
266 status = away_pending; | |
267 } else { | |
268 status = away; | |
269 } | |
3554 | 270 } else if (connecting_count) { |
4157 | 271 status = online_connecting; |
3510 | 272 } else { |
273 status = online; | |
274 } | |
275 } else { | |
3517 | 276 if (connecting_count) { |
4157 | 277 status = offline_connecting; |
3517 | 278 } else { |
279 status = offline; | |
280 } | |
3510 | 281 } |
282 | |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
283 /* update the icon if we changed status */ |
3510 | 284 if (status != oldstatus) { |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
285 icon = status; |
3510 | 286 docklet_update_icon(); |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
287 |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
288 /* and schedule the blinker function if messages are pending */ |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
289 if (status == online_pending || status == away_pending) { |
4274 | 290 g_timeout_add(500, docklet_blink_icon, &docklet); |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
291 } |
3510 | 292 } |
4157 | 293 |
294 return FALSE; /* for when we're called by the glib idle handler */ | |
3510 | 295 } |
296 | |
3554 | 297 static void docklet_embedded(GtkWidget *widget, void *data) { |
4840 | 298 debug_printf("Tray Icon: embedded\n"); |
4698 | 299 gaim_gtk_blist_docklet_add(); |
3554 | 300 } |
301 | |
4274 | 302 static void docklet_remove_callbacks() { |
303 debug_printf("Tray Icon: removing callbacks"); | |
304 | |
305 while (g_source_remove_by_user_data(&docklet)) { | |
306 debug_printf("."); | |
307 } | |
308 | |
309 debug_printf("\n"); | |
310 } | |
311 | |
3554 | 312 static void docklet_destroyed(GtkWidget *widget, void *data) { |
4093 | 313 debug_printf("Tray Icon: destroyed\n"); |
314 | |
4698 | 315 gaim_gtk_blist_docklet_remove(); |
4093 | 316 |
3570 | 317 docklet_flush_queue(); |
4093 | 318 |
4274 | 319 docklet_remove_callbacks(); |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
320 |
4093 | 321 g_object_unref(G_OBJECT(docklet)); |
322 docklet = NULL; | |
323 | |
4274 | 324 g_idle_add(docklet_create, &docklet); |
3554 | 325 } |
326 | |
4274 | 327 static gboolean docklet_create() { |
3510 | 328 GtkWidget *box; |
329 | |
3570 | 330 if (docklet) { |
4093 | 331 /* if this is being called when a tray icon exists, it's because |
332 something messed up. try destroying it before we proceed, | |
333 although docklet_refcount may be all hosed. hopefully won't happen. */ | |
334 debug_printf("Tray Icon: trying to create icon but it already exists?\n"); | |
335 gaim_plugin_remove(); | |
3510 | 336 } |
337 | |
338 docklet = egg_tray_icon_new("Gaim"); | |
339 box = gtk_event_box_new(); | |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
340 image = gtk_image_new(); |
3510 | 341 |
3554 | 342 g_signal_connect(G_OBJECT(docklet), "embedded", G_CALLBACK(docklet_embedded), NULL); |
343 g_signal_connect(G_OBJECT(docklet), "destroy", G_CALLBACK(docklet_destroyed), NULL); | |
344 g_signal_connect(G_OBJECT(box), "button-press-event", G_CALLBACK(docklet_clicked), NULL); | |
3510 | 345 |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
346 gtk_container_add(GTK_CONTAINER(box), image); |
3510 | 347 gtk_container_add(GTK_CONTAINER(docklet), box); |
348 gtk_widget_show_all(GTK_WIDGET(docklet)); | |
349 | |
3554 | 350 /* ref the docklet before we bandy it about the place */ |
351 g_object_ref(G_OBJECT(docklet)); | |
3510 | 352 docklet_update_status(); |
353 docklet_update_icon(); | |
354 | |
4093 | 355 debug_printf("Tray Icon: created\n"); |
356 | |
357 return FALSE; /* for when we're called by the glib idle handler */ | |
3510 | 358 } |
359 | |
360 static void gaim_signon(struct gaim_connection *gc, void *data) { | |
361 docklet_update_status(); | |
362 } | |
363 | |
364 static void gaim_signoff(struct gaim_connection *gc, void *data) { | |
4157 | 365 /* do this when idle so that if the prpl was connecting |
366 and was cancelled, we register that connecting_count | |
367 has returned to 0 */ | |
4274 | 368 g_idle_add(docklet_update_status, &docklet); |
3510 | 369 } |
370 | |
4491 | 371 static void gaim_connecting(struct gaim_account *account, void *data) { |
3510 | 372 docklet_update_status(); |
373 } | |
374 | |
375 static void gaim_away(struct gaim_connection *gc, char *state, char *message, void *data) { | |
376 /* we only support global away. this is the way it is, ok? */ | |
377 docklet_update_status(); | |
378 } | |
379 | |
4274 | 380 static void gaim_im_recv(struct gaim_connection *gc, char **who, char **what, void *data) { |
3510 | 381 /* if message queuing while away is enabled, this event could be the first |
4274 | 382 message so we need to see if the status (and hence icon) needs changing. |
383 do this when idle so that all message processing is completed, queuing | |
384 etc, before we run. */ | |
385 g_idle_add(docklet_update_status, &docklet); | |
3510 | 386 } |
387 | |
3570 | 388 /* static void gaim_buddy_signon(struct gaim_connection *gc, char *who, void *data) { |
3510 | 389 } |
390 | |
391 static void gaim_buddy_signoff(struct gaim_connection *gc, char *who, void *data) { | |
392 } | |
393 | |
394 static void gaim_buddy_away(struct gaim_connection *gc, char *who, void *data) { | |
395 } | |
396 | |
397 static void gaim_buddy_back(struct gaim_connection *gc, char *who, void *data) { | |
398 } | |
399 | |
400 static void gaim_new_conversation(char *who, void *data) { | |
3570 | 401 } */ |
3510 | 402 |
4250
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
403 static void docklet_register_icon(const char *name, char *fn) { |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
404 gchar *filename; |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
405 |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
406 filename = g_build_filename(DATADIR, "pixmaps", "gaim", fn, NULL); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
407 gtk_icon_factory_add(icon_factory, name, |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
408 gtk_icon_set_new_from_pixbuf(gdk_pixbuf_new_from_file(filename, NULL))); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
409 g_free(filename); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
410 } |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
411 |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
412 static void docklet_register_icon_factory() { |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
413 icon_factory = gtk_icon_factory_new(); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
414 |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
415 docklet_register_icon("gaim-docklet-offline", "offline.png"); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
416 docklet_register_icon("gaim-docklet-connect", "connect.png"); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
417 docklet_register_icon("gaim-docklet-online", "online.png"); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
418 docklet_register_icon("gaim-docklet-msgunread", "msgunread.png"); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
419 docklet_register_icon("gaim-docklet-away", "away.png"); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
420 docklet_register_icon("gaim-docklet-msgpend", "msgpend.png"); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
421 |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
422 gtk_icon_factory_add_default(icon_factory); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
423 } |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
424 |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
425 static void docklet_unregister_icon_factory() { |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
426 gtk_icon_factory_remove_default(icon_factory); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
427 } |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
428 |
3510 | 429 char *gaim_plugin_init(GModule *handle) { |
4250
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
430 docklet_register_icon_factory(); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
431 |
4093 | 432 docklet_create(NULL); |
3510 | 433 |
434 gaim_signal_connect(handle, event_signon, gaim_signon, NULL); | |
435 gaim_signal_connect(handle, event_signoff, gaim_signoff, NULL); | |
436 gaim_signal_connect(handle, event_connecting, gaim_connecting, NULL); | |
437 gaim_signal_connect(handle, event_away, gaim_away, NULL); | |
4274 | 438 gaim_signal_connect(handle, event_im_recv, gaim_im_recv, NULL); |
3570 | 439 /* gaim_signal_connect(handle, event_buddy_signon, gaim_buddy_signon, NULL); |
3510 | 440 gaim_signal_connect(handle, event_buddy_signoff, gaim_buddy_signoff, NULL); |
441 gaim_signal_connect(handle, event_buddy_away, gaim_buddy_away, NULL); | |
442 gaim_signal_connect(handle, event_buddy_back, gaim_buddy_back, NULL); | |
3570 | 443 gaim_signal_connect(handle, event_new_conversation, gaim_new_conversation, NULL); */ |
3510 | 444 |
445 return NULL; | |
446 } | |
447 | |
3554 | 448 void gaim_plugin_remove() { |
3570 | 449 if (GTK_WIDGET_VISIBLE(docklet)) { |
4698 | 450 gaim_gtk_blist_docklet_remove(); |
3570 | 451 } |
3554 | 452 |
3570 | 453 docklet_flush_queue(); |
3554 | 454 |
4274 | 455 docklet_remove_callbacks(); |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
456 |
3570 | 457 g_signal_handlers_disconnect_by_func(G_OBJECT(docklet), G_CALLBACK(docklet_destroyed), NULL); |
458 gtk_widget_destroy(GTK_WIDGET(docklet)); | |
3554 | 459 |
4093 | 460 g_object_unref(G_OBJECT(docklet)); |
461 docklet = NULL; | |
4250
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
462 |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
463 docklet_unregister_icon_factory(); |
4093 | 464 |
4567 | 465 /* do this while gaim has no other way to toggle the global mute */ |
466 gaim_sound_set_mute(FALSE); | |
467 | |
4093 | 468 debug_printf("Tray Icon: removed\n"); |
3554 | 469 } |
470 | |
3570 | 471 GtkWidget *gaim_plugin_config_gtk() { |
472 GtkWidget *frame; | |
473 GtkWidget *vbox, *hbox; | |
474 GtkWidget *toggle; | |
3517 | 475 |
3570 | 476 frame = gtk_vbox_new(FALSE, 18); |
477 gtk_container_set_border_width(GTK_CONTAINER(frame), 12); | |
478 | |
4093 | 479 vbox = make_frame(frame, _("Tray Icon Configuration")); |
3570 | 480 hbox = gtk_hbox_new(FALSE, 18); |
481 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
3517 | 482 |
3570 | 483 /* toggle = gtk_check_button_new_with_mnemonic(_("_Automatically show buddy list on sign on")); |
484 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), blist_options & OPT_BLIST_APP_BUDDY_SHOW); | |
485 g_signal_connect(G_OBJECT(toggle), "clicked", G_CALLBACK(docklet_toggle_blist_show), NULL); | |
486 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); */ | |
3517 | 487 |
4093 | 488 toggle = gtk_check_button_new_with_mnemonic(_("_Hide new messages until tray icon is clicked")); |
3570 | 489 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), away_options & OPT_AWAY_QUEUE_UNREAD); |
490 g_signal_connect(G_OBJECT(toggle), "clicked", G_CALLBACK(docklet_toggle_queue), NULL); | |
491 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
492 | |
493 gtk_widget_show_all(frame); | |
494 return frame; | |
3517 | 495 } |
3570 | 496 |
3551 | 497 struct gaim_plugin_description desc; |
498 struct gaim_plugin_description *gaim_plugin_desc() { | |
499 desc.api_version = PLUGIN_API_VERSION; | |
4585 | 500 desc.name = g_strdup(_("System Tray Icon")); |
3551 | 501 desc.version = g_strdup(VERSION); |
4567 | 502 desc.description = g_strdup(_("Interacts with a Notification Area applet (in GNOME or KDE, for example) to display the current status of Gaim, allow fast access to commonly used functions, and to toggle display of the buddy list or login window. Also allows messages to be queued until the icon is clicked, similar to ICQ.")); |
4606 | 503 desc.authors = g_strdup("Robert McQueen <robot101@debian.org>"); |
3551 | 504 desc.url = g_strdup(WEBSITE); |
505 return &desc; | |
506 } | |
3510 | 507 |
3570 | 508 char *name() { |
4093 | 509 return _("System Tray Icon"); |
3510 | 510 } |
511 | |
3570 | 512 char *description() { |
4567 | 513 return _("Interacts with a Notification Area applet (in GNOME or KDE, for example) to display the current status of Gaim, allow fast access to commonly used functions, and to toggle display of the buddy list or login window. Also allows messages to be queued until the icon is clicked, similar to ICQ."); |
3510 | 514 } |