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