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