Mercurial > pidgin
annotate src/applet.c @ 2136:73253b36c3cb
[gaim-migrate @ 2146]
i wonder if this will help anything.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 08 Aug 2001 19:13:01 +0000 |
parents | b66aca8e8dce |
children | 64b4c69c1c5e |
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 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
31 #include <config.h> |
1261 | 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 | |
47 GtkWidget *icon; | |
48 GdkPixmap *icon_offline_pm=NULL; | |
49 GdkPixmap *icon_offline_bm=NULL; | |
50 | |
51 GdkPixmap *icon_online_pm=NULL; | |
52 GdkPixmap *icon_online_bm=NULL; | |
53 | |
54 GdkPixmap *icon_connect_pm=NULL; | |
55 GdkPixmap *icon_connect_bm=NULL; | |
56 | |
57 GdkPixmap *icon_msg_pending_pm=NULL; | |
58 GdkPixmap *icon_msg_pending_bm=NULL; | |
59 | |
60 GdkPixmap *icon_away_pm=NULL; | |
61 GdkPixmap *icon_away_bm=NULL; | |
62 | |
63 static GtkAllocation get_applet_pos(gboolean); | |
64 gint sizehint=48; | |
65 | |
66 static gboolean load_applet_icon(const char *name, int height, int width, | |
67 GdkPixmap **pm, GdkBitmap **bm) | |
68 { | |
69 gboolean result = TRUE; | |
70 char *path; | |
71 GdkImlibImage *im; | |
72 | |
73 path = gnome_pixmap_file(name); | |
74 | |
75 im=gdk_imlib_load_image( path ); | |
76 | |
77 if ((*pm)!=NULL) | |
78 gdk_imlib_free_pixmap((*pm)); | |
79 | |
80 if( im!= NULL ){ | |
81 gdk_imlib_render(im,width,height); | |
82 | |
83 (*pm) = gdk_imlib_move_image(im); | |
84 (*bm) = gdk_imlib_move_mask(im); | |
85 | |
86 } else { | |
87 result = FALSE; | |
88 debug_printf(_("file not found: %s\n"),path); | |
89 } | |
90 | |
91 free(path); | |
92 return result; | |
93 } | |
94 | |
95 #ifdef HAVE_PANEL_PIXEL_SIZE | |
96 static void applet_change_pixel_size(GtkWidget *w, int size, gpointer data) | |
97 { | |
98 sizehint = size; | |
99 update_pixmaps(); | |
100 } | |
101 #endif | |
102 | |
103 static gboolean update_applet(){ | |
104 char buf[BUF_LONG]; | |
105 GSList *c = connections; | |
106 | |
107 if (connecting) { | |
108 gtk_pixmap_set( GTK_PIXMAP(icon), | |
109 icon_connect_pm, | |
110 icon_connect_bm ); | |
111 applet_set_tooltips(_("Attempting to sign on....")); | |
112 } else if (!connections) { | |
113 gtk_pixmap_set( GTK_PIXMAP(icon), | |
114 icon_offline_pm, | |
115 icon_offline_bm ); | |
1815
f15d449b3167
[gaim-migrate @ 1825]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1689
diff
changeset
|
116 applet_set_tooltips(_("Offline. Click to bring up login box.")); |
1281
83d8b2078f4c
[gaim-migrate @ 1291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1280
diff
changeset
|
117 } else if (!awaymessage) { |
1261 | 118 gtk_pixmap_set( GTK_PIXMAP(icon), |
119 icon_online_pm, | |
120 icon_online_bm ); | |
121 g_snprintf(buf, sizeof buf, "Online: "); | |
122 while (c) { | |
123 strcat(buf, ((struct gaim_connection *)c->data)->username); | |
124 c = g_slist_next(c); | |
125 if (c) strcat(buf, ", "); | |
126 } | |
127 applet_set_tooltips(buf); | |
128 } else { | |
129 gtk_pixmap_set( GTK_PIXMAP(icon), | |
130 icon_online_pm, | |
131 icon_online_bm ); | |
132 } | |
133 | |
134 return TRUE; | |
135 } | |
136 | |
137 void update_pixmaps() { | |
1689
09017c023fcd
[gaim-migrate @ 1699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1591
diff
changeset
|
138 load_applet_icon( GAIM_GNOME_OFFLINE_ICON, (sizehint-1), (sizehint-1), |
1261 | 139 &icon_offline_pm, &icon_offline_bm ); |
1689
09017c023fcd
[gaim-migrate @ 1699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1591
diff
changeset
|
140 load_applet_icon( GAIM_GNOME_CONNECT_ICON, (sizehint-1), (sizehint-1), |
1261 | 141 &icon_connect_pm, &icon_connect_bm ); |
1689
09017c023fcd
[gaim-migrate @ 1699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1591
diff
changeset
|
142 load_applet_icon( GAIM_GNOME_ONLINE_ICON, (sizehint-1), (sizehint-1), |
1261 | 143 &icon_online_pm, &icon_online_bm ); |
144 update_applet(); | |
145 gtk_widget_set_usize(appletframe, sizehint, sizehint); | |
146 } | |
147 | |
148 | |
149 extern GtkWidget *mainwindow; | |
150 void applet_show_login(AppletWidget *widget, gpointer data) { | |
151 show_login(); | |
152 if (general_options & OPT_GEN_NEAR_APPLET) { | |
153 GtkAllocation a = get_applet_pos(FALSE); | |
154 gtk_widget_set_uposition(mainwindow, a.x, a.y); | |
155 } | |
156 } | |
157 | |
158 void applet_do_signon(AppletWidget *widget, gpointer data) { | |
159 applet_show_login(NULL, 0); | |
160 } | |
161 | |
162 void insert_applet_away() { | |
163 GSList *awy = away_messages; | |
164 struct away_message *a; | |
165 char *awayname; | |
166 | |
167 applet_widget_register_callback_dir(APPLET_WIDGET(applet), | |
168 "away/", | |
169 _("Away")); | |
170 applet_widget_register_callback(APPLET_WIDGET(applet), | |
171 "away/new", | |
172 _("New Away Message"), | |
173 (AppletCallbackFunc)create_away_mess, | |
174 NULL); | |
175 | |
176 while(awy) { | |
177 a = (struct away_message *)awy->data; | |
178 | |
179 awayname = g_malloc(sizeof *awayname * (6 + strlen(a->name))); | |
180 awayname[0] = '\0'; | |
181 strcat(awayname, "away/"); | |
182 strcat(awayname, a->name); | |
183 applet_widget_register_callback(APPLET_WIDGET(applet), | |
184 awayname, | |
185 a->name, | |
186 (AppletCallbackFunc)do_away_message, | |
187 a); | |
188 | |
189 awy = g_slist_next(awy); | |
1421
13a34fb4abb0
[gaim-migrate @ 1431]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1420
diff
changeset
|
190 g_free(awayname); |
1261 | 191 } |
192 } | |
193 | |
194 void remove_applet_away() { | |
195 GSList *awy = away_messages; | |
196 struct away_message *a; | |
197 char *awayname; | |
198 | |
1591
5c74d8b6cb57
[gaim-migrate @ 1601]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
199 if (!applet) |
5c74d8b6cb57
[gaim-migrate @ 1601]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
200 return; |
5c74d8b6cb57
[gaim-migrate @ 1601]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
201 |
1261 | 202 applet_widget_unregister_callback(APPLET_WIDGET(applet), "away/new"); |
203 | |
204 while (awy) { | |
205 a = (struct away_message *)awy->data; | |
206 | |
207 awayname = g_malloc(sizeof *awayname * (6 + strlen(a->name))); | |
208 awayname[0] = '\0'; | |
209 strcat(awayname, "away/"); | |
210 strcat(awayname, a->name); | |
211 applet_widget_unregister_callback(APPLET_WIDGET(applet), awayname); | |
212 | |
213 awy = g_slist_next(awy); | |
214 free(awayname); | |
215 } | |
216 applet_widget_unregister_callback_dir(APPLET_WIDGET(applet), "away/"); | |
217 applet_widget_unregister_callback(APPLET_WIDGET(applet), "away"); | |
218 } | |
219 | |
220 static GtkAllocation get_applet_pos(gboolean for_blist) { | |
221 gint x,y,pad; | |
222 GtkRequisition buddy_req, applet_req; | |
223 GtkAllocation result; | |
224 GNOME_Panel_OrientType orient = applet_widget_get_panel_orient( APPLET_WIDGET(applet) ); | |
225 pad = 5; | |
226 | |
1420
9be6790092dc
[gaim-migrate @ 1430]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1413
diff
changeset
|
227 gdk_window_get_position(gtk_widget_get_parent_window(appletframe), &x, &y); |
1261 | 228 if (for_blist) { |
229 if (general_options & OPT_GEN_SAVED_WINDOWS) { | |
230 buddy_req.width = blist_pos.width; | |
231 buddy_req.height = blist_pos.height; | |
232 } else { | |
233 buddy_req = blist->requisition; | |
234 } | |
235 } else { | |
236 buddy_req = mainwindow->requisition; | |
237 } | |
238 applet_req = appletframe->requisition; | |
239 | |
240 /* FIXME : we need to be smarter here */ | |
241 switch( orient ){ | |
242 case ORIENT_UP: | |
243 result.x=x; | |
244 result.y=y-(buddy_req.height+pad); | |
245 break; | |
246 case ORIENT_DOWN: | |
247 result.x=x; | |
248 result.y=y+applet_req.height+pad; | |
249 break; | |
250 case ORIENT_LEFT: | |
251 result.x=x-(buddy_req.width + pad ); | |
252 result.y=y; | |
253 break; | |
254 case ORIENT_RIGHT: | |
255 result.x=x+applet_req.width+pad; | |
256 result.y=y; | |
257 break; | |
258 } | |
259 return result; | |
260 } | |
261 | |
262 void createOnlinePopup(){ | |
263 GtkAllocation al; | |
264 if (blist) gtk_widget_show(blist); | |
265 al = get_applet_pos(TRUE); | |
266 if (general_options & OPT_GEN_NEAR_APPLET) | |
267 gtk_widget_set_uposition ( blist, al.x, al.y ); | |
268 else if (general_options & OPT_GEN_SAVED_WINDOWS) | |
1420
9be6790092dc
[gaim-migrate @ 1430]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1413
diff
changeset
|
269 gtk_widget_set_uposition(blist, blist_pos.x - blist_pos.xoff, blist_pos.y - blist_pos.yoff); |
1261 | 270 } |
271 | |
272 void AppletClicked( GtkWidget *sender, GdkEventButton *ev, gpointer data ){ | |
273 if (!ev || ev->button != 1 || ev->type != GDK_BUTTON_PRESS) | |
274 return; | |
275 | |
276 if(applet_buddy_show) { | |
277 applet_buddy_show = FALSE; | |
278 if (!connections && mainwindow) | |
279 gtk_widget_hide(mainwindow); | |
280 else | |
281 gtk_widget_hide(blist); | |
282 } else { | |
283 applet_buddy_show = TRUE; | |
284 if (!connections) | |
285 applet_show_login( APPLET_WIDGET(applet), NULL ); | |
286 else | |
287 createOnlinePopup(); | |
288 } | |
289 } | |
290 | |
291 | |
292 /*************************************************************** | |
293 ** | |
294 ** Initialize GNOME stuff | |
295 ** | |
296 ****************************************************************/ | |
297 | |
298 gint init_applet_mgr(int argc, char *argv[]) { | |
299 GtkWidget *vbox; | |
300 | |
301 applet_widget_init("GAIM",VERSION,argc,argv,NULL,0,NULL); | |
302 | |
303 /*init imlib for graphics*/ | |
304 gdk_imlib_init(); | |
305 gtk_widget_push_visual(gdk_imlib_get_visual()); | |
306 gtk_widget_push_colormap(gdk_imlib_get_colormap()); | |
307 | |
308 applet=applet_widget_new("gaim_applet"); | |
309 if(!applet) g_error(_("Can't create GAIM applet!")); | |
310 gtk_widget_set_events(applet, gtk_widget_get_events(applet) | | |
311 GDK_BUTTON_PRESS_MASK); | |
312 | |
313 appletframe = gtk_frame_new(NULL); | |
1689
09017c023fcd
[gaim-migrate @ 1699]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1591
diff
changeset
|
314 gtk_frame_set_shadow_type(GTK_FRAME(appletframe), GTK_SHADOW_NONE); |
1261 | 315 #ifdef HAVE_PANEL_PIXEL_SIZE |
316 gtk_widget_set_usize(appletframe, 5, 5); | |
317 #else | |
318 gtk_widget_set_usize(appletframe, 48, 48); | |
319 #endif | |
320 | |
321 /*load offline icon*/ | |
322 load_applet_icon( GAIM_GNOME_OFFLINE_ICON, 32, 32, | |
323 &icon_offline_pm, &icon_offline_bm ); | |
324 | |
325 /*load connecting icon*/ | |
326 load_applet_icon( GAIM_GNOME_CONNECT_ICON, 32, 32, | |
327 &icon_connect_pm, &icon_connect_bm ); | |
328 | |
329 /*load online icon*/ | |
330 load_applet_icon( GAIM_GNOME_ONLINE_ICON, 32, 32, | |
331 &icon_online_pm, &icon_online_bm ); | |
332 | |
333 /*icon_away and icon_msg_pennding need to be implemented*/ | |
334 | |
335 icon=gtk_pixmap_new(icon_offline_pm,icon_offline_bm); | |
336 | |
337 vbox = gtk_vbox_new(FALSE,0); | |
338 | |
339 gtk_box_pack_start(GTK_BOX(vbox), icon, FALSE, TRUE, 0); | |
340 | |
341 update_applet(); | |
342 | |
343 gtk_container_add( GTK_CONTAINER(appletframe), vbox ); | |
344 applet_widget_add(APPLET_WIDGET(applet), appletframe); | |
345 | |
346 gtk_widget_show( vbox ); | |
347 gtk_widget_show( appletframe ); | |
348 | |
349 applet_widget_register_stock_callback(APPLET_WIDGET(applet), | |
350 "about", | |
351 GNOME_STOCK_MENU_ABOUT, | |
352 _("About..."), | |
1456
6650776468b3
[gaim-migrate @ 1466]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1421
diff
changeset
|
353 (AppletCallbackFunc)show_about, |
1261 | 354 NULL); |
355 | |
356 gtk_signal_connect( GTK_OBJECT(applet), "button_press_event", GTK_SIGNAL_FUNC( AppletClicked), NULL); | |
357 | |
358 gtk_signal_connect( GTK_OBJECT(applet), "destroy", GTK_SIGNAL_FUNC( do_quit), NULL); | |
359 | |
360 #ifdef HAVE_PANEL_PIXEL_SIZE | |
361 gtk_signal_connect(GTK_OBJECT(applet), "change_pixel_size", | |
362 GTK_SIGNAL_FUNC(applet_change_pixel_size), NULL); | |
363 #endif | |
364 | |
365 gtk_widget_show(icon); | |
366 gtk_widget_show(applet); | |
367 return 0; | |
368 } | |
369 | |
370 void set_user_state( enum gaim_user_states state ){ | |
371 if (state == signing_on) | |
372 connecting++; | |
373 else if ((state == away || state == online) && connecting > 0) | |
374 connecting--; | |
375 update_applet(); | |
376 } | |
377 | |
378 void applet_set_tooltips(char *msg) { | |
1591
5c74d8b6cb57
[gaim-migrate @ 1601]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
379 if (!applet) |
5c74d8b6cb57
[gaim-migrate @ 1601]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
380 return; |
1261 | 381 applet_widget_set_tooltip(APPLET_WIDGET(applet), msg); |
382 } | |
383 | |
384 #endif /*USE_APPLET*/ |