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