Mercurial > pidgin
annotate src/applet.c @ 1642:b29f70d97062
[gaim-migrate @ 1652]
jabber user registration
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Sat, 24 Mar 2001 06:45:48 +0000 |
parents | 5c74d8b6cb57 |
children | 09017c023fcd |
rev | line source |
---|---|
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.")); | |
1281
83d8b2078f4c
[gaim-migrate @ 1291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1280
diff
changeset
|
120 } else if (!awaymessage) { |
1261 | 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); | |
1421
13a34fb4abb0
[gaim-migrate @ 1431]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1420
diff
changeset
|
195 g_free(awayname); |
1261 | 196 } |
197 } | |
198 | |
199 void remove_applet_away() { | |
200 GSList *awy = away_messages; | |
201 struct away_message *a; | |
202 char *awayname; | |
203 | |
1591
5c74d8b6cb57
[gaim-migrate @ 1601]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
204 if (!applet) |
5c74d8b6cb57
[gaim-migrate @ 1601]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
205 return; |
5c74d8b6cb57
[gaim-migrate @ 1601]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
206 |
1261 | 207 applet_widget_unregister_callback(APPLET_WIDGET(applet), "away/new"); |
208 | |
209 while (awy) { | |
210 a = (struct away_message *)awy->data; | |
211 | |
212 awayname = g_malloc(sizeof *awayname * (6 + strlen(a->name))); | |
213 awayname[0] = '\0'; | |
214 strcat(awayname, "away/"); | |
215 strcat(awayname, a->name); | |
216 applet_widget_unregister_callback(APPLET_WIDGET(applet), awayname); | |
217 | |
218 awy = g_slist_next(awy); | |
219 free(awayname); | |
220 } | |
221 applet_widget_unregister_callback_dir(APPLET_WIDGET(applet), "away/"); | |
222 applet_widget_unregister_callback(APPLET_WIDGET(applet), "away"); | |
223 } | |
224 | |
225 static GtkAllocation get_applet_pos(gboolean for_blist) { | |
226 gint x,y,pad; | |
227 GtkRequisition buddy_req, applet_req; | |
228 GtkAllocation result; | |
229 GNOME_Panel_OrientType orient = applet_widget_get_panel_orient( APPLET_WIDGET(applet) ); | |
230 pad = 5; | |
231 | |
1420
9be6790092dc
[gaim-migrate @ 1430]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1413
diff
changeset
|
232 gdk_window_get_position(gtk_widget_get_parent_window(appletframe), &x, &y); |
1261 | 233 if (for_blist) { |
234 if (general_options & OPT_GEN_SAVED_WINDOWS) { | |
235 buddy_req.width = blist_pos.width; | |
236 buddy_req.height = blist_pos.height; | |
237 } else { | |
238 buddy_req = blist->requisition; | |
239 } | |
240 } else { | |
241 buddy_req = mainwindow->requisition; | |
242 } | |
243 applet_req = appletframe->requisition; | |
244 | |
245 /* FIXME : we need to be smarter here */ | |
246 switch( orient ){ | |
247 case ORIENT_UP: | |
248 result.x=x; | |
249 result.y=y-(buddy_req.height+pad); | |
250 break; | |
251 case ORIENT_DOWN: | |
252 result.x=x; | |
253 result.y=y+applet_req.height+pad; | |
254 break; | |
255 case ORIENT_LEFT: | |
256 result.x=x-(buddy_req.width + pad ); | |
257 result.y=y; | |
258 break; | |
259 case ORIENT_RIGHT: | |
260 result.x=x+applet_req.width+pad; | |
261 result.y=y; | |
262 break; | |
263 } | |
264 return result; | |
265 } | |
266 | |
267 void createOnlinePopup(){ | |
268 GtkAllocation al; | |
269 if (blist) gtk_widget_show(blist); | |
270 al = get_applet_pos(TRUE); | |
271 if (general_options & OPT_GEN_NEAR_APPLET) | |
272 gtk_widget_set_uposition ( blist, al.x, al.y ); | |
273 else if (general_options & OPT_GEN_SAVED_WINDOWS) | |
1420
9be6790092dc
[gaim-migrate @ 1430]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1413
diff
changeset
|
274 gtk_widget_set_uposition(blist, blist_pos.x - blist_pos.xoff, blist_pos.y - blist_pos.yoff); |
1261 | 275 } |
276 | |
277 void AppletClicked( GtkWidget *sender, GdkEventButton *ev, gpointer data ){ | |
278 if (!ev || ev->button != 1 || ev->type != GDK_BUTTON_PRESS) | |
279 return; | |
280 | |
281 if(applet_buddy_show) { | |
282 applet_buddy_show = FALSE; | |
283 if (!connections && mainwindow) | |
284 gtk_widget_hide(mainwindow); | |
285 else | |
286 gtk_widget_hide(blist); | |
287 } else { | |
288 applet_buddy_show = TRUE; | |
289 if (!connections) | |
290 applet_show_login( APPLET_WIDGET(applet), NULL ); | |
291 else | |
292 createOnlinePopup(); | |
293 } | |
294 } | |
295 | |
296 | |
297 /*************************************************************** | |
298 ** | |
299 ** Initialize GNOME stuff | |
300 ** | |
301 ****************************************************************/ | |
302 | |
303 gint init_applet_mgr(int argc, char *argv[]) { | |
304 GtkWidget *vbox; | |
305 | |
306 GtkStyle *label_style; | |
307 GdkFont *label_font = NULL; | |
308 | |
309 applet_widget_init("GAIM",VERSION,argc,argv,NULL,0,NULL); | |
310 | |
311 /*init imlib for graphics*/ | |
312 gdk_imlib_init(); | |
313 gtk_widget_push_visual(gdk_imlib_get_visual()); | |
314 gtk_widget_push_colormap(gdk_imlib_get_colormap()); | |
315 | |
316 applet=applet_widget_new("gaim_applet"); | |
317 if(!applet) g_error(_("Can't create GAIM applet!")); | |
318 gtk_widget_set_events(applet, gtk_widget_get_events(applet) | | |
319 GDK_BUTTON_PRESS_MASK); | |
320 | |
321 appletframe = gtk_frame_new(NULL); | |
322 #ifdef HAVE_PANEL_PIXEL_SIZE | |
323 gtk_widget_set_usize(appletframe, 5, 5); | |
324 #else | |
325 gtk_widget_set_usize(appletframe, 48, 48); | |
326 #endif | |
327 | |
328 /*load offline icon*/ | |
329 load_applet_icon( GAIM_GNOME_OFFLINE_ICON, 32, 32, | |
330 &icon_offline_pm, &icon_offline_bm ); | |
331 | |
332 /*load connecting icon*/ | |
333 load_applet_icon( GAIM_GNOME_CONNECT_ICON, 32, 32, | |
334 &icon_connect_pm, &icon_connect_bm ); | |
335 | |
336 /*load online icon*/ | |
337 load_applet_icon( GAIM_GNOME_ONLINE_ICON, 32, 32, | |
338 &icon_online_pm, &icon_online_bm ); | |
339 | |
340 /*icon_away and icon_msg_pennding need to be implemented*/ | |
341 | |
342 icon=gtk_pixmap_new(icon_offline_pm,icon_offline_bm); | |
343 | |
344 vbox = gtk_vbox_new(FALSE,0); | |
345 | |
346 gtk_box_pack_start(GTK_BOX(vbox), icon, FALSE, TRUE, 0); | |
347 | |
348 status_label = gtk_label_new(_("Offline")); | |
349 | |
350 update_applet(); | |
351 | |
352 /*set this label's font*/ | |
353 label_style = gtk_widget_get_style( status_label ); | |
354 | |
355 label_font = gdk_font_load( _MSG_FONT_ ); | |
356 | |
357 | |
358 if( label_font != NULL ){ | |
359 label_style->font = label_font; | |
360 gtk_widget_set_style( status_label, label_style ); | |
361 } else { | |
362 debug_printf(_("Font does not exist") ); | |
363 } | |
364 | |
365 gtk_box_pack_start(GTK_BOX(vbox), status_label, FALSE, TRUE, 0); | |
366 | |
367 gtk_container_add( GTK_CONTAINER(appletframe), vbox ); | |
368 applet_widget_add(APPLET_WIDGET(applet), appletframe); | |
369 | |
370 gtk_widget_show( status_label ); | |
371 gtk_widget_show( vbox ); | |
372 gtk_widget_show( appletframe ); | |
373 | |
374 applet_widget_register_stock_callback(APPLET_WIDGET(applet), | |
375 "about", | |
376 GNOME_STOCK_MENU_ABOUT, | |
377 _("About..."), | |
1456
6650776468b3
[gaim-migrate @ 1466]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1421
diff
changeset
|
378 (AppletCallbackFunc)show_about, |
1261 | 379 NULL); |
380 | |
381 gtk_signal_connect( GTK_OBJECT(applet), "button_press_event", GTK_SIGNAL_FUNC( AppletClicked), NULL); | |
382 | |
383 gtk_signal_connect( GTK_OBJECT(applet), "destroy", GTK_SIGNAL_FUNC( do_quit), NULL); | |
384 | |
385 #ifdef HAVE_PANEL_PIXEL_SIZE | |
386 gtk_signal_connect(GTK_OBJECT(applet), "change_pixel_size", | |
387 GTK_SIGNAL_FUNC(applet_change_pixel_size), NULL); | |
388 #endif | |
389 | |
390 gtk_widget_show(icon); | |
391 gtk_widget_show(applet); | |
392 return 0; | |
393 } | |
394 | |
395 void set_user_state( enum gaim_user_states state ){ | |
396 if (state == signing_on) | |
397 connecting++; | |
398 else if ((state == away || state == online) && connecting > 0) | |
399 connecting--; | |
400 update_applet(); | |
401 } | |
402 | |
403 void applet_set_tooltips(char *msg) { | |
1591
5c74d8b6cb57
[gaim-migrate @ 1601]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
404 if (!applet) |
5c74d8b6cb57
[gaim-migrate @ 1601]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
405 return; |
1261 | 406 applet_widget_set_tooltip(APPLET_WIDGET(applet), msg); |
407 } | |
408 | |
409 #endif /*USE_APPLET*/ |