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