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