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