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