Mercurial > pidgin.yaz
annotate src/gtkblist.c @ 9301:3d5519a84d02
[gaim-migrate @ 10105]
Some stuff. Mostly from nosnilmot. Re-split the raise on events
preference for IMs and chats.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 17 Jun 2004 01:18:21 +0000 |
parents | 7a8aa87164ae |
children | af707cc1e229 |
rev | line source |
---|---|
5228 | 1 /* |
2 * gaim | |
3 * | |
8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
5228 | 7 * |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 * | |
22 */ | |
7620 | 23 #include "gtkinternal.h" |
24 | |
25 #include "account.h" | |
9015 | 26 #include "connection.h" |
7620 | 27 #include "core.h" |
28 #include "debug.h" | |
29 #include "multi.h" | |
30 #include "notify.h" | |
31 #include "prpl.h" | |
32 #include "prefs.h" | |
8986 | 33 #include "plugin.h" |
7620 | 34 #include "request.h" |
35 #include "signals.h" | |
36 #include "sound.h" | |
37 #include "stock.h" | |
38 #include "util.h" | |
39 | |
40 #include "gtkaccount.h" | |
41 #include "gtkblist.h" | |
42 #include "gtkconv.h" | |
43 #include "gtkdebug.h" | |
44 #include "gtkft.h" | |
45 #include "gtklog.h" | |
46 #include "gtkpounce.h" | |
47 #include "gtkprefs.h" | |
48 #include "gtkprivacy.h" | |
8113 | 49 #include "gtkroomlist.h" |
7620 | 50 #include "gtkutils.h" |
51 | |
52 #include "ui.h" | |
53 | |
54 #include "gaim.h" | |
5228 | 55 |
56 #include <gdk/gdkkeysyms.h> | |
57 #include <gtk/gtk.h> | |
7620 | 58 #include <gdk/gdk.h> |
59 | |
7662 | 60 #if (GTK_CHECK_VERSION(2,2,0) && !(defined(__APPLE__) && defined(__MACH__))) |
61 #define WANT_DROP_SHADOW | |
62 #endif | |
63 | |
7620 | 64 typedef struct |
65 { | |
66 GaimAccount *account; | |
67 | |
68 GtkWidget *window; | |
69 GtkWidget *combo; | |
70 GtkWidget *entry; | |
71 GtkWidget *entry_for_alias; | |
72 GtkWidget *account_box; | |
73 | |
74 } GaimGtkAddBuddyData; | |
75 | |
76 typedef struct | |
77 { | |
78 GaimAccount *account; | |
79 | |
80 GtkWidget *window; | |
81 GtkWidget *account_menu; | |
82 GtkWidget *alias_entry; | |
83 GtkWidget *group_combo; | |
84 GtkWidget *entries_box; | |
85 GtkSizeGroup *sg; | |
86 | |
87 GList *entries; | |
88 | |
89 } GaimGtkAddChatData; | |
90 | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
91 typedef struct |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
92 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
93 GaimAccount *account; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
94 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
95 GtkWidget *window; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
96 GtkWidget *account_menu; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
97 GtkWidget *entries_box; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
98 GtkSizeGroup *sg; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
99 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
100 GList *entries; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
101 } GaimGtkJoinChatData; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
102 |
7620 | 103 |
8986 | 104 static GtkWidget *protomenu = NULL, *pluginmenu = NULL; |
5228 | 105 |
5422 | 106 GSList *gaim_gtk_blist_sort_methods = NULL; |
107 static struct gaim_gtk_blist_sort_method *current_sort_method = NULL; | |
7620 | 108 static GtkTreeIter sort_method_none(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur); |
109 | |
110 /* The functions we use for sorting aren't available in gtk 2.0.x, and | |
111 * segfault in 2.2.0. 2.2.1 is known to work, so I'll require that */ | |
112 #if GTK_CHECK_VERSION(2,2,1) | |
113 static GtkTreeIter sort_method_alphabetical(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur); | |
114 static GtkTreeIter sort_method_status(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur); | |
115 static GtkTreeIter sort_method_log(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur); | |
116 #endif | |
117 static GaimGtkBuddyList *gtkblist = NULL; | |
5228 | 118 |
119 /* part of the best damn Docklet code this side of Tahiti */ | |
120 static gboolean gaim_gtk_blist_obscured = FALSE; | |
121 | |
122 static void gaim_gtk_blist_selection_changed(GtkTreeSelection *selection, gpointer data); | |
7620 | 123 static void gaim_gtk_blist_update(GaimBuddyList *list, GaimBlistNode *node); |
5234 | 124 static char *gaim_get_tooltip_text(GaimBlistNode *node); |
5228 | 125 static char *item_factory_translate_func (const char *path, gpointer func_data); |
5273 | 126 static gboolean get_iter_from_node(GaimBlistNode *node, GtkTreeIter *iter); |
7620 | 127 static void redo_buddy_list(GaimBuddyList *list, gboolean remove); |
128 static void gaim_gtk_blist_collapse_contact_cb(GtkWidget *w, GaimBlistNode *node); | |
129 | |
130 static void show_rename_group(GtkWidget *unused, GaimGroup *g); | |
5422 | 131 |
5256 | 132 struct _gaim_gtk_blist_node { |
133 GtkTreeRowReference *row; | |
7620 | 134 gboolean contact_expanded; |
5256 | 135 }; |
136 | |
7662 | 137 #ifdef WANT_DROP_SHADOW |
7620 | 138 /**************************** Weird drop shadow stuff *******************/ |
139 /* This is based on a patch for drop shadows in GTK menus available at http://www.xfce.org/gtkmenu-shadow/ */ | |
140 | |
141 enum side { | |
142 EAST_SIDE, | |
143 SOUTH_SIDE | |
144 }; | |
145 | |
146 const double shadow_strip_l[5] = { | |
147 .937, .831, .670, .478, .180 | |
148 }; | |
149 | |
150 const double bottom_left_corner[25] = { | |
151 1.00, .682, .423, .333, .258, | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
152 1.00, .898, .800, .682, .584, |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
153 1.00, .937, .874, .800, .737, |
7620 | 154 1.00, .968, .937, .898, .866, |
155 1.00, .988, .976, .960, .945 | |
156 }; | |
157 | |
158 const double bottom_right_corner[25] = { | |
159 .258, .584, .737, .866, .945, | |
160 .584, .682, .800, .898, .960, | |
161 .737, .800, .874, .937, .976, | |
162 .866, .898, .937, .968, .988, | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
163 .945, .960, .976, .988, .996 |
7620 | 164 }; |
165 | |
166 const double top_right_corner[25] = { | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
167 1.00, 1.00, 1.00, 1.00, 1.00, |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
168 .686, .898, .937, .968, .988, |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
169 .423, .803, .874, .937, .976, |
7620 | 170 .333, .686, .800, .898, .960, |
171 .258, .584, .737, .866, .945 | |
172 }; | |
173 | |
174 const double top_left_corner[25] = { | |
175 .988, .968, .937, .898, .498, | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
176 .976, .937, .874, .803, .423, |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
177 .960, .898, .800, .686, .333, |
7620 | 178 .945, .866, .737, .584, .258, |
179 .941, .847, .698, .521, .215 | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
180 }; |
7620 | 181 |
182 | |
183 static GdkPixbuf * | |
184 get_pixbuf (GtkWidget *menu, | |
185 int x, | |
186 int y, | |
187 int width, | |
188 int height) | |
189 { | |
190 GdkPixbuf *dest, *src; | |
191 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET(menu)); | |
192 GdkWindow *root = gdk_screen_get_root_window (screen); | |
193 gint screen_height = gdk_screen_get_height (screen); | |
194 gint screen_width = gdk_screen_get_width (screen); | |
195 gint original_width = width; | |
196 gint original_height = height; | |
197 | |
198 #ifdef _WIN32 | |
199 /* In Win32, GDK gets the workarea that isn't occupied by toolbars | |
200 (including the taskbar) and uses that region as the screen size. | |
201 GTK returns positions based on a screen size that ignores these | |
202 toolbars. Since we want a pixmap with real X,Y coordinates, we | |
203 need to find out the offset from GTK's screen to GDK's screen, | |
204 and adjust the pixmaps we grab accordingly. GDK will not deal | |
205 with toolbar position updates, so we're stuck restarting Gaim | |
206 if that happens. */ | |
207 RECT *workarea = g_malloc(sizeof(RECT)); | |
208 SystemParametersInfo(SPI_GETWORKAREA, 0, (void *)workarea, 0); | |
209 x += (workarea->left); | |
210 y += (workarea->top); | |
211 g_free(workarea); | |
212 #endif | |
213 | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
214 if (x < 0) |
7620 | 215 { |
216 width += x; | |
217 x = 0; | |
218 } | |
219 | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
220 if (y < 0) |
7620 | 221 { |
222 height += y; | |
223 y = 0; | |
224 } | |
225 | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
226 if (x + width > screen_width) |
7620 | 227 { |
228 width = screen_width - x; | |
229 } | |
230 | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
231 if (y + height > screen_height) |
7620 | 232 { |
233 height = screen_height - y; | |
234 } | |
235 | |
236 if (width <= 0 || height <= 0) | |
237 return NULL; | |
238 | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
239 dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, |
7620 | 240 original_width, original_height); |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
241 src = gdk_pixbuf_get_from_drawable (NULL, root, NULL, x, y, 0, 0, |
7620 | 242 width, height); |
243 gdk_pixbuf_copy_area (src, 0, 0, width, height, dest, 0, 0); | |
244 | |
245 g_object_unref (G_OBJECT (src)); | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
246 |
7620 | 247 return dest; |
248 } | |
249 | |
250 static void | |
251 shadow_paint(GaimGtkBuddyList *blist, GdkRectangle *area, enum side shadow) | |
252 { | |
253 gint width, height; | |
254 GdkGC *gc = gtkblist->tipwindow->style->black_gc; | |
255 | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
256 switch (shadow) |
7620 | 257 { |
258 case EAST_SIDE: | |
259 if (gtkblist->east != NULL) | |
260 { | |
261 if (area) | |
262 gdk_gc_set_clip_rectangle (gc, area); | |
263 | |
264 width = gdk_pixbuf_get_width (gtkblist->east); | |
265 height = gdk_pixbuf_get_height (gtkblist->east); | |
266 | |
267 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->east_shadow), gc, | |
268 gtkblist->east, 0, 0, 0, 0, width, height, GDK_RGB_DITHER_NONE, | |
269 0, 0); | |
270 | |
271 if (area) | |
272 gdk_gc_set_clip_rectangle (gc, NULL); | |
273 } | |
274 break; | |
275 case SOUTH_SIDE: | |
276 if (blist->south != NULL) | |
277 { | |
278 if (area) | |
279 gdk_gc_set_clip_rectangle (gc, area); | |
280 | |
281 width = gdk_pixbuf_get_width (gtkblist->south); | |
282 height = gdk_pixbuf_get_height (gtkblist->south); | |
283 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->south_shadow), gc, gtkblist->south, | |
284 0, 0, 0, 0, width, height, GDK_RGB_DITHER_NONE, 0, 0); | |
8040 | 285 |
7620 | 286 if (area) |
287 gdk_gc_set_clip_rectangle (gc, NULL); | |
288 } | |
289 break; | |
290 default: | |
291 break; | |
292 } | |
293 } | |
294 | |
295 static void | |
296 pixbuf_add_shadow (GdkPixbuf *pb, | |
297 enum side shadow) | |
298 { | |
299 gint width, rowstride, height; | |
300 gint i; | |
301 guchar *pixels, *p; | |
302 | |
303 width = gdk_pixbuf_get_width (pb); | |
304 height = gdk_pixbuf_get_height (pb); | |
305 rowstride = gdk_pixbuf_get_rowstride (pb); | |
306 pixels = gdk_pixbuf_get_pixels (pb); | |
307 | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
308 switch (shadow) |
7620 | 309 { |
310 case EAST_SIDE: | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
311 if (height > 5) |
7620 | 312 { |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
313 for (i = 0; i < width; i++) |
7620 | 314 { |
315 gint j, k; | |
316 | |
317 p = pixels + (i * rowstride); | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
318 for (j = 0, k = 0; j < 3 * width; j += 3, k++) |
7620 | 319 { |
320 p[j] = (guchar) (p[j] * top_right_corner [i * width + k]); | |
321 p[j + 1] = (guchar) (p[j + 1] * top_right_corner [i * width + k]); | |
322 p[j + 2] = (guchar) (p[j + 2] * top_right_corner [i * width + k]); | |
323 } | |
324 } | |
325 | |
326 i = 5; | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
327 } |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
328 else |
7620 | 329 { |
330 i = 0; | |
331 } | |
332 | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
333 for (;i < height; i++) |
7620 | 334 { |
335 gint j, k; | |
336 | |
337 p = pixels + (i * rowstride); | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
338 for (j = 0, k = 0; j < 3 * width; j += 3, k++) |
7620 | 339 { |
340 p[j] = (guchar) (p[j] * shadow_strip_l[width - 1 - k]); | |
341 p[j + 1] = (guchar) (p[j + 1] * shadow_strip_l[width - 1 - k]); | |
342 p[j + 2] = (guchar) (p[j + 2] * shadow_strip_l[width - 1 - k]); | |
343 } | |
344 } | |
345 break; | |
346 | |
347 case SOUTH_SIDE: | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
348 for (i = 0; i < height; i++) |
7620 | 349 { |
350 gint j, k; | |
351 | |
352 p = pixels + (i * rowstride); | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
353 for (j = 0, k = 0; j < 3 * height; j += 3, k++) |
7620 | 354 { |
355 p[j] = (guchar) (p[j] * bottom_left_corner[i * height + k]); | |
356 p[j + 1] = (guchar) (p[j + 1] * bottom_left_corner[i * height + k]); | |
357 p[j + 2] = (guchar) (p[j + 2] * bottom_left_corner[i * height + k]); | |
358 } | |
359 | |
360 p = pixels + (i * rowstride) + 3 * height; | |
361 for (j = 0, k = 0; j < (width * 3) - (6 * height); j += 3, k++) | |
362 { | |
363 p[j] = (guchar) (p[j] * bottom_right_corner [i * height]); | |
364 p[j + 1] = (guchar) (p[j + 1] * bottom_right_corner [i * height]); | |
365 p[j + 2] = (guchar) (p[j + 2] * bottom_right_corner [i * height]); | |
366 } | |
367 | |
368 p = pixels + (i * rowstride) + ((width * 3) - (3 * height)); | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
369 for (j = 0, k = 0; j < 3 * height; j += 3, k++) |
7620 | 370 { |
371 p[j] = (guchar) (p[j] * bottom_right_corner[i * height + k]); | |
372 p[j + 1] = (guchar) (p[j + 1] * bottom_right_corner[i * height + k]); | |
373 p[j + 2] = (guchar) (p[j + 2] * bottom_right_corner[i * height + k]); | |
374 } | |
375 } | |
376 break; | |
377 | |
378 default: | |
379 break; | |
380 } | |
381 } | |
382 | |
383 static gboolean | |
384 map_shadow_windows (gpointer data) | |
385 { | |
386 GaimGtkBuddyList *blist = (GaimGtkBuddyList*)data; | |
387 GtkWidget *widget = blist->tipwindow; | |
388 GdkPixbuf *pixbuf; | |
389 int x, y; | |
390 | |
391 gtk_window_get_position(GTK_WINDOW(widget), &x, &y); | |
392 pixbuf = get_pixbuf (widget, | |
393 x + widget->allocation.width, y, | |
394 5, widget->allocation.height + 5); | |
395 if (pixbuf != NULL) | |
396 { | |
397 pixbuf_add_shadow (pixbuf, EAST_SIDE); | |
398 if (blist->east != NULL) | |
399 { | |
400 g_object_unref (G_OBJECT (blist->east)); | |
401 } | |
402 blist->east = pixbuf; | |
403 } | |
404 | |
405 pixbuf = get_pixbuf (widget, | |
406 x, y + widget->allocation.height, | |
407 widget->allocation.width + 5, 5); | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
408 if (pixbuf != NULL) |
7620 | 409 { |
410 pixbuf_add_shadow (pixbuf, SOUTH_SIDE); | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
411 if (blist->south != NULL) |
7620 | 412 { |
413 g_object_unref (G_OBJECT (blist->south)); | |
414 } | |
415 blist->south = pixbuf; | |
416 } | |
417 | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
418 gdk_window_move_resize (blist->east_shadow, |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
419 x + widget->allocation.width, y, |
7620 | 420 5, widget->allocation.height); |
421 | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
422 gdk_window_move_resize (blist->south_shadow, |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
423 x, y + widget->allocation.height, |
7620 | 424 widget->allocation.width + 5, 5); |
425 gdk_window_show (blist->east_shadow); | |
426 gdk_window_show (blist->south_shadow); | |
427 shadow_paint(blist, NULL, EAST_SIDE); | |
428 shadow_paint(blist, NULL, SOUTH_SIDE); | |
429 | |
430 return FALSE; | |
431 } | |
432 | |
433 /**************** END WEIRD DROP SHADOW STUFF ***********************************/ | |
434 #endif | |
8254 | 435 |
7620 | 436 static GSList *blist_prefs_callbacks = NULL; |
437 | |
5228 | 438 /*************************************************** |
439 * Callbacks * | |
440 ***************************************************/ | |
441 | |
442 static gboolean gtk_blist_delete_cb(GtkWidget *w, GdkEventAny *event, gpointer data) | |
443 { | |
444 if (docklet_count) | |
445 gaim_blist_set_visible(FALSE); | |
446 else | |
7620 | 447 gaim_core_quit(); |
5228 | 448 |
449 /* we handle everything, event should not propogate further */ | |
450 return TRUE; | |
451 } | |
452 | |
453 static gboolean gtk_blist_configure_cb(GtkWidget *w, GdkEventConfigure *event, gpointer data) | |
454 { | |
455 /* unfortunately GdkEventConfigure ignores the window gravity, but * | |
456 * the only way we have of setting the position doesn't. we have to * | |
7620 | 457 * call get_position because it does pay attention to the gravity. * |
458 * this is inefficient and I agree it sucks, but it's more likely * | |
459 * to work correctly. - Robot101 */ | |
5228 | 460 gint x, y; |
461 | |
462 /* check for visibility because when we aren't visible, this will * | |
463 * give us bogus (0,0) coordinates. - xOr */ | |
7620 | 464 if (GTK_WIDGET_VISIBLE(w)) |
5228 | 465 gtk_window_get_position(GTK_WINDOW(w), &x, &y); |
7620 | 466 else |
467 return FALSE; /* carry on normally */ | |
468 | |
469 /* don't save if nothing changed */ | |
470 if (x == gaim_prefs_get_int("/gaim/gtk/blist/x") && | |
471 y == gaim_prefs_get_int("/gaim/gtk/blist/y") && | |
472 event->width == gaim_prefs_get_int("/gaim/gtk/blist/width") && | |
473 event->height == gaim_prefs_get_int("/gaim/gtk/blist/height")) { | |
474 | |
475 return FALSE; /* carry on normally */ | |
5228 | 476 } |
477 | |
7620 | 478 /* don't save off-screen positioning */ |
479 if (x + event->width < 0 || | |
480 y + event->height < 0 || | |
481 x > gdk_screen_width() || | |
482 y > gdk_screen_height()) { | |
483 | |
484 return FALSE; /* carry on normally */ | |
485 } | |
486 | |
487 /* store the position */ | |
488 gaim_prefs_set_int("/gaim/gtk/blist/x", x); | |
489 gaim_prefs_set_int("/gaim/gtk/blist/y", y); | |
490 gaim_prefs_set_int("/gaim/gtk/blist/width", event->width); | |
491 gaim_prefs_set_int("/gaim/gtk/blist/height", event->height); | |
492 | |
5228 | 493 /* continue to handle event normally */ |
494 return FALSE; | |
495 } | |
496 | |
497 static gboolean gtk_blist_visibility_cb(GtkWidget *w, GdkEventVisibility *event, gpointer data) | |
498 { | |
499 if (event->state == GDK_VISIBILITY_FULLY_OBSCURED) | |
500 gaim_gtk_blist_obscured = TRUE; | |
501 else | |
502 gaim_gtk_blist_obscured = FALSE; | |
503 | |
504 /* continue to handle event normally */ | |
505 return FALSE; | |
506 } | |
507 | |
7620 | 508 static void gtk_blist_menu_info_cb(GtkWidget *w, GaimBuddy *b) |
5228 | 509 { |
510 serv_get_info(b->account->gc, b->name); | |
511 } | |
512 | |
7620 | 513 static void gtk_blist_menu_im_cb(GtkWidget *w, GaimBuddy *b) |
5228 | 514 { |
7620 | 515 GaimConversation *conv = gaim_conversation_new(GAIM_CONV_IM, b->account, |
516 b->name); | |
517 | |
518 if(conv) { | |
519 GaimConvWindow *win = gaim_conversation_get_window(conv); | |
520 | |
521 gaim_conv_window_raise(win); | |
522 gaim_conv_window_switch_conversation( | |
523 gaim_conversation_get_window(conv), | |
524 gaim_conversation_get_index(conv)); | |
525 | |
526 if (GAIM_IS_GTK_WINDOW(win)) | |
527 gtk_window_present(GTK_WINDOW(GAIM_GTK_WINDOW(win)->window)); | |
528 } | |
5228 | 529 } |
530 | |
7620 | 531 static void gtk_blist_menu_autojoin_cb(GtkWidget *w, GaimChat *chat) |
532 { | |
7693 | 533 gaim_blist_node_set_bool((GaimBlistNode*)chat, "gtk-autojoin", |
534 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w))); | |
7620 | 535 } |
536 | |
537 static void gtk_blist_menu_join_cb(GtkWidget *w, GaimChat *chat) | |
5228 | 538 { |
5234 | 539 serv_join_chat(chat->account->gc, chat->components); |
540 } | |
541 | |
542 static void gtk_blist_menu_alias_cb(GtkWidget *w, GaimBlistNode *node) | |
543 { | |
544 if(GAIM_BLIST_NODE_IS_BUDDY(node)) | |
7620 | 545 alias_dialog_bud((GaimBuddy*)node); |
546 else if(GAIM_BLIST_NODE_IS_CONTACT(node)) | |
547 alias_dialog_contact((GaimContact*)node); | |
5234 | 548 else if(GAIM_BLIST_NODE_IS_CHAT(node)) |
7620 | 549 alias_dialog_blist_chat((GaimChat*)node); |
5228 | 550 } |
551 | |
7620 | 552 static void gtk_blist_menu_bp_cb(GtkWidget *w, GaimBuddy *b) |
5228 | 553 { |
7620 | 554 gaim_gtkpounce_dialog_show(b->account, b->name, NULL); |
5228 | 555 } |
556 | |
7620 | 557 static void gtk_blist_menu_showlog_cb(GtkWidget *w, GaimBuddy *b) |
5228 | 558 { |
7620 | 559 gaim_gtk_log_show(b->name, b->account); |
560 } | |
561 | |
5228 | 562 static void gtk_blist_show_systemlog_cb() |
563 { | |
8573 | 564 gaim_gtk_syslog_show(); |
5228 | 565 } |
566 | |
567 static void gtk_blist_show_onlinehelp_cb() | |
568 { | |
7620 | 569 gaim_notify_uri(NULL, GAIM_WEBSITE "documentation.php"); |
5228 | 570 } |
571 | |
572 static void gtk_blist_button_im_cb(GtkWidget *w, GtkTreeView *tv) | |
573 { | |
574 GtkTreeIter iter; | |
575 GtkTreeModel *model = gtk_tree_view_get_model(tv); | |
576 GtkTreeSelection *sel = gtk_tree_view_get_selection(tv); | |
577 | |
578 if(gtk_tree_selection_get_selected(sel, &model, &iter)){ | |
579 GaimBlistNode *node; | |
580 | |
581 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
582 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
7620 | 583 gaim_conversation_new(GAIM_CONV_IM, ((GaimBuddy*)node)->account, ((GaimBuddy*)node)->name); |
584 return; | |
585 } else if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
586 GaimBuddy *buddy = | |
587 gaim_contact_get_priority_buddy((GaimContact*)node); | |
588 gaim_conversation_new(GAIM_CONV_IM, buddy->account, buddy->name); | |
5228 | 589 return; |
590 } | |
591 } | |
592 show_im_dialog(); | |
593 } | |
594 | |
595 static void gtk_blist_button_info_cb(GtkWidget *w, GtkTreeView *tv) | |
596 { | |
597 GtkTreeIter iter; | |
598 GtkTreeModel *model = gtk_tree_view_get_model(tv); | |
599 GtkTreeSelection *sel = gtk_tree_view_get_selection(tv); | |
600 | |
601 if(gtk_tree_selection_get_selected(sel, &model, &iter)){ | |
602 GaimBlistNode *node; | |
603 | |
604 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
605 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
7620 | 606 serv_get_info(((GaimBuddy*)node)->account->gc, ((GaimBuddy*)node)->name); |
607 return; | |
608 } else if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
609 GaimBuddy *buddy = gaim_contact_get_priority_buddy((GaimContact*)node); | |
610 serv_get_info(buddy->account->gc, buddy->name); | |
5228 | 611 return; |
612 } | |
613 } | |
614 show_info_dialog(); | |
615 } | |
616 | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
617 static void |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
618 do_join_chat(GaimGtkJoinChatData *data) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
619 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
620 if (data) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
621 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
622 GHashTable *components = |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
623 g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
624 GList *tmp; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
625 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
626 for (tmp = data->entries; tmp != NULL; tmp = tmp->next) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
627 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
628 if (g_object_get_data(tmp->data, "is_spin")) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
629 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
630 g_hash_table_replace(components, |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
631 g_strdup(g_object_get_data(tmp->data, "identifier")), |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
632 g_strdup_printf("%d", |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
633 gtk_spin_button_get_value_as_int(tmp->data))); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
634 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
635 else |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
636 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
637 g_hash_table_replace(components, |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
638 g_strdup(g_object_get_data(tmp->data, "identifier")), |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
639 g_strdup(gtk_entry_get_text(tmp->data))); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
640 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
641 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
642 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
643 serv_join_chat(gaim_account_get_connection(data->account), components); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
644 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
645 g_hash_table_destroy(components); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
646 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
647 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
648 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
649 static void |
8940 | 650 do_joinchat(GtkWidget *dialog, int id, GaimGtkJoinChatData *info) |
651 { | |
652 switch(id) | |
653 { | |
654 case GTK_RESPONSE_OK: | |
655 do_join_chat(info); | |
656 | |
657 break; | |
658 } | |
659 | |
660 gtk_widget_destroy(GTK_WIDGET(dialog)); | |
661 g_list_free(info->entries); | |
662 g_free(info); | |
663 } | |
664 | |
665 static void | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
666 rebuild_joinchat_entries(GaimGtkJoinChatData *data) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
667 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
668 GaimConnection *gc; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
669 GList *list, *tmp; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
670 struct proto_chat_entry *pce; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
671 gboolean focus = TRUE; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
672 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
673 gc = gaim_account_get_connection(data->account); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
674 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
675 while (GTK_BOX(data->entries_box)->children) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
676 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
677 gtk_container_remove(GTK_CONTAINER(data->entries_box), |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
678 ((GtkBoxChild *)GTK_BOX(data->entries_box)->children->data)->widget); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
679 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
680 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
681 if (data->entries != NULL) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
682 g_list_free(data->entries); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
683 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
684 data->entries = NULL; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
685 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
686 list = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info(gc); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
687 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
688 for (tmp = list; tmp; tmp = tmp->next) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
689 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
690 GtkWidget *label; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
691 GtkWidget *rowbox; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
692 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
693 pce = tmp->data; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
694 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
695 rowbox = gtk_hbox_new(FALSE, 12); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
696 gtk_box_pack_start(GTK_BOX(data->entries_box), rowbox, FALSE, FALSE, 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
697 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
698 label = gtk_label_new_with_mnemonic(pce->label); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
699 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
700 gtk_size_group_add_widget(data->sg, label); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
701 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
702 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
703 if (pce->is_int) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
704 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
705 GtkObject *adjust; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
706 GtkWidget *spin; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
707 adjust = gtk_adjustment_new(pce->min, pce->min, pce->max, |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
708 1, 10, 10); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
709 spin = gtk_spin_button_new(GTK_ADJUSTMENT(adjust), 1, 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
710 g_object_set_data(G_OBJECT(spin), "is_spin", |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
711 GINT_TO_POINTER(TRUE)); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
712 g_object_set_data(G_OBJECT(spin), "identifier", pce->identifier); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
713 data->entries = g_list_append(data->entries, spin); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
714 gtk_widget_set_size_request(spin, 50, -1); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
715 gtk_box_pack_end(GTK_BOX(rowbox), spin, FALSE, FALSE, 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
716 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(spin)); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
717 gaim_set_accessible_label (spin, label); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
718 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
719 else |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
720 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
721 GtkWidget *entry = gtk_entry_new(); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
722 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
723 gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
724 g_object_set_data(G_OBJECT(entry), "identifier", pce->identifier); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
725 data->entries = g_list_append(data->entries, entry); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
726 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
727 if (pce->def) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
728 gtk_entry_set_text(GTK_ENTRY(entry), pce->def); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
729 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
730 if (focus) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
731 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
732 gtk_widget_grab_focus(entry); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
733 focus = FALSE; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
734 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
735 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
736 if (pce->secret) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
737 gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
738 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
739 gtk_box_pack_end(GTK_BOX(rowbox), entry, TRUE, TRUE, 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
740 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(entry)); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
741 gaim_set_accessible_label (entry, label); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
742 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
743 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
744 g_free(pce); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
745 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
746 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
747 g_list_free(list); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
748 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
749 gtk_widget_show_all(data->entries_box); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
750 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
751 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
752 static void |
8940 | 753 joinchat_select_account_cb(GObject *w, GaimAccount *account, |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
754 GaimGtkJoinChatData *data) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
755 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
756 if (gaim_account_get_protocol(data->account) == |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
757 gaim_account_get_protocol(account)) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
758 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
759 data->account = account; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
760 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
761 else |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
762 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
763 data->account = account; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
764 rebuild_joinchat_entries(data); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
765 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
766 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
767 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
768 static gboolean |
8940 | 769 joinchat_account_filter_func(GaimAccount *account) |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
770 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
771 GaimConnection *gc = gaim_account_get_connection(account); |
8940 | 772 GaimPluginProtocolInfo *prpl_info = NULL; |
773 | |
774 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
775 | |
776 return (prpl_info->chat_info != NULL); | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
777 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
778 |
8940 | 779 gboolean |
780 gaim_gtk_blist_joinchat_is_showable() | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
781 { |
8940 | 782 GList *c; |
783 GaimConnection *gc; | |
784 | |
785 for (c = gaim_connections_get_all(); c != NULL; c = c->next) { | |
786 gc = c->data; | |
787 | |
788 if (joinchat_account_filter_func(gaim_connection_get_account(gc))) | |
789 return TRUE; | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
790 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
791 |
8940 | 792 return FALSE; |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
793 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
794 |
8305
57bdd25752c1
[gaim-migrate @ 9029]
Christian Hammond <chipx86@chipx86.com>
parents:
8303
diff
changeset
|
795 void |
8940 | 796 gaim_gtk_blist_joinchat_show(void) |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
797 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
798 GtkWidget *hbox, *vbox; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
799 GtkWidget *rowbox; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
800 GtkWidget *label; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
801 GaimGtkBuddyList *gtkblist; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
802 GtkWidget *img = NULL; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
803 GaimGtkJoinChatData *data = NULL; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
804 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
805 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
806 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
807 GTK_ICON_SIZE_DIALOG); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
808 data = g_new0(GaimGtkJoinChatData, 1); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
809 |
8975 | 810 data->window = gtk_dialog_new_with_buttons(_("Join a Chat"), |
811 NULL, GTK_DIALOG_NO_SEPARATOR, | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
812 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
8308 | 813 GAIM_STOCK_CHAT, GTK_RESPONSE_OK, NULL); |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
814 gtk_dialog_set_default_response(GTK_DIALOG(data->window), GTK_RESPONSE_OK); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
815 gtk_container_set_border_width(GTK_CONTAINER(data->window), 6); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
816 gtk_window_set_resizable(GTK_WINDOW(data->window), FALSE); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
817 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(data->window)->vbox), 12); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
818 gtk_container_set_border_width( |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
819 GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), 6); |
8975 | 820 gtk_window_set_role(GTK_WINDOW(data->window), "join_chat"); |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
821 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
822 hbox = gtk_hbox_new(FALSE, 12); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
823 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), hbox); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
824 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
825 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
826 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
827 vbox = gtk_vbox_new(FALSE, 5); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
828 gtk_container_set_border_width(GTK_CONTAINER(vbox), 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
829 gtk_container_add(GTK_CONTAINER(hbox), vbox); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
830 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
831 label = gtk_label_new(_("Please enter the appropriate information " |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
832 "about the chat you would like to join.\n")); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
833 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
834 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
835 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
836 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
837 rowbox = gtk_hbox_new(FALSE, 12); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
838 gtk_box_pack_start(GTK_BOX(vbox), rowbox, TRUE, TRUE, 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
839 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
840 data->sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
841 |
8940 | 842 label = gtk_label_new_with_mnemonic(_("_Account:")); |
843 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
844 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); | |
845 gtk_size_group_add_widget(data->sg, label); | |
846 | |
847 data->account_menu = gaim_gtk_account_option_menu_new(NULL, FALSE, | |
848 G_CALLBACK(joinchat_select_account_cb), | |
849 joinchat_account_filter_func, data); | |
850 gtk_box_pack_start(GTK_BOX(rowbox), data->account_menu, TRUE, TRUE, 0); | |
851 gtk_label_set_mnemonic_widget(GTK_LABEL(label), | |
852 GTK_WIDGET(data->account_menu)); | |
853 gaim_set_accessible_label (data->account_menu, label); | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
854 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
855 data->entries_box = gtk_vbox_new(FALSE, 5); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
856 gtk_container_add(GTK_CONTAINER(vbox), data->entries_box); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
857 gtk_container_set_border_width(GTK_CONTAINER(data->entries_box), 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
858 |
8940 | 859 data->account = gaim_gtk_account_option_menu_get_selected(data->account_menu); |
860 | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
861 rebuild_joinchat_entries(data); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
862 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
863 g_signal_connect(G_OBJECT(data->window), "response", |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
864 G_CALLBACK(do_joinchat), data); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
865 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
866 g_object_unref(data->sg); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
867 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
868 gtk_widget_show_all(data->window); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
869 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
870 |
5234 | 871 static void gtk_blist_button_chat_cb(GtkWidget *w, GtkTreeView *tv) |
5228 | 872 { |
5234 | 873 GtkTreeIter iter; |
874 GtkTreeModel *model = gtk_tree_view_get_model(tv); | |
875 GtkTreeSelection *sel = gtk_tree_view_get_selection(tv); | |
876 | |
877 if(gtk_tree_selection_get_selected(sel, &model, &iter)){ | |
878 GaimBlistNode *node; | |
879 | |
880 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
881 if (GAIM_BLIST_NODE_IS_CHAT(node)) { | |
7620 | 882 serv_join_chat(((GaimChat *)node)->account->gc, ((GaimChat *)node)->components); |
5234 | 883 return; |
884 } | |
885 } | |
8940 | 886 gaim_gtk_blist_joinchat_show(); |
5228 | 887 } |
888 | |
889 static void gtk_blist_button_away_cb(GtkWidget *w, gpointer data) | |
890 { | |
891 gtk_menu_popup(GTK_MENU(awaymenu), NULL, NULL, NULL, NULL, 1, GDK_CURRENT_TIME); | |
892 } | |
893 | |
894 static void gtk_blist_row_expanded_cb(GtkTreeView *tv, GtkTreeIter *iter, GtkTreePath *path, gpointer user_data) { | |
895 GaimBlistNode *node; | |
896 GValue val = {0,}; | |
897 | |
898 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), iter, NODE_COLUMN, &val); | |
899 | |
900 node = g_value_get_pointer(&val); | |
901 | |
902 if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
7693 | 903 gaim_blist_node_set_bool(node, "collapsed", FALSE); |
5228 | 904 } |
905 } | |
906 | |
907 static void gtk_blist_row_collapsed_cb(GtkTreeView *tv, GtkTreeIter *iter, GtkTreePath *path, gpointer user_data) { | |
908 GaimBlistNode *node; | |
909 GValue val = {0,}; | |
910 | |
911 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), iter, NODE_COLUMN, &val); | |
912 | |
913 node = g_value_get_pointer(&val); | |
914 | |
915 if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
7693 | 916 gaim_blist_node_set_bool(node, "collapsed", TRUE); |
7620 | 917 } else if(GAIM_BLIST_NODE_IS_CONTACT(node)) { |
918 gaim_gtk_blist_collapse_contact_cb(NULL, node); | |
5228 | 919 } |
920 } | |
921 | |
922 static void gtk_blist_row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) { | |
923 GaimBlistNode *node; | |
924 GtkTreeIter iter; | |
925 GValue val = { 0, }; | |
926 | |
927 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
928 | |
929 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
930 node = g_value_get_pointer(&val); | |
931 | |
7620 | 932 if(GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_BUDDY(node)) { |
933 GaimBuddy *buddy; | |
934 GaimConversation *conv; | |
935 | |
936 if(GAIM_BLIST_NODE_IS_CONTACT(node)) | |
937 buddy = gaim_contact_get_priority_buddy((GaimContact*)node); | |
938 else | |
939 buddy = (GaimBuddy*)node; | |
940 | |
941 conv = gaim_conversation_new(GAIM_CONV_IM, buddy->account, buddy->name); | |
5489
5b5aa701d46b
[gaim-migrate @ 5885]
Christian Hammond <chipx86@chipx86.com>
parents:
5451
diff
changeset
|
942 |
5228 | 943 if(conv) { |
7620 | 944 GaimConvWindow *win = gaim_conversation_get_window(conv); |
945 | |
946 gaim_conv_window_raise(win); | |
947 gaim_conv_window_switch_conversation( | |
5228 | 948 gaim_conversation_get_window(conv), |
949 gaim_conversation_get_index(conv)); | |
5489
5b5aa701d46b
[gaim-migrate @ 5885]
Christian Hammond <chipx86@chipx86.com>
parents:
5451
diff
changeset
|
950 |
5b5aa701d46b
[gaim-migrate @ 5885]
Christian Hammond <chipx86@chipx86.com>
parents:
5451
diff
changeset
|
951 if (GAIM_IS_GTK_WINDOW(win)) |
5b5aa701d46b
[gaim-migrate @ 5885]
Christian Hammond <chipx86@chipx86.com>
parents:
5451
diff
changeset
|
952 gtk_window_present(GTK_WINDOW(GAIM_GTK_WINDOW(win)->window)); |
5228 | 953 } |
5234 | 954 } else if (GAIM_BLIST_NODE_IS_CHAT(node)) { |
7620 | 955 serv_join_chat(((GaimChat *)node)->account->gc, ((GaimChat *)node)->components); |
5228 | 956 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { |
957 if (gtk_tree_view_row_expanded(tv, path)) | |
958 gtk_tree_view_collapse_row(tv, path); | |
959 else | |
960 gtk_tree_view_expand_row(tv,path,FALSE); | |
961 } | |
962 } | |
963 | |
5234 | 964 static void gaim_gtk_blist_add_chat_cb() |
965 { | |
966 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)); | |
967 GtkTreeIter iter; | |
968 GaimBlistNode *node; | |
969 | |
970 if(gtk_tree_selection_get_selected(sel, NULL, &iter)){ | |
971 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
7620 | 972 if (GAIM_BLIST_NODE_IS_BUDDY(node)) |
7859 | 973 gaim_blist_request_add_chat(NULL, (GaimGroup*)node->parent->parent, NULL); |
7620 | 974 if (GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_CHAT(node)) |
7859 | 975 gaim_blist_request_add_chat(NULL, (GaimGroup*)node->parent, NULL); |
5234 | 976 else if (GAIM_BLIST_NODE_IS_GROUP(node)) |
7859 | 977 gaim_blist_request_add_chat(NULL, (GaimGroup*)node, NULL); |
5234 | 978 } |
979 else { | |
7859 | 980 gaim_blist_request_add_chat(NULL, NULL, NULL); |
5234 | 981 } |
982 } | |
983 | |
5228 | 984 static void gaim_gtk_blist_add_buddy_cb() |
985 { | |
986 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)); | |
987 GtkTreeIter iter; | |
988 GaimBlistNode *node; | |
989 | |
990 if(gtk_tree_selection_get_selected(sel, NULL, &iter)){ | |
991 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
7620 | 992 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { |
993 gaim_blist_request_add_buddy(NULL, NULL, ((GaimGroup*)node->parent->parent)->name, | |
994 NULL); | |
995 } else if (GAIM_BLIST_NODE_IS_CONTACT(node) | |
996 || GAIM_BLIST_NODE_IS_CHAT(node)) { | |
997 gaim_blist_request_add_buddy(NULL, NULL, ((GaimGroup*)node->parent)->name, NULL); | |
998 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
999 gaim_blist_request_add_buddy(NULL, NULL, ((GaimGroup*)node)->name, NULL); | |
1000 } | |
5228 | 1001 } |
1002 else { | |
7620 | 1003 gaim_blist_request_add_buddy(NULL, NULL, NULL, NULL); |
1004 } | |
1005 } | |
1006 | |
1007 static void | |
1008 gaim_gtk_blist_remove_cb (GtkWidget *w, GaimBlistNode *node) | |
1009 { | |
1010 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
1011 show_confirm_del((GaimBuddy*)node); | |
1012 } else if (GAIM_BLIST_NODE_IS_CHAT(node)) { | |
1013 show_confirm_del_blist_chat((GaimChat*)node); | |
1014 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
1015 show_confirm_del_group((GaimGroup*)node); | |
1016 } else if (GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
1017 show_confirm_del_contact((GaimContact*)node); | |
5228 | 1018 } |
1019 } | |
1020 | |
1021 static void | |
7620 | 1022 gaim_gtk_blist_expand_contact_cb(GtkWidget *w, GaimBlistNode *node) |
5228 | 1023 { |
7620 | 1024 struct _gaim_gtk_blist_node *gtknode; |
1025 GaimBlistNode *bnode; | |
1026 | |
1027 if(!GAIM_BLIST_NODE_IS_CONTACT(node)) | |
1028 return; | |
1029 | |
1030 gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; | |
1031 | |
1032 gtknode->contact_expanded = TRUE; | |
1033 | |
1034 for(bnode = node->child; bnode; bnode = bnode->next) { | |
1035 gaim_gtk_blist_update(NULL, bnode); | |
1036 } | |
1037 gaim_gtk_blist_update(NULL, node); | |
1038 } | |
1039 | |
1040 static void | |
1041 gaim_gtk_blist_collapse_contact_cb(GtkWidget *w, GaimBlistNode *node) | |
1042 { | |
1043 GaimBlistNode *bnode; | |
1044 struct _gaim_gtk_blist_node *gtknode; | |
1045 | |
1046 if(!GAIM_BLIST_NODE_IS_CONTACT(node)) | |
1047 return; | |
1048 | |
1049 gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; | |
1050 | |
1051 gtknode->contact_expanded = FALSE; | |
1052 | |
1053 for(bnode = node->child; bnode; bnode = bnode->next) { | |
1054 gaim_gtk_blist_update(NULL, bnode); | |
5228 | 1055 } |
1056 } | |
1057 | |
9030 | 1058 |
1059 static void | |
1060 blist_node_menu_cb(GtkMenuItem *item, GaimBlistNode *node) | |
1061 { | |
1062 GaimBlistNodeAction *act; | |
1063 act = (GaimBlistNodeAction *) g_object_get_data(G_OBJECT(item), | |
1064 "gaimcallback"); | |
1065 if(act->callback) | |
1066 act->callback(node, act->data); | |
1067 } | |
1068 | |
1069 | |
1070 static void | |
1071 append_blist_node_action (GtkWidget *menu, GaimBlistNodeAction *act, | |
1072 GaimBlistNode *node, gboolean *dup_separator) | |
5228 | 1073 { |
9030 | 1074 if(act == NULL) { |
1075 if(! *dup_separator) { | |
1076 gaim_separator(menu); | |
1077 *dup_separator = TRUE; | |
1078 } | |
1079 } else { | |
1080 GtkWidget *menuitem; | |
1081 | |
1082 *dup_separator = FALSE; | |
1083 | |
1084 menuitem = gtk_menu_item_new_with_mnemonic(act->label); | |
1085 g_object_set_data(G_OBJECT(menuitem), "gaimcallback", act); | |
1086 g_signal_connect(G_OBJECT(menuitem), "activate", | |
1087 G_CALLBACK(blist_node_menu_cb), node); | |
1088 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
1089 } | |
5228 | 1090 } |
1091 | |
9030 | 1092 |
9051 | 1093 void |
1094 gaim_gtk_append_blist_node_proto_menu (GtkWidget *menu, GaimConnection *gc, GaimBlistNode *node) | |
9030 | 1095 { |
1096 GList *l, *ll; | |
1097 gboolean dup_separator = FALSE; | |
1098 GaimPluginProtocolInfo *prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
1099 | |
1100 if(!prpl_info || !prpl_info->blist_node_menu) | |
1101 return; | |
1102 | |
1103 for(l = ll = prpl_info->blist_node_menu(node); l; l = l->next) { | |
1104 GaimBlistNodeAction *act = (GaimBlistNodeAction *) l->data; | |
1105 append_blist_node_action(menu, act, node, &dup_separator); | |
1106 } | |
1107 g_list_free(ll); | |
1108 } | |
1109 | |
1110 | |
9051 | 1111 void |
1112 gaim_gtk_append_blist_node_extended_menu (GtkWidget *menu, GaimBlistNode *node) | |
9030 | 1113 { |
1114 GList *l, *ll; | |
1115 gboolean dup_separator = FALSE; | |
1116 | |
1117 for(l = ll = gaim_blist_node_get_extended_menu(node); l; l = l->next) { | |
1118 GaimBlistNodeAction *act = (GaimBlistNodeAction *) l->data; | |
1119 append_blist_node_action(menu, act, node, &dup_separator); | |
1120 } | |
1121 g_list_free(ll); | |
1122 } | |
1123 | |
1124 | |
7620 | 1125 static void make_buddy_menu(GtkWidget *menu, GaimPluginProtocolInfo *prpl_info, GaimBuddy *b) |
1126 { | |
1127 if (prpl_info && prpl_info->get_info) { | |
8137 | 1128 gaim_new_item_from_stock(menu, _("Get _Info"), GAIM_STOCK_INFO, |
7620 | 1129 G_CALLBACK(gtk_blist_menu_info_cb), b, 0, 0, NULL); |
1130 } | |
8137 | 1131 gaim_new_item_from_stock(menu, _("I_M"), GAIM_STOCK_IM, |
7620 | 1132 G_CALLBACK(gtk_blist_menu_im_cb), b, 0, 0, NULL); |
1133 gaim_new_item_from_stock(menu, _("Add Buddy _Pounce"), NULL, | |
1134 G_CALLBACK(gtk_blist_menu_bp_cb), b, 0, 0, NULL); | |
1135 gaim_new_item_from_stock(menu, _("View _Log"), NULL, | |
1136 G_CALLBACK(gtk_blist_menu_showlog_cb), b, 0, 0, NULL); | |
1137 | |
9051 | 1138 gaim_gtk_append_blist_node_proto_menu(menu, b->account->gc, (GaimBlistNode *) b); |
1139 gaim_gtk_append_blist_node_extended_menu(menu, (GaimBlistNode *) b); | |
7620 | 1140 |
1141 gaim_separator(menu); | |
9030 | 1142 |
8302
462ead6fc1a0
[gaim-migrate @ 9026]
Christian Hammond <chipx86@chipx86.com>
parents:
8259
diff
changeset
|
1143 gaim_new_item_from_stock(menu, _("_Alias..."), GAIM_STOCK_ALIAS, |
7620 | 1144 G_CALLBACK(gtk_blist_menu_alias_cb), b, 0, 0, NULL); |
1145 gaim_new_item_from_stock(menu, _("_Remove"), GTK_STOCK_REMOVE, | |
1146 G_CALLBACK(gaim_gtk_blist_remove_cb), b, | |
1147 0, 0, NULL); | |
1148 } | |
1149 | |
1150 static gboolean gtk_blist_key_press_cb(GtkWidget *tv, GdkEventKey *event, | |
1151 gpointer null) | |
1152 { | |
1153 GaimBlistNode *node; | |
1154 GValue val = { 0, }; | |
1155 GtkTreeIter iter; | |
1156 GtkTreeSelection *sel; | |
1157 | |
1158 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv)); | |
1159 if(!gtk_tree_selection_get_selected(sel, NULL, &iter)) | |
1160 return FALSE; | |
1161 | |
1162 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), &iter, | |
1163 NODE_COLUMN, &val); | |
1164 node = g_value_get_pointer(&val); | |
1165 | |
1166 if(event->state & GDK_CONTROL_MASK && | |
1167 (event->keyval == 'o' || event->keyval == 'O')) { | |
1168 GaimBuddy *buddy; | |
1169 | |
1170 if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
1171 buddy = gaim_contact_get_priority_buddy((GaimContact*)node); | |
1172 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
1173 buddy = (GaimBuddy*)node; | |
1174 } else { | |
1175 return FALSE; | |
1176 } | |
1177 if(buddy) | |
1178 serv_get_info(buddy->account->gc, buddy->name); | |
1179 } | |
1180 | |
1181 return FALSE; | |
1182 } | |
1183 | |
9013 | 1184 |
8143 | 1185 static GtkWidget * |
8952 | 1186 create_group_menu (GaimBlistNode *node, GaimGroup *g) |
8143 | 1187 { |
1188 GtkWidget *menu; | |
1189 | |
1190 menu = gtk_menu_new(); | |
1191 gaim_new_item_from_stock(menu, _("Add a _Buddy"), GTK_STOCK_ADD, | |
1192 G_CALLBACK(gaim_gtk_blist_add_buddy_cb), node, 0, 0, NULL); | |
1193 gaim_new_item_from_stock(menu, _("Add a C_hat"), GTK_STOCK_ADD, | |
1194 G_CALLBACK(gaim_gtk_blist_add_chat_cb), node, 0, 0, NULL); | |
1195 gaim_new_item_from_stock(menu, _("_Delete Group"), GTK_STOCK_REMOVE, | |
1196 G_CALLBACK(gaim_gtk_blist_remove_cb), node, 0, 0, NULL); | |
1197 gaim_new_item_from_stock(menu, _("_Rename"), NULL, | |
1198 G_CALLBACK(show_rename_group), node, 0, 0, NULL); | |
8952 | 1199 |
9051 | 1200 gaim_gtk_append_blist_node_extended_menu(menu, node); |
8952 | 1201 |
8143 | 1202 return menu; |
1203 } | |
1204 | |
8586 | 1205 |
8143 | 1206 static GtkWidget * |
8586 | 1207 create_chat_menu (GaimBlistNode *node, |
1208 GaimChat *c, | |
1209 GaimPlugin *prpl, | |
1210 GaimPluginProtocolInfo *prpl_info) | |
8143 | 1211 { |
1212 GtkWidget *menu; | |
9030 | 1213 gboolean autojoin; |
8143 | 1214 |
1215 menu = gtk_menu_new(); | |
9030 | 1216 autojoin = (gaim_blist_node_get_bool(node, "gtk-autojoin") || |
1217 (gaim_blist_node_get_string(node, "gtk-autojoin") != NULL)); | |
1218 | |
8143 | 1219 gaim_new_item_from_stock(menu, _("_Join"), GAIM_STOCK_CHAT, |
9030 | 1220 G_CALLBACK(gtk_blist_menu_join_cb), node, 0, 0, NULL); |
8143 | 1221 gaim_new_check_item(menu, _("Auto-Join"), |
9030 | 1222 G_CALLBACK(gtk_blist_menu_autojoin_cb), node, autojoin); |
1223 | |
9051 | 1224 gaim_gtk_append_blist_node_proto_menu(menu, c->account->gc, node); |
1225 gaim_gtk_append_blist_node_extended_menu(menu, node); | |
8586 | 1226 |
1227 gaim_separator(menu); | |
9030 | 1228 |
8302
462ead6fc1a0
[gaim-migrate @ 9026]
Christian Hammond <chipx86@chipx86.com>
parents:
8259
diff
changeset
|
1229 gaim_new_item_from_stock(menu, _("_Alias..."), GAIM_STOCK_ALIAS, |
8143 | 1230 G_CALLBACK(gtk_blist_menu_alias_cb), node, 0, 0, NULL); |
1231 gaim_new_item_from_stock(menu, _("_Remove"), GTK_STOCK_REMOVE, | |
1232 G_CALLBACK(gaim_gtk_blist_remove_cb), node, 0, 0, NULL); | |
8586 | 1233 |
8143 | 1234 return menu; |
1235 } | |
1236 | |
1237 static GtkWidget * | |
1238 create_contact_menu (GaimBlistNode *node) | |
1239 { | |
1240 GtkWidget *menu; | |
1241 | |
1242 menu = gtk_menu_new(); | |
8302
462ead6fc1a0
[gaim-migrate @ 9026]
Christian Hammond <chipx86@chipx86.com>
parents:
8259
diff
changeset
|
1243 gaim_new_item_from_stock(menu, _("_Alias..."), GAIM_STOCK_ALIAS, |
8143 | 1244 G_CALLBACK(gtk_blist_menu_alias_cb), node, 0, 0, NULL); |
1245 gaim_new_item_from_stock(menu, _("_Collapse"), GTK_STOCK_ZOOM_OUT, | |
1246 G_CALLBACK(gaim_gtk_blist_collapse_contact_cb), | |
1247 node, 0, 0, NULL); | |
1248 gaim_new_item_from_stock(menu, _("_Remove"), GTK_STOCK_REMOVE, | |
1249 G_CALLBACK(gaim_gtk_blist_remove_cb), node, 0, 0, NULL); | |
9051 | 1250 |
1251 gaim_gtk_append_blist_node_extended_menu(menu, node); | |
1252 | |
8143 | 1253 return menu; |
1254 } | |
1255 | |
1256 static GtkWidget * | |
1257 create_buddy_menu (GaimBlistNode *node, | |
1258 GaimBuddy *b, | |
1259 GaimPlugin *prpl, | |
1260 GaimPluginProtocolInfo *prpl_info) | |
1261 { | |
1262 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; | |
1263 GtkWidget *menu; | |
1264 GtkWidget *menuitem; | |
1265 gboolean show_offline = gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies"); | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
1266 |
8143 | 1267 menu = gtk_menu_new(); |
1268 make_buddy_menu(menu, prpl_info, b); | |
1269 | |
1270 if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
1271 gaim_separator(menu); | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
1272 |
8143 | 1273 if(gtknode->contact_expanded) { |
1274 gaim_new_item_from_stock(menu, _("_Collapse"), | |
1275 GTK_STOCK_ZOOM_OUT, | |
1276 G_CALLBACK(gaim_gtk_blist_collapse_contact_cb), | |
1277 node, 0, 0, NULL); | |
1278 } else { | |
1279 gaim_new_item_from_stock(menu, _("_Expand"), | |
1280 GTK_STOCK_ZOOM_IN, | |
1281 G_CALLBACK(gaim_gtk_blist_expand_contact_cb), node, | |
1282 0, 0, NULL); | |
1283 } | |
1284 if(node->child->next) { | |
1285 GaimBlistNode *bnode; | |
1286 | |
1287 for(bnode = node->child; bnode; bnode = bnode->next) { | |
1288 GaimBuddy *buddy = (GaimBuddy*)bnode; | |
1289 GtkWidget *submenu; | |
1290 GtkWidget *image; | |
1291 | |
1292 if(buddy == b) | |
1293 continue; | |
1294 if(!buddy->account->gc) | |
1295 continue; | |
1296 if(!show_offline && !GAIM_BUDDY_IS_ONLINE(buddy)) | |
1297 continue; | |
1298 | |
1299 menuitem = gtk_image_menu_item_new_with_label(buddy->name); | |
1300 image = gtk_image_new_from_pixbuf( | |
1301 gaim_gtk_blist_get_status_icon(bnode, | |
1302 GAIM_STATUS_ICON_SMALL)); | |
1303 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), | |
1304 image); | |
1305 gtk_widget_show(image); | |
1306 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
1307 gtk_widget_show(menuitem); | |
1308 | |
1309 submenu = gtk_menu_new(); | |
1310 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); | |
1311 gtk_widget_show(submenu); | |
1312 | |
1313 prpl = gaim_find_prpl(gaim_account_get_protocol_id(buddy->account)); | |
1314 prpl_info = prpl ? GAIM_PLUGIN_PROTOCOL_INFO(prpl) : NULL; | |
1315 | |
1316 make_buddy_menu(submenu, prpl_info, buddy); | |
1317 } | |
1318 } | |
1319 } | |
1320 return menu; | |
1321 } | |
1322 | |
1323 static gboolean | |
1324 gaim_gtk_blist_show_context_menu(GaimBlistNode *node, | |
1325 GtkMenuPositionFunc func, | |
1326 GtkWidget *tv, | |
1327 guint button, | |
1328 guint32 time) | |
1329 { | |
1330 struct _gaim_gtk_blist_node *gtknode; | |
1331 GtkWidget *menu = NULL; | |
1332 gboolean handled = FALSE; | |
1333 | |
1334 gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; | |
1335 | |
1336 /* Create a menu based on the thing we right-clicked on */ | |
1337 if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
8952 | 1338 GaimGroup *g = (GaimGroup *)node; |
1339 menu = create_group_menu(node, g); | |
8143 | 1340 } else if (GAIM_BLIST_NODE_IS_CHAT(node)) { |
8586 | 1341 GaimChat *c = (GaimChat *)node; |
1342 GaimPlugin *prpl = NULL; | |
1343 GaimPluginProtocolInfo *prpl_info = NULL; | |
1344 prpl = gaim_find_prpl(gaim_account_get_protocol_id(c->account)); | |
1345 if (prpl != NULL) | |
1346 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
1347 menu = create_chat_menu(node, c, prpl, prpl_info); | |
8143 | 1348 } else if ((GAIM_BLIST_NODE_IS_CONTACT(node)) && (gtknode->contact_expanded)) { |
1349 menu = create_contact_menu(node); | |
1350 } else if (GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
1351 GaimBuddy *b; | |
1352 GaimPlugin *prpl = NULL; | |
1353 GaimPluginProtocolInfo *prpl_info = NULL; | |
1354 | |
1355 if (GAIM_BLIST_NODE_IS_CONTACT(node)) | |
1356 b = gaim_contact_get_priority_buddy((GaimContact*)node); | |
1357 else | |
1358 b = (GaimBuddy *)node; | |
1359 | |
1360 prpl = gaim_find_prpl(gaim_account_get_protocol_id(b->account)); | |
1361 if (prpl != NULL) | |
1362 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
1363 menu = create_buddy_menu(node, b, prpl, prpl_info); | |
1364 } | |
1365 | |
1366 /* Now display the menu */ | |
1367 if (menu != NULL) { | |
1368 gtk_widget_show_all(menu); | |
1369 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, func, tv, button, time); | |
1370 handled = TRUE; | |
1371 } | |
1372 | |
1373 return handled; | |
1374 } | |
1375 | |
1376 static gboolean gtk_blist_button_press_cb(GtkWidget *tv, GdkEventButton *event, gpointer user_data) | |
5228 | 1377 { |
1378 GtkTreePath *path; | |
1379 GaimBlistNode *node; | |
1380 GValue val = { 0, }; | |
1381 GtkTreeIter iter; | |
1382 GtkTreeSelection *sel; | |
1383 GaimPlugin *prpl = NULL; | |
1384 GaimPluginProtocolInfo *prpl_info = NULL; | |
7620 | 1385 struct _gaim_gtk_blist_node *gtknode; |
1386 gboolean handled = FALSE; | |
5228 | 1387 |
1388 /* Here we figure out which node was clicked */ | |
1389 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL)) | |
1390 return FALSE; | |
1391 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
8143 | 1392 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); |
5228 | 1393 node = g_value_get_pointer(&val); |
7620 | 1394 gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; |
1395 | |
8143 | 1396 /* Right click draws a context menu */ |
1397 if ((event->button == 3) && (event->type == GDK_BUTTON_PRESS)) { | |
1398 handled = gaim_gtk_blist_show_context_menu(node, NULL, tv, 3, event->time); | |
1399 | |
1400 /* CTRL+middle click expands or collapse a contact */ | |
1401 } else if ((event->button == 2) && (event->type == GDK_BUTTON_PRESS) && | |
1402 (event->state & GDK_CONTROL_MASK) && (GAIM_BLIST_NODE_IS_CONTACT(node))) { | |
1403 if (gtknode->contact_expanded) | |
7620 | 1404 gaim_gtk_blist_collapse_contact_cb(NULL, node); |
1405 else | |
1406 gaim_gtk_blist_expand_contact_cb(NULL, node); | |
1407 handled = TRUE; | |
8143 | 1408 |
1409 /* Double middle click gets info */ | |
1410 } else if ((event->button == 2) && (event->type == GDK_2BUTTON_PRESS) && | |
1411 ((GAIM_BLIST_NODE_IS_CONTACT(node)) || (GAIM_BLIST_NODE_IS_BUDDY(node)))) { | |
7620 | 1412 GaimBuddy *b; |
1413 if(GAIM_BLIST_NODE_IS_CONTACT(node)) | |
1414 b = gaim_contact_get_priority_buddy((GaimContact*)node); | |
1415 else | |
1416 b = (GaimBuddy *)node; | |
1417 | |
7956 | 1418 prpl = gaim_find_prpl(gaim_account_get_protocol_id(b->account)); |
5228 | 1419 if (prpl != NULL) |
1420 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
1421 | |
8143 | 1422 if (prpl && prpl_info->get_info) |
1423 serv_get_info(b->account->gc, b->name); | |
1424 handled = TRUE; | |
5228 | 1425 } |
1426 | |
8143 | 1427 #if (1) |
1428 /* | |
1429 * This code only exists because GTK doesn't work. If we return | |
1430 * FALSE here, as would be normal the event propoagates down and | |
1431 * somehow gets interpreted as the start of a drag event. | |
1432 * | |
1433 * Um, isn't it _normal_ to return TRUE here? Since the event | |
1434 * was handled? --Mark | |
1435 */ | |
7620 | 1436 if(handled) { |
1437 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv)); | |
1438 gtk_tree_selection_select_path(sel, path); | |
1439 gtk_tree_path_free(path); | |
1440 return TRUE; | |
1441 } | |
5228 | 1442 #endif |
7753 | 1443 gtk_tree_path_free(path); |
8143 | 1444 |
7620 | 1445 return FALSE; |
5228 | 1446 } |
1447 | |
8143 | 1448 static gboolean |
1449 gaim_gtk_blist_popup_menu_cb(GtkWidget *tv, void *user_data) | |
1450 { | |
1451 GaimBlistNode *node; | |
1452 GValue val = { 0, }; | |
1453 GtkTreeIter iter; | |
1454 GtkTreeSelection *sel; | |
1455 gboolean handled = FALSE; | |
1456 | |
1457 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv)); | |
1458 if (!gtk_tree_selection_get_selected(sel, NULL, &iter)) | |
1459 return FALSE; | |
1460 | |
1461 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), | |
1462 &iter, NODE_COLUMN, &val); | |
1463 node = g_value_get_pointer(&val); | |
1464 | |
1465 /* Shift+F10 draws a context menu */ | |
1466 handled = gaim_gtk_blist_show_context_menu(node, gaim_gtk_treeview_popup_menu_position_func, tv, 0, GDK_CURRENT_TIME); | |
1467 | |
1468 return handled; | |
1469 } | |
1470 | |
5228 | 1471 static void gaim_gtk_blist_show_empty_groups_cb(gpointer data, guint action, GtkWidget *item) |
1472 { | |
7620 | 1473 gaim_prefs_set_bool("/gaim/gtk/blist/show_empty_groups", |
1474 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item))); | |
5228 | 1475 } |
1476 | |
1477 static void gaim_gtk_blist_edit_mode_cb(gpointer callback_data, guint callback_action, | |
1478 GtkWidget *checkitem) { | |
1479 if(gtkblist->window->window) { | |
1480 GdkCursor *cursor = gdk_cursor_new(GDK_WATCH); | |
1481 gdk_window_set_cursor(gtkblist->window->window, cursor); | |
1482 while (gtk_events_pending()) | |
1483 gtk_main_iteration(); | |
1484 gdk_cursor_unref(cursor); | |
1485 } | |
1486 | |
7620 | 1487 gaim_prefs_set_bool("/gaim/gtk/blist/show_offline_buddies", |
1488 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(checkitem))); | |
5228 | 1489 |
1490 if(gtkblist->window->window) { | |
1491 GdkCursor *cursor = gdk_cursor_new(GDK_LEFT_PTR); | |
1492 gdk_window_set_cursor(gtkblist->window->window, cursor); | |
1493 gdk_cursor_unref(cursor); | |
1494 } | |
1495 } | |
1496 | |
8089 | 1497 static void |
1498 add_buddies_from_vcard(const char *prpl_id, GaimGroup *group, GList *list, | |
1499 const char *alias) | |
1500 { | |
1501 GList *l; | |
1502 GaimAccount *account = NULL; | |
1503 GaimConnection *gc; | |
1504 | |
1505 if (list == NULL) | |
1506 return; | |
1507 | |
1508 for (l = gaim_connections_get_all(); l != NULL; l = l->next) | |
1509 { | |
1510 gc = (GaimConnection *)l->data; | |
1511 account = gaim_connection_get_account(gc); | |
1512 | |
1513 if (!strcmp(gaim_account_get_protocol_id(account), prpl_id)) | |
1514 break; | |
1515 | |
1516 account = NULL; | |
1517 } | |
1518 | |
1519 if (account != NULL) | |
1520 { | |
1521 for (l = list; l != NULL; l = l->next) | |
1522 { | |
1523 gaim_blist_request_add_buddy(account, l->data, | |
1524 (group ? group->name : NULL), | |
1525 alias); | |
1526 } | |
1527 } | |
1528 | |
1529 g_list_foreach(list, (GFunc)g_free, NULL); | |
1530 g_list_free(list); | |
1531 } | |
1532 | |
1533 static gboolean | |
1534 parse_vcard(const char *vcard, GaimGroup *group) | |
1535 { | |
1536 char *temp_vcard; | |
1537 char *s, *c; | |
1538 char *alias = NULL; | |
1539 GList *aims = NULL; | |
1540 GList *icqs = NULL; | |
1541 GList *yahoos = NULL; | |
1542 GList *msns = NULL; | |
1543 GList *jabbers = NULL; | |
1544 | |
1545 s = temp_vcard = g_strdup(vcard); | |
1546 | |
1547 while (*s != '\0' && strncmp(s, "END:vCard", strlen("END:vCard"))) | |
1548 { | |
1549 char *field, *value; | |
1550 | |
1551 field = s; | |
1552 | |
1553 /* Grab the field */ | |
1554 while (*s != '\r' && *s != '\n' && *s != '\0' && *s != ':') | |
1555 s++; | |
1556 | |
1557 if (*s == '\r') s++; | |
1558 if (*s == '\n') | |
1559 { | |
1560 s++; | |
1561 continue; | |
1562 } | |
1563 | |
1564 if (*s != '\0') *s++ = '\0'; | |
1565 | |
1566 if ((c = strchr(field, ';')) != NULL) | |
1567 *c = '\0'; | |
1568 | |
1569 /* Proceed to the end of the line */ | |
1570 value = s; | |
1571 | |
1572 while (*s != '\r' && *s != '\n' && *s != '\0') | |
1573 s++; | |
1574 | |
1575 if (*s == '\r') *s++ = '\0'; | |
1576 if (*s == '\n') *s++ = '\0'; | |
1577 | |
1578 /* We only want to worry about a few fields here. */ | |
1579 if (!strcmp(field, "FN")) | |
1580 alias = g_strdup(value); | |
1581 else if (!strcmp(field, "X-AIM") || !strcmp(field, "X-ICQ") || | |
1582 !strcmp(field, "X-YAHOO") || !strcmp(field, "X-MSN") || | |
1583 !strcmp(field, "X-JABBER")) | |
1584 { | |
1585 char **values = g_strsplit(value, ":", 0); | |
1586 char **im; | |
1587 | |
1588 for (im = values; *im != NULL; im++) | |
1589 { | |
1590 if (!strcmp(field, "X-AIM")) | |
1591 aims = g_list_append(aims, g_strdup(*im)); | |
1592 else if (!strcmp(field, "X-ICQ")) | |
1593 icqs = g_list_append(icqs, g_strdup(*im)); | |
1594 else if (!strcmp(field, "X-YAHOO")) | |
1595 yahoos = g_list_append(yahoos, g_strdup(*im)); | |
1596 else if (!strcmp(field, "X-MSN")) | |
1597 msns = g_list_append(msns, g_strdup(*im)); | |
1598 else if (!strcmp(field, "X-JABBER")) | |
1599 jabbers = g_list_append(jabbers, g_strdup(*im)); | |
1600 } | |
1601 | |
1602 g_strfreev(values); | |
1603 } | |
1604 } | |
1605 | |
1606 g_free(temp_vcard); | |
1607 | |
1608 if (aims == NULL && icqs == NULL && yahoos == NULL && | |
1609 msns == NULL && jabbers == NULL) | |
1610 { | |
1611 if (alias != NULL) | |
1612 g_free(alias); | |
1613 | |
1614 return FALSE; | |
1615 } | |
1616 | |
1617 add_buddies_from_vcard("prpl-oscar", group, aims, alias); | |
1618 add_buddies_from_vcard("prpl-oscar", group, icqs, alias); | |
1619 add_buddies_from_vcard("prpl-yahoo", group, yahoos, alias); | |
1620 add_buddies_from_vcard("prpl-msn", group, msns, alias); | |
1621 add_buddies_from_vcard("prpl-jabber", group, jabbers, alias); | |
1622 | |
1623 if (alias != NULL) | |
1624 g_free(alias); | |
1625 | |
1626 return TRUE; | |
1627 } | |
1628 | |
5228 | 1629 static void gaim_gtk_blist_drag_data_get_cb (GtkWidget *widget, |
1630 GdkDragContext *dc, | |
1631 GtkSelectionData *data, | |
1632 guint info, | |
1633 guint time, | |
1634 gpointer *null) | |
1635 { | |
8089 | 1636 if (data->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE)) |
1637 { | |
5228 | 1638 GtkTreeRowReference *ref = g_object_get_data(G_OBJECT(dc), "gtk-tree-view-source-row"); |
1639 GtkTreePath *sourcerow = gtk_tree_row_reference_get_path(ref); | |
1640 GtkTreeIter iter; | |
1641 GaimBlistNode *node = NULL; | |
1642 GValue val = {0}; | |
5273 | 1643 if(!sourcerow) |
1644 return; | |
5228 | 1645 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, sourcerow); |
1646 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
1647 node = g_value_get_pointer(&val); | |
1648 gtk_selection_data_set (data, | |
1649 gdk_atom_intern ("GAIM_BLIST_NODE", FALSE), | |
1650 8, /* bits */ | |
1651 (void*)&node, | |
1652 sizeof (node)); | |
5273 | 1653 |
5228 | 1654 gtk_tree_path_free(sourcerow); |
1655 } | |
8089 | 1656 else if (data->target == gdk_atom_intern("application/x-im-contact", FALSE)) |
1657 { | |
7706 | 1658 GtkTreeRowReference *ref; |
1659 GtkTreePath *sourcerow; | |
1660 GtkTreeIter iter; | |
1661 GaimBlistNode *node = NULL; | |
1662 GaimBuddy *buddy; | |
1663 GaimConnection *gc; | |
1664 GValue val = {0}; | |
1665 GString *str; | |
1666 const char *protocol; | |
1667 char *mime_str; | |
1668 | |
1669 ref = g_object_get_data(G_OBJECT(dc), "gtk-tree-view-source-row"); | |
1670 sourcerow = gtk_tree_row_reference_get_path(ref); | |
1671 | |
1672 if (!sourcerow) | |
1673 return; | |
1674 | |
1675 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, | |
1676 sourcerow); | |
1677 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), &iter, | |
1678 NODE_COLUMN, &val); | |
1679 | |
1680 node = g_value_get_pointer(&val); | |
1681 | |
1682 if (GAIM_BLIST_NODE_IS_CONTACT(node)) | |
1683 { | |
1684 buddy = gaim_contact_get_priority_buddy((GaimContact *)node); | |
1685 } | |
1686 else if (!GAIM_BLIST_NODE_IS_BUDDY(node)) | |
1687 { | |
1688 gtk_tree_path_free(sourcerow); | |
1689 return; | |
1690 } | |
1691 else | |
1692 { | |
1693 buddy = (GaimBuddy *)node; | |
1694 } | |
1695 | |
1696 gc = gaim_account_get_connection(buddy->account); | |
1697 | |
1698 if (gc == NULL) | |
1699 { | |
1700 gtk_tree_path_free(sourcerow); | |
1701 return; | |
1702 } | |
1703 | |
1704 protocol = | |
1705 GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->list_icon(buddy->account, | |
1706 buddy); | |
1707 | |
1708 str = g_string_new(NULL); | |
1709 g_string_printf(str, | |
1710 "MIME-Version: 1.0\r\n" | |
1711 "Content-Type: application/x-im-contact\r\n" | |
1712 "X-IM-Protocol: %s\r\n" | |
1713 "X-IM-Username: %s\r\n", | |
1714 protocol, | |
1715 buddy->name); | |
1716 | |
1717 if (buddy->alias != NULL) | |
1718 { | |
1719 g_string_append_printf(str, | |
1720 "X-IM-Alias: %s\r\n", | |
1721 buddy->alias); | |
1722 } | |
1723 | |
1724 str = g_string_append(str, "\r\n"); | |
1725 | |
1726 mime_str = g_string_free(str, FALSE); | |
1727 | |
1728 gtk_selection_data_set(data, | |
1729 gdk_atom_intern("application/x-im-contact", FALSE), | |
1730 8, /* bits */ | |
1731 mime_str, | |
1732 strlen(mime_str) + 1); | |
1733 | |
1734 g_free(mime_str); | |
1735 gtk_tree_path_free(sourcerow); | |
1736 } | |
5228 | 1737 } |
1738 | |
1739 static void gaim_gtk_blist_drag_data_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, | |
1740 GtkSelectionData *sd, guint info, guint t) | |
7620 | 1741 { |
5228 | 1742 if (sd->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE) && sd->data) { |
1743 GaimBlistNode *n = NULL; | |
1744 GtkTreePath *path = NULL; | |
1745 GtkTreeViewDropPosition position; | |
1746 memcpy(&n, sd->data, sizeof(n)); | |
1747 if(gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), x, y, &path, &position)) { | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
1748 /* if we're here, I think it means the drop is ok */ |
7642 | 1749 GtkTreeIter iter; |
5228 | 1750 GaimBlistNode *node; |
1751 GValue val = {0}; | |
7620 | 1752 struct _gaim_gtk_blist_node *gtknode; |
1753 | |
1754 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), | |
1755 &iter, path); | |
1756 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), | |
1757 &iter, NODE_COLUMN, &val); | |
5228 | 1758 node = g_value_get_pointer(&val); |
7620 | 1759 gtknode = node->ui_data; |
1760 | |
1761 if (GAIM_BLIST_NODE_IS_CONTACT(n)) { | |
1762 GaimContact *c = (GaimContact*)n; | |
1763 if (GAIM_BLIST_NODE_IS_CONTACT(node) && gtknode->contact_expanded) { | |
1764 gaim_blist_merge_contact(c, node); | |
1765 } else if (GAIM_BLIST_NODE_IS_CONTACT(node) || | |
5234 | 1766 GAIM_BLIST_NODE_IS_CHAT(node)) { |
5228 | 1767 switch(position) { |
1768 case GTK_TREE_VIEW_DROP_AFTER: | |
1769 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
7620 | 1770 gaim_blist_add_contact(c, (GaimGroup*)node->parent, |
1771 node); | |
1772 break; | |
1773 case GTK_TREE_VIEW_DROP_BEFORE: | |
1774 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
1775 gaim_blist_add_contact(c, (GaimGroup*)node->parent, | |
1776 node->prev); | |
1777 break; | |
1778 } | |
1779 } else if(GAIM_BLIST_NODE_IS_GROUP(node)) { | |
1780 gaim_blist_add_contact(c, (GaimGroup*)node, NULL); | |
1781 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
1782 gaim_blist_merge_contact(c, node); | |
1783 } | |
1784 } else if (GAIM_BLIST_NODE_IS_BUDDY(n)) { | |
1785 GaimBuddy *b = (GaimBuddy*)n; | |
1786 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
1787 switch(position) { | |
1788 case GTK_TREE_VIEW_DROP_AFTER: | |
1789 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
1790 gaim_blist_add_buddy(b, (GaimContact*)node->parent, | |
1791 (GaimGroup*)node->parent->parent, node); | |
5228 | 1792 break; |
1793 case GTK_TREE_VIEW_DROP_BEFORE: | |
1794 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
7620 | 1795 gaim_blist_add_buddy(b, (GaimContact*)node->parent, |
1796 (GaimGroup*)node->parent->parent, | |
1797 node->prev); | |
5228 | 1798 break; |
1799 } | |
7620 | 1800 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) { |
1801 gaim_blist_add_buddy(b, NULL, (GaimGroup*)node->parent, | |
1802 NULL); | |
5228 | 1803 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { |
7620 | 1804 gaim_blist_add_buddy(b, NULL, (GaimGroup*)node, NULL); |
1805 } else if (GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
1806 if(gtknode->contact_expanded) { | |
1807 switch(position) { | |
1808 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
1809 case GTK_TREE_VIEW_DROP_AFTER: | |
1810 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
1811 gaim_blist_add_buddy(b, (GaimContact*)node, | |
1812 (GaimGroup*)node->parent, NULL); | |
1813 break; | |
1814 case GTK_TREE_VIEW_DROP_BEFORE: | |
1815 gaim_blist_add_buddy(b, NULL, | |
1816 (GaimGroup*)node->parent, node->prev); | |
1817 break; | |
1818 } | |
1819 } else { | |
1820 switch(position) { | |
1821 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
1822 case GTK_TREE_VIEW_DROP_AFTER: | |
1823 gaim_blist_add_buddy(b, NULL, | |
1824 (GaimGroup*)node->parent, NULL); | |
1825 break; | |
1826 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
1827 case GTK_TREE_VIEW_DROP_BEFORE: | |
1828 gaim_blist_add_buddy(b, NULL, | |
1829 (GaimGroup*)node->parent, node->prev); | |
1830 break; | |
1831 } | |
1832 } | |
5228 | 1833 } |
5234 | 1834 } else if (GAIM_BLIST_NODE_IS_CHAT(n)) { |
7620 | 1835 GaimChat *chat = (GaimChat *)n; |
1836 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
1837 switch(position) { | |
1838 case GTK_TREE_VIEW_DROP_AFTER: | |
1839 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
1840 gaim_blist_add_chat(chat, | |
1841 (GaimGroup*)node->parent->parent, node); | |
1842 break; | |
1843 case GTK_TREE_VIEW_DROP_BEFORE: | |
1844 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
1845 gaim_blist_add_chat(chat, | |
1846 (GaimGroup*)node->parent->parent, | |
1847 node->prev); | |
1848 break; | |
1849 } | |
1850 } else if(GAIM_BLIST_NODE_IS_CONTACT(node) || | |
5234 | 1851 GAIM_BLIST_NODE_IS_CHAT(node)) { |
1852 switch(position) { | |
1853 case GTK_TREE_VIEW_DROP_AFTER: | |
1854 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
7620 | 1855 gaim_blist_add_chat(chat, (GaimGroup*)node->parent, node); |
5234 | 1856 break; |
1857 case GTK_TREE_VIEW_DROP_BEFORE: | |
1858 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
7620 | 1859 gaim_blist_add_chat(chat, (GaimGroup*)node->parent, node->prev); |
5234 | 1860 break; |
1861 } | |
1862 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
7620 | 1863 gaim_blist_add_chat(chat, (GaimGroup*)node, NULL); |
5234 | 1864 } |
5228 | 1865 } else if (GAIM_BLIST_NODE_IS_GROUP(n)) { |
7620 | 1866 GaimGroup *g = (GaimGroup*)n; |
5228 | 1867 if (GAIM_BLIST_NODE_IS_GROUP(node)) { |
1868 switch (position) { | |
1869 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
1870 case GTK_TREE_VIEW_DROP_AFTER: | |
1871 gaim_blist_add_group(g, node); | |
1872 break; | |
1873 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
1874 case GTK_TREE_VIEW_DROP_BEFORE: | |
1875 gaim_blist_add_group(g, node->prev); | |
1876 break; | |
1877 } | |
7620 | 1878 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) { |
1879 gaim_blist_add_group(g, node->parent->parent); | |
1880 } else if(GAIM_BLIST_NODE_IS_CONTACT(node) || | |
5234 | 1881 GAIM_BLIST_NODE_IS_CHAT(node)) { |
5228 | 1882 gaim_blist_add_group(g, node->parent); |
1883 } | |
1884 } | |
1885 | |
1886 gtk_tree_path_free(path); | |
7620 | 1887 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); |
5228 | 1888 } |
1889 } | |
7706 | 1890 else if (sd->target == gdk_atom_intern("application/x-im-contact", |
1891 FALSE) && sd->data) | |
1892 { | |
1893 GaimGroup *group = NULL; | |
1894 GtkTreePath *path = NULL; | |
1895 GtkTreeViewDropPosition position; | |
7712
2823111061ba
[gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents:
7706
diff
changeset
|
1896 GaimAccount *account; |
7706 | 1897 char *protocol = NULL; |
1898 char *username = NULL; | |
1899 char *alias = NULL; | |
1900 | |
1901 if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), | |
1902 x, y, &path, &position)) | |
1903 { | |
1904 GtkTreeIter iter; | |
1905 GaimBlistNode *node; | |
1906 GValue val = {0}; | |
1907 | |
1908 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), | |
1909 &iter, path); | |
1910 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), | |
1911 &iter, NODE_COLUMN, &val); | |
1912 node = g_value_get_pointer(&val); | |
1913 | |
1914 if (GAIM_BLIST_NODE_IS_BUDDY(node)) | |
1915 { | |
1916 group = (GaimGroup *)node->parent->parent; | |
1917 } | |
1918 else if (GAIM_BLIST_NODE_IS_CHAT(node) || | |
1919 GAIM_BLIST_NODE_IS_CONTACT(node)) | |
1920 { | |
1921 group = (GaimGroup *)node->parent; | |
1922 } | |
1923 else if (GAIM_BLIST_NODE_IS_GROUP(node)) | |
1924 { | |
1925 group = (GaimGroup *)node; | |
1926 } | |
1927 } | |
1928 | |
7712
2823111061ba
[gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents:
7706
diff
changeset
|
1929 if (gaim_gtk_parse_x_im_contact(sd->data, FALSE, &account, |
2823111061ba
[gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents:
7706
diff
changeset
|
1930 &protocol, &username, &alias)) |
7706 | 1931 { |
1932 if (account == NULL) | |
1933 { | |
1934 gaim_notify_error(NULL, NULL, | |
1935 _("You are not currently signed on with an account that " | |
1936 "can add that buddy."), NULL); | |
1937 } | |
1938 else | |
1939 { | |
1940 gaim_blist_request_add_buddy(account, username, | |
1941 (group ? group->name : NULL), | |
1942 alias); | |
1943 } | |
1944 } | |
1945 | |
1946 if (username != NULL) g_free(username); | |
1947 if (protocol != NULL) g_free(protocol); | |
1948 if (alias != NULL) g_free(alias); | |
1949 | |
1950 if (path != NULL) | |
1951 gtk_tree_path_free(path); | |
1952 | |
1953 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); | |
1954 } | |
8089 | 1955 else if (sd->target == gdk_atom_intern("text/x-vcard", FALSE) && sd->data) |
1956 { | |
1957 gboolean result; | |
1958 GaimGroup *group = NULL; | |
1959 GtkTreePath *path = NULL; | |
1960 GtkTreeViewDropPosition position; | |
1961 | |
1962 if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), | |
1963 x, y, &path, &position)) | |
1964 { | |
1965 GtkTreeIter iter; | |
1966 GaimBlistNode *node; | |
1967 GValue val = {0}; | |
1968 | |
1969 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), | |
1970 &iter, path); | |
1971 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), | |
1972 &iter, NODE_COLUMN, &val); | |
1973 node = g_value_get_pointer(&val); | |
1974 | |
1975 if (GAIM_BLIST_NODE_IS_BUDDY(node)) | |
1976 { | |
1977 group = (GaimGroup *)node->parent->parent; | |
1978 } | |
1979 else if (GAIM_BLIST_NODE_IS_CHAT(node) || | |
1980 GAIM_BLIST_NODE_IS_CONTACT(node)) | |
1981 { | |
1982 group = (GaimGroup *)node->parent; | |
1983 } | |
1984 else if (GAIM_BLIST_NODE_IS_GROUP(node)) | |
1985 { | |
1986 group = (GaimGroup *)node; | |
1987 } | |
1988 } | |
1989 | |
1990 result = parse_vcard(sd->data, group); | |
1991 | |
1992 gtk_drag_finish(dc, result, (dc->action == GDK_ACTION_MOVE), t); | |
1993 } | |
5228 | 1994 } |
1995 | |
5234 | 1996 static void gaim_gtk_blist_paint_tip(GtkWidget *widget, GdkEventExpose *event, GaimBlistNode *node) |
5228 | 1997 { |
1998 GtkStyle *style; | |
5234 | 1999 GdkPixbuf *pixbuf = gaim_gtk_blist_get_status_icon(node, GAIM_STATUS_ICON_LARGE); |
5228 | 2000 PangoLayout *layout; |
5234 | 2001 char *tooltiptext = gaim_get_tooltip_text(node); |
5228 | 2002 |
7620 | 2003 if(!tooltiptext) |
2004 return; | |
2005 | |
5228 | 2006 layout = gtk_widget_create_pango_layout (gtkblist->tipwindow, NULL); |
2007 pango_layout_set_markup(layout, tooltiptext, strlen(tooltiptext)); | |
2008 pango_layout_set_wrap(layout, PANGO_WRAP_WORD); | |
2009 pango_layout_set_width(layout, 300000); | |
2010 style = gtkblist->tipwindow->style; | |
2011 | |
2012 gtk_paint_flat_box (style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, | |
2013 NULL, gtkblist->tipwindow, "tooltip", 0, 0, -1, -1); | |
2014 | |
2015 #if GTK_CHECK_VERSION(2,2,0) | |
2016 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, pixbuf, | |
2017 0, 0, 4, 4, -1 , -1, GDK_RGB_DITHER_NONE, 0, 0); | |
2018 #else | |
2019 gdk_pixbuf_render_to_drawable(pixbuf, GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, 0, 0, 4, 4, -1, -1, GDK_RGB_DITHER_NONE, 0, 0); | |
2020 #endif | |
2021 | |
2022 gtk_paint_layout (style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, TRUE, | |
2023 NULL, gtkblist->tipwindow, "tooltip", 38, 4, layout); | |
2024 | |
2025 g_object_unref (pixbuf); | |
2026 g_object_unref (layout); | |
2027 g_free(tooltiptext); | |
7620 | 2028 |
7662 | 2029 #ifdef WANT_DROP_SHADOW |
8040 | 2030 shadow_paint(gtkblist, NULL, EAST_SIDE); |
2031 shadow_paint(gtkblist, NULL, SOUTH_SIDE); | |
7620 | 2032 #endif |
2033 | |
5228 | 2034 return; |
2035 } | |
2036 | |
8254 | 2037 static void gaim_gtk_blist_tooltip_destroy() |
2038 { | |
2039 if (gtkblist->tipwindow == NULL) | |
2040 return; | |
2041 | |
2042 gtk_widget_destroy(gtkblist->tipwindow); | |
2043 gtkblist->tipwindow = NULL; | |
2044 #ifdef WANT_DROP_SHADOW | |
2045 gdk_window_set_user_data (gtkblist->east_shadow, NULL); | |
2046 gdk_window_destroy (gtkblist->east_shadow); | |
2047 gtkblist->east_shadow = NULL; | |
2048 | |
2049 gdk_window_set_user_data (gtkblist->south_shadow, NULL); | |
2050 gdk_window_destroy (gtkblist->south_shadow); | |
2051 gtkblist->south_shadow = NULL; | |
2052 #endif | |
2053 } | |
2054 | |
5228 | 2055 static gboolean gaim_gtk_blist_tooltip_timeout(GtkWidget *tv) |
2056 { | |
2057 GtkTreePath *path; | |
2058 GtkTreeIter iter; | |
2059 GaimBlistNode *node; | |
2060 GValue val = {0}; | |
5234 | 2061 int scr_w,scr_h, w, h, x, y; |
2062 PangoLayout *layout; | |
7636 | 2063 gboolean tooltip_top = FALSE; |
5234 | 2064 char *tooltiptext = NULL; |
7636 | 2065 struct _gaim_gtk_blist_node *gtknode; |
7662 | 2066 #ifdef WANT_DROP_SHADOW |
7620 | 2067 GdkWindowAttr attr; |
2068 #endif | |
5228 | 2069 |
7636 | 2070 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), gtkblist->tip_rect.x, gtkblist->tip_rect.y, &path, NULL, NULL, NULL)) |
5228 | 2071 return FALSE; |
2072 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
2073 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
2074 node = g_value_get_pointer(&val); | |
7620 | 2075 |
2076 if(!GAIM_BLIST_NODE_IS_CONTACT(node) && !GAIM_BLIST_NODE_IS_BUDDY(node) | |
2077 && !GAIM_BLIST_NODE_IS_CHAT(node)) | |
5234 | 2078 return FALSE; |
5228 | 2079 |
7636 | 2080 gtknode = node->ui_data; |
2081 | |
7731 | 2082 if (node->child && GAIM_BLIST_NODE_IS_CONTACT(node) && |
8960 | 2083 (((GaimContact*)node)->online > 1 || |
2084 (gaim_blist_node_get_bool(node, "show_offline") && | |
2085 ((GaimContact*)node)->currentsize > 1)) && | |
2086 !gtknode->contact_expanded && | |
7731 | 2087 gaim_prefs_get_bool("/gaim/gtk/blist/auto_expand_contacts")) { |
7719 | 2088 GtkTreeIter i; |
7636 | 2089 gaim_gtk_blist_expand_contact_cb(NULL, node); |
8083 | 2090 tooltip_top = TRUE; /* When the person expands, the new screennames will be below. |
2091 We'll draw the tip above the cursor so that the user can see | |
2092 the included buddies */ | |
2093 | |
7636 | 2094 while (gtk_events_pending()) |
2095 gtk_main_iteration(); | |
2096 | |
8083 | 2097 /* we check to see if we're still supposed to be moving, now that gtk events have |
2098 * happened, and the mouse might not still be in the buddy list */ | |
2099 if(!gtkblist->timeout) { | |
2100 gaim_gtk_blist_collapse_contact_cb(NULL, node); | |
2101 return FALSE; | |
2102 } | |
2103 | |
7636 | 2104 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, >kblist->contact_rect); |
7720 | 2105 gdk_drawable_get_size(GDK_DRAWABLE(tv->window), &(gtkblist->contact_rect.width), NULL); |
7636 | 2106 gtkblist->mouseover_contact = node; |
2107 gtk_tree_path_down (path); | |
7719 | 2108 while (gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &i, path)) { |
7636 | 2109 GdkRectangle rect; |
2110 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, &rect); | |
2111 gtkblist->contact_rect.height += rect.height; | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2112 gtk_tree_path_next(path); |
7636 | 2113 } |
2114 } | |
2115 | |
2116 gtk_tree_path_free(path); | |
2117 | |
5234 | 2118 tooltiptext = gaim_get_tooltip_text(node); |
7620 | 2119 |
2120 if(!tooltiptext) | |
2121 return FALSE; | |
2122 | |
7837 | 2123 if(gtkblist->tipwindow) |
2124 gtk_widget_destroy(gtkblist->tipwindow); | |
5234 | 2125 gtkblist->tipwindow = gtk_window_new(GTK_WINDOW_POPUP); |
2126 gtk_widget_set_app_paintable(gtkblist->tipwindow, TRUE); | |
2127 gtk_window_set_resizable(GTK_WINDOW(gtkblist->tipwindow), FALSE); | |
2128 gtk_widget_set_name(gtkblist->tipwindow, "gtk-tooltips"); | |
2129 g_signal_connect(G_OBJECT(gtkblist->tipwindow), "expose_event", | |
2130 G_CALLBACK(gaim_gtk_blist_paint_tip), node); | |
2131 gtk_widget_ensure_style (gtkblist->tipwindow); | |
7837 | 2132 |
7662 | 2133 #ifdef WANT_DROP_SHADOW |
7620 | 2134 attr.window_type = GDK_WINDOW_TEMP; |
2135 attr.override_redirect = TRUE; | |
2136 attr.x = gtkblist->tipwindow->allocation.x; | |
2137 attr.y = gtkblist->tipwindow->allocation.y; | |
2138 attr.width = gtkblist->tipwindow->allocation.width; | |
2139 attr.height = gtkblist->tipwindow->allocation.height; | |
2140 attr.wclass = GDK_INPUT_OUTPUT; | |
2141 attr.visual = gtk_widget_get_visual (gtkblist->window); | |
2142 attr.colormap = gtk_widget_get_colormap (gtkblist->window); | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2143 |
7620 | 2144 attr.event_mask = gtk_widget_get_events (gtkblist->tipwindow); |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2145 |
7620 | 2146 attr.event_mask |= (GDK_EXPOSURE_MASK | GDK_KEY_PRESS_MASK | |
2147 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK ); | |
7897 | 2148 if(gtkblist->east_shadow) { |
2149 gdk_window_set_user_data (gtkblist->east_shadow, NULL); | |
2150 gdk_window_destroy (gtkblist->east_shadow); | |
2151 } | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2152 gtkblist->east_shadow = gdk_window_new(gtk_widget_get_root_window(gtkblist->tipwindow), &attr, |
7620 | 2153 GDK_WA_NOREDIR | GDK_WA_VISUAL | GDK_WA_COLORMAP); |
2154 gdk_window_set_user_data (gtkblist->east_shadow, gtkblist->tipwindow); | |
2155 gdk_window_set_back_pixmap (gtkblist->east_shadow, NULL, FALSE); | |
2156 | |
7897 | 2157 if(gtkblist->south_shadow) { |
2158 gdk_window_set_user_data (gtkblist->south_shadow, NULL); | |
2159 gdk_window_destroy (gtkblist->south_shadow); | |
2160 } | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2161 gtkblist->south_shadow = gdk_window_new(gtk_widget_get_root_window(gtkblist->tipwindow), &attr, |
7620 | 2162 GDK_WA_NOREDIR | GDK_WA_VISUAL | GDK_WA_COLORMAP); |
2163 gdk_window_set_user_data (gtkblist->south_shadow, gtkblist->tipwindow); | |
2164 gdk_window_set_back_pixmap (gtkblist->south_shadow, NULL, FALSE); | |
2165 #endif | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2166 |
5234 | 2167 layout = gtk_widget_create_pango_layout (gtkblist->tipwindow, NULL); |
2168 pango_layout_set_wrap(layout, PANGO_WRAP_WORD); | |
2169 pango_layout_set_width(layout, 300000); | |
2170 pango_layout_set_markup(layout, tooltiptext, strlen(tooltiptext)); | |
2171 scr_w = gdk_screen_width(); | |
2172 scr_h = gdk_screen_height(); | |
2173 pango_layout_get_size (layout, &w, &h); | |
2174 w = PANGO_PIXELS(w) + 8; | |
2175 h = PANGO_PIXELS(h) + 8; | |
5228 | 2176 |
5234 | 2177 /* 38 is the size of a large status icon plus 4 pixels padding on each side. |
2178 * I should #define this or something */ | |
2179 w = w + 38; | |
2180 h = MAX(h, 38); | |
2181 | |
2182 gdk_window_get_pointer(NULL, &x, &y, NULL); | |
2183 if (GTK_WIDGET_NO_WINDOW(gtkblist->window)) | |
2184 y+=gtkblist->window->allocation.y; | |
2185 | |
2186 x -= ((w >> 1) + 4); | |
5228 | 2187 |
7636 | 2188 if ((y + h + 4) > scr_h || tooltip_top) |
7620 | 2189 y = y - h - 5; |
5234 | 2190 else |
2191 y = y + 6; | |
7620 | 2192 |
7719 | 2193 if (y < 0) |
2194 y = 0; | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2195 |
7719 | 2196 if (y != 0) { |
2197 if ((x + w) > scr_w) | |
2198 x -= (x + w + 5) - scr_w; | |
2199 else if (x < 0) | |
2200 x = 0; | |
2201 } else { | |
2202 x -= (w / 2 + 10); | |
2203 if (x < 0) | |
2204 x += w + 15; | |
2205 } | |
2206 | |
5234 | 2207 g_object_unref (layout); |
2208 g_free(tooltiptext); | |
2209 gtk_widget_set_size_request(gtkblist->tipwindow, w, h); | |
2210 gtk_window_move(GTK_WINDOW(gtkblist->tipwindow), x, y); | |
2211 gtk_widget_show(gtkblist->tipwindow); | |
5228 | 2212 |
7662 | 2213 #ifdef WANT_DROP_SHADOW |
7620 | 2214 map_shadow_windows(gtkblist); |
2215 #endif | |
2216 | |
5228 | 2217 return FALSE; |
2218 } | |
2219 | |
2220 static gboolean gaim_gtk_blist_motion_cb (GtkWidget *tv, GdkEventMotion *event, gpointer null) | |
2221 { | |
2222 GtkTreePath *path; | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2223 int delay; |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2224 |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2225 delay = gaim_prefs_get_int("/gaim/gtk/blist/tooltip_delay"); |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2226 |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2227 if (delay == 0) |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2228 return FALSE; |
8083 | 2229 |
5228 | 2230 if (gtkblist->timeout) { |
7636 | 2231 if ((event->y > gtkblist->tip_rect.y) && ((event->y - gtkblist->tip_rect.height) < gtkblist->tip_rect.y)) |
5228 | 2232 return FALSE; |
2233 /* We've left the cell. Remove the timeout and create a new one below */ | |
8254 | 2234 gaim_gtk_blist_tooltip_destroy(); |
5228 | 2235 g_source_remove(gtkblist->timeout); |
2236 } | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2237 |
5228 | 2238 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL); |
7636 | 2239 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, >kblist->tip_rect); |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2240 |
5228 | 2241 if (path) |
2242 gtk_tree_path_free(path); | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2243 gtkblist->timeout = g_timeout_add(delay, (GSourceFunc)gaim_gtk_blist_tooltip_timeout, tv); |
7636 | 2244 |
2245 if (gtkblist->mouseover_contact) { | |
2246 if ((event->y < gtkblist->contact_rect.y) || ((event->y - gtkblist->contact_rect.height) > gtkblist->contact_rect.y)) { | |
2247 gaim_gtk_blist_collapse_contact_cb(NULL, gtkblist->mouseover_contact); | |
2248 gtkblist->mouseover_contact = NULL; | |
2249 } | |
2250 } | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2251 |
5228 | 2252 return FALSE; |
2253 } | |
2254 | |
2255 static void gaim_gtk_blist_leave_cb (GtkWidget *w, GdkEventCrossing *e, gpointer n) | |
2256 { | |
8083 | 2257 |
5228 | 2258 if (gtkblist->timeout) { |
2259 g_source_remove(gtkblist->timeout); | |
2260 gtkblist->timeout = 0; | |
2261 } | |
8254 | 2262 gaim_gtk_blist_tooltip_destroy(); |
7720 | 2263 |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2264 if (gtkblist->mouseover_contact && |
7720 | 2265 !((e->x > gtkblist->contact_rect.x) && (e->x < (gtkblist->contact_rect.x + gtkblist->contact_rect.width)) && |
2266 (e->y > gtkblist->contact_rect.y) && (e->y < (gtkblist->contact_rect.y + gtkblist->contact_rect.height)))) { | |
2267 gaim_gtk_blist_collapse_contact_cb(NULL, gtkblist->mouseover_contact); | |
7636 | 2268 gtkblist->mouseover_contact = NULL; |
2269 } | |
5228 | 2270 } |
2271 | |
2272 static void | |
2273 toggle_debug(void) | |
2274 { | |
7620 | 2275 gaim_prefs_set_bool("/gaim/gtk/debug/enabled", |
2276 !gaim_prefs_get_bool("/gaim/gtk/debug/enabled")); | |
5228 | 2277 } |
2278 | |
2279 | |
2280 /*************************************************** | |
2281 * Crap * | |
2282 ***************************************************/ | |
2283 static GtkItemFactoryEntry blist_menu[] = | |
2284 { | |
2285 /* Buddies menu */ | |
2286 { N_("/_Buddies"), NULL, NULL, 0, "<Branch>" }, | |
7887 | 2287 { N_("/Buddies/New Instant _Message..."), "<CTL>M", show_im_dialog, 0, "<StockItem>", GAIM_STOCK_IM }, |
8940 | 2288 { N_("/Buddies/Join a _Chat..."), "<CTL>C", gaim_gtk_blist_joinchat_show, 0, "<StockItem>", GAIM_STOCK_CHAT }, |
8143 | 2289 { N_("/Buddies/Get User _Info..."), "<CTL>I", show_info_dialog, 0, "<StockItem>", GAIM_STOCK_INFO }, |
8911 | 2290 { N_("/Buddies/View User _Log..."), "<CTL>L", show_log_dialog, 0, "<StockItem>" }, |
5228 | 2291 { "/Buddies/sep1", NULL, NULL, 0, "<Separator>" }, |
5398 | 2292 { N_("/Buddies/Show _Offline Buddies"), NULL, gaim_gtk_blist_edit_mode_cb, 1, "<CheckItem>"}, |
5228 | 2293 { N_("/Buddies/Show _Empty Groups"), NULL, gaim_gtk_blist_show_empty_groups_cb, 1, "<CheckItem>"}, |
7853 | 2294 { N_("/Buddies/_Add Buddy..."), "<CTL>B", gaim_gtk_blist_add_buddy_cb, 0, "<StockItem>", GTK_STOCK_ADD }, |
2295 { N_("/Buddies/Add C_hat..."), NULL, gaim_gtk_blist_add_chat_cb, 0, "<StockItem>", GTK_STOCK_ADD }, | |
2296 { N_("/Buddies/Add _Group..."), NULL, gaim_blist_request_add_group, 0, "<StockItem>", GTK_STOCK_ADD }, | |
5228 | 2297 { "/Buddies/sep2", NULL, NULL, 0, "<Separator>" }, |
7620 | 2298 { N_("/Buddies/_Signoff"), "<CTL>D", gaim_connections_disconnect_all, 0, "<StockItem>", GAIM_STOCK_SIGN_OFF }, |
2299 { N_("/Buddies/_Quit"), "<CTL>Q", gaim_core_quit, 0, "<StockItem>", GTK_STOCK_QUIT }, | |
5228 | 2300 |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2301 /* Tools */ |
5228 | 2302 { N_("/_Tools"), NULL, NULL, 0, "<Branch>" }, |
2303 { N_("/Tools/_Away"), NULL, NULL, 0, "<Branch>" }, | |
2304 { N_("/Tools/Buddy _Pounce"), NULL, NULL, 0, "<Branch>" }, | |
8845 | 2305 { N_("/Tools/Account Ac_tions"), NULL, NULL, 0, "<Branch>" }, |
8986 | 2306 { N_("/Tools/Pl_ugin Actions"), NULL, NULL, 0, "<Branch>" }, |
5228 | 2307 { "/Tools/sep1", NULL, NULL, 0, "<Separator>" }, |
7620 | 2308 { N_("/Tools/A_ccounts"), "<CTL>A", gaim_gtk_accounts_window_show, 0, "<StockItem>", GAIM_STOCK_ACCOUNTS }, |
7737 | 2309 { N_("/Tools/_File Transfers"), NULL, gaim_show_xfer_dialog, 0, "<StockItem>", GAIM_STOCK_FILE_TRANSFER }, |
8113 | 2310 { N_("/Tools/R_oom List"), NULL, gaim_gtk_roomlist_dialog_show, 0, NULL }, |
7870 | 2311 { N_("/Tools/Pr_eferences"), "<CTL>P", gaim_gtk_prefs_show, 0, "<StockItem>", GTK_STOCK_PREFERENCES }, |
7856 | 2312 { N_("/Tools/Pr_ivacy"), NULL, gaim_gtk_privacy_dialog_show, 0, NULL }, |
5228 | 2313 { "/Tools/sep2", NULL, NULL, 0, "<Separator>" }, |
7620 | 2314 { N_("/Tools/View System _Log"), NULL, gtk_blist_show_systemlog_cb, 0, NULL }, |
5228 | 2315 |
2316 /* Help */ | |
2317 { N_("/_Help"), NULL, NULL, 0, "<Branch>" }, | |
2318 { N_("/Help/Online _Help"), "F1", gtk_blist_show_onlinehelp_cb, 0, "<StockItem>", GTK_STOCK_HELP }, | |
7620 | 2319 { N_("/Help/_Debug Window"), NULL, toggle_debug, 0, NULL }, |
2320 { N_("/Help/_About"), NULL, show_about, 0, "<StockItem>", GAIM_STOCK_ABOUT }, | |
5228 | 2321 }; |
2322 | |
2323 /********************************************************* | |
2324 * Private Utility functions * | |
2325 *********************************************************/ | |
7620 | 2326 static void |
2327 rename_group_cb(GaimGroup *g, const char *new_name) | |
2328 { | |
2329 gaim_blist_rename_group(g, new_name); | |
2330 } | |
2331 | |
9285 | 2332 /* |
2333 * Should disallow empty group names. | |
2334 */ | |
7620 | 2335 static void |
2336 show_rename_group(GtkWidget *unused, GaimGroup *g) | |
2337 { | |
2338 gaim_request_input(NULL, _("Rename Group"), _("New group name"), | |
2339 _("Please enter a new name for the selected group."), | |
8697 | 2340 g->name, FALSE, FALSE, NULL, |
7620 | 2341 _("OK"), G_CALLBACK(rename_group_cb), |
2342 _("Cancel"), NULL, g); | |
2343 } | |
5228 | 2344 |
5234 | 2345 static char *gaim_get_tooltip_text(GaimBlistNode *node) |
5228 | 2346 { |
5237 | 2347 GaimPlugin *prpl; |
2348 GaimPluginProtocolInfo *prpl_info = NULL; | |
5228 | 2349 char *text = NULL; |
7956 | 2350 |
5234 | 2351 if(GAIM_BLIST_NODE_IS_CHAT(node)) { |
7620 | 2352 GaimChat *chat = (GaimChat *)node; |
5237 | 2353 char *name = NULL; |
5274 | 2354 struct proto_chat_entry *pce; |
2355 GList *parts, *tmp; | |
2356 GString *parts_text = g_string_new(""); | |
2357 | |
7956 | 2358 prpl = gaim_find_prpl(gaim_account_get_protocol_id(chat->account)); |
5274 | 2359 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
2360 | |
2361 parts = prpl_info->chat_info(chat->account->gc); | |
5237 | 2362 |
7620 | 2363 name = g_markup_escape_text(gaim_chat_get_name(chat), -1); |
2364 | |
2365 if(g_list_length(gaim_connections_get_all()) > 1) { | |
5274 | 2366 char *account = g_markup_escape_text(chat->account->username, -1); |
2367 g_string_append_printf(parts_text, _("\n<b>Account:</b> %s"), | |
2368 account); | |
2369 g_free(account); | |
5237 | 2370 } |
5274 | 2371 for(tmp = parts; tmp; tmp = tmp->next) { |
7889 | 2372 char *label, *tmp2, *value; |
5274 | 2373 pce = tmp->data; |
5237 | 2374 |
8020 | 2375 if(!pce->secret) { |
2376 | |
2377 tmp2 = g_markup_escape_text(pce->label, -1); | |
2378 label = gaim_text_strip_mnemonic(tmp2); | |
2379 g_free(tmp2); | |
2380 | |
2381 value = g_markup_escape_text(g_hash_table_lookup(chat->components, | |
2382 pce->identifier), -1); | |
2383 | |
2384 g_string_append_printf(parts_text, "\n<b>%s</b> %s", label, value); | |
2385 g_free(label); | |
2386 g_free(value); | |
2387 } | |
5274 | 2388 g_free(pce); |
2389 } | |
2390 g_list_free(parts); | |
2391 | |
2392 text = g_strdup_printf("<span size='larger' weight='bold'>%s</span>%s", | |
2393 name, parts_text->str); | |
2394 g_string_free(parts_text, TRUE); | |
5237 | 2395 g_free(name); |
7620 | 2396 } else if(GAIM_BLIST_NODE_IS_CONTACT(node) || |
2397 GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
2398 GaimBuddy *b; | |
5234 | 2399 char *statustext = NULL; |
7620 | 2400 char *contactaliastext = NULL; |
5234 | 2401 char *aliastext = NULL, *nicktext = NULL; |
7950 | 2402 char *loggedin = NULL, *idletime = NULL; |
2403 char *warning = NULL; | |
5274 | 2404 char *accounttext = NULL; |
5228 | 2405 |
7620 | 2406 if(GAIM_BLIST_NODE_IS_CONTACT(node)) { |
2407 GaimContact *contact = (GaimContact*)node; | |
2408 b = gaim_contact_get_priority_buddy(contact); | |
2409 if(contact->alias) | |
2410 contactaliastext = g_markup_escape_text(contact->alias, -1); | |
2411 } else { | |
2412 b = (GaimBuddy *)node; | |
2413 } | |
2414 | |
7956 | 2415 prpl = gaim_find_prpl(gaim_account_get_protocol_id(b->account)); |
5234 | 2416 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
2417 | |
7620 | 2418 if (prpl_info && prpl_info->tooltip_text) { |
5234 | 2419 const char *end; |
2420 statustext = prpl_info->tooltip_text(b); | |
5228 | 2421 |
5234 | 2422 if(statustext && !g_utf8_validate(statustext, -1, &end)) { |
2423 char *new = g_strndup(statustext, | |
2424 g_utf8_pointer_to_offset(statustext, end)); | |
2425 g_free(statustext); | |
2426 statustext = new; | |
2427 } | |
2428 } | |
2429 | |
2430 if (!statustext && !GAIM_BUDDY_IS_ONLINE(b)) | |
8861 | 2431 statustext = g_strdup(_("\n<b>Status:</b> Offline")); |
5228 | 2432 |
7950 | 2433 if (b->signon > 0) |
2434 loggedin = gaim_str_seconds_to_string(time(NULL) - b->signon); | |
2435 | |
5341 | 2436 if (b->idle > 0) |
7620 | 2437 idletime = gaim_str_seconds_to_string(time(NULL) - b->idle); |
5228 | 2438 |
5234 | 2439 if(b->alias && b->alias[0]) |
2440 aliastext = g_markup_escape_text(b->alias, -1); | |
5228 | 2441 |
5234 | 2442 if(b->server_alias) |
2443 nicktext = g_markup_escape_text(b->server_alias, -1); | |
5228 | 2444 |
5234 | 2445 if (b->evil > 0) |
2446 warning = g_strdup_printf(_("%d%%"), b->evil); | |
5228 | 2447 |
7620 | 2448 if(g_list_length(gaim_connections_get_all()) > 1) |
5274 | 2449 accounttext = g_markup_escape_text(b->account->username, -1); |
2450 | |
5234 | 2451 text = g_strdup_printf("<span size='larger' weight='bold'>%s</span>" |
8592 | 2452 "%s %s" /* Account */ |
7620 | 2453 "%s %s" /* Contact Alias */ |
5438 | 2454 "%s %s" /* Alias */ |
2455 "%s %s" /* Nickname */ | |
8592 | 2456 "%s %s" /* Logged In */ |
2457 "%s %s" /* Idle */ | |
2458 "%s %s" /* Warning */ | |
2459 "%s" /* Status */ | |
5438 | 2460 "%s", |
2461 b->name, | |
2462 accounttext ? _("\n<b>Account:</b>") : "", accounttext ? accounttext : "", | |
7620 | 2463 contactaliastext ? _("\n<b>Contact Alias:</b>") : "", contactaliastext ? contactaliastext : "", |
5438 | 2464 aliastext ? _("\n<b>Alias:</b>") : "", aliastext ? aliastext : "", |
2465 nicktext ? _("\n<b>Nickname:</b>") : "", nicktext ? nicktext : "", | |
7950 | 2466 loggedin ? _("\n<b>Logged In:</b>") : "", loggedin ? loggedin : "", |
5438 | 2467 idletime ? _("\n<b>Idle:</b>") : "", idletime ? idletime : "", |
2468 b->evil ? _("\n<b>Warned:</b>") : "", b->evil ? warning : "", | |
8592 | 2469 statustext ? statustext : "", |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2470 !g_ascii_strcasecmp(b->name, "robflynn") ? _("\n<b>Description:</b> Spooky") : |
7620 | 2471 !g_ascii_strcasecmp(b->name, "seanegn") ? _("\n<b>Status</b>: Awesome") : |
2472 !g_ascii_strcasecmp(b->name, "chipx86") ? _("\n<b>Status</b>: Rockin'") : ""); | |
5234 | 2473 |
2474 if(warning) | |
2475 g_free(warning); | |
7950 | 2476 if(loggedin) |
2477 g_free(loggedin); | |
5234 | 2478 if(idletime) |
2479 g_free(idletime); | |
2480 if(statustext) | |
2481 g_free(statustext); | |
2482 if(nicktext) | |
2483 g_free(nicktext); | |
2484 if(aliastext) | |
2485 g_free(aliastext); | |
5274 | 2486 if(accounttext) |
2487 g_free(accounttext); | |
5234 | 2488 } |
8824 | 2489 gaim_signal_emit(gaim_gtk_blist_get_handle(), |
8817 | 2490 "drawing-tooltip", node, &text); |
5228 | 2491 return text; |
2492 } | |
2493 | |
7620 | 2494 struct _emblem_data { |
2495 char *filename; | |
2496 int x; | |
2497 int y; | |
2498 }; | |
2499 | |
5234 | 2500 GdkPixbuf *gaim_gtk_blist_get_status_icon(GaimBlistNode *node, GaimStatusIconSize size) |
5228 | 2501 { |
7620 | 2502 GdkPixbuf *scale, *status = NULL; |
2503 int i, scalesize = 30; | |
2504 char *filename; | |
5228 | 2505 const char *protoname = NULL; |
7620 | 2506 struct _gaim_gtk_blist_node *gtknode = node->ui_data; |
2507 struct _emblem_data emblems[4] = {{NULL, 15, 15}, {NULL, 0, 15}, | |
2508 {NULL, 0, 0}, {NULL, 15, 0}}; | |
2509 | |
2510 GaimBuddy *buddy = NULL; | |
2511 GaimChat *chat = NULL; | |
2512 | |
2513 if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
2514 if(!gtknode->contact_expanded) | |
2515 buddy = gaim_contact_get_priority_buddy((GaimContact*)node); | |
2516 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
2517 buddy = (GaimBuddy*)node; | |
2518 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) { | |
2519 chat = (GaimChat*)node; | |
2520 } else { | |
5228 | 2521 return NULL; |
5234 | 2522 } |
2523 | |
7620 | 2524 if(buddy || chat) { |
2525 GaimAccount *account; | |
2526 GaimPlugin *prpl; | |
2527 GaimPluginProtocolInfo *prpl_info; | |
2528 | |
2529 if(buddy) | |
2530 account = buddy->account; | |
2531 else | |
2532 account = chat->account; | |
2533 | |
7956 | 2534 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); |
7620 | 2535 if(!prpl) |
2536 return NULL; | |
2537 | |
2538 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
2539 | |
2540 if(prpl_info && prpl_info->list_icon) { | |
2541 protoname = prpl_info->list_icon(account, buddy); | |
2542 } | |
2543 if(prpl_info && prpl_info->list_emblems && buddy) { | |
2544 if(buddy->present != GAIM_BUDDY_SIGNING_OFF) | |
2545 prpl_info->list_emblems(buddy, &emblems[0].filename, | |
2546 &emblems[1].filename, &emblems[2].filename, | |
2547 &emblems[3].filename); | |
2548 } | |
5234 | 2549 } |
5228 | 2550 |
7620 | 2551 if(size == GAIM_STATUS_ICON_SMALL) { |
5228 | 2552 scalesize = 15; |
7620 | 2553 /* So that only the se icon will composite */ |
2554 emblems[1].filename = emblems[2].filename = emblems[3].filename = NULL; | |
5228 | 2555 } |
2556 | |
7620 | 2557 if(buddy && buddy->present == GAIM_BUDDY_SIGNING_ON) { |
2558 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "login.png", NULL); | |
2559 } else if(buddy && buddy->present == GAIM_BUDDY_SIGNING_OFF) { | |
2560 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "logout.png", NULL); | |
2561 } else if(buddy || chat) { | |
5228 | 2562 char *image = g_strdup_printf("%s.png", protoname); |
2563 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
2564 g_free(image); | |
7620 | 2565 } else { |
2566 /* gaim dude */ | |
2567 filename = g_build_filename(DATADIR, "pixmaps", "gaim.png", NULL); | |
5228 | 2568 } |
7620 | 2569 |
2570 status = gdk_pixbuf_new_from_file(filename, NULL); | |
2571 g_free(filename); | |
2572 | |
2573 if(!status) | |
2574 return NULL; | |
2575 | |
2576 scale = gdk_pixbuf_scale_simple(status, scalesize, scalesize, | |
2577 GDK_INTERP_BILINEAR); | |
2578 g_object_unref(status); | |
2579 | |
2580 for(i=0; i<4; i++) { | |
2581 if(emblems[i].filename) { | |
2582 GdkPixbuf *emblem; | |
2583 char *image = g_strdup_printf("%s.png", emblems[i].filename); | |
2584 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
2585 g_free(image); | |
2586 emblem = gdk_pixbuf_new_from_file(filename, NULL); | |
2587 g_free(filename); | |
2588 if(emblem) { | |
2589 if(i == 0 && size == GAIM_STATUS_ICON_SMALL) { | |
2590 gdk_pixbuf_composite(emblem, | |
2591 scale, 5, 5, | |
2592 10, 10, | |
2593 5, 5, | |
2594 .6, .6, | |
2595 GDK_INTERP_BILINEAR, | |
2596 255); | |
2597 } else { | |
2598 gdk_pixbuf_composite(emblem, | |
2599 scale, emblems[i].x, emblems[i].y, | |
2600 15, 15, | |
2601 emblems[i].x, emblems[i].y, | |
2602 1, 1, | |
2603 GDK_INTERP_BILINEAR, | |
2604 255); | |
2605 } | |
2606 g_object_unref(emblem); | |
2607 } | |
5228 | 2608 } |
2609 } | |
7620 | 2610 |
2611 if(buddy) { | |
2612 if(buddy->present == GAIM_BUDDY_OFFLINE) | |
2613 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE); | |
2614 else if(buddy->idle && | |
2615 gaim_prefs_get_bool("/gaim/gtk/blist/grey_idle_buddies")) | |
2616 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.25, FALSE); | |
5228 | 2617 } |
7620 | 2618 |
5228 | 2619 return scale; |
2620 } | |
2621 | |
7620 | 2622 static GdkPixbuf *gaim_gtk_blist_get_buddy_icon(GaimBuddy *b) |
5228 | 2623 { |
7620 | 2624 const char *file; |
5228 | 2625 GdkPixbuf *buf, *ret; |
2626 | |
7620 | 2627 if (!gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")) |
5228 | 2628 return NULL; |
2629 | |
7693 | 2630 if ((file = gaim_blist_node_get_string((GaimBlistNode*)b, "buddy_icon")) == NULL) |
5228 | 2631 return NULL; |
2632 | |
2633 buf = gdk_pixbuf_new_from_file(file, NULL); | |
2634 | |
2635 | |
2636 if (buf) { | |
2637 if (!GAIM_BUDDY_IS_ONLINE(b)) | |
2638 gdk_pixbuf_saturate_and_pixelate(buf, buf, 0.0, FALSE); | |
7620 | 2639 if (b->idle && gaim_prefs_get_bool("/gaim/gtk/blist/grey_idle_buddies")) |
5228 | 2640 gdk_pixbuf_saturate_and_pixelate(buf, buf, 0.25, FALSE); |
2641 | |
2642 ret = gdk_pixbuf_scale_simple(buf,30,30, GDK_INTERP_BILINEAR); | |
2643 g_object_unref(G_OBJECT(buf)); | |
2644 return ret; | |
2645 } | |
2646 return NULL; | |
2647 } | |
2648 | |
7620 | 2649 static gchar *gaim_gtk_blist_get_name_markup(GaimBuddy *b, gboolean selected) |
5228 | 2650 { |
7620 | 2651 const char *name; |
2652 char *esc, *text = NULL; | |
5228 | 2653 GaimPlugin *prpl; |
2654 GaimPluginProtocolInfo *prpl_info = NULL; | |
7620 | 2655 GaimContact *contact; |
2656 struct _gaim_gtk_blist_node *gtkcontactnode = NULL; | |
5228 | 2657 int ihrs, imin; |
2658 char *idletime = NULL, *warning = NULL, *statustext = NULL; | |
2659 time_t t; | |
7620 | 2660 /* XXX Clean up this crap */ |
2661 | |
2662 contact = (GaimContact*)((GaimBlistNode*)b)->parent; | |
2663 if(contact) | |
2664 gtkcontactnode = ((GaimBlistNode*)contact)->ui_data; | |
2665 | |
2666 if(gtkcontactnode && !gtkcontactnode->contact_expanded && contact->alias) | |
2667 name = contact->alias; | |
2668 else | |
2669 name = gaim_get_buddy_alias(b); | |
2670 esc = g_markup_escape_text(name, strlen(name)); | |
2671 | |
7956 | 2672 prpl = gaim_find_prpl(gaim_account_get_protocol_id(b->account)); |
5228 | 2673 |
2674 if (prpl != NULL) | |
2675 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
2676 | |
7620 | 2677 if (!gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")) { |
2678 if ((b->idle && !selected && | |
2679 gaim_prefs_get_bool("/gaim/gtk/blist/grey_idle_buddies")) || | |
2680 !GAIM_BUDDY_IS_ONLINE(b)) { | |
2681 if (selected) | |
2682 text = g_strdup(esc); | |
2683 else | |
2684 text = g_strdup_printf("<span color='dim grey'>%s</span>", | |
2685 esc); | |
5228 | 2686 g_free(esc); |
2687 return text; | |
7620 | 2688 } |
2689 else { | |
5228 | 2690 return esc; |
2691 } | |
2692 } | |
2693 | |
2694 time(&t); | |
2695 ihrs = (t - b->idle) / 3600; | |
2696 imin = ((t - b->idle) / 60) % 60; | |
2697 | |
8122
36674144c510
[gaim-migrate @ 8826]
Christian Hammond <chipx86@chipx86.com>
parents:
8113
diff
changeset
|
2698 if (prpl_info && prpl_info->status_text && b->account->gc) { |
5228 | 2699 char *tmp = prpl_info->status_text(b); |
2700 const char *end; | |
2701 | |
2702 if(tmp && !g_utf8_validate(tmp, -1, &end)) { | |
2703 char *new = g_strndup(tmp, | |
2704 g_utf8_pointer_to_offset(tmp, end)); | |
2705 g_free(tmp); | |
2706 tmp = new; | |
2707 } | |
2708 | |
2709 if(tmp) { | |
2710 char buf[32]; | |
2711 char *c = tmp; | |
2712 int length = 0, vis=0; | |
2713 gboolean inside = FALSE; | |
2714 g_strdelimit(tmp, "\n", ' '); | |
7620 | 2715 gaim_str_strip_cr(tmp); |
5228 | 2716 |
2717 while(*c && vis < 20) { | |
2718 if(*c == '&') | |
2719 inside = TRUE; | |
2720 else if(*c == ';') | |
2721 inside = FALSE; | |
2722 if(!inside) | |
2723 vis++; | |
7620 | 2724 c = g_utf8_next_char(c); /* this is fun */ |
5228 | 2725 } |
2726 | |
7620 | 2727 length = c - tmp; |
2728 | |
5228 | 2729 if(vis == 20) |
2730 g_snprintf(buf, sizeof(buf), "%%.%ds...", length); | |
2731 else | |
2732 g_snprintf(buf, sizeof(buf), "%%s "); | |
2733 | |
2734 statustext = g_strdup_printf(buf, tmp); | |
2735 | |
2736 g_free(tmp); | |
2737 } | |
2738 } | |
2739 | |
7620 | 2740 if (b->idle > 0 && |
2741 gaim_prefs_get_bool("/gaim/gtk/blist/show_idle_time")) { | |
5228 | 2742 if (ihrs) |
2743 idletime = g_strdup_printf(_("Idle (%dh%02dm) "), ihrs, imin); | |
2744 else | |
2745 idletime = g_strdup_printf(_("Idle (%dm) "), imin); | |
2746 } | |
2747 | |
7620 | 2748 if (b->evil > 0 && |
2749 gaim_prefs_get_bool("/gaim/gtk/blist/show_warning_level")) | |
5228 | 2750 warning = g_strdup_printf(_("Warned (%d%%) "), b->evil); |
2751 | |
2752 if(!GAIM_BUDDY_IS_ONLINE(b) && !statustext) | |
7620 | 2753 statustext = g_strdup(_("Offline ")); |
2754 | |
2755 if (b->idle && !selected && | |
2756 gaim_prefs_get_bool("/gaim/gtk/blist/grey_idle_buddies")) { | |
2757 | |
5228 | 2758 text = g_strdup_printf("<span color='dim grey'>%s</span>\n" |
2759 "<span color='dim grey' size='smaller'>%s%s%s</span>", | |
2760 esc, | |
2761 statustext != NULL ? statustext : "", | |
2762 idletime != NULL ? idletime : "", | |
2763 warning != NULL ? warning : ""); | |
7620 | 2764 } else if (statustext == NULL && idletime == NULL && warning == NULL && |
2765 GAIM_BUDDY_IS_ONLINE(b)) { | |
5228 | 2766 text = g_strdup(esc); |
2767 } else { | |
2768 text = g_strdup_printf("%s\n" | |
2769 "<span %s size='smaller'>%s%s%s</span>", esc, | |
2770 selected ? "" : "color='dim grey'", | |
2771 statustext != NULL ? statustext : "", | |
7620 | 2772 idletime != NULL ? idletime : "", |
5228 | 2773 warning != NULL ? warning : ""); |
2774 } | |
2775 if (idletime) | |
2776 g_free(idletime); | |
2777 if (warning) | |
2778 g_free(warning); | |
2779 if (statustext) | |
2780 g_free(statustext); | |
2781 if (esc) | |
2782 g_free(esc); | |
2783 | |
2784 return text; | |
2785 } | |
2786 | |
2787 static void gaim_gtk_blist_restore_position() | |
2788 { | |
7620 | 2789 int blist_x, blist_y, blist_width, blist_height; |
2790 | |
2791 blist_width = gaim_prefs_get_int("/gaim/gtk/blist/width"); | |
2792 | |
2793 /* if the window exists, is hidden, we're saving positions, and the | |
2794 * position is sane... */ | |
2795 if (gtkblist && gtkblist->window && | |
2796 !GTK_WIDGET_VISIBLE(gtkblist->window) && blist_width != 0) { | |
2797 | |
2798 blist_x = gaim_prefs_get_int("/gaim/gtk/blist/x"); | |
2799 blist_y = gaim_prefs_get_int("/gaim/gtk/blist/y"); | |
2800 blist_height = gaim_prefs_get_int("/gaim/gtk/blist/height"); | |
2801 | |
5228 | 2802 /* ...check position is on screen... */ |
7620 | 2803 if (blist_x >= gdk_screen_width()) |
2804 blist_x = gdk_screen_width() - 100; | |
2805 else if (blist_x + blist_width < 0) | |
2806 blist_x = 100; | |
2807 | |
2808 if (blist_y >= gdk_screen_height()) | |
2809 blist_y = gdk_screen_height() - 100; | |
2810 else if (blist_y + blist_height < 0) | |
2811 blist_y = 100; | |
2812 | |
5228 | 2813 /* ...and move it back. */ |
7620 | 2814 gtk_window_move(GTK_WINDOW(gtkblist->window), blist_x, blist_y); |
2815 gtk_window_resize(GTK_WINDOW(gtkblist->window), blist_width, blist_height); | |
5228 | 2816 } |
2817 } | |
2818 | |
7620 | 2819 static gboolean gaim_gtk_blist_refresh_timer(GaimBuddyList *list) |
5228 | 2820 { |
7620 | 2821 GaimBlistNode *gnode, *cnode; |
2822 | |
2823 for(gnode = list->root; gnode; gnode = gnode->next) { | |
2824 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
5234 | 2825 continue; |
7620 | 2826 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
2827 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
2828 GaimBuddy *buddy = gaim_contact_get_priority_buddy((GaimContact*)cnode); | |
2829 if(buddy && buddy->idle) | |
2830 gaim_gtk_blist_update(list, cnode); | |
2831 } | |
5228 | 2832 } |
2833 } | |
2834 | |
2835 /* keep on going */ | |
2836 return TRUE; | |
2837 } | |
2838 | |
7620 | 2839 static void gaim_gtk_blist_hide_node(GaimBuddyList *list, GaimBlistNode *node) |
5260 | 2840 { |
2841 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; | |
2842 GtkTreeIter iter; | |
2843 | |
2844 if (!gtknode || !gtknode->row || !gtkblist) | |
2845 return; | |
2846 | |
2847 if(gtkblist->selected_node == node) | |
2848 gtkblist->selected_node = NULL; | |
2849 | |
2850 if (get_iter_from_node(node, &iter)) { | |
2851 gtk_tree_store_remove(gtkblist->treemodel, &iter); | |
7620 | 2852 if(GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_BUDDY(node) |
2853 || GAIM_BLIST_NODE_IS_CHAT(node)) { | |
5260 | 2854 gaim_gtk_blist_update(list, node->parent); |
2855 } | |
2856 } | |
2857 gtk_tree_row_reference_free(gtknode->row); | |
2858 gtknode->row = NULL; | |
2859 } | |
2860 | |
7620 | 2861 static void |
8937 | 2862 sign_on_off_cb(GaimConnection *gc, GaimBuddyList *blist) |
7620 | 2863 { |
8259
4f9f68ab8770
[gaim-migrate @ 8982]
Christian Hammond <chipx86@chipx86.com>
parents:
8254
diff
changeset
|
2864 GaimGtkBuddyList *gtkblist = GAIM_GTK_BLIST(blist); |
8937 | 2865 GtkWidget *widget; |
8259
4f9f68ab8770
[gaim-migrate @ 8982]
Christian Hammond <chipx86@chipx86.com>
parents:
8254
diff
changeset
|
2866 |
7620 | 2867 gaim_gtk_blist_update_protocol_actions(); |
8235 | 2868 gaim_gtkpounce_menu_build(gtkblist->bpmenu); |
8937 | 2869 |
8940 | 2870 /* Make menu items sensitive/insensitive where appropriate */ |
2871 widget = gtk_item_factory_get_widget(gtkblist->ift, N_("/Buddies/Join a Chat...")); | |
2872 gtk_widget_set_sensitive(widget, gaim_gtk_blist_joinchat_is_showable()); | |
2873 | |
8937 | 2874 widget = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Room List")); |
8939 | 2875 gtk_widget_set_sensitive(widget, gaim_gtk_roomlist_is_showable()); |
8938 | 2876 |
2877 widget = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Privacy")); | |
2878 gtk_widget_set_sensitive(widget, gaim_gtk_privacy_is_showable()); | |
7620 | 2879 } |
2880 | |
8986 | 2881 |
2882 static void | |
2883 plugin_changed_cb(GaimPlugin *p, gpointer *data) | |
2884 { | |
2885 gaim_gtk_blist_update_plugin_actions(); | |
2886 } | |
2887 | |
2888 | |
7620 | 2889 /* this is called on all sorts of signals, and we have no reason to pass |
2890 * it anything, so it remains without arguments. If you need anything | |
2891 * more specific, do as below, and create another callback that calls | |
2892 * this */ | |
2893 static void | |
2894 raise_on_events_cb() | |
2895 { | |
2896 if(gtkblist && gtkblist->window && | |
2897 gaim_prefs_get_bool("/gaim/gtk/blist/raise_on_events")) { | |
2898 gtk_widget_show(gtkblist->window); | |
2899 gtk_window_deiconify(GTK_WINDOW(gtkblist->window)); | |
2900 gdk_window_raise(gtkblist->window->window); | |
2901 } | |
2902 } | |
2903 | |
5228 | 2904 /********************************************************************************** |
2905 * Public API Functions * | |
2906 **********************************************************************************/ | |
7620 | 2907 static void gaim_gtk_blist_new_list(GaimBuddyList *blist) |
5228 | 2908 { |
7620 | 2909 GaimGtkBuddyList *gtkblist; |
2910 | |
2911 gtkblist = g_new0(GaimGtkBuddyList, 1); | |
2912 blist->ui_data = gtkblist; | |
2913 | |
2914 /* All of these signal handlers are for the "Raise on Events" option */ | |
2915 gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-on", | |
2916 gtkblist, GAIM_CALLBACK(raise_on_events_cb), NULL); | |
2917 gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-off", | |
2918 gtkblist, GAIM_CALLBACK(raise_on_events_cb), NULL); | |
5228 | 2919 } |
2920 | |
5256 | 2921 static void gaim_gtk_blist_new_node(GaimBlistNode *node) |
2922 { | |
2923 node->ui_data = g_new0(struct _gaim_gtk_blist_node, 1); | |
2924 } | |
2925 | |
5228 | 2926 void gaim_gtk_blist_update_columns() |
2927 { | |
2928 if(!gtkblist) | |
2929 return; | |
2930 | |
7620 | 2931 if (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")) { |
5228 | 2932 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, TRUE); |
2933 gtk_tree_view_column_set_visible(gtkblist->idle_column, FALSE); | |
2934 gtk_tree_view_column_set_visible(gtkblist->warning_column, FALSE); | |
2935 } else { | |
7620 | 2936 gtk_tree_view_column_set_visible(gtkblist->idle_column, |
2937 gaim_prefs_get_bool("/gaim/gtk/blist/show_idle_time")); | |
2938 gtk_tree_view_column_set_visible(gtkblist->warning_column, | |
2939 gaim_prefs_get_bool("/gaim/gtk/blist/show_warning_level")); | |
5228 | 2940 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, FALSE); |
2941 } | |
2942 } | |
2943 | |
8089 | 2944 enum {DRAG_BUDDY, DRAG_ROW, DRAG_VCARD}; |
5228 | 2945 |
2946 static char * | |
2947 item_factory_translate_func (const char *path, gpointer func_data) | |
2948 { | |
7620 | 2949 return _((char *)path); |
5228 | 2950 } |
2951 | |
5422 | 2952 void gaim_gtk_blist_setup_sort_methods() |
2953 { | |
7620 | 2954 gaim_gtk_blist_sort_method_reg("none", _("None"), sort_method_none); |
2955 #if GTK_CHECK_VERSION(2,2,1) | |
2956 gaim_gtk_blist_sort_method_reg("alphabetical", _("Alphabetical"), sort_method_alphabetical); | |
2957 gaim_gtk_blist_sort_method_reg("status", _("By status"), sort_method_status); | |
2958 gaim_gtk_blist_sort_method_reg("log_size", _("By log size"), sort_method_log); | |
2959 #endif | |
2960 gaim_gtk_blist_sort_method_set(gaim_prefs_get_string("/gaim/gtk/blist/sort_type")); | |
2961 } | |
2962 | |
2963 static void _prefs_change_redo_list() { | |
2964 redo_buddy_list(gaim_get_blist(), TRUE); | |
2965 } | |
2966 | |
2967 static void _prefs_change_sort_method(const char *pref_name, GaimPrefType type, | |
2968 gpointer val, gpointer data) { | |
2969 if(!strcmp(pref_name, "/gaim/gtk/blist/sort_type")) | |
2970 gaim_gtk_blist_sort_method_set(val); | |
2971 } | |
2972 | |
2973 static void gaim_gtk_blist_show(GaimBuddyList *list) | |
5228 | 2974 { |
2975 GtkCellRenderer *rend; | |
2976 GtkTreeViewColumn *column; | |
2977 GtkWidget *sw; | |
2978 GtkWidget *button; | |
2979 GtkSizeGroup *sg; | |
2980 GtkAccelGroup *accel_group; | |
2981 GtkTreeSelection *selection; | |
2982 GtkTargetEntry gte[] = {{"GAIM_BLIST_NODE", GTK_TARGET_SAME_APP, DRAG_ROW}, | |
8089 | 2983 {"application/x-im-contact", 0, DRAG_BUDDY}, |
2984 {"text/x-vcard", 0, DRAG_VCARD }}; | |
5228 | 2985 |
2986 if (gtkblist && gtkblist->window) { | |
2987 gtk_widget_show(gtkblist->window); | |
2988 return; | |
2989 } | |
2990 | |
2991 gtkblist = GAIM_GTK_BLIST(list); | |
2992 | |
2993 gtkblist->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
2994 gtk_window_set_role(GTK_WINDOW(gtkblist->window), "buddy_list"); | |
2995 gtk_window_set_title(GTK_WINDOW(gtkblist->window), _("Buddy List")); | |
2996 | |
2997 GTK_WINDOW(gtkblist->window)->allow_shrink = TRUE; | |
2998 | |
2999 gtkblist->vbox = gtk_vbox_new(FALSE, 0); | |
3000 gtk_container_add(GTK_CONTAINER(gtkblist->window), gtkblist->vbox); | |
3001 | |
3002 g_signal_connect(G_OBJECT(gtkblist->window), "delete_event", G_CALLBACK(gtk_blist_delete_cb), NULL); | |
3003 g_signal_connect(G_OBJECT(gtkblist->window), "configure_event", G_CALLBACK(gtk_blist_configure_cb), NULL); | |
3004 g_signal_connect(G_OBJECT(gtkblist->window), "visibility_notify_event", G_CALLBACK(gtk_blist_visibility_cb), NULL); | |
3005 gtk_widget_add_events(gtkblist->window, GDK_VISIBILITY_NOTIFY_MASK); | |
3006 | |
3007 /******************************* Menu bar *************************************/ | |
3008 accel_group = gtk_accel_group_new(); | |
3009 gtk_window_add_accel_group(GTK_WINDOW (gtkblist->window), accel_group); | |
3010 g_object_unref(accel_group); | |
5427 | 3011 gtkblist->ift = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GaimMain>", accel_group); |
3012 gtk_item_factory_set_translate_func (gtkblist->ift, | |
5228 | 3013 item_factory_translate_func, |
3014 NULL, NULL); | |
5427 | 3015 gtk_item_factory_create_items(gtkblist->ift, sizeof(blist_menu) / sizeof(*blist_menu), |
5228 | 3016 blist_menu, NULL); |
7620 | 3017 gaim_gtk_load_accels(); |
3018 g_signal_connect(G_OBJECT(accel_group), "accel-changed", | |
3019 G_CALLBACK(gaim_gtk_save_accels_cb), NULL); | |
5427 | 3020 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtk_item_factory_get_widget(gtkblist->ift, "<GaimMain>"), FALSE, FALSE, 0); |
5228 | 3021 |
5427 | 3022 awaymenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Away")); |
5228 | 3023 do_away_menu(); |
3024 | |
5427 | 3025 gtkblist->bpmenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Buddy Pounce")); |
5228 | 3026 gaim_gtkpounce_menu_build(gtkblist->bpmenu); |
3027 | |
8844 | 3028 protomenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Account Actions")); |
7620 | 3029 gaim_gtk_blist_update_protocol_actions(); |
8986 | 3030 |
3031 pluginmenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Plugin Actions")); | |
3032 gaim_gtk_blist_update_plugin_actions(); | |
5228 | 3033 /****************************** GtkTreeView **********************************/ |
3034 sw = gtk_scrolled_window_new(NULL,NULL); | |
3035 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); | |
3036 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
3037 | |
7620 | 3038 gtkblist->treemodel = gtk_tree_store_new(BLIST_COLUMNS, |
3039 GDK_TYPE_PIXBUF, G_TYPE_BOOLEAN, G_TYPE_STRING, | |
3040 G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_POINTER); | |
5228 | 3041 |
3042 gtkblist->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(gtkblist->treemodel)); | |
3043 gtk_widget_set_size_request(gtkblist->treeview, -1, 200); | |
9176 | 3044 gtk_widget_set_name(gtkblist->treeview, "gaim_gtkblist_treeview"); |
5228 | 3045 |
3046 /* Set up selection stuff */ | |
3047 | |
3048 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)); | |
3049 g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(gaim_gtk_blist_selection_changed), NULL); | |
3050 | |
3051 | |
3052 /* Set up dnd */ | |
7650 | 3053 gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(gtkblist->treeview), |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
3054 GDK_BUTTON1_MASK, gte, 3, |
7650 | 3055 GDK_ACTION_COPY); |
3056 gtk_tree_view_enable_model_drag_dest(GTK_TREE_VIEW(gtkblist->treeview), | |
8089 | 3057 gte, 3, |
7650 | 3058 GDK_ACTION_COPY | GDK_ACTION_MOVE); |
7636 | 3059 |
3060 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-received", G_CALLBACK(gaim_gtk_blist_drag_data_rcv_cb), NULL); | |
5228 | 3061 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-get", G_CALLBACK(gaim_gtk_blist_drag_data_get_cb), NULL); |
3062 | |
3063 /* Tooltips */ | |
3064 g_signal_connect(G_OBJECT(gtkblist->treeview), "motion-notify-event", G_CALLBACK(gaim_gtk_blist_motion_cb), NULL); | |
3065 g_signal_connect(G_OBJECT(gtkblist->treeview), "leave-notify-event", G_CALLBACK(gaim_gtk_blist_leave_cb), NULL); | |
3066 | |
3067 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(gtkblist->treeview), FALSE); | |
3068 | |
3069 column = gtk_tree_view_column_new (); | |
3070 | |
3071 rend = gtk_cell_renderer_pixbuf_new(); | |
3072 gtk_tree_view_column_pack_start (column, rend, FALSE); | |
7620 | 3073 gtk_tree_view_column_set_attributes (column, rend, |
5228 | 3074 "pixbuf", STATUS_ICON_COLUMN, |
3075 "visible", STATUS_ICON_VISIBLE_COLUMN, | |
3076 NULL); | |
3077 g_object_set(rend, "xalign", 0.0, "ypad", 0, NULL); | |
3078 | |
3079 rend = gtk_cell_renderer_text_new(); | |
3080 gtk_tree_view_column_pack_start (column, rend, TRUE); | |
7620 | 3081 gtk_tree_view_column_set_attributes (column, rend, |
5228 | 3082 "markup", NAME_COLUMN, |
3083 NULL); | |
3084 g_object_set(rend, "ypad", 0, "yalign", 0.5, NULL); | |
3085 | |
3086 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); | |
3087 | |
3088 rend = gtk_cell_renderer_text_new(); | |
3089 gtkblist->warning_column = gtk_tree_view_column_new_with_attributes("Warning", rend, "markup", WARNING_COLUMN, NULL); | |
3090 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->warning_column); | |
3091 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); | |
3092 | |
3093 rend = gtk_cell_renderer_text_new(); | |
3094 gtkblist->idle_column = gtk_tree_view_column_new_with_attributes("Idle", rend, "markup", IDLE_COLUMN, NULL); | |
3095 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->idle_column); | |
3096 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); | |
3097 | |
3098 rend = gtk_cell_renderer_pixbuf_new(); | |
3099 gtkblist->buddy_icon_column = gtk_tree_view_column_new_with_attributes("Buddy Icon", rend, "pixbuf", BUDDY_ICON_COLUMN, NULL); | |
3100 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); | |
3101 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->buddy_icon_column); | |
3102 | |
3103 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-activated", G_CALLBACK(gtk_blist_row_activated_cb), NULL); | |
3104 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-expanded", G_CALLBACK(gtk_blist_row_expanded_cb), NULL); | |
3105 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-collapsed", G_CALLBACK(gtk_blist_row_collapsed_cb), NULL); | |
3106 g_signal_connect(G_OBJECT(gtkblist->treeview), "button-press-event", G_CALLBACK(gtk_blist_button_press_cb), NULL); | |
7620 | 3107 g_signal_connect(G_OBJECT(gtkblist->treeview), "key-press-event", G_CALLBACK(gtk_blist_key_press_cb), NULL); |
8143 | 3108 g_signal_connect(G_OBJECT(gtkblist->treeview), "popup-menu", G_CALLBACK(gaim_gtk_blist_popup_menu_cb), NULL); |
5228 | 3109 |
5419 | 3110 /* Enable CTRL+F searching */ |
3111 gtk_tree_view_set_search_column(GTK_TREE_VIEW(gtkblist->treeview), NAME_COLUMN); | |
3112 | |
5228 | 3113 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), sw, TRUE, TRUE, 0); |
3114 gtk_container_add(GTK_CONTAINER(sw), gtkblist->treeview); | |
3115 gaim_gtk_blist_update_columns(); | |
3116 | |
3117 /* set the Show Offline Buddies option. must be done | |
3118 * after the treeview or faceprint gets mad. -Robot101 | |
3119 */ | |
5427 | 3120 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Buddies/Show Offline Buddies"))), |
7620 | 3121 gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies")); |
5427 | 3122 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Buddies/Show Empty Groups"))), |
7620 | 3123 gaim_prefs_get_bool("/gaim/gtk/blist/show_empty_groups")); |
5228 | 3124 |
3125 /* OK... let's show this bad boy. */ | |
3126 gaim_gtk_blist_refresh(list); | |
3127 gaim_gtk_blist_restore_position(); | |
3128 gtk_widget_show_all(gtkblist->window); | |
3129 | |
3130 /**************************** Button Box **************************************/ | |
3131 /* add this afterwards so it doesn't force up the width of the window */ | |
3132 | |
3133 gtkblist->tooltips = gtk_tooltips_new(); | |
3134 | |
3135 sg = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); | |
3136 gtkblist->bbox = gtk_hbox_new(TRUE, 0); | |
3137 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtkblist->bbox, FALSE, FALSE, 0); | |
3138 gtk_widget_show(gtkblist->bbox); | |
3139 | |
8137 | 3140 button = gaim_pixbuf_button_from_stock(_("I_M"), GAIM_STOCK_IM, GAIM_BUTTON_VERTICAL); |
5228 | 3141 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); |
3142 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
3143 gtk_size_group_add_widget(sg, button); | |
3144 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_im_cb), | |
3145 gtkblist->treeview); | |
3146 gtk_tooltips_set_tip(GTK_TOOLTIPS(gtkblist->tooltips), button, _("Send a message to the selected buddy"), NULL); | |
3147 gtk_widget_show(button); | |
3148 | |
8137 | 3149 button = gaim_pixbuf_button_from_stock(_("Get _Info"), GAIM_STOCK_INFO, GAIM_BUTTON_VERTICAL); |
5228 | 3150 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); |
3151 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
3152 gtk_size_group_add_widget(sg, button); | |
3153 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_info_cb), | |
3154 gtkblist->treeview); | |
3155 gtk_tooltips_set_tip(GTK_TOOLTIPS(gtkblist->tooltips), button, _("Get information on the selected buddy"), NULL); | |
3156 gtk_widget_show(button); | |
3157 | |
8137 | 3158 button = gaim_pixbuf_button_from_stock(_("_Chat"), GAIM_STOCK_CHAT, GAIM_BUTTON_VERTICAL); |
5228 | 3159 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); |
3160 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
3161 gtk_size_group_add_widget(sg, button); | |
5234 | 3162 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_chat_cb), gtkblist->treeview); |
5228 | 3163 gtk_tooltips_set_tip(GTK_TOOLTIPS(gtkblist->tooltips), button, _("Join a chat room"), NULL); |
3164 gtk_widget_show(button); | |
3165 | |
8137 | 3166 button = gaim_pixbuf_button_from_stock(_("_Away"), GAIM_STOCK_ICON_AWAY, GAIM_BUTTON_VERTICAL); |
5228 | 3167 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); |
3168 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
3169 gtk_size_group_add_widget(sg, button); | |
3170 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_away_cb), NULL); | |
3171 gtk_tooltips_set_tip(GTK_TOOLTIPS(gtkblist->tooltips), button, _("Set an away message"), NULL); | |
3172 gtk_widget_show(button); | |
3173 | |
3174 /* this will show the right image/label widgets for us */ | |
3175 gaim_gtk_blist_update_toolbar(); | |
3176 | |
3177 /* start the refresh timer */ | |
7620 | 3178 if (gaim_prefs_get_bool("/gaim/gtk/blist/show_idle_time") || |
3179 gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")) { | |
3180 | |
3181 gtkblist->refresh_timer = g_timeout_add(30000, | |
3182 (GSourceFunc)gaim_gtk_blist_refresh_timer, list); | |
3183 } | |
3184 | |
3185 /* attach prefs callbacks */ | |
3186 /* for the toolbar buttons */ | |
3187 blist_prefs_callbacks = g_slist_prepend(blist_prefs_callbacks, | |
3188 GINT_TO_POINTER( | |
3189 gaim_prefs_connect_callback("/gaim/gtk/blist/button_style", | |
3190 gaim_gtk_blist_update_toolbar, NULL))); | |
3191 blist_prefs_callbacks = g_slist_prepend(blist_prefs_callbacks, | |
3192 GINT_TO_POINTER( | |
3193 gaim_prefs_connect_callback("/gaim/gtk/blist/show_buttons", | |
3194 gaim_gtk_blist_update_toolbar, NULL))); | |
3195 | |
3196 /* things that affect how buddies are displayed */ | |
3197 blist_prefs_callbacks = g_slist_prepend(blist_prefs_callbacks, | |
3198 GINT_TO_POINTER( | |
3199 gaim_prefs_connect_callback("/gaim/gtk/blist/grey_idle_buddies", | |
3200 _prefs_change_redo_list, NULL))); | |
3201 blist_prefs_callbacks = g_slist_prepend(blist_prefs_callbacks, | |
3202 GINT_TO_POINTER( | |
3203 gaim_prefs_connect_callback("/gaim/gtk/blist/show_buddy_icons", | |
3204 _prefs_change_redo_list, NULL))); | |
3205 blist_prefs_callbacks = g_slist_prepend(blist_prefs_callbacks, | |
3206 GINT_TO_POINTER( | |
3207 gaim_prefs_connect_callback("/gaim/gtk/blist/show_warning_level", | |
3208 _prefs_change_redo_list, NULL))); | |
3209 blist_prefs_callbacks = g_slist_prepend(blist_prefs_callbacks, | |
3210 GINT_TO_POINTER( | |
3211 gaim_prefs_connect_callback("/gaim/gtk/blist/show_idle_time", | |
3212 _prefs_change_redo_list, NULL))); | |
3213 blist_prefs_callbacks = g_slist_prepend(blist_prefs_callbacks, | |
3214 GINT_TO_POINTER( | |
3215 gaim_prefs_connect_callback("/gaim/gtk/blist/show_empty_groups", | |
3216 _prefs_change_redo_list, NULL))); | |
3217 blist_prefs_callbacks = g_slist_prepend(blist_prefs_callbacks, | |
3218 GINT_TO_POINTER( | |
3219 gaim_prefs_connect_callback("/gaim/gtk/blist/show_offline_buddies", | |
3220 _prefs_change_redo_list, NULL))); | |
3221 | |
3222 /* sorting */ | |
3223 blist_prefs_callbacks = g_slist_prepend(blist_prefs_callbacks, | |
3224 GINT_TO_POINTER( | |
3225 gaim_prefs_connect_callback("/gaim/gtk/blist/sort_type", | |
3226 _prefs_change_sort_method, NULL))); | |
3227 | |
3228 /* things that affect what columns are displayed */ | |
3229 blist_prefs_callbacks = g_slist_prepend(blist_prefs_callbacks, | |
3230 GINT_TO_POINTER( | |
3231 gaim_prefs_connect_callback("/gaim/gtk/blist/show_buddy_icons", | |
3232 gaim_gtk_blist_update_columns, NULL))); | |
3233 blist_prefs_callbacks = g_slist_prepend(blist_prefs_callbacks, | |
3234 GINT_TO_POINTER( | |
3235 gaim_prefs_connect_callback("/gaim/gtk/blist/show_idle_time", | |
3236 gaim_gtk_blist_update_columns, NULL))); | |
3237 blist_prefs_callbacks = g_slist_prepend(blist_prefs_callbacks, | |
3238 GINT_TO_POINTER( | |
3239 gaim_prefs_connect_callback("/gaim/gtk/blist/show_warning_level", | |
3240 gaim_gtk_blist_update_columns, NULL))); | |
8259
4f9f68ab8770
[gaim-migrate @ 8982]
Christian Hammond <chipx86@chipx86.com>
parents:
8254
diff
changeset
|
3241 |
4f9f68ab8770
[gaim-migrate @ 8982]
Christian Hammond <chipx86@chipx86.com>
parents:
8254
diff
changeset
|
3242 /* Setup some gaim signal handlers. */ |
8937 | 3243 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", |
3244 gtkblist, GAIM_CALLBACK(sign_on_off_cb), list); | |
3245 gaim_signal_connect(gaim_connections_get_handle(), "signed-off", | |
3246 gtkblist, GAIM_CALLBACK(sign_on_off_cb), list); | |
8815 | 3247 |
8986 | 3248 gaim_signal_connect(gaim_plugins_get_handle(), "plugin-load", |
3249 gtkblist, GAIM_CALLBACK(plugin_changed_cb), NULL); | |
3250 gaim_signal_connect(gaim_plugins_get_handle(), "plugin-unload", | |
3251 gtkblist, GAIM_CALLBACK(plugin_changed_cb), NULL); | |
3252 | |
8815 | 3253 /* emit our created signal */ |
3254 gaim_signal_emit(gaim_gtk_blist_get_handle(), "gtkblist-created", list); | |
5228 | 3255 } |
3256 | |
7620 | 3257 /* XXX: does this need fixing? */ |
3258 static void redo_buddy_list(GaimBuddyList *list, gboolean remove) | |
5228 | 3259 { |
7620 | 3260 GaimBlistNode *gnode, *cnode, *bnode; |
3261 | |
3262 for(gnode = list->root; gnode; gnode = gnode->next) { | |
3263 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
5234 | 3264 continue; |
7620 | 3265 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
3266 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
3267 if(remove) | |
3268 gaim_gtk_blist_hide_node(list, cnode); | |
3269 | |
3270 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
3271 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
3272 continue; | |
3273 if(remove) | |
3274 gaim_gtk_blist_hide_node(list, bnode); | |
3275 gaim_gtk_blist_update(list, bnode); | |
3276 } | |
3277 | |
3278 gaim_gtk_blist_update(list, cnode); | |
3279 } else if(GAIM_BLIST_NODE_IS_CHAT(cnode)) { | |
3280 if(remove) | |
3281 gaim_gtk_blist_hide_node(list, cnode); | |
3282 | |
3283 gaim_gtk_blist_update(list, cnode); | |
3284 } | |
5228 | 3285 } |
7620 | 3286 gaim_gtk_blist_update(list, gnode); |
5228 | 3287 } |
3288 } | |
3289 | |
7620 | 3290 void gaim_gtk_blist_refresh(GaimBuddyList *list) |
5422 | 3291 { |
3292 redo_buddy_list(list, FALSE); | |
3293 } | |
3294 | |
5297 | 3295 void |
3296 gaim_gtk_blist_update_refresh_timeout() | |
3297 { | |
7620 | 3298 GaimBuddyList *blist; |
3299 GaimGtkBuddyList *gtkblist; | |
5297 | 3300 |
3301 blist = gaim_get_blist(); | |
3302 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); | |
3303 | |
7620 | 3304 if (gaim_prefs_get_bool("/gaim/gtk/blist/show_idle_time") || |
3305 gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")) { | |
3306 | |
3307 gtkblist->refresh_timer = g_timeout_add(30000, | |
3308 (GSourceFunc)gaim_gtk_blist_refresh_timer, blist); | |
5297 | 3309 } else { |
3310 g_source_remove(gtkblist->refresh_timer); | |
3311 gtkblist->refresh_timer = 0; | |
3312 } | |
3313 } | |
3314 | |
5256 | 3315 static gboolean get_iter_from_node(GaimBlistNode *node, GtkTreeIter *iter) { |
3316 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; | |
3317 GtkTreePath *path; | |
5228 | 3318 |
7620 | 3319 /* XXX: why do we assume we have a buddy here? */ |
5263 | 3320 if (!gtknode) { |
7620 | 3321 #if 0 |
3322 gaim_debug(GAIM_DEBUG_ERROR, "gtkblist", "buddy %s has no ui_data\n", ((GaimBuddy *)node)->name); | |
3323 #endif | |
5263 | 3324 return FALSE; |
3325 } | |
3326 | |
3327 if (!gtkblist) { | |
3328 gaim_debug(GAIM_DEBUG_ERROR, "gtkblist", "get_iter_from_node was called, but we don't seem to have a blist\n"); | |
3329 return FALSE; | |
3330 } | |
3331 | |
3332 if (!gtknode->row) | |
5228 | 3333 return FALSE; |
3334 | |
5256 | 3335 if ((path = gtk_tree_row_reference_get_path(gtknode->row)) == NULL) |
5228 | 3336 return FALSE; |
5256 | 3337 if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), iter, path)) { |
3338 gtk_tree_path_free(path); | |
3339 return FALSE; | |
3340 } | |
3341 gtk_tree_path_free(path); | |
3342 return TRUE; | |
5228 | 3343 } |
3344 | |
7620 | 3345 static void |
3346 gaim_gtk_blist_update_toolbar_icons (GtkWidget *widget, gpointer data) | |
3347 { | |
3348 GaimButtonStyle style = gaim_prefs_get_int("/gaim/gtk/blist/button_style"); | |
3349 | |
5228 | 3350 if (GTK_IS_IMAGE(widget)) { |
7620 | 3351 if (style == GAIM_BUTTON_IMAGE || style == GAIM_BUTTON_TEXT_IMAGE) |
5228 | 3352 gtk_widget_show(widget); |
3353 else | |
3354 gtk_widget_hide(widget); | |
7620 | 3355 } |
3356 else if (GTK_IS_LABEL(widget)) { | |
3357 if (style == GAIM_BUTTON_IMAGE) | |
5228 | 3358 gtk_widget_hide(widget); |
3359 else | |
3360 gtk_widget_show(widget); | |
7620 | 3361 } |
3362 else if (GTK_IS_CONTAINER(widget)) { | |
3363 gtk_container_foreach(GTK_CONTAINER(widget), | |
3364 gaim_gtk_blist_update_toolbar_icons, NULL); | |
5228 | 3365 } |
3366 } | |
3367 | |
3368 void gaim_gtk_blist_update_toolbar() { | |
3369 if (!gtkblist) | |
3370 return; | |
3371 | |
7620 | 3372 if (gaim_prefs_get_int("/gaim/gtk/blist/button_style") == GAIM_BUTTON_NONE) |
5228 | 3373 gtk_widget_hide(gtkblist->bbox); |
3374 else { | |
7620 | 3375 gtk_container_foreach(GTK_CONTAINER(gtkblist->bbox), |
3376 gaim_gtk_blist_update_toolbar_icons, NULL); | |
5228 | 3377 gtk_widget_show(gtkblist->bbox); |
3378 } | |
3379 } | |
3380 | |
7620 | 3381 static void gaim_gtk_blist_remove(GaimBuddyList *list, GaimBlistNode *node) |
5228 | 3382 { |
5260 | 3383 gaim_gtk_blist_hide_node(list, node); |
5228 | 3384 |
7620 | 3385 if(node->parent) |
3386 gaim_gtk_blist_update(list, node->parent); | |
3387 | |
5263 | 3388 /* There's something I don't understand here */ |
3389 /* g_free(node->ui_data); | |
3390 node->ui_data = NULL; */ | |
5228 | 3391 } |
3392 | |
3393 static gboolean do_selection_changed(GaimBlistNode *new_selection) | |
3394 { | |
5254 | 3395 GaimBlistNode *old_selection = NULL; |
5228 | 3396 |
5254 | 3397 /* test for gtkblist because crazy timeout means we can be called after the blist is gone */ |
3398 if (gtkblist && new_selection != gtkblist->selected_node) { | |
3399 old_selection = gtkblist->selected_node; | |
5228 | 3400 gtkblist->selected_node = new_selection; |
3401 if(new_selection) | |
3402 gaim_gtk_blist_update(NULL, new_selection); | |
3403 if(old_selection) | |
3404 gaim_gtk_blist_update(NULL, old_selection); | |
3405 } | |
3406 | |
3407 return FALSE; | |
3408 } | |
3409 | |
3410 static void gaim_gtk_blist_selection_changed(GtkTreeSelection *selection, gpointer data) | |
3411 { | |
3412 GaimBlistNode *new_selection = NULL; | |
3413 GtkTreeIter iter; | |
3414 | |
3415 if(gtk_tree_selection_get_selected(selection, NULL, &iter)){ | |
3416 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, | |
3417 NODE_COLUMN, &new_selection, -1); | |
3418 } | |
5254 | 3419 |
5228 | 3420 /* we set this up as a timeout, otherwise the blist flickers */ |
3421 g_timeout_add(0, (GSourceFunc)do_selection_changed, new_selection); | |
3422 } | |
3423 | |
8252 | 3424 static gboolean insert_node(GaimBuddyList *list, GaimBlistNode *node, GtkTreeIter *iter) |
7620 | 3425 { |
3426 GtkTreeIter parent_iter, cur, *curptr = NULL; | |
3427 struct _gaim_gtk_blist_node *gtknode = node->ui_data; | |
5256 | 3428 GtkTreePath *newpath; |
7620 | 3429 |
3430 if(!gtknode || !iter) | |
8252 | 3431 return FALSE; |
7620 | 3432 |
3433 if(node->parent && !get_iter_from_node(node->parent, &parent_iter)) | |
8252 | 3434 return FALSE; |
7620 | 3435 |
3436 if(get_iter_from_node(node, &cur)) | |
3437 curptr = &cur; | |
3438 | |
3439 if(GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_CHAT(node)) { | |
3440 *iter = current_sort_method->func(node, list, parent_iter, curptr); | |
3441 } else { | |
3442 *iter = sort_method_none(node, list, parent_iter, curptr); | |
5228 | 3443 } |
3444 | |
7620 | 3445 gtk_tree_row_reference_free(gtknode->row); |
3446 newpath = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), | |
3447 iter); | |
3448 gtknode->row = | |
3449 gtk_tree_row_reference_new(GTK_TREE_MODEL(gtkblist->treemodel), | |
3450 newpath); | |
5256 | 3451 gtk_tree_path_free(newpath); |
3452 | |
5228 | 3453 gtk_tree_store_set(gtkblist->treemodel, iter, |
3454 NODE_COLUMN, node, | |
3455 -1); | |
7620 | 3456 |
3457 if(node->parent) { | |
3458 GtkTreePath *expand = NULL; | |
3459 struct _gaim_gtk_blist_node *gtkparentnode = node->parent->ui_data; | |
3460 | |
3461 if(GAIM_BLIST_NODE_IS_GROUP(node->parent)) { | |
7693 | 3462 if(!gaim_blist_node_get_bool(node->parent, "collapsed")) |
7620 | 3463 expand = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &parent_iter); |
3464 } else if(GAIM_BLIST_NODE_IS_CONTACT(node->parent) && | |
3465 gtkparentnode->contact_expanded) { | |
3466 expand = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &parent_iter); | |
3467 } | |
3468 if(expand) { | |
7693 | 3469 gtk_tree_view_expand_row(GTK_TREE_VIEW(gtkblist->treeview), expand, FALSE); |
7620 | 3470 gtk_tree_path_free(expand); |
3471 } | |
3472 } | |
3473 | |
8252 | 3474 return TRUE; |
5228 | 3475 } |
3476 | |
7620 | 3477 static void gaim_gtk_blist_update_group(GaimBuddyList *list, GaimBlistNode *node) |
3478 { | |
3479 GaimGroup *group; | |
8203 | 3480 int count; |
7620 | 3481 |
3482 g_return_if_fail(GAIM_BLIST_NODE_IS_GROUP(node)); | |
3483 | |
3484 group = (GaimGroup*)node; | |
3485 | |
8203 | 3486 if(gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies")) |
3487 count = gaim_blist_get_group_size(group, FALSE); | |
3488 else | |
3489 count = gaim_blist_get_group_online_count(group); | |
3490 if(gaim_prefs_get_bool("/gaim/gtk/blist/show_empty_groups") || count > 0) { | |
7620 | 3491 char *mark, *esc; |
3492 GtkTreeIter iter; | |
3493 | |
8252 | 3494 if(!insert_node(list, node, &iter)) |
3495 return; | |
7620 | 3496 |
3497 esc = g_markup_escape_text(group->name, -1); | |
8945 | 3498 mark = g_strdup_printf("<span weight='bold'>%s</span> (%d/%d)", |
3499 esc, gaim_blist_get_group_online_count(group), | |
3500 gaim_blist_get_group_size(group, FALSE)); | |
7620 | 3501 g_free(esc); |
3502 | |
3503 gtk_tree_store_set(gtkblist->treemodel, &iter, | |
3504 STATUS_ICON_COLUMN, NULL, | |
3505 STATUS_ICON_VISIBLE_COLUMN, FALSE, | |
3506 NAME_COLUMN, mark, | |
3507 NODE_COLUMN, node, | |
3508 -1); | |
3509 g_free(mark); | |
3510 } else { | |
3511 gaim_gtk_blist_hide_node(list, node); | |
3512 } | |
3513 } | |
3514 | |
3515 static void buddy_node(GaimBuddy *buddy, GtkTreeIter *iter, GaimBlistNode *node) | |
5228 | 3516 { |
7620 | 3517 GdkPixbuf *status, *avatar; |
3518 char *mark; | |
3519 char *warning = NULL, *idle = NULL; | |
3520 | |
3521 gboolean selected = (gtkblist->selected_node == node); | |
3522 | |
3523 status = gaim_gtk_blist_get_status_icon((GaimBlistNode*)buddy, | |
3524 (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons") | |
3525 ? GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL)); | |
3526 | |
3527 avatar = gaim_gtk_blist_get_buddy_icon(buddy); | |
3528 mark = gaim_gtk_blist_get_name_markup(buddy, selected); | |
3529 | |
3530 if (buddy->idle > 0) { | |
3531 time_t t; | |
3532 int ihrs, imin; | |
3533 time(&t); | |
3534 ihrs = (t - buddy->idle) / 3600; | |
3535 imin = ((t - buddy->idle) / 60) % 60; | |
3536 if(ihrs > 0) | |
3537 idle = g_strdup_printf("(%d:%02d)", ihrs, imin); | |
3538 else | |
3539 idle = g_strdup_printf("(%d)", imin); | |
3540 } | |
3541 | |
3542 if (buddy->evil > 0) | |
3543 warning = g_strdup_printf("%d%%", buddy->evil); | |
3544 | |
3545 if (gaim_prefs_get_bool("/gaim/gtk/blist/grey_idle_buddies") && | |
3546 buddy->idle) { | |
3547 | |
3548 if(warning && !selected) { | |
3549 char *w2 = g_strdup_printf("<span color='dim grey'>%s</span>", | |
3550 warning); | |
3551 g_free(warning); | |
3552 warning = w2; | |
3553 } | |
3554 | |
3555 if(idle && !selected) { | |
3556 char *i2 = g_strdup_printf("<span color='dim grey'>%s</span>", | |
3557 idle); | |
3558 g_free(idle); | |
3559 idle = i2; | |
5228 | 3560 } |
7620 | 3561 } |
3562 | |
3563 gtk_tree_store_set(gtkblist->treemodel, iter, | |
3564 STATUS_ICON_COLUMN, status, | |
3565 STATUS_ICON_VISIBLE_COLUMN, TRUE, | |
3566 NAME_COLUMN, mark, | |
3567 WARNING_COLUMN, warning, | |
3568 IDLE_COLUMN, idle, | |
3569 BUDDY_ICON_COLUMN, avatar, | |
3570 -1); | |
3571 | |
3572 g_free(mark); | |
3573 if(idle) | |
3574 g_free(idle); | |
3575 if(warning) | |
3576 g_free(warning); | |
3577 if(status) | |
3578 g_object_unref(status); | |
3579 if(avatar) | |
3580 g_object_unref(avatar); | |
3581 } | |
3582 | |
3583 static void gaim_gtk_blist_update_contact(GaimBuddyList *list, GaimBlistNode *node) | |
3584 { | |
3585 GaimContact *contact; | |
3586 GaimBuddy *buddy; | |
3587 struct _gaim_gtk_blist_node *gtknode; | |
3588 | |
3589 g_return_if_fail(GAIM_BLIST_NODE_IS_CONTACT(node)); | |
3590 | |
3591 /* First things first, update the group */ | |
3592 gaim_gtk_blist_update_group(list, node->parent); | |
3593 | |
3594 gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; | |
3595 contact = (GaimContact*)node; | |
3596 buddy = gaim_contact_get_priority_buddy(contact); | |
3597 | |
3598 if(buddy && (buddy->present != GAIM_BUDDY_OFFLINE || | |
3599 (gaim_account_is_connected(buddy->account) && | |
8960 | 3600 gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies")) || |
3601 gaim_blist_node_get_bool(node, "show_offline"))) { | |
7620 | 3602 GtkTreeIter iter; |
3603 | |
8252 | 3604 if(!insert_node(list, node, &iter)) |
3605 return; | |
7620 | 3606 |
3607 if(gtknode->contact_expanded) { | |
3608 GdkPixbuf *status; | |
5228 | 3609 char *mark; |
3610 | |
7620 | 3611 status = gaim_gtk_blist_get_status_icon(node, |
3612 (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons") ? | |
3613 GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL)); | |
3614 | |
3615 mark = g_markup_escape_text(gaim_contact_get_alias(contact), -1); | |
3616 | |
5228 | 3617 gtk_tree_store_set(gtkblist->treemodel, &iter, |
7620 | 3618 STATUS_ICON_COLUMN, status, |
3619 STATUS_ICON_VISIBLE_COLUMN, TRUE, | |
5228 | 3620 NAME_COLUMN, mark, |
7620 | 3621 WARNING_COLUMN, NULL, |
3622 IDLE_COLUMN, NULL, | |
3623 BUDDY_ICON_COLUMN, NULL, | |
5228 | 3624 -1); |
3625 g_free(mark); | |
7620 | 3626 if(status) |
3627 g_object_unref(status); | |
3628 } else { | |
3629 buddy_node(buddy, &iter, node); | |
5228 | 3630 } |
7620 | 3631 } else { |
3632 gaim_gtk_blist_hide_node(list, node); | |
5228 | 3633 } |
7620 | 3634 } |
3635 | |
3636 static void gaim_gtk_blist_update_buddy(GaimBuddyList *list, GaimBlistNode *node) | |
3637 { | |
3638 GaimContact *contact; | |
3639 GaimBuddy *buddy; | |
3640 struct _gaim_gtk_blist_node *gtkparentnode; | |
3641 | |
3642 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
3643 | |
3644 buddy = (GaimBuddy*)node; | |
3645 contact = (GaimContact*)node->parent; | |
3646 gtkparentnode = (struct _gaim_gtk_blist_node *)node->parent->ui_data; | |
3647 | |
3648 /* First things first, update the contact */ | |
3649 gaim_gtk_blist_update_contact(list, node->parent); | |
3650 | |
3651 if(gtkparentnode->contact_expanded && | |
3652 (buddy->present != GAIM_BUDDY_OFFLINE || | |
3653 (gaim_account_is_connected(buddy->account) && | |
8960 | 3654 gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies")) || |
3655 gaim_blist_node_get_bool(node->parent, "show_offline"))) { | |
7620 | 3656 GtkTreeIter iter; |
3657 | |
8252 | 3658 if(!insert_node(list, node, &iter)) |
3659 return; | |
3660 | |
7620 | 3661 buddy_node(buddy, &iter, node); |
3662 | |
3663 } else { | |
3664 gaim_gtk_blist_hide_node(list, node); | |
3665 } | |
3666 | |
3667 } | |
3668 | |
3669 static void gaim_gtk_blist_update_chat(GaimBuddyList *list, GaimBlistNode *node) | |
3670 { | |
3671 GaimChat *chat; | |
3672 | |
3673 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node)); | |
3674 | |
3675 /* First things first, update the group */ | |
3676 gaim_gtk_blist_update_group(list, node->parent); | |
3677 | |
3678 chat = (GaimChat*)node; | |
3679 | |
3680 if(gaim_account_is_connected(chat->account)) { | |
3681 GtkTreeIter iter; | |
5234 | 3682 GdkPixbuf *status; |
7620 | 3683 char *mark; |
3684 | |
8252 | 3685 if(!insert_node(list, node, &iter)) |
3686 return; | |
5234 | 3687 |
3688 status = gaim_gtk_blist_get_status_icon(node, | |
7620 | 3689 (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons") ? |
3690 GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL)); | |
3691 | |
3692 mark = g_markup_escape_text(gaim_chat_get_name(chat), -1); | |
5234 | 3693 |
3694 gtk_tree_store_set(gtkblist->treemodel, &iter, | |
7620 | 3695 STATUS_ICON_COLUMN, status, |
3696 STATUS_ICON_VISIBLE_COLUMN, TRUE, | |
3697 NAME_COLUMN, mark, | |
3698 -1); | |
5228 | 3699 |
3700 g_free(mark); | |
7620 | 3701 if(status) |
5228 | 3702 g_object_unref(status); |
7620 | 3703 } else { |
5260 | 3704 gaim_gtk_blist_hide_node(list, node); |
5228 | 3705 } |
7620 | 3706 } |
3707 | |
3708 static void gaim_gtk_blist_update(GaimBuddyList *list, GaimBlistNode *node) | |
3709 { | |
3710 if(!gtkblist) | |
3711 return; | |
3712 | |
3713 switch(node->type) { | |
3714 case GAIM_BLIST_GROUP_NODE: | |
3715 gaim_gtk_blist_update_group(list, node); | |
3716 break; | |
3717 case GAIM_BLIST_CONTACT_NODE: | |
3718 gaim_gtk_blist_update_contact(list, node); | |
3719 break; | |
3720 case GAIM_BLIST_BUDDY_NODE: | |
3721 gaim_gtk_blist_update_buddy(list, node); | |
3722 break; | |
3723 case GAIM_BLIST_CHAT_NODE: | |
3724 gaim_gtk_blist_update_chat(list, node); | |
3725 break; | |
3726 case GAIM_BLIST_OTHER_NODE: | |
3727 return; | |
3728 } | |
5234 | 3729 |
5228 | 3730 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(gtkblist->treeview)); |
3731 } | |
3732 | |
7620 | 3733 |
3734 static void gaim_gtk_blist_destroy(GaimBuddyList *list) | |
5228 | 3735 { |
3736 if (!gtkblist) | |
3737 return; | |
3738 | |
8937 | 3739 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-on", |
3740 gtkblist, GAIM_CALLBACK(sign_on_off_cb)); | |
3741 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-off", | |
3742 gtkblist, GAIM_CALLBACK(sign_on_off_cb)); | |
8259
4f9f68ab8770
[gaim-migrate @ 8982]
Christian Hammond <chipx86@chipx86.com>
parents:
8254
diff
changeset
|
3743 |
5228 | 3744 gtk_widget_destroy(gtkblist->window); |
7620 | 3745 |
8254 | 3746 gaim_gtk_blist_tooltip_destroy(); |
7620 | 3747 |
5228 | 3748 gtk_object_sink(GTK_OBJECT(gtkblist->tooltips)); |
3749 | |
3750 if (gtkblist->refresh_timer) | |
3751 g_source_remove(gtkblist->refresh_timer); | |
3752 if (gtkblist->timeout) | |
3753 g_source_remove(gtkblist->timeout); | |
3754 | |
3755 gtkblist->refresh_timer = 0; | |
3756 gtkblist->timeout = 0; | |
3757 gtkblist->window = gtkblist->vbox = gtkblist->treeview = NULL; | |
3758 gtkblist->treemodel = NULL; | |
3759 gtkblist->idle_column = NULL; | |
3760 gtkblist->warning_column = gtkblist->buddy_icon_column = NULL; | |
8254 | 3761 gtkblist->bbox = NULL; |
5427 | 3762 g_object_unref(G_OBJECT(gtkblist->ift)); |
5228 | 3763 protomenu = NULL; |
8986 | 3764 pluginmenu = NULL; |
5228 | 3765 awaymenu = NULL; |
3766 gtkblist = NULL; | |
7620 | 3767 |
3768 while(blist_prefs_callbacks) { | |
3769 gaim_prefs_disconnect_callback(GPOINTER_TO_INT(blist_prefs_callbacks->data)); | |
3770 blist_prefs_callbacks = g_slist_remove(blist_prefs_callbacks, blist_prefs_callbacks->data); | |
3771 } | |
5228 | 3772 } |
3773 | |
7620 | 3774 static void gaim_gtk_blist_set_visible(GaimBuddyList *list, gboolean show) |
5228 | 3775 { |
3776 if (!(gtkblist && gtkblist->window)) | |
3777 return; | |
3778 | |
3779 if (show) { | |
3780 gaim_gtk_blist_restore_position(); | |
3781 gtk_window_present(GTK_WINDOW(gtkblist->window)); | |
3782 } else { | |
7620 | 3783 if (!gaim_connections_get_all() || docklet_count) { |
5228 | 3784 #ifdef _WIN32 |
3785 wgaim_systray_minimize(gtkblist->window); | |
3786 #endif | |
3787 gtk_widget_hide(gtkblist->window); | |
3788 } else { | |
3789 gtk_window_iconify(GTK_WINDOW(gtkblist->window)); | |
3790 } | |
3791 } | |
3792 } | |
3793 | |
7620 | 3794 static GList * |
3795 groups_tree(void) | |
3796 { | |
3797 GList *tmp = NULL; | |
3798 char *tmp2; | |
3799 GaimGroup *g; | |
3800 GaimBlistNode *gnode; | |
3801 | |
3802 if (gaim_get_blist()->root == NULL) | |
3803 { | |
3804 tmp2 = g_strdup(_("Buddies")); | |
3805 tmp = g_list_append(tmp, tmp2); | |
3806 } | |
3807 else | |
3808 { | |
3809 for (gnode = gaim_get_blist()->root; | |
3810 gnode != NULL; | |
3811 gnode = gnode->next) | |
3812 { | |
3813 if (GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
3814 { | |
3815 g = (GaimGroup *)gnode; | |
3816 tmp2 = g->name; | |
3817 tmp = g_list_append(tmp, tmp2); | |
3818 } | |
3819 } | |
3820 } | |
3821 | |
3822 return tmp; | |
3823 } | |
3824 | |
3825 static void | |
3826 add_buddy_select_account_cb(GObject *w, GaimAccount *account, | |
3827 GaimGtkAddBuddyData *data) | |
3828 { | |
3829 /* Save our account */ | |
3830 data->account = account; | |
3831 } | |
3832 | |
3833 static void | |
3834 destroy_add_buddy_dialog_cb(GtkWidget *win, GaimGtkAddBuddyData *data) | |
3835 { | |
3836 g_free(data); | |
3837 } | |
3838 | |
3839 static void | |
3840 add_buddy_cb(GtkWidget *w, int resp, GaimGtkAddBuddyData *data) | |
3841 { | |
3842 const char *grp, *who, *whoalias; | |
3843 GaimConversation *c; | |
3844 GaimBuddy *b; | |
3845 GaimGroup *g; | |
3846 | |
3847 if (resp == GTK_RESPONSE_OK) | |
3848 { | |
3849 who = gtk_entry_get_text(GTK_ENTRY(data->entry)); | |
3850 grp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(data->combo)->entry)); | |
3851 whoalias = gtk_entry_get_text(GTK_ENTRY(data->entry_for_alias)); | |
3852 | |
3853 c = gaim_find_conversation_with_account(who, data->account); | |
3854 | |
3855 if ((g = gaim_find_group(grp)) == NULL) | |
3856 { | |
3857 g = gaim_group_new(grp); | |
3858 gaim_blist_add_group(g, NULL); | |
3859 } | |
3860 | |
3861 b = gaim_buddy_new(data->account, who, whoalias); | |
3862 gaim_blist_add_buddy(b, NULL, g, NULL); | |
9285 | 3863 serv_add_buddy(gaim_account_get_connection(data->account), b); |
7620 | 3864 |
7887 | 3865 /* |
9285 | 3866 * XXX |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
3867 * It really seems like it would be better if the call to serv_add_buddy() |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
3868 * and gaim_conversation_update() were done in blist.c, possibly in the |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
3869 * gaim_blist_add_buddy() function. Maybe serv_add_buddy() should be |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
3870 * renamed to gaim_blist_add_new_buddy() or something, and have it call |
7887 | 3871 * gaim_blist_add_buddy() after it creates it. --Mark |
9285 | 3872 * |
3873 * No that's not good. blist.c should only deal with adding nodes to the | |
3874 * local list. We need a new, non-gtk file that calls both serv_add_buddy | |
3875 * and gaim_blist_add_buddy(). Or something. --Mark | |
7887 | 3876 */ |
3877 | |
7620 | 3878 if (c != NULL) { |
3879 gaim_buddy_icon_update(gaim_conv_im_get_icon(GAIM_CONV_IM(c))); | |
3880 gaim_conversation_update(c, GAIM_CONV_UPDATE_ADD); | |
3881 } | |
3882 } | |
3883 | |
3884 gtk_widget_destroy(data->window); | |
3885 } | |
3886 | |
3887 static void | |
3888 gaim_gtk_blist_request_add_buddy(GaimAccount *account, const char *username, | |
3889 const char *group, const char *alias) | |
3890 { | |
3891 GtkWidget *table; | |
3892 GtkWidget *label; | |
3893 GtkWidget *hbox; | |
3894 GtkWidget *vbox; | |
3895 GtkWidget *img; | |
3896 GaimGtkBuddyList *gtkblist; | |
3897 GaimGtkAddBuddyData *data = g_new0(GaimGtkAddBuddyData, 1); | |
3898 | |
3899 data->account = | |
3900 (account != NULL | |
3901 ? account | |
3902 : gaim_connection_get_account(gaim_connections_get_all()->data)); | |
3903 | |
3904 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, | |
3905 GTK_ICON_SIZE_DIALOG); | |
3906 | |
3907 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); | |
3908 | |
3909 data->window = gtk_dialog_new_with_buttons(_("Add Buddy"), | |
8975 | 3910 NULL, GTK_DIALOG_NO_SEPARATOR, |
7620 | 3911 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
3912 GTK_STOCK_ADD, GTK_RESPONSE_OK, | |
3913 NULL); | |
3914 | |
3915 gtk_dialog_set_default_response(GTK_DIALOG(data->window), GTK_RESPONSE_OK); | |
3916 gtk_container_set_border_width(GTK_CONTAINER(data->window), 6); | |
3917 gtk_window_set_resizable(GTK_WINDOW(data->window), FALSE); | |
3918 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(data->window)->vbox), 12); | |
3919 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), 6); | |
3920 gtk_window_set_role(GTK_WINDOW(data->window), "add_buddy"); | |
8975 | 3921 gtk_window_set_type_hint(GTK_WINDOW(data->window), |
3922 GDK_WINDOW_TYPE_HINT_DIALOG); | |
7620 | 3923 |
3924 hbox = gtk_hbox_new(FALSE, 12); | |
3925 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), hbox); | |
3926 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
3927 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
3928 | |
3929 vbox = gtk_vbox_new(FALSE, 0); | |
3930 gtk_container_add(GTK_CONTAINER(hbox), vbox); | |
3931 | |
3932 label = gtk_label_new( | |
3933 _("Please enter the screen name of the person you would like " | |
3934 "to add to your buddy list. You may optionally enter an alias, " | |
3935 "or nickname, for the buddy. The alias will be displayed in " | |
3936 "place of the screen name whenever possible.\n")); | |
3937 | |
3938 gtk_widget_set_size_request(GTK_WIDGET(label), 400, -1); | |
3939 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
3940 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
3941 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
3942 | |
3943 hbox = gtk_hbox_new(FALSE, 6); | |
3944 gtk_container_add(GTK_CONTAINER(vbox), hbox); | |
3945 | |
3946 g_signal_connect(G_OBJECT(data->window), "destroy", | |
3947 G_CALLBACK(destroy_add_buddy_dialog_cb), data); | |
3948 | |
3949 table = gtk_table_new(4, 2, FALSE); | |
3950 gtk_table_set_row_spacings(GTK_TABLE(table), 5); | |
3951 gtk_table_set_col_spacings(GTK_TABLE(table), 5); | |
3952 gtk_container_set_border_width(GTK_CONTAINER(table), 0); | |
3953 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); | |
3954 | |
3955 label = gtk_label_new(_("Screen Name:")); | |
3956 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
3957 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); | |
3958 | |
3959 data->entry = gtk_entry_new(); | |
3960 gtk_table_attach_defaults(GTK_TABLE(table), data->entry, 1, 2, 0, 1); | |
3961 gtk_widget_grab_focus(data->entry); | |
3962 | |
3963 if (username != NULL) | |
3964 gtk_entry_set_text(GTK_ENTRY(data->entry), username); | |
3965 | |
3966 gtk_entry_set_activates_default (GTK_ENTRY(data->entry), TRUE); | |
8137 | 3967 gaim_set_accessible_label (data->entry, label); |
7620 | 3968 |
3969 label = gtk_label_new(_("Alias:")); | |
3970 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
3971 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2); | |
3972 | |
3973 data->entry_for_alias = gtk_entry_new(); | |
3974 gtk_table_attach_defaults(GTK_TABLE(table), | |
3975 data->entry_for_alias, 1, 2, 1, 2); | |
3976 | |
3977 if (alias != NULL) | |
3978 gtk_entry_set_text(GTK_ENTRY(data->entry_for_alias), alias); | |
3979 | |
3980 gtk_entry_set_activates_default (GTK_ENTRY(data->entry_for_alias), TRUE); | |
8137 | 3981 gaim_set_accessible_label (data->entry_for_alias, label); |
7620 | 3982 |
3983 label = gtk_label_new(_("Group:")); | |
3984 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
3985 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3); | |
3986 | |
3987 data->combo = gtk_combo_new(); | |
3988 gtk_combo_set_popdown_strings(GTK_COMBO(data->combo), groups_tree()); | |
3989 gtk_table_attach_defaults(GTK_TABLE(table), data->combo, 1, 2, 2, 3); | |
8137 | 3990 gaim_set_accessible_label (data->combo, label); |
7620 | 3991 |
3992 /* Set up stuff for the account box */ | |
3993 label = gtk_label_new(_("Account:")); | |
3994 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
3995 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4); | |
3996 | |
3997 data->account_box = gaim_gtk_account_option_menu_new(account, FALSE, | |
3998 G_CALLBACK(add_buddy_select_account_cb), NULL, data); | |
3999 | |
4000 gtk_table_attach_defaults(GTK_TABLE(table), data->account_box, 1, 2, 3, 4); | |
8137 | 4001 gaim_set_accessible_label (data->account_box, label); |
7620 | 4002 |
4003 /* End of account box */ | |
4004 | |
4005 g_signal_connect(G_OBJECT(data->window), "response", | |
4006 G_CALLBACK(add_buddy_cb), data); | |
4007 | |
4008 gtk_widget_show_all(data->window); | |
4009 | |
4010 if (group != NULL) | |
4011 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(data->combo)->entry), group); | |
4012 } | |
4013 | |
4014 static void | |
4015 add_chat_cb(GtkWidget *w, GaimGtkAddChatData *data) | |
4016 { | |
4017 GHashTable *components; | |
4018 GList *tmp; | |
4019 GaimChat *chat; | |
4020 GaimGroup *group; | |
4021 const char *group_name; | |
4022 | |
4023 components = g_hash_table_new_full(g_str_hash, g_str_equal, | |
4024 g_free, g_free); | |
4025 | |
4026 for (tmp = data->entries; tmp; tmp = tmp->next) | |
4027 { | |
4028 if (g_object_get_data(tmp->data, "is_spin")) | |
4029 { | |
4030 g_hash_table_replace(components, | |
4031 g_strdup(g_object_get_data(tmp->data, "identifier")), | |
4032 g_strdup_printf("%d", | |
4033 gtk_spin_button_get_value_as_int(tmp->data))); | |
4034 } | |
4035 else | |
4036 { | |
4037 g_hash_table_replace(components, | |
4038 g_strdup(g_object_get_data(tmp->data, "identifier")), | |
4039 g_strdup(gtk_entry_get_text(tmp->data))); | |
4040 } | |
4041 } | |
4042 | |
4043 chat = gaim_chat_new(data->account, | |
4044 gtk_entry_get_text(GTK_ENTRY(data->alias_entry)), | |
4045 components); | |
4046 | |
4047 group_name = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(data->group_combo)->entry)); | |
4048 | |
4049 if ((group = gaim_find_group(group_name)) == NULL) | |
4050 { | |
4051 group = gaim_group_new(group_name); | |
4052 gaim_blist_add_group(group, NULL); | |
4053 } | |
4054 | |
4055 if (chat != NULL) | |
4056 { | |
4057 gaim_blist_add_chat(chat, group, NULL); | |
4058 } | |
4059 | |
4060 gtk_widget_destroy(data->window); | |
4061 g_list_free(data->entries); | |
4062 | |
4063 g_free(data); | |
4064 } | |
4065 | |
4066 static void | |
4067 add_chat_resp_cb(GtkWidget *w, int resp, GaimGtkAddChatData *data) | |
4068 { | |
4069 if (resp == GTK_RESPONSE_OK) | |
4070 { | |
4071 add_chat_cb(NULL, data); | |
4072 } | |
4073 else | |
4074 { | |
4075 gtk_widget_destroy(data->window); | |
4076 g_list_free(data->entries); | |
4077 g_free(data); | |
4078 } | |
4079 } | |
4080 | |
4081 static void | |
4082 rebuild_addchat_entries(GaimGtkAddChatData *data) | |
4083 { | |
4084 GaimConnection *gc; | |
4085 GList *list, *tmp; | |
4086 struct proto_chat_entry *pce; | |
4087 gboolean focus = TRUE; | |
4088 | |
4089 gc = gaim_account_get_connection(data->account); | |
4090 | |
4091 while (GTK_BOX(data->entries_box)->children) | |
4092 { | |
4093 gtk_container_remove(GTK_CONTAINER(data->entries_box), | |
4094 ((GtkBoxChild *)GTK_BOX(data->entries_box)->children->data)->widget); | |
4095 } | |
4096 | |
4097 if (data->entries != NULL) | |
4098 g_list_free(data->entries); | |
4099 | |
4100 data->entries = NULL; | |
4101 | |
4102 list = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info(gc); | |
4103 | |
4104 for (tmp = list; tmp; tmp = tmp->next) | |
4105 { | |
4106 GtkWidget *label; | |
4107 GtkWidget *rowbox; | |
4108 | |
4109 pce = tmp->data; | |
4110 | |
4111 rowbox = gtk_hbox_new(FALSE, 5); | |
4112 gtk_box_pack_start(GTK_BOX(data->entries_box), rowbox, FALSE, FALSE, 0); | |
4113 | |
7889 | 4114 label = gtk_label_new_with_mnemonic(pce->label); |
7620 | 4115 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); |
4116 gtk_size_group_add_widget(data->sg, label); | |
4117 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); | |
4118 | |
4119 if (pce->is_int) | |
4120 { | |
4121 GtkObject *adjust; | |
4122 GtkWidget *spin; | |
4123 adjust = gtk_adjustment_new(pce->min, pce->min, pce->max, | |
4124 1, 10, 10); | |
4125 spin = gtk_spin_button_new(GTK_ADJUSTMENT(adjust), 1, 0); | |
4126 g_object_set_data(G_OBJECT(spin), "is_spin", GINT_TO_POINTER(TRUE)); | |
4127 g_object_set_data(G_OBJECT(spin), "identifier", pce->identifier); | |
4128 data->entries = g_list_append(data->entries, spin); | |
4129 gtk_widget_set_size_request(spin, 50, -1); | |
4130 gtk_box_pack_end(GTK_BOX(rowbox), spin, FALSE, FALSE, 0); | |
7891 | 4131 gtk_label_set_mnemonic_widget(GTK_LABEL(label), spin); |
8137 | 4132 gaim_set_accessible_label (spin, label); |
7620 | 4133 } |
4134 else | |
4135 { | |
4136 GtkWidget *entry = gtk_entry_new(); | |
4137 | |
4138 g_object_set_data(G_OBJECT(entry), "identifier", pce->identifier); | |
4139 data->entries = g_list_append(data->entries, entry); | |
4140 | |
4141 if (pce->def) | |
4142 gtk_entry_set_text(GTK_ENTRY(entry), pce->def); | |
4143 | |
4144 if (focus) | |
4145 { | |
4146 gtk_widget_grab_focus(entry); | |
4147 focus = FALSE; | |
4148 } | |
4149 | |
4150 if (pce->secret) | |
4151 gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); | |
4152 | |
4153 gtk_box_pack_end(GTK_BOX(rowbox), entry, TRUE, TRUE, 0); | |
4154 | |
4155 g_signal_connect(G_OBJECT(entry), "activate", | |
4156 G_CALLBACK(add_chat_cb), data); | |
7891 | 4157 gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry); |
8137 | 4158 gaim_set_accessible_label (entry, label); |
7620 | 4159 } |
4160 | |
4161 g_free(pce); | |
4162 } | |
4163 | |
4164 g_list_free(list); | |
4165 | |
4166 gtk_widget_show_all(data->entries_box); | |
4167 } | |
4168 | |
4169 static void | |
4170 add_chat_select_account_cb(GObject *w, GaimAccount *account, | |
4171 GaimGtkAddChatData *data) | |
4172 { | |
4173 if (gaim_account_get_protocol(data->account) == | |
4174 gaim_account_get_protocol(account)) | |
4175 { | |
4176 data->account = account; | |
4177 } | |
4178 else | |
4179 { | |
4180 data->account = account; | |
4181 rebuild_addchat_entries(data); | |
4182 } | |
4183 } | |
4184 | |
4185 static gboolean | |
4186 add_chat_check_account_func(GaimAccount *account) | |
4187 { | |
4188 GaimConnection *gc = gaim_account_get_connection(account); | |
4189 | |
4190 return (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info != NULL); | |
4191 } | |
4192 | |
4193 void | |
7859 | 4194 gaim_gtk_blist_request_add_chat(GaimAccount *account, GaimGroup *group, |
4195 const char *alias) | |
7620 | 4196 { |
4197 GaimGtkAddChatData *data; | |
8975 | 4198 GaimGtkBuddyList *gtkblist; |
4199 GList *l; | |
4200 GaimConnection *gc; | |
7620 | 4201 GtkWidget *label; |
4202 GtkWidget *rowbox; | |
4203 GtkWidget *hbox; | |
4204 GtkWidget *vbox; | |
4205 GtkWidget *img; | |
4206 | |
4207 data = g_new0(GaimGtkAddChatData, 1); | |
4208 | |
4209 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, | |
4210 GTK_ICON_SIZE_DIALOG); | |
4211 | |
8975 | 4212 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); |
4213 | |
4214 if (account != NULL) | |
7620 | 4215 { |
4216 data->account = account; | |
4217 } | |
4218 else | |
4219 { | |
4220 /* Select an account with chat capabilities */ | |
4221 for (l = gaim_connections_get_all(); l != NULL; l = l->next) | |
4222 { | |
4223 gc = (GaimConnection *)l->data; | |
4224 | |
4225 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->join_chat != NULL) | |
4226 { | |
4227 data->account = gaim_connection_get_account(gc); | |
4228 break; | |
4229 } | |
4230 } | |
4231 } | |
4232 | |
4233 if (data->account == NULL) | |
4234 { | |
4235 gaim_notify_error(NULL, NULL, | |
4236 _("You are not currently signed on with any " | |
4237 "protocols that have the ability to chat."), NULL); | |
4238 return; | |
4239 } | |
4240 | |
4241 data->sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
4242 | |
8975 | 4243 data->window = gtk_dialog_new_with_buttons(_("Add Chat"), |
4244 NULL, GTK_DIALOG_NO_SEPARATOR, | |
4245 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
4246 GTK_STOCK_ADD, GTK_RESPONSE_OK, | |
4247 NULL); | |
4248 | |
4249 gtk_dialog_set_default_response(GTK_DIALOG(data->window), GTK_RESPONSE_OK); | |
4250 gtk_container_set_border_width(GTK_CONTAINER(data->window), 6); | |
4251 gtk_window_set_resizable(GTK_WINDOW(data->window), FALSE); | |
4252 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(data->window)->vbox), 12); | |
4253 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), 6); | |
7620 | 4254 gtk_window_set_role(GTK_WINDOW(data->window), "add_chat"); |
8975 | 4255 gtk_window_set_type_hint(GTK_WINDOW(data->window), |
4256 GDK_WINDOW_TYPE_HINT_DIALOG); | |
7620 | 4257 |
4258 hbox = gtk_hbox_new(FALSE, 12); | |
4259 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), hbox); | |
4260 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
4261 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
4262 | |
4263 vbox = gtk_vbox_new(FALSE, 5); | |
4264 gtk_container_add(GTK_CONTAINER(hbox), vbox); | |
4265 | |
4266 label = gtk_label_new( | |
4267 _("Please enter an alias, and the appropriate information " | |
4268 "about the chat you would like to add to your buddy list.\n")); | |
4269 gtk_widget_set_size_request(label, 400, -1); | |
4270 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
4271 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
4272 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
4273 | |
4274 rowbox = gtk_hbox_new(FALSE, 5); | |
4275 gtk_box_pack_start(GTK_BOX(vbox), rowbox, FALSE, FALSE, 0); | |
4276 | |
4277 label = gtk_label_new(_("Account:")); | |
4278 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
4279 gtk_size_group_add_widget(data->sg, label); | |
4280 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); | |
4281 | |
4282 data->account_menu = gaim_gtk_account_option_menu_new(account, FALSE, | |
4283 G_CALLBACK(add_chat_select_account_cb), | |
4284 add_chat_check_account_func, data); | |
4285 gtk_box_pack_start(GTK_BOX(rowbox), data->account_menu, TRUE, TRUE, 0); | |
8137 | 4286 gaim_set_accessible_label (data->account_menu, label); |
7620 | 4287 |
4288 data->entries_box = gtk_vbox_new(FALSE, 5); | |
4289 gtk_container_set_border_width(GTK_CONTAINER(data->entries_box), 0); | |
4290 gtk_box_pack_start(GTK_BOX(vbox), data->entries_box, TRUE, TRUE, 0); | |
4291 | |
4292 rebuild_addchat_entries(data); | |
4293 | |
4294 rowbox = gtk_hbox_new(FALSE, 5); | |
4295 gtk_box_pack_start(GTK_BOX(vbox), rowbox, FALSE, FALSE, 0); | |
4296 | |
4297 label = gtk_label_new(_("Alias:")); | |
4298 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
4299 gtk_size_group_add_widget(data->sg, label); | |
4300 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); | |
4301 | |
4302 data->alias_entry = gtk_entry_new(); | |
7859 | 4303 if (alias != NULL) |
4304 gtk_entry_set_text(GTK_ENTRY(data->alias_entry), alias); | |
7620 | 4305 gtk_box_pack_end(GTK_BOX(rowbox), data->alias_entry, TRUE, TRUE, 0); |
8137 | 4306 gaim_set_accessible_label (data->alias_entry, label); |
7620 | 4307 |
4308 rowbox = gtk_hbox_new(FALSE, 5); | |
4309 gtk_box_pack_start(GTK_BOX(vbox), rowbox, FALSE, FALSE, 0); | |
4310 | |
4311 label = gtk_label_new(_("Group:")); | |
4312 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
4313 gtk_size_group_add_widget(data->sg, label); | |
4314 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); | |
4315 | |
4316 data->group_combo = gtk_combo_new(); | |
4317 gtk_combo_set_popdown_strings(GTK_COMBO(data->group_combo), groups_tree()); | |
4318 gtk_box_pack_end(GTK_BOX(rowbox), data->group_combo, TRUE, TRUE, 0); | |
4319 | |
4320 if (group) | |
4321 { | |
4322 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(data->group_combo)->entry), | |
4323 group->name); | |
4324 } | |
8137 | 4325 gaim_set_accessible_label (data->group_combo, label); |
7620 | 4326 |
4327 g_signal_connect(G_OBJECT(data->window), "response", | |
4328 G_CALLBACK(add_chat_resp_cb), data); | |
4329 | |
4330 gtk_widget_show_all(data->window); | |
4331 } | |
4332 | |
4333 static void | |
4334 add_group_cb(GaimConnection *gc, const char *group_name) | |
4335 { | |
9285 | 4336 GaimGroup *group; |
4337 | |
4338 group = gaim_group_new(group_name); | |
4339 gaim_blist_add_group(group, NULL); | |
7620 | 4340 } |
4341 | |
4342 void | |
4343 gaim_gtk_blist_request_add_group(void) | |
4344 { | |
7853 | 4345 gaim_request_input(NULL, _("Add Group"), NULL, |
7620 | 4346 _("Please enter the name of the group to be added."), |
8697 | 4347 NULL, FALSE, FALSE, NULL, |
7620 | 4348 _("Add"), G_CALLBACK(add_group_cb), |
4349 _("Cancel"), NULL, NULL); | |
4350 } | |
4351 | |
5228 | 4352 void gaim_gtk_blist_docklet_toggle() { |
4353 /* Useful for the docklet plugin and also for the win32 tray icon*/ | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
4354 /* This is called when one of those is clicked--it will show/hide the |
5228 | 4355 buddy list/login window--depending on which is active */ |
7620 | 4356 if (gaim_connections_get_all()) { |
5228 | 4357 if (gtkblist && gtkblist->window) { |
4358 if (GTK_WIDGET_VISIBLE(gtkblist->window)) { | |
4359 gaim_blist_set_visible(GAIM_WINDOW_ICONIFIED(gtkblist->window) || gaim_gtk_blist_obscured); | |
4360 } else { | |
4361 #if _WIN32 | |
4362 wgaim_systray_maximize(gtkblist->window); | |
4363 #endif | |
4364 gaim_blist_set_visible(TRUE); | |
4365 } | |
4366 } else { | |
4367 /* we're logging in or something... do nothing */ | |
4368 /* or should I make the blist? */ | |
4369 gaim_debug(GAIM_DEBUG_WARNING, "blist", | |
7620 | 4370 "docklet_toggle called with gaim_connections_get_all() " |
5228 | 4371 "but no blist!\n"); |
4372 } | |
4373 } else if (mainwindow) { | |
4374 if (GTK_WIDGET_VISIBLE(mainwindow)) { | |
4375 if (GAIM_WINDOW_ICONIFIED(mainwindow)) { | |
4376 gtk_window_present(GTK_WINDOW(mainwindow)); | |
4377 } else { | |
4378 #if _WIN32 | |
4379 wgaim_systray_minimize(mainwindow); | |
4380 #endif | |
4381 gtk_widget_hide(mainwindow); | |
4382 } | |
4383 } else { | |
4384 #if _WIN32 | |
4385 wgaim_systray_maximize(mainwindow); | |
4386 #endif | |
4387 show_login(); | |
4388 } | |
4389 } else { | |
4390 show_login(); | |
4391 } | |
4392 } | |
4393 | |
4394 void gaim_gtk_blist_docklet_add() | |
4395 { | |
4396 docklet_count++; | |
4397 } | |
4398 | |
4399 void gaim_gtk_blist_docklet_remove() | |
4400 { | |
4401 docklet_count--; | |
4402 if (!docklet_count) { | |
7620 | 4403 if (gaim_connections_get_all()) |
5228 | 4404 gaim_blist_set_visible(TRUE); |
4405 else if (mainwindow) | |
4406 gtk_window_present(GTK_WINDOW(mainwindow)); | |
4407 else | |
4408 show_login(); | |
4409 } | |
4410 } | |
4411 | |
7620 | 4412 static GaimBlistUiOps blist_ui_ops = |
5228 | 4413 { |
4414 gaim_gtk_blist_new_list, | |
5256 | 4415 gaim_gtk_blist_new_node, |
5228 | 4416 gaim_gtk_blist_show, |
4417 gaim_gtk_blist_update, | |
4418 gaim_gtk_blist_remove, | |
4419 gaim_gtk_blist_destroy, | |
7620 | 4420 gaim_gtk_blist_set_visible, |
4421 gaim_gtk_blist_request_add_buddy, | |
4422 gaim_gtk_blist_request_add_chat, | |
4423 gaim_gtk_blist_request_add_group | |
5228 | 4424 }; |
4425 | |
4426 | |
7620 | 4427 GaimBlistUiOps * |
4428 gaim_gtk_blist_get_ui_ops(void) | |
5228 | 4429 { |
4430 return &blist_ui_ops; | |
4431 } | |
4432 | |
7620 | 4433 static void account_signon_cb(GaimConnection *gc, gpointer z) |
4434 { | |
4435 GaimAccount *account = gaim_connection_get_account(gc); | |
4436 GaimBlistNode *gnode, *cnode; | |
4437 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) | |
4438 { | |
4439 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
4440 continue; | |
4441 for(cnode = gnode->child; cnode; cnode = cnode->next) | |
4442 { | |
4443 GaimChat *chat; | |
4444 | |
4445 if(!GAIM_BLIST_NODE_IS_CHAT(cnode)) | |
4446 continue; | |
4447 | |
4448 chat = (GaimChat *)cnode; | |
4449 | |
4450 if(chat->account != account) | |
4451 continue; | |
4452 | |
8197 | 4453 if(gaim_blist_node_get_bool((GaimBlistNode*)chat, "gtk-autojoin") || |
8198 | 4454 (gaim_blist_node_get_string((GaimBlistNode*)chat, |
4455 "gtk-autojoin") != NULL)) | |
7620 | 4456 serv_join_chat(gc, chat->components); |
4457 } | |
4458 } | |
4459 } | |
4460 | |
8815 | 4461 void * |
4462 gaim_gtk_blist_get_handle() { | |
4463 static int handle; | |
4464 | |
4465 return &handle; | |
4466 } | |
4467 | |
7620 | 4468 void gaim_gtk_blist_init(void) |
4469 { | |
8815 | 4470 void *gtk_blist_handle = gaim_gtk_blist_get_handle(); |
7620 | 4471 |
4472 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", | |
8815 | 4473 gtk_blist_handle, GAIM_CALLBACK(account_signon_cb), |
7620 | 4474 NULL); |
7731 | 4475 |
4476 /* Initialize prefs */ | |
8819 | 4477 gaim_prefs_add_none("/gaim/gtk/blist"); |
7731 | 4478 gaim_prefs_add_bool("/gaim/gtk/blist/auto_expand_contacts", TRUE); |
8819 | 4479 gaim_prefs_add_int("/gaim/gtk/blist/button_style", GAIM_BUTTON_TEXT_IMAGE); |
4480 gaim_prefs_add_bool("/gaim/gtk/blist/grey_idle_buddies", TRUE); | |
4481 gaim_prefs_add_bool("/gaim/gtk/blist/raise_on_events", FALSE); | |
4482 gaim_prefs_add_bool("/gaim/gtk/blist/show_buddy_icons", TRUE); | |
4483 gaim_prefs_add_bool("/gaim/gtk/blist/show_empty_groups", FALSE); | |
4484 gaim_prefs_add_bool("/gaim/gtk/blist/show_idle_time", TRUE); | |
4485 gaim_prefs_add_bool("/gaim/gtk/blist/show_offline_buddies", FALSE); | |
4486 gaim_prefs_add_bool("/gaim/gtk/blist/show_warning_level", TRUE); | |
4487 gaim_prefs_add_string("/gaim/gtk/blist/sort_type", ""); | |
4488 gaim_prefs_add_int("/gaim/gtk/blist/x", 0); | |
4489 gaim_prefs_add_int("/gaim/gtk/blist/y", 0); | |
4490 gaim_prefs_add_int("/gaim/gtk/blist/width", 0); | |
4491 gaim_prefs_add_int("/gaim/gtk/blist/height", 0); | |
4492 gaim_prefs_add_int("/gaim/gtk/blist/tooltip_delay", 500); | |
7731 | 4493 |
8815 | 4494 /* Register our signals */ |
4495 gaim_signal_register(gtk_blist_handle, "gtkblist-created", | |
8819 | 4496 gaim_marshal_VOID__POINTER, NULL, 1, |
4497 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
4498 GAIM_SUBTYPE_BLIST)); | |
4499 | |
4500 gaim_signal_register(gtk_blist_handle, "drawing-tooltip", | |
4501 gaim_marshal_VOID__POINTER_POINTER, NULL, 2, | |
4502 gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_BLIST_NODE), | |
4503 gaim_value_new_outgoing(GAIM_TYPE_STRING)); | |
7620 | 4504 } |
4505 | |
8815 | 4506 void |
4507 gaim_gtk_blist_uninit(void) { | |
4508 gaim_signals_unregister_by_instance(gaim_gtk_blist_get_handle()); | |
4509 } | |
5228 | 4510 |
4511 /********************************************************************* | |
4512 * Public utility functions * | |
4513 *********************************************************************/ | |
4514 | |
4515 GdkPixbuf * | |
7620 | 4516 create_prpl_icon(GaimAccount *account) |
5228 | 4517 { |
4518 GaimPlugin *prpl; | |
4519 GaimPluginProtocolInfo *prpl_info = NULL; | |
4520 GdkPixbuf *status = NULL; | |
4521 char *filename = NULL; | |
4522 const char *protoname = NULL; | |
4523 char buf[256]; | |
4524 | |
7956 | 4525 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); |
5228 | 4526 |
4527 if (prpl != NULL) { | |
4528 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
4529 | |
4530 if (prpl_info->list_icon != NULL) | |
4531 protoname = prpl_info->list_icon(account, NULL); | |
4532 } | |
4533 | |
4534 if (protoname == NULL) | |
4535 return NULL; | |
4536 | |
4537 /* | |
4538 * Status icons will be themeable too, and then it will look up | |
4539 * protoname from the theme | |
4540 */ | |
4541 g_snprintf(buf, sizeof(buf), "%s.png", protoname); | |
4542 | |
4543 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", | |
4544 "default", buf, NULL); | |
4545 status = gdk_pixbuf_new_from_file(filename, NULL); | |
4546 g_free(filename); | |
4547 | |
4548 return status; | |
4549 } | |
4550 | |
5422 | 4551 |
4552 /********************************************************************* | |
4553 * Buddy List sorting functions * | |
4554 *********************************************************************/ | |
4555 | |
7620 | 4556 void gaim_gtk_blist_sort_method_reg(const char *id, const char *name, gaim_gtk_blist_sort_function func) |
5422 | 4557 { |
4558 struct gaim_gtk_blist_sort_method *method = g_new0(struct gaim_gtk_blist_sort_method, 1); | |
7620 | 4559 method->id = g_strdup(id); |
5422 | 4560 method->name = g_strdup(name); |
7620 | 4561 method->func = func;; |
5422 | 4562 gaim_gtk_blist_sort_methods = g_slist_append(gaim_gtk_blist_sort_methods, method); |
4563 } | |
4564 | |
7620 | 4565 void gaim_gtk_blist_sort_method_unreg(const char *id){ |
4566 GSList *l = gaim_gtk_blist_sort_methods; | |
4567 | |
4568 while(l) { | |
4569 struct gaim_gtk_blist_sort_method *method = l->data; | |
4570 if(!strcmp(method->id, id)) { | |
4571 gaim_gtk_blist_sort_methods = g_slist_remove(gaim_gtk_blist_sort_methods, method); | |
4572 g_free(method->id); | |
4573 g_free(method->name); | |
4574 g_free(method); | |
4575 break; | |
4576 } | |
4577 } | |
5422 | 4578 } |
4579 | |
7620 | 4580 void gaim_gtk_blist_sort_method_set(const char *id){ |
5422 | 4581 GSList *l = gaim_gtk_blist_sort_methods; |
7620 | 4582 |
4583 if(!id) | |
4584 id = "none"; | |
4585 | |
4586 while (l && strcmp(((struct gaim_gtk_blist_sort_method*)l->data)->id, id)) | |
5422 | 4587 l = l->next; |
7620 | 4588 |
5422 | 4589 if (l) { |
4590 current_sort_method = l->data; | |
4591 } else if (!current_sort_method) { | |
7620 | 4592 gaim_gtk_blist_sort_method_set("none"); |
5422 | 4593 return; |
4594 } | |
4595 redo_buddy_list(gaim_get_blist(), TRUE); | |
4596 | |
4597 } | |
4598 | |
4599 /****************************************** | |
4600 ** Sort Methods | |
4601 ******************************************/ | |
4602 | |
7620 | 4603 static GtkTreeIter sort_method_none(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter parent_iter, GtkTreeIter *cur) |
5422 | 4604 { |
7620 | 4605 GtkTreeIter iter; |
4606 GaimBlistNode *sibling = node->prev; | |
4607 GtkTreeIter sibling_iter; | |
4608 | |
4609 if(cur) | |
5422 | 4610 return *cur; |
7620 | 4611 |
4612 while (sibling && !get_iter_from_node(sibling, &sibling_iter)) { | |
4613 sibling = sibling->prev; | |
5422 | 4614 } |
7620 | 4615 |
4616 gtk_tree_store_insert_after(gtkblist->treemodel, &iter, | |
4617 node->parent ? &parent_iter : NULL, | |
4618 sibling ? &sibling_iter : NULL); | |
4619 | |
5422 | 4620 return iter; |
4621 } | |
4622 | |
7620 | 4623 #if GTK_CHECK_VERSION(2,2,1) |
4624 | |
4625 static GtkTreeIter sort_method_alphabetical(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur) | |
5422 | 4626 { |
4627 GtkTreeIter more_z, iter; | |
4628 GaimBlistNode *n; | |
4629 GValue val = {0,}; | |
7620 | 4630 |
4631 const char *my_name; | |
4632 | |
4633 if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
4634 my_name = gaim_contact_get_alias((GaimContact*)node); | |
4635 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) { | |
4636 my_name = gaim_chat_get_name((GaimChat*)node); | |
4637 } else { | |
4638 return sort_method_none(node, blist, groupiter, cur); | |
4639 } | |
4640 | |
5422 | 4641 |
4642 if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(gtkblist->treemodel), &more_z, &groupiter)) { | |
4643 gtk_tree_store_insert(gtkblist->treemodel, &iter, &groupiter, 0); | |
7620 | 4644 return iter; |
4645 } | |
4646 | |
4647 do { | |
4648 const char *this_name; | |
4649 int cmp; | |
4650 | |
4651 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &more_z, NODE_COLUMN, &val); | |
4652 n = g_value_get_pointer(&val); | |
4653 | |
4654 if(GAIM_BLIST_NODE_IS_CONTACT(n)) { | |
4655 this_name = gaim_contact_get_alias((GaimContact*)n); | |
4656 } else if(GAIM_BLIST_NODE_IS_CHAT(n)) { | |
4657 this_name = gaim_chat_get_name((GaimChat*)n); | |
4658 } else { | |
4659 this_name = NULL; | |
4660 } | |
4661 | |
4662 cmp = gaim_utf8_strcasecmp(my_name, this_name); | |
4663 | |
4664 if(this_name && (cmp < 0 || (cmp == 0 && node < n))) { | |
4665 if(cur) { | |
4666 gtk_tree_store_move_before(gtkblist->treemodel, cur, &more_z); | |
4667 return *cur; | |
4668 } else { | |
4669 gtk_tree_store_insert_before(gtkblist->treemodel, &iter, | |
4670 &groupiter, &more_z); | |
4671 return iter; | |
4672 } | |
4673 } | |
4674 g_value_unset(&val); | |
4675 } while (gtk_tree_model_iter_next (GTK_TREE_MODEL(gtkblist->treemodel), &more_z)); | |
4676 | |
4677 if(cur) { | |
4678 gtk_tree_store_move_before(gtkblist->treemodel, cur, NULL); | |
4679 return *cur; | |
4680 } else { | |
4681 gtk_tree_store_append(gtkblist->treemodel, &iter, &groupiter); | |
4682 return iter; | |
4683 } | |
4684 } | |
4685 | |
4686 static GtkTreeIter sort_method_status(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur) | |
4687 { | |
4688 GtkTreeIter more_z, iter; | |
4689 GaimBlistNode *n; | |
4690 GValue val = {0,}; | |
4691 | |
4692 GaimBuddy *my_buddy, *this_buddy; | |
4693 | |
4694 if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
4695 my_buddy = gaim_contact_get_priority_buddy((GaimContact*)node); | |
4696 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) { | |
4697 if(cur) | |
4698 return *cur; | |
4699 | |
4700 gtk_tree_store_append(gtkblist->treemodel, &iter, &groupiter); | |
4701 return iter; | |
4702 } else { | |
4703 return sort_method_none(node, blist, groupiter, cur); | |
4704 } | |
4705 | |
4706 | |
4707 if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(gtkblist->treemodel), &more_z, &groupiter)) { | |
4708 gtk_tree_store_insert(gtkblist->treemodel, &iter, &groupiter, 0); | |
5422 | 4709 return iter; |
4710 } | |
4711 | |
4712 do { | |
7620 | 4713 int cmp; |
4714 | |
5422 | 4715 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &more_z, NODE_COLUMN, &val); |
4716 n = g_value_get_pointer(&val); | |
7620 | 4717 |
4718 if(GAIM_BLIST_NODE_IS_CONTACT(n)) { | |
4719 this_buddy = gaim_contact_get_priority_buddy((GaimContact*)n); | |
4720 } else { | |
4721 this_buddy = NULL; | |
4722 } | |
4723 | |
4724 cmp = gaim_utf8_strcasecmp(my_buddy ? | |
4725 gaim_contact_get_alias(gaim_buddy_get_contact(my_buddy)) | |
4726 : NULL, this_buddy ? | |
4727 gaim_contact_get_alias(gaim_buddy_get_contact(this_buddy)) | |
4728 : NULL); | |
4729 | |
4730 /* Hideous */ | |
4731 if(!this_buddy || | |
4732 ((my_buddy->present > this_buddy->present) || | |
4733 (my_buddy->present == this_buddy->present && | |
4734 (((my_buddy->uc & UC_UNAVAILABLE) < (this_buddy->uc & UC_UNAVAILABLE)) || | |
4735 (((my_buddy->uc & UC_UNAVAILABLE) == (this_buddy->uc & UC_UNAVAILABLE)) && | |
4736 (((my_buddy->idle == 0) && (this_buddy->idle != 0)) || | |
4737 (this_buddy->idle && (my_buddy->idle > this_buddy->idle)) || | |
4738 ((my_buddy->idle == this_buddy->idle) && | |
4739 (cmp < 0 || (cmp == 0 && node < n))))))))) { | |
4740 if(cur) { | |
4741 gtk_tree_store_move_before(gtkblist->treemodel, cur, &more_z); | |
4742 return *cur; | |
4743 } else { | |
4744 gtk_tree_store_insert_before(gtkblist->treemodel, &iter, | |
4745 &groupiter, &more_z); | |
4746 return iter; | |
4747 } | |
5422 | 4748 } |
4749 g_value_unset(&val); | |
4750 } while (gtk_tree_model_iter_next (GTK_TREE_MODEL(gtkblist->treemodel), &more_z)); | |
7620 | 4751 |
4752 if(cur) { | |
4753 gtk_tree_store_move_before(gtkblist->treemodel, cur, NULL); | |
4754 return *cur; | |
4755 } else { | |
4756 gtk_tree_store_append(gtkblist->treemodel, &iter, &groupiter); | |
4757 return iter; | |
4758 } | |
5422 | 4759 } |
4760 | |
7620 | 4761 static GtkTreeIter sort_method_log(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur) |
5422 | 4762 { |
4763 GtkTreeIter more_z, iter; | |
7620 | 4764 GaimBlistNode *n = NULL, *n2; |
5422 | 4765 GValue val = {0,}; |
7620 | 4766 |
4767 int log_size = 0, this_log_size = 0; | |
4768 const char *buddy_name, *this_buddy_name; | |
4769 | |
4770 if(cur && (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(gtkblist->treemodel), &groupiter) == 1)) | |
4771 return *cur; | |
4772 | |
4773 if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
4774 for (n = node->child; n; n = n->next) | |
8898 | 4775 log_size += gaim_log_get_total_size(GAIM_LOG_IM, ((GaimBuddy*)(n))->name, ((GaimBuddy*)(n))->account); |
7620 | 4776 buddy_name = gaim_contact_get_alias((GaimContact*)node); |
4777 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) { | |
4778 /* we don't have a reliable way of getting the log filename | |
4779 * from the chat info in the blist, yet */ | |
4780 if(cur) | |
4781 return *cur; | |
4782 | |
4783 gtk_tree_store_append(gtkblist->treemodel, &iter, &groupiter); | |
4784 return iter; | |
4785 } else { | |
4786 return sort_method_none(node, blist, groupiter, cur); | |
4787 } | |
4788 | |
4789 | |
5422 | 4790 if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(gtkblist->treemodel), &more_z, &groupiter)) { |
4791 gtk_tree_store_insert(gtkblist->treemodel, &iter, &groupiter, 0); | |
4792 return iter; | |
4793 } | |
4794 | |
4795 do { | |
7620 | 4796 int cmp; |
4797 | |
5422 | 4798 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &more_z, NODE_COLUMN, &val); |
4799 n = g_value_get_pointer(&val); | |
7620 | 4800 this_log_size = 0; |
4801 | |
4802 if(GAIM_BLIST_NODE_IS_CONTACT(n)) { | |
4803 for (n2 = n->child; n2; n2 = n2->next) | |
8898 | 4804 this_log_size += gaim_log_get_total_size(GAIM_LOG_IM, ((GaimBuddy*)(n2))->name, ((GaimBuddy*)(n2))->account); |
7620 | 4805 this_buddy_name = gaim_contact_get_alias((GaimContact*)n); |
4806 } else { | |
4807 this_buddy_name = NULL; | |
5422 | 4808 } |
7620 | 4809 |
4810 cmp = gaim_utf8_strcasecmp(buddy_name, this_buddy_name); | |
4811 | |
4812 if (!GAIM_BLIST_NODE_IS_CONTACT(n) || log_size > this_log_size || | |
4813 ((log_size == this_log_size) && | |
4814 (cmp < 0 || (cmp == 0 && node < n)))) { | |
4815 if(cur) { | |
4816 gtk_tree_store_move_before(gtkblist->treemodel, cur, &more_z); | |
4817 return *cur; | |
4818 } else { | |
4819 gtk_tree_store_insert_before(gtkblist->treemodel, &iter, | |
4820 &groupiter, &more_z); | |
4821 return iter; | |
4822 } | |
5422 | 4823 } |
4824 g_value_unset(&val); | |
4825 } while (gtk_tree_model_iter_next (GTK_TREE_MODEL(gtkblist->treemodel), &more_z)); | |
7620 | 4826 |
4827 if(cur) { | |
4828 gtk_tree_store_move_before(gtkblist->treemodel, cur, NULL); | |
4829 return *cur; | |
4830 } else { | |
4831 gtk_tree_store_append(gtkblist->treemodel, &iter, &groupiter); | |
4832 return iter; | |
4833 } | |
4834 } | |
4835 | |
4836 #endif | |
4837 | |
9015 | 4838 |
7620 | 4839 static void |
9015 | 4840 plugin_act(GtkObject *obk, GaimPluginAction *pam) |
7620 | 4841 { |
9015 | 4842 if (pam->callback) pam->callback(pam); |
5422 | 4843 } |
7620 | 4844 |
8986 | 4845 |
9015 | 4846 |
8986 | 4847 static void |
9015 | 4848 build_plugin_actions(GtkWidget *menu, GaimPlugin *plugin, gpointer context) |
8986 | 4849 { |
9015 | 4850 GtkWidget *menuitem = NULL; |
4851 GaimPluginAction *action = NULL; | |
4852 GList *l, *ll; | |
4853 | |
4854 for (l = ll = GAIM_PLUGIN_ACTIONS(plugin, context); l; l = l->next) { | |
4855 if (l->data) { | |
4856 action = (GaimPluginAction *) l->data; | |
4857 action->plugin = plugin; | |
4858 action->context = context; | |
4859 | |
4860 menuitem = gtk_menu_item_new_with_label(action->label); | |
4861 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
4862 g_signal_connect(G_OBJECT(menuitem), "activate", | |
4863 G_CALLBACK(plugin_act), action); | |
4864 g_object_set_data(G_OBJECT(menuitem), "plugin_action", action); | |
4865 gtk_widget_show(menuitem); | |
4866 } | |
4867 else | |
4868 gaim_separator(menu); | |
4869 } | |
4870 | |
4871 g_list_free(ll); | |
8986 | 4872 } |
4873 | |
4874 | |
7620 | 4875 void |
4876 gaim_gtk_blist_update_protocol_actions(void) | |
4877 { | |
9015 | 4878 GtkWidget *menuitem, *submenu; |
7620 | 4879 GList *l; |
4880 GaimConnection *gc = NULL; | |
9015 | 4881 GaimPlugin *plugin = NULL; |
7620 | 4882 int count = 0; |
9015 | 4883 |
9019 | 4884 if (protomenu == NULL) |
7620 | 4885 return; |
4886 | |
9019 | 4887 /* Clear the old Account Actions menu */ |
9015 | 4888 for (l = gtk_container_get_children(GTK_CONTAINER(protomenu)); l; l = l->next) { |
4889 GaimPluginAction *action; | |
4890 | |
7620 | 4891 menuitem = l->data; |
9015 | 4892 action = (GaimPluginAction *) g_object_get_data(G_OBJECT(menuitem), |
4893 "plugin_action"); | |
4894 g_free(action); | |
7620 | 4895 |
4896 gtk_container_remove(GTK_CONTAINER(protomenu), GTK_WIDGET(menuitem)); | |
4897 } | |
4898 | |
9019 | 4899 /* Count the number of accounts with actions */ |
9015 | 4900 for (l = gaim_connections_get_all(); l; l = l->next) { |
4901 gc = l->data; | |
4902 plugin = gc->prpl; | |
4903 | |
9019 | 4904 if (GAIM_CONNECTION_IS_CONNECTED(gc) && GAIM_PLUGIN_HAS_ACTIONS(plugin)) |
4905 count++; | |
4906 | |
9015 | 4907 /* no need to count past 2, so don't */ |
9019 | 4908 if (count > 1) |
9015 | 4909 break; |
7620 | 4910 } |
4911 | |
9015 | 4912 if (count == 0) { |
4913 menuitem = gtk_menu_item_new_with_label(_("No actions available")); | |
7620 | 4914 gtk_menu_shell_append(GTK_MENU_SHELL(protomenu), menuitem); |
9015 | 4915 gtk_widget_set_sensitive(menuitem, FALSE); |
7620 | 4916 gtk_widget_show(menuitem); |
4917 } | |
9019 | 4918 |
4919 else if (count == 1) { | |
4920 /* Find the one account that has actions */ | |
4921 for (l = gaim_connections_get_all(); l; l = l->next) { | |
4922 gc = l->data; | |
4923 plugin = gc->prpl; | |
4924 | |
4925 if (GAIM_CONNECTION_IS_CONNECTED(gc) && GAIM_PLUGIN_HAS_ACTIONS(plugin)) | |
4926 break; | |
4927 } | |
4928 | |
9015 | 4929 build_plugin_actions(protomenu, plugin, gc); |
7620 | 4930 } |
9019 | 4931 |
7620 | 4932 else { |
9015 | 4933 for (l = gaim_connections_get_all(); l; l = l->next) { |
7620 | 4934 GaimAccount *account; |
4935 GdkPixbuf *pixbuf, *scale; | |
4936 GtkWidget *image; | |
9015 | 4937 char *buf; |
4938 | |
4939 gc = l->data; | |
4940 plugin = gc->prpl; | |
4941 | |
9019 | 4942 if (!GAIM_CONNECTION_IS_CONNECTED(gc) || !GAIM_PLUGIN_HAS_ACTIONS(plugin)) |
7620 | 4943 continue; |
4944 | |
4945 account = gaim_connection_get_account(gc); | |
9015 | 4946 buf = g_strconcat(gaim_account_get_username(account), " (", |
4947 plugin->info->name, ")", NULL); | |
7620 | 4948 menuitem = gtk_image_menu_item_new_with_label(buf); |
9015 | 4949 g_free(buf); |
4950 | |
4951 pixbuf = create_prpl_icon(account); | |
9019 | 4952 if (pixbuf) { |
7620 | 4953 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, |
4954 GDK_INTERP_BILINEAR); | |
4955 image = gtk_image_new_from_pixbuf(scale); | |
4956 g_object_unref(G_OBJECT(pixbuf)); | |
4957 g_object_unref(G_OBJECT(scale)); | |
4958 gtk_widget_show(image); | |
9015 | 4959 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); |
7620 | 4960 } |
4961 | |
4962 gtk_menu_shell_append(GTK_MENU_SHELL(protomenu), menuitem); | |
4963 gtk_widget_show(menuitem); | |
4964 | |
4965 submenu = gtk_menu_new(); | |
4966 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); | |
4967 gtk_widget_show(submenu); | |
4968 | |
9015 | 4969 build_plugin_actions(submenu, plugin, gc); |
7620 | 4970 } |
4971 } | |
4972 } | |
8986 | 4973 |
4974 | |
4975 void | |
4976 gaim_gtk_blist_update_plugin_actions(void) | |
4977 { | |
9015 | 4978 GtkWidget *menuitem, *submenu; |
4979 GaimPlugin *plugin = NULL; | |
8986 | 4980 GList *l; |
4981 int count = 0; | |
4982 | |
9019 | 4983 if (pluginmenu == NULL) |
8986 | 4984 return; |
4985 | |
9019 | 4986 /* Clear the old Account Actions menu */ |
9015 | 4987 for (l = gtk_container_get_children(GTK_CONTAINER(pluginmenu)); l; l = l->next) { |
4988 GaimPluginAction *action; | |
8986 | 4989 |
4990 menuitem = l->data; | |
9015 | 4991 action = g_object_get_data(G_OBJECT(menuitem), "plugin_action"); |
4992 g_free(action); | |
8986 | 4993 |
4994 gtk_container_remove(GTK_CONTAINER(pluginmenu), GTK_WIDGET(menuitem)); | |
4995 } | |
4996 | |
9019 | 4997 /* Count the number of plugins with actions */ |
9015 | 4998 for (l = gaim_plugins_get_loaded(); l; l = l->next) { |
4999 plugin = (GaimPlugin *) l->data; | |
5000 | |
9019 | 5001 if (!GAIM_IS_PROTOCOL_PLUGIN(plugin) && GAIM_PLUGIN_HAS_ACTIONS(plugin)) |
5002 count++; | |
5003 | |
5004 /* no need to count past 2, so don't */ | |
5005 if (count > 1) | |
9015 | 5006 break; |
8986 | 5007 } |
5008 | |
5009 if (count == 0) { | |
5010 menuitem = gtk_menu_item_new_with_label(_("No actions available")); | |
5011 gtk_menu_shell_append(GTK_MENU_SHELL(pluginmenu), menuitem); | |
9015 | 5012 gtk_widget_set_sensitive(menuitem, FALSE); |
8986 | 5013 gtk_widget_show(menuitem); |
5014 } | |
9019 | 5015 |
5016 else if (count == 1) { | |
5017 /* Find the one plugin that has actions */ | |
5018 for (l = gaim_plugins_get_loaded(); l; l = l->next) { | |
5019 plugin = (GaimPlugin *) l->data; | |
5020 | |
5021 if (!GAIM_IS_PROTOCOL_PLUGIN(plugin) && GAIM_PLUGIN_HAS_ACTIONS(plugin)) | |
5022 break; | |
5023 } | |
5024 | |
9015 | 5025 build_plugin_actions(pluginmenu, plugin, NULL); |
8986 | 5026 } |
9019 | 5027 |
8986 | 5028 else { |
9015 | 5029 for (l = gaim_plugins_get_loaded(); l; l = l->next) { |
5030 plugin = (GaimPlugin *) l->data; | |
5031 | |
5032 if (GAIM_IS_PROTOCOL_PLUGIN(plugin)) | |
8986 | 5033 continue; |
5034 | |
9019 | 5035 if (!GAIM_PLUGIN_HAS_ACTIONS(plugin)) |
9015 | 5036 continue; |
5037 | |
5038 menuitem = gtk_image_menu_item_new_with_label(plugin->info->name); | |
8986 | 5039 gtk_menu_shell_append(GTK_MENU_SHELL(pluginmenu), menuitem); |
5040 gtk_widget_show(menuitem); | |
5041 | |
5042 submenu = gtk_menu_new(); | |
5043 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); | |
5044 gtk_widget_show(submenu); | |
5045 | |
9015 | 5046 build_plugin_actions(submenu, plugin, NULL); |
8986 | 5047 } |
5048 } | |
5049 } |