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