Mercurial > pidgin.yaz
annotate plugins/docklet/docklet.c @ 4824:d544c32dcf19
[gaim-migrate @ 5149]
A Mayan pilot needs to plane
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Tue, 18 Mar 2003 17:30:07 +0000 |
parents | 751c37a940dd |
children | a701ef925850 |
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 |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
228 debug_printf("Tray Icon: updated icon to '%s'\n", icon_name); |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
229 } |
3510 | 230 |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
231 static gboolean docklet_blink_icon() { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
232 if (status == online_pending) { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
233 if (status == icon) { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
234 /* last icon was the right one... let's change it */ |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
235 icon = online; |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
236 } else { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
237 /* last icon was the wrong one, change it back */ |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
238 icon = online_pending; |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
239 } |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
240 } else if (status == away_pending) { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
241 if (status == icon) { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
242 /* last icon was the right one... let's change it */ |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
243 icon = away; |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
244 } else { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
245 /* last icon was the wrong one, change it back */ |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
246 icon = away_pending; |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
247 } |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
248 } else { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
249 /* no messages, stop blinking */ |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
250 return FALSE; |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
251 } |
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 docklet_update_icon(); |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
254 |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
255 return TRUE; /* keep blinking */ |
3510 | 256 } |
257 | |
4157 | 258 static gboolean docklet_update_status() { |
3510 | 259 enum docklet_status oldstatus; |
260 | |
261 oldstatus = status; | |
262 | |
263 if (connections) { | |
3517 | 264 if (unread_message_queue) { |
4157 | 265 status = online_pending; |
3517 | 266 } else if (awaymessage) { |
3510 | 267 if (message_queue) { |
268 status = away_pending; | |
269 } else { | |
270 status = away; | |
271 } | |
3554 | 272 } else if (connecting_count) { |
4157 | 273 status = online_connecting; |
3510 | 274 } else { |
275 status = online; | |
276 } | |
277 } else { | |
3517 | 278 if (connecting_count) { |
4157 | 279 status = offline_connecting; |
3517 | 280 } else { |
281 status = offline; | |
282 } | |
3510 | 283 } |
284 | |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
285 /* update the icon if we changed status */ |
3510 | 286 if (status != oldstatus) { |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
287 icon = status; |
3510 | 288 docklet_update_icon(); |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
289 |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
290 /* and schedule the blinker function if messages are pending */ |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
291 if (status == online_pending || status == away_pending) { |
4274 | 292 g_timeout_add(500, docklet_blink_icon, &docklet); |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
293 } |
3510 | 294 } |
4157 | 295 |
296 return FALSE; /* for when we're called by the glib idle handler */ | |
3510 | 297 } |
298 | |
3554 | 299 static void docklet_embedded(GtkWidget *widget, void *data) { |
4698 | 300 debug_printf("Tray Icon:embedded\n"); |
301 gaim_gtk_blist_docklet_add(); | |
3554 | 302 } |
303 | |
4274 | 304 static void docklet_remove_callbacks() { |
305 debug_printf("Tray Icon: removing callbacks"); | |
306 | |
307 while (g_source_remove_by_user_data(&docklet)) { | |
308 debug_printf("."); | |
309 } | |
310 | |
311 debug_printf("\n"); | |
312 } | |
313 | |
3554 | 314 static void docklet_destroyed(GtkWidget *widget, void *data) { |
4093 | 315 debug_printf("Tray Icon: destroyed\n"); |
316 | |
4698 | 317 gaim_gtk_blist_docklet_remove(); |
4093 | 318 |
3570 | 319 docklet_flush_queue(); |
4093 | 320 |
4274 | 321 docklet_remove_callbacks(); |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
322 |
4093 | 323 g_object_unref(G_OBJECT(docklet)); |
324 docklet = NULL; | |
325 | |
4274 | 326 g_idle_add(docklet_create, &docklet); |
3554 | 327 } |
328 | |
4274 | 329 static gboolean docklet_create() { |
3510 | 330 GtkWidget *box; |
331 | |
3570 | 332 if (docklet) { |
4093 | 333 /* if this is being called when a tray icon exists, it's because |
334 something messed up. try destroying it before we proceed, | |
335 although docklet_refcount may be all hosed. hopefully won't happen. */ | |
336 debug_printf("Tray Icon: trying to create icon but it already exists?\n"); | |
337 gaim_plugin_remove(); | |
3510 | 338 } |
339 | |
340 docklet = egg_tray_icon_new("Gaim"); | |
341 box = gtk_event_box_new(); | |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
342 image = gtk_image_new(); |
3510 | 343 |
3554 | 344 g_signal_connect(G_OBJECT(docklet), "embedded", G_CALLBACK(docklet_embedded), NULL); |
345 g_signal_connect(G_OBJECT(docklet), "destroy", G_CALLBACK(docklet_destroyed), NULL); | |
346 g_signal_connect(G_OBJECT(box), "button-press-event", G_CALLBACK(docklet_clicked), NULL); | |
3510 | 347 |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
348 gtk_container_add(GTK_CONTAINER(box), image); |
3510 | 349 gtk_container_add(GTK_CONTAINER(docklet), box); |
350 gtk_widget_show_all(GTK_WIDGET(docklet)); | |
351 | |
3554 | 352 /* ref the docklet before we bandy it about the place */ |
353 g_object_ref(G_OBJECT(docklet)); | |
3510 | 354 docklet_update_status(); |
355 docklet_update_icon(); | |
356 | |
4093 | 357 debug_printf("Tray Icon: created\n"); |
358 | |
359 return FALSE; /* for when we're called by the glib idle handler */ | |
3510 | 360 } |
361 | |
362 static void gaim_signon(struct gaim_connection *gc, void *data) { | |
363 docklet_update_status(); | |
364 } | |
365 | |
366 static void gaim_signoff(struct gaim_connection *gc, void *data) { | |
4157 | 367 /* do this when idle so that if the prpl was connecting |
368 and was cancelled, we register that connecting_count | |
369 has returned to 0 */ | |
4274 | 370 g_idle_add(docklet_update_status, &docklet); |
3510 | 371 } |
372 | |
4491 | 373 static void gaim_connecting(struct gaim_account *account, void *data) { |
3510 | 374 docklet_update_status(); |
375 } | |
376 | |
377 static void gaim_away(struct gaim_connection *gc, char *state, char *message, void *data) { | |
378 /* we only support global away. this is the way it is, ok? */ | |
379 docklet_update_status(); | |
380 } | |
381 | |
4274 | 382 static void gaim_im_recv(struct gaim_connection *gc, char **who, char **what, void *data) { |
3510 | 383 /* if message queuing while away is enabled, this event could be the first |
4274 | 384 message so we need to see if the status (and hence icon) needs changing. |
385 do this when idle so that all message processing is completed, queuing | |
386 etc, before we run. */ | |
387 g_idle_add(docklet_update_status, &docklet); | |
3510 | 388 } |
389 | |
3570 | 390 /* static void gaim_buddy_signon(struct gaim_connection *gc, char *who, void *data) { |
3510 | 391 } |
392 | |
393 static void gaim_buddy_signoff(struct gaim_connection *gc, char *who, void *data) { | |
394 } | |
395 | |
396 static void gaim_buddy_away(struct gaim_connection *gc, char *who, void *data) { | |
397 } | |
398 | |
399 static void gaim_buddy_back(struct gaim_connection *gc, char *who, void *data) { | |
400 } | |
401 | |
402 static void gaim_new_conversation(char *who, void *data) { | |
3570 | 403 } */ |
3510 | 404 |
4250
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
405 static void docklet_register_icon(const char *name, char *fn) { |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
406 gchar *filename; |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
407 |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
408 filename = g_build_filename(DATADIR, "pixmaps", "gaim", fn, NULL); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
409 gtk_icon_factory_add(icon_factory, name, |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
410 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
|
411 g_free(filename); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
412 } |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
413 |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
414 static void docklet_register_icon_factory() { |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
415 icon_factory = gtk_icon_factory_new(); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
416 |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
417 docklet_register_icon("gaim-docklet-offline", "offline.png"); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
418 docklet_register_icon("gaim-docklet-connect", "connect.png"); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
419 docklet_register_icon("gaim-docklet-online", "online.png"); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
420 docklet_register_icon("gaim-docklet-msgunread", "msgunread.png"); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
421 docklet_register_icon("gaim-docklet-away", "away.png"); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
422 docklet_register_icon("gaim-docklet-msgpend", "msgpend.png"); |
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 gtk_icon_factory_add_default(icon_factory); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
425 } |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
426 |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
427 static void docklet_unregister_icon_factory() { |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
428 gtk_icon_factory_remove_default(icon_factory); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
429 } |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
430 |
3510 | 431 char *gaim_plugin_init(GModule *handle) { |
4250
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
432 docklet_register_icon_factory(); |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
433 |
4093 | 434 docklet_create(NULL); |
3510 | 435 |
436 gaim_signal_connect(handle, event_signon, gaim_signon, NULL); | |
437 gaim_signal_connect(handle, event_signoff, gaim_signoff, NULL); | |
438 gaim_signal_connect(handle, event_connecting, gaim_connecting, NULL); | |
439 gaim_signal_connect(handle, event_away, gaim_away, NULL); | |
4274 | 440 gaim_signal_connect(handle, event_im_recv, gaim_im_recv, NULL); |
3570 | 441 /* gaim_signal_connect(handle, event_buddy_signon, gaim_buddy_signon, NULL); |
3510 | 442 gaim_signal_connect(handle, event_buddy_signoff, gaim_buddy_signoff, NULL); |
443 gaim_signal_connect(handle, event_buddy_away, gaim_buddy_away, NULL); | |
444 gaim_signal_connect(handle, event_buddy_back, gaim_buddy_back, NULL); | |
3570 | 445 gaim_signal_connect(handle, event_new_conversation, gaim_new_conversation, NULL); */ |
3510 | 446 |
447 return NULL; | |
448 } | |
449 | |
3554 | 450 void gaim_plugin_remove() { |
3570 | 451 if (GTK_WIDGET_VISIBLE(docklet)) { |
4698 | 452 gaim_gtk_blist_docklet_remove(); |
3570 | 453 } |
3554 | 454 |
3570 | 455 docklet_flush_queue(); |
3554 | 456 |
4274 | 457 docklet_remove_callbacks(); |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
458 |
3570 | 459 g_signal_handlers_disconnect_by_func(G_OBJECT(docklet), G_CALLBACK(docklet_destroyed), NULL); |
460 gtk_widget_destroy(GTK_WIDGET(docklet)); | |
3554 | 461 |
4093 | 462 g_object_unref(G_OBJECT(docklet)); |
463 docklet = NULL; | |
4250
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
464 |
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
465 docklet_unregister_icon_factory(); |
4093 | 466 |
4567 | 467 /* do this while gaim has no other way to toggle the global mute */ |
468 gaim_sound_set_mute(FALSE); | |
469 | |
4093 | 470 debug_printf("Tray Icon: removed\n"); |
3554 | 471 } |
472 | |
3570 | 473 GtkWidget *gaim_plugin_config_gtk() { |
474 GtkWidget *frame; | |
475 GtkWidget *vbox, *hbox; | |
476 GtkWidget *toggle; | |
3517 | 477 |
3570 | 478 frame = gtk_vbox_new(FALSE, 18); |
479 gtk_container_set_border_width(GTK_CONTAINER(frame), 12); | |
480 | |
4093 | 481 vbox = make_frame(frame, _("Tray Icon Configuration")); |
3570 | 482 hbox = gtk_hbox_new(FALSE, 18); |
483 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
3517 | 484 |
3570 | 485 /* toggle = gtk_check_button_new_with_mnemonic(_("_Automatically show buddy list on sign on")); |
486 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), blist_options & OPT_BLIST_APP_BUDDY_SHOW); | |
487 g_signal_connect(G_OBJECT(toggle), "clicked", G_CALLBACK(docklet_toggle_blist_show), NULL); | |
488 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); */ | |
3517 | 489 |
4093 | 490 toggle = gtk_check_button_new_with_mnemonic(_("_Hide new messages until tray icon is clicked")); |
3570 | 491 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), away_options & OPT_AWAY_QUEUE_UNREAD); |
492 g_signal_connect(G_OBJECT(toggle), "clicked", G_CALLBACK(docklet_toggle_queue), NULL); | |
493 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
494 | |
495 gtk_widget_show_all(frame); | |
496 return frame; | |
3517 | 497 } |
3570 | 498 |
3551 | 499 struct gaim_plugin_description desc; |
500 struct gaim_plugin_description *gaim_plugin_desc() { | |
501 desc.api_version = PLUGIN_API_VERSION; | |
4585 | 502 desc.name = g_strdup(_("System Tray Icon")); |
3551 | 503 desc.version = g_strdup(VERSION); |
4567 | 504 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 | 505 desc.authors = g_strdup("Robert McQueen <robot101@debian.org>"); |
3551 | 506 desc.url = g_strdup(WEBSITE); |
507 return &desc; | |
508 } | |
3510 | 509 |
3570 | 510 char *name() { |
4093 | 511 return _("System Tray Icon"); |
3510 | 512 } |
513 | |
3570 | 514 char *description() { |
4567 | 515 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 | 516 } |