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