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