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