comparison src/applet.c @ 2484:a4647b25dbf1

[gaim-migrate @ 2497] yay committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Thu, 11 Oct 2001 21:11:22 +0000
parents 16e8b83b10a2
children cf3218cd9f94
comparison
equal deleted inserted replaced
2483:e73ca8d8d358 2484:a4647b25dbf1
30 #ifdef HAVE_CONFIG_H 30 #ifdef HAVE_CONFIG_H
31 #include <config.h> 31 #include <config.h>
32 #endif 32 #endif
33 #ifdef USE_APPLET 33 #ifdef USE_APPLET
34 #include <string.h> 34 #include <string.h>
35 #include <gdk_imlib.h> 35 #include <gdk-pixbuf/gdk-pixbuf.h>
36 #include <libart_lgpl/art_affine.h>
37 #include <libart_lgpl/art_rgb_affine.h>
38 #include <libart_lgpl/art_rgb_rgba_affine.h>
36 #include "gaim.h" 39 #include "gaim.h"
37 #include "applet.h" 40 #include "applet.h"
41 #include "pixmaps/aimicon.xpm"
38 42
39 static int connecting = 0; 43 static int connecting = 0;
40 44
41 gboolean applet_buddy_show = FALSE; 45 gboolean applet_buddy_show = FALSE;
42 GtkWidget *applet_popup = NULL;
43 46
44 GtkWidget *applet; 47 GtkWidget *applet;
45 GtkWidget *appletframe; 48 static GtkWidget *icon;
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 49
63 static GtkAllocation get_applet_pos(gboolean); 50 static GtkAllocation get_applet_pos(gboolean);
64 gint sizehint = 48; 51 static gint sizehint = 48;
65 52
66 static gboolean load_applet_icon(const char *name, int height, int width, GdkPixmap **pm, GdkBitmap **bm) 53 static GdkPixmap *get_applet_icon(const char *name)
67 { 54 {
68 gboolean result = TRUE; 55 GdkPixmap *cache;
56 GdkGC *gc;
69 char *path; 57 char *path;
70 GdkImlibImage *im; 58 GdkPixbuf *pb;
59 guchar *dst, *p;
60 double affine[6];
61 int r,g,b,i;
62
63 cache = gdk_pixmap_new(applet->window, sizehint, sizehint,
64 gtk_widget_get_visual(applet)->depth);
65 gc = gdk_gc_new(cache);
66 gdk_gc_copy(gc, applet->style->bg_gc[GTK_WIDGET_STATE(applet)]);
71 67
72 path = gnome_pixmap_file(name); 68 path = gnome_pixmap_file(name);
73 69 pb = gdk_pixbuf_new_from_file(path);
74 im = gdk_imlib_load_image(path); 70 g_free(path);
75 71 if (!pb)
76 if ((*pm) != NULL) 72 return NULL;
77 gdk_imlib_free_pixmap((*pm)); 73
78 74 dst = g_new0(guchar, sizehint*sizehint*3);
79 if (im != NULL) { 75 r = applet->style->bg[GTK_WIDGET_STATE(applet)].red>>8;
80 gdk_imlib_render(im, width, height); 76 g = applet->style->bg[GTK_WIDGET_STATE(applet)].green>>8;
81 77 b = applet->style->bg[GTK_WIDGET_STATE(applet)].blue>>8;
82 (*pm) = gdk_imlib_move_image(im); 78 p = dst;
83 (*bm) = gdk_imlib_move_mask(im); 79 for (i = 0; i < 48*48; i++) {
84 80 *p++ = r;
85 } else { 81 *p++ = g;
86 result = FALSE; 82 *p++ = b;
87 debug_printf(_("file not found: %s\n"), path); 83 }
88 } 84
89 85 art_affine_identity(affine);
90 free(path); 86 art_rgb_rgba_affine(dst, 0, 0, sizehint, sizehint, sizehint * 3,
91 return result; 87 gdk_pixbuf_get_pixels(pb),
92 } 88 gdk_pixbuf_get_width(pb), gdk_pixbuf_get_height(pb),
93 89 gdk_pixbuf_get_rowstride(pb), affine, ART_FILTER_NEAREST, NULL);
94 #ifdef HAVE_PANEL_PIXEL_SIZE 90
95 static void applet_change_pixel_size(GtkWidget *w, int size, gpointer data) 91 gdk_pixbuf_unref(pb);
96 { 92 gdk_draw_rgb_image(cache, gc, 0, 0, sizehint, sizehint,
97 sizehint = size; 93 GDK_RGB_DITHER_NORMAL, dst, sizehint * 3);
98 update_pixmaps(); 94 g_free(dst);
99 } 95
100 #endif 96 gdk_gc_unref(gc);
97 return cache;
98 }
101 99
102 static gboolean update_applet() 100 static gboolean update_applet()
103 { 101 {
104 char buf[BUF_LONG]; 102 char buf[BUF_LONG];
105 GSList *c = connections; 103 GSList *c = connections;
104 GdkPixmap *newpix;
106 105
107 if (connecting) { 106 if (connecting) {
108 gtk_pixmap_set(GTK_PIXMAP(icon), icon_connect_pm, icon_connect_bm); 107 newpix = get_applet_icon(GAIM_GNOME_CONNECT_ICON);
109 applet_set_tooltips(_("Attempting to sign on....")); 108 applet_set_tooltips(_("Attempting to sign on...."));
110 } else if (!connections) { 109 } else if (!connections) {
111 gtk_pixmap_set(GTK_PIXMAP(icon), icon_offline_pm, icon_offline_bm); 110 newpix = get_applet_icon(GAIM_GNOME_OFFLINE_ICON);
112 applet_set_tooltips(_("Offline. Click to bring up login box.")); 111 applet_set_tooltips(_("Offline. Click to bring up login box."));
113 } else if (awaymessage) { 112 } else if (awaymessage) {
114 int dsr = 0; 113 int dsr = 0;
115 114
116 if ((away_options & OPT_AWAY_QUEUE) && message_queue) { 115 if ((away_options & OPT_AWAY_QUEUE) && message_queue) {
123 m = m->next; 122 m = m->next;
124 } 123 }
125 } 124 }
126 125
127 if (dsr) { 126 if (dsr) {
128 gtk_pixmap_set(GTK_PIXMAP(icon), icon_msg_pending_pm, icon_msg_pending_bm); 127 newpix = get_applet_icon(GAIM_GNOME_MSG_PENDING_ICON);
129 g_snprintf(buf, sizeof(buf), _("Away: %d pending."), dsr); 128 g_snprintf(buf, sizeof(buf), _("Away: %d pending."), dsr);
130 } else { 129 } else {
131 gtk_pixmap_set(GTK_PIXMAP(icon), icon_away_pm, icon_away_bm); 130 newpix = get_applet_icon(GAIM_GNOME_AWAY_ICON);
132 g_snprintf(buf, sizeof(buf), _("Away.")); 131 g_snprintf(buf, sizeof(buf), _("Away."));
133 } 132 }
134 133
135 applet_set_tooltips(buf); 134 applet_set_tooltips(buf);
136 } else { 135 } else {
137 gtk_pixmap_set(GTK_PIXMAP(icon), icon_online_pm, icon_online_bm); 136 newpix = get_applet_icon(GAIM_GNOME_ONLINE_ICON);
138 g_snprintf(buf, sizeof buf, "Online: "); 137 g_snprintf(buf, sizeof buf, "Online: ");
139 while (c) { 138 while (c) {
140 strcat(buf, ((struct gaim_connection *)c->data)->username); 139 strcat(buf, ((struct gaim_connection *)c->data)->username);
141 c = g_slist_next(c); 140 c = g_slist_next(c);
142 if (c) 141 if (c)
143 strcat(buf, ", "); 142 strcat(buf, ", ");
144 } 143 }
145 applet_set_tooltips(buf); 144 applet_set_tooltips(buf);
146 } 145 }
147 146
147 if (newpix) {
148 gtk_pixmap_set(GTK_PIXMAP(icon), newpix, NULL);
149 gdk_pixmap_unref(newpix);
150 }
151
148 return TRUE; 152 return TRUE;
149 } 153 }
150 154
151 void update_pixmaps() 155 #ifdef HAVE_PANEL_PIXEL_SIZE
152 { 156 static void applet_change_pixel_size(GtkWidget *w, int size, gpointer data)
153 load_applet_icon(GAIM_GNOME_OFFLINE_ICON, (sizehint - 1), (sizehint - 1), 157 {
154 &icon_offline_pm, &icon_offline_bm); 158 sizehint = size;
155 load_applet_icon(GAIM_GNOME_CONNECT_ICON, (sizehint - 1), (sizehint - 1), 159 gtk_widget_set_usize(icon, sizehint, sizehint);
156 &icon_connect_pm, &icon_connect_bm);
157 load_applet_icon(GAIM_GNOME_ONLINE_ICON, (sizehint - 1), (sizehint - 1),
158 &icon_online_pm, &icon_online_bm);
159 load_applet_icon(GAIM_GNOME_AWAY_ICON, (sizehint - 1), (sizehint - 1),
160 &icon_away_pm, &icon_away_bm);
161 load_applet_icon(GAIM_GNOME_MSG_PENDING_ICON, (sizehint - 1), (sizehint - 1),
162 &icon_msg_pending_pm, &icon_msg_pending_bm);
163 update_applet(); 160 update_applet();
164 gtk_widget_set_usize(appletframe, sizehint, sizehint); 161 }
165 } 162 #endif
166
167 163
168 extern GtkWidget *mainwindow; 164 extern GtkWidget *mainwindow;
169 void applet_show_login(AppletWidget *widget, gpointer data) 165 void applet_show_login(AppletWidget *widget, gpointer data)
170 { 166 {
171 show_login(); 167 show_login();
241 GtkRequisition buddy_req, applet_req; 237 GtkRequisition buddy_req, applet_req;
242 GtkAllocation result; 238 GtkAllocation result;
243 GNOME_Panel_OrientType orient = applet_widget_get_panel_orient(APPLET_WIDGET(applet)); 239 GNOME_Panel_OrientType orient = applet_widget_get_panel_orient(APPLET_WIDGET(applet));
244 pad = 5; 240 pad = 5;
245 241
246 gdk_window_get_position(gtk_widget_get_parent_window(appletframe), &x, &y); 242 gdk_window_get_position(gtk_widget_get_parent_window(icon), &x, &y);
247 if (for_blist) { 243 if (for_blist) {
248 if (blist_options & OPT_BLIST_SAVED_WINDOWS) { 244 if (blist_options & OPT_BLIST_SAVED_WINDOWS) {
249 buddy_req.width = blist_pos.width; 245 buddy_req.width = blist_pos.width;
250 buddy_req.height = blist_pos.height; 246 buddy_req.height = blist_pos.height;
251 } else { 247 } else {
252 buddy_req = blist->requisition; 248 buddy_req = blist->requisition;
253 } 249 }
254 } else { 250 } else {
255 buddy_req = mainwindow->requisition; 251 buddy_req = mainwindow->requisition;
256 } 252 }
257 applet_req = appletframe->requisition; 253 applet_req = icon->requisition;
258 254
259 /* FIXME : we need to be smarter here */ 255 /* FIXME : we need to be smarter here */
260 switch (orient) { 256 switch (orient) {
261 case ORIENT_UP: 257 case ORIENT_UP:
262 result.x = x; 258 result.x = x;
318 ** 314 **
319 ****************************************************************/ 315 ****************************************************************/
320 316
321 gint init_applet_mgr(int argc, char *argv[]) 317 gint init_applet_mgr(int argc, char *argv[])
322 { 318 {
323 GtkWidget *vbox; 319 GdkPixmap *pm;
324 320
325 applet_widget_init("GAIM", VERSION, argc, argv, NULL, 0, NULL); 321 applet_widget_init("GAIM", VERSION, argc, argv, NULL, 0, NULL);
326 322
327 /*init imlib for graphics */ 323 /*init imlib for graphics */
328 gdk_imlib_init(); 324 gdk_imlib_init();
331 327
332 applet = applet_widget_new("gaim_applet"); 328 applet = applet_widget_new("gaim_applet");
333 if (!applet) 329 if (!applet)
334 g_error(_("Can't create GAIM applet!")); 330 g_error(_("Can't create GAIM applet!"));
335 gtk_widget_set_events(applet, gtk_widget_get_events(applet) | GDK_BUTTON_PRESS_MASK); 331 gtk_widget_set_events(applet, gtk_widget_get_events(applet) | GDK_BUTTON_PRESS_MASK);
336 332 gtk_widget_realize(applet);
337 appletframe = gtk_frame_new(NULL); 333
338 gtk_frame_set_shadow_type(GTK_FRAME(appletframe), GTK_SHADOW_NONE); 334 pm = get_applet_icon(GAIM_GNOME_OFFLINE_ICON);
339 #ifdef HAVE_PANEL_PIXEL_SIZE 335 if (!pm)
340 gtk_widget_set_usize(appletframe, 5, 5); 336 pm = gdk_pixmap_create_from_xpm_d(applet->window, NULL,
341 #else 337 &applet->style->bg[GTK_WIDGET_STATE(applet)], aimicon_xpm);
342 gtk_widget_set_usize(appletframe, 48, 48); 338 icon = gtk_pixmap_new(pm, NULL);
343 #endif 339 gtk_widget_set_usize(icon, sizehint, sizehint);
344 340 gdk_pixmap_unref(pm);
345 /*load offline icon */ 341 applet_widget_add(APPLET_WIDGET(applet), icon);
346 load_applet_icon(GAIM_GNOME_OFFLINE_ICON, 32, 32, &icon_offline_pm, &icon_offline_bm);
347
348 /*load connecting icon */
349 load_applet_icon(GAIM_GNOME_CONNECT_ICON, 32, 32, &icon_connect_pm, &icon_connect_bm);
350
351 /*load online icon */
352 load_applet_icon(GAIM_GNOME_ONLINE_ICON, 32, 32, &icon_online_pm, &icon_online_bm);
353
354 /*load away icon */
355 load_applet_icon(GAIM_GNOME_AWAY_ICON, 32, 32, &icon_away_pm, &icon_away_bm);
356
357 /*load msg_pending icon */
358 load_applet_icon(GAIM_GNOME_ONLINE_ICON, 32, 32, &icon_msg_pending_pm, &icon_msg_pending_bm);
359
360 icon = gtk_pixmap_new(icon_offline_pm, icon_offline_bm);
361
362 vbox = gtk_vbox_new(FALSE, 0);
363
364 gtk_box_pack_start(GTK_BOX(vbox), icon, FALSE, TRUE, 0);
365
366 update_applet();
367
368 gtk_container_add(GTK_CONTAINER(appletframe), vbox);
369 applet_widget_add(APPLET_WIDGET(applet), appletframe);
370
371 gtk_widget_show(vbox);
372 gtk_widget_show(appletframe);
373 342
374 applet_widget_register_stock_callback(APPLET_WIDGET(applet), 343 applet_widget_register_stock_callback(APPLET_WIDGET(applet),
375 "about", 344 "about",
376 GNOME_STOCK_MENU_ABOUT, 345 GNOME_STOCK_MENU_ABOUT,
377 _("About..."), (AppletCallbackFunc)show_about, NULL); 346 _("About..."), (AppletCallbackFunc)show_about, NULL);