Mercurial > pidgin
annotate src/buddy.c @ 5186:a107115a13ae
[gaim-migrate @ 5550]
don't infinite loop on unload
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Sun, 20 Apr 2003 20:56:14 +0000 |
parents | 0f31d00d2501 |
children | 7c1c9bdc1f8e |
rev | line source |
---|---|
1 | 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 */ | |
21 | |
349
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
342
diff
changeset
|
22 #ifdef HAVE_CONFIG_H |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2048
diff
changeset
|
23 #include <config.h> |
349
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
342
diff
changeset
|
24 #endif |
391
be408b41c172
[gaim-migrate @ 401]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
350
diff
changeset
|
25 #ifdef GAIM_PLUGINS |
3630 | 26 #ifndef _WIN32 |
391
be408b41c172
[gaim-migrate @ 401]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
350
diff
changeset
|
27 #include <dlfcn.h> |
3630 | 28 #endif |
391
be408b41c172
[gaim-migrate @ 401]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
350
diff
changeset
|
29 #endif /* GAIM_PLUGINS */ |
1 | 30 #include <string.h> |
31 #include <stdio.h> | |
32 #include <stdlib.h> | |
3159 | 33 #include <ctype.h> |
1 | 34 #include <math.h> |
35 #include <time.h> | |
3630 | 36 #include <ctype.h> |
37 | |
38 #ifdef _WIN32 | |
39 #include <gdk/gdkwin32.h> | |
40 #else | |
1233
728a90516211
[gaim-migrate @ 1243]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1230
diff
changeset
|
41 #include <unistd.h> |
3630 | 42 #include <gdk/gdkx.h> |
43 #endif | |
1 | 44 |
1634
d029dc28a61e
[gaim-migrate @ 1644]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1625
diff
changeset
|
45 #include <gdk/gdkkeysyms.h> |
1 | 46 #include <gtk/gtk.h> |
1030
38452403563b
[gaim-migrate @ 1040]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1002
diff
changeset
|
47 #include "prpl.h" |
4561 | 48 #include "sound.h" |
1 | 49 #include "gaim.h" |
4687 | 50 #include "gtklist.h" |
5054 | 51 #include "gtkpounce.h" |
4687 | 52 #include "gtkft.h" |
3630 | 53 |
54 #ifdef _WIN32 | |
55 #include "win32dep.h" | |
56 #endif | |
57 | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
58 static struct gaim_gtk_buddy_list *gtkblist = NULL; |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
59 |
4840 | 60 /* part of the best damn Docklet code this side of Tahiti */ |
4698 | 61 static gboolean gaim_gtk_blist_obscured = FALSE; |
62 | |
4810 | 63 static void gaim_gtk_blist_selection_changed(GtkTreeSelection *selection, gpointer data); |
4687 | 64 static void gaim_gtk_blist_update(struct gaim_buddy_list *list, GaimBlistNode *node); |
4724 | 65 static char *gaim_get_tooltip_text(struct buddy *b); |
4834 | 66 static char *item_factory_translate_func (const char *path, gpointer func_data); |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
67 |
4687 | 68 /*************************************************** |
69 * Callbacks * | |
70 ***************************************************/ | |
3869 | 71 |
4840 | 72 static gboolean gtk_blist_delete_cb(GtkWidget *w, GdkEventAny *event, gpointer data) |
4698 | 73 { |
74 if (docklet_count) | |
75 gaim_blist_set_visible(FALSE); | |
76 else | |
77 do_quit(); | |
4840 | 78 |
79 /* we handle everything, event should not propogate further */ | |
80 return TRUE; | |
81 } | |
82 | |
83 static gboolean gtk_blist_save_prefs_cb(gpointer data) | |
84 { | |
85 save_prefs(); | |
86 | |
87 /* only run once */ | |
88 return FALSE; | |
89 } | |
90 | |
91 static gboolean gtk_blist_configure_cb(GtkWidget *w, GdkEventConfigure *event, gpointer data) | |
92 { | |
93 /* unfortunately GdkEventConfigure ignores the window gravity, but * | |
94 * the only way we have of setting the position doesn't. we have to * | |
95 * call get_position and get_size because they do pay attention to * | |
96 * the gravity. this is inefficient and I agree it sucks, but it's * | |
97 * more likely to work correctly. - Robot101 */ | |
98 gint x, y; | |
99 | |
100 /* check for visibility because when we aren't visible, this will * | |
101 * give us bogus (0,0) coordinates. - xOr */ | |
102 if (GTK_WIDGET_VISIBLE(w)) { | |
103 gtk_window_get_position(GTK_WINDOW(w), &x, &y); | |
104 | |
105 if (x != blist_pos.x || | |
106 y != blist_pos.y || | |
107 event->width != blist_pos.width || | |
108 event->height != blist_pos.height) { | |
109 blist_pos.x = x; | |
110 blist_pos.y = y; | |
111 blist_pos.width = event->width; | |
112 blist_pos.height = event->height; | |
113 | |
114 if (!g_main_context_find_source_by_user_data(NULL, >k_blist_save_prefs_cb)) { | |
115 g_timeout_add(5000, gtk_blist_save_prefs_cb, >k_blist_save_prefs_cb); | |
116 } | |
117 } | |
118 } | |
119 | |
120 /* continue to handle event normally */ | |
121 return FALSE; | |
122 } | |
123 | |
124 static gboolean gtk_blist_visibility_cb(GtkWidget *w, GdkEventVisibility *event, gpointer data) | |
125 { | |
126 if (event->state == GDK_VISIBILITY_FULLY_OBSCURED) | |
127 gaim_gtk_blist_obscured = TRUE; | |
128 else | |
129 gaim_gtk_blist_obscured = FALSE; | |
130 | |
131 /* continue to handle event normally */ | |
132 return FALSE; | |
4698 | 133 } |
134 | |
4732 | 135 static void gtk_blist_menu_info_cb(GtkWidget *w, struct buddy *b) |
136 { | |
137 serv_get_info(b->account->gc, b->name); | |
138 } | |
139 | |
4697 | 140 static void gtk_blist_menu_im_cb(GtkWidget *w, struct buddy *b) |
141 { | |
142 gaim_conversation_new(GAIM_CONV_IM, b->account, b->name); | |
143 } | |
144 | |
145 static void gtk_blist_menu_alias_cb(GtkWidget *w, struct buddy *b) | |
146 { | |
147 alias_dialog_bud(b); | |
148 } | |
149 | |
150 static void gtk_blist_menu_bp_cb(GtkWidget *w, struct buddy *b) | |
151 { | |
5032
cb700c07ee07
[gaim-migrate @ 5375]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
152 gaim_gtkpounce_dialog_show(b, NULL); |
4697 | 153 } |
154 | |
155 static void gtk_blist_menu_showlog_cb(GtkWidget *w, struct buddy *b) | |
156 { | |
157 show_log(b->name); | |
158 } | |
159 | |
160 static void gtk_blist_show_systemlog_cb() | |
161 { | |
162 show_log(NULL); | |
163 } | |
164 | |
4776 | 165 static void gtk_blist_show_onlinehelp_cb() |
166 { | |
4916 | 167 open_url(NULL, WEBSITE "documentation.php"); |
4776 | 168 } |
169 | |
4692 | 170 static void gtk_blist_button_im_cb(GtkWidget *w, GtkTreeView *tv) |
171 { | |
172 GtkTreeIter iter; | |
173 GtkTreeModel *model = gtk_tree_view_get_model(tv); | |
174 GtkTreeSelection *sel = gtk_tree_view_get_selection(tv); | |
175 | |
176 if(gtk_tree_selection_get_selected(sel, &model, &iter)){ | |
177 GaimBlistNode *node; | |
178 | |
179 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
4999 | 180 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { |
4692 | 181 gaim_conversation_new(GAIM_CONV_IM, ((struct buddy*)node)->account, ((struct buddy*)node)->name); |
4999 | 182 return; |
183 } | |
4692 | 184 } |
4999 | 185 show_im_dialog(); |
4694 | 186 } |
4692 | 187 |
4694 | 188 static void gtk_blist_button_info_cb(GtkWidget *w, GtkTreeView *tv) |
189 { | |
190 GtkTreeIter iter; | |
191 GtkTreeModel *model = gtk_tree_view_get_model(tv); | |
192 GtkTreeSelection *sel = gtk_tree_view_get_selection(tv); | |
4692 | 193 |
4694 | 194 if(gtk_tree_selection_get_selected(sel, &model, &iter)){ |
195 GaimBlistNode *node; | |
196 | |
197 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
198 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
199 serv_get_info(((struct buddy*)node)->account->gc, ((struct buddy*)node)->name); | |
200 return; | |
201 } | |
202 } | |
203 show_info_dialog(); | |
204 } | |
205 | |
206 static void gtk_blist_button_chat_cb(GtkWidget *w, gpointer data) | |
207 { | |
208 /* FIXME: someday, we can check to see if we've selected a chat node */ | |
209 join_chat(); | |
210 } | |
211 | |
212 static void gtk_blist_button_away_cb(GtkWidget *w, gpointer data) | |
213 { | |
214 gtk_menu_popup(GTK_MENU(awaymenu), NULL, NULL, NULL, NULL, 1, GDK_CURRENT_TIME); | |
4692 | 215 } |
216 | |
5142 | 217 static void gtk_blist_row_expanded_cb(GtkTreeView *tv, GtkTreeIter *iter, GtkTreePath *path, gpointer user_data) { |
218 GaimBlistNode *node; | |
219 GValue val = {0,}; | |
220 | |
221 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), iter, NODE_COLUMN, &val); | |
222 | |
223 node = g_value_get_pointer(&val); | |
224 | |
225 if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
226 gaim_group_set_setting((struct group *)node, "collapsed", NULL); | |
227 gaim_blist_save(); | |
228 } | |
229 } | |
230 | |
231 static void gtk_blist_row_collapsed_cb(GtkTreeView *tv, GtkTreeIter *iter, GtkTreePath *path, gpointer user_data) { | |
232 GaimBlistNode *node; | |
233 GValue val = {0,}; | |
234 | |
235 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), iter, NODE_COLUMN, &val); | |
236 | |
237 node = g_value_get_pointer(&val); | |
238 | |
239 if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
240 gaim_group_set_setting((struct group *)node, "collapsed", "true"); | |
241 gaim_blist_save(); | |
242 } | |
243 } | |
244 | |
4687 | 245 static void gtk_blist_row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) { |
246 GaimBlistNode *node; | |
247 GtkTreeIter iter; | |
248 GValue val = { 0, }; | |
4936 | 249 |
4687 | 250 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); |
4936 | 251 |
4687 | 252 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); |
253 node = g_value_get_pointer(&val); | |
4936 | 254 |
4687 | 255 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { |
4911 | 256 struct gaim_conversation *conv = |
257 gaim_conversation_new(GAIM_CONV_IM, ((struct buddy*)node)->account, ((struct buddy*)node)->name); | |
258 if(conv) { | |
259 gaim_window_raise(gaim_conversation_get_window(conv)); | |
260 gaim_window_switch_conversation( | |
261 gaim_conversation_get_window(conv), | |
262 gaim_conversation_get_index(conv)); | |
263 } | |
4697 | 264 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { |
265 if (gtk_tree_view_row_expanded(tv, path)) | |
266 gtk_tree_view_collapse_row(tv, path); | |
267 else | |
268 gtk_tree_view_expand_row(tv,path,FALSE); | |
1 | 269 } |
270 } | |
271 | |
4916 | 272 static void gaim_gtk_blist_add_buddy_cb() |
273 { | |
274 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)); | |
275 GtkTreeIter iter; | |
276 GaimBlistNode *node; | |
277 | |
278 if(gtk_tree_selection_get_selected(sel, NULL, &iter)){ | |
279 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
280 if (GAIM_BLIST_NODE_IS_BUDDY(node)) | |
281 show_add_buddy(NULL, NULL, ((struct group*)node->parent)->name, NULL); | |
282 else if (GAIM_BLIST_NODE_IS_GROUP(node)) | |
283 show_add_buddy(NULL, NULL, ((struct group*)node)->name, NULL); | |
284 } | |
285 else { | |
286 show_add_buddy(NULL, NULL, NULL, NULL); | |
287 } | |
288 } | |
5018 | 289 |
4921 | 290 static void |
4916 | 291 gaim_gtk_blist_remove_cb (GtkWidget *w, GaimBlistNode *node) |
292 { | |
293 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
294 struct buddy *b = (struct buddy*)node; | |
295 show_confirm_del(b->account->gc, b->name); | |
296 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
297 struct group *g = (struct group*)node; | |
298 show_confirm_del_group(g); | |
299 } | |
300 } | |
301 | |
4687 | 302 static void gaim_proto_menu_cb(GtkMenuItem *item, struct buddy *b) |
1 | 303 { |
4687 | 304 struct proto_buddy_menu *pbm = g_object_get_data(G_OBJECT(item), "gaimcallback"); |
305 if (pbm->callback) | |
306 pbm->callback(pbm->gc, b->name); | |
1396
df7c3cacac92
[gaim-migrate @ 1406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1392
diff
changeset
|
307 } |
1 | 308 |
4687 | 309 static gboolean gtk_blist_button_press_cb(GtkWidget *tv, GdkEventButton *event, gpointer null) |
1391
d606da211acb
[gaim-migrate @ 1401]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1376
diff
changeset
|
310 { |
4687 | 311 GtkTreePath *path; |
312 GaimBlistNode *node; | |
313 GValue val = { 0, }; | |
314 GtkTreeIter iter; | |
315 GtkWidget *menu, *menuitem; | |
4702 | 316 GtkTreeSelection *sel; |
4687 | 317 GList *list; |
318 struct prpl *prpl; | |
1391
d606da211acb
[gaim-migrate @ 1401]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1376
diff
changeset
|
319 |
4687 | 320 if (event->button != 3) |
321 return FALSE; | |
4718 | 322 |
4687 | 323 /* Here we figure out which node was clicked */ |
324 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL)) | |
325 return FALSE; | |
326 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
327 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
328 node = g_value_get_pointer(&val); | |
329 menu = gtk_menu_new(); | |
3251 | 330 |
4916 | 331 if (GAIM_BLIST_NODE_IS_GROUP(node)) { |
5156 | 332 gaim_new_item_from_stock(menu, _("_Add a Buddy"), GTK_STOCK_ADD, G_CALLBACK(gaim_gtk_blist_add_buddy_cb), node, 0, 0, NULL); |
333 gaim_new_item_from_stock(menu, _("_Delete Group"), GTK_STOCK_REMOVE, G_CALLBACK(gaim_gtk_blist_remove_cb), node, 0, 0, NULL); | |
334 gaim_new_item_from_stock(menu, _("_Rename"), NULL, G_CALLBACK(show_rename_group), node, 0, 0, NULL); | |
4916 | 335 } else if (GAIM_BLIST_NODE_IS_BUDDY(node)) { |
336 /* Protocol specific options */ | |
337 prpl = find_prpl(((struct buddy*)node)->account->protocol); | |
338 | |
5156 | 339 if (prpl && prpl->get_info) |
340 gaim_new_item_from_stock(menu, _("_Get Info"), GAIM_STOCK_INFO, G_CALLBACK(gtk_blist_menu_info_cb), node, 0, 0, NULL); | |
4732 | 341 |
5156 | 342 gaim_new_item_from_stock(menu, _("_IM"), GAIM_STOCK_IM, G_CALLBACK(gtk_blist_menu_im_cb), node, 0, 0, NULL); |
343 gaim_new_item_from_stock(menu, _("Add Buddy _Pounce"), NULL, G_CALLBACK(gtk_blist_menu_bp_cb), node, 0, 0, NULL); | |
344 gaim_new_item_from_stock(menu, _("View _Log"), NULL, G_CALLBACK(gtk_blist_menu_showlog_cb), node, 0, 0, NULL); | |
4916 | 345 |
346 if (prpl) { | |
347 list = prpl->buddy_menu(((struct buddy*)node)->account->gc, ((struct buddy*)node)->name); | |
348 while (list) { | |
349 struct proto_buddy_menu *pbm = list->data; | |
350 menuitem = gtk_menu_item_new_with_mnemonic(pbm->label); | |
351 g_object_set_data(G_OBJECT(menuitem), "gaimcallback", pbm); | |
352 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gaim_proto_menu_cb), node); | |
353 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
354 list = list->next; | |
355 } | |
356 } | |
5017 | 357 |
358 plugin_event (event_draw_menu, menu, ((struct buddy *) node)->name); | |
5156 | 359 |
4916 | 360 gaim_separator(menu); |
5156 | 361 gaim_new_item_from_stock(menu, _("_Alias"), GAIM_STOCK_EDIT, G_CALLBACK(gtk_blist_menu_alias_cb), node, 0, 0, NULL); |
362 gaim_new_item_from_stock(menu, _("_Remove"), GTK_STOCK_REMOVE, G_CALLBACK(gaim_gtk_blist_remove_cb), node, 0, 0, NULL); | |
4732 | 363 } |
4916 | 364 |
4687 | 365 gtk_widget_show_all(menu); |
366 | |
367 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time); | |
1 | 368 |
4702 | 369 #if (1) /* This code only exists because GTK doesn't work. If we return FALSE here, as would be normal |
370 * the event propoagates down and somehow gets interpreted as the start of a drag event. */ | |
371 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv)); | |
372 gtk_tree_selection_select_path(sel, path); | |
4721 | 373 gtk_tree_path_free(path); |
4702 | 374 return TRUE; |
375 #endif | |
1 | 376 } |
377 | |
5000 | 378 static void gaim_gtk_blist_show_empty_groups_cb(gpointer data, guint action, GtkWidget *item) |
379 { | |
380 if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item))) | |
381 blist_options &= ~OPT_BLIST_NO_MT_GRP; | |
382 else | |
383 blist_options |= OPT_BLIST_NO_MT_GRP; | |
384 save_prefs(); | |
385 gaim_gtk_blist_refresh(gaim_get_blist()); | |
386 } | |
387 | |
4944 | 388 static void gaim_gtk_blist_edit_mode_cb(gpointer callback_data, guint callback_action, |
4936 | 389 GtkWidget *checkitem) { |
5135 | 390 if(gtkblist->window->window) { |
391 GdkCursor *cursor = gdk_cursor_new(GDK_WATCH); | |
392 gdk_window_set_cursor(gtkblist->window->window, cursor); | |
393 while (gtk_events_pending()) | |
394 gtk_main_iteration(); | |
395 gdk_cursor_unref(cursor); | |
396 } | |
397 | |
4936 | 398 if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(checkitem))) |
399 blist_options |= OPT_BLIST_SHOW_OFFLINE; | |
400 else | |
401 blist_options &= ~OPT_BLIST_SHOW_OFFLINE; | |
4929 | 402 save_prefs(); |
5135 | 403 |
404 if(gtkblist->window->window) { | |
405 GdkCursor *cursor = gdk_cursor_new(GDK_LEFT_PTR); | |
406 gdk_window_set_cursor(gtkblist->window->window, cursor); | |
407 gdk_cursor_unref(cursor); | |
408 } | |
409 | |
4916 | 410 gaim_gtk_blist_refresh(gaim_get_blist()); |
411 } | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4349
diff
changeset
|
412 |
4702 | 413 static void gaim_gtk_blist_drag_data_get_cb (GtkWidget *widget, |
414 GdkDragContext *dc, | |
415 GtkSelectionData *data, | |
416 guint info, | |
417 guint time, | |
418 gpointer *null) | |
419 { | |
4781 | 420 if (data->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE)) { |
4702 | 421 GtkTreeRowReference *ref = g_object_get_data(G_OBJECT(dc), "gtk-tree-view-source-row"); |
422 GtkTreePath *sourcerow = gtk_tree_row_reference_get_path(ref); | |
423 GtkTreeIter iter; | |
424 GaimBlistNode *node = NULL; | |
425 GValue val = {0}; | |
426 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, sourcerow); | |
427 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
428 node = g_value_get_pointer(&val); | |
4781 | 429 gtk_selection_data_set (data, |
430 gdk_atom_intern ("GAIM_BLIST_NODE", FALSE), | |
431 8, /* bits */ | |
432 (void*)&node, | |
433 sizeof (node)); | |
434 | |
4721 | 435 gtk_tree_path_free(sourcerow); |
4702 | 436 } |
4781 | 437 |
4702 | 438 } |
439 | |
440 static void gaim_gtk_blist_drag_data_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, | |
441 GtkSelectionData *sd, guint info, guint t) | |
442 { | |
4781 | 443 if (sd->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE) && sd->data) { |
444 GaimBlistNode *n = NULL; | |
4702 | 445 GtkTreePath *path = NULL; |
4704 | 446 GtkTreeViewDropPosition position; |
4781 | 447 memcpy(&n, sd->data, sizeof(n)); |
4704 | 448 if(gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), x, y, &path, &position)) { |
449 /* if we're here, I think it means the drop is ok */ | |
4770 | 450 GtkTreeIter iter; |
451 GaimBlistNode *node; | |
452 GValue val = {0}; | |
453 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
454 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
455 node = g_value_get_pointer(&val); | |
4781 | 456 |
457 if (GAIM_BLIST_NODE_IS_BUDDY(n)) { | |
458 struct buddy *b = (struct buddy*)n; | |
459 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
4795 | 460 switch(position) { |
461 case GTK_TREE_VIEW_DROP_AFTER: | |
462 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
463 gaim_blist_add_buddy(b, (struct group*)node->parent, node); | |
464 break; | |
465 case GTK_TREE_VIEW_DROP_BEFORE: | |
466 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
467 gaim_blist_add_buddy(b, (struct group*)node->parent, node->prev); | |
468 break; | |
4781 | 469 } |
470 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
471 gaim_blist_add_buddy(b, (struct group*)node, NULL); | |
4795 | 472 } |
4781 | 473 } else if (GAIM_BLIST_NODE_IS_GROUP(n)) { |
474 struct group *g = (struct group*)n; | |
475 if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
476 switch (position) { | |
477 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
478 case GTK_TREE_VIEW_DROP_AFTER: | |
479 gaim_blist_add_group(g, node); | |
480 break; | |
481 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
482 case GTK_TREE_VIEW_DROP_BEFORE: | |
483 gaim_blist_add_group(g, node->prev); | |
484 break; | |
485 } | |
486 | |
5055 | 487 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) { |
488 gaim_blist_add_group(g, node->parent); | |
4770 | 489 } |
4781 | 490 |
4777 | 491 } |
4781 | 492 |
4721 | 493 gtk_tree_path_free(path); |
4970 | 494 gaim_blist_save(); |
4704 | 495 } |
4702 | 496 } |
497 } | |
498 | |
4724 | 499 static void gaim_gtk_blist_paint_tip(GtkWidget *widget, GdkEventExpose *event, struct buddy *b) |
500 { | |
501 GtkStyle *style; | |
502 GdkPixbuf *pixbuf = gaim_gtk_blist_get_status_icon(b, GAIM_STATUS_ICON_LARGE); | |
503 PangoLayout *layout; | |
504 char *tooltiptext = gaim_get_tooltip_text(b); | |
505 | |
506 layout = gtk_widget_create_pango_layout (gtkblist->tipwindow, NULL); | |
507 pango_layout_set_markup(layout, tooltiptext, strlen(tooltiptext)); | |
4732 | 508 pango_layout_set_wrap(layout, PANGO_WRAP_WORD); |
4733 | 509 pango_layout_set_width(layout, 300000); |
4724 | 510 style = gtkblist->tipwindow->style; |
4732 | 511 |
4724 | 512 gtk_paint_flat_box (style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, |
513 NULL, gtkblist->tipwindow, "tooltip", 0, 0, -1, -1); | |
4729 | 514 |
515 #if GTK_CHECK_VERSION(2,2,0) | |
4724 | 516 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, pixbuf, |
517 0, 0, 4, 4, -1 , -1, GDK_RGB_DITHER_NONE, 0, 0); | |
4729 | 518 #else |
4758 | 519 gdk_pixbuf_render_to_drawable(pixbuf, GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, 0, 0, 4, 4, -1, -1, GDK_RGB_DITHER_NONE, 0, 0); |
4729 | 520 #endif |
4724 | 521 |
522 gtk_paint_layout (style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, TRUE, | |
523 NULL, gtkblist->tipwindow, "tooltip", 38, 4, layout); | |
524 | |
525 g_object_unref (pixbuf); | |
526 g_object_unref (layout); | |
527 g_free(tooltiptext); | |
528 return; | |
529 } | |
530 | |
531 static gboolean gaim_gtk_blist_tooltip_timeout(GtkWidget *tv) | |
532 { | |
533 GtkTreePath *path; | |
534 GtkTreeIter iter; | |
535 GaimBlistNode *node; | |
536 GValue val = {0}; | |
537 | |
538 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), gtkblist->rect.x, gtkblist->rect.y, &path, NULL, NULL, NULL)) | |
539 return FALSE; | |
540 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
541 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
542 node = g_value_get_pointer(&val); | |
543 | |
544 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
545 int scr_w,scr_h, w, h, x, y; | |
546 PangoLayout *layout; | |
547 struct buddy *buddy = (struct buddy*)node; | |
548 char *tooltiptext = gaim_get_tooltip_text(buddy); | |
549 gtkblist->tipwindow = gtk_window_new(GTK_WINDOW_POPUP); | |
4907
68e2b07ef8d7
[gaim-migrate @ 5241]
Christian Hammond <chipx86@chipx86.com>
parents:
4883
diff
changeset
|
550 gtkblist->tipwindow->parent = tv; |
4724 | 551 gtk_widget_set_app_paintable(gtkblist->tipwindow, TRUE); |
4729 | 552 gtk_window_set_resizable(GTK_WINDOW(gtkblist->tipwindow), FALSE); |
4724 | 553 gtk_widget_set_name(gtkblist->tipwindow, "gtk-tooltips"); |
554 g_signal_connect(G_OBJECT(gtkblist->tipwindow), "expose_event", | |
555 G_CALLBACK(gaim_gtk_blist_paint_tip), buddy); | |
556 gtk_widget_ensure_style (gtkblist->tipwindow); | |
557 | |
558 layout = gtk_widget_create_pango_layout (gtkblist->tipwindow, NULL); | |
4733 | 559 pango_layout_set_wrap(layout, PANGO_WRAP_WORD); |
560 pango_layout_set_width(layout, 300000); | |
4724 | 561 pango_layout_set_markup(layout, tooltiptext, strlen(tooltiptext)); |
562 scr_w = gdk_screen_width(); | |
563 scr_h = gdk_screen_height(); | |
564 pango_layout_get_size (layout, &w, &h); | |
565 w = PANGO_PIXELS(w) + 8; | |
566 h = PANGO_PIXELS(h) + 8; | |
567 | |
568 /* 38 is the size of a large status icon plus 4 pixels padding on each side. | |
569 I should #define this or something */ | |
570 w = w + 38; | |
571 h = MAX(h, 38); | |
572 | |
573 gdk_window_get_pointer(NULL, &x, &y, NULL); | |
574 if (GTK_WIDGET_NO_WINDOW(gtkblist->window)) | |
575 y+=gtkblist->window->allocation.y; | |
576 | |
577 x -= ((w >> 1) + 4); | |
578 | |
579 if ((x + w) > scr_w) | |
580 x -= (x + w) - scr_w; | |
581 else if (x < 0) | |
582 x = 0; | |
583 | |
584 if ((y + h + 4) > scr_h) | |
585 y = y - h; | |
586 else | |
587 y = y + 6; | |
588 g_object_unref (layout); | |
589 g_free(tooltiptext); | |
590 gtk_widget_set_size_request(gtkblist->tipwindow, w, h); | |
4729 | 591 gtk_window_move(GTK_WINDOW(gtkblist->tipwindow), x, y); |
4724 | 592 gtk_widget_show(gtkblist->tipwindow); |
593 } | |
4729 | 594 |
4724 | 595 gtk_tree_path_free(path); |
596 return FALSE; | |
597 } | |
598 | |
4730 | 599 static gboolean gaim_gtk_blist_motion_cb (GtkWidget *tv, GdkEventMotion *event, gpointer null) |
4724 | 600 { |
601 GtkTreePath *path; | |
602 if (gtkblist->timeout) { | |
603 if ((event->y > gtkblist->rect.y) && ((event->y - gtkblist->rect.height) < gtkblist->rect.y)) | |
4732 | 604 return FALSE; |
4724 | 605 /* We've left the cell. Remove the timeout and create a new one below */ |
606 if (gtkblist->tipwindow) { | |
607 gtk_widget_destroy(gtkblist->tipwindow); | |
608 gtkblist->tipwindow = NULL; | |
609 } | |
610 | |
611 g_source_remove(gtkblist->timeout); | |
612 } | |
613 | |
614 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL); | |
615 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, >kblist->rect); | |
616 if (path) | |
617 gtk_tree_path_free(path); | |
618 gtkblist->timeout = g_timeout_add(500, (GSourceFunc)gaim_gtk_blist_tooltip_timeout, tv); | |
4730 | 619 return FALSE; |
4724 | 620 } |
621 | |
622 static void gaim_gtk_blist_leave_cb (GtkWidget *w, GdkEventCrossing *e, gpointer n) | |
623 { | |
4978 | 624 if (gtkblist->timeout) { |
625 g_source_remove(gtkblist->timeout); | |
626 gtkblist->timeout = 0; | |
627 } | |
4724 | 628 if (gtkblist->tipwindow) { |
629 gtk_widget_destroy(gtkblist->tipwindow); | |
630 gtkblist->tipwindow = NULL; | |
631 } | |
4978 | 632 } |
4724 | 633 |
4687 | 634 /*************************************************** |
635 * Crap * | |
636 ***************************************************/ | |
637 static GtkItemFactoryEntry blist_menu[] = | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
638 { |
4687 | 639 /* Buddies menu */ |
640 { N_("/_Buddies"), NULL, NULL, 0, "<Branch>" }, | |
5024 | 641 { N_("/Buddies/New _Instant Message..."), "<CTL>I", show_im_dialog, 0, "<StockItem>", GAIM_STOCK_IM }, |
642 { N_("/Buddies/Join a _Chat..."), "<CTL>C", join_chat, 0, "<StockItem>", GAIM_STOCK_CHAT }, | |
5145 | 643 { N_("/Buddies/Get _User Info..."), "<CTL>J", show_info_dialog, 0, "<StockItem>", GAIM_STOCK_INFO }, |
4834 | 644 { "/Buddies/sep1", NULL, NULL, 0, "<Separator>" }, |
4983 | 645 { N_("/Buddies/_Show Offline Buddies"), NULL, gaim_gtk_blist_edit_mode_cb, 1, "<CheckItem>"}, |
5000 | 646 { N_("/Buddies/Show _Empty Groups"), NULL, gaim_gtk_blist_show_empty_groups_cb, 1, "<CheckItem>"}, |
4983 | 647 { N_("/Buddies/_Add a Buddy..."), NULL, gaim_gtk_blist_add_buddy_cb, 0, "<StockItem>", GTK_STOCK_ADD }, |
648 { N_("/Buddies/Add a _Group..."), NULL, show_add_group, 0, NULL}, | |
5024 | 649 { "/Buddies/sep2", NULL, NULL, 0, "<Separator>" }, |
650 { N_("/Buddies/_Signoff"), "<CTL>D", signoff_all, 0, "<StockItem>", GAIM_STOCK_SIGN_OFF }, | |
651 { N_("/Buddies/_Quit"), "<CTL>Q", do_quit, 0, "<StockItem>", GTK_STOCK_QUIT }, | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
652 |
4687 | 653 /* Tools */ |
654 { N_("/_Tools"), NULL, NULL, 0, "<Branch>" }, | |
655 { N_("/Tools/_Away"), NULL, NULL, 0, "<Branch>" }, | |
656 { N_("/Tools/Buddy _Pounce"), NULL, NULL, 0, "<Branch>" }, | |
5024 | 657 { N_("/Tools/P_rotocol Actions"), NULL, NULL, 0, "<Branch>" }, |
658 { "/Tools/sep1", NULL, NULL, 0, "<Separator>" }, | |
5053 | 659 { N_("/Tools/A_ccounts..."), "<CTL>A", account_editor, 0, "<StockItem>", GAIM_STOCK_ACCOUNTS }, |
5024 | 660 { N_("/Tools/_File Transfers..."), NULL, gaim_show_xfer_dialog, 0, "<StockItem>", GAIM_STOCK_FILE_TRANSFER }, |
661 { N_("/Tools/Preferences..."), "<CTL>P", show_prefs, 0, "<StockItem>", GTK_STOCK_PREFERENCES }, | |
662 { N_("/Tools/Pr_ivacy..."), NULL, show_privacy_options, 0, "<StockItem>", GAIM_STOCK_PRIVACY }, | |
4834 | 663 { "/Tools/sep2", NULL, NULL, 0, "<Separator>" }, |
5024 | 664 { N_("/Tools/View System _Log..."), NULL, gtk_blist_show_systemlog_cb, 0, NULL }, |
3251 | 665 |
4687 | 666 /* Help */ |
667 { N_("/_Help"), NULL, NULL, 0, "<Branch>" }, | |
5024 | 668 { N_("/Help/Online _Help"), "F1", gtk_blist_show_onlinehelp_cb, 0, "<StockItem>", GTK_STOCK_HELP }, |
669 { N_("/Help/_Debug Window..."), NULL, toggle_debug, 0, NULL }, | |
670 { N_("/Help/_About..."), NULL, show_about, 0, "<StockItem>", GAIM_STOCK_ABOUT }, | |
4687 | 671 }; |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
672 |
4687 | 673 /********************************************************* |
674 * Private Utility functions * | |
675 *********************************************************/ | |
676 | |
4724 | 677 static char *gaim_get_tooltip_text(struct buddy *b) |
678 { | |
679 char *text = NULL; | |
680 struct prpl* prpl = find_prpl(b->account->protocol); | |
681 char *statustext = NULL; | |
4867 | 682 char *aliastext = NULL, *nicktext = NULL; |
4724 | 683 char *warning = NULL, *idletime = NULL; |
684 | |
685 if (prpl->tooltip_text) { | |
4815 | 686 const char *end; |
4732 | 687 statustext = prpl->tooltip_text(b); |
4815 | 688 |
689 if(statustext && !g_utf8_validate(statustext, -1, &end)) { | |
690 char *new = g_strndup(statustext, | |
691 g_utf8_pointer_to_offset(statustext, end)); | |
692 g_free(statustext); | |
693 statustext = new; | |
694 } | |
4724 | 695 } |
4732 | 696 |
5131 | 697 if (!statustext && !GAIM_BUDDY_IS_ONLINE(b)) |
698 statustext = g_strdup(_("<b>Status:</b> Offline")); | |
699 | |
5002 | 700 if (b->idle > 0) { |
4724 | 701 int ihrs, imin; |
702 time_t t; | |
703 time(&t); | |
704 ihrs = (t - b->idle) / 3600; | |
705 imin = ((t - b->idle) / 60) % 60; | |
706 if (ihrs) | |
4744 | 707 idletime = g_strdup_printf(_("%dh%02dm"), ihrs, imin); |
4724 | 708 else |
4744 | 709 idletime = g_strdup_printf(_("%dm"), imin); |
4724 | 710 } |
4732 | 711 |
4945 | 712 if(b->alias && b->alias[0]) |
4867 | 713 aliastext = g_markup_escape_text(b->alias, -1); |
714 | |
715 if(b->server_alias) | |
716 nicktext = g_markup_escape_text(b->server_alias, -1); | |
717 | |
4724 | 718 if (b->evil > 0) |
4744 | 719 warning = g_strdup_printf(_("%d%%"), b->evil); |
4732 | 720 |
4724 | 721 text = g_strdup_printf("<span size='larger' weight='bold'>%s</span>" |
4744 | 722 "%s %s" /* Alias */ |
723 "%s %s" /* Nickname */ | |
724 "%s %s" /* Idle */ | |
725 "%s %s" /* Warning */ | |
4968 | 726 "%s%s" /* Status */ |
727 "%s", | |
4724 | 728 b->name, |
4867 | 729 aliastext ? _("\n<b>Alias:</b>") : "", aliastext ? aliastext : "", |
730 nicktext ? _("\n<b>Nickname:</b>") : "", nicktext ? nicktext : "", | |
5002 | 731 idletime ? _("\n<b>Idle:</b>") : "", idletime ? idletime : "", |
4744 | 732 b->evil ? _("\n<b>Warned:</b>") : "", b->evil ? warning : "", |
4968 | 733 statustext ? "\n" : "", statustext ? statustext : "", |
5116 | 734 !g_ascii_strcasecmp(b->name, "robflynn") ? _("\n<b>Description:</b> Spooky") : ""); |
4968 | 735 |
4737 | 736 if(warning) |
737 g_free(warning); | |
738 if(idletime) | |
739 g_free(idletime); | |
740 if(statustext) | |
741 g_free(statustext); | |
4867 | 742 if(nicktext) |
743 g_free(nicktext); | |
744 if(aliastext) | |
745 g_free(aliastext); | |
4737 | 746 |
4724 | 747 return text; |
748 | |
749 } | |
750 | |
5168 | 751 GdkPixbuf *gaim_gtk_blist_get_status_icon(struct buddy *b, GaimStatusIconSize size) |
4687 | 752 { |
753 GdkPixbuf *status = NULL; | |
754 GdkPixbuf *scale = NULL; | |
755 GdkPixbuf *emblem = NULL; | |
4737 | 756 gchar *filename = NULL; |
4687 | 757 const char *protoname = NULL; |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
758 |
4691 | 759 char *se = NULL, *sw = NULL ,*nw = NULL ,*ne = NULL; |
4737 | 760 |
4687 | 761 int scalesize = 30; |
762 | |
763 struct prpl* prpl = find_prpl(b->account->protocol); | |
4916 | 764 |
765 if (!prpl) | |
766 return NULL; | |
767 | |
4687 | 768 if (prpl->list_icon) |
769 protoname = prpl->list_icon(b->account, b); | |
5068 | 770 if (b->present != GAIM_BUDDY_SIGNING_OFF && prpl->list_emblems) |
4687 | 771 prpl->list_emblems(b, &se, &sw, &nw, &ne); |
5068 | 772 |
4724 | 773 if (size == GAIM_STATUS_ICON_SMALL) { |
4687 | 774 scalesize = 15; |
775 sw = nw = ne = NULL; /* So that only the se icon will composite */ | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
776 } |
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
777 |
4701 | 778 |
5068 | 779 if (b->present == GAIM_BUDDY_SIGNING_ON) { |
4687 | 780 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "login.png", NULL); |
781 status = gdk_pixbuf_new_from_file(filename,NULL); | |
782 g_free(filename); | |
5068 | 783 } else if (b->present == GAIM_BUDDY_SIGNING_OFF) { |
784 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "logout.png", NULL); | |
785 status = gdk_pixbuf_new_from_file(filename,NULL); | |
786 g_free(filename); | |
4701 | 787 |
4737 | 788 /* "Hey, what's all this crap?" you ask. Status icons will be themeable too, and |
4687 | 789 then it will look up protoname from the theme */ |
790 } else { | |
791 char *image = g_strdup_printf("%s.png", protoname); | |
792 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
793 status = gdk_pixbuf_new_from_file(filename,NULL); | |
794 g_free(image); | |
795 g_free(filename); | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
796 |
4687 | 797 } |
4737 | 798 |
4687 | 799 if (!status) |
800 return NULL; | |
4737 | 801 |
4687 | 802 scale = gdk_pixbuf_scale_simple(status, scalesize, scalesize, GDK_INTERP_BILINEAR); |
4737 | 803 |
804 g_object_unref(G_OBJECT(status)); | |
805 | |
4687 | 806 /* Emblems */ |
4737 | 807 |
4687 | 808 /* Each protocol can specify up to four "emblems" to composite over the base icon. "away", "busy", "mobile user" |
809 * are all examples of states represented by emblems. I'm not even really sure I like this yet. */ | |
4737 | 810 |
4687 | 811 /* XXX Clean this crap up, yo. */ |
812 if (se) { | |
813 char *image = g_strdup_printf("%s.png", se); | |
814 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
815 g_free(image); | |
816 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
817 g_free(filename); | |
818 if (emblem) { | |
4724 | 819 if (size == GAIM_STATUS_ICON_LARGE) |
4687 | 820 gdk_pixbuf_composite (emblem, |
821 scale, 15, 15, | |
822 15, 15, | |
823 15, 15, | |
824 1, 1, | |
825 GDK_INTERP_BILINEAR, | |
826 255); | |
827 else | |
828 gdk_pixbuf_composite (emblem, | |
5017 | 829 scale, 5, 5, |
830 10, 10, | |
831 5, 5, | |
832 .6, .6, | |
4687 | 833 GDK_INTERP_BILINEAR, |
834 255); | |
4737 | 835 g_object_unref(G_OBJECT(emblem)); |
4687 | 836 } |
837 } | |
838 if (sw) { | |
839 char *image = g_strdup_printf("%s.png", sw); | |
840 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
841 g_free(image); | |
842 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
843 g_free(filename); | |
844 if (emblem) { | |
4737 | 845 gdk_pixbuf_composite (emblem, |
846 scale, 0, 15, | |
847 15, 15, | |
848 0, 15, | |
849 1, 1, | |
850 GDK_INTERP_BILINEAR, | |
851 255); | |
852 g_object_unref(G_OBJECT(emblem)); | |
4687 | 853 } |
854 } | |
855 if (nw) { | |
856 char *image = g_strdup_printf("%s.png", nw); | |
857 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
858 g_free(image); | |
859 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
860 g_free(filename); | |
861 if (emblem) { | |
862 gdk_pixbuf_composite (emblem, | |
863 scale, 0, 0, | |
864 15, 15, | |
865 0, 0, | |
866 1, 1, | |
867 GDK_INTERP_BILINEAR, | |
868 255); | |
4737 | 869 g_object_unref(G_OBJECT(emblem)); |
4687 | 870 } |
871 } | |
872 if (ne) { | |
873 char *image = g_strdup_printf("%s.png", ne); | |
874 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
875 g_free(image); | |
876 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
877 g_free(filename); | |
878 if (emblem) { | |
879 gdk_pixbuf_composite (emblem, | |
880 scale, 15, 0, | |
881 15, 15, | |
882 15, 0, | |
883 1, 1, | |
884 GDK_INTERP_BILINEAR, | |
885 255); | |
4954 | 886 g_object_unref(G_OBJECT(emblem)); |
4687 | 887 } |
4737 | 888 } |
4687 | 889 |
4737 | 890 |
4718 | 891 /* Idle grey buddies affects the whole row. This converts the status icon to greyscale. */ |
5068 | 892 if (b->present == GAIM_BUDDY_OFFLINE) |
4928 | 893 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE); |
894 else if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS) | |
895 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.25, FALSE); | |
4687 | 896 return scale; |
1 | 897 } |
898 | |
4737 | 899 static GdkPixbuf *gaim_gtk_blist_get_buddy_icon(struct buddy *b) |
1 | 900 { |
4687 | 901 /* This just opens a file from ~/.gaim/icons/screenname. This needs to change to be more gooder. */ |
4737 | 902 char *file; |
903 GdkPixbuf *buf, *ret; | |
904 | |
4687 | 905 if (!(blist_options & OPT_BLIST_SHOW_ICONS)) |
906 return NULL; | |
4737 | 907 |
4757 | 908 if ((file = gaim_buddy_get_setting(b, "buddy_icon")) == NULL) |
909 return NULL; | |
910 | |
4737 | 911 buf = gdk_pixbuf_new_from_file(file, NULL); |
912 g_free(file); | |
913 | |
914 | |
4687 | 915 if (buf) { |
5068 | 916 if (!GAIM_BUDDY_IS_ONLINE(b)) |
4928 | 917 gdk_pixbuf_saturate_and_pixelate(buf, buf, 0.0, FALSE); |
918 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS) | |
919 gdk_pixbuf_saturate_and_pixelate(buf, buf, 0.25, FALSE); | |
920 | |
4737 | 921 ret = gdk_pixbuf_scale_simple(buf,30,30, GDK_INTERP_BILINEAR); |
922 g_object_unref(G_OBJECT(buf)); | |
923 return ret; | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
924 } |
4687 | 925 return NULL; |
2986 | 926 } |
927 | |
4810 | 928 static gchar *gaim_gtk_blist_get_name_markup(struct buddy *b, gboolean selected) |
1 | 929 { |
4687 | 930 char *name = gaim_get_buddy_alias(b); |
931 char *esc = g_markup_escape_text(name, strlen(name)), *text = NULL; | |
4722 | 932 struct prpl* prpl = find_prpl(b->account->protocol); |
933 | |
4687 | 934 /* XXX Clean up this crap */ |
4699 | 935 |
4687 | 936 int ihrs, imin; |
4724 | 937 char *idletime = NULL, *warning = NULL, *statustext = NULL; |
4732 | 938 time_t t; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
939 |
4687 | 940 if (!(blist_options & OPT_BLIST_SHOW_ICONS)) { |
5068 | 941 if ((b->idle && blist_options & OPT_BLIST_GREY_IDLERS && !selected) || !GAIM_BUDDY_IS_ONLINE(b)) { |
4718 | 942 text = g_strdup_printf("<span color='dim grey'>%s</span>", |
4699 | 943 esc); |
4687 | 944 g_free(esc); |
945 return text; | |
946 } else { | |
947 return esc; | |
948 } | |
1 | 949 } |
950 | |
4687 | 951 time(&t); |
952 ihrs = (t - b->idle) / 3600; | |
953 imin = ((t - b->idle) / 60) % 60; | |
4699 | 954 |
4916 | 955 if (prpl && prpl->status_text) { |
4732 | 956 char *tmp = prpl->status_text(b); |
4815 | 957 const char *end; |
958 | |
959 if(tmp && !g_utf8_validate(tmp, -1, &end)) { | |
960 char *new = g_strndup(tmp, | |
961 g_utf8_pointer_to_offset(tmp, end)); | |
962 g_free(tmp); | |
963 tmp = new; | |
964 } | |
4732 | 965 |
966 if(tmp) { | |
4855 | 967 char buf[32]; |
968 char *c = tmp; | |
969 int length = 0, vis=0; | |
970 gboolean inside = FALSE; | |
4806 | 971 g_strdelimit(tmp, "\n", ' '); |
4852
d1c17e81055e
[gaim-migrate @ 5179]
Christian Hammond <chipx86@chipx86.com>
parents:
4847
diff
changeset
|
972 |
4855 | 973 while(*c && vis < 20) { |
974 if(*c == '&') | |
975 inside = TRUE; | |
4856 | 976 else if(*c == ';') |
977 inside = FALSE; | |
4855 | 978 if(!inside) |
979 vis++; | |
980 length++; | |
981 c++; /* this is fun */ | |
982 } | |
4852
d1c17e81055e
[gaim-migrate @ 5179]
Christian Hammond <chipx86@chipx86.com>
parents:
4847
diff
changeset
|
983 |
4855 | 984 if(vis == 20) |
985 g_snprintf(buf, sizeof(buf), "%%.%ds...", length); | |
986 else | |
987 g_snprintf(buf, sizeof(buf), "%%s "); | |
4852
d1c17e81055e
[gaim-migrate @ 5179]
Christian Hammond <chipx86@chipx86.com>
parents:
4847
diff
changeset
|
988 |
4855 | 989 statustext = g_strdup_printf(buf, tmp); |
4852
d1c17e81055e
[gaim-migrate @ 5179]
Christian Hammond <chipx86@chipx86.com>
parents:
4847
diff
changeset
|
990 |
4732 | 991 g_free(tmp); |
992 } | |
4722 | 993 } |
4732 | 994 |
5002 | 995 if (b->idle > 0) { |
4687 | 996 if (ihrs) |
4757 | 997 idletime = g_strdup_printf(_("Idle (%dh%02dm) "), ihrs, imin); |
4687 | 998 else |
4757 | 999 idletime = g_strdup_printf(_("Idle (%dm) "), imin); |
4687 | 1000 } |
4757 | 1001 |
4687 | 1002 if (b->evil > 0) |
4757 | 1003 warning = g_strdup_printf(_("Warned (%d%%) "), b->evil); |
1004 | |
5135 | 1005 if(!GAIM_BUDDY_IS_ONLINE(b) && !statustext) |
1006 statustext = g_strdup("Offline "); | |
1007 | |
4810 | 1008 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS && !selected) { |
4916 | 1009 text = g_strdup_printf("<span color='dim grey'>%s</span>\n" |
5135 | 1010 "<span color='dim grey' size='smaller'>%s%s%s</span>", |
4687 | 1011 esc, |
4722 | 1012 statustext != NULL ? statustext : "", |
5135 | 1013 idletime != NULL ? idletime : "", |
1014 warning != NULL ? warning : ""); | |
5068 | 1015 } else if (statustext == NULL && idletime == NULL && warning == NULL && GAIM_BUDDY_IS_ONLINE(b)) { |
4916 | 1016 text = g_strdup(esc); |
4797 | 1017 } else { |
4916 | 1018 text = g_strdup_printf("%s\n" |
5135 | 1019 "<span %s size='smaller'>%s%s%s</span>", esc, |
4916 | 1020 selected ? "" : "color='dim grey'", |
1021 statustext != NULL ? statustext : "", | |
1022 idletime != NULL ? idletime : "", | |
5135 | 1023 warning != NULL ? warning : ""); |
4797 | 1024 } |
4722 | 1025 if (idletime) |
4687 | 1026 g_free(idletime); |
4722 | 1027 if (warning) |
4687 | 1028 g_free(warning); |
4722 | 1029 if (statustext) |
1030 g_free(statustext); | |
4737 | 1031 if (esc) |
1032 g_free(esc); | |
4699 | 1033 |
4687 | 1034 return text; |
1035 } | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
1036 |
4840 | 1037 static void gaim_gtk_blist_restore_position() |
1038 { | |
1039 /* if the window exists, is hidden, we're saving positions, and the position is sane... */ | |
1040 if(gtkblist && gtkblist->window && | |
1041 !GTK_WIDGET_VISIBLE(gtkblist->window) && | |
1042 blist_pos.width != 0) { | |
1043 /* ...check position is on screen... */ | |
1044 if (blist_pos.x >= gdk_screen_width()) | |
1045 blist_pos.x = gdk_screen_width() - 100; | |
1046 else if (blist_pos.x < 0) | |
1047 blist_pos.x = 100; | |
1048 | |
1049 if (blist_pos.y >= gdk_screen_height()) | |
1050 blist_pos.y = gdk_screen_height() - 100; | |
1051 else if (blist_pos.y < 0) | |
1052 blist_pos.y = 100; | |
1053 | |
1054 /* ...and move it back. */ | |
1055 gtk_window_move(GTK_WINDOW(gtkblist->window), blist_pos.x, blist_pos.y); | |
1056 gtk_window_resize(GTK_WINDOW(gtkblist->window), blist_pos.width, blist_pos.height); | |
1057 } | |
1058 } | |
1059 | |
4944 | 1060 static gboolean gaim_gtk_blist_refresh_timer(struct gaim_buddy_list *list) |
1061 { | |
1062 GaimBlistNode *group = list->root; | |
1063 GaimBlistNode *buddy; | |
1064 | |
1065 while (group) { | |
1066 buddy = group->child; | |
1067 while (buddy) { | |
1068 if (((struct buddy *)buddy)->idle) | |
1069 gaim_gtk_blist_update(list, buddy); | |
1070 buddy = buddy->next; | |
1071 } | |
1072 group = group->next; | |
1073 } | |
1074 | |
1075 /* keep on going */ | |
1076 return TRUE; | |
1077 } | |
4840 | 1078 |
4687 | 1079 /********************************************************************************** |
1080 * Public API Functions * | |
1081 **********************************************************************************/ | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1082 static void gaim_gtk_blist_new_list(struct gaim_buddy_list *blist) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1083 { |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1084 blist->ui_data = g_new0(struct gaim_gtk_buddy_list, 1); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1085 } |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1086 |
4729 | 1087 void gaim_gtk_blist_update_columns() |
1088 { | |
1089 if (blist_options & OPT_BLIST_SHOW_ICONS) { | |
1090 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, TRUE); | |
1091 gtk_tree_view_column_set_visible(gtkblist->idle_column, FALSE); | |
1092 gtk_tree_view_column_set_visible(gtkblist->warning_column, FALSE); | |
1093 } else { | |
1094 gtk_tree_view_column_set_visible(gtkblist->idle_column, blist_options & OPT_BLIST_SHOW_IDLETIME); | |
1095 gtk_tree_view_column_set_visible(gtkblist->warning_column, blist_options & OPT_BLIST_SHOW_WARN); | |
1096 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, FALSE); | |
1097 } | |
1098 } | |
1099 | |
4702 | 1100 enum {DRAG_BUDDY, DRAG_ROW}; |
1101 | |
4834 | 1102 static char * |
1103 item_factory_translate_func (const char *path, gpointer func_data) | |
1104 { | |
1105 return _(path); | |
1106 } | |
1107 | |
4687 | 1108 static void gaim_gtk_blist_show(struct gaim_buddy_list *list) |
1109 { | |
1110 GtkItemFactory *ift; | |
1111 GtkCellRenderer *rend; | |
1112 GtkTreeViewColumn *column; | |
1113 GtkWidget *sw; | |
1114 GtkWidget *button; | |
4694 | 1115 GtkSizeGroup *sg; |
5089 | 1116 GtkAccelGroup *accel_group; |
4810 | 1117 GtkTreeSelection *selection; |
4781 | 1118 GtkTargetEntry gte[] = {{"GAIM_BLIST_NODE", GTK_TARGET_SAME_APP, DRAG_ROW}, |
4702 | 1119 {"application/x-im-contact", 0, DRAG_BUDDY}}; |
4690 | 1120 |
4745 | 1121 if (gtkblist && gtkblist->window) { |
4687 | 1122 gtk_widget_show(gtkblist->window); |
1123 return; | |
1124 } | |
4690 | 1125 |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1126 gtkblist = GAIM_GTK_BLIST(list); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1127 |
4687 | 1128 gtkblist->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
4840 | 1129 gtk_window_set_role(GTK_WINDOW(gtkblist->window), "buddy_list"); |
4964 | 1130 gtk_window_set_title(GTK_WINDOW(gtkblist->window), _("Buddy List")); |
4690 | 1131 |
5168 | 1132 GTK_WINDOW(gtkblist->window)->allow_shrink = TRUE; |
1133 | |
4925 | 1134 gtkblist->vbox = gtk_vbox_new(FALSE, 0); |
4687 | 1135 gtk_container_add(GTK_CONTAINER(gtkblist->window), gtkblist->vbox); |
1 | 1136 |
4840 | 1137 g_signal_connect(G_OBJECT(gtkblist->window), "delete_event", G_CALLBACK(gtk_blist_delete_cb), NULL); |
1138 g_signal_connect(G_OBJECT(gtkblist->window), "configure_event", G_CALLBACK(gtk_blist_configure_cb), NULL); | |
1139 g_signal_connect(G_OBJECT(gtkblist->window), "visibility_notify_event", G_CALLBACK(gtk_blist_visibility_cb), NULL); | |
1140 gtk_widget_add_events(gtkblist->window, GDK_VISIBILITY_NOTIFY_MASK); | |
4698 | 1141 |
4687 | 1142 /******************************* Menu bar *************************************/ |
5089 | 1143 accel_group = gtk_accel_group_new(); |
1144 gtk_window_add_accel_group(GTK_WINDOW (gtkblist->window), accel_group); | |
1145 g_object_unref(accel_group); | |
1146 ift = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GaimMain>", accel_group); | |
4834 | 1147 gtk_item_factory_set_translate_func (ift, |
1148 item_factory_translate_func, | |
1149 NULL, NULL); | |
4687 | 1150 gtk_item_factory_create_items(ift, sizeof(blist_menu) / sizeof(*blist_menu), |
1151 blist_menu, NULL); | |
1152 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtk_item_factory_get_widget(ift, "<GaimMain>"), FALSE, FALSE, 0); | |
1 | 1153 |
4834 | 1154 awaymenu = gtk_item_factory_get_widget(ift, N_("/Tools/Away")); |
4694 | 1155 do_away_menu(); |
1156 | |
5032
cb700c07ee07
[gaim-migrate @ 5375]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
1157 gtkblist->bpmenu = gtk_item_factory_get_widget(ift, N_("/Tools/Buddy Pounce")); |
cb700c07ee07
[gaim-migrate @ 5375]
Christian Hammond <chipx86@chipx86.com>
parents:
5024
diff
changeset
|
1158 gaim_gtkpounce_menu_build(gtkblist->bpmenu); |
4696 | 1159 |
4834 | 1160 protomenu = gtk_item_factory_get_widget(ift, N_("/Tools/Protocol Actions")); |
4696 | 1161 do_proto_menu(); |
1162 | |
4687 | 1163 /****************************** GtkTreeView **********************************/ |
1164 sw = gtk_scrolled_window_new(NULL,NULL); | |
1165 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); | |
1166 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
1167 | |
5060 | 1168 gtkblist->treemodel = gtk_tree_store_new(BLIST_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_BOOLEAN, G_TYPE_STRING, |
4687 | 1169 G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_POINTER); |
4702 | 1170 |
4687 | 1171 gtkblist->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(gtkblist->treemodel)); |
4943 | 1172 gtk_widget_set_size_request(gtkblist->treeview, -1, 200); |
4704 | 1173 |
4810 | 1174 /* Set up selection stuff */ |
1175 | |
1176 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)); | |
1177 g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(gaim_gtk_blist_selection_changed), NULL); | |
1178 | |
1179 | |
4702 | 1180 /* Set up dnd */ |
1181 gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(gtkblist->treeview), GDK_BUTTON1_MASK, gte, | |
1182 2, GDK_ACTION_COPY); | |
4704 | 1183 gtk_tree_view_enable_model_drag_dest(GTK_TREE_VIEW(gtkblist->treeview), gte, 2, |
4702 | 1184 GDK_ACTION_COPY | GDK_ACTION_MOVE); |
4704 | 1185 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-received", G_CALLBACK(gaim_gtk_blist_drag_data_rcv_cb), NULL); |
1186 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-get", G_CALLBACK(gaim_gtk_blist_drag_data_get_cb), NULL); | |
1187 | |
4724 | 1188 /* Tooltips */ |
1189 g_signal_connect(G_OBJECT(gtkblist->treeview), "motion-notify-event", G_CALLBACK(gaim_gtk_blist_motion_cb), NULL); | |
1190 g_signal_connect(G_OBJECT(gtkblist->treeview), "leave-notify-event", G_CALLBACK(gaim_gtk_blist_leave_cb), NULL); | |
4687 | 1191 |
1192 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(gtkblist->treeview), FALSE); | |
1 | 1193 |
5060 | 1194 column = gtk_tree_view_column_new (); |
1195 | |
4687 | 1196 rend = gtk_cell_renderer_pixbuf_new(); |
5060 | 1197 gtk_tree_view_column_pack_start (column, rend, FALSE); |
1198 gtk_tree_view_column_set_attributes (column, rend, | |
1199 "pixbuf", STATUS_ICON_COLUMN, | |
1200 "visible", STATUS_ICON_VISIBLE_COLUMN, | |
1201 NULL); | |
4933 | 1202 g_object_set(rend, "xalign", 0.0, "ypad", 0, NULL); |
4706 | 1203 |
4687 | 1204 rend = gtk_cell_renderer_text_new(); |
5060 | 1205 gtk_tree_view_column_pack_start (column, rend, TRUE); |
1206 gtk_tree_view_column_set_attributes (column, rend, | |
1207 "markup", NAME_COLUMN, | |
1208 NULL); | |
1209 g_object_set(rend, "ypad", 0, "yalign", 0.5, NULL); | |
1210 | |
4687 | 1211 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); |
4706 | 1212 |
4687 | 1213 rend = gtk_cell_renderer_text_new(); |
4725 | 1214 gtkblist->warning_column = gtk_tree_view_column_new_with_attributes("Warning", rend, "markup", WARNING_COLUMN, NULL); |
1215 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->warning_column); | |
4796 | 1216 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); |
4687 | 1217 |
1218 rend = gtk_cell_renderer_text_new(); | |
4725 | 1219 gtkblist->idle_column = gtk_tree_view_column_new_with_attributes("Idle", rend, "markup", IDLE_COLUMN, NULL); |
1220 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->idle_column); | |
4796 | 1221 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); |
1 | 1222 |
4687 | 1223 rend = gtk_cell_renderer_pixbuf_new(); |
4725 | 1224 gtkblist->buddy_icon_column = gtk_tree_view_column_new_with_attributes("Buddy Icon", rend, "pixbuf", BUDDY_ICON_COLUMN, NULL); |
4796 | 1225 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); |
4725 | 1226 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->buddy_icon_column); |
4718 | 1227 |
4687 | 1228 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-activated", G_CALLBACK(gtk_blist_row_activated_cb), NULL); |
5142 | 1229 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-expanded", G_CALLBACK(gtk_blist_row_expanded_cb), NULL); |
1230 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-collapsed", G_CALLBACK(gtk_blist_row_collapsed_cb), NULL); | |
4687 | 1231 g_signal_connect(G_OBJECT(gtkblist->treeview), "button-press-event", G_CALLBACK(gtk_blist_button_press_cb), NULL); |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
1232 |
4687 | 1233 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), sw, TRUE, TRUE, 0); |
1234 gtk_container_add(GTK_CONTAINER(sw), gtkblist->treeview); | |
4725 | 1235 gaim_gtk_blist_update_columns(); |
4934 | 1236 |
4956 | 1237 /* set the Show Offline Buddies option. must be done |
1238 * after the treeview or faceprint gets mad. -Robot101 | |
1239 */ | |
5000 | 1240 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (ift, N_("/Buddies/Show Offline Buddies"))), |
4956 | 1241 blist_options & OPT_BLIST_SHOW_OFFLINE); |
5000 | 1242 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (ift, N_("/Buddies/Show Empty Groups"))), |
1243 !(blist_options & OPT_BLIST_NO_MT_GRP)); | |
4956 | 1244 |
1245 /* OK... let's show this bad boy. */ | |
1246 gaim_gtk_blist_refresh(list); | |
1247 gaim_gtk_blist_restore_position(); | |
1248 gtk_widget_show_all(gtkblist->window); | |
1249 | |
4687 | 1250 /**************************** Button Box **************************************/ |
4956 | 1251 /* add this afterwards so it doesn't force up the width of the window */ |
4694 | 1252 |
5018 | 1253 gtkblist->tooltips = gtk_tooltips_new(); |
4973 | 1254 |
4694 | 1255 sg = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); |
4687 | 1256 gtkblist->bbox = gtk_hbox_new(TRUE, 0); |
1257 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtkblist->bbox, FALSE, FALSE, 0); | |
4956 | 1258 gtk_widget_show(gtkblist->bbox); |
1259 | |
4687 | 1260 button = gaim_pixbuf_button_from_stock(_("IM"), GAIM_STOCK_IM, GAIM_BUTTON_VERTICAL); |
1261 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
1262 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 1263 gtk_size_group_add_widget(sg, button); |
4692 | 1264 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_im_cb), |
4697 | 1265 gtkblist->treeview); |
5018 | 1266 gtk_tooltips_set_tip(GTK_TOOLTIPS(gtkblist->tooltips), button, _("Send a message to the selected buddy"), NULL); |
4956 | 1267 gtk_widget_show(button); |
1268 | |
4687 | 1269 button = gaim_pixbuf_button_from_stock(_("Get Info"), GAIM_STOCK_INFO, GAIM_BUTTON_VERTICAL); |
1270 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
1271 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 1272 gtk_size_group_add_widget(sg, button); |
1273 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_info_cb), | |
4697 | 1274 gtkblist->treeview); |
5018 | 1275 gtk_tooltips_set_tip(GTK_TOOLTIPS(gtkblist->tooltips), button, _("Get information on the selected buddy"), NULL); |
4956 | 1276 gtk_widget_show(button); |
4729 | 1277 |
4687 | 1278 button = gaim_pixbuf_button_from_stock(_("Chat"), GAIM_STOCK_CHAT, GAIM_BUTTON_VERTICAL); |
1279 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
1280 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 1281 gtk_size_group_add_widget(sg, button); |
1282 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_chat_cb), NULL); | |
5018 | 1283 gtk_tooltips_set_tip(GTK_TOOLTIPS(gtkblist->tooltips), button, _("Join a chat room"), NULL); |
4956 | 1284 gtk_widget_show(button); |
4694 | 1285 |
5024 | 1286 button = gaim_pixbuf_button_from_stock(_("Away"), GAIM_STOCK_ICON_AWAY, GAIM_BUTTON_VERTICAL); |
4687 | 1287 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); |
1288 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 1289 gtk_size_group_add_widget(sg, button); |
1290 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_away_cb), NULL); | |
5018 | 1291 gtk_tooltips_set_tip(GTK_TOOLTIPS(gtkblist->tooltips), button, _("Set an away message"), NULL); |
4956 | 1292 gtk_widget_show(button); |
4687 | 1293 |
4956 | 1294 /* this will show the right image/label widgets for us */ |
4944 | 1295 gaim_gtk_blist_update_toolbar(); |
1296 | |
4956 | 1297 /* start the refresh timer */ |
4944 | 1298 gtkblist->refresh_timer = g_timeout_add(30000, (GSourceFunc)gaim_gtk_blist_refresh_timer, list); |
4687 | 1299 } |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
1300 |
4687 | 1301 void gaim_gtk_blist_refresh(struct gaim_buddy_list *list) |
1302 { | |
1303 GaimBlistNode *group = list->root; | |
1304 GaimBlistNode *buddy; | |
4690 | 1305 |
4687 | 1306 while (group) { |
4916 | 1307 buddy = group->child; |
4687 | 1308 gaim_gtk_blist_update(list, group); |
1309 while (buddy) { | |
4699 | 1310 gaim_gtk_blist_update(list, buddy); |
4687 | 1311 buddy = buddy->next; |
1312 } | |
1313 group = group->next; | |
1314 } | |
1315 } | |
1 | 1316 |
4699 | 1317 static gboolean get_iter_from_node_helper(GaimBlistNode *node, GtkTreeIter *iter, GtkTreeIter *root) { |
4867 | 1318 |
4699 | 1319 do { |
1320 GaimBlistNode *n; | |
1321 GtkTreeIter child; | |
1322 | |
1323 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), root, NODE_COLUMN, &n, -1); | |
1324 if(n == node) { | |
1325 *iter = *root; | |
1326 return TRUE; | |
1327 } | |
1328 | |
1329 if(gtk_tree_model_iter_children(GTK_TREE_MODEL(gtkblist->treemodel), &child, root)) { | |
1330 if(get_iter_from_node_helper(node,iter,&child)) | |
1331 return TRUE; | |
1332 } | |
1333 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(gtkblist->treemodel), root)); | |
1334 | |
1335 return FALSE; | |
1336 } | |
1337 | |
1338 static gboolean get_iter_from_node(GaimBlistNode *node, GtkTreeIter *iter) { | |
1339 GtkTreeIter root; | |
1340 | |
1341 if (!gtkblist) | |
1342 return FALSE; | |
1343 | |
1344 if(!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(gtkblist->treemodel), &root)) | |
1345 return FALSE; | |
1346 | |
1347 return get_iter_from_node_helper(node, iter, &root); | |
1348 } | |
1349 | |
4944 | 1350 /* |
1351 * These state assignments suck. I'm sorry. They're for historical reasons. | |
1352 * Roll on new prefs. -Robot101 | |
1353 * | |
1354 * NO_BUTTON_TEXT && SHOW_BUTTON_XPM - image | |
1355 * !NO_BUTTON_TEXT && !SHOW_BUTTON_XPM - text | |
1356 * !NO_BUTTON_TEXT && SHOW_BUTTON_XPM - text & images | |
1357 * NO_BUTTON_TEXT && !SHOW_BUTTON_XPM - none | |
1358 */ | |
1359 | |
1360 static void gaim_gtk_blist_update_toolbar_icons (GtkWidget *widget, gpointer data) { | |
1361 if (GTK_IS_IMAGE(widget)) { | |
1362 if (blist_options & OPT_BLIST_SHOW_BUTTON_XPM) | |
1363 gtk_widget_show(widget); | |
1364 else | |
1365 gtk_widget_hide(widget); | |
1366 } else if (GTK_IS_LABEL(widget)) { | |
1367 if (blist_options & OPT_BLIST_NO_BUTTON_TEXT) | |
1368 gtk_widget_hide(widget); | |
1369 else | |
1370 gtk_widget_show(widget); | |
1371 } else if (GTK_IS_CONTAINER(widget)) { | |
1372 gtk_container_foreach(GTK_CONTAINER(widget), gaim_gtk_blist_update_toolbar_icons, NULL); | |
1373 } | |
1374 } | |
1375 | |
4697 | 1376 void gaim_gtk_blist_update_toolbar() { |
1377 if (!gtkblist) | |
1378 return; | |
4699 | 1379 |
4944 | 1380 if (blist_options & OPT_BLIST_NO_BUTTON_TEXT && !(blist_options & OPT_BLIST_SHOW_BUTTON_XPM)) |
4697 | 1381 gtk_widget_hide(gtkblist->bbox); |
4944 | 1382 else { |
1383 gtk_container_foreach(GTK_CONTAINER(gtkblist->bbox), gaim_gtk_blist_update_toolbar_icons, NULL); | |
4956 | 1384 gtk_widget_show(gtkblist->bbox); |
4944 | 1385 } |
4697 | 1386 } |
1387 | |
4701 | 1388 static void gaim_gtk_blist_remove(struct gaim_buddy_list *list, GaimBlistNode *node) |
1389 { | |
1390 GtkTreeIter iter; | |
1391 | |
4912 | 1392 /* For some reason, we're called before we have a buddy list sometimes */ |
1393 if(!gtkblist) | |
1394 return; | |
1395 | |
4831 | 1396 if(gtkblist->selected_node == node) |
1397 gtkblist->selected_node = NULL; | |
1398 | |
4701 | 1399 if (get_iter_from_node(node, &iter)) { |
1400 gtk_tree_store_remove(gtkblist->treemodel, &iter); | |
5041 | 1401 if(GAIM_BLIST_NODE_IS_BUDDY(node)) { |
1402 gaim_gtk_blist_update(list, node->parent); | |
4701 | 1403 } |
1404 } | |
1405 } | |
1406 | |
4810 | 1407 static gboolean do_selection_changed(GaimBlistNode *new_selection) |
1408 { | |
1409 GaimBlistNode *old_selection = gtkblist->selected_node; | |
1410 | |
1411 if(new_selection != gtkblist->selected_node) { | |
1412 gtkblist->selected_node = new_selection; | |
1413 if(new_selection) | |
1414 gaim_gtk_blist_update(NULL, new_selection); | |
1415 if(old_selection) | |
1416 gaim_gtk_blist_update(NULL, old_selection); | |
1417 } | |
1418 | |
1419 return FALSE; | |
1420 } | |
1421 | |
1422 static void gaim_gtk_blist_selection_changed(GtkTreeSelection *selection, gpointer data) | |
1423 { | |
1424 GaimBlistNode *new_selection = NULL; | |
1425 GtkTreeIter iter; | |
1426 | |
1427 if(gtk_tree_selection_get_selected(selection, NULL, &iter)){ | |
1428 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, | |
1429 NODE_COLUMN, &new_selection, -1); | |
1430 } | |
1431 /* we set this up as a timeout, otherwise the blist flickers */ | |
1432 g_timeout_add(0, (GSourceFunc)do_selection_changed, new_selection); | |
1433 } | |
1434 | |
4936 | 1435 static void make_a_group(GaimBlistNode *node, GtkTreeIter *iter) { |
1436 GaimBlistNode *sibling; | |
1437 GtkTreeIter siblingiter; | |
4980 | 1438 struct group *group = (struct group *)node; |
1439 char *esc = g_markup_escape_text(group->name, -1); | |
1440 char *mark; | |
1441 | |
1442 if(blist_options & OPT_BLIST_SHOW_GRPNUM) | |
1443 mark = g_strdup_printf("<span weight='bold'>%s</span> (%d/%d)", esc, gaim_blist_get_group_online_count(group), gaim_blist_get_group_size(group, FALSE)); | |
1444 else | |
1445 mark = g_strdup_printf("<span weight='bold'>%s</span>", esc); | |
1446 | |
4936 | 1447 g_free(esc); |
4980 | 1448 |
4936 | 1449 sibling = node->prev; |
1450 while (sibling && !get_iter_from_node(sibling, &siblingiter)) { | |
1451 sibling = sibling->prev; | |
1452 } | |
1453 | |
1454 gtk_tree_store_insert_after(gtkblist->treemodel, iter, NULL, | |
1455 sibling ? &siblingiter : NULL); | |
1456 gtk_tree_store_set(gtkblist->treemodel, iter, | |
5060 | 1457 STATUS_ICON_COLUMN, NULL, |
1458 STATUS_ICON_VISIBLE_COLUMN, FALSE, | |
4936 | 1459 NAME_COLUMN, mark, |
1460 NODE_COLUMN, node, | |
1461 -1); | |
1462 g_free(mark); | |
1463 } | |
1464 | |
4701 | 1465 |
4687 | 1466 static void gaim_gtk_blist_update(struct gaim_buddy_list *list, GaimBlistNode *node) |
1467 { | |
4699 | 1468 GtkTreeIter iter; |
4936 | 1469 GtkTreePath *expand = NULL; |
4699 | 1470 gboolean new_entry = FALSE; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
1471 |
4687 | 1472 if (!gtkblist) |
1473 return; | |
4699 | 1474 |
1475 if (!get_iter_from_node(node, &iter)) { /* This is a newly added node */ | |
1476 new_entry = TRUE; | |
4687 | 1477 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { |
5068 | 1478 if (((struct buddy*)node)->present != GAIM_BUDDY_OFFLINE || ((blist_options & OPT_BLIST_SHOW_OFFLINE) && ((struct buddy*)node)->account->gc)) { |
4699 | 1479 GtkTreeIter groupiter; |
1480 GaimBlistNode *oldersibling; | |
1481 GtkTreeIter oldersiblingiter; | |
5142 | 1482 char *collapsed = gaim_group_get_setting((struct group *)node->parent, "collapsed"); |
4690 | 1483 |
4936 | 1484 if(node->parent && |
1485 !get_iter_from_node(node->parent, &groupiter)) { | |
1486 /* This buddy's group has not yet been added. | |
1487 * We do that here */ | |
1488 make_a_group(node->parent, &groupiter); | |
5000 | 1489 } |
5142 | 1490 if(!collapsed) |
4936 | 1491 expand = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &groupiter); |
5142 | 1492 else |
1493 g_free(collapsed); | |
4810 | 1494 |
4699 | 1495 oldersibling = node->prev; |
4867 | 1496 while (oldersibling && !get_iter_from_node(oldersibling, &oldersiblingiter)) { |
4699 | 1497 oldersibling = oldersibling->prev; |
4867 | 1498 } |
4699 | 1499 |
1500 gtk_tree_store_insert_after(gtkblist->treemodel, &iter, &groupiter, oldersibling ? &oldersiblingiter : NULL); | |
4810 | 1501 |
4767 | 1502 if (blist_options & OPT_BLIST_POPUP) |
1503 gtk_window_present(GTK_WINDOW(gtkblist->window)); | |
4699 | 1504 |
1505 } | |
1506 } | |
5000 | 1507 else if (GAIM_BLIST_NODE_IS_GROUP(node) && |
1508 ((blist_options & OPT_BLIST_SHOW_OFFLINE) || | |
1509 !(blist_options & OPT_BLIST_NO_MT_GRP))) { | |
4936 | 1510 make_a_group(node, &iter); |
1511 expand = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &iter); | |
4916 | 1512 } |
1513 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
5000 | 1514 if((blist_options & OPT_BLIST_NO_MT_GRP) && !(blist_options & OPT_BLIST_SHOW_OFFLINE) && !gaim_blist_get_group_online_count((struct group *)node)) { |
4916 | 1515 gtk_tree_store_remove(gtkblist->treemodel, &iter); |
4936 | 1516 } else { |
4980 | 1517 struct group *group = (struct group *)node; |
1518 char *esc = g_markup_escape_text(group->name, -1); | |
1519 char *mark; | |
1520 | |
1521 if(blist_options & OPT_BLIST_SHOW_GRPNUM) | |
1522 mark = g_strdup_printf("<span weight='bold'>%s</span> (%d/%d)", esc, gaim_blist_get_group_online_count(group), gaim_blist_get_group_size(group, FALSE)); | |
1523 else | |
1524 mark = g_strdup_printf("<span weight='bold'>%s</span>", esc); | |
1525 | |
4916 | 1526 g_free(esc); |
1527 gtk_tree_store_set(gtkblist->treemodel, &iter, | |
4936 | 1528 NAME_COLUMN, mark, |
1529 -1); | |
4916 | 1530 g_free(mark); |
1531 } | |
4699 | 1532 } |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1533 |
5068 | 1534 if (GAIM_BLIST_NODE_IS_BUDDY(node) && (((struct buddy*)node)->present != GAIM_BUDDY_OFFLINE || ((blist_options & OPT_BLIST_SHOW_OFFLINE) && ((struct buddy*)node)->account->gc))) { |
4687 | 1535 GdkPixbuf *status, *avatar; |
1536 char *mark; | |
4697 | 1537 char *warning = NULL, *idle = NULL; |
1538 | |
4810 | 1539 gboolean selected = (gtkblist->selected_node == node); |
1540 | |
1541 status = gaim_gtk_blist_get_status_icon((struct buddy*)node, | |
4724 | 1542 blist_options & OPT_BLIST_SHOW_ICONS ? GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL); |
4687 | 1543 avatar = gaim_gtk_blist_get_buddy_icon((struct buddy*)node); |
4810 | 1544 mark = gaim_gtk_blist_get_name_markup((struct buddy*)node, selected); |
4697 | 1545 |
4725 | 1546 if (((struct buddy*)node)->idle > 0) { |
4697 | 1547 time_t t; |
1548 int ihrs, imin; | |
1549 time(&t); | |
1550 ihrs = (t - ((struct buddy *)node)->idle) / 3600; | |
1551 imin = ((t - ((struct buddy*)node)->idle) / 60) % 60; | |
4718 | 1552 if(ihrs > 0) |
1553 idle = g_strdup_printf("(%d:%02d)", ihrs, imin); | |
1554 else | |
1555 idle = g_strdup_printf("(%d)", imin); | |
4697 | 1556 } |
1557 | |
4725 | 1558 if (((struct buddy*)node)->evil > 0) |
4699 | 1559 warning = g_strdup_printf("%d%%", ((struct buddy*)node)->evil); |
4810 | 1560 |
4697 | 1561 |
4718 | 1562 if((blist_options & OPT_BLIST_GREY_IDLERS) |
1563 && ((struct buddy *)node)->idle) { | |
4810 | 1564 if(warning && !selected) { |
4718 | 1565 char *w2 = g_strdup_printf("<span color='dim grey'>%s</span>", |
1566 warning); | |
1567 g_free(warning); | |
1568 warning = w2; | |
1569 } | |
1570 | |
4810 | 1571 if(idle && !selected) { |
4718 | 1572 char *i2 = g_strdup_printf("<span color='dim grey'>%s</span>", |
1573 idle); | |
1574 g_free(idle); | |
1575 idle = i2; | |
1576 } | |
1577 } | |
1578 | |
4699 | 1579 gtk_tree_store_set(gtkblist->treemodel, &iter, |
4687 | 1580 STATUS_ICON_COLUMN, status, |
5060 | 1581 STATUS_ICON_VISIBLE_COLUMN, TRUE, |
4687 | 1582 NAME_COLUMN, mark, |
4697 | 1583 WARNING_COLUMN, warning, |
1584 IDLE_COLUMN, idle, | |
4699 | 1585 BUDDY_ICON_COLUMN, avatar, |
4687 | 1586 NODE_COLUMN, node, |
1587 -1); | |
4699 | 1588 |
4687 | 1589 g_free(mark); |
4697 | 1590 if (idle) |
1591 g_free(idle); | |
1592 if (warning) | |
1593 g_free(warning); | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1594 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1595 if (status != NULL) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1596 g_object_unref(status); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1597 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1598 if (avatar != NULL) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1599 g_object_unref(avatar); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1600 |
4701 | 1601 } else if (GAIM_BLIST_NODE_IS_BUDDY(node) && !new_entry) { |
1602 gaim_gtk_blist_remove(list, node); | |
4767 | 1603 if (blist_options & OPT_BLIST_POPUP) |
1604 gtk_window_present(GTK_WINDOW(gtkblist->window)); | |
4687 | 1605 } |
4980 | 1606 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(gtkblist->treeview)); |
4936 | 1607 |
4974 | 1608 |
4936 | 1609 if(expand) { |
1610 gtk_tree_view_expand_row(GTK_TREE_VIEW(gtkblist->treeview), expand, TRUE); | |
1611 gtk_tree_path_free(expand); | |
1612 } | |
4980 | 1613 |
1614 if(GAIM_BLIST_NODE_IS_BUDDY(node)) | |
1615 gaim_gtk_blist_update(list, node->parent); | |
4687 | 1616 } |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
1617 |
4687 | 1618 static void gaim_gtk_blist_destroy(struct gaim_buddy_list *list) |
1619 { | |
4770 | 1620 if (!gtkblist) |
1621 return; | |
4944 | 1622 |
4687 | 1623 gtk_widget_destroy(gtkblist->window); |
5018 | 1624 gtk_object_sink(GTK_OBJECT(gtkblist->tooltips)); |
4745 | 1625 |
4944 | 1626 if (gtkblist->refresh_timer) |
1627 g_source_remove(gtkblist->refresh_timer); | |
1628 if (gtkblist->timeout) | |
1629 g_source_remove(gtkblist->timeout); | |
1630 | |
1631 gtkblist->refresh_timer = 0; | |
1632 gtkblist->timeout = 0; | |
4745 | 1633 gtkblist->window = gtkblist->vbox = gtkblist->treeview = NULL; |
1634 gtkblist->treemodel = NULL; | |
1635 gtkblist->idle_column = NULL; | |
1636 gtkblist->warning_column = gtkblist->buddy_icon_column = NULL; | |
1637 gtkblist->bbox = gtkblist->tipwindow = NULL; | |
1638 protomenu = NULL; | |
1639 awaymenu = NULL; | |
4687 | 1640 } |
1 | 1641 |
4687 | 1642 static void gaim_gtk_blist_set_visible(struct gaim_buddy_list *list, gboolean show) |
1643 { | |
4840 | 1644 if (!(gtkblist && gtkblist->window)) |
1645 return; | |
1646 | |
4698 | 1647 if (show) { |
4840 | 1648 gaim_gtk_blist_restore_position(); |
4699 | 1649 gtk_window_present(GTK_WINDOW(gtkblist->window)); |
4698 | 1650 } else { |
1651 if (!connections || docklet_count) { | |
1652 #ifdef _WIN32 | |
4711
0c1f3e651d3e
[gaim-migrate @ 5022]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4706
diff
changeset
|
1653 wgaim_systray_minimize(gtkblist->window); |
4698 | 1654 #endif |
1655 gtk_widget_hide(gtkblist->window); | |
1656 } else { | |
1657 gtk_window_iconify(GTK_WINDOW(gtkblist->window)); | |
1658 } | |
1659 } | |
1660 } | |
1661 | |
1662 void gaim_gtk_blist_docklet_toggle() { | |
1663 /* Useful for the docklet plugin and also for the win32 tray icon*/ | |
1664 /* This is called when one of those is clicked--it will show/hide the | |
1665 buddy list/login window--depending on which is active */ | |
4840 | 1666 if (connections) { |
1667 if (gtkblist && gtkblist->window) { | |
1668 if (GTK_WIDGET_VISIBLE(gtkblist->window)) { | |
1669 gaim_blist_set_visible(GAIM_WINDOW_ICONIFIED(gtkblist->window) || gaim_gtk_blist_obscured); | |
1670 } else { | |
4698 | 1671 #if _WIN32 |
4840 | 1672 wgaim_systray_maximize(gtkblist->window); |
4698 | 1673 #endif |
4840 | 1674 gaim_blist_set_visible(TRUE); |
1675 } | |
1676 } else { | |
1677 /* we're logging in or something... do nothing */ | |
1678 /* or should I make the blist? */ | |
1679 debug_printf("docklet_toggle called with connections but no blist!\n"); | |
4698 | 1680 } |
4840 | 1681 } else if (mainwindow) { |
1682 if (GTK_WIDGET_VISIBLE(mainwindow)) { | |
4698 | 1683 if (GAIM_WINDOW_ICONIFIED(mainwindow)) { |
1684 gtk_window_present(GTK_WINDOW(mainwindow)); | |
1685 } else { | |
1686 #if _WIN32 | |
1687 wgaim_systray_minimize(mainwindow); | |
1688 #endif | |
1689 gtk_widget_hide(mainwindow); | |
1690 } | |
1691 } else { | |
1692 #if _WIN32 | |
1693 wgaim_systray_maximize(mainwindow); | |
1694 #endif | |
4833 | 1695 show_login(); |
4698 | 1696 } |
4840 | 1697 } else { |
1698 show_login(); | |
4698 | 1699 } |
1700 } | |
1701 | |
1702 void gaim_gtk_blist_docklet_add() | |
1703 { | |
1704 docklet_count++; | |
1705 } | |
1706 | |
1707 void gaim_gtk_blist_docklet_remove() | |
1708 { | |
1709 docklet_count--; | |
1710 if (!docklet_count) { | |
4944 | 1711 if (connections) |
4698 | 1712 gaim_blist_set_visible(TRUE); |
4944 | 1713 else if (mainwindow) |
4840 | 1714 gtk_window_present(GTK_WINDOW(mainwindow)); |
4944 | 1715 else |
4840 | 1716 show_login(); |
4698 | 1717 } |
4687 | 1718 } |
1 | 1719 |
4687 | 1720 static struct gaim_blist_ui_ops blist_ui_ops = |
1721 { | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1722 gaim_gtk_blist_new_list, |
5068 | 1723 NULL, |
4687 | 1724 gaim_gtk_blist_show, |
1725 gaim_gtk_blist_update, | |
1726 gaim_gtk_blist_remove, | |
1727 gaim_gtk_blist_destroy, | |
1728 gaim_gtk_blist_set_visible | |
1729 }; | |
1 | 1730 |
1731 | |
4687 | 1732 struct gaim_blist_ui_ops *gaim_get_gtk_blist_ui_ops() |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
1733 { |
4687 | 1734 return &blist_ui_ops; |
1037
1c663beef29d
[gaim-migrate @ 1047]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1036
diff
changeset
|
1735 } |
1c663beef29d
[gaim-migrate @ 1047]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1036
diff
changeset
|
1736 |
3131 | 1737 |
1738 | |
4687 | 1739 /********************************************************************* |
1740 * Public utility functions * | |
1741 *********************************************************************/ | |
1058
4927ce25d8cc
[gaim-migrate @ 1068]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1742 |
4687 | 1743 GdkPixbuf * |
1744 create_prpl_icon(struct gaim_account *account) | |
4553
d03fcb3f4be2
[gaim-migrate @ 4833]
Christian Hammond <chipx86@chipx86.com>
parents:
4525
diff
changeset
|
1745 { |
4687 | 1746 struct prpl *prpl = find_prpl(account->protocol); |
1747 GdkPixbuf *status = NULL; | |
1748 char *filename = NULL; | |
5151 | 1749 const char *protoname = NULL; |
1750 | |
1751 /* this is so we can get the icon when the prpl isn't loaded. | |
1752 * it's not as bad as it looks, since most of the time this function | |
1753 * is called, the prpl is already loaded, so it'll just increment and | |
1754 * decrement the refcount, won't have to go through the hassle of | |
1755 * actually loading and unloading the prpl. the few times it actually | |
1756 * does that, it saves us from crashing */ | |
1757 if(prpl && prpl->list_icon) { | |
1758 ref_protocol(prpl); | |
1759 protoname = prpl->list_icon(account, NULL); | |
1760 unref_protocol(prpl); | |
1761 } | |
1762 | |
4687 | 1763 /* "Hey, what's all this crap?" you ask. Status icons will be themeable too, and |
1764 then it will look up protoname from the theme */ | |
1765 if (!strcmp(protoname, "aim")) { | |
1766 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "aim.png", NULL); | |
1767 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1768 g_free(filename); | |
1769 } else if (!strcmp(protoname, "yahoo")) { | |
1770 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "yahoo.png", NULL); | |
1771 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1772 g_free(filename); | |
1773 } else if (!strcmp(protoname, "msn")) { | |
1774 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "msn.png", NULL); | |
1775 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1776 g_free(filename); | |
1777 } else if (!strcmp(protoname, "jabber")) { | |
1778 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "jabber.png", NULL); | |
1779 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1780 g_free(filename); | |
1781 } else if (!strcmp(protoname, "icq")) { | |
1782 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "icq.png", NULL); | |
1783 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1784 g_free(filename); | |
1785 } else if (!strcmp(protoname, "gadu-gadu")) { | |
4987 | 1786 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "gadu-gadu.png", NULL); |
4687 | 1787 status = gdk_pixbuf_new_from_file(filename,NULL); |
1788 g_free(filename); | |
1789 } else if (!strcmp(protoname, "napster")) { | |
1790 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "napster.png", NULL); | |
1791 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1792 g_free(filename); | |
1793 } else if (!strcmp(protoname, "irc")) { | |
1794 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "irc.png", NULL); | |
1795 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1796 g_free(filename); | |
960
fa681641643d
[gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
945
diff
changeset
|
1797 } |
4687 | 1798 return status; |
1 | 1799 } |
4699 | 1800 |