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