Mercurial > pidgin
annotate src/buddy.c @ 4983:10d7a6686c1f
[gaim-migrate @ 5318]
let's try this for a bit.
Moved the stuff from Edit to other menus.
My only problem is that this makes the buddy list
a bit too thin. I can't read the title of the window, or many of my buddies'
names. I may need to set a default size a bit larger so that we won't get
complaints about that.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Thu, 03 Apr 2003 16:57:39 +0000 |
parents | 06baf1e9094c |
children | b5e52f7e5302 |
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 { | |
4978 | 620 if (gtkblist->timeout) { |
621 g_source_remove(gtkblist->timeout); | |
622 gtkblist->timeout = 0; | |
623 } | |
4724 | 624 if (gtkblist->tipwindow) { |
625 gtk_widget_destroy(gtkblist->tipwindow); | |
626 gtkblist->tipwindow = NULL; | |
627 } | |
4978 | 628 } |
4724 | 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>" }, |
4983 | 645 { N_("/Buddies/_Show Offline Buddies"), NULL, gaim_gtk_blist_edit_mode_cb, 1, "<CheckItem>"}, |
646 { N_("/Buddies/_Add a Buddy..."), NULL, gaim_gtk_blist_add_buddy_cb, 0, "<StockItem>", GTK_STOCK_ADD }, | |
647 { N_("/Buddies/Add a _Group..."), NULL, show_add_group, 0, NULL}, | |
648 { "/Buddies/sep3", NULL, NULL, 0, "<Separator>" }, | |
4687 | 649 { N_("/Buddies/_Signoff"), "<CTL>D", signoff_all, 0, NULL }, |
650 { N_("/Buddies/_Quit"), "<CTL>Q", do_quit, 0, | |
651 "<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>" }, | |
4916 | 657 { N_("/Tools/sep1"), NULL, NULL, 0, "<Separator>" }, |
4698 | 658 { N_("/Tools/_File Transfers"), NULL, gaim_show_xfer_dialog, 0, |
4687 | 659 "<StockItem>", GTK_STOCK_REVERT_TO_SAVED }, |
4834 | 660 { "/Tools/sep2", NULL, NULL, 0, "<Separator>" }, |
4687 | 661 { N_("/Tools/P_rotocol Actions"), NULL, NULL, 0, "<Branch>" }, |
4697 | 662 { N_("/Tools/View System _Log"), NULL, gtk_blist_show_systemlog_cb, 0, NULL }, |
4983 | 663 { "/Tools/sep3", NULL, NULL, 0, "<Separator>" }, |
664 { N_("/Tools/A_ccounts"), "<CTL>A", account_editor, 0, NULL }, | |
665 { N_("/Tools/Preferences"), "<CTL>P", show_prefs, 0, | |
666 "<StockItem>", GTK_STOCK_PREFERENCES }, | |
667 { N_("/Tools/Pr_ivacy"), NULL, show_privacy_options, 0, NULL }, | |
3251 | 668 |
4687 | 669 /* Help */ |
670 { N_("/_Help"), NULL, NULL, 0, "<Branch>" }, | |
4776 | 671 { N_("/Help/Online _Help"), "F1", gtk_blist_show_onlinehelp_cb, 0, |
4687 | 672 "<StockItem>", GTK_STOCK_HELP }, |
4755 | 673 { N_("/Help/_Debug Window"), NULL, toggle_debug, 0, NULL }, |
4687 | 674 { N_("/Help/_About"), NULL, show_about, 0, NULL }, |
675 | |
676 }; | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
677 |
4687 | 678 /********************************************************* |
679 * Private Utility functions * | |
680 *********************************************************/ | |
681 | |
4724 | 682 static char *gaim_get_tooltip_text(struct buddy *b) |
683 { | |
684 char *text = NULL; | |
685 struct prpl* prpl = find_prpl(b->account->protocol); | |
686 char *statustext = NULL; | |
4867 | 687 char *aliastext = NULL, *nicktext = NULL; |
4724 | 688 char *warning = NULL, *idletime = NULL; |
689 | |
690 if (prpl->tooltip_text) { | |
4815 | 691 const char *end; |
4732 | 692 statustext = prpl->tooltip_text(b); |
4815 | 693 |
694 if(statustext && !g_utf8_validate(statustext, -1, &end)) { | |
695 char *new = g_strndup(statustext, | |
696 g_utf8_pointer_to_offset(statustext, end)); | |
697 g_free(statustext); | |
698 statustext = new; | |
699 } | |
4724 | 700 } |
4732 | 701 |
4724 | 702 if (b->idle) { |
703 int ihrs, imin; | |
704 time_t t; | |
705 time(&t); | |
706 ihrs = (t - b->idle) / 3600; | |
707 imin = ((t - b->idle) / 60) % 60; | |
708 if (ihrs) | |
4744 | 709 idletime = g_strdup_printf(_("%dh%02dm"), ihrs, imin); |
4724 | 710 else |
4744 | 711 idletime = g_strdup_printf(_("%dm"), imin); |
4724 | 712 } |
4732 | 713 |
4945 | 714 if(b->alias && b->alias[0]) |
4867 | 715 aliastext = g_markup_escape_text(b->alias, -1); |
716 | |
717 if(b->server_alias) | |
718 nicktext = g_markup_escape_text(b->server_alias, -1); | |
719 | |
4724 | 720 if (b->evil > 0) |
4744 | 721 warning = g_strdup_printf(_("%d%%"), b->evil); |
4732 | 722 |
4724 | 723 text = g_strdup_printf("<span size='larger' weight='bold'>%s</span>" |
4744 | 724 "%s %s" /* Alias */ |
725 "%s %s" /* Nickname */ | |
726 "%s %s" /* Idle */ | |
727 "%s %s" /* Warning */ | |
4916 | 728 "%s" /* Offline */ |
4968 | 729 "%s%s" /* Status */ |
730 "%s", | |
4724 | 731 b->name, |
4867 | 732 aliastext ? _("\n<b>Alias:</b>") : "", aliastext ? aliastext : "", |
733 nicktext ? _("\n<b>Nickname:</b>") : "", nicktext ? nicktext : "", | |
734 b->idle ? _("\n<b>Idle:</b>") : "", b->idle ? idletime : "", | |
4744 | 735 b->evil ? _("\n<b>Warned:</b>") : "", b->evil ? warning : "", |
4916 | 736 !b->present ? _("\n<b>Status:</b> Offline") : "", |
4968 | 737 statustext ? "\n" : "", statustext ? statustext : "", |
4980 | 738 !g_ascii_strcasecmp(b->name, "robflynn") ? "\n<b>Description:</b> Spooky" : ""); |
4968 | 739 |
4737 | 740 if(warning) |
741 g_free(warning); | |
742 if(idletime) | |
743 g_free(idletime); | |
744 if(statustext) | |
745 g_free(statustext); | |
4867 | 746 if(nicktext) |
747 g_free(nicktext); | |
748 if(aliastext) | |
749 g_free(aliastext); | |
4737 | 750 |
4724 | 751 return text; |
752 | |
753 } | |
754 | |
755 static GdkPixbuf *gaim_gtk_blist_get_status_icon(struct buddy *b, GaimStatusIconSize size) | |
4687 | 756 { |
757 GdkPixbuf *status = NULL; | |
758 GdkPixbuf *scale = NULL; | |
759 GdkPixbuf *emblem = NULL; | |
4737 | 760 gchar *filename = NULL; |
4687 | 761 const char *protoname = NULL; |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
762 |
4691 | 763 char *se = NULL, *sw = NULL ,*nw = NULL ,*ne = NULL; |
4737 | 764 |
4687 | 765 int scalesize = 30; |
766 | |
767 struct prpl* prpl = find_prpl(b->account->protocol); | |
4916 | 768 |
769 if (!prpl) | |
770 return NULL; | |
771 | |
4687 | 772 if (prpl->list_icon) |
773 protoname = prpl->list_icon(b->account, b); | |
774 if (prpl->list_emblems) | |
775 prpl->list_emblems(b, &se, &sw, &nw, &ne); | |
4916 | 776 |
4724 | 777 if (size == GAIM_STATUS_ICON_SMALL) { |
4687 | 778 scalesize = 15; |
779 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
|
780 } |
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
781 |
4701 | 782 |
4687 | 783 if (b->present == 2) { |
4701 | 784 struct gaim_gtk_blist_node *gtknode; |
4687 | 785 /* If b->present is 2, that means this buddy has just signed on. We use the "login" icon for the |
786 * status, and we set a timeout to change it to a normal icon after 10 seconds. */ | |
787 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "login.png", NULL); | |
788 status = gdk_pixbuf_new_from_file(filename,NULL); | |
789 g_free(filename); | |
4701 | 790 |
791 gtknode = GAIM_GTK_BLIST_NODE((GaimBlistNode*)b); | |
4773 | 792 if (gtknode->timer > 0) |
793 g_source_remove(gtknode->timer); | |
4701 | 794 gtknode->timer = g_timeout_add(10000, (GSourceFunc)gaim_reset_present_icon, b); |
795 | |
4737 | 796 /* "Hey, what's all this crap?" you ask. Status icons will be themeable too, and |
4687 | 797 then it will look up protoname from the theme */ |
798 } else { | |
799 char *image = g_strdup_printf("%s.png", protoname); | |
800 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
801 status = gdk_pixbuf_new_from_file(filename,NULL); | |
802 g_free(image); | |
803 g_free(filename); | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
804 |
4687 | 805 } |
4737 | 806 |
4687 | 807 if (!status) |
808 return NULL; | |
4737 | 809 |
4687 | 810 scale = gdk_pixbuf_scale_simple(status, scalesize, scalesize, GDK_INTERP_BILINEAR); |
4737 | 811 |
812 g_object_unref(G_OBJECT(status)); | |
813 | |
4687 | 814 /* Emblems */ |
4737 | 815 |
4687 | 816 /* Each protocol can specify up to four "emblems" to composite over the base icon. "away", "busy", "mobile user" |
817 * are all examples of states represented by emblems. I'm not even really sure I like this yet. */ | |
4737 | 818 |
4687 | 819 /* XXX Clean this crap up, yo. */ |
820 if (se) { | |
821 char *image = g_strdup_printf("%s.png", se); | |
822 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
823 g_free(image); | |
824 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
825 g_free(filename); | |
826 if (emblem) { | |
4724 | 827 if (size == GAIM_STATUS_ICON_LARGE) |
4687 | 828 gdk_pixbuf_composite (emblem, |
829 scale, 15, 15, | |
830 15, 15, | |
831 15, 15, | |
832 1, 1, | |
833 GDK_INTERP_BILINEAR, | |
834 255); | |
835 else | |
836 gdk_pixbuf_composite (emblem, | |
837 scale, 0, 0, | |
838 15, 15, | |
839 0, 0, | |
840 1, 1, | |
841 GDK_INTERP_BILINEAR, | |
842 255); | |
4737 | 843 g_object_unref(G_OBJECT(emblem)); |
4687 | 844 } |
845 } | |
846 if (sw) { | |
847 char *image = g_strdup_printf("%s.png", sw); | |
848 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
849 g_free(image); | |
850 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
851 g_free(filename); | |
852 if (emblem) { | |
4737 | 853 gdk_pixbuf_composite (emblem, |
854 scale, 0, 15, | |
855 15, 15, | |
856 0, 15, | |
857 1, 1, | |
858 GDK_INTERP_BILINEAR, | |
859 255); | |
860 g_object_unref(G_OBJECT(emblem)); | |
4687 | 861 } |
862 } | |
863 if (nw) { | |
864 char *image = g_strdup_printf("%s.png", nw); | |
865 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
866 g_free(image); | |
867 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
868 g_free(filename); | |
869 if (emblem) { | |
870 gdk_pixbuf_composite (emblem, | |
871 scale, 0, 0, | |
872 15, 15, | |
873 0, 0, | |
874 1, 1, | |
875 GDK_INTERP_BILINEAR, | |
876 255); | |
4737 | 877 g_object_unref(G_OBJECT(emblem)); |
4687 | 878 } |
879 } | |
880 if (ne) { | |
881 char *image = g_strdup_printf("%s.png", ne); | |
882 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
883 g_free(image); | |
884 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
885 g_free(filename); | |
886 if (emblem) { | |
887 gdk_pixbuf_composite (emblem, | |
888 scale, 15, 0, | |
889 15, 15, | |
890 15, 0, | |
891 1, 1, | |
892 GDK_INTERP_BILINEAR, | |
893 255); | |
4954 | 894 g_object_unref(G_OBJECT(emblem)); |
4687 | 895 } |
4737 | 896 } |
4687 | 897 |
4737 | 898 |
4718 | 899 /* Idle grey buddies affects the whole row. This converts the status icon to greyscale. */ |
4930 | 900 if (!b->present) |
4928 | 901 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE); |
902 else if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS) | |
903 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.25, FALSE); | |
4687 | 904 return scale; |
1 | 905 } |
906 | |
4737 | 907 static GdkPixbuf *gaim_gtk_blist_get_buddy_icon(struct buddy *b) |
1 | 908 { |
4687 | 909 /* This just opens a file from ~/.gaim/icons/screenname. This needs to change to be more gooder. */ |
4737 | 910 char *file; |
911 GdkPixbuf *buf, *ret; | |
912 | |
4687 | 913 if (!(blist_options & OPT_BLIST_SHOW_ICONS)) |
914 return NULL; | |
4737 | 915 |
4757 | 916 if ((file = gaim_buddy_get_setting(b, "buddy_icon")) == NULL) |
917 return NULL; | |
918 | |
4737 | 919 buf = gdk_pixbuf_new_from_file(file, NULL); |
920 g_free(file); | |
921 | |
922 | |
4687 | 923 if (buf) { |
4930 | 924 if (!b->present) |
4928 | 925 gdk_pixbuf_saturate_and_pixelate(buf, buf, 0.0, FALSE); |
926 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS) | |
927 gdk_pixbuf_saturate_and_pixelate(buf, buf, 0.25, FALSE); | |
928 | |
4737 | 929 ret = gdk_pixbuf_scale_simple(buf,30,30, GDK_INTERP_BILINEAR); |
930 g_object_unref(G_OBJECT(buf)); | |
931 return ret; | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
932 } |
4687 | 933 return NULL; |
2986 | 934 } |
935 | |
4810 | 936 static gchar *gaim_gtk_blist_get_name_markup(struct buddy *b, gboolean selected) |
1 | 937 { |
4687 | 938 char *name = gaim_get_buddy_alias(b); |
939 char *esc = g_markup_escape_text(name, strlen(name)), *text = NULL; | |
4722 | 940 struct prpl* prpl = find_prpl(b->account->protocol); |
941 | |
4687 | 942 /* XXX Clean up this crap */ |
4699 | 943 |
4687 | 944 int ihrs, imin; |
4724 | 945 char *idletime = NULL, *warning = NULL, *statustext = NULL; |
4732 | 946 time_t t; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
947 |
4687 | 948 if (!(blist_options & OPT_BLIST_SHOW_ICONS)) { |
4978 | 949 if ((b->idle > 0 && blist_options & OPT_BLIST_GREY_IDLERS && !selected) || b->present == 0) { |
4718 | 950 text = g_strdup_printf("<span color='dim grey'>%s</span>", |
4699 | 951 esc); |
4687 | 952 g_free(esc); |
953 return text; | |
954 } else { | |
955 return esc; | |
956 } | |
1 | 957 } |
958 | |
4687 | 959 time(&t); |
960 ihrs = (t - b->idle) / 3600; | |
961 imin = ((t - b->idle) / 60) % 60; | |
4699 | 962 |
4916 | 963 if (prpl && prpl->status_text) { |
4732 | 964 char *tmp = prpl->status_text(b); |
4815 | 965 const char *end; |
966 | |
967 if(tmp && !g_utf8_validate(tmp, -1, &end)) { | |
968 char *new = g_strndup(tmp, | |
969 g_utf8_pointer_to_offset(tmp, end)); | |
970 g_free(tmp); | |
971 tmp = new; | |
972 } | |
4732 | 973 |
974 if(tmp) { | |
4855 | 975 char buf[32]; |
976 char *c = tmp; | |
977 int length = 0, vis=0; | |
978 gboolean inside = FALSE; | |
4806 | 979 g_strdelimit(tmp, "\n", ' '); |
4852
d1c17e81055e
[gaim-migrate @ 5179]
Christian Hammond <chipx86@chipx86.com>
parents:
4847
diff
changeset
|
980 |
4855 | 981 while(*c && vis < 20) { |
982 if(*c == '&') | |
983 inside = TRUE; | |
4856 | 984 else if(*c == ';') |
985 inside = FALSE; | |
4855 | 986 if(!inside) |
987 vis++; | |
988 length++; | |
989 c++; /* this is fun */ | |
990 } | |
4852
d1c17e81055e
[gaim-migrate @ 5179]
Christian Hammond <chipx86@chipx86.com>
parents:
4847
diff
changeset
|
991 |
4855 | 992 if(vis == 20) |
993 g_snprintf(buf, sizeof(buf), "%%.%ds...", length); | |
994 else | |
995 g_snprintf(buf, sizeof(buf), "%%s "); | |
4852
d1c17e81055e
[gaim-migrate @ 5179]
Christian Hammond <chipx86@chipx86.com>
parents:
4847
diff
changeset
|
996 |
4855 | 997 statustext = g_strdup_printf(buf, tmp); |
4852
d1c17e81055e
[gaim-migrate @ 5179]
Christian Hammond <chipx86@chipx86.com>
parents:
4847
diff
changeset
|
998 |
4732 | 999 g_free(tmp); |
1000 } | |
4722 | 1001 } |
4732 | 1002 |
4687 | 1003 if (b->idle) { |
1004 if (ihrs) | |
4757 | 1005 idletime = g_strdup_printf(_("Idle (%dh%02dm) "), ihrs, imin); |
4687 | 1006 else |
4757 | 1007 idletime = g_strdup_printf(_("Idle (%dm) "), imin); |
4687 | 1008 } |
4757 | 1009 |
4687 | 1010 if (b->evil > 0) |
4757 | 1011 warning = g_strdup_printf(_("Warned (%d%%) "), b->evil); |
1012 | |
4810 | 1013 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS && !selected) { |
4916 | 1014 text = g_strdup_printf("<span color='dim grey'>%s</span>\n" |
1015 "<span color='dim grey' size='smaller'>%s%s%s%s</span>", | |
4687 | 1016 esc, |
4722 | 1017 statustext != NULL ? statustext : "", |
1018 idletime != NULL ? idletime : "", | |
4916 | 1019 warning != NULL ? warning : "", |
1020 !b->present ? _("Offline ") : ""); | |
1021 } else if (statustext == NULL && idletime == NULL && warning == NULL && b->present) { | |
1022 text = g_strdup(esc); | |
4797 | 1023 } else { |
4916 | 1024 text = g_strdup_printf("%s\n" |
1025 "<span %s size='smaller'>%s%s%s%s</span>", esc, | |
1026 selected ? "" : "color='dim grey'", | |
1027 statustext != NULL ? statustext : "", | |
1028 idletime != NULL ? idletime : "", | |
1029 warning != NULL ? warning : "", | |
1030 !b->present ? _("Offline ") : ""); | |
4797 | 1031 } |
4722 | 1032 if (idletime) |
4687 | 1033 g_free(idletime); |
4722 | 1034 if (warning) |
4687 | 1035 g_free(warning); |
4722 | 1036 if (statustext) |
1037 g_free(statustext); | |
4737 | 1038 if (esc) |
1039 g_free(esc); | |
4699 | 1040 |
4687 | 1041 return text; |
1042 } | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
1043 |
4840 | 1044 static void gaim_gtk_blist_restore_position() |
1045 { | |
1046 /* if the window exists, is hidden, we're saving positions, and the position is sane... */ | |
1047 if(gtkblist && gtkblist->window && | |
1048 !GTK_WIDGET_VISIBLE(gtkblist->window) && | |
1049 blist_options & OPT_BLIST_SAVED_WINDOWS && | |
1050 blist_pos.width != 0) { | |
1051 /* ...check position is on screen... */ | |
1052 if (blist_pos.x >= gdk_screen_width()) | |
1053 blist_pos.x = gdk_screen_width() - 100; | |
1054 else if (blist_pos.x < 0) | |
1055 blist_pos.x = 100; | |
1056 | |
1057 if (blist_pos.y >= gdk_screen_height()) | |
1058 blist_pos.y = gdk_screen_height() - 100; | |
1059 else if (blist_pos.y < 0) | |
1060 blist_pos.y = 100; | |
1061 | |
1062 /* ...and move it back. */ | |
1063 gtk_window_move(GTK_WINDOW(gtkblist->window), blist_pos.x, blist_pos.y); | |
1064 gtk_window_resize(GTK_WINDOW(gtkblist->window), blist_pos.width, blist_pos.height); | |
1065 } | |
1066 } | |
1067 | |
4944 | 1068 static gboolean gaim_gtk_blist_refresh_timer(struct gaim_buddy_list *list) |
1069 { | |
1070 GaimBlistNode *group = list->root; | |
1071 GaimBlistNode *buddy; | |
1072 | |
1073 while (group) { | |
1074 buddy = group->child; | |
1075 while (buddy) { | |
1076 if (((struct buddy *)buddy)->idle) | |
1077 gaim_gtk_blist_update(list, buddy); | |
1078 buddy = buddy->next; | |
1079 } | |
1080 group = group->next; | |
1081 } | |
1082 | |
1083 /* keep on going */ | |
1084 return TRUE; | |
1085 } | |
4840 | 1086 |
4687 | 1087 /********************************************************************************** |
1088 * Public API Functions * | |
1089 **********************************************************************************/ | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1090 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
|
1091 { |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1092 blist->ui_data = g_new0(struct gaim_gtk_buddy_list, 1); |
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 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1095 static void gaim_gtk_blist_new_node(GaimBlistNode *node) |
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 node->ui_data = g_new0(struct gaim_gtk_blist_node, 1); |
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 |
4729 | 1100 void gaim_gtk_blist_update_columns() |
1101 { | |
1102 if (blist_options & OPT_BLIST_SHOW_ICONS) { | |
1103 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, TRUE); | |
1104 gtk_tree_view_column_set_visible(gtkblist->idle_column, FALSE); | |
1105 gtk_tree_view_column_set_visible(gtkblist->warning_column, FALSE); | |
1106 } else { | |
1107 gtk_tree_view_column_set_visible(gtkblist->idle_column, blist_options & OPT_BLIST_SHOW_IDLETIME); | |
1108 gtk_tree_view_column_set_visible(gtkblist->warning_column, blist_options & OPT_BLIST_SHOW_WARN); | |
1109 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, FALSE); | |
1110 } | |
1111 } | |
1112 | |
4702 | 1113 enum {DRAG_BUDDY, DRAG_ROW}; |
1114 | |
4834 | 1115 static char * |
1116 item_factory_translate_func (const char *path, gpointer func_data) | |
1117 { | |
1118 return _(path); | |
1119 } | |
1120 | |
4687 | 1121 static void gaim_gtk_blist_show(struct gaim_buddy_list *list) |
1122 { | |
1123 GtkItemFactory *ift; | |
1124 GtkCellRenderer *rend; | |
1125 GtkTreeViewColumn *column; | |
1126 GtkWidget *sw; | |
1127 GtkWidget *button; | |
4973 | 1128 GtkTooltips *tooltips; |
4694 | 1129 GtkSizeGroup *sg; |
4810 | 1130 GtkTreeSelection *selection; |
4781 | 1131 GtkTargetEntry gte[] = {{"GAIM_BLIST_NODE", GTK_TARGET_SAME_APP, DRAG_ROW}, |
4702 | 1132 {"application/x-im-contact", 0, DRAG_BUDDY}}; |
4690 | 1133 |
4745 | 1134 if (gtkblist && gtkblist->window) { |
4687 | 1135 gtk_widget_show(gtkblist->window); |
1136 return; | |
1137 } | |
4690 | 1138 |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1139 gtkblist = GAIM_GTK_BLIST(list); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1140 |
4687 | 1141 gtkblist->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
4840 | 1142 gtk_window_set_role(GTK_WINDOW(gtkblist->window), "buddy_list"); |
4964 | 1143 gtk_window_set_title(GTK_WINDOW(gtkblist->window), _("Buddy List")); |
4879
4f5bd9a2da37
[gaim-migrate @ 5209]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4867
diff
changeset
|
1144 gtk_widget_realize(gtkblist->window); |
4690 | 1145 |
4925 | 1146 gtkblist->vbox = gtk_vbox_new(FALSE, 0); |
4687 | 1147 gtk_container_add(GTK_CONTAINER(gtkblist->window), gtkblist->vbox); |
1 | 1148 |
4840 | 1149 g_signal_connect(G_OBJECT(gtkblist->window), "delete_event", G_CALLBACK(gtk_blist_delete_cb), NULL); |
1150 g_signal_connect(G_OBJECT(gtkblist->window), "configure_event", G_CALLBACK(gtk_blist_configure_cb), NULL); | |
1151 g_signal_connect(G_OBJECT(gtkblist->window), "visibility_notify_event", G_CALLBACK(gtk_blist_visibility_cb), NULL); | |
1152 gtk_widget_add_events(gtkblist->window, GDK_VISIBILITY_NOTIFY_MASK); | |
4698 | 1153 |
4687 | 1154 /******************************* Menu bar *************************************/ |
1155 ift = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GaimMain>", NULL); | |
4834 | 1156 gtk_item_factory_set_translate_func (ift, |
1157 item_factory_translate_func, | |
1158 NULL, NULL); | |
4687 | 1159 gtk_item_factory_create_items(ift, sizeof(blist_menu) / sizeof(*blist_menu), |
1160 blist_menu, NULL); | |
1161 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtk_item_factory_get_widget(ift, "<GaimMain>"), FALSE, FALSE, 0); | |
1 | 1162 |
4834 | 1163 awaymenu = gtk_item_factory_get_widget(ift, N_("/Tools/Away")); |
4694 | 1164 do_away_menu(); |
1165 | |
4834 | 1166 bpmenu = gtk_item_factory_get_widget(ift, N_("/Tools/Buddy Pounce")); |
4696 | 1167 do_bp_menu(); |
1168 | |
4834 | 1169 protomenu = gtk_item_factory_get_widget(ift, N_("/Tools/Protocol Actions")); |
4696 | 1170 do_proto_menu(); |
1171 | |
4687 | 1172 /****************************** GtkTreeView **********************************/ |
1173 sw = gtk_scrolled_window_new(NULL,NULL); | |
1174 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); | |
1175 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
1176 | |
4847 | 1177 gtkblist->treemodel = gtk_tree_store_new(BLIST_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, |
4687 | 1178 G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_POINTER); |
4702 | 1179 |
4687 | 1180 gtkblist->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(gtkblist->treemodel)); |
4943 | 1181 gtk_widget_set_size_request(gtkblist->treeview, -1, 200); |
4704 | 1182 |
4810 | 1183 /* Set up selection stuff */ |
1184 | |
1185 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)); | |
1186 g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(gaim_gtk_blist_selection_changed), NULL); | |
1187 | |
1188 | |
4702 | 1189 /* Set up dnd */ |
1190 gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(gtkblist->treeview), GDK_BUTTON1_MASK, gte, | |
1191 2, GDK_ACTION_COPY); | |
4704 | 1192 gtk_tree_view_enable_model_drag_dest(GTK_TREE_VIEW(gtkblist->treeview), gte, 2, |
4702 | 1193 GDK_ACTION_COPY | GDK_ACTION_MOVE); |
4704 | 1194 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-received", G_CALLBACK(gaim_gtk_blist_drag_data_rcv_cb), NULL); |
1195 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-get", G_CALLBACK(gaim_gtk_blist_drag_data_get_cb), NULL); | |
1196 | |
4724 | 1197 /* Tooltips */ |
1198 g_signal_connect(G_OBJECT(gtkblist->treeview), "motion-notify-event", G_CALLBACK(gaim_gtk_blist_motion_cb), NULL); | |
1199 g_signal_connect(G_OBJECT(gtkblist->treeview), "leave-notify-event", G_CALLBACK(gaim_gtk_blist_leave_cb), NULL); | |
4687 | 1200 |
1201 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(gtkblist->treeview), FALSE); | |
1 | 1202 |
4687 | 1203 rend = gtk_cell_renderer_pixbuf_new(); |
1204 column = gtk_tree_view_column_new_with_attributes("Status", rend, "pixbuf", STATUS_ICON_COLUMN, NULL); | |
1205 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); | |
4933 | 1206 g_object_set(rend, "xalign", 0.0, "ypad", 0, NULL); |
4706 | 1207 |
4687 | 1208 rend = gtk_cell_renderer_text_new(); |
1209 column = gtk_tree_view_column_new_with_attributes("Name", rend, "markup", NAME_COLUMN, NULL); | |
1210 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); | |
4797 | 1211 g_object_set(rend, "ypad", 0, "yalign", 0.5, NULL); |
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); |
1229 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
|
1230 |
4687 | 1231 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), sw, TRUE, TRUE, 0); |
1232 gtk_container_add(GTK_CONTAINER(sw), gtkblist->treeview); | |
4725 | 1233 gaim_gtk_blist_update_columns(); |
4934 | 1234 |
4956 | 1235 /* set the Show Offline Buddies option. must be done |
1236 * after the treeview or faceprint gets mad. -Robot101 | |
1237 */ | |
1238 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (ift, N_("/Edit/Show Offline Buddies"))), | |
1239 blist_options & OPT_BLIST_SHOW_OFFLINE); | |
1240 | |
1241 /* OK... let's show this bad boy. */ | |
1242 gaim_gtk_blist_refresh(list); | |
1243 gaim_gtk_blist_restore_position(); | |
1244 gtk_widget_show_all(gtkblist->window); | |
1245 | |
4687 | 1246 /**************************** Button Box **************************************/ |
4956 | 1247 /* add this afterwards so it doesn't force up the width of the window */ |
4694 | 1248 |
4973 | 1249 tooltips = gtk_tooltips_new(); |
1250 | |
4694 | 1251 sg = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); |
4687 | 1252 gtkblist->bbox = gtk_hbox_new(TRUE, 0); |
1253 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtkblist->bbox, FALSE, FALSE, 0); | |
4956 | 1254 gtk_widget_show(gtkblist->bbox); |
1255 | |
4687 | 1256 button = gaim_pixbuf_button_from_stock(_("IM"), GAIM_STOCK_IM, GAIM_BUTTON_VERTICAL); |
1257 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
1258 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 1259 gtk_size_group_add_widget(sg, button); |
4692 | 1260 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_im_cb), |
4697 | 1261 gtkblist->treeview); |
4973 | 1262 gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips), button, _("Send an Instant Message to the selected buddy"), NULL); |
4956 | 1263 gtk_widget_show(button); |
1264 | |
4687 | 1265 button = gaim_pixbuf_button_from_stock(_("Get Info"), GAIM_STOCK_INFO, GAIM_BUTTON_VERTICAL); |
1266 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
1267 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 1268 gtk_size_group_add_widget(sg, button); |
1269 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_info_cb), | |
4697 | 1270 gtkblist->treeview); |
4973 | 1271 gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips), button, _("Get information on the selected buddy"), NULL); |
4956 | 1272 gtk_widget_show(button); |
4729 | 1273 |
4687 | 1274 button = gaim_pixbuf_button_from_stock(_("Chat"), GAIM_STOCK_CHAT, GAIM_BUTTON_VERTICAL); |
1275 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
1276 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 1277 gtk_size_group_add_widget(sg, button); |
1278 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_chat_cb), NULL); | |
4973 | 1279 gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips), button, _("Join a chat room"), NULL); |
4956 | 1280 gtk_widget_show(button); |
4694 | 1281 |
4687 | 1282 button = gaim_pixbuf_button_from_stock(_("Away"), GAIM_STOCK_AWAY, GAIM_BUTTON_VERTICAL); |
1283 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
1284 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 1285 gtk_size_group_add_widget(sg, button); |
1286 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_away_cb), NULL); | |
4973 | 1287 gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips), button, _("Set an away message"), NULL); |
4956 | 1288 gtk_widget_show(button); |
4687 | 1289 |
4980 | 1290 /* we're done setting tooltips */ |
1291 gtk_object_sink(GTK_OBJECT(tooltips)); | |
1292 | |
4956 | 1293 /* this will show the right image/label widgets for us */ |
4944 | 1294 gaim_gtk_blist_update_toolbar(); |
1295 | |
4956 | 1296 /* start the refresh timer */ |
4944 | 1297 gtkblist->refresh_timer = g_timeout_add(30000, (GSourceFunc)gaim_gtk_blist_refresh_timer, list); |
4687 | 1298 } |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
1299 |
4687 | 1300 void gaim_gtk_blist_refresh(struct gaim_buddy_list *list) |
1301 { | |
1302 GaimBlistNode *group = list->root; | |
1303 GaimBlistNode *buddy; | |
4690 | 1304 |
4687 | 1305 while (group) { |
4916 | 1306 buddy = group->child; |
4687 | 1307 gaim_gtk_blist_update(list, group); |
1308 while (buddy) { | |
4699 | 1309 gaim_gtk_blist_update(list, buddy); |
4687 | 1310 buddy = buddy->next; |
1311 } | |
1312 group = group->next; | |
1313 } | |
1314 } | |
1 | 1315 |
4699 | 1316 static gboolean get_iter_from_node_helper(GaimBlistNode *node, GtkTreeIter *iter, GtkTreeIter *root) { |
4867 | 1317 |
4699 | 1318 do { |
1319 GaimBlistNode *n; | |
1320 GtkTreeIter child; | |
1321 | |
1322 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), root, NODE_COLUMN, &n, -1); | |
1323 if(n == node) { | |
1324 *iter = *root; | |
1325 return TRUE; | |
1326 } | |
1327 | |
1328 if(gtk_tree_model_iter_children(GTK_TREE_MODEL(gtkblist->treemodel), &child, root)) { | |
1329 if(get_iter_from_node_helper(node,iter,&child)) | |
1330 return TRUE; | |
1331 } | |
1332 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(gtkblist->treemodel), root)); | |
1333 | |
1334 return FALSE; | |
1335 } | |
1336 | |
1337 static gboolean get_iter_from_node(GaimBlistNode *node, GtkTreeIter *iter) { | |
1338 GtkTreeIter root; | |
1339 | |
1340 if (!gtkblist) | |
1341 return FALSE; | |
1342 | |
1343 if(!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(gtkblist->treemodel), &root)) | |
1344 return FALSE; | |
1345 | |
1346 return get_iter_from_node_helper(node, iter, &root); | |
1347 } | |
1348 | |
4944 | 1349 /* |
1350 * These state assignments suck. I'm sorry. They're for historical reasons. | |
1351 * Roll on new prefs. -Robot101 | |
1352 * | |
1353 * NO_BUTTON_TEXT && SHOW_BUTTON_XPM - image | |
1354 * !NO_BUTTON_TEXT && !SHOW_BUTTON_XPM - text | |
1355 * !NO_BUTTON_TEXT && SHOW_BUTTON_XPM - text & images | |
1356 * NO_BUTTON_TEXT && !SHOW_BUTTON_XPM - none | |
1357 */ | |
1358 | |
1359 static void gaim_gtk_blist_update_toolbar_icons (GtkWidget *widget, gpointer data) { | |
1360 if (GTK_IS_IMAGE(widget)) { | |
1361 if (blist_options & OPT_BLIST_SHOW_BUTTON_XPM) | |
1362 gtk_widget_show(widget); | |
1363 else | |
1364 gtk_widget_hide(widget); | |
1365 } else if (GTK_IS_LABEL(widget)) { | |
1366 if (blist_options & OPT_BLIST_NO_BUTTON_TEXT) | |
1367 gtk_widget_hide(widget); | |
1368 else | |
1369 gtk_widget_show(widget); | |
1370 } else if (GTK_IS_CONTAINER(widget)) { | |
1371 gtk_container_foreach(GTK_CONTAINER(widget), gaim_gtk_blist_update_toolbar_icons, NULL); | |
1372 } | |
1373 } | |
1374 | |
4697 | 1375 void gaim_gtk_blist_update_toolbar() { |
1376 if (!gtkblist) | |
1377 return; | |
4699 | 1378 |
4944 | 1379 if (blist_options & OPT_BLIST_NO_BUTTON_TEXT && !(blist_options & OPT_BLIST_SHOW_BUTTON_XPM)) |
4697 | 1380 gtk_widget_hide(gtkblist->bbox); |
4944 | 1381 else { |
1382 gtk_container_foreach(GTK_CONTAINER(gtkblist->bbox), gaim_gtk_blist_update_toolbar_icons, NULL); | |
4956 | 1383 gtk_widget_show(gtkblist->bbox); |
4944 | 1384 } |
4697 | 1385 } |
1386 | |
4701 | 1387 static void gaim_gtk_blist_remove(struct gaim_buddy_list *list, GaimBlistNode *node) |
1388 { | |
1389 struct gaim_gtk_blist_node *gtknode; | |
1390 GtkTreeIter iter; | |
1391 | |
1392 if (!node->ui_data) | |
1393 return; | |
1394 | |
1395 gtknode = (struct gaim_gtk_blist_node *)node->ui_data; | |
1396 | |
1397 if (gtknode->timer > 0) { | |
1398 g_source_remove(gtknode->timer); | |
1399 gtknode->timer = 0; | |
1400 } | |
1401 | |
4912 | 1402 /* For some reason, we're called before we have a buddy list sometimes */ |
1403 if(!gtkblist) | |
1404 return; | |
1405 | |
4831 | 1406 if(gtkblist->selected_node == node) |
1407 gtkblist->selected_node = NULL; | |
1408 | |
4701 | 1409 if (get_iter_from_node(node, &iter)) { |
1410 gtk_tree_store_remove(gtkblist->treemodel, &iter); | |
4918
553d96cb9b26
[gaim-migrate @ 5252]
Christian Hammond <chipx86@chipx86.com>
parents:
4916
diff
changeset
|
1411 if(GAIM_BLIST_NODE_IS_BUDDY(node) && |
4954 | 1412 !(blist_options & OPT_BLIST_SHOW_OFFLINE) && |
4918
553d96cb9b26
[gaim-migrate @ 5252]
Christian Hammond <chipx86@chipx86.com>
parents:
4916
diff
changeset
|
1413 gaim_blist_get_group_online_count((struct group *)node->parent) == 0) { |
4701 | 1414 GtkTreeIter groupiter; |
1415 if(get_iter_from_node(node->parent, &groupiter)) | |
1416 gtk_tree_store_remove(gtkblist->treemodel, &groupiter); | |
1417 } | |
1418 } | |
1419 } | |
1420 | |
4810 | 1421 static gboolean do_selection_changed(GaimBlistNode *new_selection) |
1422 { | |
1423 GaimBlistNode *old_selection = gtkblist->selected_node; | |
1424 | |
1425 if(new_selection != gtkblist->selected_node) { | |
1426 gtkblist->selected_node = new_selection; | |
1427 if(new_selection) | |
1428 gaim_gtk_blist_update(NULL, new_selection); | |
1429 if(old_selection) | |
1430 gaim_gtk_blist_update(NULL, old_selection); | |
1431 } | |
1432 | |
1433 return FALSE; | |
1434 } | |
1435 | |
1436 static void gaim_gtk_blist_selection_changed(GtkTreeSelection *selection, gpointer data) | |
1437 { | |
1438 GaimBlistNode *new_selection = NULL; | |
1439 GtkTreeIter iter; | |
1440 | |
1441 if(gtk_tree_selection_get_selected(selection, NULL, &iter)){ | |
1442 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, | |
1443 NODE_COLUMN, &new_selection, -1); | |
1444 } | |
1445 /* we set this up as a timeout, otherwise the blist flickers */ | |
1446 g_timeout_add(0, (GSourceFunc)do_selection_changed, new_selection); | |
1447 } | |
1448 | |
4936 | 1449 static void make_a_group(GaimBlistNode *node, GtkTreeIter *iter) { |
1450 GaimBlistNode *sibling; | |
1451 GtkTreeIter siblingiter; | |
1452 GdkPixbuf *groupicon = gtk_widget_render_icon(gtkblist->treeview, | |
1453 GTK_STOCK_OPEN, GTK_ICON_SIZE_SMALL_TOOLBAR, NULL); | |
4980 | 1454 struct group *group = (struct group *)node; |
1455 char *esc = g_markup_escape_text(group->name, -1); | |
1456 char *mark; | |
1457 | |
1458 if(blist_options & OPT_BLIST_SHOW_GRPNUM) | |
1459 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)); | |
1460 else | |
1461 mark = g_strdup_printf("<span weight='bold'>%s</span>", esc); | |
1462 | |
4936 | 1463 g_free(esc); |
4980 | 1464 |
4936 | 1465 sibling = node->prev; |
1466 while (sibling && !get_iter_from_node(sibling, &siblingiter)) { | |
1467 sibling = sibling->prev; | |
1468 } | |
1469 | |
1470 gtk_tree_store_insert_after(gtkblist->treemodel, iter, NULL, | |
1471 sibling ? &siblingiter : NULL); | |
1472 gtk_tree_store_set(gtkblist->treemodel, iter, | |
1473 STATUS_ICON_COLUMN, groupicon, | |
1474 NAME_COLUMN, mark, | |
1475 NODE_COLUMN, node, | |
1476 -1); | |
1477 g_free(mark); | |
1478 g_object_unref(groupicon); | |
1479 } | |
1480 | |
4701 | 1481 |
4687 | 1482 static void gaim_gtk_blist_update(struct gaim_buddy_list *list, GaimBlistNode *node) |
1483 { | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1484 struct gaim_gtk_blist_node *gtknode; |
4699 | 1485 GtkTreeIter iter; |
4936 | 1486 GtkTreePath *expand = NULL; |
4699 | 1487 gboolean new_entry = FALSE; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
1488 |
4687 | 1489 if (!gtkblist) |
1490 return; | |
4699 | 1491 |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1492 gtknode = GAIM_GTK_BLIST_NODE(node); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1493 |
4690 | 1494 |
4699 | 1495 if (!get_iter_from_node(node, &iter)) { /* This is a newly added node */ |
1496 new_entry = TRUE; | |
4687 | 1497 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { |
4929 | 1498 if (((struct buddy*)node)->present || (blist_options & OPT_BLIST_SHOW_OFFLINE && ((struct buddy*)node)->account->gc)) { |
4699 | 1499 GtkTreeIter groupiter; |
1500 GaimBlistNode *oldersibling; | |
1501 GtkTreeIter oldersiblingiter; | |
4690 | 1502 |
4936 | 1503 if(node->parent && |
1504 !get_iter_from_node(node->parent, &groupiter)) { | |
1505 /* This buddy's group has not yet been added. | |
1506 * We do that here */ | |
1507 make_a_group(node->parent, &groupiter); | |
1508 expand = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &groupiter); | |
4687 | 1509 } |
4810 | 1510 |
4699 | 1511 oldersibling = node->prev; |
4867 | 1512 while (oldersibling && !get_iter_from_node(oldersibling, &oldersiblingiter)) { |
4699 | 1513 oldersibling = oldersibling->prev; |
4867 | 1514 } |
4699 | 1515 |
1516 gtk_tree_store_insert_after(gtkblist->treemodel, &iter, &groupiter, oldersibling ? &oldersiblingiter : NULL); | |
4810 | 1517 |
4767 | 1518 if (blist_options & OPT_BLIST_POPUP) |
1519 gtk_window_present(GTK_WINDOW(gtkblist->window)); | |
4699 | 1520 |
1521 } | |
1522 } | |
4936 | 1523 else if (GAIM_BLIST_NODE_IS_GROUP(node) && (blist_options & OPT_BLIST_SHOW_OFFLINE)) { |
1524 make_a_group(node, &iter); | |
1525 expand = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &iter); | |
4916 | 1526 } |
1527 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
4936 | 1528 if ((gaim_blist_get_group_online_count((struct group *)node) == 0) || |
1529 (!gtk_tree_model_iter_has_child(GTK_TREE_MODEL(gtkblist->treemodel), &iter) && !(blist_options & OPT_BLIST_SHOW_OFFLINE))) { | |
4916 | 1530 gtk_tree_store_remove(gtkblist->treemodel, &iter); |
4936 | 1531 } else { |
4980 | 1532 struct group *group = (struct group *)node; |
1533 char *esc = g_markup_escape_text(group->name, -1); | |
1534 char *mark; | |
1535 | |
1536 if(blist_options & OPT_BLIST_SHOW_GRPNUM) | |
1537 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)); | |
1538 else | |
1539 mark = g_strdup_printf("<span weight='bold'>%s</span>", esc); | |
1540 | |
4916 | 1541 g_free(esc); |
1542 gtk_tree_store_set(gtkblist->treemodel, &iter, | |
4936 | 1543 NAME_COLUMN, mark, |
1544 -1); | |
4916 | 1545 g_free(mark); |
1546 } | |
4699 | 1547 } |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1548 |
4929 | 1549 if (GAIM_BLIST_NODE_IS_BUDDY(node) && (((struct buddy*)node)->present || (blist_options & OPT_BLIST_SHOW_OFFLINE && ((struct buddy*)node)->account->gc))) { |
4687 | 1550 GdkPixbuf *status, *avatar; |
1551 char *mark; | |
4697 | 1552 char *warning = NULL, *idle = NULL; |
1553 | |
4810 | 1554 gboolean selected = (gtkblist->selected_node == node); |
1555 | |
1556 status = gaim_gtk_blist_get_status_icon((struct buddy*)node, | |
4724 | 1557 blist_options & OPT_BLIST_SHOW_ICONS ? GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL); |
4687 | 1558 avatar = gaim_gtk_blist_get_buddy_icon((struct buddy*)node); |
4810 | 1559 mark = gaim_gtk_blist_get_name_markup((struct buddy*)node, selected); |
4697 | 1560 |
4725 | 1561 if (((struct buddy*)node)->idle > 0) { |
4697 | 1562 time_t t; |
1563 int ihrs, imin; | |
1564 time(&t); | |
1565 ihrs = (t - ((struct buddy *)node)->idle) / 3600; | |
1566 imin = ((t - ((struct buddy*)node)->idle) / 60) % 60; | |
4718 | 1567 if(ihrs > 0) |
1568 idle = g_strdup_printf("(%d:%02d)", ihrs, imin); | |
1569 else | |
1570 idle = g_strdup_printf("(%d)", imin); | |
4697 | 1571 } |
1572 | |
4725 | 1573 if (((struct buddy*)node)->evil > 0) |
4699 | 1574 warning = g_strdup_printf("%d%%", ((struct buddy*)node)->evil); |
4810 | 1575 |
4697 | 1576 |
4718 | 1577 if((blist_options & OPT_BLIST_GREY_IDLERS) |
1578 && ((struct buddy *)node)->idle) { | |
4810 | 1579 if(warning && !selected) { |
4718 | 1580 char *w2 = g_strdup_printf("<span color='dim grey'>%s</span>", |
1581 warning); | |
1582 g_free(warning); | |
1583 warning = w2; | |
1584 } | |
1585 | |
4810 | 1586 if(idle && !selected) { |
4718 | 1587 char *i2 = g_strdup_printf("<span color='dim grey'>%s</span>", |
1588 idle); | |
1589 g_free(idle); | |
1590 idle = i2; | |
1591 } | |
1592 } | |
1593 | |
1594 | |
4699 | 1595 gtk_tree_store_set(gtkblist->treemodel, &iter, |
4687 | 1596 STATUS_ICON_COLUMN, status, |
1597 NAME_COLUMN, mark, | |
4697 | 1598 WARNING_COLUMN, warning, |
1599 IDLE_COLUMN, idle, | |
4699 | 1600 BUDDY_ICON_COLUMN, avatar, |
4687 | 1601 NODE_COLUMN, node, |
1602 -1); | |
4699 | 1603 |
4687 | 1604 g_free(mark); |
4697 | 1605 if (idle) |
1606 g_free(idle); | |
1607 if (warning) | |
1608 g_free(warning); | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1609 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1610 if (status != NULL) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1611 g_object_unref(status); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1612 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1613 if (avatar != NULL) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1614 g_object_unref(avatar); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1615 |
4701 | 1616 } else if (GAIM_BLIST_NODE_IS_BUDDY(node) && !new_entry) { |
1617 gaim_gtk_blist_remove(list, node); | |
4767 | 1618 if (blist_options & OPT_BLIST_POPUP) |
1619 gtk_window_present(GTK_WINDOW(gtkblist->window)); | |
4687 | 1620 } |
4980 | 1621 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(gtkblist->treeview)); |
4936 | 1622 |
4974 | 1623 |
4936 | 1624 if(expand) { |
1625 gtk_tree_view_expand_row(GTK_TREE_VIEW(gtkblist->treeview), expand, TRUE); | |
1626 gtk_tree_path_free(expand); | |
1627 } | |
4980 | 1628 |
1629 if(GAIM_BLIST_NODE_IS_BUDDY(node)) | |
1630 gaim_gtk_blist_update(list, node->parent); | |
4687 | 1631 } |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
1632 |
4687 | 1633 static void gaim_gtk_blist_destroy(struct gaim_buddy_list *list) |
1634 { | |
4770 | 1635 if (!gtkblist) |
1636 return; | |
4944 | 1637 |
4687 | 1638 gtk_widget_destroy(gtkblist->window); |
4745 | 1639 |
4944 | 1640 if (gtkblist->refresh_timer) |
1641 g_source_remove(gtkblist->refresh_timer); | |
1642 if (gtkblist->timeout) | |
1643 g_source_remove(gtkblist->timeout); | |
1644 | |
1645 gtkblist->refresh_timer = 0; | |
1646 gtkblist->timeout = 0; | |
4745 | 1647 gtkblist->window = gtkblist->vbox = gtkblist->treeview = NULL; |
1648 gtkblist->treemodel = NULL; | |
1649 gtkblist->idle_column = NULL; | |
1650 gtkblist->warning_column = gtkblist->buddy_icon_column = NULL; | |
1651 gtkblist->bbox = gtkblist->tipwindow = NULL; | |
1652 protomenu = NULL; | |
1653 awaymenu = NULL; | |
1654 bpmenu = NULL; | |
4687 | 1655 } |
1 | 1656 |
4687 | 1657 static void gaim_gtk_blist_set_visible(struct gaim_buddy_list *list, gboolean show) |
1658 { | |
4840 | 1659 if (!(gtkblist && gtkblist->window)) |
1660 return; | |
1661 | |
4698 | 1662 if (show) { |
4840 | 1663 gaim_gtk_blist_restore_position(); |
4699 | 1664 gtk_window_present(GTK_WINDOW(gtkblist->window)); |
4698 | 1665 } else { |
1666 if (!connections || docklet_count) { | |
1667 #ifdef _WIN32 | |
4711
0c1f3e651d3e
[gaim-migrate @ 5022]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4706
diff
changeset
|
1668 wgaim_systray_minimize(gtkblist->window); |
4698 | 1669 #endif |
1670 gtk_widget_hide(gtkblist->window); | |
1671 } else { | |
1672 gtk_window_iconify(GTK_WINDOW(gtkblist->window)); | |
1673 } | |
1674 } | |
1675 } | |
1676 | |
1677 void gaim_gtk_blist_docklet_toggle() { | |
1678 /* Useful for the docklet plugin and also for the win32 tray icon*/ | |
1679 /* This is called when one of those is clicked--it will show/hide the | |
1680 buddy list/login window--depending on which is active */ | |
4840 | 1681 if (connections) { |
1682 if (gtkblist && gtkblist->window) { | |
1683 if (GTK_WIDGET_VISIBLE(gtkblist->window)) { | |
1684 gaim_blist_set_visible(GAIM_WINDOW_ICONIFIED(gtkblist->window) || gaim_gtk_blist_obscured); | |
1685 } else { | |
4698 | 1686 #if _WIN32 |
4840 | 1687 wgaim_systray_maximize(gtkblist->window); |
4698 | 1688 #endif |
4840 | 1689 gaim_blist_set_visible(TRUE); |
1690 } | |
1691 } else { | |
1692 /* we're logging in or something... do nothing */ | |
1693 /* or should I make the blist? */ | |
1694 debug_printf("docklet_toggle called with connections but no blist!\n"); | |
4698 | 1695 } |
4840 | 1696 } else if (mainwindow) { |
1697 if (GTK_WIDGET_VISIBLE(mainwindow)) { | |
4698 | 1698 if (GAIM_WINDOW_ICONIFIED(mainwindow)) { |
1699 gtk_window_present(GTK_WINDOW(mainwindow)); | |
1700 } else { | |
1701 #if _WIN32 | |
1702 wgaim_systray_minimize(mainwindow); | |
1703 #endif | |
1704 gtk_widget_hide(mainwindow); | |
1705 } | |
1706 } else { | |
1707 #if _WIN32 | |
1708 wgaim_systray_maximize(mainwindow); | |
1709 #endif | |
4833 | 1710 show_login(); |
4698 | 1711 } |
4840 | 1712 } else { |
1713 show_login(); | |
4698 | 1714 } |
1715 } | |
1716 | |
1717 void gaim_gtk_blist_docklet_add() | |
1718 { | |
1719 docklet_count++; | |
1720 } | |
1721 | |
1722 void gaim_gtk_blist_docklet_remove() | |
1723 { | |
1724 docklet_count--; | |
1725 if (!docklet_count) { | |
4944 | 1726 if (connections) |
4698 | 1727 gaim_blist_set_visible(TRUE); |
4944 | 1728 else if (mainwindow) |
4840 | 1729 gtk_window_present(GTK_WINDOW(mainwindow)); |
4944 | 1730 else |
4840 | 1731 show_login(); |
4698 | 1732 } |
4687 | 1733 } |
1 | 1734 |
4687 | 1735 static struct gaim_blist_ui_ops blist_ui_ops = |
1736 { | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1737 gaim_gtk_blist_new_list, |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1738 gaim_gtk_blist_new_node, |
4687 | 1739 gaim_gtk_blist_show, |
1740 gaim_gtk_blist_update, | |
1741 gaim_gtk_blist_remove, | |
1742 gaim_gtk_blist_destroy, | |
1743 gaim_gtk_blist_set_visible | |
1744 }; | |
1 | 1745 |
1746 | |
4687 | 1747 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
|
1748 { |
4687 | 1749 return &blist_ui_ops; |
1037
1c663beef29d
[gaim-migrate @ 1047]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1036
diff
changeset
|
1750 } |
1c663beef29d
[gaim-migrate @ 1047]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1036
diff
changeset
|
1751 |
3131 | 1752 |
1753 | |
4687 | 1754 /********************************************************************* |
1755 * Public utility functions * | |
1756 *********************************************************************/ | |
1058
4927ce25d8cc
[gaim-migrate @ 1068]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1757 |
4687 | 1758 GdkPixbuf * |
1759 create_prpl_icon(struct gaim_account *account) | |
4553
d03fcb3f4be2
[gaim-migrate @ 4833]
Christian Hammond <chipx86@chipx86.com>
parents:
4525
diff
changeset
|
1760 { |
4687 | 1761 struct prpl *prpl = find_prpl(account->protocol); |
1762 GdkPixbuf *status = NULL; | |
1763 char *filename = NULL; | |
1764 const char *protoname = prpl->list_icon(account, NULL); | |
1765 /* "Hey, what's all this crap?" you ask. Status icons will be themeable too, and | |
1766 then it will look up protoname from the theme */ | |
1767 if (!strcmp(protoname, "aim")) { | |
1768 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "aim.png", NULL); | |
1769 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1770 g_free(filename); | |
1771 } else if (!strcmp(protoname, "yahoo")) { | |
1772 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "yahoo.png", NULL); | |
1773 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1774 g_free(filename); | |
1775 } else if (!strcmp(protoname, "msn")) { | |
1776 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "msn.png", NULL); | |
1777 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1778 g_free(filename); | |
1779 } else if (!strcmp(protoname, "jabber")) { | |
1780 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "jabber.png", NULL); | |
1781 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1782 g_free(filename); | |
1783 } else if (!strcmp(protoname, "icq")) { | |
1784 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "icq.png", NULL); | |
1785 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1786 g_free(filename); | |
1787 } else if (!strcmp(protoname, "gadu-gadu")) { | |
1788 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "gadugadu.png", NULL); | |
1789 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1790 g_free(filename); | |
1791 } else if (!strcmp(protoname, "napster")) { | |
1792 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "napster.png", NULL); | |
1793 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1794 g_free(filename); | |
1795 } else if (!strcmp(protoname, "irc")) { | |
1796 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "irc.png", NULL); | |
1797 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1798 g_free(filename); | |
960
fa681641643d
[gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
945
diff
changeset
|
1799 } |
4687 | 1800 return status; |
1 | 1801 } |
4699 | 1802 |