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