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