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