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