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