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