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