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