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