Thu, 02 Dec 2004 20:34:19 +0000
[gaim-migrate @ 11480]
"After applying this patch, which modifies the make files and makes the
@file/@ingroup markers at the top of several gtk files more uniform,
the following files should be renamed:
dnd-hints.h -> gtkdnd-hints.h
dnd-hints.c -> gtkdnd-hints.c
gaim-disclosure.h -> gtkgaim-disclosure.h
gaim-disclosure.c -> gtkgaim-disclosure.c
stock.h -> gtkstock.h
stock.c -> gtkstock.c
I believe that completes the renaming of files which are explicitly for
gtkgaim; all files in /gaim/src which depend upon gtk should now have
gtk in their name. There are two candidates which might be considered
part of gtkgaim rather than part of the core, but I didn't modify them:
session.c and log.c. Both are quite gaim-UI specific, it seems,
particularly session, but perhaps other UIs could also make use of
their functionality.
-Evan "
committer: Luke Schierer <lschiere@pidgin.im>
| 6209 | 1 | /* |
| 2 | * System tray icon (aka docklet) plugin for Gaim | |
| 3 | * | |
| 4 | * Copyright (C) 2002-3 Robert McQueen <robot101@debian.org> | |
| 5 | * Copyright (C) 2003 Herman Bloggs <hermanator12002@yahoo.com> | |
| 6 | * Inspired by a similar plugin by: | |
| 7 | * John (J5) Palmieri <johnp@martianrock.com> | |
| 8 | * | |
| 9 | * This program is free software; you can redistribute it and/or | |
| 10 | * modify it under the terms of the GNU General Public License as | |
| 11 | * published by the Free Software Foundation; either version 2 of the | |
| 12 | * License, or (at your option) any later version. | |
| 13 | * | |
| 14 | * This program is distributed in the hope that it will be useful, but | |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | * General Public License for more details. | |
| 18 | * | |
| 19 | * You should have received a copy of the GNU General Public License | |
| 20 | * along with this program; if not, write to the Free Software | |
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
| 22 | * 02111-1307, USA. | |
| 23 | */ | |
| 24 | ||
| 25 | #include "internal.h" | |
| 9791 | 26 | #include "gtkgaim.h" |
| 6209 | 27 | #include "debug.h" |
|
10297
b36800725b7a
[gaim-migrate @ 11480]
Evan Schoenberg <evands@pidgin.im>
parents:
10268
diff
changeset
|
28 | #include "gtkstock.h" |
| 6209 | 29 | |
| 30 | #include "gaim.h" | |
|
9709
2e73f176cc80
[gaim-migrate @ 10570]
Mark Doliner <markdoliner@pidgin.im>
parents:
9229
diff
changeset
|
31 | #include "gtkdialogs.h" |
| 6209 | 32 | |
| 33 | #include "eggtrayicon.h" | |
| 34 | #include "docklet.h" | |
| 35 | ||
| 36 | /* globals */ | |
| 37 | static EggTrayIcon *docklet = NULL; | |
| 38 | static GtkWidget *image = NULL; | |
|
6894
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
39 | static GdkPixbuf *blank_icon = NULL; |
| 6209 | 40 | |
| 41 | /* protos */ | |
| 42 | static void docklet_x11_create(); | |
| 43 | ||
| 44 | static gboolean | |
| 45 | docklet_x11_create_cb() | |
| 46 | { | |
| 47 | docklet_x11_create(); | |
| 48 | ||
| 49 | return FALSE; /* for when we're called by the glib idle handler */ | |
| 50 | } | |
| 51 | ||
| 52 | static void | |
| 53 | docklet_x11_embedded_cb(GtkWidget *widget, void *data) | |
| 54 | { | |
| 55 | gaim_debug(GAIM_DEBUG_INFO, "tray icon", "embedded\n"); | |
| 56 | ||
| 57 | docklet_embedded(); | |
| 58 | } | |
| 59 | ||
| 60 | static void | |
| 61 | docklet_x11_destroyed_cb(GtkWidget *widget, void *data) | |
| 62 | { | |
| 63 | gaim_debug(GAIM_DEBUG_INFO, "tray icon", "destroyed\n"); | |
| 64 | ||
| 65 | docklet_remove(TRUE); | |
| 66 | ||
| 67 | g_object_unref(G_OBJECT(docklet)); | |
| 68 | docklet = NULL; | |
| 69 | ||
| 70 | g_idle_add(docklet_x11_create_cb, &handle); | |
| 71 | } | |
| 72 | ||
| 73 | static void | |
| 74 | docklet_x11_clicked_cb(GtkWidget *button, GdkEventButton *event, void *data) | |
| 75 | { | |
| 76 | if (event->type != GDK_BUTTON_PRESS) | |
| 77 | return; | |
| 78 | ||
| 79 | docklet_clicked(event->button); | |
| 80 | } | |
| 81 | ||
| 82 | static void | |
| 83 | docklet_x11_update_icon(enum docklet_status icon) | |
| 84 | { | |
| 85 | const gchar *icon_name = NULL; | |
| 86 | ||
| 87 | switch (icon) { | |
| 88 | case offline: | |
| 89 | icon_name = GAIM_STOCK_ICON_OFFLINE; | |
| 90 | break; | |
| 91 | case offline_connecting: | |
| 92 | case online_connecting: | |
| 93 | icon_name = GAIM_STOCK_ICON_CONNECT; | |
| 94 | break; | |
| 95 | case online: | |
| 96 | icon_name = GAIM_STOCK_ICON_ONLINE; | |
| 97 | break; | |
| 98 | case online_pending: | |
| 99 | icon_name = GAIM_STOCK_ICON_ONLINE_MSG; | |
| 100 | break; | |
| 101 | case away: | |
| 102 | icon_name = GAIM_STOCK_ICON_AWAY; | |
| 103 | break; | |
| 104 | case away_pending: | |
| 105 | icon_name = GAIM_STOCK_ICON_AWAY_MSG; | |
| 106 | break; | |
| 107 | } | |
| 108 | ||
| 109 | gtk_image_set_from_stock(GTK_IMAGE(image), icon_name, GTK_ICON_SIZE_LARGE_TOOLBAR); | |
| 110 | } | |
| 111 | ||
| 112 | static void | |
|
6894
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
113 | docklet_x11_blank_icon() |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
114 | { |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
115 | if (!blank_icon) { |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
116 | gint width, height; |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
117 | |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
118 | gtk_icon_size_lookup(GTK_ICON_SIZE_LARGE_TOOLBAR, &width, &height); |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
119 | blank_icon = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height); |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
120 | gdk_pixbuf_fill(blank_icon, 0); |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
121 | } |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
122 | |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
123 | gtk_image_set_from_pixbuf(GTK_IMAGE(image), blank_icon); |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
124 | } |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
125 | |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
126 | static void |
|
10268
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
127 | docklet_x11_position_menu(GtkMenu *menu, int *x, int *y, gboolean *push_in, |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
128 | gpointer user_data) |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
129 | { |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
130 | GtkWidget *widget = GTK_WIDGET(docklet); |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
131 | GtkRequisition req; |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
132 | gint menu_xpos, menu_ypos; |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
133 | |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
134 | gtk_widget_size_request(GTK_WIDGET(menu), &req); |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
135 | gdk_window_get_origin(widget->window, &menu_xpos, &menu_ypos); |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
136 | |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
137 | menu_xpos += widget->allocation.x; |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
138 | menu_ypos += widget->allocation.y; |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
139 | |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
140 | if (menu_ypos > gdk_screen_get_height(gtk_widget_get_screen(widget)) / 2) |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
141 | menu_ypos -= req.height; |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
142 | else |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
143 | menu_ypos += widget->allocation.height; |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
144 | |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
145 | *x = menu_xpos; |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
146 | *y = menu_ypos; |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
147 | |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
148 | *push_in = TRUE; |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
149 | } |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
150 | |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
151 | static void |
| 6209 | 152 | docklet_x11_destroy() |
| 153 | { | |
| 154 | docklet_remove(GTK_WIDGET_VISIBLE(docklet)); | |
| 155 | ||
| 156 | g_signal_handlers_disconnect_by_func(G_OBJECT(docklet), G_CALLBACK(docklet_x11_destroyed_cb), NULL); | |
| 157 | gtk_widget_destroy(GTK_WIDGET(docklet)); | |
| 158 | ||
| 159 | g_object_unref(G_OBJECT(docklet)); | |
| 160 | docklet = NULL; | |
| 161 | ||
|
6894
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
162 | if (blank_icon) |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
163 | g_object_unref(G_OBJECT(blank_icon)); |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
164 | blank_icon = NULL; |
|
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
165 | |
| 6209 | 166 | gaim_debug(GAIM_DEBUG_INFO, "tray icon", "destroyed\n"); |
| 167 | } | |
| 168 | ||
| 169 | static void | |
| 170 | docklet_x11_create() | |
| 171 | { | |
| 172 | GtkWidget *box; | |
| 173 | ||
| 174 | if (docklet) { | |
| 175 | /* if this is being called when a tray icon exists, it's because | |
| 176 | something messed up. try destroying it before we proceed, | |
| 177 | although docklet_refcount may be all hosed. hopefully won't happen. */ | |
| 178 | gaim_debug(GAIM_DEBUG_WARNING, "tray icon", "trying to create icon but it already exists?\n"); | |
| 179 | docklet_x11_destroy(); | |
| 180 | } | |
| 181 | ||
| 182 | docklet = egg_tray_icon_new("Gaim"); | |
| 183 | box = gtk_event_box_new(); | |
| 184 | image = gtk_image_new(); | |
| 185 | ||
| 186 | g_signal_connect(G_OBJECT(docklet), "embedded", G_CALLBACK(docklet_x11_embedded_cb), NULL); | |
| 187 | g_signal_connect(G_OBJECT(docklet), "destroy", G_CALLBACK(docklet_x11_destroyed_cb), NULL); | |
| 188 | g_signal_connect(G_OBJECT(box), "button-press-event", G_CALLBACK(docklet_x11_clicked_cb), NULL); | |
| 189 | ||
| 190 | gtk_container_add(GTK_CONTAINER(box), image); | |
| 191 | gtk_container_add(GTK_CONTAINER(docklet), box); | |
| 9229 | 192 | |
| 193 | if(!gtk_check_version(2,4,0)) | |
| 194 | g_object_set(G_OBJECT(box), "visible-window", FALSE, NULL); | |
| 195 | ||
| 6209 | 196 | gtk_widget_show_all(GTK_WIDGET(docklet)); |
| 197 | ||
| 198 | /* ref the docklet before we bandy it about the place */ | |
| 199 | g_object_ref(G_OBJECT(docklet)); | |
| 200 | ||
| 201 | gaim_debug(GAIM_DEBUG_INFO, "tray icon", "created\n"); | |
| 202 | } | |
| 203 | ||
| 204 | static struct docklet_ui_ops ui_ops = | |
| 205 | { | |
| 206 | docklet_x11_create, | |
| 207 | docklet_x11_destroy, | |
|
6894
8c6e286b079d
[gaim-migrate @ 7441]
Herman Bloggs <herman@bluedigits.com>
parents:
6371
diff
changeset
|
208 | docklet_x11_update_icon, |
|
10268
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
209 | docklet_x11_blank_icon, |
|
862ed5d3f227
[gaim-migrate @ 11414]
Christian Hammond <chipx86@chipx86.com>
parents:
9791
diff
changeset
|
210 | docklet_x11_position_menu |
| 6209 | 211 | }; |
| 212 | ||
| 213 | void | |
| 214 | docklet_ui_init() | |
| 215 | { | |
| 216 | docklet_set_ui_ops(&ui_ops); | |
| 217 | } |