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