Mercurial > pidgin
annotate plugins/docklet/docklet.c @ 5872:059d95c67cda
[gaim-migrate @ 6304]
The legendary Header File Cleanup! Files now only include what they need.
This should reduce the number of files that must recompile when a header
file changes. It's a lot nicer. Trust me on it. I also added a couple new
header files. I hope I didn't break TOO much!
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Sat, 14 Jun 2003 23:21:02 +0000 |
| parents | b61520e71679 |
| children | dbe2a2174be9 |
| 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 */ | |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
30 #include "internal.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
31 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
32 #include "debug.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
33 #include "prefs.h" |
| 4561 | 34 #include "sound.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
35 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
36 #include "gtkaccount.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
37 #include "gtkblist.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
38 #include "gtkft.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
39 #include "gtkplugin.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
40 #include "gtkprefs.h" |
| 5684 | 41 #include "gtksound.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
42 #include "gtkutils.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
43 #include "stock.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
44 |
| 3510 | 45 #include "eggtrayicon.h" |
| 46 | |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
47 #include "gaim.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
48 #include "ui.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
49 |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
50 #define DOCKLET_PLUGIN_ID "gtk-docklet" |
| 3867 | 51 |
| 3510 | 52 /* types */ |
| 53 enum docklet_status { | |
| 4157 | 54 offline, |
| 55 offline_connecting, | |
| 3510 | 56 online, |
| 4157 | 57 online_connecting, |
| 58 online_pending, | |
| 3510 | 59 away, |
| 4157 | 60 away_pending |
| 3510 | 61 }; |
| 62 | |
| 63 /* functions */ | |
| 4093 | 64 static gboolean docklet_create(); |
| 4157 | 65 static gboolean docklet_update_status(); |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
66 static gboolean plugin_unload(GaimPlugin *plugin); |
| 3510 | 67 |
| 68 /* globals */ | |
| 3513 | 69 static EggTrayIcon *docklet = NULL; |
|
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
70 static GtkWidget *image = NULL; |
| 3510 | 71 static enum docklet_status status; |
|
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
72 static enum docklet_status icon; |
| 3510 | 73 |
| 3554 | 74 static void docklet_toggle_mute(GtkWidget *toggle, void *data) { |
| 5684 | 75 gaim_gtk_sound_set_mute(GTK_CHECK_MENU_ITEM(toggle)->active); |
| 3510 | 76 } |
| 77 | |
|
5554
7b36d02031a2
[gaim-migrate @ 5955]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
78 static void docklet_set_bool(GtkWidget *widget, const char *key) { |
|
7b36d02031a2
[gaim-migrate @ 5955]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
79 gaim_prefs_set_bool(key, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))); |
| 3510 | 80 } |
| 3570 | 81 |
| 3554 | 82 static void docklet_flush_queue() { |
| 3570 | 83 if (unread_message_queue) { |
| 4274 | 84 purge_away_queue(&unread_message_queue); |
| 3570 | 85 } |
| 3510 | 86 } |
| 87 | |
| 88 static void docklet_menu(GdkEventButton *event) { | |
| 3513 | 89 static GtkWidget *menu = NULL; |
| 3512 | 90 GtkWidget *entry; |
| 3510 | 91 |
| 92 if (menu) { | |
| 93 gtk_widget_destroy(menu); | |
| 94 } | |
| 95 | |
| 96 menu = gtk_menu_new(); | |
| 97 | |
| 4157 | 98 switch (status) { |
| 99 case offline: | |
| 100 case offline_connecting: | |
| 5584 | 101 /* XXX CHIP KILLED AUTO CONNECTING */ |
| 102 #if 0 | |
| 5024 | 103 gaim_new_item_from_stock(menu, _("Auto-login"), GAIM_STOCK_SIGN_ON, G_CALLBACK(auto_login), NULL, 0, 0, NULL); |
| 5584 | 104 #endif |
| 4567 | 105 break; |
| 106 default: | |
| 5024 | 107 gaim_new_item_from_stock(menu, _("New Message.."), GAIM_STOCK_IM, G_CALLBACK(show_im_dialog), NULL, 0, 0, NULL); |
| 108 gaim_new_item_from_stock(menu, _("Join A Chat..."), GAIM_STOCK_CHAT, G_CALLBACK(join_chat), NULL, 0, 0, NULL); | |
| 4567 | 109 break; |
| 110 } | |
| 111 | |
| 112 switch (status) { | |
| 113 case offline: | |
| 114 case offline_connecting: | |
| 4157 | 115 break; |
| 116 case online: | |
| 117 case online_connecting: | |
| 118 case online_pending: { | |
| 3510 | 119 GtkWidget *docklet_awaymenu; |
| 120 GSList *awy = NULL; | |
| 121 struct away_message *a = NULL; | |
| 122 | |
| 123 docklet_awaymenu = gtk_menu_new(); | |
| 124 awy = away_messages; | |
| 125 | |
| 126 while (awy) { | |
| 127 a = (struct away_message *)awy->data; | |
| 128 | |
| 129 entry = gtk_menu_item_new_with_label(a->name); | |
| 3554 | 130 g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(do_away_message), a); |
| 4635 | 131 gtk_menu_shell_append(GTK_MENU_SHELL(docklet_awaymenu), entry); |
| 3510 | 132 |
| 133 awy = g_slist_next(awy); | |
| 134 } | |
| 135 | |
| 4157 | 136 if (away_messages) |
| 137 gaim_separator(docklet_awaymenu); | |
| 3510 | 138 |
| 139 entry = gtk_menu_item_new_with_label(_("New...")); | |
| 3554 | 140 g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(create_away_mess), NULL); |
| 4635 | 141 gtk_menu_shell_append(GTK_MENU_SHELL(docklet_awaymenu), entry); |
| 3510 | 142 |
| 143 entry = gtk_menu_item_new_with_label(_("Away")); | |
| 3512 | 144 gtk_menu_item_set_submenu(GTK_MENU_ITEM(entry), docklet_awaymenu); |
| 4635 | 145 gtk_menu_shell_append(GTK_MENU_SHELL(menu), entry); |
| 4157 | 146 } break; |
| 147 case away: | |
| 148 case away_pending: | |
| 3510 | 149 entry = gtk_menu_item_new_with_label(_("Back")); |
| 3554 | 150 g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(do_im_back), NULL); |
| 4635 | 151 gtk_menu_shell_append(GTK_MENU_SHELL(menu), entry); |
| 4157 | 152 break; |
| 3510 | 153 } |
| 154 | |
| 4567 | 155 gaim_separator(menu); |
| 156 | |
| 157 entry = gtk_check_menu_item_new_with_label(_("Mute Sounds")); | |
| 5684 | 158 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(entry), gaim_gtk_sound_get_mute()); |
| 4567 | 159 g_signal_connect(G_OBJECT(entry), "toggled", G_CALLBACK(docklet_toggle_mute), NULL); |
| 4635 | 160 gtk_menu_shell_append(GTK_MENU_SHELL(menu), entry); |
| 4567 | 161 |
| 5669 | 162 gaim_new_item_from_stock(menu, _("File Transfers"), GAIM_STOCK_FILE_TRANSFER, G_CALLBACK(gaim_show_xfer_dialog), NULL, 0, 0, NULL); |
| 163 gaim_new_item_from_stock(menu, _("Accounts"), GAIM_STOCK_ACCOUNTS, G_CALLBACK(gaim_gtk_account_dialog_show), NULL, 0, 0, NULL); | |
| 164 gaim_new_item_from_stock(menu, _("Preferences"), GTK_STOCK_PREFERENCES, G_CALLBACK(gaim_gtk_prefs_show), NULL, 0, 0, NULL); | |
| 4567 | 165 |
| 166 gaim_separator(menu); | |
| 167 | |
| 4157 | 168 switch (status) { |
| 169 case offline: | |
| 170 case offline_connecting: | |
| 171 break; | |
| 172 default: | |
| 5607 | 173 gaim_new_item_from_stock(menu, _("Signoff"), GTK_STOCK_CLOSE, G_CALLBACK(gaim_connections_disconnect_all), NULL, 0, 0, 0); |
| 4157 | 174 break; |
| 175 } | |
| 176 | |
| 177 gaim_new_item_from_stock(menu, _("Quit"), GTK_STOCK_QUIT, G_CALLBACK(do_quit), NULL, 0, 0, 0); | |
| 3510 | 178 |
| 179 gtk_widget_show_all(menu); | |
| 180 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, event->time); | |
| 181 } | |
| 182 | |
| 183 static void docklet_clicked(GtkWidget *button, GdkEventButton *event, void *data) { | |
| 3939 | 184 if (event->type != GDK_BUTTON_PRESS) |
| 185 return; | |
| 186 | |
| 3510 | 187 switch (event->button) { |
| 188 case 1: | |
| 3517 | 189 if (unread_message_queue) { |
| 3570 | 190 docklet_flush_queue(); |
| 3517 | 191 docklet_update_status(); |
| 3570 | 192 } else { |
| 4698 | 193 gaim_gtk_blist_docklet_toggle(); |
| 3554 | 194 } |
| 3510 | 195 break; |
| 196 case 2: | |
| 197 break; | |
| 198 case 3: | |
| 199 docklet_menu(event); | |
| 200 break; | |
| 201 } | |
| 202 } | |
| 203 | |
|
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
204 static void docklet_update_icon() { |
|
4250
3b884e35e6b5
[gaim-migrate @ 4500]
Christian Hammond <chipx86@chipx86.com>
parents:
4157
diff
changeset
|
205 const gchar *icon_name = NULL; |
| 3510 | 206 |
|
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
207 switch (icon) { |
| 4157 | 208 case offline: |
| 5024 | 209 icon_name = GAIM_STOCK_ICON_OFFLINE; |
| 4157 | 210 break; |
| 211 case offline_connecting: | |
| 212 case online_connecting: | |
| 5024 | 213 icon_name = GAIM_STOCK_ICON_CONNECT; |
| 4157 | 214 break; |
| 3510 | 215 case online: |
| 5024 | 216 icon_name = GAIM_STOCK_ICON_ONLINE; |
| 3510 | 217 break; |
| 4157 | 218 case online_pending: |
| 5024 | 219 icon_name = GAIM_STOCK_ICON_ONLINE_MSG; |
| 4157 | 220 break; |
| 3510 | 221 case away: |
| 5024 | 222 icon_name = GAIM_STOCK_ICON_AWAY; |
| 3510 | 223 break; |
| 224 case away_pending: | |
| 5024 | 225 icon_name = GAIM_STOCK_ICON_AWAY_MSG; |
| 3510 | 226 break; |
| 227 } | |
| 228 | |
|
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
229 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
|
230 } |
| 3510 | 231 |
|
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
232 static gboolean docklet_blink_icon() { |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
233 if (status == online_pending) { |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
234 if (status == icon) { |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
235 /* last icon was the right one... let's change it */ |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
236 icon = online; |
|
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 /* last icon was the wrong one, change it back */ |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
239 icon = online_pending; |
|
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 } else if (status == away_pending) { |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
242 if (status == icon) { |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
243 /* last icon was the right one... let's change it */ |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
244 icon = away; |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
245 } else { |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
246 /* last icon was the wrong one, change it back */ |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
247 icon = away_pending; |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
248 } |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
249 } else { |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
250 /* no messages, stop blinking */ |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
251 return FALSE; |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
252 } |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
253 |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
254 docklet_update_icon(); |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
255 |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
256 return TRUE; /* keep blinking */ |
| 3510 | 257 } |
| 258 | |
| 4157 | 259 static gboolean docklet_update_status() { |
| 3510 | 260 enum docklet_status oldstatus; |
| 261 | |
| 262 oldstatus = status; | |
| 263 | |
| 5584 | 264 if (gaim_connections_get_all()) { |
| 3517 | 265 if (unread_message_queue) { |
| 4157 | 266 status = online_pending; |
| 3517 | 267 } else if (awaymessage) { |
| 3510 | 268 if (message_queue) { |
| 269 status = away_pending; | |
| 270 } else { | |
| 271 status = away; | |
| 272 } | |
| 5584 | 273 /* XXX Chip killed my dog... */ |
| 274 #if 0 | |
| 3554 | 275 } else if (connecting_count) { |
| 4157 | 276 status = online_connecting; |
| 5584 | 277 #endif |
| 3510 | 278 } else { |
| 279 status = online; | |
| 280 } | |
| 281 } else { | |
| 5584 | 282 /* XXX ... and my pet goldfish ... */ |
| 283 #if 0 | |
| 3517 | 284 if (connecting_count) { |
| 4157 | 285 status = offline_connecting; |
| 3517 | 286 } else { |
| 5584 | 287 #endif |
| 3517 | 288 status = offline; |
| 5584 | 289 /* XXX ... both of them. */ |
| 290 #if 0 | |
| 3517 | 291 } |
| 5584 | 292 #endif |
| 3510 | 293 } |
| 294 | |
|
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
295 /* update the icon if we changed status */ |
| 3510 | 296 if (status != oldstatus) { |
|
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
297 icon = status; |
| 3510 | 298 docklet_update_icon(); |
|
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
299 |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
300 /* and schedule the blinker function if messages are pending */ |
|
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
301 if (status == online_pending || status == away_pending) { |
| 4274 | 302 g_timeout_add(500, docklet_blink_icon, &docklet); |
|
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
303 } |
| 3510 | 304 } |
| 4157 | 305 |
| 306 return FALSE; /* for when we're called by the glib idle handler */ | |
| 3510 | 307 } |
| 308 | |
| 3554 | 309 static void docklet_embedded(GtkWidget *widget, void *data) { |
|
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
310 gaim_debug(GAIM_DEBUG_INFO, "docklet", "Tray Icon: embedded\n"); |
| 4698 | 311 gaim_gtk_blist_docklet_add(); |
| 3554 | 312 } |
| 313 | |
| 4274 | 314 static void docklet_remove_callbacks() { |
|
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
315 gaim_debug(GAIM_DEBUG_INFO, "docklet", "Tray Icon: removing callbacks"); |
| 4274 | 316 |
| 317 while (g_source_remove_by_user_data(&docklet)) { | |
|
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
318 gaim_debug(GAIM_DEBUG_INFO, NULL, "."); |
| 4274 | 319 } |
| 320 | |
|
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
321 gaim_debug(GAIM_DEBUG_INFO, NULL, "\n"); |
| 4274 | 322 } |
| 323 | |
| 3554 | 324 static void docklet_destroyed(GtkWidget *widget, void *data) { |
|
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
325 gaim_debug(GAIM_DEBUG_INFO, "docklet", "Tray Icon: destroyed\n"); |
| 4093 | 326 |
| 4698 | 327 gaim_gtk_blist_docklet_remove(); |
| 4093 | 328 |
| 3570 | 329 docklet_flush_queue(); |
| 4093 | 330 |
| 4274 | 331 docklet_remove_callbacks(); |
|
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
332 |
| 4093 | 333 g_object_unref(G_OBJECT(docklet)); |
| 334 docklet = NULL; | |
| 335 | |
| 4274 | 336 g_idle_add(docklet_create, &docklet); |
| 3554 | 337 } |
| 338 | |
| 4274 | 339 static gboolean docklet_create() { |
| 3510 | 340 GtkWidget *box; |
| 341 | |
| 3570 | 342 if (docklet) { |
| 4093 | 343 /* if this is being called when a tray icon exists, it's because |
| 344 something messed up. try destroying it before we proceed, | |
| 345 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
|
346 gaim_debug(GAIM_DEBUG_WARNING, "docklet", |
|
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
347 "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
|
348 plugin_unload(NULL); |
| 3510 | 349 } |
| 350 | |
| 351 docklet = egg_tray_icon_new("Gaim"); | |
| 352 box = gtk_event_box_new(); | |
|
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
353 image = gtk_image_new(); |
| 3510 | 354 |
| 3554 | 355 g_signal_connect(G_OBJECT(docklet), "embedded", G_CALLBACK(docklet_embedded), NULL); |
| 356 g_signal_connect(G_OBJECT(docklet), "destroy", G_CALLBACK(docklet_destroyed), NULL); | |
| 357 g_signal_connect(G_OBJECT(box), "button-press-event", G_CALLBACK(docklet_clicked), NULL); | |
| 3510 | 358 |
|
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
359 gtk_container_add(GTK_CONTAINER(box), image); |
| 3510 | 360 gtk_container_add(GTK_CONTAINER(docklet), box); |
| 361 gtk_widget_show_all(GTK_WIDGET(docklet)); | |
| 362 | |
| 3554 | 363 /* ref the docklet before we bandy it about the place */ |
| 364 g_object_ref(G_OBJECT(docklet)); | |
| 3510 | 365 docklet_update_status(); |
| 366 docklet_update_icon(); | |
| 367 | |
|
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
368 gaim_debug(GAIM_DEBUG_INFO, "docklet", "Tray Icon: created\n"); |
| 4093 | 369 |
| 370 return FALSE; /* for when we're called by the glib idle handler */ | |
| 3510 | 371 } |
| 372 | |
| 5584 | 373 static void gaim_signon(GaimConnection *gc, void *data) { |
| 3510 | 374 docklet_update_status(); |
| 375 } | |
| 376 | |
| 5584 | 377 static void gaim_signoff(GaimConnection *gc, void *data) { |
| 4157 | 378 /* do this when idle so that if the prpl was connecting |
| 379 and was cancelled, we register that connecting_count | |
| 380 has returned to 0 */ | |
| 4274 | 381 g_idle_add(docklet_update_status, &docklet); |
| 3510 | 382 } |
| 383 | |
| 5584 | 384 static void gaim_connecting(GaimAccount *account, void *data) { |
| 3510 | 385 docklet_update_status(); |
| 386 } | |
| 387 | |
| 5584 | 388 static void gaim_away(GaimConnection *gc, char *state, char *message, void *data) { |
| 3510 | 389 /* we only support global away. this is the way it is, ok? */ |
| 390 docklet_update_status(); | |
| 391 } | |
| 392 | |
| 5584 | 393 static void gaim_im_recv(GaimConnection *gc, char **who, char **what, void *data) { |
| 3510 | 394 /* if message queuing while away is enabled, this event could be the first |
| 4274 | 395 message so we need to see if the status (and hence icon) needs changing. |
| 396 do this when idle so that all message processing is completed, queuing | |
| 397 etc, before we run. */ | |
| 398 g_idle_add(docklet_update_status, &docklet); | |
| 3510 | 399 } |
| 400 | |
| 5584 | 401 /* static void gaim_buddy_signon(GaimConnection *gc, char *who, void *data) { |
| 3510 | 402 } |
| 403 | |
| 5584 | 404 static void gaim_buddy_signoff(GaimConnection *gc, char *who, void *data) { |
| 3510 | 405 } |
| 406 | |
| 5584 | 407 static void gaim_buddy_away(GaimConnection *gc, char *who, void *data) { |
| 3510 | 408 } |
| 409 | |
| 5584 | 410 static void gaim_buddy_back(GaimConnection *gc, char *who, void *data) { |
| 3510 | 411 } |
| 412 | |
| 413 static void gaim_new_conversation(char *who, void *data) { | |
| 3570 | 414 } */ |
| 3510 | 415 |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
416 static gboolean |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
417 plugin_load(GaimPlugin *plugin) |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
418 { |
|
5554
7b36d02031a2
[gaim-migrate @ 5955]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
419 gaim_prefs_add_none("/plugins/gtk/docklet"); |
|
7b36d02031a2
[gaim-migrate @ 5955]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
420 gaim_prefs_add_bool("/plugins/gtk/docklet/queue_messages", FALSE); |
|
7b36d02031a2
[gaim-migrate @ 5955]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
421 |
| 4093 | 422 docklet_create(NULL); |
| 3510 | 423 |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
424 gaim_signal_connect(plugin, event_signon, gaim_signon, NULL); |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
425 gaim_signal_connect(plugin, event_signoff, gaim_signoff, NULL); |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
426 gaim_signal_connect(plugin, event_connecting, gaim_connecting, NULL); |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
427 gaim_signal_connect(plugin, event_away, gaim_away, NULL); |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
428 gaim_signal_connect(plugin, event_im_recv, gaim_im_recv, NULL); |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
429 /* gaim_signal_connect(plugin, event_buddy_signon, gaim_buddy_signon, NULL); |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
430 gaim_signal_connect(plugin, event_buddy_signoff, gaim_buddy_signoff, NULL); |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
431 gaim_signal_connect(plugin, event_buddy_away, gaim_buddy_away, NULL); |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
432 gaim_signal_connect(plugin, event_buddy_back, gaim_buddy_back, NULL); |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
433 gaim_signal_connect(plugin, event_new_conversation, gaim_new_conversation, NULL); */ |
| 3510 | 434 |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
435 return TRUE; |
| 3510 | 436 } |
| 437 | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
438 static gboolean |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
439 plugin_unload(GaimPlugin *plugin) |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
440 { |
| 3570 | 441 if (GTK_WIDGET_VISIBLE(docklet)) { |
| 4698 | 442 gaim_gtk_blist_docklet_remove(); |
| 3570 | 443 } |
| 3554 | 444 |
| 3570 | 445 docklet_flush_queue(); |
| 3554 | 446 |
| 4274 | 447 docklet_remove_callbacks(); |
|
4261
e252238f99df
[gaim-migrate @ 4512]
Christian Hammond <chipx86@chipx86.com>
parents:
4250
diff
changeset
|
448 |
| 3570 | 449 g_signal_handlers_disconnect_by_func(G_OBJECT(docklet), G_CALLBACK(docklet_destroyed), NULL); |
| 450 gtk_widget_destroy(GTK_WIDGET(docklet)); | |
| 3554 | 451 |
| 4093 | 452 g_object_unref(G_OBJECT(docklet)); |
| 453 docklet = NULL; | |
| 454 | |
| 4567 | 455 /* do this while gaim has no other way to toggle the global mute */ |
| 5684 | 456 gaim_gtk_sound_set_mute(FALSE); |
| 4567 | 457 |
|
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
458 gaim_debug(GAIM_DEBUG_INFO, "docklet", "Tray Icon: removed\n"); |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
459 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
460 return TRUE; |
| 3554 | 461 } |
| 462 | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
463 static GtkWidget * |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
464 get_config_frame(GaimPlugin *plugin) |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
465 { |
| 3570 | 466 GtkWidget *frame; |
| 467 GtkWidget *vbox, *hbox; | |
| 468 GtkWidget *toggle; | |
|
5554
7b36d02031a2
[gaim-migrate @ 5955]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
469 static const char *qmpref = "/plugins/gtk/docklet/queue_messages"; |
| 3517 | 470 |
| 3570 | 471 frame = gtk_vbox_new(FALSE, 18); |
| 472 gtk_container_set_border_width(GTK_CONTAINER(frame), 12); | |
| 473 | |
|
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5234
diff
changeset
|
474 vbox = gaim_gtk_make_frame(frame, _("Tray Icon Configuration")); |
| 3570 | 475 hbox = gtk_hbox_new(FALSE, 18); |
| 476 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
| 3517 | 477 |
| 4093 | 478 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
|
479 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
|
480 g_signal_connect(G_OBJECT(toggle), "clicked", G_CALLBACK(docklet_set_bool), (void *)qmpref); |
| 3570 | 481 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); |
| 482 | |
| 483 gtk_widget_show_all(frame); | |
| 484 return frame; | |
| 3517 | 485 } |
| 3570 | 486 |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
487 static GaimGtkPluginUiInfo ui_info = |
|
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 get_config_frame |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
490 }; |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
491 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
492 static GaimPluginInfo info = |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
493 { |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
494 2, /**< api_version */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
495 GAIM_PLUGIN_STANDARD, /**< type */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
496 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
497 0, /**< flags */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
498 NULL, /**< dependencies */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
499 GAIM_PRIORITY_DEFAULT, /**< priority */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
500 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
501 DOCKLET_PLUGIN_ID, /**< id */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
502 N_("System Tray Icon"), /**< name */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
503 VERSION, /**< version */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
504 /** summary */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
505 N_("Displays an icon for Gaim in the system tray."), |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
506 /** description */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
507 N_("Interacts with a Notification Area applet (in GNOME or KDE, " |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
508 "for example) to display the current status of Gaim, allow fast " |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
509 "access to commonly used functions, and to toggle display of the " |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
510 "buddy list or login window. Also allows messages to be queued " |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
511 "until the icon is clicked, similar to ICQ."), |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
512 "Robert McQueen <robot101@debian.org>", /**< author */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
513 WEBSITE, /**< homepage */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
514 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
515 plugin_load, /**< load */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
516 plugin_unload, /**< unload */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
517 NULL, /**< destroy */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
518 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
519 &ui_info, /**< ui_info */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
520 NULL /**< extra_info */ |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
521 }; |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
522 |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
523 static void |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
524 __init_plugin(GaimPlugin *plugin) |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
525 { |
| 3551 | 526 } |
| 3510 | 527 |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
528 GAIM_INIT_PLUGIN(docklet, __init_plugin, info); |
