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