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