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