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