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