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