Mercurial > pidgin.yaz
annotate src/applet.c @ 2543:830a83209475
[gaim-migrate @ 2556]
whoops
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Thu, 18 Oct 2001 22:36:47 +0000 |
parents | 2bc6ee172103 |
children | 7c64b3ad0c3d |
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> | |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
35 #include <gdk-pixbuf/gdk-pixbuf.h> |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
36 #include <libart_lgpl/art_affine.h> |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
37 #include <libart_lgpl/art_rgb_affine.h> |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
38 #include <libart_lgpl/art_rgb_rgba_affine.h> |
1261 | 39 #include "gaim.h" |
40 #include "applet.h" | |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
41 #include "pixmaps/aimicon.xpm" |
1261 | 42 |
43 static int connecting = 0; | |
44 | |
45 gboolean applet_buddy_show = FALSE; | |
46 | |
47 GtkWidget *applet; | |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
48 static GtkWidget *icon; |
1261 | 49 |
50 static GtkAllocation get_applet_pos(gboolean); | |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
51 static gint sizehint = 48; |
1261 | 52 |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
53 static GdkPixmap *get_applet_icon(const char *name) |
1261 | 54 { |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
55 GdkPixmap *cache; |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
56 GdkGC *gc; |
1261 | 57 char *path; |
2486
cf3218cd9f94
[gaim-migrate @ 2499]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2484
diff
changeset
|
58 GdkPixbuf *pb, *scale; |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
59 guchar *dst, *p; |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
60 double affine[6]; |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
61 int r,g,b,i; |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
62 |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
63 cache = gdk_pixmap_new(applet->window, sizehint, sizehint, |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
64 gtk_widget_get_visual(applet)->depth); |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
65 gc = gdk_gc_new(cache); |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
66 gdk_gc_copy(gc, applet->style->bg_gc[GTK_WIDGET_STATE(applet)]); |
1261 | 67 |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
68 path = gnome_pixmap_file(name); |
2486
cf3218cd9f94
[gaim-migrate @ 2499]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2484
diff
changeset
|
69 scale = gdk_pixbuf_new_from_file(path); |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
70 g_free(path); |
2486
cf3218cd9f94
[gaim-migrate @ 2499]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2484
diff
changeset
|
71 if (!scale) |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
72 return NULL; |
2486
cf3218cd9f94
[gaim-migrate @ 2499]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2484
diff
changeset
|
73 pb = gdk_pixbuf_scale_simple(scale, sizehint, sizehint, GDK_INTERP_HYPER); |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
74 |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
75 dst = g_new0(guchar, sizehint*sizehint*3); |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
76 r = applet->style->bg[GTK_WIDGET_STATE(applet)].red>>8; |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
77 g = applet->style->bg[GTK_WIDGET_STATE(applet)].green>>8; |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
78 b = applet->style->bg[GTK_WIDGET_STATE(applet)].blue>>8; |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
79 p = dst; |
2486
cf3218cd9f94
[gaim-migrate @ 2499]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2484
diff
changeset
|
80 for (i = 0; i < sizehint * sizehint; i++) { |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
81 *p++ = r; |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
82 *p++ = g; |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
83 *p++ = b; |
1261 | 84 } |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
85 |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
86 art_affine_identity(affine); |
2497
be88e02789e0
[gaim-migrate @ 2510]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2492
diff
changeset
|
87 if (gdk_pixbuf_get_has_alpha(pb)) |
be88e02789e0
[gaim-migrate @ 2510]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2492
diff
changeset
|
88 art_rgb_rgba_affine(dst, 0, 0, sizehint, sizehint, sizehint * 3, |
be88e02789e0
[gaim-migrate @ 2510]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2492
diff
changeset
|
89 gdk_pixbuf_get_pixels(pb), gdk_pixbuf_get_width(pb), |
be88e02789e0
[gaim-migrate @ 2510]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2492
diff
changeset
|
90 gdk_pixbuf_get_height(pb), gdk_pixbuf_get_rowstride(pb), |
be88e02789e0
[gaim-migrate @ 2510]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2492
diff
changeset
|
91 affine, ART_FILTER_NEAREST, NULL); |
be88e02789e0
[gaim-migrate @ 2510]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2492
diff
changeset
|
92 else |
be88e02789e0
[gaim-migrate @ 2510]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2492
diff
changeset
|
93 art_rgb_affine(dst, 0, 0, sizehint, sizehint, sizehint * 3, |
be88e02789e0
[gaim-migrate @ 2510]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2492
diff
changeset
|
94 gdk_pixbuf_get_pixels(pb), gdk_pixbuf_get_width(pb), |
be88e02789e0
[gaim-migrate @ 2510]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2492
diff
changeset
|
95 gdk_pixbuf_get_height(pb), gdk_pixbuf_get_rowstride(pb), |
be88e02789e0
[gaim-migrate @ 2510]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2492
diff
changeset
|
96 affine, ART_FILTER_NEAREST, NULL); |
1261 | 97 |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
98 gdk_pixbuf_unref(pb); |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
99 gdk_draw_rgb_image(cache, gc, 0, 0, sizehint, sizehint, |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
100 GDK_RGB_DITHER_NORMAL, dst, sizehint * 3); |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
101 g_free(dst); |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
102 |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
103 gdk_gc_unref(gc); |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
104 return cache; |
1261 | 105 } |
106 | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
107 static gboolean update_applet() |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
108 { |
1261 | 109 char buf[BUF_LONG]; |
110 GSList *c = connections; | |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
111 GdkPixmap *newpix; |
1261 | 112 |
113 if (connecting) { | |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
114 newpix = get_applet_icon(GAIM_GNOME_CONNECT_ICON); |
1261 | 115 applet_set_tooltips(_("Attempting to sign on....")); |
116 } else if (!connections) { | |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
117 newpix = get_applet_icon(GAIM_GNOME_OFFLINE_ICON); |
1815
f15d449b3167
[gaim-migrate @ 1825]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1689
diff
changeset
|
118 applet_set_tooltips(_("Offline. Click to bring up login box.")); |
2468
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
119 } else if (awaymessage) { |
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
120 int dsr = 0; |
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
121 |
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
122 if ((away_options & OPT_AWAY_QUEUE) && message_queue) { |
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
123 GSList *m = message_queue; |
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
124 while (m) { |
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
125 struct queued_message *qm = m->data; |
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
126 if (qm->flags & WFLAG_RECV) |
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
127 dsr++; |
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
128 m = m->next; |
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
129 } |
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
130 } |
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
131 |
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
132 if (dsr) { |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
133 newpix = get_applet_icon(GAIM_GNOME_MSG_PENDING_ICON); |
2468
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
134 g_snprintf(buf, sizeof(buf), _("Away: %d pending."), dsr); |
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
135 } else { |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
136 newpix = get_applet_icon(GAIM_GNOME_AWAY_ICON); |
2468
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
137 g_snprintf(buf, sizeof(buf), _("Away.")); |
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
138 } |
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
139 |
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
140 applet_set_tooltips(buf); |
16e8b83b10a2
[gaim-migrate @ 2481]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2372
diff
changeset
|
141 } else { |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
142 newpix = get_applet_icon(GAIM_GNOME_ONLINE_ICON); |
1261 | 143 g_snprintf(buf, sizeof buf, "Online: "); |
144 while (c) { | |
145 strcat(buf, ((struct gaim_connection *)c->data)->username); | |
146 c = g_slist_next(c); | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
147 if (c) |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
148 strcat(buf, ", "); |
1261 | 149 } |
150 applet_set_tooltips(buf); | |
151 } | |
152 | |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
153 if (newpix) { |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
154 gtk_pixmap_set(GTK_PIXMAP(icon), newpix, NULL); |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
155 gdk_pixmap_unref(newpix); |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
156 } |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
157 |
1261 | 158 return TRUE; |
159 } | |
160 | |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
161 #ifdef HAVE_PANEL_PIXEL_SIZE |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
162 static void applet_change_pixel_size(GtkWidget *w, int size, gpointer data) |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
163 { |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
164 sizehint = size; |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
165 gtk_widget_set_usize(icon, sizehint, sizehint); |
1261 | 166 update_applet(); |
167 } | |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
168 #endif |
1261 | 169 |
170 extern GtkWidget *mainwindow; | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
171 void applet_show_login(AppletWidget *widget, gpointer data) |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
172 { |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
173 show_login(); |
2314
64b4c69c1c5e
[gaim-migrate @ 2324]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
174 if (blist_options & OPT_BLIST_NEAR_APPLET) { |
1261 | 175 GtkAllocation a = get_applet_pos(FALSE); |
176 gtk_widget_set_uposition(mainwindow, a.x, a.y); | |
177 } | |
178 } | |
179 | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
180 void applet_do_signon(AppletWidget *widget, gpointer data) |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
181 { |
1261 | 182 applet_show_login(NULL, 0); |
183 } | |
184 | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
185 void insert_applet_away() |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
186 { |
1261 | 187 GSList *awy = away_messages; |
188 struct away_message *a; | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
189 char *awayname; |
1261 | 190 |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
191 applet_widget_register_callback_dir(APPLET_WIDGET(applet), "away/", _("Away")); |
1261 | 192 applet_widget_register_callback(APPLET_WIDGET(applet), |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
193 "away/new", |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
194 _("New Away Message"), |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
195 (AppletCallbackFunc)create_away_mess, NULL); |
1261 | 196 |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
197 while (awy) { |
1261 | 198 a = (struct away_message *)awy->data; |
199 | |
200 awayname = g_malloc(sizeof *awayname * (6 + strlen(a->name))); | |
201 awayname[0] = '\0'; | |
202 strcat(awayname, "away/"); | |
203 strcat(awayname, a->name); | |
204 applet_widget_register_callback(APPLET_WIDGET(applet), | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
205 awayname, |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
206 a->name, (AppletCallbackFunc)do_away_message, a); |
1261 | 207 |
208 awy = g_slist_next(awy); | |
1421
13a34fb4abb0
[gaim-migrate @ 1431]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1420
diff
changeset
|
209 g_free(awayname); |
1261 | 210 } |
211 } | |
212 | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
213 void remove_applet_away() |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
214 { |
1261 | 215 GSList *awy = away_messages; |
216 struct away_message *a; | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
217 char *awayname; |
1261 | 218 |
1591
5c74d8b6cb57
[gaim-migrate @ 1601]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
219 if (!applet) |
5c74d8b6cb57
[gaim-migrate @ 1601]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
220 return; |
5c74d8b6cb57
[gaim-migrate @ 1601]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
221 |
1261 | 222 applet_widget_unregister_callback(APPLET_WIDGET(applet), "away/new"); |
223 | |
224 while (awy) { | |
225 a = (struct away_message *)awy->data; | |
226 | |
227 awayname = g_malloc(sizeof *awayname * (6 + strlen(a->name))); | |
228 awayname[0] = '\0'; | |
229 strcat(awayname, "away/"); | |
230 strcat(awayname, a->name); | |
231 applet_widget_unregister_callback(APPLET_WIDGET(applet), awayname); | |
232 | |
233 awy = g_slist_next(awy); | |
2492
1a25e4869e7d
[gaim-migrate @ 2505]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2489
diff
changeset
|
234 g_free(awayname); |
1261 | 235 } |
236 applet_widget_unregister_callback_dir(APPLET_WIDGET(applet), "away/"); | |
237 applet_widget_unregister_callback(APPLET_WIDGET(applet), "away"); | |
238 } | |
239 | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
240 static GtkAllocation get_applet_pos(gboolean for_blist) |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
241 { |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
242 gint x, y, pad; |
1261 | 243 GtkRequisition buddy_req, applet_req; |
244 GtkAllocation result; | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
245 GNOME_Panel_OrientType orient = applet_widget_get_panel_orient(APPLET_WIDGET(applet)); |
1261 | 246 pad = 5; |
247 | |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
248 gdk_window_get_position(gtk_widget_get_parent_window(icon), &x, &y); |
1261 | 249 if (for_blist) { |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
250 if (blist_options & OPT_BLIST_SAVED_WINDOWS) { |
1261 | 251 buddy_req.width = blist_pos.width; |
252 buddy_req.height = blist_pos.height; | |
253 } else { | |
254 buddy_req = blist->requisition; | |
255 } | |
256 } else { | |
257 buddy_req = mainwindow->requisition; | |
258 } | |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
259 applet_req = icon->requisition; |
1261 | 260 |
261 /* FIXME : we need to be smarter here */ | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
262 switch (orient) { |
1261 | 263 case ORIENT_UP: |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
264 result.x = x; |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
265 result.y = y - (buddy_req.height + pad); |
1261 | 266 break; |
267 case ORIENT_DOWN: | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
268 result.x = x; |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
269 result.y = y + applet_req.height + pad; |
1261 | 270 break; |
271 case ORIENT_LEFT: | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
272 result.x = x - (buddy_req.width + pad); |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
273 result.y = y; |
1261 | 274 break; |
275 case ORIENT_RIGHT: | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
276 result.x = x + applet_req.width + pad; |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
277 result.y = y; |
1261 | 278 break; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
279 } |
1261 | 280 return result; |
281 } | |
282 | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
283 void createOnlinePopup() |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
284 { |
1261 | 285 GtkAllocation al; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
286 if (blist) |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
287 gtk_widget_show(blist); |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
288 al = get_applet_pos(TRUE); |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
289 if (blist_options & OPT_BLIST_NEAR_APPLET) |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
290 gtk_widget_set_uposition(blist, al.x, al.y); |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
291 else if (blist_options & OPT_BLIST_SAVED_WINDOWS) |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
292 gtk_widget_set_uposition(blist, blist_pos.x - blist_pos.xoff, |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
293 blist_pos.y - blist_pos.yoff); |
1261 | 294 } |
295 | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
296 void AppletClicked(GtkWidget *sender, GdkEventButton *ev, gpointer data) |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
297 { |
1261 | 298 if (!ev || ev->button != 1 || ev->type != GDK_BUTTON_PRESS) |
299 return; | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
300 |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
301 if (applet_buddy_show) { |
1261 | 302 applet_buddy_show = FALSE; |
303 if (!connections && mainwindow) | |
304 gtk_widget_hide(mainwindow); | |
305 else | |
306 gtk_widget_hide(blist); | |
307 } else { | |
308 applet_buddy_show = TRUE; | |
309 if (!connections) | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
310 applet_show_login(APPLET_WIDGET(applet), NULL); |
1261 | 311 else |
312 createOnlinePopup(); | |
313 } | |
314 } | |
315 | |
316 | |
317 /*************************************************************** | |
318 ** | |
319 ** Initialize GNOME stuff | |
320 ** | |
321 ****************************************************************/ | |
322 | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
323 gint init_applet_mgr(int argc, char *argv[]) |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
324 { |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
325 GdkPixmap *pm; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
326 |
2534 | 327 applet_widget_init("Gaim", VERSION, argc, argv, NULL, 0, NULL); |
1261 | 328 |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
329 applet = applet_widget_new("gaim_applet"); |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
330 if (!applet) |
2534 | 331 g_error(_("Can't create Gaim applet!")); |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
332 gtk_widget_set_events(applet, gtk_widget_get_events(applet) | GDK_BUTTON_PRESS_MASK); |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
333 gtk_widget_realize(applet); |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
334 |
2484
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
335 pm = get_applet_icon(GAIM_GNOME_OFFLINE_ICON); |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
336 if (!pm) |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
337 pm = gdk_pixmap_create_from_xpm_d(applet->window, NULL, |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
338 &applet->style->bg[GTK_WIDGET_STATE(applet)], aimicon_xpm); |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
339 icon = gtk_pixmap_new(pm, NULL); |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
340 gtk_widget_set_usize(icon, sizehint, sizehint); |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
341 gdk_pixmap_unref(pm); |
a4647b25dbf1
[gaim-migrate @ 2497]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2468
diff
changeset
|
342 applet_widget_add(APPLET_WIDGET(applet), icon); |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
343 |
1261 | 344 applet_widget_register_stock_callback(APPLET_WIDGET(applet), |
345 "about", | |
346 GNOME_STOCK_MENU_ABOUT, | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
347 _("About..."), (AppletCallbackFunc)show_about, NULL); |
1261 | 348 |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
349 gtk_signal_connect(GTK_OBJECT(applet), "button_press_event", GTK_SIGNAL_FUNC(AppletClicked), |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
350 NULL); |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
351 |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
352 gtk_signal_connect(GTK_OBJECT(applet), "destroy", GTK_SIGNAL_FUNC(do_quit), NULL); |
1261 | 353 |
354 #ifdef HAVE_PANEL_PIXEL_SIZE | |
355 gtk_signal_connect(GTK_OBJECT(applet), "change_pixel_size", | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
356 GTK_SIGNAL_FUNC(applet_change_pixel_size), NULL); |
1261 | 357 #endif |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
358 |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
359 gtk_widget_show(icon); |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
360 gtk_widget_show(applet); |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
361 return 0; |
1261 | 362 } |
363 | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
364 void set_user_state(enum gaim_user_states state) |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
365 { |
1261 | 366 if (state == signing_on) |
367 connecting++; | |
368 else if ((state == away || state == online) && connecting > 0) | |
369 connecting--; | |
370 update_applet(); | |
371 } | |
372 | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
373 void applet_set_tooltips(char *msg) |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
374 { |
1591
5c74d8b6cb57
[gaim-migrate @ 1601]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
375 if (!applet) |
5c74d8b6cb57
[gaim-migrate @ 1601]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
376 return; |
1261 | 377 applet_widget_set_tooltip(APPLET_WIDGET(applet), msg); |
378 } | |
379 | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2314
diff
changeset
|
380 #endif /*USE_APPLET */ |