Mercurial > pidgin
annotate plugins/docklet/docklet.c @ 5586:cde28f5c47d4
[gaim-migrate @ 5990]
Perl theoretically works.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sat, 31 May 2003 06:50:47 +0000 |
parents | cade2082f760 |
children | eeba9205dd0f |
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 - 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
|
24 - handle and update tooltips to show your current accounts/queued messages? |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
25 - show a count of queued messages in the unified queue |
3510 | 26 - dernyi's account status menu in the right click |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
27 - optional pop up notices when GNOME2's system-tray-applet supports it */ |
3510 | 28 |
29 /* includes */ | |
30 #include <gtk/gtk.h> | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
31 #include "gtkplugin.h" |
3510 | 32 #include "gaim.h" |
4561 | 33 #include "sound.h" |
5554
7b36d02031a2
[gaim-migrate @ 5955]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
34 #include "prefs.h" |
7b36d02031a2
[gaim-migrate @ 5955]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
35 #include "gtkblist.h" |
3510 | 36 #include "eggtrayicon.h" |
37 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
38 #define DOCKLET_PLUGIN_ID "gtk-docklet" |
3867 | 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(); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
54 static gboolean plugin_unload(GaimPlugin *plugin); |
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; |
3510 | 59 static enum docklet_status status; |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
60 static enum docklet_status icon; |
3510 | 61 |
3554 | 62 static void docklet_toggle_mute(GtkWidget *toggle, void *data) { |
4561 | 63 gaim_sound_set_mute(GTK_CHECK_MENU_ITEM(toggle)->active); |
3510 | 64 } |
65 | |
5554
7b36d02031a2
[gaim-migrate @ 5955]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
66 static void docklet_set_bool(GtkWidget *widget, const char *key) { |
7b36d02031a2
[gaim-migrate @ 5955]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
67 gaim_prefs_set_bool(key, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))); |
3510 | 68 } |
3570 | 69 |
3554 | 70 static void docklet_flush_queue() { |
3570 | 71 if (unread_message_queue) { |
4274 | 72 purge_away_queue(&unread_message_queue); |
3570 | 73 } |
3510 | 74 } |
75 | |
76 static void docklet_menu(GdkEventButton *event) { | |
3513 | 77 static GtkWidget *menu = NULL; |
3512 | 78 GtkWidget *entry; |
3510 | 79 |
80 if (menu) { | |
81 gtk_widget_destroy(menu); | |
82 } | |
83 | |
84 menu = gtk_menu_new(); | |
85 | |
4157 | 86 switch (status) { |
87 case offline: | |
88 case offline_connecting: | |
5584 | 89 /* XXX CHIP KILLED AUTO CONNECTING */ |
90 #if 0 | |
5024 | 91 gaim_new_item_from_stock(menu, _("Auto-login"), GAIM_STOCK_SIGN_ON, G_CALLBACK(auto_login), NULL, 0, 0, NULL); |
5584 | 92 #endif |
4567 | 93 break; |
94 default: | |
5024 | 95 gaim_new_item_from_stock(menu, _("New Message.."), GAIM_STOCK_IM, G_CALLBACK(show_im_dialog), NULL, 0, 0, NULL); |
96 gaim_new_item_from_stock(menu, _("Join A Chat..."), GAIM_STOCK_CHAT, G_CALLBACK(join_chat), NULL, 0, 0, NULL); | |
4567 | 97 break; |
98 } | |
99 | |
100 switch (status) { | |
101 case offline: | |
102 case offline_connecting: | |
4157 | 103 break; |
104 case online: | |
105 case online_connecting: | |
106 case online_pending: { | |
3510 | 107 GtkWidget *docklet_awaymenu; |
108 GSList *awy = NULL; | |
109 struct away_message *a = NULL; | |
110 | |
111 docklet_awaymenu = gtk_menu_new(); | |
112 awy = away_messages; | |
113 | |
114 while (awy) { | |
115 a = (struct away_message *)awy->data; | |
116 | |
117 entry = gtk_menu_item_new_with_label(a->name); | |
3554 | 118 g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(do_away_message), a); |
4635 | 119 gtk_menu_shell_append(GTK_MENU_SHELL(docklet_awaymenu), entry); |
3510 | 120 |
121 awy = g_slist_next(awy); | |
122 } | |
123 | |
4157 | 124 if (away_messages) |
125 gaim_separator(docklet_awaymenu); | |
3510 | 126 |
127 entry = gtk_menu_item_new_with_label(_("New...")); | |
3554 | 128 g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(create_away_mess), NULL); |
4635 | 129 gtk_menu_shell_append(GTK_MENU_SHELL(docklet_awaymenu), entry); |
3510 | 130 |
131 entry = gtk_menu_item_new_with_label(_("Away")); | |
3512 | 132 gtk_menu_item_set_submenu(GTK_MENU_ITEM(entry), docklet_awaymenu); |
4635 | 133 gtk_menu_shell_append(GTK_MENU_SHELL(menu), entry); |
4157 | 134 } break; |
135 case away: | |
136 case away_pending: | |
3510 | 137 entry = gtk_menu_item_new_with_label(_("Back")); |
3554 | 138 g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(do_im_back), NULL); |
4635 | 139 gtk_menu_shell_append(GTK_MENU_SHELL(menu), entry); |
4157 | 140 break; |
3510 | 141 } |
142 | |
4567 | 143 gaim_separator(menu); |
144 | |
145 entry = gtk_check_menu_item_new_with_label(_("Mute Sounds")); | |
146 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(entry), gaim_sound_get_mute()); | |
147 g_signal_connect(G_OBJECT(entry), "toggled", G_CALLBACK(docklet_toggle_mute), NULL); | |
4635 | 148 gtk_menu_shell_append(GTK_MENU_SHELL(menu), entry); |
4567 | 149 |
5024 | 150 gaim_new_item_from_stock(menu, _("File Transfers..."), GAIM_STOCK_FILE_TRANSFER, G_CALLBACK(gaim_show_xfer_dialog), NULL, 0, 0, NULL); |
151 gaim_new_item_from_stock(menu, _("Accounts..."), GAIM_STOCK_ACCOUNTS, G_CALLBACK(account_editor), NULL, 0, 0, NULL); | |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5234
diff
changeset
|
152 gaim_new_item_from_stock(menu, _("Preferences..."), GTK_STOCK_PREFERENCES, G_CALLBACK(gaim_gtk_prefs_show), NULL, 0, 0, NULL); |
4567 | 153 |
154 gaim_separator(menu); | |
155 | |
4157 | 156 switch (status) { |
157 case offline: | |
158 case offline_connecting: | |
159 break; | |
160 default: | |
5024 | 161 gaim_new_item_from_stock(menu, _("Signoff"), GTK_STOCK_CLOSE, G_CALLBACK(signoff_all), NULL, 0, 0, 0); |
4157 | 162 break; |
163 } | |
164 | |
165 gaim_new_item_from_stock(menu, _("Quit"), GTK_STOCK_QUIT, G_CALLBACK(do_quit), NULL, 0, 0, 0); | |
3510 | 166 |
167 gtk_widget_show_all(menu); | |
168 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, event->time); | |
169 } | |
170 | |
171 static void docklet_clicked(GtkWidget *button, GdkEventButton *event, void *data) { | |
3939 | 172 if (event->type != GDK_BUTTON_PRESS) |
173 return; | |
174 | |
3510 | 175 switch (event->button) { |
176 case 1: | |
3517 | 177 if (unread_message_queue) { |
3570 | 178 docklet_flush_queue(); |
3517 | 179 docklet_update_status(); |
3570 | 180 } else { |
4698 | 181 gaim_gtk_blist_docklet_toggle(); |
3554 | 182 } |
3510 | 183 break; |
184 case 2: | |
185 break; | |
186 case 3: | |
187 docklet_menu(event); | |
188 break; | |
189 } | |
190 } | |
191 | |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
192 static void docklet_update_icon() { |
4250
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
193 const gchar *icon_name = NULL; |
3510 | 194 |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
195 switch (icon) { |
4157 | 196 case offline: |
5024 | 197 icon_name = GAIM_STOCK_ICON_OFFLINE; |
4157 | 198 break; |
199 case offline_connecting: | |
200 case online_connecting: | |
5024 | 201 icon_name = GAIM_STOCK_ICON_CONNECT; |
4157 | 202 break; |
3510 | 203 case online: |
5024 | 204 icon_name = GAIM_STOCK_ICON_ONLINE; |
3510 | 205 break; |
4157 | 206 case online_pending: |
5024 | 207 icon_name = GAIM_STOCK_ICON_ONLINE_MSG; |
4157 | 208 break; |
3510 | 209 case away: |
5024 | 210 icon_name = GAIM_STOCK_ICON_AWAY; |
3510 | 211 break; |
212 case away_pending: | |
5024 | 213 icon_name = GAIM_STOCK_ICON_AWAY_MSG; |
3510 | 214 break; |
215 } | |
216 | |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
217 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
|
218 } |
3510 | 219 |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
220 static gboolean docklet_blink_icon() { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
221 if (status == online_pending) { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
222 if (status == icon) { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
223 /* last icon was the right one... let's change it */ |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
224 icon = online; |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
225 } else { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
226 /* last icon was the wrong one, change it back */ |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
227 icon = online_pending; |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
228 } |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
229 } else if (status == away_pending) { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
230 if (status == icon) { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
231 /* last icon was the right one... let's change it */ |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
232 icon = away; |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
233 } else { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
234 /* last icon was the wrong one, change it back */ |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
235 icon = away_pending; |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
236 } |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
237 } else { |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
238 /* no messages, stop blinking */ |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
239 return FALSE; |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
240 } |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
241 |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
242 docklet_update_icon(); |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
243 |
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
244 return TRUE; /* keep blinking */ |
3510 | 245 } |
246 | |
4157 | 247 static gboolean docklet_update_status() { |
3510 | 248 enum docklet_status oldstatus; |
249 | |
250 oldstatus = status; | |
251 | |
5584 | 252 if (gaim_connections_get_all()) { |
3517 | 253 if (unread_message_queue) { |
4157 | 254 status = online_pending; |
3517 | 255 } else if (awaymessage) { |
3510 | 256 if (message_queue) { |
257 status = away_pending; | |
258 } else { | |
259 status = away; | |
260 } | |
5584 | 261 /* XXX Chip killed my dog... */ |
262 #if 0 | |
3554 | 263 } else if (connecting_count) { |
4157 | 264 status = online_connecting; |
5584 | 265 #endif |
3510 | 266 } else { |
267 status = online; | |
268 } | |
269 } else { | |
5584 | 270 /* XXX ... and my pet goldfish ... */ |
271 #if 0 | |
3517 | 272 if (connecting_count) { |
4157 | 273 status = offline_connecting; |
3517 | 274 } else { |
5584 | 275 #endif |
3517 | 276 status = offline; |
5584 | 277 /* XXX ... both of them. */ |
278 #if 0 | |
3517 | 279 } |
5584 | 280 #endif |
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) { |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
298 gaim_debug(GAIM_DEBUG_INFO, "docklet", "Tray Icon: embedded\n"); |
4698 | 299 gaim_gtk_blist_docklet_add(); |
3554 | 300 } |
301 | |
4274 | 302 static void docklet_remove_callbacks() { |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
303 gaim_debug(GAIM_DEBUG_INFO, "docklet", "Tray Icon: removing callbacks"); |
4274 | 304 |
305 while (g_source_remove_by_user_data(&docklet)) { | |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
306 gaim_debug(GAIM_DEBUG_INFO, NULL, "."); |
4274 | 307 } |
308 | |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
309 gaim_debug(GAIM_DEBUG_INFO, NULL, "\n"); |
4274 | 310 } |
311 | |
3554 | 312 static void docklet_destroyed(GtkWidget *widget, void *data) { |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
313 gaim_debug(GAIM_DEBUG_INFO, "docklet", "Tray Icon: destroyed\n"); |
4093 | 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. */ | |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
334 gaim_debug(GAIM_DEBUG_WARNING, "docklet", |
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
335 "Tray Icon: trying to create icon but it already exists?\n"); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
336 plugin_unload(NULL); |
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 | |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
356 gaim_debug(GAIM_DEBUG_INFO, "docklet", "Tray Icon: created\n"); |
4093 | 357 |
358 return FALSE; /* for when we're called by the glib idle handler */ | |
3510 | 359 } |
360 | |
5584 | 361 static void gaim_signon(GaimConnection *gc, void *data) { |
3510 | 362 docklet_update_status(); |
363 } | |
364 | |
5584 | 365 static void gaim_signoff(GaimConnection *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 | |
5584 | 372 static void gaim_connecting(GaimAccount *account, void *data) { |
3510 | 373 docklet_update_status(); |
374 } | |
375 | |
5584 | 376 static void gaim_away(GaimConnection *gc, char *state, char *message, void *data) { |
3510 | 377 /* we only support global away. this is the way it is, ok? */ |
378 docklet_update_status(); | |
379 } | |
380 | |
5584 | 381 static void gaim_im_recv(GaimConnection *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 | |
5584 | 389 /* static void gaim_buddy_signon(GaimConnection *gc, char *who, void *data) { |
3510 | 390 } |
391 | |
5584 | 392 static void gaim_buddy_signoff(GaimConnection *gc, char *who, void *data) { |
3510 | 393 } |
394 | |
5584 | 395 static void gaim_buddy_away(GaimConnection *gc, char *who, void *data) { |
3510 | 396 } |
397 | |
5584 | 398 static void gaim_buddy_back(GaimConnection *gc, char *who, void *data) { |
3510 | 399 } |
400 | |
401 static void gaim_new_conversation(char *who, void *data) { | |
3570 | 402 } */ |
3510 | 403 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
404 static gboolean |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
405 plugin_load(GaimPlugin *plugin) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
406 { |
5554
7b36d02031a2
[gaim-migrate @ 5955]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
407 gaim_prefs_add_none("/plugins/gtk/docklet"); |
7b36d02031a2
[gaim-migrate @ 5955]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
408 gaim_prefs_add_bool("/plugins/gtk/docklet/queue_messages", FALSE); |
7b36d02031a2
[gaim-migrate @ 5955]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
409 |
4093 | 410 docklet_create(NULL); |
3510 | 411 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
412 gaim_signal_connect(plugin, event_signon, gaim_signon, NULL); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
413 gaim_signal_connect(plugin, event_signoff, gaim_signoff, NULL); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
414 gaim_signal_connect(plugin, event_connecting, gaim_connecting, NULL); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
415 gaim_signal_connect(plugin, event_away, gaim_away, NULL); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
416 gaim_signal_connect(plugin, event_im_recv, gaim_im_recv, NULL); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
417 /* gaim_signal_connect(plugin, event_buddy_signon, gaim_buddy_signon, NULL); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
418 gaim_signal_connect(plugin, event_buddy_signoff, gaim_buddy_signoff, NULL); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
419 gaim_signal_connect(plugin, event_buddy_away, gaim_buddy_away, NULL); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
420 gaim_signal_connect(plugin, event_buddy_back, gaim_buddy_back, NULL); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
421 gaim_signal_connect(plugin, event_new_conversation, gaim_new_conversation, NULL); */ |
3510 | 422 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
423 return TRUE; |
3510 | 424 } |
425 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
426 static gboolean |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
427 plugin_unload(GaimPlugin *plugin) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
428 { |
3570 | 429 if (GTK_WIDGET_VISIBLE(docklet)) { |
4698 | 430 gaim_gtk_blist_docklet_remove(); |
3570 | 431 } |
3554 | 432 |
3570 | 433 docklet_flush_queue(); |
3554 | 434 |
4274 | 435 docklet_remove_callbacks(); |
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
436 |
3570 | 437 g_signal_handlers_disconnect_by_func(G_OBJECT(docklet), G_CALLBACK(docklet_destroyed), NULL); |
438 gtk_widget_destroy(GTK_WIDGET(docklet)); | |
3554 | 439 |
4093 | 440 g_object_unref(G_OBJECT(docklet)); |
441 docklet = NULL; | |
442 | |
4567 | 443 /* do this while gaim has no other way to toggle the global mute */ |
444 gaim_sound_set_mute(FALSE); | |
445 | |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
446 gaim_debug(GAIM_DEBUG_INFO, "docklet", "Tray Icon: removed\n"); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
447 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
448 return TRUE; |
3554 | 449 } |
450 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
451 static GtkWidget * |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
452 get_config_frame(GaimPlugin *plugin) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
453 { |
3570 | 454 GtkWidget *frame; |
455 GtkWidget *vbox, *hbox; | |
456 GtkWidget *toggle; | |
5554
7b36d02031a2
[gaim-migrate @ 5955]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
457 static const char *qmpref = "/plugins/gtk/docklet/queue_messages"; |
3517 | 458 |
3570 | 459 frame = gtk_vbox_new(FALSE, 18); |
460 gtk_container_set_border_width(GTK_CONTAINER(frame), 12); | |
461 | |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5234
diff
changeset
|
462 vbox = gaim_gtk_make_frame(frame, _("Tray Icon Configuration")); |
3570 | 463 hbox = gtk_hbox_new(FALSE, 18); |
464 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
3517 | 465 |
4093 | 466 toggle = gtk_check_button_new_with_mnemonic(_("_Hide new messages until tray icon is clicked")); |
5554
7b36d02031a2
[gaim-migrate @ 5955]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
467 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), gaim_prefs_get_bool(qmpref)); |
7b36d02031a2
[gaim-migrate @ 5955]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
468 g_signal_connect(G_OBJECT(toggle), "clicked", G_CALLBACK(docklet_set_bool), (void *)qmpref); |
3570 | 469 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); |
470 | |
471 gtk_widget_show_all(frame); | |
472 return frame; | |
3517 | 473 } |
3570 | 474 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
475 static GaimGtkPluginUiInfo ui_info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
476 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
477 get_config_frame |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
478 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
479 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
480 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
481 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
482 2, /**< api_version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
483 GAIM_PLUGIN_STANDARD, /**< type */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
484 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
485 0, /**< flags */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
486 NULL, /**< dependencies */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
487 GAIM_PRIORITY_DEFAULT, /**< priority */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
488 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
489 DOCKLET_PLUGIN_ID, /**< id */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
490 N_("System Tray Icon"), /**< name */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
491 VERSION, /**< version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
492 /** summary */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
493 N_("Displays an icon for Gaim in the system tray."), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
494 /** description */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
495 N_("Interacts with a Notification Area applet (in GNOME or KDE, " |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
496 "for example) to display the current status of Gaim, allow fast " |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
497 "access to commonly used functions, and to toggle display of the " |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
498 "buddy list or login window. Also allows messages to be queued " |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
499 "until the icon is clicked, similar to ICQ."), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
500 "Robert McQueen <robot101@debian.org>", /**< author */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
501 WEBSITE, /**< homepage */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
502 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
503 plugin_load, /**< load */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
504 plugin_unload, /**< unload */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
505 NULL, /**< destroy */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
506 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
507 &ui_info, /**< ui_info */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
508 NULL /**< extra_info */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
509 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
510 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
511 static void |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
512 __init_plugin(GaimPlugin *plugin) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
513 { |
3551 | 514 } |
3510 | 515 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
516 GAIM_INIT_PLUGIN(docklet, __init_plugin, info); |