1261
|
1 /**************************************************************
|
|
2 **
|
|
3 ** GaimGnomeAppletMgr
|
|
4 ** Author - Quinticent (John Palmieri: johnp@martianrock.com)
|
|
5 **
|
|
6 ** Purpose - Takes over the task of managing the GNOME applet
|
|
7 ** code and provides a centralized codebase for
|
|
8 ** GNOME integration for Gaim.
|
|
9 **
|
|
10 **
|
|
11 ** gaim
|
|
12 **
|
|
13 ** Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
|
|
14 **
|
|
15 ** This program is free software; you can redistribute it and/or modify
|
|
16 ** it under the terms of the GNU General Public License as published by
|
|
17 ** the Free Software Foundation; either version 2 of the License, or
|
|
18 ** (at your option) any later version.
|
|
19 **
|
|
20 ** This program is distributed in the hope that it will be useful,
|
|
21 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23 ** GNU General Public License for more details.
|
|
24 **
|
|
25 ** You should have received a copy of the GNU General Public License
|
|
26 ** along with this program; if not, write to the Free Software
|
|
27 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
28 */
|
|
29
|
|
30 #ifdef HAVE_CONFIG_H
|
|
31 #include "../config.h"
|
|
32 #endif
|
|
33 #ifdef USE_APPLET
|
|
34 #include <string.h>
|
|
35 #include <gdk_imlib.h>
|
|
36 #include "gaim.h"
|
|
37 #include "applet.h"
|
|
38
|
|
39 static int connecting = 0;
|
|
40
|
|
41 gboolean applet_buddy_show = FALSE;
|
|
42 GtkWidget *applet_popup = NULL;
|
|
43
|
|
44 GtkWidget *applet;
|
|
45 GtkWidget *appletframe;
|
|
46 GtkWidget *status_label;
|
|
47
|
|
48 GtkWidget *icon;
|
|
49 GdkPixmap *icon_offline_pm=NULL;
|
|
50 GdkPixmap *icon_offline_bm=NULL;
|
|
51
|
|
52 GdkPixmap *icon_online_pm=NULL;
|
|
53 GdkPixmap *icon_online_bm=NULL;
|
|
54
|
|
55 GdkPixmap *icon_connect_pm=NULL;
|
|
56 GdkPixmap *icon_connect_bm=NULL;
|
|
57
|
|
58 GdkPixmap *icon_msg_pending_pm=NULL;
|
|
59 GdkPixmap *icon_msg_pending_bm=NULL;
|
|
60
|
|
61 GdkPixmap *icon_away_pm=NULL;
|
|
62 GdkPixmap *icon_away_bm=NULL;
|
|
63
|
|
64 static GtkAllocation get_applet_pos(gboolean);
|
|
65 gint sizehint=48;
|
|
66
|
|
67 static gboolean load_applet_icon(const char *name, int height, int width,
|
|
68 GdkPixmap **pm, GdkBitmap **bm)
|
|
69 {
|
|
70 gboolean result = TRUE;
|
|
71 char *path;
|
|
72 GdkImlibImage *im;
|
|
73
|
|
74 path = gnome_pixmap_file(name);
|
|
75
|
|
76 im=gdk_imlib_load_image( path );
|
|
77
|
|
78 if ((*pm)!=NULL)
|
|
79 gdk_imlib_free_pixmap((*pm));
|
|
80
|
|
81 if( im!= NULL ){
|
|
82 gdk_imlib_render(im,width,height);
|
|
83
|
|
84 (*pm) = gdk_imlib_move_image(im);
|
|
85 (*bm) = gdk_imlib_move_mask(im);
|
|
86
|
|
87 } else {
|
|
88 result = FALSE;
|
|
89 debug_printf(_("file not found: %s\n"),path);
|
|
90 }
|
|
91
|
|
92 free(path);
|
|
93 return result;
|
|
94 }
|
|
95
|
|
96 #ifdef HAVE_PANEL_PIXEL_SIZE
|
|
97 static void applet_change_pixel_size(GtkWidget *w, int size, gpointer data)
|
|
98 {
|
|
99 sizehint = size;
|
|
100 update_pixmaps();
|
|
101 }
|
|
102 #endif
|
|
103
|
|
104 static gboolean update_applet(){
|
|
105 char buf[BUF_LONG];
|
|
106 GSList *c = connections;
|
|
107
|
|
108 if (connecting) {
|
|
109 gtk_pixmap_set( GTK_PIXMAP(icon),
|
|
110 icon_connect_pm,
|
|
111 icon_connect_bm );
|
|
112 gtk_label_set( GTK_LABEL(status_label), _MSG_CONNECT_ );
|
|
113 applet_set_tooltips(_("Attempting to sign on...."));
|
|
114 } else if (!connections) {
|
|
115 gtk_pixmap_set( GTK_PIXMAP(icon),
|
|
116 icon_offline_pm,
|
|
117 icon_offline_bm );
|
|
118 gtk_label_set( GTK_LABEL(status_label), _MSG_OFFLINE_ );
|
|
119 applet_set_tooltips(_("Offilne. Click to bring up login box."));
|
|
120 } else if (!awaymessage) {
|
|
121 gtk_pixmap_set( GTK_PIXMAP(icon),
|
|
122 icon_online_pm,
|
|
123 icon_online_bm );
|
|
124 gtk_label_set( GTK_LABEL(status_label), _MSG_ONLINE_ );
|
|
125 g_snprintf(buf, sizeof buf, "Online: ");
|
|
126 while (c) {
|
|
127 strcat(buf, ((struct gaim_connection *)c->data)->username);
|
|
128 c = g_slist_next(c);
|
|
129 if (c) strcat(buf, ", ");
|
|
130 }
|
|
131 applet_set_tooltips(buf);
|
|
132 } else {
|
|
133 gtk_pixmap_set( GTK_PIXMAP(icon),
|
|
134 icon_online_pm,
|
|
135 icon_online_bm );
|
|
136 gtk_label_set( GTK_LABEL(status_label), _("Away") );
|
|
137 }
|
|
138
|
|
139 return TRUE;
|
|
140 }
|
|
141
|
|
142 void update_pixmaps() {
|
|
143 load_applet_icon( GAIM_GNOME_OFFLINE_ICON, (sizehint-16), (sizehint-12),
|
|
144 &icon_offline_pm, &icon_offline_bm );
|
|
145 load_applet_icon( GAIM_GNOME_CONNECT_ICON, (sizehint-16), (sizehint-12),
|
|
146 &icon_connect_pm, &icon_connect_bm );
|
|
147 load_applet_icon( GAIM_GNOME_ONLINE_ICON, (sizehint-16), (sizehint-12),
|
|
148 &icon_online_pm, &icon_online_bm );
|
|
149 update_applet();
|
|
150 gtk_widget_set_usize(appletframe, sizehint, sizehint);
|
|
151 }
|
|
152
|
|
153
|
|
154 extern GtkWidget *mainwindow;
|
|
155 void applet_show_login(AppletWidget *widget, gpointer data) {
|
|
156 show_login();
|
|
157 if (general_options & OPT_GEN_NEAR_APPLET) {
|
|
158 GtkAllocation a = get_applet_pos(FALSE);
|
|
159 gtk_widget_set_uposition(mainwindow, a.x, a.y);
|
|
160 }
|
|
161 }
|
|
162
|
|
163 void applet_do_signon(AppletWidget *widget, gpointer data) {
|
|
164 applet_show_login(NULL, 0);
|
|
165 }
|
|
166
|
|
167 void insert_applet_away() {
|
|
168 GSList *awy = away_messages;
|
|
169 struct away_message *a;
|
|
170 char *awayname;
|
|
171
|
|
172 applet_widget_register_callback_dir(APPLET_WIDGET(applet),
|
|
173 "away/",
|
|
174 _("Away"));
|
|
175 applet_widget_register_callback(APPLET_WIDGET(applet),
|
|
176 "away/new",
|
|
177 _("New Away Message"),
|
|
178 (AppletCallbackFunc)create_away_mess,
|
|
179 NULL);
|
|
180
|
|
181 while(awy) {
|
|
182 a = (struct away_message *)awy->data;
|
|
183
|
|
184 awayname = g_malloc(sizeof *awayname * (6 + strlen(a->name)));
|
|
185 awayname[0] = '\0';
|
|
186 strcat(awayname, "away/");
|
|
187 strcat(awayname, a->name);
|
|
188 applet_widget_register_callback(APPLET_WIDGET(applet),
|
|
189 awayname,
|
|
190 a->name,
|
|
191 (AppletCallbackFunc)do_away_message,
|
|
192 a);
|
|
193
|
|
194 awy = g_slist_next(awy);
|
|
195 free(awayname);
|
|
196 }
|
|
197 }
|
|
198
|
|
199 void remove_applet_away() {
|
|
200 GSList *awy = away_messages;
|
|
201 struct away_message *a;
|
|
202 char *awayname;
|
|
203
|
|
204 applet_widget_unregister_callback(APPLET_WIDGET(applet), "away/new");
|
|
205
|
|
206 while (awy) {
|
|
207 a = (struct away_message *)awy->data;
|
|
208
|
|
209 awayname = g_malloc(sizeof *awayname * (6 + strlen(a->name)));
|
|
210 awayname[0] = '\0';
|
|
211 strcat(awayname, "away/");
|
|
212 strcat(awayname, a->name);
|
|
213 applet_widget_unregister_callback(APPLET_WIDGET(applet), awayname);
|
|
214
|
|
215 awy = g_slist_next(awy);
|
|
216 free(awayname);
|
|
217 }
|
|
218 applet_widget_unregister_callback_dir(APPLET_WIDGET(applet), "away/");
|
|
219 applet_widget_unregister_callback(APPLET_WIDGET(applet), "away");
|
|
220 }
|
|
221
|
|
222 static void applet_show_about(AppletWidget *widget, gpointer data) {
|
|
223
|
|
224 const gchar *authors[] = {"Mark Spencer <markster@marko.net>",
|
|
225 "Jim Duchek <jimduchek@ou.edu>",
|
|
226 "Rob Flynn <rflynn@blueridge.net>",
|
|
227 "Eric Warmenhoven <warmenhoven@yahoo.com>",
|
|
228 "Syd Logan",
|
|
229 NULL};
|
|
230
|
|
231 GtkWidget *about=gnome_about_new(_("GAIM"),
|
|
232 _(VERSION),
|
|
233 _(""),
|
|
234 authors,
|
|
235 "",
|
|
236 NULL);
|
|
237 gtk_widget_show(about);
|
|
238 }
|
|
239
|
|
240 static GtkAllocation get_applet_pos(gboolean for_blist) {
|
|
241 gint x,y,pad;
|
|
242 GtkRequisition buddy_req, applet_req;
|
|
243 GtkAllocation result;
|
|
244 GNOME_Panel_OrientType orient = applet_widget_get_panel_orient( APPLET_WIDGET(applet) );
|
|
245 pad = 5;
|
|
246
|
|
247 gdk_window_get_position(gtk_widget_get_parent_window(appletframe), &x, &y);
|
|
248 if (for_blist) {
|
|
249 if (general_options & OPT_GEN_SAVED_WINDOWS) {
|
|
250 buddy_req.width = blist_pos.width;
|
|
251 buddy_req.height = blist_pos.height;
|
|
252 } else {
|
|
253 buddy_req = blist->requisition;
|
|
254 }
|
|
255 } else {
|
|
256 buddy_req = mainwindow->requisition;
|
|
257 }
|
|
258 applet_req = appletframe->requisition;
|
|
259
|
|
260 /* FIXME : we need to be smarter here */
|
|
261 switch( orient ){
|
|
262 case ORIENT_UP:
|
|
263 result.x=x;
|
|
264 result.y=y-(buddy_req.height+pad);
|
|
265 break;
|
|
266 case ORIENT_DOWN:
|
|
267 result.x=x;
|
|
268 result.y=y+applet_req.height+pad;
|
|
269 break;
|
|
270 case ORIENT_LEFT:
|
|
271 result.x=x-(buddy_req.width + pad );
|
|
272 result.y=y;
|
|
273 break;
|
|
274 case ORIENT_RIGHT:
|
|
275 result.x=x+applet_req.width+pad;
|
|
276 result.y=y;
|
|
277 break;
|
|
278 }
|
|
279 return result;
|
|
280 }
|
|
281
|
|
282 void createOnlinePopup(){
|
|
283 GtkAllocation al;
|
|
284 if (blist) gtk_widget_show(blist);
|
|
285 al = get_applet_pos(TRUE);
|
|
286 if (general_options & OPT_GEN_NEAR_APPLET)
|
|
287 gtk_widget_set_uposition ( blist, al.x, al.y );
|
|
288 else if (general_options & OPT_GEN_SAVED_WINDOWS)
|
|
289 gtk_widget_set_uposition(blist, blist_pos.x - blist_pos.xoff, blist_pos.y - blist_pos.yoff);
|
|
290 }
|
|
291
|
|
292 void AppletClicked( GtkWidget *sender, GdkEventButton *ev, gpointer data ){
|
|
293 if (!ev || ev->button != 1 || ev->type != GDK_BUTTON_PRESS)
|
|
294 return;
|
|
295
|
|
296 if(applet_buddy_show) {
|
|
297 applet_buddy_show = FALSE;
|
|
298 if (!connections && mainwindow)
|
|
299 gtk_widget_hide(mainwindow);
|
|
300 else
|
|
301 gtk_widget_hide(blist);
|
|
302 } else {
|
|
303 applet_buddy_show = TRUE;
|
|
304 if (!connections)
|
|
305 applet_show_login( APPLET_WIDGET(applet), NULL );
|
|
306 else
|
|
307 createOnlinePopup();
|
|
308 }
|
|
309 }
|
|
310
|
|
311
|
|
312 /***************************************************************
|
|
313 **
|
|
314 ** Initialize GNOME stuff
|
|
315 **
|
|
316 ****************************************************************/
|
|
317
|
|
318 gint init_applet_mgr(int argc, char *argv[]) {
|
|
319 GtkWidget *vbox;
|
|
320
|
|
321 GtkStyle *label_style;
|
|
322 GdkFont *label_font = NULL;
|
|
323
|
|
324 applet_widget_init("GAIM",VERSION,argc,argv,NULL,0,NULL);
|
|
325
|
|
326 /*init imlib for graphics*/
|
|
327 gdk_imlib_init();
|
|
328 gtk_widget_push_visual(gdk_imlib_get_visual());
|
|
329 gtk_widget_push_colormap(gdk_imlib_get_colormap());
|
|
330
|
|
331 applet=applet_widget_new("gaim_applet");
|
|
332 if(!applet) g_error(_("Can't create GAIM applet!"));
|
|
333 gtk_widget_set_events(applet, gtk_widget_get_events(applet) |
|
|
334 GDK_BUTTON_PRESS_MASK);
|
|
335
|
|
336 appletframe = gtk_frame_new(NULL);
|
|
337 #ifdef HAVE_PANEL_PIXEL_SIZE
|
|
338 gtk_widget_set_usize(appletframe, 5, 5);
|
|
339 #else
|
|
340 gtk_widget_set_usize(appletframe, 48, 48);
|
|
341 #endif
|
|
342
|
|
343 /*load offline icon*/
|
|
344 load_applet_icon( GAIM_GNOME_OFFLINE_ICON, 32, 32,
|
|
345 &icon_offline_pm, &icon_offline_bm );
|
|
346
|
|
347 /*load connecting icon*/
|
|
348 load_applet_icon( GAIM_GNOME_CONNECT_ICON, 32, 32,
|
|
349 &icon_connect_pm, &icon_connect_bm );
|
|
350
|
|
351 /*load online icon*/
|
|
352 load_applet_icon( GAIM_GNOME_ONLINE_ICON, 32, 32,
|
|
353 &icon_online_pm, &icon_online_bm );
|
|
354
|
|
355 /*icon_away and icon_msg_pennding need to be implemented*/
|
|
356
|
|
357 icon=gtk_pixmap_new(icon_offline_pm,icon_offline_bm);
|
|
358
|
|
359 vbox = gtk_vbox_new(FALSE,0);
|
|
360
|
|
361 gtk_box_pack_start(GTK_BOX(vbox), icon, FALSE, TRUE, 0);
|
|
362
|
|
363 status_label = gtk_label_new(_("Offline"));
|
|
364
|
|
365 update_applet();
|
|
366
|
|
367 /*set this label's font*/
|
|
368 label_style = gtk_widget_get_style( status_label );
|
|
369
|
|
370 label_font = gdk_font_load( _MSG_FONT_ );
|
|
371
|
|
372
|
|
373 if( label_font != NULL ){
|
|
374 label_style->font = label_font;
|
|
375 gtk_widget_set_style( status_label, label_style );
|
|
376 } else {
|
|
377 debug_printf(_("Font does not exist") );
|
|
378 }
|
|
379
|
|
380 gtk_box_pack_start(GTK_BOX(vbox), status_label, FALSE, TRUE, 0);
|
|
381
|
|
382 gtk_container_add( GTK_CONTAINER(appletframe), vbox );
|
|
383 applet_widget_add(APPLET_WIDGET(applet), appletframe);
|
|
384
|
|
385 gtk_widget_show( status_label );
|
|
386 gtk_widget_show( vbox );
|
|
387 gtk_widget_show( appletframe );
|
|
388
|
|
389 applet_widget_register_stock_callback(APPLET_WIDGET(applet),
|
|
390 "about",
|
|
391 GNOME_STOCK_MENU_ABOUT,
|
|
392 _("About..."),
|
|
393 applet_show_about,
|
|
394 NULL);
|
|
395
|
|
396 gtk_signal_connect( GTK_OBJECT(applet), "button_press_event", GTK_SIGNAL_FUNC( AppletClicked), NULL);
|
|
397
|
|
398 gtk_signal_connect( GTK_OBJECT(applet), "destroy", GTK_SIGNAL_FUNC( do_quit), NULL);
|
|
399
|
|
400 #ifdef HAVE_PANEL_PIXEL_SIZE
|
|
401 gtk_signal_connect(GTK_OBJECT(applet), "change_pixel_size",
|
|
402 GTK_SIGNAL_FUNC(applet_change_pixel_size), NULL);
|
|
403 #endif
|
|
404
|
|
405 gtk_widget_show(icon);
|
|
406 gtk_widget_show(applet);
|
|
407 return 0;
|
|
408 }
|
|
409
|
|
410 void set_user_state( enum gaim_user_states state ){
|
|
411 if (state == signing_on)
|
|
412 connecting++;
|
|
413 else if ((state == away || state == online) && connecting > 0)
|
|
414 connecting--;
|
|
415 update_applet();
|
|
416 }
|
|
417
|
|
418 void applet_set_tooltips(char *msg) {
|
|
419 applet_widget_set_tooltip(APPLET_WIDGET(applet), msg);
|
|
420 }
|
|
421
|
|
422 #endif /*USE_APPLET*/
|