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