Mercurial > pidgin.yaz
annotate src/gtkblist.c @ 10490:a3a540ed2518
[gaim-migrate @ 11780]
some random jabber stuff, remove a duplicate #define, and shuffle account
loading so we're not emitting signals that haven't been registered yet
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Sat, 08 Jan 2005 21:10:17 +0000 |
parents | ec82cbb21fe8 |
children | d0c336ad0b27 |
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 | |
2230 if(!GAIM_BLIST_NODE_IS_CONTACT(node)) | |
2231 return FALSE; | |
2232 | |
2233 gtknode = node->ui_data; | |
2234 | |
2235 if (!gtknode->contact_expanded) { | |
2236 GtkTreeIter i; | |
10382
9f28196ed769
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10357
diff
changeset
|
2237 |
10354 | 2238 gaim_gtk_blist_expand_contact_cb(NULL, node); |
10382
9f28196ed769
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10357
diff
changeset
|
2239 |
10354 | 2240 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, >kblist->contact_rect); |
2241 gdk_drawable_get_size(GDK_DRAWABLE(tv->window), &(gtkblist->contact_rect.width), NULL); | |
2242 gtkblist->mouseover_contact = node; | |
2243 gtk_tree_path_down (path); | |
2244 while (gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &i, path)) { | |
2245 GdkRectangle rect; | |
2246 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, &rect); | |
2247 gtkblist->contact_rect.height += rect.height; | |
2248 gtk_tree_path_next(path); | |
2249 } | |
2250 } | |
2251 gtk_tree_path_free(path); | |
2252 return FALSE; | |
2253 } | |
2254 | |
5228 | 2255 static gboolean gaim_gtk_blist_tooltip_timeout(GtkWidget *tv) |
2256 { | |
2257 GtkTreePath *path; | |
2258 GtkTreeIter iter; | |
2259 GaimBlistNode *node; | |
2260 GValue val = {0}; | |
9869 | 2261 int scr_w, scr_h, w, h, x, y; |
2262 #if GTK_CHECK_VERSION(2,2,0) | |
2263 int mon_num; | |
2264 GdkScreen *screen = NULL; | |
2265 #endif | |
5234 | 2266 PangoLayout *layout; |
7636 | 2267 gboolean tooltip_top = FALSE; |
5234 | 2268 char *tooltiptext = NULL; |
7636 | 2269 struct _gaim_gtk_blist_node *gtknode; |
9773 | 2270 GdkRectangle mon_size; |
7662 | 2271 #ifdef WANT_DROP_SHADOW |
7620 | 2272 GdkWindowAttr attr; |
2273 #endif | |
5228 | 2274 |
7636 | 2275 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 | 2276 return FALSE; |
2277 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
2278 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
2279 node = g_value_get_pointer(&val); | |
7620 | 2280 |
2281 if(!GAIM_BLIST_NODE_IS_CONTACT(node) && !GAIM_BLIST_NODE_IS_BUDDY(node) | |
2282 && !GAIM_BLIST_NODE_IS_CHAT(node)) | |
5234 | 2283 return FALSE; |
5228 | 2284 |
7636 | 2285 gtknode = node->ui_data; |
2286 | |
2287 gtk_tree_path_free(path); | |
2288 | |
5234 | 2289 tooltiptext = gaim_get_tooltip_text(node); |
7620 | 2290 |
2291 if(!tooltiptext) | |
2292 return FALSE; | |
2293 | |
7837 | 2294 if(gtkblist->tipwindow) |
2295 gtk_widget_destroy(gtkblist->tipwindow); | |
5234 | 2296 gtkblist->tipwindow = gtk_window_new(GTK_WINDOW_POPUP); |
2297 gtk_widget_set_app_paintable(gtkblist->tipwindow, TRUE); | |
2298 gtk_window_set_resizable(GTK_WINDOW(gtkblist->tipwindow), FALSE); | |
2299 gtk_widget_set_name(gtkblist->tipwindow, "gtk-tooltips"); | |
2300 g_signal_connect(G_OBJECT(gtkblist->tipwindow), "expose_event", | |
2301 G_CALLBACK(gaim_gtk_blist_paint_tip), node); | |
2302 gtk_widget_ensure_style (gtkblist->tipwindow); | |
7837 | 2303 |
7662 | 2304 #ifdef WANT_DROP_SHADOW |
10015 | 2305 if (!xcomposite_is_present()) { |
2306 attr.window_type = GDK_WINDOW_TEMP; | |
2307 attr.override_redirect = TRUE; | |
2308 attr.x = gtkblist->tipwindow->allocation.x; | |
2309 attr.y = gtkblist->tipwindow->allocation.y; | |
2310 attr.width = gtkblist->tipwindow->allocation.width; | |
2311 attr.height = gtkblist->tipwindow->allocation.height; | |
2312 attr.wclass = GDK_INPUT_OUTPUT; | |
2313 attr.visual = gtk_widget_get_visual (gtkblist->window); | |
2314 attr.colormap = gtk_widget_get_colormap (gtkblist->window); | |
2315 | |
2316 attr.event_mask = gtk_widget_get_events (gtkblist->tipwindow); | |
2317 | |
2318 attr.event_mask |= (GDK_EXPOSURE_MASK | GDK_KEY_PRESS_MASK | | |
2319 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK ); | |
2320 if(gtkblist->east_shadow) { | |
2321 gdk_window_set_user_data (gtkblist->east_shadow, NULL); | |
2322 gdk_window_destroy (gtkblist->east_shadow); | |
2323 } | |
2324 gtkblist->east_shadow = gdk_window_new(gtk_widget_get_root_window(gtkblist->tipwindow), &attr, | |
2325 GDK_WA_NOREDIR | GDK_WA_VISUAL | GDK_WA_COLORMAP); | |
2326 gdk_window_set_user_data (gtkblist->east_shadow, gtkblist->tipwindow); | |
2327 gdk_window_set_back_pixmap (gtkblist->east_shadow, NULL, FALSE); | |
2328 | |
2329 if(gtkblist->south_shadow) { | |
2330 gdk_window_set_user_data (gtkblist->south_shadow, NULL); | |
2331 gdk_window_destroy (gtkblist->south_shadow); | |
2332 } | |
2333 gtkblist->south_shadow = gdk_window_new(gtk_widget_get_root_window(gtkblist->tipwindow), &attr, | |
2334 GDK_WA_NOREDIR | GDK_WA_VISUAL | GDK_WA_COLORMAP); | |
2335 gdk_window_set_user_data (gtkblist->south_shadow, gtkblist->tipwindow); | |
2336 gdk_window_set_back_pixmap (gtkblist->south_shadow, NULL, FALSE); | |
7897 | 2337 } |
7620 | 2338 #endif |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2339 |
5234 | 2340 layout = gtk_widget_create_pango_layout (gtkblist->tipwindow, NULL); |
2341 pango_layout_set_wrap(layout, PANGO_WRAP_WORD); | |
2342 pango_layout_set_width(layout, 300000); | |
2343 pango_layout_set_markup(layout, tooltiptext, strlen(tooltiptext)); | |
2344 pango_layout_get_size (layout, &w, &h); | |
9773 | 2345 |
9869 | 2346 #if GTK_CHECK_VERSION(2,2,0) |
9773 | 2347 gdk_display_get_pointer(gdk_display_get_default(), &screen, &x, &y, NULL); |
2348 mon_num = gdk_screen_get_monitor_at_point(screen, x, y); | |
2349 gdk_screen_get_monitor_geometry(screen, mon_num, &mon_size); | |
2350 | |
2351 scr_w = mon_size.width + mon_size.x; | |
2352 scr_h = mon_size.height + mon_size.y; | |
9869 | 2353 #else |
2354 scr_w = gdk_screen_width(); | |
2355 scr_h = gdk_screen_height(); | |
2356 gdk_window_get_pointer(NULL, &x, &y, NULL); | |
2357 mon_size.x = 0; | |
2358 mon_size.y = 0; | |
2359 #endif | |
9773 | 2360 |
5234 | 2361 w = PANGO_PIXELS(w) + 8; |
2362 h = PANGO_PIXELS(h) + 8; | |
5228 | 2363 |
5234 | 2364 /* 38 is the size of a large status icon plus 4 pixels padding on each side. |
2365 * I should #define this or something */ | |
2366 w = w + 38; | |
2367 h = MAX(h, 38); | |
2368 | |
10482 | 2369 /* Now the size of the buddy icon */ |
2370 { | |
2371 GdkPixbuf *avatar = NULL; | |
2372 | |
2373 if ((avatar = gaim_gtk_blist_get_buddy_icon(node, FALSE, FALSE))) { | |
2374 w += gdk_pixbuf_get_width(avatar) + 8; | |
2375 h = MAX(h, gdk_pixbuf_get_height(avatar) + 8); | |
2376 g_object_unref(avatar); | |
2377 } | |
2378 } | |
2379 | |
9869 | 2380 #if GTK_CHECK_VERSION(2,2,0) |
10046 | 2381 if (w > mon_size.width) |
9773 | 2382 w = mon_size.width - 10; |
2383 | |
10046 | 2384 if (h > mon_size.height) |
9773 | 2385 h = mon_size.height - 10; |
9869 | 2386 #endif |
9773 | 2387 |
5234 | 2388 if (GTK_WIDGET_NO_WINDOW(gtkblist->window)) |
2389 y+=gtkblist->window->allocation.y; | |
2390 | |
2391 x -= ((w >> 1) + 4); | |
5228 | 2392 |
7636 | 2393 if ((y + h + 4) > scr_h || tooltip_top) |
7620 | 2394 y = y - h - 5; |
5234 | 2395 else |
2396 y = y + 6; | |
7620 | 2397 |
9773 | 2398 if (y < mon_size.y) |
2399 y = mon_size.y; | |
2400 | |
2401 if (y != mon_size.y) { | |
7719 | 2402 if ((x + w) > scr_w) |
2403 x -= (x + w + 5) - scr_w; | |
9773 | 2404 else if (x < mon_size.x) |
2405 x = mon_size.x; | |
7719 | 2406 } else { |
2407 x -= (w / 2 + 10); | |
9773 | 2408 if (x < mon_size.x) |
2409 x = mon_size.x; | |
7719 | 2410 } |
2411 | |
5234 | 2412 g_object_unref (layout); |
2413 g_free(tooltiptext); | |
2414 gtk_widget_set_size_request(gtkblist->tipwindow, w, h); | |
2415 gtk_window_move(GTK_WINDOW(gtkblist->tipwindow), x, y); | |
2416 gtk_widget_show(gtkblist->tipwindow); | |
5228 | 2417 |
7662 | 2418 #ifdef WANT_DROP_SHADOW |
10015 | 2419 if (!xcomposite_is_present()) { |
2420 map_shadow_windows(gtkblist); | |
2421 } | |
7620 | 2422 #endif |
2423 | |
5228 | 2424 return FALSE; |
2425 } | |
2426 | |
10354 | 2427 static gboolean gaim_gtk_blist_drag_motion_cb(GtkWidget *tv, GdkDragContext *drag_context, |
2428 gint x, gint y, guint time, gpointer user_data) | |
2429 { | |
2430 GtkTreePath *path; | |
2431 int delay; | |
2432 | |
2433 delay = 500; | |
2434 | |
2435 if (gtkblist->drag_timeout) { | |
2436 if ((y > gtkblist->tip_rect.y) && ((y - gtkblist->tip_rect.height) < gtkblist->tip_rect.y)) | |
2437 return FALSE; | |
2438 /* We've left the cell. Remove the timeout and create a new one below */ | |
2439 g_source_remove(gtkblist->drag_timeout); | |
2440 } | |
2441 | |
2442 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), x, y, &path, NULL, NULL, NULL); | |
2443 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, >kblist->tip_rect); | |
2444 | |
2445 if (path) | |
2446 gtk_tree_path_free(path); | |
2447 gtkblist->drag_timeout = g_timeout_add(delay, (GSourceFunc)gaim_gtk_blist_expand_timeout, tv); | |
2448 | |
2449 if (gtkblist->mouseover_contact) { | |
2450 if ((y < gtkblist->contact_rect.y) || ((y - gtkblist->contact_rect.height) > gtkblist->contact_rect.y)) { | |
2451 gaim_gtk_blist_collapse_contact_cb(NULL, gtkblist->mouseover_contact); | |
2452 gtkblist->mouseover_contact = NULL; | |
2453 } | |
2454 } | |
2455 | |
2456 return FALSE; | |
2457 } | |
2458 | |
5228 | 2459 static gboolean gaim_gtk_blist_motion_cb (GtkWidget *tv, GdkEventMotion *event, gpointer null) |
2460 { | |
2461 GtkTreePath *path; | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2462 int delay; |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2463 |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2464 delay = gaim_prefs_get_int("/gaim/gtk/blist/tooltip_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 if (delay == 0) |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2467 return FALSE; |
8083 | 2468 |
5228 | 2469 if (gtkblist->timeout) { |
7636 | 2470 if ((event->y > gtkblist->tip_rect.y) && ((event->y - gtkblist->tip_rect.height) < gtkblist->tip_rect.y)) |
5228 | 2471 return FALSE; |
2472 /* We've left the cell. Remove the timeout and create a new one below */ | |
8254 | 2473 gaim_gtk_blist_tooltip_destroy(); |
5228 | 2474 g_source_remove(gtkblist->timeout); |
2475 } | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2476 |
5228 | 2477 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL); |
7636 | 2478 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
|
2479 |
5228 | 2480 if (path) |
2481 gtk_tree_path_free(path); | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2482 gtkblist->timeout = g_timeout_add(delay, (GSourceFunc)gaim_gtk_blist_tooltip_timeout, tv); |
7636 | 2483 |
2484 if (gtkblist->mouseover_contact) { | |
2485 if ((event->y < gtkblist->contact_rect.y) || ((event->y - gtkblist->contact_rect.height) > gtkblist->contact_rect.y)) { | |
2486 gaim_gtk_blist_collapse_contact_cb(NULL, gtkblist->mouseover_contact); | |
2487 gtkblist->mouseover_contact = NULL; | |
2488 } | |
2489 } | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2490 |
5228 | 2491 return FALSE; |
2492 } | |
2493 | |
2494 static void gaim_gtk_blist_leave_cb (GtkWidget *w, GdkEventCrossing *e, gpointer n) | |
2495 { | |
8083 | 2496 |
5228 | 2497 if (gtkblist->timeout) { |
2498 g_source_remove(gtkblist->timeout); | |
2499 gtkblist->timeout = 0; | |
2500 } | |
10382
9f28196ed769
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10357
diff
changeset
|
2501 |
10354 | 2502 if (gtkblist->drag_timeout) { |
2503 g_source_remove(gtkblist->drag_timeout); | |
2504 gtkblist->drag_timeout = 0; | |
2505 } | |
2506 | |
8254 | 2507 gaim_gtk_blist_tooltip_destroy(); |
7720 | 2508 |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2509 if (gtkblist->mouseover_contact && |
9811 | 2510 !((e->x > gtkblist->contact_rect.x) && (e->x < (gtkblist->contact_rect.x + gtkblist->contact_rect.width)) && |
2511 (e->y > gtkblist->contact_rect.y) && (e->y < (gtkblist->contact_rect.y + gtkblist->contact_rect.height)))) { | |
2512 gaim_gtk_blist_collapse_contact_cb(NULL, gtkblist->mouseover_contact); | |
7636 | 2513 gtkblist->mouseover_contact = NULL; |
2514 } | |
5228 | 2515 } |
2516 | |
2517 static void | |
2518 toggle_debug(void) | |
2519 { | |
7620 | 2520 gaim_prefs_set_bool("/gaim/gtk/debug/enabled", |
2521 !gaim_prefs_get_bool("/gaim/gtk/debug/enabled")); | |
5228 | 2522 } |
2523 | |
2524 | |
2525 /*************************************************** | |
2526 * Crap * | |
2527 ***************************************************/ | |
2528 static GtkItemFactoryEntry blist_menu[] = | |
2529 { | |
2530 /* Buddies menu */ | |
2531 { N_("/_Buddies"), NULL, NULL, 0, "<Branch>" }, | |
9714 | 2532 { N_("/Buddies/New Instant _Message..."), "<CTL>M", gaim_gtkdialogs_im, 0, "<StockItem>", GAIM_STOCK_IM }, |
8940 | 2533 { N_("/Buddies/Join a _Chat..."), "<CTL>C", gaim_gtk_blist_joinchat_show, 0, "<StockItem>", GAIM_STOCK_CHAT }, |
9714 | 2534 { N_("/Buddies/Get User _Info..."), "<CTL>I", gaim_gtkdialogs_info, 0, "<StockItem>", GAIM_STOCK_INFO }, |
2535 { N_("/Buddies/View User _Log..."), "<CTL>L", gaim_gtkdialogs_log, 0, NULL }, | |
5228 | 2536 { "/Buddies/sep1", NULL, NULL, 0, "<Separator>" }, |
10019
8cc6f0bfa215
[gaim-migrate @ 10943]
Luke Schierer <lschiere@pidgin.im>
parents:
10018
diff
changeset
|
2537 { 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
|
2538 { N_("/Buddies/Show _Empty Groups"), "<CTL>E", gaim_gtk_blist_show_empty_groups_cb, 1, "<CheckItem>"}, |
7853 | 2539 { N_("/Buddies/_Add Buddy..."), "<CTL>B", gaim_gtk_blist_add_buddy_cb, 0, "<StockItem>", GTK_STOCK_ADD }, |
2540 { N_("/Buddies/Add C_hat..."), NULL, gaim_gtk_blist_add_chat_cb, 0, "<StockItem>", GTK_STOCK_ADD }, | |
2541 { N_("/Buddies/Add _Group..."), NULL, gaim_blist_request_add_group, 0, "<StockItem>", GTK_STOCK_ADD }, | |
5228 | 2542 { "/Buddies/sep2", NULL, NULL, 0, "<Separator>" }, |
10273 | 2543 { N_("/Buddies/_Log Out"), "<CTL>D", gaim_connections_disconnect_all, 0, "<StockItem>", GAIM_STOCK_SIGN_OFF }, |
7620 | 2544 { N_("/Buddies/_Quit"), "<CTL>Q", gaim_core_quit, 0, "<StockItem>", GTK_STOCK_QUIT }, |
5228 | 2545 |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2546 /* Tools */ |
5228 | 2547 { N_("/_Tools"), NULL, NULL, 0, "<Branch>" }, |
2548 { N_("/Tools/Buddy _Pounce"), NULL, NULL, 0, "<Branch>" }, | |
8845 | 2549 { N_("/Tools/Account Ac_tions"), NULL, NULL, 0, "<Branch>" }, |
8986 | 2550 { N_("/Tools/Pl_ugin Actions"), NULL, NULL, 0, "<Branch>" }, |
5228 | 2551 { "/Tools/sep1", NULL, NULL, 0, "<Separator>" }, |
10325 | 2552 { N_("/Tools/_Statuses"), NULL, gaim_gtk_status_window_show, 0, "<StockItem>", GAIM_STOCK_ICON_AWAY }, |
7620 | 2553 { N_("/Tools/A_ccounts"), "<CTL>A", gaim_gtk_accounts_window_show, 0, "<StockItem>", GAIM_STOCK_ACCOUNTS }, |
10325 | 2554 { N_("/Tools/Pr_eferences"), "<CTL>P", gaim_gtk_prefs_show, 0, "<StockItem>", GTK_STOCK_PREFERENCES }, |
2555 { 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
|
2556 { N_("/Tools/_File Transfers"), "<CTL>T", gaim_show_xfer_dialog, 0, "<StockItem>", GAIM_STOCK_FILE_TRANSFER }, |
8113 | 2557 { N_("/Tools/R_oom List"), NULL, gaim_gtk_roomlist_dialog_show, 0, NULL }, |
10325 | 2558 { "/Tools/sep2", NULL, NULL, 0, "<Separator>" }, |
10074 | 2559 { N_("/Tools/Mute _Sounds"), "<CTL>S", gaim_gtk_blist_mute_sounds_cb, 0, "<CheckItem>"}, |
7620 | 2560 { N_("/Tools/View System _Log"), NULL, gtk_blist_show_systemlog_cb, 0, NULL }, |
5228 | 2561 |
2562 /* Help */ | |
2563 { N_("/_Help"), NULL, NULL, 0, "<Branch>" }, | |
2564 { N_("/Help/Online _Help"), "F1", gtk_blist_show_onlinehelp_cb, 0, "<StockItem>", GTK_STOCK_HELP }, | |
7620 | 2565 { N_("/Help/_Debug Window"), NULL, toggle_debug, 0, NULL }, |
9753 | 2566 { N_("/Help/_About"), NULL, gaim_gtkdialogs_about, 0, "<StockItem>", GAIM_STOCK_ABOUT }, |
5228 | 2567 }; |
2568 | |
2569 /********************************************************* | |
2570 * Private Utility functions * | |
2571 *********************************************************/ | |
7620 | 2572 static void |
2573 rename_group_cb(GaimGroup *g, const char *new_name) | |
2574 { | |
2575 gaim_blist_rename_group(g, new_name); | |
2576 } | |
2577 | |
9285 | 2578 /* |
2579 * Should disallow empty group names. | |
2580 */ | |
7620 | 2581 static void |
2582 show_rename_group(GtkWidget *unused, GaimGroup *g) | |
2583 { | |
2584 gaim_request_input(NULL, _("Rename Group"), _("New group name"), | |
2585 _("Please enter a new name for the selected group."), | |
8697 | 2586 g->name, FALSE, FALSE, NULL, |
7620 | 2587 _("OK"), G_CALLBACK(rename_group_cb), |
2588 _("Cancel"), NULL, g); | |
2589 } | |
5228 | 2590 |
5234 | 2591 static char *gaim_get_tooltip_text(GaimBlistNode *node) |
5228 | 2592 { |
10475 | 2593 GString *str = g_string_new(""); |
5237 | 2594 GaimPlugin *prpl; |
2595 GaimPluginProtocolInfo *prpl_info = NULL; | |
10475 | 2596 char *tmp; |
2597 | |
2598 if (GAIM_BLIST_NODE_IS_CHAT(node)) | |
2599 { | |
2600 GaimChat *chat; | |
2601 GList *cur; | |
5274 | 2602 struct proto_chat_entry *pce; |
10475 | 2603 char *name, *value; |
2604 | |
2605 chat = (GaimChat *)node; | |
7956 | 2606 prpl = gaim_find_prpl(gaim_account_get_protocol_id(chat->account)); |
5274 | 2607 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
2608 | |
10475 | 2609 tmp = g_markup_escape_text(gaim_chat_get_name(chat), -1); |
2610 g_string_append_printf(str, "<span size='larger' weight='bold'>%s</span>", tmp); | |
2611 g_free(tmp); | |
2612 | |
2613 if (g_list_length(gaim_connections_get_all()) > 1) | |
2614 { | |
2615 tmp = g_markup_escape_text(chat->account->username, -1); | |
2616 g_string_append_printf(str, _("\n<b>Account:</b> %s"), tmp); | |
2617 g_free(tmp); | |
2618 } | |
2619 | |
9959 | 2620 if (prpl_info->chat_info != NULL) |
10475 | 2621 cur = prpl_info->chat_info(chat->account->gc); |
2622 else | |
2623 cur = NULL; | |
2624 | |
2625 while (cur != NULL) | |
2626 { | |
2627 pce = cur->data; | |
2628 | |
2629 if (!pce->secret && (!pce->required && | |
2630 g_hash_table_lookup(chat->components, pce->identifier) == NULL)) | |
2631 { | |
2632 tmp = gaim_text_strip_mnemonic(pce->label); | |
2633 name = g_markup_escape_text(tmp, -1); | |
2634 g_free(tmp); | |
2635 value = g_markup_escape_text(g_hash_table_lookup( | |
2636 chat->components, pce->identifier), -1); | |
2637 g_string_append_printf(str, "\n<b>%s</b> %s", name, value); | |
2638 g_free(name); | |
8020 | 2639 g_free(value); |
2640 } | |
10475 | 2641 |
5274 | 2642 g_free(pce); |
10475 | 2643 cur = g_list_remove(cur, pce); |
5274 | 2644 } |
10475 | 2645 } |
2646 else if (GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_BUDDY(node)) | |
2647 { | |
2648 GaimContact *c; | |
7620 | 2649 GaimBuddy *b; |
9944 | 2650 GaimPresence *presence; |
10475 | 2651 char *tmp; |
9944 | 2652 gboolean idle; |
2653 time_t idle_secs; | |
10475 | 2654 int lastseen; |
9944 | 2655 unsigned int warning_level; |
10475 | 2656 |
2657 if (GAIM_BLIST_NODE_IS_CONTACT(node)) | |
2658 { | |
2659 c = (GaimContact *)node; | |
2660 b = gaim_contact_get_priority_buddy(c); | |
2661 } | |
2662 else | |
2663 { | |
7620 | 2664 b = (GaimBuddy *)node; |
10475 | 2665 c = gaim_buddy_get_contact(b); |
7620 | 2666 } |
2667 | |
7956 | 2668 prpl = gaim_find_prpl(gaim_account_get_protocol_id(b->account)); |
5234 | 2669 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
2670 | |
10475 | 2671 presence = gaim_buddy_get_presence(b); |
2672 | |
2673 /* Buddy Name */ | |
2674 tmp = g_markup_escape_text(gaim_buddy_get_name(b), -1); | |
2675 g_string_append_printf(str, "<span size='larger' weight='bold'>%s</span>", tmp); | |
2676 g_free(tmp); | |
2677 | |
2678 /* Account */ | |
2679 if (g_list_length(gaim_connections_get_all()) > 1) | |
2680 { | |
2681 tmp = g_markup_escape_text(gaim_account_get_username( | |
2682 gaim_buddy_get_account(b)), -1); | |
2683 g_string_append_printf(str, _("\n<b>Account:</b> %s"), tmp); | |
2684 g_free(tmp); | |
2685 } | |
2686 | |
2687 /* Contact Alias */ | |
2688 if (GAIM_BLIST_NODE_IS_CONTACT(node) && | |
2689 (gaim_contact_get_alias(c) != NULL)) | |
2690 { | |
2691 tmp = g_markup_escape_text(gaim_contact_get_alias(c), -1); | |
2692 g_string_append_printf(str, _("\n<b>Contact Alias:</b> %s"), tmp); | |
2693 g_free(tmp); | |
2694 } | |
2695 | |
2696 /* Alias */ | |
2697 if ((b->alias != NULL) && (b->alias[0] != '\0')) | |
2698 { | |
2699 tmp = g_markup_escape_text(b->alias, -1); | |
2700 g_string_append_printf(str, _("\n<b>Alias:</b> %s"), tmp); | |
2701 g_free(tmp); | |
2702 } | |
2703 | |
2704 /* Nickname/Server Alias */ | |
2705 if (b->server_alias != NULL) | |
2706 { | |
2707 tmp = g_markup_escape_text(b->server_alias, -1); | |
2708 g_string_append_printf(str, _("\n<b>Nickname:</b> %s"), tmp); | |
2709 g_free(tmp); | |
2710 } | |
2711 | |
2712 /* Logged In */ | |
2713 if (b->signon > 0) | |
2714 { | |
2715 tmp = gaim_str_seconds_to_string(time(NULL) - b->signon); | |
2716 g_string_append_printf(str, _("\n<b>Logged In:</b> %s"), tmp); | |
2717 g_free(tmp); | |
2718 } | |
2719 | |
2720 /* Idle */ | |
2721 idle = gaim_presence_is_idle(presence); | |
2722 if (idle) | |
2723 { | |
2724 idle_secs = gaim_presence_get_idle_time(presence); | |
2725 if (idle_secs > 0) | |
2726 { | |
2727 tmp = gaim_str_seconds_to_string(time(NULL) - idle_secs); | |
2728 g_string_append_printf(str, _("\n<b>Idle:</b> %s"), tmp); | |
2729 g_free(tmp); | |
2730 } | |
2731 else | |
2732 g_string_append_printf(str, _("\n<b>Idle</b>")); | |
2733 } | |
2734 | |
2735 /* Last Seen */ | |
2736 if ((b->present == GAIM_BUDDY_SIGNING_ON) || | |
2737 (b->present == GAIM_BUDDY_OFFLINE)) | |
2738 { | |
2739 lastseen = gaim_blist_node_get_int(&b->node, "last_seen"); | |
2740 if (lastseen > 0) | |
2741 { | |
2742 tmp = gaim_str_seconds_to_string(time(NULL) - lastseen); | |
2743 g_string_append_printf(str, _("\n<b>Last Seen:</b> %s ago"), tmp); | |
2744 g_free(tmp); | |
5234 | 2745 } |
2746 } | |
2747 | |
10475 | 2748 /* Warning */ |
9949 | 2749 warning_level = gaim_presence_get_warning_level(presence); |
9944 | 2750 if (warning_level > 0) |
10475 | 2751 { |
2752 tmp = g_strdup_printf(_("%d%%"), warning_level); | |
2753 g_string_append_printf(str, _("\n<b>Warned:</b> %s"), tmp); | |
2754 g_free(tmp); | |
2755 } | |
2756 | |
2757 /* Offline? */ | |
2758 if (!GAIM_BUDDY_IS_ONLINE(b)) { | |
2759 g_string_append_printf(str, _("\n<b>Status:</b> Offline")); | |
2760 } | |
2761 else if (prpl_info && prpl_info->tooltip_text) | |
2762 { | |
2763 /* Additional text from the PRPL */ | |
2764 const char *end; | |
2765 tmp = prpl_info->tooltip_text(b); | |
2766 | |
2767 if (tmp && !g_utf8_validate(tmp, -1, &end)) | |
2768 { | |
2769 char *new = g_strndup(tmp, g_utf8_pointer_to_offset(tmp, end)); | |
2770 g_free(tmp); | |
2771 tmp = new; | |
2772 } | |
2773 | |
2774 g_string_append(str, tmp); | |
10476 | 2775 g_free(tmp); |
10475 | 2776 } |
2777 | |
2778 /* These are Easter Eggs. Patches to remove them will be rejected. */ | |
2779 if (!g_ascii_strcasecmp(b->name, "robflynn")) | |
2780 g_string_append(str, _("\n<b>Description:</b> Spooky")); | |
2781 if (!g_ascii_strcasecmp(b->name, "seanegn")) | |
2782 g_string_append(str, _("\n<b>Status:</b> Awesome")); | |
2783 if (!g_ascii_strcasecmp(b->name, "chipx86")) | |
2784 g_string_append(str, _("\n<b>Status:</b> Rockin'")); | |
5234 | 2785 } |
10475 | 2786 |
8824 | 2787 gaim_signal_emit(gaim_gtk_blist_get_handle(), |
10477 | 2788 "drawing-tooltip", node, str); |
10475 | 2789 |
2790 return g_string_free(str, FALSE); | |
5228 | 2791 } |
2792 | |
7620 | 2793 struct _emblem_data { |
9954 | 2794 const char *filename; |
7620 | 2795 int x; |
2796 int y; | |
2797 }; | |
2798 | |
9944 | 2799 GdkPixbuf * |
2800 gaim_gtk_blist_get_status_icon(GaimBlistNode *node, GaimStatusIconSize size) | |
5228 | 2801 { |
7620 | 2802 GdkPixbuf *scale, *status = NULL; |
2803 int i, scalesize = 30; | |
2804 char *filename; | |
5228 | 2805 const char *protoname = NULL; |
7620 | 2806 struct _gaim_gtk_blist_node *gtknode = node->ui_data; |
2807 struct _emblem_data emblems[4] = {{NULL, 15, 15}, {NULL, 0, 15}, | |
2808 {NULL, 0, 0}, {NULL, 15, 0}}; | |
9944 | 2809 GaimPresence *presence = NULL; |
7620 | 2810 GaimBuddy *buddy = NULL; |
2811 GaimChat *chat = NULL; | |
2812 | |
2813 if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
2814 if(!gtknode->contact_expanded) | |
2815 buddy = gaim_contact_get_priority_buddy((GaimContact*)node); | |
2816 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
2817 buddy = (GaimBuddy*)node; | |
2818 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) { | |
2819 chat = (GaimChat*)node; | |
2820 } else { | |
5228 | 2821 return NULL; |
5234 | 2822 } |
2823 | |
7620 | 2824 if(buddy || chat) { |
2825 GaimAccount *account; | |
2826 GaimPlugin *prpl; | |
2827 GaimPluginProtocolInfo *prpl_info; | |
2828 | |
2829 if(buddy) | |
2830 account = buddy->account; | |
2831 else | |
2832 account = chat->account; | |
2833 | |
7956 | 2834 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); |
7620 | 2835 if(!prpl) |
2836 return NULL; | |
2837 | |
2838 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
2839 | |
2840 if(prpl_info && prpl_info->list_icon) { | |
2841 protoname = prpl_info->list_icon(account, buddy); | |
2842 } | |
2843 if(prpl_info && prpl_info->list_emblems && buddy) { | |
2844 if(buddy->present != GAIM_BUDDY_SIGNING_OFF) | |
2845 prpl_info->list_emblems(buddy, &emblems[0].filename, | |
2846 &emblems[1].filename, &emblems[2].filename, | |
2847 &emblems[3].filename); | |
2848 } | |
5234 | 2849 } |
5228 | 2850 |
7620 | 2851 if(size == GAIM_STATUS_ICON_SMALL) { |
5228 | 2852 scalesize = 15; |
7620 | 2853 /* So that only the se icon will composite */ |
2854 emblems[1].filename = emblems[2].filename = emblems[3].filename = NULL; | |
5228 | 2855 } |
2856 | |
7620 | 2857 if(buddy && buddy->present == GAIM_BUDDY_SIGNING_ON) { |
2858 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "login.png", NULL); | |
2859 } else if(buddy && buddy->present == GAIM_BUDDY_SIGNING_OFF) { | |
2860 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "logout.png", NULL); | |
2861 } else if(buddy || chat) { | |
5228 | 2862 char *image = g_strdup_printf("%s.png", protoname); |
2863 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
2864 g_free(image); | |
7620 | 2865 } else { |
2866 /* gaim dude */ | |
2867 filename = g_build_filename(DATADIR, "pixmaps", "gaim.png", NULL); | |
5228 | 2868 } |
7620 | 2869 |
2870 status = gdk_pixbuf_new_from_file(filename, NULL); | |
2871 g_free(filename); | |
2872 | |
2873 if(!status) | |
2874 return NULL; | |
2875 | |
2876 scale = gdk_pixbuf_scale_simple(status, scalesize, scalesize, | |
2877 GDK_INTERP_BILINEAR); | |
2878 g_object_unref(status); | |
2879 | |
2880 for(i=0; i<4; i++) { | |
2881 if(emblems[i].filename) { | |
2882 GdkPixbuf *emblem; | |
2883 char *image = g_strdup_printf("%s.png", emblems[i].filename); | |
2884 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
2885 g_free(image); | |
2886 emblem = gdk_pixbuf_new_from_file(filename, NULL); | |
2887 g_free(filename); | |
2888 if(emblem) { | |
2889 if(i == 0 && size == GAIM_STATUS_ICON_SMALL) { | |
2890 gdk_pixbuf_composite(emblem, | |
2891 scale, 5, 5, | |
2892 10, 10, | |
2893 5, 5, | |
2894 .6, .6, | |
2895 GDK_INTERP_BILINEAR, | |
2896 255); | |
2897 } else { | |
2898 gdk_pixbuf_composite(emblem, | |
2899 scale, emblems[i].x, emblems[i].y, | |
2900 15, 15, | |
2901 emblems[i].x, emblems[i].y, | |
2902 1, 1, | |
2903 GDK_INTERP_BILINEAR, | |
2904 255); | |
2905 } | |
2906 g_object_unref(emblem); | |
2907 } | |
5228 | 2908 } |
2909 } | |
7620 | 2910 |
2911 if(buddy) { | |
9944 | 2912 presence = gaim_buddy_get_presence(buddy); |
2913 | |
2914 if (!GAIM_BUDDY_IS_ONLINE(buddy)) | |
7620 | 2915 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE); |
10118 | 2916 else if (gaim_presence_is_idle(presence)) |
9944 | 2917 { |
7620 | 2918 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.25, FALSE); |
9944 | 2919 } |
5228 | 2920 } |
7620 | 2921 |
5228 | 2922 return scale; |
2923 } | |
2924 | |
7620 | 2925 static gchar *gaim_gtk_blist_get_name_markup(GaimBuddy *b, gboolean selected) |
5228 | 2926 { |
7620 | 2927 const char *name; |
2928 char *esc, *text = NULL; | |
5228 | 2929 GaimPlugin *prpl; |
2930 GaimPluginProtocolInfo *prpl_info = NULL; | |
7620 | 2931 GaimContact *contact; |
9944 | 2932 GaimPresence *presence; |
7620 | 2933 struct _gaim_gtk_blist_node *gtkcontactnode = NULL; |
5228 | 2934 char *idletime = NULL, *warning = NULL, *statustext = NULL; |
9944 | 2935 unsigned int warning_level; |
5228 | 2936 time_t t; |
7620 | 2937 /* XXX Clean up this crap */ |
2938 | |
2939 contact = (GaimContact*)((GaimBlistNode*)b)->parent; | |
2940 if(contact) | |
2941 gtkcontactnode = ((GaimBlistNode*)contact)->ui_data; | |
2942 | |
2943 if(gtkcontactnode && !gtkcontactnode->contact_expanded && contact->alias) | |
2944 name = contact->alias; | |
2945 else | |
9620 | 2946 name = gaim_buddy_get_alias(b); |
7620 | 2947 esc = g_markup_escape_text(name, strlen(name)); |
2948 | |
7956 | 2949 prpl = gaim_find_prpl(gaim_account_get_protocol_id(b->account)); |
5228 | 2950 |
2951 if (prpl != NULL) | |
2952 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
2953 | |
9944 | 2954 presence = gaim_buddy_get_presence(b); |
2955 | |
7620 | 2956 if (!gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")) { |
9944 | 2957 |
10118 | 2958 if ((gaim_presence_is_idle(presence) || !GAIM_BUDDY_IS_ONLINE(b)) && !selected) |
9944 | 2959 { |
10118 | 2960 text = g_strdup_printf("<span color='%s'>%s</span>", |
2961 dim_grey(), esc); | |
5228 | 2962 g_free(esc); |
2963 return text; | |
7620 | 2964 } |
9944 | 2965 else |
5228 | 2966 return esc; |
2967 } | |
2968 | |
8122
36674144c510
[gaim-migrate @ 8826]
Christian Hammond <chipx86@chipx86.com>
parents:
8113
diff
changeset
|
2969 if (prpl_info && prpl_info->status_text && b->account->gc) { |
5228 | 2970 char *tmp = prpl_info->status_text(b); |
2971 const char *end; | |
2972 | |
2973 if(tmp && !g_utf8_validate(tmp, -1, &end)) { | |
2974 char *new = g_strndup(tmp, | |
2975 g_utf8_pointer_to_offset(tmp, end)); | |
2976 g_free(tmp); | |
2977 tmp = new; | |
2978 } | |
2979 | |
10288 | 2980 #if !GTK_CHECK_VERSION(2,6,0) |
5228 | 2981 if(tmp) { |
2982 char buf[32]; | |
2983 char *c = tmp; | |
2984 int length = 0, vis=0; | |
2985 gboolean inside = FALSE; | |
2986 g_strdelimit(tmp, "\n", ' '); | |
7620 | 2987 gaim_str_strip_cr(tmp); |
5228 | 2988 |
2989 while(*c && vis < 20) { | |
2990 if(*c == '&') | |
2991 inside = TRUE; | |
2992 else if(*c == ';') | |
2993 inside = FALSE; | |
2994 if(!inside) | |
2995 vis++; | |
7620 | 2996 c = g_utf8_next_char(c); /* this is fun */ |
5228 | 2997 } |
2998 | |
7620 | 2999 length = c - tmp; |
3000 | |
5228 | 3001 if(vis == 20) |
3002 g_snprintf(buf, sizeof(buf), "%%.%ds...", length); | |
3003 else | |
3004 g_snprintf(buf, sizeof(buf), "%%s "); | |
3005 | |
3006 statustext = g_strdup_printf(buf, tmp); | |
3007 | |
3008 g_free(tmp); | |
3009 } | |
10288 | 3010 #else |
3011 statustext = tmp; | |
3012 #endif | |
5228 | 3013 } |
3014 | |
10351 | 3015 if (gaim_presence_is_idle(presence)) { |
9944 | 3016 time_t idle_secs = gaim_presence_get_idle_time(presence); |
3017 | |
10351 | 3018 if (idle_secs > 0) { |
9944 | 3019 int ihrs, imin; |
3020 | |
3021 time(&t); | |
3022 ihrs = (t - idle_secs) / 3600; | |
3023 imin = ((t - idle_secs) / 60) % 60; | |
3024 | |
3025 if (ihrs) | |
3026 idletime = g_strdup_printf(_("Idle (%dh%02dm) "), ihrs, imin); | |
3027 else | |
3028 idletime = g_strdup_printf(_("Idle (%dm) "), imin); | |
3029 } | |
5228 | 3030 else |
9944 | 3031 idletime = g_strdup(_("Idle ")); |
5228 | 3032 } |
3033 | |
9944 | 3034 warning_level = gaim_presence_get_warning_level(presence); |
3035 | |
10351 | 3036 if (warning_level > 0) { |
9944 | 3037 warning = g_strdup_printf(_("Warned (%d%%) "), warning_level); |
3038 } | |
5228 | 3039 |
3040 if(!GAIM_BUDDY_IS_ONLINE(b) && !statustext) | |
7620 | 3041 statustext = g_strdup(_("Offline ")); |
3042 | |
10118 | 3043 if (gaim_presence_is_idle(presence) && !selected) { |
3044 text = g_strdup_printf("<span color='%s'>%s</span>\n" | |
3045 "<span color='%s' size='smaller'>%s%s%s</span>", | |
3046 dim_grey(), esc, dim_grey(), | |
5228 | 3047 statustext != NULL ? statustext : "", |
3048 idletime != NULL ? idletime : "", | |
3049 warning != NULL ? warning : ""); | |
7620 | 3050 } else if (statustext == NULL && idletime == NULL && warning == NULL && |
3051 GAIM_BUDDY_IS_ONLINE(b)) { | |
5228 | 3052 text = g_strdup(esc); |
3053 } else { | |
10118 | 3054 if (selected) |
3055 text = g_strdup_printf("%s\n" | |
3056 "<span size='smaller'>%s%s%s</span>", esc, | |
3057 statustext != NULL ? statustext : "", | |
3058 idletime != NULL ? idletime : "", | |
3059 warning != NULL ? warning : ""); | |
3060 else | |
3061 text = g_strdup_printf("%s\n" | |
3062 "<span color='%s' size='smaller'>%s%s%s</span>", esc, | |
10144 | 3063 dim_grey(), |
10118 | 3064 statustext != NULL ? statustext : "", |
3065 idletime != NULL ? idletime : "", | |
3066 warning != NULL ? warning : ""); | |
5228 | 3067 } |
3068 if (idletime) | |
3069 g_free(idletime); | |
3070 if (warning) | |
3071 g_free(warning); | |
3072 if (statustext) | |
3073 g_free(statustext); | |
3074 if (esc) | |
3075 g_free(esc); | |
3076 | |
3077 return text; | |
3078 } | |
3079 | |
3080 static void gaim_gtk_blist_restore_position() | |
3081 { | |
7620 | 3082 int blist_x, blist_y, blist_width, blist_height; |
3083 | |
3084 blist_width = gaim_prefs_get_int("/gaim/gtk/blist/width"); | |
3085 | |
3086 /* if the window exists, is hidden, we're saving positions, and the | |
3087 * position is sane... */ | |
3088 if (gtkblist && gtkblist->window && | |
3089 !GTK_WIDGET_VISIBLE(gtkblist->window) && blist_width != 0) { | |
3090 | |
3091 blist_x = gaim_prefs_get_int("/gaim/gtk/blist/x"); | |
3092 blist_y = gaim_prefs_get_int("/gaim/gtk/blist/y"); | |
3093 blist_height = gaim_prefs_get_int("/gaim/gtk/blist/height"); | |
3094 | |
5228 | 3095 /* ...check position is on screen... */ |
7620 | 3096 if (blist_x >= gdk_screen_width()) |
3097 blist_x = gdk_screen_width() - 100; | |
3098 else if (blist_x + blist_width < 0) | |
3099 blist_x = 100; | |
3100 | |
3101 if (blist_y >= gdk_screen_height()) | |
3102 blist_y = gdk_screen_height() - 100; | |
3103 else if (blist_y + blist_height < 0) | |
3104 blist_y = 100; | |
3105 | |
5228 | 3106 /* ...and move it back. */ |
7620 | 3107 gtk_window_move(GTK_WINDOW(gtkblist->window), blist_x, blist_y); |
3108 gtk_window_resize(GTK_WINDOW(gtkblist->window), blist_width, blist_height); | |
5228 | 3109 } |
3110 } | |
3111 | |
7620 | 3112 static gboolean gaim_gtk_blist_refresh_timer(GaimBuddyList *list) |
5228 | 3113 { |
7620 | 3114 GaimBlistNode *gnode, *cnode; |
3115 | |
3116 for(gnode = list->root; gnode; gnode = gnode->next) { | |
3117 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
5234 | 3118 continue; |
7620 | 3119 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
3120 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
9944 | 3121 GaimBuddy *buddy; |
3122 | |
3123 buddy = gaim_contact_get_priority_buddy((GaimContact*)cnode); | |
10012 | 3124 |
3125 if (buddy && | |
3126 gaim_presence_is_idle(gaim_buddy_get_presence(buddy))) | |
9944 | 3127 gaim_gtk_blist_update(list, cnode); |
7620 | 3128 } |
5228 | 3129 } |
3130 } | |
3131 | |
3132 /* keep on going */ | |
3133 return TRUE; | |
3134 } | |
3135 | |
7620 | 3136 static void gaim_gtk_blist_hide_node(GaimBuddyList *list, GaimBlistNode *node) |
5260 | 3137 { |
3138 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; | |
3139 GtkTreeIter iter; | |
3140 | |
3141 if (!gtknode || !gtknode->row || !gtkblist) | |
3142 return; | |
3143 | |
3144 if(gtkblist->selected_node == node) | |
3145 gtkblist->selected_node = NULL; | |
3146 | |
3147 if (get_iter_from_node(node, &iter)) { | |
3148 gtk_tree_store_remove(gtkblist->treemodel, &iter); | |
7620 | 3149 if(GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_BUDDY(node) |
3150 || GAIM_BLIST_NODE_IS_CHAT(node)) { | |
5260 | 3151 gaim_gtk_blist_update(list, node->parent); |
3152 } | |
3153 } | |
3154 gtk_tree_row_reference_free(gtknode->row); | |
3155 gtknode->row = NULL; | |
3156 } | |
3157 | |
10352 | 3158 static const char *require_connection[] = |
7620 | 3159 { |
10352 | 3160 N_("/Buddies/New Instant Message..."), |
3161 N_("/Buddies/Join a Chat..."), | |
3162 N_("/Buddies/Get User Info..."), | |
3163 N_("/Buddies/Add Buddy..."), | |
3164 N_("/Buddies/Add Chat..."), | |
3165 N_("/Buddies/Add Group..."), | |
3166 N_("/Buddies/Log Out") | |
3167 }; | |
3168 | |
10357 | 3169 static const int require_connection_size = sizeof(require_connection) |
3170 / sizeof(*require_connection); | |
10352 | 3171 |
3172 /** | |
3173 * Rebuild dynamic menus and make menu items sensitive/insensitive | |
3174 * where appropriate. | |
3175 */ | |
3176 static void | |
3177 update_menu_bar(GaimGtkBuddyList *gtkblist) | |
3178 { | |
8937 | 3179 GtkWidget *widget; |
10352 | 3180 gboolean sensitive; |
3181 int i; | |
3182 | |
3183 g_return_if_fail(gtkblist != NULL); | |
8259
4f9f68ab8770
[gaim-migrate @ 8982]
Christian Hammond <chipx86@chipx86.com>
parents:
8254
diff
changeset
|
3184 |
7620 | 3185 gaim_gtk_blist_update_protocol_actions(); |
8235 | 3186 gaim_gtkpounce_menu_build(gtkblist->bpmenu); |
8937 | 3187 |
10352 | 3188 sensitive = (gaim_connections_get_all() != NULL); |
3189 | |
10357 | 3190 for (i = 0; i < require_connection_size; i++) |
10352 | 3191 { |
3192 widget = gtk_item_factory_get_widget(gtkblist->ift, require_connection[i]); | |
3193 gtk_widget_set_sensitive(widget, sensitive); | |
3194 } | |
3195 | |
8940 | 3196 widget = gtk_item_factory_get_widget(gtkblist->ift, N_("/Buddies/Join a Chat...")); |
3197 gtk_widget_set_sensitive(widget, gaim_gtk_blist_joinchat_is_showable()); | |
3198 | |
8937 | 3199 widget = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Room List")); |
8939 | 3200 gtk_widget_set_sensitive(widget, gaim_gtk_roomlist_is_showable()); |
8938 | 3201 |
3202 widget = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Privacy")); | |
3203 gtk_widget_set_sensitive(widget, gaim_gtk_privacy_is_showable()); | |
7620 | 3204 } |
3205 | |
10352 | 3206 static void |
3207 sign_on_off_cb(GaimConnection *gc, GaimBuddyList *blist) | |
3208 { | |
3209 GaimGtkBuddyList *gtkblist = GAIM_GTK_BLIST(blist); | |
3210 | |
3211 update_menu_bar(gtkblist); | |
3212 } | |
8986 | 3213 |
3214 static void | |
3215 plugin_changed_cb(GaimPlugin *p, gpointer *data) | |
3216 { | |
3217 gaim_gtk_blist_update_plugin_actions(); | |
3218 } | |
3219 | |
5228 | 3220 /********************************************************************************** |
3221 * Public API Functions * | |
3222 **********************************************************************************/ | |
9774 | 3223 |
7620 | 3224 static void gaim_gtk_blist_new_list(GaimBuddyList *blist) |
5228 | 3225 { |
7620 | 3226 GaimGtkBuddyList *gtkblist; |
3227 | |
3228 gtkblist = g_new0(GaimGtkBuddyList, 1); | |
3229 blist->ui_data = gtkblist; | |
5228 | 3230 } |
3231 | |
5256 | 3232 static void gaim_gtk_blist_new_node(GaimBlistNode *node) |
3233 { | |
3234 node->ui_data = g_new0(struct _gaim_gtk_blist_node, 1); | |
3235 } | |
3236 | |
5228 | 3237 void gaim_gtk_blist_update_columns() |
3238 { | |
3239 if(!gtkblist) | |
3240 return; | |
3241 | |
7620 | 3242 if (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")) { |
5228 | 3243 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, TRUE); |
3244 gtk_tree_view_column_set_visible(gtkblist->idle_column, FALSE); | |
3245 gtk_tree_view_column_set_visible(gtkblist->warning_column, FALSE); | |
3246 } else { | |
10351 | 3247 gtk_tree_view_column_set_visible(gtkblist->idle_column, TRUE); |
3248 gtk_tree_view_column_set_visible(gtkblist->warning_column, TRUE); | |
5228 | 3249 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, FALSE); |
3250 } | |
3251 } | |
3252 | |
10433 | 3253 enum { |
3254 DRAG_BUDDY, | |
3255 DRAG_ROW, | |
3256 DRAG_VCARD, | |
3257 DRAG_TEXT, | |
3258 DRAG_URI, | |
3259 NUM_TARGETS | |
3260 }; | |
5228 | 3261 |
3262 static char * | |
3263 item_factory_translate_func (const char *path, gpointer func_data) | |
3264 { | |
7620 | 3265 return _((char *)path); |
5228 | 3266 } |
3267 | |
5422 | 3268 void gaim_gtk_blist_setup_sort_methods() |
3269 { | |
7620 | 3270 gaim_gtk_blist_sort_method_reg("none", _("None"), sort_method_none); |
3271 #if GTK_CHECK_VERSION(2,2,1) | |
3272 gaim_gtk_blist_sort_method_reg("alphabetical", _("Alphabetical"), sort_method_alphabetical); | |
3273 gaim_gtk_blist_sort_method_reg("status", _("By status"), sort_method_status); | |
3274 gaim_gtk_blist_sort_method_reg("log_size", _("By log size"), sort_method_log); | |
3275 #endif | |
3276 gaim_gtk_blist_sort_method_set(gaim_prefs_get_string("/gaim/gtk/blist/sort_type")); | |
3277 } | |
3278 | |
10433 | 3279 static void _prefs_change_redo_list() |
3280 { | |
7620 | 3281 redo_buddy_list(gaim_get_blist(), TRUE); |
3282 } | |
3283 | |
3284 static void _prefs_change_sort_method(const char *pref_name, GaimPrefType type, | |
10433 | 3285 gpointer val, gpointer data) |
3286 { | |
7620 | 3287 if(!strcmp(pref_name, "/gaim/gtk/blist/sort_type")) |
3288 gaim_gtk_blist_sort_method_set(val); | |
3289 } | |
3290 | |
10433 | 3291 /* |
3292 * "This is so dead sexy." | |
3293 * "Two thumbs up." | |
3294 * "Best movie of the year." | |
3295 * | |
3296 * This is the function that handles CTRL+F searching in the buddy list. | |
3297 * It finds the top-most buddy/group/chat/whatever containing the | |
3298 * entered string. | |
3299 * | |
3300 * It's somewhat ineffecient, because we strip all the HTML from the | |
3301 * "name" column of the buddy list (because the GtkTreeModel does not | |
3302 * contain the screen name in a non-markedup format). But the alternative | |
3303 * is to add an extra column to the GtkTreeModel. And this function is | |
3304 * used rarely, so it shouldn't matter TOO much. | |
3305 */ | |
3306 static gboolean | |
3307 _search_func(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer search_data) | |
3308 { | |
10435 | 3309 gboolean result; |
10433 | 3310 gchar *enteredstring; |
10439 | 3311 gchar *withmarkup; |
10433 | 3312 gchar *nomarkup; |
3313 const gchar *normalized; | |
10435 | 3314 |
3315 gtk_tree_model_get(model, iter, column, &withmarkup, -1); | |
10433 | 3316 |
3317 enteredstring = g_strdup(gaim_normalize(NULL, key)); | |
3318 nomarkup = gaim_markup_strip_html(withmarkup); | |
3319 normalized = gaim_normalize(NULL, nomarkup); | |
3320 | |
3321 result = (g_strstr_len(normalized, strlen(normalized), enteredstring) == NULL); | |
3322 | |
10439 | 3323 g_free(withmarkup); |
10433 | 3324 g_free(enteredstring); |
3325 g_free(nomarkup); | |
3326 | |
3327 return result; | |
3328 } | |
3329 | |
7620 | 3330 static void gaim_gtk_blist_show(GaimBuddyList *list) |
5228 | 3331 { |
10087 | 3332 void *handle; |
5228 | 3333 GtkCellRenderer *rend; |
3334 GtkTreeViewColumn *column; | |
10178
96a850ab30c8
[gaim-migrate @ 11293]
Christian Hammond <chipx86@chipx86.com>
parents:
10144
diff
changeset
|
3335 GtkWidget *menu; |
5228 | 3336 GtkWidget *sw; |
10178
96a850ab30c8
[gaim-migrate @ 11293]
Christian Hammond <chipx86@chipx86.com>
parents:
10144
diff
changeset
|
3337 GtkWidget *selector; |
5228 | 3338 GtkAccelGroup *accel_group; |
3339 GtkTreeSelection *selection; | |
9556 | 3340 GtkTargetEntry dte[] = {{"GAIM_BLIST_NODE", GTK_TARGET_SAME_APP, DRAG_ROW}, |
8089 | 3341 {"application/x-im-contact", 0, DRAG_BUDDY}, |
9495 | 3342 {"text/x-vcard", 0, DRAG_VCARD }, |
9525 | 3343 {"text/uri-list", 0, DRAG_URI}, |
3344 {"text/plain", 0, DRAG_TEXT}}; | |
9556 | 3345 GtkTargetEntry ste[] = {{"GAIM_BLIST_NODE", GTK_TARGET_SAME_APP, DRAG_ROW}, |
3346 {"application/x-im-contact", 0, DRAG_BUDDY}, | |
3347 {"text/x-vcard", 0, DRAG_VCARD }}; | |
5228 | 3348 if (gtkblist && gtkblist->window) { |
10282 | 3349 if (gaim_prefs_get_bool("/gaim/gtk/blist/list_visible") || docklet_count == 0) |
3350 gtk_widget_show(gtkblist->window); | |
5228 | 3351 return; |
3352 } | |
3353 | |
3354 gtkblist = GAIM_GTK_BLIST(list); | |
3355 | |
3356 gtkblist->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
3357 gtk_window_set_role(GTK_WINDOW(gtkblist->window), "buddy_list"); | |
9746 | 3358 gtk_window_set_title(GTK_WINDOW(gtkblist->window), _("Buddy List")); |
5228 | 3359 |
3360 gtkblist->vbox = gtk_vbox_new(FALSE, 0); | |
10178
96a850ab30c8
[gaim-migrate @ 11293]
Christian Hammond <chipx86@chipx86.com>
parents:
10144
diff
changeset
|
3361 gtk_widget_show(gtkblist->vbox); |
5228 | 3362 gtk_container_add(GTK_CONTAINER(gtkblist->window), gtkblist->vbox); |
3363 | |
3364 g_signal_connect(G_OBJECT(gtkblist->window), "delete_event", G_CALLBACK(gtk_blist_delete_cb), NULL); | |
3365 g_signal_connect(G_OBJECT(gtkblist->window), "configure_event", G_CALLBACK(gtk_blist_configure_cb), NULL); | |
3366 g_signal_connect(G_OBJECT(gtkblist->window), "visibility_notify_event", G_CALLBACK(gtk_blist_visibility_cb), NULL); | |
3367 gtk_widget_add_events(gtkblist->window, GDK_VISIBILITY_NOTIFY_MASK); | |
3368 | |
3369 /******************************* Menu bar *************************************/ | |
3370 accel_group = gtk_accel_group_new(); | |
3371 gtk_window_add_accel_group(GTK_WINDOW (gtkblist->window), accel_group); | |
3372 g_object_unref(accel_group); | |
5427 | 3373 gtkblist->ift = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GaimMain>", accel_group); |
9811 | 3374 gtk_item_factory_set_translate_func(gtkblist->ift, |
3375 item_factory_translate_func, | |
3376 NULL, NULL); | |
5427 | 3377 gtk_item_factory_create_items(gtkblist->ift, sizeof(blist_menu) / sizeof(*blist_menu), |
9811 | 3378 blist_menu, NULL); |
7620 | 3379 gaim_gtk_load_accels(); |
3380 g_signal_connect(G_OBJECT(accel_group), "accel-changed", | |
3381 G_CALLBACK(gaim_gtk_save_accels_cb), NULL); | |
10178
96a850ab30c8
[gaim-migrate @ 11293]
Christian Hammond <chipx86@chipx86.com>
parents:
10144
diff
changeset
|
3382 menu = gtk_item_factory_get_widget(gtkblist->ift, "<GaimMain>"); |
96a850ab30c8
[gaim-migrate @ 11293]
Christian Hammond <chipx86@chipx86.com>
parents:
10144
diff
changeset
|
3383 gtk_widget_show(menu); |
96a850ab30c8
[gaim-migrate @ 11293]
Christian Hammond <chipx86@chipx86.com>
parents:
10144
diff
changeset
|
3384 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), menu, FALSE, FALSE, 0); |
5228 | 3385 |
5427 | 3386 gtkblist->bpmenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Buddy Pounce")); |
8844 | 3387 protomenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Account Actions")); |
8986 | 3388 pluginmenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Plugin Actions")); |
10352 | 3389 |
5228 | 3390 /****************************** GtkTreeView **********************************/ |
3391 sw = gtk_scrolled_window_new(NULL,NULL); | |
10178
96a850ab30c8
[gaim-migrate @ 11293]
Christian Hammond <chipx86@chipx86.com>
parents:
10144
diff
changeset
|
3392 gtk_widget_show(sw); |
5228 | 3393 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); |
3394 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
3395 | |
7620 | 3396 gtkblist->treemodel = gtk_tree_store_new(BLIST_COLUMNS, |
3397 GDK_TYPE_PIXBUF, G_TYPE_BOOLEAN, G_TYPE_STRING, | |
3398 G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_POINTER); | |
5228 | 3399 |
3400 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
|
3401 gtk_widget_show(gtkblist->treeview); |
9176 | 3402 gtk_widget_set_name(gtkblist->treeview, "gaim_gtkblist_treeview"); |
5228 | 3403 |
3404 /* Set up selection stuff */ | |
3405 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)); | |
3406 g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(gaim_gtk_blist_selection_changed), NULL); | |
3407 | |
3408 /* Set up dnd */ | |
7650 | 3409 gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(gtkblist->treeview), |
9811 | 3410 GDK_BUTTON1_MASK, ste, 3, |
3411 GDK_ACTION_COPY); | |
7650 | 3412 gtk_tree_view_enable_model_drag_dest(GTK_TREE_VIEW(gtkblist->treeview), |
9811 | 3413 dte, 5, |
3414 GDK_ACTION_COPY | GDK_ACTION_MOVE); | |
7636 | 3415 |
10087 | 3416 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-received", G_CALLBACK(gaim_gtk_blist_drag_data_rcv_cb), NULL); |
5228 | 3417 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-get", G_CALLBACK(gaim_gtk_blist_drag_data_get_cb), NULL); |
10433 | 3418 |
10354 | 3419 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-motion", G_CALLBACK(gaim_gtk_blist_drag_motion_cb), NULL); |
5228 | 3420 |
3421 /* Tooltips */ | |
3422 g_signal_connect(G_OBJECT(gtkblist->treeview), "motion-notify-event", G_CALLBACK(gaim_gtk_blist_motion_cb), NULL); | |
3423 g_signal_connect(G_OBJECT(gtkblist->treeview), "leave-notify-event", G_CALLBACK(gaim_gtk_blist_leave_cb), NULL); | |
3424 | |
3425 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(gtkblist->treeview), FALSE); | |
3426 | |
3427 column = gtk_tree_view_column_new (); | |
3428 | |
3429 rend = gtk_cell_renderer_pixbuf_new(); | |
9811 | 3430 gtk_tree_view_column_pack_start(column, rend, FALSE); |
3431 gtk_tree_view_column_set_attributes(column, rend, | |
3432 "pixbuf", STATUS_ICON_COLUMN, | |
3433 "visible", STATUS_ICON_VISIBLE_COLUMN, | |
3434 NULL); | |
5228 | 3435 g_object_set(rend, "xalign", 0.0, "ypad", 0, NULL); |
3436 | |
3437 rend = gtk_cell_renderer_text_new(); | |
3438 gtk_tree_view_column_pack_start (column, rend, TRUE); | |
9811 | 3439 gtk_tree_view_column_set_attributes(column, rend, |
3440 "markup", NAME_COLUMN, | |
3441 NULL); | |
5228 | 3442 g_object_set(rend, "ypad", 0, "yalign", 0.5, NULL); |
10285 | 3443 #if GTK_CHECK_VERSION(2,6,0) |
3444 gtk_tree_view_column_set_expand (column, TRUE); | |
3445 g_object_set(rend, "ellipsize", PANGO_ELLIPSIZE_END); | |
3446 #endif | |
5228 | 3447 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); |
3448 | |
3449 rend = gtk_cell_renderer_text_new(); | |
10351 | 3450 gtkblist->idle_column = gtk_tree_view_column_new_with_attributes("Idle", rend, "markup", IDLE_COLUMN, NULL); |
3451 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->idle_column); | |
5228 | 3452 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); |
3453 | |
3454 rend = gtk_cell_renderer_text_new(); | |
10351 | 3455 gtkblist->warning_column = gtk_tree_view_column_new_with_attributes("Warning", rend, "markup", WARNING_COLUMN, NULL); |
3456 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->warning_column); | |
5228 | 3457 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); |
3458 | |
3459 rend = gtk_cell_renderer_pixbuf_new(); | |
3460 gtkblist->buddy_icon_column = gtk_tree_view_column_new_with_attributes("Buddy Icon", rend, "pixbuf", BUDDY_ICON_COLUMN, NULL); | |
3461 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); | |
3462 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->buddy_icon_column); | |
3463 | |
3464 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-activated", G_CALLBACK(gtk_blist_row_activated_cb), NULL); | |
3465 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-expanded", G_CALLBACK(gtk_blist_row_expanded_cb), NULL); | |
3466 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-collapsed", G_CALLBACK(gtk_blist_row_collapsed_cb), NULL); | |
3467 g_signal_connect(G_OBJECT(gtkblist->treeview), "button-press-event", G_CALLBACK(gtk_blist_button_press_cb), NULL); | |
7620 | 3468 g_signal_connect(G_OBJECT(gtkblist->treeview), "key-press-event", G_CALLBACK(gtk_blist_key_press_cb), NULL); |
8143 | 3469 g_signal_connect(G_OBJECT(gtkblist->treeview), "popup-menu", G_CALLBACK(gaim_gtk_blist_popup_menu_cb), NULL); |
5228 | 3470 |
5419 | 3471 /* Enable CTRL+F searching */ |
3472 gtk_tree_view_set_search_column(GTK_TREE_VIEW(gtkblist->treeview), NAME_COLUMN); | |
10433 | 3473 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(gtkblist->treeview), _search_func, NULL, NULL); |
5419 | 3474 |
5228 | 3475 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), sw, TRUE, TRUE, 0); |
3476 gtk_container_add(GTK_CONTAINER(sw), gtkblist->treeview); | |
3477 gaim_gtk_blist_update_columns(); | |
3478 | |
10178
96a850ab30c8
[gaim-migrate @ 11293]
Christian Hammond <chipx86@chipx86.com>
parents:
10144
diff
changeset
|
3479 selector = gaim_gtk_status_selector_new(); |
96a850ab30c8
[gaim-migrate @ 11293]
Christian Hammond <chipx86@chipx86.com>
parents:
10144
diff
changeset
|
3480 gtk_widget_show(selector); |
96a850ab30c8
[gaim-migrate @ 11293]
Christian Hammond <chipx86@chipx86.com>
parents:
10144
diff
changeset
|
3481 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
|
3482 |
5228 | 3483 /* set the Show Offline Buddies option. must be done |
3484 * after the treeview or faceprint gets mad. -Robot101 | |
3485 */ | |
5427 | 3486 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Buddies/Show Offline Buddies"))), |
7620 | 3487 gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies")); |
5427 | 3488 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Buddies/Show Empty Groups"))), |
7620 | 3489 gaim_prefs_get_bool("/gaim/gtk/blist/show_empty_groups")); |
10074 | 3490 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Tools/Mute Sounds"))), |
3491 gaim_prefs_get_bool("/gaim/gtk/sound/mute")); | |
3492 if(!strcmp(gaim_prefs_get_string("/gaim/gtk/sound/method"), "none")) | |
3493 gtk_widget_set_sensitive(gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Mute Sounds")), FALSE); | |
5228 | 3494 |
10353 | 3495 /* Update some dynamic things */ |
3496 update_menu_bar(gtkblist); | |
3497 gaim_gtk_blist_update_plugin_actions(); | |
3498 | |
5228 | 3499 /* OK... let's show this bad boy. */ |
10282 | 3500 if (gaim_prefs_get_bool("/gaim/gtk/blist/list_visible") || docklet_count == 0) { |
3501 gaim_gtk_blist_refresh(list); | |
3502 gaim_gtk_blist_restore_position(); | |
3503 gtk_widget_show(gtkblist->window); | |
3504 } | |
5228 | 3505 |
3506 /* start the refresh timer */ | |
10351 | 3507 gtkblist->refresh_timer = g_timeout_add(30000, (GSourceFunc)gaim_gtk_blist_refresh_timer, list); |
10353 | 3508 |
10087 | 3509 handle = gaim_gtk_blist_get_handle(); |
3510 | |
7620 | 3511 /* things that affect how buddies are displayed */ |
10087 | 3512 gaim_prefs_connect_callback(handle, "/gaim/gtk/blist/show_buddy_icons", |
3513 _prefs_change_redo_list, NULL); | |
3514 gaim_prefs_connect_callback(handle, "/gaim/gtk/blist/show_empty_groups", | |
3515 _prefs_change_redo_list, NULL); | |
3516 gaim_prefs_connect_callback(handle, "/gaim/gtk/blist/show_offline_buddies", | |
3517 _prefs_change_redo_list, NULL); | |
7620 | 3518 |
3519 /* sorting */ | |
10087 | 3520 gaim_prefs_connect_callback(handle, "/gaim/gtk/blist/sort_type", |
3521 _prefs_change_sort_method, NULL); | |
7620 | 3522 |
3523 /* things that affect what columns are displayed */ | |
10087 | 3524 gaim_prefs_connect_callback(handle, "/gaim/gtk/blist/show_buddy_icons", |
3525 gaim_gtk_blist_update_columns, NULL); | |
8259
4f9f68ab8770
[gaim-migrate @ 8982]
Christian Hammond <chipx86@chipx86.com>
parents:
8254
diff
changeset
|
3526 |
10074 | 3527 /* menus */ |
10087 | 3528 gaim_prefs_connect_callback(handle, "/gaim/gtk/sound/mute", |
3529 gaim_gtk_blist_mute_pref_cb, NULL); | |
3530 gaim_prefs_connect_callback(handle, "/gaim/gtk/sound/method", | |
3531 gaim_gtk_blist_sound_method_pref_cb, NULL); | |
10074 | 3532 |
8259
4f9f68ab8770
[gaim-migrate @ 8982]
Christian Hammond <chipx86@chipx86.com>
parents:
8254
diff
changeset
|
3533 /* Setup some gaim signal handlers. */ |
8937 | 3534 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", |
3535 gtkblist, GAIM_CALLBACK(sign_on_off_cb), list); | |
3536 gaim_signal_connect(gaim_connections_get_handle(), "signed-off", | |
3537 gtkblist, GAIM_CALLBACK(sign_on_off_cb), list); | |
8815 | 3538 |
8986 | 3539 gaim_signal_connect(gaim_plugins_get_handle(), "plugin-load", |
3540 gtkblist, GAIM_CALLBACK(plugin_changed_cb), NULL); | |
3541 gaim_signal_connect(gaim_plugins_get_handle(), "plugin-unload", | |
3542 gtkblist, GAIM_CALLBACK(plugin_changed_cb), NULL); | |
3543 | |
8815 | 3544 /* emit our created signal */ |
10087 | 3545 gaim_signal_emit(handle, "gtkblist-created", list); |
5228 | 3546 } |
3547 | |
7620 | 3548 /* XXX: does this need fixing? */ |
3549 static void redo_buddy_list(GaimBuddyList *list, gboolean remove) | |
5228 | 3550 { |
7620 | 3551 GaimBlistNode *gnode, *cnode, *bnode; |
3552 | |
3553 for(gnode = list->root; gnode; gnode = gnode->next) { | |
3554 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
5234 | 3555 continue; |
7620 | 3556 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
3557 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
3558 if(remove) | |
3559 gaim_gtk_blist_hide_node(list, cnode); | |
3560 | |
3561 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
3562 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
3563 continue; | |
3564 if(remove) | |
3565 gaim_gtk_blist_hide_node(list, bnode); | |
3566 gaim_gtk_blist_update(list, bnode); | |
3567 } | |
3568 | |
3569 gaim_gtk_blist_update(list, cnode); | |
3570 } else if(GAIM_BLIST_NODE_IS_CHAT(cnode)) { | |
3571 if(remove) | |
3572 gaim_gtk_blist_hide_node(list, cnode); | |
3573 | |
3574 gaim_gtk_blist_update(list, cnode); | |
3575 } | |
5228 | 3576 } |
7620 | 3577 gaim_gtk_blist_update(list, gnode); |
5228 | 3578 } |
3579 } | |
3580 | |
7620 | 3581 void gaim_gtk_blist_refresh(GaimBuddyList *list) |
5422 | 3582 { |
3583 redo_buddy_list(list, FALSE); | |
3584 } | |
3585 | |
5297 | 3586 void |
3587 gaim_gtk_blist_update_refresh_timeout() | |
3588 { | |
7620 | 3589 GaimBuddyList *blist; |
3590 GaimGtkBuddyList *gtkblist; | |
5297 | 3591 |
3592 blist = gaim_get_blist(); | |
3593 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); | |
3594 | |
10351 | 3595 gtkblist->refresh_timer = g_timeout_add(30000,(GSourceFunc)gaim_gtk_blist_refresh_timer, blist); |
5297 | 3596 } |
3597 | |
5256 | 3598 static gboolean get_iter_from_node(GaimBlistNode *node, GtkTreeIter *iter) { |
3599 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; | |
3600 GtkTreePath *path; | |
5228 | 3601 |
7620 | 3602 /* XXX: why do we assume we have a buddy here? */ |
5263 | 3603 if (!gtknode) { |
7620 | 3604 #if 0 |
10006 | 3605 gaim_debug_error("gtkblist", "buddy %s has no ui_data\n", ((GaimBuddy *)node)->name); |
7620 | 3606 #endif |
5263 | 3607 return FALSE; |
3608 } | |
3609 | |
3610 if (!gtkblist) { | |
10006 | 3611 gaim_debug_error("gtkblist", "get_iter_from_node was called, but we don't seem to have a blist\n"); |
5263 | 3612 return FALSE; |
3613 } | |
3614 | |
3615 if (!gtknode->row) | |
5228 | 3616 return FALSE; |
3617 | |
5256 | 3618 if ((path = gtk_tree_row_reference_get_path(gtknode->row)) == NULL) |
5228 | 3619 return FALSE; |
5256 | 3620 if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), iter, path)) { |
3621 gtk_tree_path_free(path); | |
3622 return FALSE; | |
3623 } | |
3624 gtk_tree_path_free(path); | |
3625 return TRUE; | |
5228 | 3626 } |
3627 | |
7620 | 3628 static void gaim_gtk_blist_remove(GaimBuddyList *list, GaimBlistNode *node) |
5228 | 3629 { |
10222 | 3630 gaim_request_close_with_handle(node); |
3631 | |
5260 | 3632 gaim_gtk_blist_hide_node(list, node); |
5228 | 3633 |
7620 | 3634 if(node->parent) |
3635 gaim_gtk_blist_update(list, node->parent); | |
3636 | |
5263 | 3637 /* There's something I don't understand here */ |
3638 /* g_free(node->ui_data); | |
3639 node->ui_data = NULL; */ | |
5228 | 3640 } |
3641 | |
3642 static gboolean do_selection_changed(GaimBlistNode *new_selection) | |
3643 { | |
5254 | 3644 GaimBlistNode *old_selection = NULL; |
5228 | 3645 |
5254 | 3646 /* test for gtkblist because crazy timeout means we can be called after the blist is gone */ |
3647 if (gtkblist && new_selection != gtkblist->selected_node) { | |
3648 old_selection = gtkblist->selected_node; | |
5228 | 3649 gtkblist->selected_node = new_selection; |
3650 if(new_selection) | |
3651 gaim_gtk_blist_update(NULL, new_selection); | |
3652 if(old_selection) | |
3653 gaim_gtk_blist_update(NULL, old_selection); | |
3654 } | |
3655 | |
3656 return FALSE; | |
3657 } | |
3658 | |
3659 static void gaim_gtk_blist_selection_changed(GtkTreeSelection *selection, gpointer data) | |
3660 { | |
3661 GaimBlistNode *new_selection = NULL; | |
3662 GtkTreeIter iter; | |
3663 | |
3664 if(gtk_tree_selection_get_selected(selection, NULL, &iter)){ | |
3665 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, | |
3666 NODE_COLUMN, &new_selection, -1); | |
3667 } | |
5254 | 3668 |
5228 | 3669 /* we set this up as a timeout, otherwise the blist flickers */ |
3670 g_timeout_add(0, (GSourceFunc)do_selection_changed, new_selection); | |
3671 } | |
3672 | |
8252 | 3673 static gboolean insert_node(GaimBuddyList *list, GaimBlistNode *node, GtkTreeIter *iter) |
7620 | 3674 { |
3675 GtkTreeIter parent_iter, cur, *curptr = NULL; | |
3676 struct _gaim_gtk_blist_node *gtknode = node->ui_data; | |
5256 | 3677 GtkTreePath *newpath; |
7620 | 3678 |
3679 if(!gtknode || !iter) | |
8252 | 3680 return FALSE; |
7620 | 3681 |
3682 if(node->parent && !get_iter_from_node(node->parent, &parent_iter)) | |
8252 | 3683 return FALSE; |
7620 | 3684 |
3685 if(get_iter_from_node(node, &cur)) | |
3686 curptr = &cur; | |
3687 | |
3688 if(GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_CHAT(node)) { | |
3689 *iter = current_sort_method->func(node, list, parent_iter, curptr); | |
3690 } else { | |
3691 *iter = sort_method_none(node, list, parent_iter, curptr); | |
5228 | 3692 } |
3693 | |
7620 | 3694 gtk_tree_row_reference_free(gtknode->row); |
3695 newpath = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), | |
3696 iter); | |
3697 gtknode->row = | |
3698 gtk_tree_row_reference_new(GTK_TREE_MODEL(gtkblist->treemodel), | |
3699 newpath); | |
5256 | 3700 gtk_tree_path_free(newpath); |
3701 | |
5228 | 3702 gtk_tree_store_set(gtkblist->treemodel, iter, |
3703 NODE_COLUMN, node, | |
3704 -1); | |
7620 | 3705 |
3706 if(node->parent) { | |
3707 GtkTreePath *expand = NULL; | |
3708 struct _gaim_gtk_blist_node *gtkparentnode = node->parent->ui_data; | |
3709 | |
3710 if(GAIM_BLIST_NODE_IS_GROUP(node->parent)) { | |
7693 | 3711 if(!gaim_blist_node_get_bool(node->parent, "collapsed")) |
7620 | 3712 expand = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &parent_iter); |
3713 } else if(GAIM_BLIST_NODE_IS_CONTACT(node->parent) && | |
3714 gtkparentnode->contact_expanded) { | |
3715 expand = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &parent_iter); | |
3716 } | |
3717 if(expand) { | |
7693 | 3718 gtk_tree_view_expand_row(GTK_TREE_VIEW(gtkblist->treeview), expand, FALSE); |
7620 | 3719 gtk_tree_path_free(expand); |
3720 } | |
3721 } | |
3722 | |
8252 | 3723 return TRUE; |
5228 | 3724 } |
3725 | |
7620 | 3726 static void gaim_gtk_blist_update_group(GaimBuddyList *list, GaimBlistNode *node) |
3727 { | |
3728 GaimGroup *group; | |
8203 | 3729 int count; |
7620 | 3730 |
3731 g_return_if_fail(GAIM_BLIST_NODE_IS_GROUP(node)); | |
3732 | |
3733 group = (GaimGroup*)node; | |
3734 | |
8203 | 3735 if(gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies")) |
3736 count = gaim_blist_get_group_size(group, FALSE); | |
3737 else | |
3738 count = gaim_blist_get_group_online_count(group); | |
3739 if(gaim_prefs_get_bool("/gaim/gtk/blist/show_empty_groups") || count > 0) { | |
7620 | 3740 char *mark, *esc; |
3741 GtkTreeIter iter; | |
3742 | |
8252 | 3743 if(!insert_node(list, node, &iter)) |
3744 return; | |
7620 | 3745 |
3746 esc = g_markup_escape_text(group->name, -1); | |
8945 | 3747 mark = g_strdup_printf("<span weight='bold'>%s</span> (%d/%d)", |
3748 esc, gaim_blist_get_group_online_count(group), | |
3749 gaim_blist_get_group_size(group, FALSE)); | |
7620 | 3750 g_free(esc); |
3751 | |
3752 gtk_tree_store_set(gtkblist->treemodel, &iter, | |
3753 STATUS_ICON_COLUMN, NULL, | |
3754 STATUS_ICON_VISIBLE_COLUMN, FALSE, | |
3755 NAME_COLUMN, mark, | |
3756 NODE_COLUMN, node, | |
3757 -1); | |
3758 g_free(mark); | |
3759 } else { | |
3760 gaim_gtk_blist_hide_node(list, node); | |
3761 } | |
3762 } | |
3763 | |
3764 static void buddy_node(GaimBuddy *buddy, GtkTreeIter *iter, GaimBlistNode *node) | |
5228 | 3765 { |
9944 | 3766 GaimPresence *presence; |
7620 | 3767 GdkPixbuf *status, *avatar; |
3768 char *mark; | |
3769 char *warning = NULL, *idle = NULL; | |
9944 | 3770 unsigned int warning_level; |
7620 | 3771 gboolean selected = (gtkblist->selected_node == node); |
3772 | |
9944 | 3773 presence = gaim_buddy_get_presence(buddy); |
3774 | |
7620 | 3775 status = gaim_gtk_blist_get_status_icon((GaimBlistNode*)buddy, |
3776 (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons") | |
3777 ? GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL)); | |
3778 | |
10482 | 3779 avatar = gaim_gtk_blist_get_buddy_icon((GaimBlistNode *)buddy, TRUE, TRUE); |
7620 | 3780 mark = gaim_gtk_blist_get_name_markup(buddy, selected); |
3781 | |
9944 | 3782 if (gaim_presence_is_idle(presence)) |
3783 { | |
3784 time_t idle_secs = gaim_presence_get_idle_time(presence); | |
3785 | |
3786 if (idle_secs > 0) | |
3787 { | |
3788 time_t t; | |
3789 int ihrs, imin; | |
3790 time(&t); | |
3791 ihrs = (t - idle_secs) / 3600; | |
3792 imin = ((t - idle_secs) / 60) % 60; | |
3793 | |
3794 if (ihrs > 0) | |
3795 idle = g_strdup_printf("(%d:%02d)", ihrs, imin); | |
3796 else | |
3797 idle = g_strdup_printf("(%d)", imin); | |
3798 } | |
7620 | 3799 } |
3800 | |
9944 | 3801 warning_level = gaim_presence_get_warning_level(presence); |
3802 | |
3803 if (warning_level > 0) | |
3804 warning = g_strdup_printf("%d%%", warning_level); | |
7620 | 3805 |
10118 | 3806 if (gaim_presence_is_idle(presence)) |
9944 | 3807 { |
3808 if (warning && !selected) { | |
10118 | 3809 char *w2 = g_strdup_printf("<span color='%s'>%s</span>", |
3810 dim_grey(), warning); | |
7620 | 3811 g_free(warning); |
3812 warning = w2; | |
3813 } | |
3814 | |
9944 | 3815 if (idle && !selected) { |
10118 | 3816 char *i2 = g_strdup_printf("<span color='%s'>%s</span>", |
3817 dim_grey(), idle); | |
7620 | 3818 g_free(idle); |
3819 idle = i2; | |
5228 | 3820 } |
7620 | 3821 } |
3822 | |
3823 gtk_tree_store_set(gtkblist->treemodel, iter, | |
3824 STATUS_ICON_COLUMN, status, | |
3825 STATUS_ICON_VISIBLE_COLUMN, TRUE, | |
3826 NAME_COLUMN, mark, | |
3827 WARNING_COLUMN, warning, | |
3828 IDLE_COLUMN, idle, | |
3829 BUDDY_ICON_COLUMN, avatar, | |
3830 -1); | |
3831 | |
3832 g_free(mark); | |
3833 if(idle) | |
3834 g_free(idle); | |
3835 if(warning) | |
3836 g_free(warning); | |
3837 if(status) | |
3838 g_object_unref(status); | |
3839 if(avatar) | |
3840 g_object_unref(avatar); | |
3841 } | |
3842 | |
3843 static void gaim_gtk_blist_update_contact(GaimBuddyList *list, GaimBlistNode *node) | |
3844 { | |
3845 GaimContact *contact; | |
3846 GaimBuddy *buddy; | |
3847 struct _gaim_gtk_blist_node *gtknode; | |
3848 | |
3849 g_return_if_fail(GAIM_BLIST_NODE_IS_CONTACT(node)); | |
3850 | |
3851 /* First things first, update the group */ | |
3852 gaim_gtk_blist_update_group(list, node->parent); | |
3853 | |
3854 gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; | |
3855 contact = (GaimContact*)node; | |
3856 buddy = gaim_contact_get_priority_buddy(contact); | |
3857 | |
10006 | 3858 if (buddy && (gaim_presence_is_online(buddy->presence) || |
3859 (gaim_account_is_connected(buddy->account) && | |
3860 gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies")) || | |
3861 gaim_blist_node_get_bool(node, "show_offline"))) | |
3862 { | |
7620 | 3863 GtkTreeIter iter; |
3864 | |
8252 | 3865 if(!insert_node(list, node, &iter)) |
3866 return; | |
7620 | 3867 |
3868 if(gtknode->contact_expanded) { | |
3869 GdkPixbuf *status; | |
5228 | 3870 char *mark; |
3871 | |
7620 | 3872 status = gaim_gtk_blist_get_status_icon(node, |
3873 (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons") ? | |
3874 GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL)); | |
3875 | |
3876 mark = g_markup_escape_text(gaim_contact_get_alias(contact), -1); | |
3877 | |
5228 | 3878 gtk_tree_store_set(gtkblist->treemodel, &iter, |
7620 | 3879 STATUS_ICON_COLUMN, status, |
3880 STATUS_ICON_VISIBLE_COLUMN, TRUE, | |
5228 | 3881 NAME_COLUMN, mark, |
7620 | 3882 WARNING_COLUMN, NULL, |
3883 IDLE_COLUMN, NULL, | |
3884 BUDDY_ICON_COLUMN, NULL, | |
5228 | 3885 -1); |
3886 g_free(mark); | |
7620 | 3887 if(status) |
3888 g_object_unref(status); | |
3889 } else { | |
3890 buddy_node(buddy, &iter, node); | |
5228 | 3891 } |
7620 | 3892 } else { |
3893 gaim_gtk_blist_hide_node(list, node); | |
5228 | 3894 } |
7620 | 3895 } |
3896 | |
3897 static void gaim_gtk_blist_update_buddy(GaimBuddyList *list, GaimBlistNode *node) | |
3898 { | |
3899 GaimContact *contact; | |
3900 GaimBuddy *buddy; | |
3901 struct _gaim_gtk_blist_node *gtkparentnode; | |
3902 | |
3903 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
3904 | |
3905 buddy = (GaimBuddy*)node; | |
3906 contact = (GaimContact*)node->parent; | |
3907 gtkparentnode = (struct _gaim_gtk_blist_node *)node->parent->ui_data; | |
3908 | |
3909 /* First things first, update the contact */ | |
3910 gaim_gtk_blist_update_contact(list, node->parent); | |
3911 | |
10006 | 3912 if (gtkparentnode->contact_expanded && |
3913 (gaim_presence_is_online(buddy->presence) || | |
7620 | 3914 (gaim_account_is_connected(buddy->account) && |
10006 | 3915 gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies")) || |
3916 gaim_blist_node_get_bool(node->parent, "show_offline"))) | |
3917 { | |
7620 | 3918 GtkTreeIter iter; |
3919 | |
10006 | 3920 if (!insert_node(list, node, &iter)) |
8252 | 3921 return; |
3922 | |
7620 | 3923 buddy_node(buddy, &iter, node); |
3924 | |
3925 } else { | |
3926 gaim_gtk_blist_hide_node(list, node); | |
3927 } | |
3928 | |
3929 } | |
3930 | |
3931 static void gaim_gtk_blist_update_chat(GaimBuddyList *list, GaimBlistNode *node) | |
3932 { | |
3933 GaimChat *chat; | |
3934 | |
3935 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node)); | |
3936 | |
3937 /* First things first, update the group */ | |
3938 gaim_gtk_blist_update_group(list, node->parent); | |
3939 | |
3940 chat = (GaimChat*)node; | |
3941 | |
3942 if(gaim_account_is_connected(chat->account)) { | |
3943 GtkTreeIter iter; | |
5234 | 3944 GdkPixbuf *status; |
7620 | 3945 char *mark; |
3946 | |
8252 | 3947 if(!insert_node(list, node, &iter)) |
3948 return; | |
5234 | 3949 |
3950 status = gaim_gtk_blist_get_status_icon(node, | |
7620 | 3951 (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons") ? |
3952 GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL)); | |
3953 | |
3954 mark = g_markup_escape_text(gaim_chat_get_name(chat), -1); | |
5234 | 3955 |
3956 gtk_tree_store_set(gtkblist->treemodel, &iter, | |
7620 | 3957 STATUS_ICON_COLUMN, status, |
3958 STATUS_ICON_VISIBLE_COLUMN, TRUE, | |
3959 NAME_COLUMN, mark, | |
3960 -1); | |
5228 | 3961 |
3962 g_free(mark); | |
7620 | 3963 if(status) |
5228 | 3964 g_object_unref(status); |
7620 | 3965 } else { |
5260 | 3966 gaim_gtk_blist_hide_node(list, node); |
5228 | 3967 } |
7620 | 3968 } |
3969 | |
3970 static void gaim_gtk_blist_update(GaimBuddyList *list, GaimBlistNode *node) | |
3971 { | |
3972 if(!gtkblist) | |
3973 return; | |
3974 | |
3975 switch(node->type) { | |
3976 case GAIM_BLIST_GROUP_NODE: | |
3977 gaim_gtk_blist_update_group(list, node); | |
3978 break; | |
3979 case GAIM_BLIST_CONTACT_NODE: | |
3980 gaim_gtk_blist_update_contact(list, node); | |
3981 break; | |
3982 case GAIM_BLIST_BUDDY_NODE: | |
3983 gaim_gtk_blist_update_buddy(list, node); | |
3984 break; | |
3985 case GAIM_BLIST_CHAT_NODE: | |
3986 gaim_gtk_blist_update_chat(list, node); | |
3987 break; | |
3988 case GAIM_BLIST_OTHER_NODE: | |
3989 return; | |
3990 } | |
5234 | 3991 |
5228 | 3992 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(gtkblist->treeview)); |
3993 } | |
3994 | |
7620 | 3995 |
3996 static void gaim_gtk_blist_destroy(GaimBuddyList *list) | |
5228 | 3997 { |
3998 if (!gtkblist) | |
3999 return; | |
4000 | |
8937 | 4001 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-on", |
4002 gtkblist, GAIM_CALLBACK(sign_on_off_cb)); | |
4003 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-off", | |
4004 gtkblist, GAIM_CALLBACK(sign_on_off_cb)); | |
8259
4f9f68ab8770
[gaim-migrate @ 8982]
Christian Hammond <chipx86@chipx86.com>
parents:
8254
diff
changeset
|
4005 |
5228 | 4006 gtk_widget_destroy(gtkblist->window); |
7620 | 4007 |
8254 | 4008 gaim_gtk_blist_tooltip_destroy(); |
7620 | 4009 |
5228 | 4010 if (gtkblist->refresh_timer) |
4011 g_source_remove(gtkblist->refresh_timer); | |
4012 if (gtkblist->timeout) | |
4013 g_source_remove(gtkblist->timeout); | |
10354 | 4014 if (gtkblist->drag_timeout) |
4015 g_source_remove(gtkblist->drag_timeout); | |
5228 | 4016 |
4017 gtkblist->refresh_timer = 0; | |
4018 gtkblist->timeout = 0; | |
10354 | 4019 gtkblist->drag_timeout = 0; |
5228 | 4020 gtkblist->window = gtkblist->vbox = gtkblist->treeview = NULL; |
4021 gtkblist->treemodel = NULL; | |
4022 gtkblist->idle_column = NULL; | |
4023 gtkblist->warning_column = gtkblist->buddy_icon_column = NULL; | |
5427 | 4024 g_object_unref(G_OBJECT(gtkblist->ift)); |
5228 | 4025 protomenu = NULL; |
8986 | 4026 pluginmenu = NULL; |
5228 | 4027 gtkblist = NULL; |
7620 | 4028 |
10087 | 4029 gaim_prefs_disconnect_by_handle(gaim_gtk_blist_get_handle()); |
5228 | 4030 } |
4031 | |
7620 | 4032 static void gaim_gtk_blist_set_visible(GaimBuddyList *list, gboolean show) |
5228 | 4033 { |
4034 if (!(gtkblist && gtkblist->window)) | |
4035 return; | |
10325 | 4036 |
10282 | 4037 gaim_prefs_set_bool("/gaim/gtk/blist/list_visible", show); |
10325 | 4038 |
5228 | 4039 if (show) { |
4040 gaim_gtk_blist_restore_position(); | |
4041 gtk_window_present(GTK_WINDOW(gtkblist->window)); | |
4042 } else { | |
7620 | 4043 if (!gaim_connections_get_all() || docklet_count) { |
5228 | 4044 #ifdef _WIN32 |
4045 wgaim_systray_minimize(gtkblist->window); | |
4046 #endif | |
4047 gtk_widget_hide(gtkblist->window); | |
4048 } else { | |
4049 gtk_window_iconify(GTK_WINDOW(gtkblist->window)); | |
4050 } | |
4051 } | |
4052 } | |
4053 | |
7620 | 4054 static GList * |
4055 groups_tree(void) | |
4056 { | |
4057 GList *tmp = NULL; | |
4058 char *tmp2; | |
4059 GaimGroup *g; | |
4060 GaimBlistNode *gnode; | |
4061 | |
4062 if (gaim_get_blist()->root == NULL) | |
4063 { | |
4064 tmp2 = g_strdup(_("Buddies")); | |
4065 tmp = g_list_append(tmp, tmp2); | |
4066 } | |
4067 else | |
4068 { | |
4069 for (gnode = gaim_get_blist()->root; | |
4070 gnode != NULL; | |
4071 gnode = gnode->next) | |
4072 { | |
4073 if (GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
4074 { | |
4075 g = (GaimGroup *)gnode; | |
4076 tmp2 = g->name; | |
4077 tmp = g_list_append(tmp, tmp2); | |
4078 } | |
4079 } | |
4080 } | |
4081 | |
4082 return tmp; | |
4083 } | |
4084 | |
4085 static void | |
4086 add_buddy_select_account_cb(GObject *w, GaimAccount *account, | |
4087 GaimGtkAddBuddyData *data) | |
4088 { | |
4089 /* Save our account */ | |
4090 data->account = account; | |
4091 } | |
4092 | |
4093 static void | |
4094 destroy_add_buddy_dialog_cb(GtkWidget *win, GaimGtkAddBuddyData *data) | |
4095 { | |
4096 g_free(data); | |
4097 } | |
4098 | |
4099 static void | |
4100 add_buddy_cb(GtkWidget *w, int resp, GaimGtkAddBuddyData *data) | |
4101 { | |
4102 const char *grp, *who, *whoalias; | |
4103 GaimConversation *c; | |
4104 GaimBuddy *b; | |
4105 GaimGroup *g; | |
4106 | |
4107 if (resp == GTK_RESPONSE_OK) | |
4108 { | |
4109 who = gtk_entry_get_text(GTK_ENTRY(data->entry)); | |
4110 grp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(data->combo)->entry)); | |
4111 whoalias = gtk_entry_get_text(GTK_ENTRY(data->entry_for_alias)); | |
9658 | 4112 if (*whoalias == '\0') |
4113 whoalias = NULL; | |
7620 | 4114 |
4115 if ((g = gaim_find_group(grp)) == NULL) | |
4116 { | |
4117 g = gaim_group_new(grp); | |
4118 gaim_blist_add_group(g, NULL); | |
4119 } | |
4120 | |
4121 b = gaim_buddy_new(data->account, who, whoalias); | |
4122 gaim_blist_add_buddy(b, NULL, g, NULL); | |
9285 | 4123 serv_add_buddy(gaim_account_get_connection(data->account), b); |
7620 | 4124 |
7887 | 4125 /* |
9285 | 4126 * XXX |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
4127 * 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
|
4128 * 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
|
4129 * gaim_blist_add_buddy() function. Maybe serv_add_buddy() should be |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
4130 * renamed to gaim_blist_add_new_buddy() or something, and have it call |
7887 | 4131 * gaim_blist_add_buddy() after it creates it. --Mark |
9285 | 4132 * |
4133 * No that's not good. blist.c should only deal with adding nodes to the | |
4134 * local list. We need a new, non-gtk file that calls both serv_add_buddy | |
4135 * and gaim_blist_add_buddy(). Or something. --Mark | |
7887 | 4136 */ |
4137 | |
10246 | 4138 c = gaim_find_conversation_with_account(GAIM_CONV_IM, who, data->account); |
7620 | 4139 if (c != NULL) { |
4140 gaim_buddy_icon_update(gaim_conv_im_get_icon(GAIM_CONV_IM(c))); | |
4141 gaim_conversation_update(c, GAIM_CONV_UPDATE_ADD); | |
4142 } | |
4143 } | |
4144 | |
4145 gtk_widget_destroy(data->window); | |
4146 } | |
4147 | |
4148 static void | |
4149 gaim_gtk_blist_request_add_buddy(GaimAccount *account, const char *username, | |
4150 const char *group, const char *alias) | |
4151 { | |
4152 GtkWidget *table; | |
4153 GtkWidget *label; | |
4154 GtkWidget *hbox; | |
4155 GtkWidget *vbox; | |
4156 GtkWidget *img; | |
4157 GaimGtkBuddyList *gtkblist; | |
4158 GaimGtkAddBuddyData *data = g_new0(GaimGtkAddBuddyData, 1); | |
4159 | |
4160 data->account = | |
4161 (account != NULL | |
4162 ? account | |
4163 : gaim_connection_get_account(gaim_connections_get_all()->data)); | |
4164 | |
4165 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, | |
4166 GTK_ICON_SIZE_DIALOG); | |
4167 | |
4168 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); | |
4169 | |
4170 data->window = gtk_dialog_new_with_buttons(_("Add Buddy"), | |
8975 | 4171 NULL, GTK_DIALOG_NO_SEPARATOR, |
7620 | 4172 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
4173 GTK_STOCK_ADD, GTK_RESPONSE_OK, | |
4174 NULL); | |
4175 | |
4176 gtk_dialog_set_default_response(GTK_DIALOG(data->window), GTK_RESPONSE_OK); | |
4177 gtk_container_set_border_width(GTK_CONTAINER(data->window), 6); | |
4178 gtk_window_set_resizable(GTK_WINDOW(data->window), FALSE); | |
4179 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(data->window)->vbox), 12); | |
4180 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), 6); | |
4181 gtk_window_set_role(GTK_WINDOW(data->window), "add_buddy"); | |
8975 | 4182 gtk_window_set_type_hint(GTK_WINDOW(data->window), |
9811 | 4183 GDK_WINDOW_TYPE_HINT_DIALOG); |
7620 | 4184 |
4185 hbox = gtk_hbox_new(FALSE, 12); | |
4186 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), hbox); | |
4187 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
4188 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
4189 | |
4190 vbox = gtk_vbox_new(FALSE, 0); | |
4191 gtk_container_add(GTK_CONTAINER(hbox), vbox); | |
4192 | |
4193 label = gtk_label_new( | |
4194 _("Please enter the screen name of the person you would like " | |
4195 "to add to your buddy list. You may optionally enter an alias, " | |
4196 "or nickname, for the buddy. The alias will be displayed in " | |
4197 "place of the screen name whenever possible.\n")); | |
4198 | |
4199 gtk_widget_set_size_request(GTK_WIDGET(label), 400, -1); | |
4200 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
4201 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
4202 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
4203 | |
4204 hbox = gtk_hbox_new(FALSE, 6); | |
4205 gtk_container_add(GTK_CONTAINER(vbox), hbox); | |
4206 | |
4207 g_signal_connect(G_OBJECT(data->window), "destroy", | |
4208 G_CALLBACK(destroy_add_buddy_dialog_cb), data); | |
4209 | |
4210 table = gtk_table_new(4, 2, FALSE); | |
4211 gtk_table_set_row_spacings(GTK_TABLE(table), 5); | |
4212 gtk_table_set_col_spacings(GTK_TABLE(table), 5); | |
4213 gtk_container_set_border_width(GTK_CONTAINER(table), 0); | |
4214 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); | |
4215 | |
4216 label = gtk_label_new(_("Screen Name:")); | |
4217 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
4218 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); | |
4219 | |
4220 data->entry = gtk_entry_new(); | |
4221 gtk_table_attach_defaults(GTK_TABLE(table), data->entry, 1, 2, 0, 1); | |
4222 gtk_widget_grab_focus(data->entry); | |
4223 | |
4224 if (username != NULL) | |
4225 gtk_entry_set_text(GTK_ENTRY(data->entry), username); | |
4226 | |
4227 gtk_entry_set_activates_default (GTK_ENTRY(data->entry), TRUE); | |
8137 | 4228 gaim_set_accessible_label (data->entry, label); |
7620 | 4229 |
4230 label = gtk_label_new(_("Alias:")); | |
4231 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
4232 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2); | |
4233 | |
4234 data->entry_for_alias = gtk_entry_new(); | |
4235 gtk_table_attach_defaults(GTK_TABLE(table), | |
4236 data->entry_for_alias, 1, 2, 1, 2); | |
4237 | |
4238 if (alias != NULL) | |
4239 gtk_entry_set_text(GTK_ENTRY(data->entry_for_alias), alias); | |
4240 | |
4241 gtk_entry_set_activates_default (GTK_ENTRY(data->entry_for_alias), TRUE); | |
8137 | 4242 gaim_set_accessible_label (data->entry_for_alias, label); |
7620 | 4243 |
4244 label = gtk_label_new(_("Group:")); | |
4245 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
4246 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3); | |
4247 | |
4248 data->combo = gtk_combo_new(); | |
4249 gtk_combo_set_popdown_strings(GTK_COMBO(data->combo), groups_tree()); | |
4250 gtk_table_attach_defaults(GTK_TABLE(table), data->combo, 1, 2, 2, 3); | |
8137 | 4251 gaim_set_accessible_label (data->combo, label); |
7620 | 4252 |
4253 /* Set up stuff for the account box */ | |
4254 label = gtk_label_new(_("Account:")); | |
4255 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
4256 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4); | |
4257 | |
4258 data->account_box = gaim_gtk_account_option_menu_new(account, FALSE, | |
4259 G_CALLBACK(add_buddy_select_account_cb), NULL, data); | |
4260 | |
4261 gtk_table_attach_defaults(GTK_TABLE(table), data->account_box, 1, 2, 3, 4); | |
8137 | 4262 gaim_set_accessible_label (data->account_box, label); |
7620 | 4263 |
4264 /* End of account box */ | |
4265 | |
4266 g_signal_connect(G_OBJECT(data->window), "response", | |
4267 G_CALLBACK(add_buddy_cb), data); | |
4268 | |
4269 gtk_widget_show_all(data->window); | |
4270 | |
4271 if (group != NULL) | |
4272 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(data->combo)->entry), group); | |
4273 } | |
4274 | |
4275 static void | |
4276 add_chat_cb(GtkWidget *w, GaimGtkAddChatData *data) | |
4277 { | |
4278 GHashTable *components; | |
4279 GList *tmp; | |
4280 GaimChat *chat; | |
4281 GaimGroup *group; | |
4282 const char *group_name; | |
9918 | 4283 char *chat_name = NULL; |
4284 GaimConversation *conv = NULL; | |
10475 | 4285 const char *value; |
7620 | 4286 |
4287 components = g_hash_table_new_full(g_str_hash, g_str_equal, | |
4288 g_free, g_free); | |
4289 | |
4290 for (tmp = data->entries; tmp; tmp = tmp->next) | |
4291 { | |
4292 if (g_object_get_data(tmp->data, "is_spin")) | |
4293 { | |
4294 g_hash_table_replace(components, | |
4295 g_strdup(g_object_get_data(tmp->data, "identifier")), | |
4296 g_strdup_printf("%d", | |
4297 gtk_spin_button_get_value_as_int(tmp->data))); | |
4298 } | |
4299 else | |
4300 { | |
10475 | 4301 value = gtk_entry_get_text(tmp->data); |
4302 if (*value != '\0') | |
4303 g_hash_table_replace(components, | |
4304 g_strdup(g_object_get_data(tmp->data, "identifier")), | |
4305 g_strdup(value)); | |
7620 | 4306 } |
4307 } | |
4308 | |
4309 chat = gaim_chat_new(data->account, | |
4310 gtk_entry_get_text(GTK_ENTRY(data->alias_entry)), | |
4311 components); | |
4312 | |
4313 group_name = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(data->group_combo)->entry)); | |
4314 | |
4315 if ((group = gaim_find_group(group_name)) == NULL) | |
4316 { | |
4317 group = gaim_group_new(group_name); | |
4318 gaim_blist_add_group(group, NULL); | |
4319 } | |
4320 | |
4321 if (chat != NULL) | |
4322 { | |
4323 gaim_blist_add_chat(chat, group, NULL); | |
9918 | 4324 |
4325 if (GAIM_PLUGIN_PROTOCOL_INFO(data->account->gc->prpl)->get_chat_name != NULL) | |
4326 chat_name = GAIM_PLUGIN_PROTOCOL_INFO( | |
4327 data->account->gc->prpl)->get_chat_name(chat->components); | |
10246 | 4328 |
9918 | 4329 if (chat_name != NULL) { |
10246 | 4330 conv = gaim_find_conversation_with_account(GAIM_CONV_CHAT, |
4331 chat_name, | |
4332 data->account); | |
9918 | 4333 g_free(chat_name); |
4334 } | |
4335 | |
4336 if (conv != NULL) | |
4337 gaim_conversation_update(conv, GAIM_CONV_UPDATE_ADD); | |
7620 | 4338 } |
4339 | |
4340 gtk_widget_destroy(data->window); | |
9812 | 4341 g_free(data->default_chat_name); |
7620 | 4342 g_list_free(data->entries); |
4343 g_free(data); | |
4344 } | |
4345 | |
4346 static void | |
4347 add_chat_resp_cb(GtkWidget *w, int resp, GaimGtkAddChatData *data) | |
4348 { | |
4349 if (resp == GTK_RESPONSE_OK) | |
4350 { | |
4351 add_chat_cb(NULL, data); | |
4352 } | |
4353 else | |
4354 { | |
4355 gtk_widget_destroy(data->window); | |
9812 | 4356 g_free(data->default_chat_name); |
7620 | 4357 g_list_free(data->entries); |
4358 g_free(data); | |
4359 } | |
4360 } | |
4361 | |
10475 | 4362 /* |
4363 * Check the values of all the text entry boxes. If any required input | |
4364 * strings are empty then don't allow the user to click on "OK." | |
4365 */ | |
4366 static void | |
4367 addchat_set_sensitive_if_input_cb(GtkWidget *entry, gpointer user_data) | |
4368 { | |
4369 GaimGtkAddChatData *data; | |
4370 GList *tmp; | |
4371 const char *text; | |
4372 gboolean required; | |
4373 gboolean sensitive = TRUE; | |
4374 | |
4375 data = user_data; | |
4376 | |
4377 for (tmp = data->entries; tmp != NULL; tmp = tmp->next) | |
4378 { | |
4379 if (!g_object_get_data(tmp->data, "is_spin")) | |
4380 { | |
4381 required = GPOINTER_TO_INT(g_object_get_data(tmp->data, "required")); | |
4382 text = gtk_entry_get_text(tmp->data); | |
4383 if (required && (*text == '\0')) | |
4384 sensitive = FALSE; | |
4385 } | |
4386 } | |
4387 | |
4388 gtk_dialog_set_response_sensitive(GTK_DIALOG(data->window), GTK_RESPONSE_OK, sensitive); | |
4389 } | |
4390 | |
7620 | 4391 static void |
4392 rebuild_addchat_entries(GaimGtkAddChatData *data) | |
4393 { | |
4394 GaimConnection *gc; | |
9959 | 4395 GList *list = NULL, *tmp = NULL; |
9754 | 4396 GHashTable *defaults = NULL; |
7620 | 4397 struct proto_chat_entry *pce; |
4398 gboolean focus = TRUE; | |
4399 | |
10127 | 4400 g_return_if_fail(data->account != NULL); |
4401 | |
7620 | 4402 gc = gaim_account_get_connection(data->account); |
4403 | |
4404 while (GTK_BOX(data->entries_box)->children) | |
4405 { | |
4406 gtk_container_remove(GTK_CONTAINER(data->entries_box), | |
10475 | 4407 ((GtkBoxChild *)GTK_BOX(data->entries_box)->children->data)->widget); |
7620 | 4408 } |
4409 | |
4410 if (data->entries != NULL) | |
4411 g_list_free(data->entries); | |
4412 | |
4413 data->entries = NULL; | |
4414 | |
9959 | 4415 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info != NULL) |
4416 list = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info(gc); | |
7620 | 4417 |
9754 | 4418 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults != NULL) |
10475 | 4419 defaults = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, data->default_chat_name); |
9754 | 4420 |
7620 | 4421 for (tmp = list; tmp; tmp = tmp->next) |
4422 { | |
4423 GtkWidget *label; | |
4424 GtkWidget *rowbox; | |
10475 | 4425 GtkWidget *input; |
7620 | 4426 |
4427 pce = tmp->data; | |
4428 | |
4429 rowbox = gtk_hbox_new(FALSE, 5); | |
4430 gtk_box_pack_start(GTK_BOX(data->entries_box), rowbox, FALSE, FALSE, 0); | |
4431 | |
7889 | 4432 label = gtk_label_new_with_mnemonic(pce->label); |
7620 | 4433 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); |
4434 gtk_size_group_add_widget(data->sg, label); | |
4435 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); | |
4436 | |
4437 if (pce->is_int) | |
4438 { | |
4439 GtkObject *adjust; | |
4440 adjust = gtk_adjustment_new(pce->min, pce->min, pce->max, | |
4441 1, 10, 10); | |
10475 | 4442 input = gtk_spin_button_new(GTK_ADJUSTMENT(adjust), 1, 0); |
4443 gtk_widget_set_size_request(input, 50, -1); | |
4444 gtk_box_pack_end(GTK_BOX(rowbox), input, FALSE, FALSE, 0); | |
7620 | 4445 } |
4446 else | |
4447 { | |
9754 | 4448 char *value; |
10475 | 4449 input = gtk_entry_new(); |
4450 gtk_entry_set_activates_default(GTK_ENTRY(input), TRUE); | |
9754 | 4451 value = g_hash_table_lookup(defaults, pce->identifier); |
4452 if (value != NULL) | |
10475 | 4453 gtk_entry_set_text(GTK_ENTRY(input), value); |
7620 | 4454 if (pce->secret) |
10475 | 4455 gtk_entry_set_visibility(GTK_ENTRY(input), FALSE); |
4456 gtk_box_pack_end(GTK_BOX(rowbox), input, TRUE, TRUE, 0); | |
4457 g_signal_connect(G_OBJECT(input), "changed", | |
4458 G_CALLBACK(addchat_set_sensitive_if_input_cb), data); | |
7620 | 4459 } |
4460 | |
10475 | 4461 /* Do the following for any type of input widget */ |
4462 if (focus) | |
4463 { | |
4464 gtk_widget_grab_focus(input); | |
4465 focus = FALSE; | |
4466 } | |
4467 gtk_label_set_mnemonic_widget(GTK_LABEL(label), input); | |
4468 gaim_set_accessible_label(input, label); | |
4469 g_object_set_data(G_OBJECT(input), "identifier", pce->identifier); | |
4470 g_object_set_data(G_OBJECT(input), "is_spin", GINT_TO_POINTER(pce->is_int)); | |
4471 g_object_set_data(G_OBJECT(input), "required", GINT_TO_POINTER(pce->required)); | |
4472 data->entries = g_list_append(data->entries, input); | |
4473 | |
7620 | 4474 g_free(pce); |
4475 } | |
4476 | |
4477 g_list_free(list); | |
9754 | 4478 g_hash_table_destroy(defaults); |
7620 | 4479 |
10475 | 4480 /* Set whether the "OK" button should be clickable initially */ |
4481 addchat_set_sensitive_if_input_cb(NULL, data); | |
4482 | |
7620 | 4483 gtk_widget_show_all(data->entries_box); |
4484 } | |
4485 | |
4486 static void | |
10475 | 4487 addchat_select_account_cb(GObject *w, GaimAccount *account, |
7620 | 4488 GaimGtkAddChatData *data) |
4489 { | |
9460 | 4490 if (strcmp(gaim_account_get_protocol_id(data->account), |
4491 gaim_account_get_protocol_id(account)) == 0) | |
7620 | 4492 { |
4493 data->account = account; | |
4494 } | |
4495 else | |
4496 { | |
4497 data->account = account; | |
4498 rebuild_addchat_entries(data); | |
4499 } | |
4500 } | |
4501 | |
4502 void | |
7859 | 4503 gaim_gtk_blist_request_add_chat(GaimAccount *account, GaimGroup *group, |
9754 | 4504 const char *alias, const char *name) |
7620 | 4505 { |
4506 GaimGtkAddChatData *data; | |
8975 | 4507 GaimGtkBuddyList *gtkblist; |
4508 GList *l; | |
4509 GaimConnection *gc; | |
7620 | 4510 GtkWidget *label; |
4511 GtkWidget *rowbox; | |
4512 GtkWidget *hbox; | |
4513 GtkWidget *vbox; | |
4514 GtkWidget *img; | |
4515 | |
9812 | 4516 if (account != NULL) { |
4517 gc = gaim_account_get_connection(account); | |
4518 | |
4519 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->join_chat == NULL) { | |
4520 gaim_notify_error(gc, NULL, _("This protocol does not support chat rooms."), NULL); | |
4521 return; | |
4522 } | |
4523 } else { | |
4524 /* Find an account with chat capabilities */ | |
4525 for (l = gaim_connections_get_all(); l != NULL; l = l->next) { | |
4526 gc = (GaimConnection *)l->data; | |
4527 | |
4528 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->join_chat != NULL) { | |
4529 account = gaim_connection_get_account(gc); | |
4530 break; | |
4531 } | |
4532 } | |
4533 | |
4534 if (account == NULL) { | |
4535 gaim_notify_error(NULL, NULL, | |
4536 _("You are not currently signed on with any " | |
4537 "protocols that have the ability to chat."), NULL); | |
4538 return; | |
4539 } | |
4540 } | |
4541 | |
7620 | 4542 data = g_new0(GaimGtkAddChatData, 1); |
9812 | 4543 data->account = account; |
4544 data->default_chat_name = g_strdup(name); | |
7620 | 4545 |
4546 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, | |
4547 GTK_ICON_SIZE_DIALOG); | |
4548 | |
8975 | 4549 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); |
4550 | |
7620 | 4551 data->sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); |
4552 | |
8975 | 4553 data->window = gtk_dialog_new_with_buttons(_("Add Chat"), |
4554 NULL, GTK_DIALOG_NO_SEPARATOR, | |
4555 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
4556 GTK_STOCK_ADD, GTK_RESPONSE_OK, | |
4557 NULL); | |
4558 | |
4559 gtk_dialog_set_default_response(GTK_DIALOG(data->window), GTK_RESPONSE_OK); | |
4560 gtk_container_set_border_width(GTK_CONTAINER(data->window), 6); | |
4561 gtk_window_set_resizable(GTK_WINDOW(data->window), FALSE); | |
4562 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(data->window)->vbox), 12); | |
4563 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), 6); | |
7620 | 4564 gtk_window_set_role(GTK_WINDOW(data->window), "add_chat"); |
8975 | 4565 gtk_window_set_type_hint(GTK_WINDOW(data->window), |
9811 | 4566 GDK_WINDOW_TYPE_HINT_DIALOG); |
7620 | 4567 |
4568 hbox = gtk_hbox_new(FALSE, 12); | |
4569 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), hbox); | |
4570 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
4571 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
4572 | |
4573 vbox = gtk_vbox_new(FALSE, 5); | |
4574 gtk_container_add(GTK_CONTAINER(hbox), vbox); | |
4575 | |
4576 label = gtk_label_new( | |
4577 _("Please enter an alias, and the appropriate information " | |
4578 "about the chat you would like to add to your buddy list.\n")); | |
4579 gtk_widget_set_size_request(label, 400, -1); | |
4580 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
4581 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
4582 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
4583 | |
4584 rowbox = gtk_hbox_new(FALSE, 5); | |
4585 gtk_box_pack_start(GTK_BOX(vbox), rowbox, FALSE, FALSE, 0); | |
4586 | |
4587 label = gtk_label_new(_("Account:")); | |
4588 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
4589 gtk_size_group_add_widget(data->sg, label); | |
4590 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); | |
4591 | |
4592 data->account_menu = gaim_gtk_account_option_menu_new(account, FALSE, | |
10475 | 4593 G_CALLBACK(addchat_select_account_cb), |
9987 | 4594 chat_account_filter_func, data); |
7620 | 4595 gtk_box_pack_start(GTK_BOX(rowbox), data->account_menu, TRUE, TRUE, 0); |
8137 | 4596 gaim_set_accessible_label (data->account_menu, label); |
7620 | 4597 |
4598 data->entries_box = gtk_vbox_new(FALSE, 5); | |
9811 | 4599 gtk_container_set_border_width(GTK_CONTAINER(data->entries_box), 0); |
7620 | 4600 gtk_box_pack_start(GTK_BOX(vbox), data->entries_box, TRUE, TRUE, 0); |
4601 | |
4602 rebuild_addchat_entries(data); | |
4603 | |
4604 rowbox = gtk_hbox_new(FALSE, 5); | |
4605 gtk_box_pack_start(GTK_BOX(vbox), rowbox, FALSE, FALSE, 0); | |
4606 | |
4607 label = gtk_label_new(_("Alias:")); | |
4608 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
4609 gtk_size_group_add_widget(data->sg, label); | |
4610 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); | |
4611 | |
4612 data->alias_entry = gtk_entry_new(); | |
7859 | 4613 if (alias != NULL) |
4614 gtk_entry_set_text(GTK_ENTRY(data->alias_entry), alias); | |
7620 | 4615 gtk_box_pack_end(GTK_BOX(rowbox), data->alias_entry, TRUE, TRUE, 0); |
10311 | 4616 gtk_entry_set_activates_default(GTK_ENTRY(data->alias_entry), TRUE); |
8137 | 4617 gaim_set_accessible_label (data->alias_entry, label); |
7620 | 4618 |
4619 rowbox = gtk_hbox_new(FALSE, 5); | |
4620 gtk_box_pack_start(GTK_BOX(vbox), rowbox, FALSE, FALSE, 0); | |
4621 | |
9811 | 4622 label = gtk_label_new(_("Group:")); |
7620 | 4623 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); |
4624 gtk_size_group_add_widget(data->sg, label); | |
4625 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); | |
4626 | |
9811 | 4627 data->group_combo = gtk_combo_new(); |
4628 gtk_combo_set_popdown_strings(GTK_COMBO(data->group_combo), groups_tree()); | |
7620 | 4629 gtk_box_pack_end(GTK_BOX(rowbox), data->group_combo, TRUE, TRUE, 0); |
4630 | |
4631 if (group) | |
4632 { | |
4633 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(data->group_combo)->entry), | |
4634 group->name); | |
4635 } | |
8137 | 4636 gaim_set_accessible_label (data->group_combo, label); |
7620 | 4637 |
4638 g_signal_connect(G_OBJECT(data->window), "response", | |
4639 G_CALLBACK(add_chat_resp_cb), data); | |
4640 | |
4641 gtk_widget_show_all(data->window); | |
4642 } | |
4643 | |
4644 static void | |
4645 add_group_cb(GaimConnection *gc, const char *group_name) | |
4646 { | |
9285 | 4647 GaimGroup *group; |
4648 | |
4649 group = gaim_group_new(group_name); | |
4650 gaim_blist_add_group(group, NULL); | |
7620 | 4651 } |
4652 | |
4653 void | |
4654 gaim_gtk_blist_request_add_group(void) | |
4655 { | |
7853 | 4656 gaim_request_input(NULL, _("Add Group"), NULL, |
7620 | 4657 _("Please enter the name of the group to be added."), |
8697 | 4658 NULL, FALSE, FALSE, NULL, |
7620 | 4659 _("Add"), G_CALLBACK(add_group_cb), |
4660 _("Cancel"), NULL, NULL); | |
4661 } | |
4662 | |
5228 | 4663 void gaim_gtk_blist_docklet_toggle() { |
4664 /* 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
|
4665 /* This is called when one of those is clicked--it will show/hide the |
5228 | 4666 buddy list/login window--depending on which is active */ |
10315 | 4667 if (gtkblist && gtkblist->window) { |
4668 if (GTK_WIDGET_VISIBLE(gtkblist->window)) { | |
4669 gaim_blist_set_visible(GAIM_WINDOW_ICONIFIED(gtkblist->window) || gaim_gtk_blist_obscured); | |
5228 | 4670 } else { |
4671 #if _WIN32 | |
10315 | 4672 wgaim_systray_maximize(gtkblist->window); |
5228 | 4673 #endif |
10315 | 4674 gaim_blist_set_visible(TRUE); |
5228 | 4675 } |
4676 } else { | |
10315 | 4677 /* we're logging in or something... do nothing */ |
4678 /* or should I make the blist? */ | |
4679 gaim_debug_warning("gtkblist", | |
4680 "docklet_toggle called with gaim_connections_get_all() " | |
4681 "but no blist!\n"); | |
5228 | 4682 } |
4683 } | |
4684 | |
4685 void gaim_gtk_blist_docklet_add() | |
4686 { | |
4687 docklet_count++; | |
4688 } | |
4689 | |
4690 void gaim_gtk_blist_docklet_remove() | |
4691 { | |
4692 docklet_count--; | |
4693 if (!docklet_count) { | |
4694 gaim_blist_set_visible(TRUE); | |
4695 } | |
4696 } | |
4697 | |
7620 | 4698 static GaimBlistUiOps blist_ui_ops = |
5228 | 4699 { |
4700 gaim_gtk_blist_new_list, | |
5256 | 4701 gaim_gtk_blist_new_node, |
5228 | 4702 gaim_gtk_blist_show, |
4703 gaim_gtk_blist_update, | |
4704 gaim_gtk_blist_remove, | |
4705 gaim_gtk_blist_destroy, | |
7620 | 4706 gaim_gtk_blist_set_visible, |
4707 gaim_gtk_blist_request_add_buddy, | |
4708 gaim_gtk_blist_request_add_chat, | |
10012 | 4709 gaim_gtk_blist_request_add_group |
5228 | 4710 }; |
4711 | |
4712 | |
7620 | 4713 GaimBlistUiOps * |
4714 gaim_gtk_blist_get_ui_ops(void) | |
5228 | 4715 { |
4716 return &blist_ui_ops; | |
4717 } | |
4718 | |
7620 | 4719 static void account_signon_cb(GaimConnection *gc, gpointer z) |
4720 { | |
4721 GaimAccount *account = gaim_connection_get_account(gc); | |
4722 GaimBlistNode *gnode, *cnode; | |
4723 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) | |
4724 { | |
4725 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
4726 continue; | |
4727 for(cnode = gnode->child; cnode; cnode = cnode->next) | |
4728 { | |
4729 GaimChat *chat; | |
4730 | |
4731 if(!GAIM_BLIST_NODE_IS_CHAT(cnode)) | |
4732 continue; | |
4733 | |
4734 chat = (GaimChat *)cnode; | |
4735 | |
4736 if(chat->account != account) | |
4737 continue; | |
4738 | |
8197 | 4739 if(gaim_blist_node_get_bool((GaimBlistNode*)chat, "gtk-autojoin") || |
8198 | 4740 (gaim_blist_node_get_string((GaimBlistNode*)chat, |
4741 "gtk-autojoin") != NULL)) | |
7620 | 4742 serv_join_chat(gc, chat->components); |
4743 } | |
4744 } | |
4745 } | |
4746 | |
8815 | 4747 void * |
4748 gaim_gtk_blist_get_handle() { | |
4749 static int handle; | |
4750 | |
4751 return &handle; | |
4752 } | |
4753 | |
7620 | 4754 void gaim_gtk_blist_init(void) |
4755 { | |
8815 | 4756 void *gtk_blist_handle = gaim_gtk_blist_get_handle(); |
7620 | 4757 |
4758 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", | |
8815 | 4759 gtk_blist_handle, GAIM_CALLBACK(account_signon_cb), |
7620 | 4760 NULL); |
7731 | 4761 |
4762 /* Initialize prefs */ | |
8819 | 4763 gaim_prefs_add_none("/gaim/gtk/blist"); |
4764 gaim_prefs_add_bool("/gaim/gtk/blist/show_buddy_icons", TRUE); | |
4765 gaim_prefs_add_bool("/gaim/gtk/blist/show_empty_groups", FALSE); | |
4766 gaim_prefs_add_bool("/gaim/gtk/blist/show_offline_buddies", FALSE); | |
10282 | 4767 gaim_prefs_add_bool("/gaim/gtk/blist/list_visible", TRUE); |
9711 | 4768 gaim_prefs_add_string("/gaim/gtk/blist/sort_type", "alphabetical"); |
8819 | 4769 gaim_prefs_add_int("/gaim/gtk/blist/x", 0); |
4770 gaim_prefs_add_int("/gaim/gtk/blist/y", 0); | |
9778 | 4771 gaim_prefs_add_int("/gaim/gtk/blist/width", 309); /* Golden ratio, baby */ |
4772 gaim_prefs_add_int("/gaim/gtk/blist/height", 500); /* Golden ratio, baby */ | |
8819 | 4773 gaim_prefs_add_int("/gaim/gtk/blist/tooltip_delay", 500); |
7731 | 4774 |
8815 | 4775 /* Register our signals */ |
4776 gaim_signal_register(gtk_blist_handle, "gtkblist-created", | |
9811 | 4777 gaim_marshal_VOID__POINTER, NULL, 1, |
4778 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
4779 GAIM_SUBTYPE_BLIST)); | |
8819 | 4780 |
4781 gaim_signal_register(gtk_blist_handle, "drawing-tooltip", | |
9811 | 4782 gaim_marshal_VOID__POINTER_POINTER, NULL, 2, |
4783 gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_BLIST_NODE), | |
10477 | 4784 gaim_value_new_outgoing(GAIM_TYPE_BOXED, "GString *")); |
7620 | 4785 } |
4786 | |
8815 | 4787 void |
4788 gaim_gtk_blist_uninit(void) { | |
4789 gaim_signals_unregister_by_instance(gaim_gtk_blist_get_handle()); | |
4790 } | |
5228 | 4791 |
4792 /********************************************************************* | |
4793 * Public utility functions * | |
4794 *********************************************************************/ | |
4795 | |
4796 GdkPixbuf * | |
7620 | 4797 create_prpl_icon(GaimAccount *account) |
5228 | 4798 { |
4799 GaimPlugin *prpl; | |
4800 GaimPluginProtocolInfo *prpl_info = NULL; | |
4801 GdkPixbuf *status = NULL; | |
4802 char *filename = NULL; | |
4803 const char *protoname = NULL; | |
4804 char buf[256]; | |
4805 | |
10046 | 4806 g_return_val_if_fail(account != NULL, NULL); |
4807 | |
7956 | 4808 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); |
5228 | 4809 |
4810 if (prpl != NULL) { | |
4811 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
4812 | |
4813 if (prpl_info->list_icon != NULL) | |
4814 protoname = prpl_info->list_icon(account, NULL); | |
4815 } | |
4816 | |
4817 if (protoname == NULL) | |
4818 return NULL; | |
4819 | |
4820 /* | |
4821 * Status icons will be themeable too, and then it will look up | |
4822 * protoname from the theme | |
4823 */ | |
4824 g_snprintf(buf, sizeof(buf), "%s.png", protoname); | |
4825 | |
4826 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", | |
4827 "default", buf, NULL); | |
4828 status = gdk_pixbuf_new_from_file(filename, NULL); | |
4829 g_free(filename); | |
4830 | |
4831 return status; | |
4832 } | |
4833 | |
5422 | 4834 |
4835 /********************************************************************* | |
9811 | 4836 * Buddy List sorting functions * |
5422 | 4837 *********************************************************************/ |
4838 | |
7620 | 4839 void gaim_gtk_blist_sort_method_reg(const char *id, const char *name, gaim_gtk_blist_sort_function func) |
5422 | 4840 { |
4841 struct gaim_gtk_blist_sort_method *method = g_new0(struct gaim_gtk_blist_sort_method, 1); | |
7620 | 4842 method->id = g_strdup(id); |
5422 | 4843 method->name = g_strdup(name); |
9775 | 4844 method->func = func; |
5422 | 4845 gaim_gtk_blist_sort_methods = g_slist_append(gaim_gtk_blist_sort_methods, method); |
4846 } | |
4847 | |
7620 | 4848 void gaim_gtk_blist_sort_method_unreg(const char *id){ |
4849 GSList *l = gaim_gtk_blist_sort_methods; | |
4850 | |
4851 while(l) { | |
4852 struct gaim_gtk_blist_sort_method *method = l->data; | |
4853 if(!strcmp(method->id, id)) { | |
4854 gaim_gtk_blist_sort_methods = g_slist_remove(gaim_gtk_blist_sort_methods, method); | |
4855 g_free(method->id); | |
4856 g_free(method->name); | |
4857 g_free(method); | |
4858 break; | |
4859 } | |
4860 } | |
5422 | 4861 } |
4862 | |
7620 | 4863 void gaim_gtk_blist_sort_method_set(const char *id){ |
5422 | 4864 GSList *l = gaim_gtk_blist_sort_methods; |
7620 | 4865 |
4866 if(!id) | |
4867 id = "none"; | |
4868 | |
4869 while (l && strcmp(((struct gaim_gtk_blist_sort_method*)l->data)->id, id)) | |
5422 | 4870 l = l->next; |
7620 | 4871 |
5422 | 4872 if (l) { |
4873 current_sort_method = l->data; | |
4874 } else if (!current_sort_method) { | |
7620 | 4875 gaim_gtk_blist_sort_method_set("none"); |
5422 | 4876 return; |
4877 } | |
4878 redo_buddy_list(gaim_get_blist(), TRUE); | |
4879 | |
4880 } | |
4881 | |
4882 /****************************************** | |
4883 ** Sort Methods | |
4884 ******************************************/ | |
4885 | |
7620 | 4886 static GtkTreeIter sort_method_none(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter parent_iter, GtkTreeIter *cur) |
5422 | 4887 { |
7620 | 4888 GtkTreeIter iter; |
4889 GaimBlistNode *sibling = node->prev; | |
4890 GtkTreeIter sibling_iter; | |
4891 | |
4892 if(cur) | |
5422 | 4893 return *cur; |
7620 | 4894 |
4895 while (sibling && !get_iter_from_node(sibling, &sibling_iter)) { | |
4896 sibling = sibling->prev; | |
5422 | 4897 } |
7620 | 4898 |
4899 gtk_tree_store_insert_after(gtkblist->treemodel, &iter, | |
4900 node->parent ? &parent_iter : NULL, | |
4901 sibling ? &sibling_iter : NULL); | |
4902 | |
5422 | 4903 return iter; |
4904 } | |
4905 | |
7620 | 4906 #if GTK_CHECK_VERSION(2,2,1) |
4907 | |
4908 static GtkTreeIter sort_method_alphabetical(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur) | |
5422 | 4909 { |
4910 GtkTreeIter more_z, iter; | |
4911 GaimBlistNode *n; | |
4912 GValue val = {0,}; | |
7620 | 4913 |
4914 const char *my_name; | |
4915 | |
4916 if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
4917 my_name = gaim_contact_get_alias((GaimContact*)node); | |
4918 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) { | |
4919 my_name = gaim_chat_get_name((GaimChat*)node); | |
4920 } else { | |
4921 return sort_method_none(node, blist, groupiter, cur); | |
4922 } | |
4923 | |
5422 | 4924 |
4925 if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(gtkblist->treemodel), &more_z, &groupiter)) { | |
4926 gtk_tree_store_insert(gtkblist->treemodel, &iter, &groupiter, 0); | |
7620 | 4927 return iter; |
4928 } | |
4929 | |
4930 do { | |
4931 const char *this_name; | |
4932 int cmp; | |
4933 | |
4934 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &more_z, NODE_COLUMN, &val); | |
4935 n = g_value_get_pointer(&val); | |
4936 | |
4937 if(GAIM_BLIST_NODE_IS_CONTACT(n)) { | |
4938 this_name = gaim_contact_get_alias((GaimContact*)n); | |
4939 } else if(GAIM_BLIST_NODE_IS_CHAT(n)) { | |
4940 this_name = gaim_chat_get_name((GaimChat*)n); | |
4941 } else { | |
4942 this_name = NULL; | |
4943 } | |
4944 | |
4945 cmp = gaim_utf8_strcasecmp(my_name, this_name); | |
4946 | |
4947 if(this_name && (cmp < 0 || (cmp == 0 && node < n))) { | |
4948 if(cur) { | |
4949 gtk_tree_store_move_before(gtkblist->treemodel, cur, &more_z); | |
4950 return *cur; | |
4951 } else { | |
4952 gtk_tree_store_insert_before(gtkblist->treemodel, &iter, | |
4953 &groupiter, &more_z); | |
4954 return iter; | |
4955 } | |
4956 } | |
4957 g_value_unset(&val); | |
4958 } while (gtk_tree_model_iter_next (GTK_TREE_MODEL(gtkblist->treemodel), &more_z)); | |
4959 | |
4960 if(cur) { | |
4961 gtk_tree_store_move_before(gtkblist->treemodel, cur, NULL); | |
4962 return *cur; | |
4963 } else { | |
4964 gtk_tree_store_append(gtkblist->treemodel, &iter, &groupiter); | |
4965 return iter; | |
4966 } | |
4967 } | |
4968 | |
4969 static GtkTreeIter sort_method_status(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur) | |
4970 { | |
4971 GtkTreeIter more_z, iter; | |
4972 GaimBlistNode *n; | |
4973 GValue val = {0,}; | |
4974 | |
4975 GaimBuddy *my_buddy, *this_buddy; | |
4976 | |
4977 if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
4978 my_buddy = gaim_contact_get_priority_buddy((GaimContact*)node); | |
4979 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) { | |
4980 if(cur) | |
4981 return *cur; | |
4982 | |
4983 gtk_tree_store_append(gtkblist->treemodel, &iter, &groupiter); | |
4984 return iter; | |
4985 } else { | |
4986 return sort_method_none(node, blist, groupiter, cur); | |
4987 } | |
4988 | |
4989 | |
4990 if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(gtkblist->treemodel), &more_z, &groupiter)) { | |
4991 gtk_tree_store_insert(gtkblist->treemodel, &iter, &groupiter, 0); | |
5422 | 4992 return iter; |
4993 } | |
4994 | |
4995 do { | |
9944 | 4996 gint name_cmp; |
4997 gint presence_cmp; | |
7620 | 4998 |
5422 | 4999 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &more_z, NODE_COLUMN, &val); |
5000 n = g_value_get_pointer(&val); | |
7620 | 5001 |
5002 if(GAIM_BLIST_NODE_IS_CONTACT(n)) { | |
5003 this_buddy = gaim_contact_get_priority_buddy((GaimContact*)n); | |
5004 } else { | |
5005 this_buddy = NULL; | |
5006 } | |
5007 | |
9944 | 5008 name_cmp = gaim_utf8_strcasecmp( |
5009 (my_buddy | |
5010 ? gaim_contact_get_alias(gaim_buddy_get_contact(my_buddy)) | |
5011 : NULL), | |
5012 (this_buddy | |
5013 ? gaim_contact_get_alias(gaim_buddy_get_contact(this_buddy)) | |
5014 : NULL)); | |
5015 | |
5016 presence_cmp = gaim_presence_compare( | |
5017 gaim_buddy_get_presence(my_buddy), | |
5018 gaim_buddy_get_presence(this_buddy)); | |
5019 | |
5020 if (this_buddy == NULL || | |
5021 (presence_cmp > 0 || | |
5022 (presence_cmp == 0 && | |
5023 (name_cmp < 0 || (name_cmp == 0 && node < n))))) | |
5024 { | |
5025 if (cur != NULL) | |
5026 { | |
7620 | 5027 gtk_tree_store_move_before(gtkblist->treemodel, cur, &more_z); |
5028 return *cur; | |
9944 | 5029 } |
5030 else | |
5031 { | |
7620 | 5032 gtk_tree_store_insert_before(gtkblist->treemodel, &iter, |
9944 | 5033 &groupiter, &more_z); |
7620 | 5034 return iter; |
5035 } | |
5422 | 5036 } |
9944 | 5037 |
5422 | 5038 g_value_unset(&val); |
9944 | 5039 } |
5040 while (gtk_tree_model_iter_next(GTK_TREE_MODEL(gtkblist->treemodel), | |
5041 &more_z)); | |
7620 | 5042 |
5043 if(cur) { | |
5044 gtk_tree_store_move_before(gtkblist->treemodel, cur, NULL); | |
5045 return *cur; | |
5046 } else { | |
5047 gtk_tree_store_append(gtkblist->treemodel, &iter, &groupiter); | |
5048 return iter; | |
5049 } | |
5422 | 5050 } |
5051 | |
7620 | 5052 static GtkTreeIter sort_method_log(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur) |
5422 | 5053 { |
5054 GtkTreeIter more_z, iter; | |
7620 | 5055 GaimBlistNode *n = NULL, *n2; |
5422 | 5056 GValue val = {0,}; |
7620 | 5057 |
5058 int log_size = 0, this_log_size = 0; | |
5059 const char *buddy_name, *this_buddy_name; | |
5060 | |
5061 if(cur && (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(gtkblist->treemodel), &groupiter) == 1)) | |
5062 return *cur; | |
5063 | |
5064 if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
5065 for (n = node->child; n; n = n->next) | |
8898 | 5066 log_size += gaim_log_get_total_size(GAIM_LOG_IM, ((GaimBuddy*)(n))->name, ((GaimBuddy*)(n))->account); |
7620 | 5067 buddy_name = gaim_contact_get_alias((GaimContact*)node); |
5068 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) { | |
5069 /* we don't have a reliable way of getting the log filename | |
5070 * from the chat info in the blist, yet */ | |
5071 if(cur) | |
5072 return *cur; | |
5073 | |
5074 gtk_tree_store_append(gtkblist->treemodel, &iter, &groupiter); | |
5075 return iter; | |
5076 } else { | |
5077 return sort_method_none(node, blist, groupiter, cur); | |
5078 } | |
5079 | |
5080 | |
5422 | 5081 if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(gtkblist->treemodel), &more_z, &groupiter)) { |
5082 gtk_tree_store_insert(gtkblist->treemodel, &iter, &groupiter, 0); | |
5083 return iter; | |
5084 } | |
5085 | |
5086 do { | |
7620 | 5087 int cmp; |
5088 | |
5422 | 5089 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &more_z, NODE_COLUMN, &val); |
5090 n = g_value_get_pointer(&val); | |
7620 | 5091 this_log_size = 0; |
5092 | |
5093 if(GAIM_BLIST_NODE_IS_CONTACT(n)) { | |
5094 for (n2 = n->child; n2; n2 = n2->next) | |
8898 | 5095 this_log_size += gaim_log_get_total_size(GAIM_LOG_IM, ((GaimBuddy*)(n2))->name, ((GaimBuddy*)(n2))->account); |
7620 | 5096 this_buddy_name = gaim_contact_get_alias((GaimContact*)n); |
5097 } else { | |
5098 this_buddy_name = NULL; | |
5422 | 5099 } |
7620 | 5100 |
5101 cmp = gaim_utf8_strcasecmp(buddy_name, this_buddy_name); | |
5102 | |
5103 if (!GAIM_BLIST_NODE_IS_CONTACT(n) || log_size > this_log_size || | |
5104 ((log_size == this_log_size) && | |
5105 (cmp < 0 || (cmp == 0 && node < n)))) { | |
5106 if(cur) { | |
5107 gtk_tree_store_move_before(gtkblist->treemodel, cur, &more_z); | |
5108 return *cur; | |
5109 } else { | |
5110 gtk_tree_store_insert_before(gtkblist->treemodel, &iter, | |
5111 &groupiter, &more_z); | |
5112 return iter; | |
5113 } | |
5422 | 5114 } |
5115 g_value_unset(&val); | |
5116 } while (gtk_tree_model_iter_next (GTK_TREE_MODEL(gtkblist->treemodel), &more_z)); | |
7620 | 5117 |
5118 if(cur) { | |
5119 gtk_tree_store_move_before(gtkblist->treemodel, cur, NULL); | |
5120 return *cur; | |
5121 } else { | |
5122 gtk_tree_store_append(gtkblist->treemodel, &iter, &groupiter); | |
5123 return iter; | |
5124 } | |
5125 } | |
5126 | |
5127 #endif | |
5128 | |
5129 static void | |
9015 | 5130 plugin_act(GtkObject *obk, GaimPluginAction *pam) |
7620 | 5131 { |
10352 | 5132 if (pam->callback) |
5133 pam->callback(pam); | |
5422 | 5134 } |
7620 | 5135 |
8986 | 5136 static void |
9015 | 5137 build_plugin_actions(GtkWidget *menu, GaimPlugin *plugin, gpointer context) |
8986 | 5138 { |
9015 | 5139 GtkWidget *menuitem = NULL; |
5140 GaimPluginAction *action = NULL; | |
5141 GList *l, *ll; | |
5142 | |
5143 for (l = ll = GAIM_PLUGIN_ACTIONS(plugin, context); l; l = l->next) { | |
5144 if (l->data) { | |
5145 action = (GaimPluginAction *) l->data; | |
5146 action->plugin = plugin; | |
5147 action->context = context; | |
5148 | |
5149 menuitem = gtk_menu_item_new_with_label(action->label); | |
5150 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
5151 g_signal_connect(G_OBJECT(menuitem), "activate", | |
5152 G_CALLBACK(plugin_act), action); | |
5153 g_object_set_data(G_OBJECT(menuitem), "plugin_action", action); | |
5154 gtk_widget_show(menuitem); | |
5155 } | |
5156 else | |
5157 gaim_separator(menu); | |
5158 } | |
5159 | |
5160 g_list_free(ll); | |
8986 | 5161 } |
5162 | |
5163 | |
7620 | 5164 void |
5165 gaim_gtk_blist_update_protocol_actions(void) | |
5166 { | |
9015 | 5167 GtkWidget *menuitem, *submenu; |
7620 | 5168 GList *l; |
5169 GaimConnection *gc = NULL; | |
9015 | 5170 GaimPlugin *plugin = NULL; |
7620 | 5171 int count = 0; |
9015 | 5172 |
9019 | 5173 if (protomenu == NULL) |
7620 | 5174 return; |
5175 | |
9019 | 5176 /* Clear the old Account Actions menu */ |
9015 | 5177 for (l = gtk_container_get_children(GTK_CONTAINER(protomenu)); l; l = l->next) { |
5178 GaimPluginAction *action; | |
9987 | 5179 |
7620 | 5180 menuitem = l->data; |
9015 | 5181 action = (GaimPluginAction *) g_object_get_data(G_OBJECT(menuitem), |
5182 "plugin_action"); | |
5183 g_free(action); | |
7620 | 5184 |
5185 gtk_container_remove(GTK_CONTAINER(protomenu), GTK_WIDGET(menuitem)); | |
5186 } | |
5187 | |
9019 | 5188 /* Count the number of accounts with actions */ |
9015 | 5189 for (l = gaim_connections_get_all(); l; l = l->next) { |
5190 gc = l->data; | |
5191 plugin = gc->prpl; | |
5192 | |
9019 | 5193 if (GAIM_CONNECTION_IS_CONNECTED(gc) && GAIM_PLUGIN_HAS_ACTIONS(plugin)) |
5194 count++; | |
5195 | |
9015 | 5196 /* no need to count past 2, so don't */ |
9019 | 5197 if (count > 1) |
9015 | 5198 break; |
7620 | 5199 } |
5200 | |
9015 | 5201 if (count == 0) { |
5202 menuitem = gtk_menu_item_new_with_label(_("No actions available")); | |
7620 | 5203 gtk_menu_shell_append(GTK_MENU_SHELL(protomenu), menuitem); |
9015 | 5204 gtk_widget_set_sensitive(menuitem, FALSE); |
7620 | 5205 gtk_widget_show(menuitem); |
5206 } | |
9019 | 5207 |
5208 else if (count == 1) { | |
5209 /* Find the one account that has actions */ | |
5210 for (l = gaim_connections_get_all(); l; l = l->next) { | |
5211 gc = l->data; | |
5212 plugin = gc->prpl; | |
5213 | |
5214 if (GAIM_CONNECTION_IS_CONNECTED(gc) && GAIM_PLUGIN_HAS_ACTIONS(plugin)) | |
5215 break; | |
5216 } | |
5217 | |
9015 | 5218 build_plugin_actions(protomenu, plugin, gc); |
7620 | 5219 } |
9019 | 5220 |
7620 | 5221 else { |
9015 | 5222 for (l = gaim_connections_get_all(); l; l = l->next) { |
7620 | 5223 GaimAccount *account; |
5224 GdkPixbuf *pixbuf, *scale; | |
5225 GtkWidget *image; | |
9015 | 5226 char *buf; |
5227 | |
5228 gc = l->data; | |
5229 plugin = gc->prpl; | |
5230 | |
9019 | 5231 if (!GAIM_CONNECTION_IS_CONNECTED(gc) || !GAIM_PLUGIN_HAS_ACTIONS(plugin)) |
7620 | 5232 continue; |
5233 | |
5234 account = gaim_connection_get_account(gc); | |
9015 | 5235 buf = g_strconcat(gaim_account_get_username(account), " (", |
5236 plugin->info->name, ")", NULL); | |
7620 | 5237 menuitem = gtk_image_menu_item_new_with_label(buf); |
9015 | 5238 g_free(buf); |
5239 | |
5240 pixbuf = create_prpl_icon(account); | |
9019 | 5241 if (pixbuf) { |
7620 | 5242 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, |
5243 GDK_INTERP_BILINEAR); | |
5244 image = gtk_image_new_from_pixbuf(scale); | |
5245 g_object_unref(G_OBJECT(pixbuf)); | |
5246 g_object_unref(G_OBJECT(scale)); | |
5247 gtk_widget_show(image); | |
9015 | 5248 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); |
7620 | 5249 } |
5250 | |
5251 gtk_menu_shell_append(GTK_MENU_SHELL(protomenu), menuitem); | |
5252 gtk_widget_show(menuitem); | |
5253 | |
5254 submenu = gtk_menu_new(); | |
5255 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); | |
5256 gtk_widget_show(submenu); | |
5257 | |
9015 | 5258 build_plugin_actions(submenu, plugin, gc); |
7620 | 5259 } |
5260 } | |
5261 } | |
8986 | 5262 |
5263 void | |
5264 gaim_gtk_blist_update_plugin_actions(void) | |
5265 { | |
9015 | 5266 GtkWidget *menuitem, *submenu; |
5267 GaimPlugin *plugin = NULL; | |
8986 | 5268 GList *l; |
5269 int count = 0; | |
5270 | |
9019 | 5271 if (pluginmenu == NULL) |
8986 | 5272 return; |
5273 | |
9019 | 5274 /* Clear the old Account Actions menu */ |
9015 | 5275 for (l = gtk_container_get_children(GTK_CONTAINER(pluginmenu)); l; l = l->next) { |
5276 GaimPluginAction *action; | |
8986 | 5277 |
5278 menuitem = l->data; | |
9015 | 5279 action = g_object_get_data(G_OBJECT(menuitem), "plugin_action"); |
5280 g_free(action); | |
8986 | 5281 |
5282 gtk_container_remove(GTK_CONTAINER(pluginmenu), GTK_WIDGET(menuitem)); | |
5283 } | |
5284 | |
9019 | 5285 /* Count the number of plugins with actions */ |
9015 | 5286 for (l = gaim_plugins_get_loaded(); l; l = l->next) { |
5287 plugin = (GaimPlugin *) l->data; | |
5288 | |
9019 | 5289 if (!GAIM_IS_PROTOCOL_PLUGIN(plugin) && GAIM_PLUGIN_HAS_ACTIONS(plugin)) |
5290 count++; | |
5291 | |
5292 /* no need to count past 2, so don't */ | |
5293 if (count > 1) | |
9015 | 5294 break; |
8986 | 5295 } |
5296 | |
5297 if (count == 0) { | |
5298 menuitem = gtk_menu_item_new_with_label(_("No actions available")); | |
5299 gtk_menu_shell_append(GTK_MENU_SHELL(pluginmenu), menuitem); | |
9015 | 5300 gtk_widget_set_sensitive(menuitem, FALSE); |
8986 | 5301 gtk_widget_show(menuitem); |
5302 } | |
9019 | 5303 |
5304 else if (count == 1) { | |
5305 /* Find the one plugin that has actions */ | |
5306 for (l = gaim_plugins_get_loaded(); l; l = l->next) { | |
5307 plugin = (GaimPlugin *) l->data; | |
5308 | |
5309 if (!GAIM_IS_PROTOCOL_PLUGIN(plugin) && GAIM_PLUGIN_HAS_ACTIONS(plugin)) | |
5310 break; | |
5311 } | |
5312 | |
9015 | 5313 build_plugin_actions(pluginmenu, plugin, NULL); |
8986 | 5314 } |
9019 | 5315 |
8986 | 5316 else { |
9015 | 5317 for (l = gaim_plugins_get_loaded(); l; l = l->next) { |
5318 plugin = (GaimPlugin *) l->data; | |
5319 | |
5320 if (GAIM_IS_PROTOCOL_PLUGIN(plugin)) | |
8986 | 5321 continue; |
5322 | |
9019 | 5323 if (!GAIM_PLUGIN_HAS_ACTIONS(plugin)) |
9015 | 5324 continue; |
5325 | |
5326 menuitem = gtk_image_menu_item_new_with_label(plugin->info->name); | |
8986 | 5327 gtk_menu_shell_append(GTK_MENU_SHELL(pluginmenu), menuitem); |
5328 gtk_widget_show(menuitem); | |
5329 | |
5330 submenu = gtk_menu_new(); | |
5331 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); | |
5332 gtk_widget_show(submenu); | |
5333 | |
9015 | 5334 build_plugin_actions(submenu, plugin, NULL); |
8986 | 5335 } |
5336 } | |
5337 } |