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