Mercurial > pidgin
annotate src/buddy.c @ 4999:abe9720a0615
[gaim-migrate @ 5334]
make the IM button do something when a buddy isn't selected
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Fri, 04 Apr 2003 21:09:11 +0000 |
parents | 1f92610b0772 |
children | 17f5e6628b37 |
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); | |
4999 | 181 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { |
4692 | 182 gaim_conversation_new(GAIM_CONV_IM, ((struct buddy*)node)->account, ((struct buddy*)node)->name); |
4999 | 183 return; |
184 } | |
4692 | 185 } |
4999 | 186 show_im_dialog(); |
4694 | 187 } |
4692 | 188 |
4694 | 189 static void gtk_blist_button_info_cb(GtkWidget *w, GtkTreeView *tv) |
190 { | |
191 GtkTreeIter iter; | |
192 GtkTreeModel *model = gtk_tree_view_get_model(tv); | |
193 GtkTreeSelection *sel = gtk_tree_view_get_selection(tv); | |
4692 | 194 |
4694 | 195 if(gtk_tree_selection_get_selected(sel, &model, &iter)){ |
196 GaimBlistNode *node; | |
197 | |
198 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
199 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
200 serv_get_info(((struct buddy*)node)->account->gc, ((struct buddy*)node)->name); | |
201 return; | |
202 } | |
203 } | |
204 show_info_dialog(); | |
205 } | |
206 | |
207 static void gtk_blist_button_chat_cb(GtkWidget *w, gpointer data) | |
208 { | |
209 /* FIXME: someday, we can check to see if we've selected a chat node */ | |
210 join_chat(); | |
211 } | |
212 | |
213 static void gtk_blist_button_away_cb(GtkWidget *w, gpointer data) | |
214 { | |
215 gtk_menu_popup(GTK_MENU(awaymenu), NULL, NULL, NULL, NULL, 1, GDK_CURRENT_TIME); | |
4692 | 216 } |
217 | |
4687 | 218 static void gtk_blist_row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) { |
219 GaimBlistNode *node; | |
220 GtkTreeIter iter; | |
221 GValue val = { 0, }; | |
4936 | 222 |
4687 | 223 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); |
4936 | 224 |
4687 | 225 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); |
226 node = g_value_get_pointer(&val); | |
4936 | 227 |
4687 | 228 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { |
4911 | 229 struct gaim_conversation *conv = |
230 gaim_conversation_new(GAIM_CONV_IM, ((struct buddy*)node)->account, ((struct buddy*)node)->name); | |
231 if(conv) { | |
232 gaim_window_raise(gaim_conversation_get_window(conv)); | |
233 gaim_window_switch_conversation( | |
234 gaim_conversation_get_window(conv), | |
235 gaim_conversation_get_index(conv)); | |
236 } | |
4697 | 237 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { |
238 if (gtk_tree_view_row_expanded(tv, path)) | |
239 gtk_tree_view_collapse_row(tv, path); | |
240 else | |
241 gtk_tree_view_expand_row(tv,path,FALSE); | |
1 | 242 } |
243 } | |
244 | |
4916 | 245 static void gaim_gtk_blist_add_buddy_cb() |
246 { | |
247 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)); | |
248 GtkTreeIter iter; | |
249 GaimBlistNode *node; | |
250 | |
251 if(gtk_tree_selection_get_selected(sel, NULL, &iter)){ | |
252 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
253 if (GAIM_BLIST_NODE_IS_BUDDY(node)) | |
254 show_add_buddy(NULL, NULL, ((struct group*)node->parent)->name, NULL); | |
255 else if (GAIM_BLIST_NODE_IS_GROUP(node)) | |
256 show_add_buddy(NULL, NULL, ((struct group*)node)->name, NULL); | |
257 } | |
258 else { | |
259 show_add_buddy(NULL, NULL, NULL, NULL); | |
260 } | |
261 } | |
4921 | 262 static void |
4916 | 263 gaim_gtk_blist_remove_cb (GtkWidget *w, GaimBlistNode *node) |
264 { | |
265 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
266 struct buddy *b = (struct buddy*)node; | |
267 show_confirm_del(b->account->gc, b->name); | |
268 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
269 struct group *g = (struct group*)node; | |
270 show_confirm_del_group(g); | |
271 } | |
272 } | |
273 | |
4687 | 274 static void gaim_proto_menu_cb(GtkMenuItem *item, struct buddy *b) |
1 | 275 { |
4687 | 276 struct proto_buddy_menu *pbm = g_object_get_data(G_OBJECT(item), "gaimcallback"); |
277 if (pbm->callback) | |
278 pbm->callback(pbm->gc, b->name); | |
1396
df7c3cacac92
[gaim-migrate @ 1406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1392
diff
changeset
|
279 } |
1 | 280 |
4687 | 281 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
|
282 { |
4687 | 283 GtkTreePath *path; |
284 GaimBlistNode *node; | |
285 GValue val = { 0, }; | |
286 GtkTreeIter iter; | |
287 GtkWidget *menu, *menuitem; | |
288 GtkWidget *image; | |
4702 | 289 GtkTreeSelection *sel; |
4687 | 290 GList *list; |
291 struct prpl *prpl; | |
1391
d606da211acb
[gaim-migrate @ 1401]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1376
diff
changeset
|
292 |
4687 | 293 if (event->button != 3) |
294 return FALSE; | |
4718 | 295 |
4687 | 296 /* Here we figure out which node was clicked */ |
297 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL)) | |
298 return FALSE; | |
299 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
300 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
301 node = g_value_get_pointer(&val); | |
302 menu = gtk_menu_new(); | |
3251 | 303 |
4916 | 304 if (GAIM_BLIST_NODE_IS_GROUP(node)) { |
305 menuitem = gtk_image_menu_item_new_with_mnemonic(_("_Add a Buddy")); | |
306 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gaim_gtk_blist_add_buddy_cb), node); | |
307 image = gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU); | |
308 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); | |
309 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
310 | |
311 menuitem = gtk_image_menu_item_new_with_mnemonic(_("_Delete Group")); | |
312 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gaim_gtk_blist_remove_cb), node); | |
313 image = gtk_image_new_from_stock(GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU); | |
314 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); | |
315 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
316 | |
317 menuitem = gtk_image_menu_item_new_with_mnemonic(_("_Rename")); | |
318 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(show_rename_group), node); | |
319 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
320 } else if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
321 /* Protocol specific options */ | |
322 prpl = find_prpl(((struct buddy*)node)->account->protocol); | |
323 | |
324 if(prpl && prpl->get_info) { | |
325 menuitem = gtk_image_menu_item_new_with_mnemonic(_("_Get Info")); | |
326 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_info_cb), node); | |
327 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
328 } | |
4732 | 329 |
4916 | 330 menuitem = gtk_image_menu_item_new_with_mnemonic(_("_IM")); |
331 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_im_cb), node); | |
332 image = gtk_image_new_from_stock(GAIM_STOCK_IM, GTK_ICON_SIZE_MENU); | |
333 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); | |
334 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
335 | |
336 menuitem = gtk_image_menu_item_new_with_mnemonic(_("Add Buddy _Pounce")); | |
337 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_bp_cb), node); | |
338 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
339 | |
340 menuitem = gtk_image_menu_item_new_with_mnemonic(_("View _Log")); | |
341 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_showlog_cb), node); | |
342 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
343 | |
344 if (prpl) { | |
345 list = prpl->buddy_menu(((struct buddy*)node)->account->gc, ((struct buddy*)node)->name); | |
346 while (list) { | |
347 struct proto_buddy_menu *pbm = list->data; | |
348 menuitem = gtk_menu_item_new_with_mnemonic(pbm->label); | |
349 g_object_set_data(G_OBJECT(menuitem), "gaimcallback", pbm); | |
350 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gaim_proto_menu_cb), node); | |
351 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
352 list = list->next; | |
353 } | |
354 } | |
355 | |
356 gaim_separator(menu); | |
357 | |
358 menuitem = gtk_image_menu_item_new_with_mnemonic(_("_Alias")); | |
359 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_alias_cb), node); | |
360 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
361 | |
362 menuitem = gtk_image_menu_item_new_with_mnemonic(_("_Remove")); | |
363 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gaim_gtk_blist_remove_cb), node); | |
364 image = gtk_image_new_from_stock(GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU); | |
365 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); | |
4732 | 366 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
367 } | |
4916 | 368 |
4687 | 369 gtk_widget_show_all(menu); |
370 | |
371 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time); | |
1 | 372 |
4702 | 373 #if (1) /* This code only exists because GTK doesn't work. If we return FALSE here, as would be normal |
374 * the event propoagates down and somehow gets interpreted as the start of a drag event. */ | |
375 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv)); | |
376 gtk_tree_selection_select_path(sel, path); | |
4721 | 377 gtk_tree_path_free(path); |
4702 | 378 return TRUE; |
379 #endif | |
1 | 380 } |
381 | |
4944 | 382 static void gaim_gtk_blist_edit_mode_cb(gpointer callback_data, guint callback_action, |
4936 | 383 GtkWidget *checkitem) { |
4916 | 384 GdkCursor *cursor = gdk_cursor_new(GDK_WATCH); |
385 gdk_window_set_cursor(gtkblist->window->window, cursor); | |
386 while (gtk_events_pending()) | |
387 gtk_main_iteration(); | |
4936 | 388 if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(checkitem))) |
389 blist_options |= OPT_BLIST_SHOW_OFFLINE; | |
390 else | |
391 blist_options &= ~OPT_BLIST_SHOW_OFFLINE; | |
4929 | 392 save_prefs(); |
4916 | 393 gdk_cursor_unref(cursor); |
394 cursor = gdk_cursor_new(GDK_LEFT_PTR); | |
395 gdk_window_set_cursor(gtkblist->window->window, cursor); | |
396 gdk_cursor_unref(cursor); | |
397 gaim_gtk_blist_refresh(gaim_get_blist()); | |
398 } | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4349
diff
changeset
|
399 |
4944 | 400 /* This is called 10 seconds after the buddy logs in. It removes the "logged in" icon and replaces it with |
401 * the normal status icon. Make sure they didn't sign off in the mean-time though. */ | |
1 | 402 |
4944 | 403 static gboolean gaim_reset_present_icon (GaimBlistNode *b) |
404 { | |
405 if (((struct buddy *)b)->present == 2) { | |
406 ((struct buddy *)b)->present = 1; | |
407 gaim_gtk_blist_update(NULL, b); | |
4697 | 408 } |
4944 | 409 |
410 return FALSE; | |
4697 | 411 } |
1 | 412 |
4702 | 413 static void gaim_gtk_blist_drag_data_get_cb (GtkWidget *widget, |
414 GdkDragContext *dc, | |
415 GtkSelectionData *data, | |
416 guint info, | |
417 guint time, | |
418 gpointer *null) | |
419 { | |
4781 | 420 if (data->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE)) { |
4702 | 421 GtkTreeRowReference *ref = g_object_get_data(G_OBJECT(dc), "gtk-tree-view-source-row"); |
422 GtkTreePath *sourcerow = gtk_tree_row_reference_get_path(ref); | |
423 GtkTreeIter iter; | |
424 GaimBlistNode *node = NULL; | |
425 GValue val = {0}; | |
426 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, sourcerow); | |
427 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
428 node = g_value_get_pointer(&val); | |
4781 | 429 gtk_selection_data_set (data, |
430 gdk_atom_intern ("GAIM_BLIST_NODE", FALSE), | |
431 8, /* bits */ | |
432 (void*)&node, | |
433 sizeof (node)); | |
434 | |
4721 | 435 gtk_tree_path_free(sourcerow); |
4702 | 436 } |
4781 | 437 |
4702 | 438 } |
439 | |
440 static void gaim_gtk_blist_drag_data_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, | |
441 GtkSelectionData *sd, guint info, guint t) | |
442 { | |
4781 | 443 if (sd->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE) && sd->data) { |
444 GaimBlistNode *n = NULL; | |
4702 | 445 GtkTreePath *path = NULL; |
4704 | 446 GtkTreeViewDropPosition position; |
4781 | 447 memcpy(&n, sd->data, sizeof(n)); |
4704 | 448 if(gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), x, y, &path, &position)) { |
449 /* if we're here, I think it means the drop is ok */ | |
4770 | 450 GtkTreeIter iter; |
451 GaimBlistNode *node; | |
452 GValue val = {0}; | |
453 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
454 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
455 node = g_value_get_pointer(&val); | |
4781 | 456 |
457 if (GAIM_BLIST_NODE_IS_BUDDY(n)) { | |
458 struct buddy *b = (struct buddy*)n; | |
459 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
4795 | 460 switch(position) { |
461 case GTK_TREE_VIEW_DROP_AFTER: | |
462 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
463 gaim_blist_add_buddy(b, (struct group*)node->parent, node); | |
464 break; | |
465 case GTK_TREE_VIEW_DROP_BEFORE: | |
466 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
467 gaim_blist_add_buddy(b, (struct group*)node->parent, node->prev); | |
468 break; | |
4781 | 469 } |
470 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
471 gaim_blist_add_buddy(b, (struct group*)node, NULL); | |
4795 | 472 } |
4781 | 473 } else if (GAIM_BLIST_NODE_IS_GROUP(n)) { |
474 struct group *g = (struct group*)n; | |
475 if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
476 switch (position) { | |
477 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
478 case GTK_TREE_VIEW_DROP_AFTER: | |
479 gaim_blist_add_group(g, node); | |
480 break; | |
481 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
482 case GTK_TREE_VIEW_DROP_BEFORE: | |
483 gaim_blist_add_group(g, node->prev); | |
484 break; | |
485 } | |
486 | |
4770 | 487 } |
4781 | 488 |
4777 | 489 } |
4781 | 490 |
4721 | 491 gtk_tree_path_free(path); |
4970 | 492 gaim_blist_save(); |
4704 | 493 } |
4702 | 494 } |
495 } | |
496 | |
4724 | 497 static void gaim_gtk_blist_paint_tip(GtkWidget *widget, GdkEventExpose *event, struct buddy *b) |
498 { | |
499 GtkStyle *style; | |
500 GdkPixbuf *pixbuf = gaim_gtk_blist_get_status_icon(b, GAIM_STATUS_ICON_LARGE); | |
501 PangoLayout *layout; | |
502 char *tooltiptext = gaim_get_tooltip_text(b); | |
503 | |
504 layout = gtk_widget_create_pango_layout (gtkblist->tipwindow, NULL); | |
505 pango_layout_set_markup(layout, tooltiptext, strlen(tooltiptext)); | |
4732 | 506 pango_layout_set_wrap(layout, PANGO_WRAP_WORD); |
4733 | 507 pango_layout_set_width(layout, 300000); |
4724 | 508 style = gtkblist->tipwindow->style; |
4732 | 509 |
4724 | 510 gtk_paint_flat_box (style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, |
511 NULL, gtkblist->tipwindow, "tooltip", 0, 0, -1, -1); | |
4729 | 512 |
513 #if GTK_CHECK_VERSION(2,2,0) | |
4724 | 514 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, pixbuf, |
515 0, 0, 4, 4, -1 , -1, GDK_RGB_DITHER_NONE, 0, 0); | |
4729 | 516 #else |
4758 | 517 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 | 518 #endif |
4724 | 519 |
520 gtk_paint_layout (style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, TRUE, | |
521 NULL, gtkblist->tipwindow, "tooltip", 38, 4, layout); | |
522 | |
523 g_object_unref (pixbuf); | |
524 g_object_unref (layout); | |
525 g_free(tooltiptext); | |
526 return; | |
527 } | |
528 | |
529 static gboolean gaim_gtk_blist_tooltip_timeout(GtkWidget *tv) | |
530 { | |
531 GtkTreePath *path; | |
532 GtkTreeIter iter; | |
533 GaimBlistNode *node; | |
534 GValue val = {0}; | |
535 | |
536 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), gtkblist->rect.x, gtkblist->rect.y, &path, NULL, NULL, NULL)) | |
537 return FALSE; | |
538 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
539 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
540 node = g_value_get_pointer(&val); | |
541 | |
542 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
543 int scr_w,scr_h, w, h, x, y; | |
544 PangoLayout *layout; | |
545 struct buddy *buddy = (struct buddy*)node; | |
546 char *tooltiptext = gaim_get_tooltip_text(buddy); | |
547 gtkblist->tipwindow = gtk_window_new(GTK_WINDOW_POPUP); | |
4907
68e2b07ef8d7
[gaim-migrate @ 5241]
Christian Hammond <chipx86@chipx86.com>
parents:
4883
diff
changeset
|
548 gtkblist->tipwindow->parent = tv; |
4724 | 549 gtk_widget_set_app_paintable(gtkblist->tipwindow, TRUE); |
4729 | 550 gtk_window_set_resizable(GTK_WINDOW(gtkblist->tipwindow), FALSE); |
4724 | 551 gtk_widget_set_name(gtkblist->tipwindow, "gtk-tooltips"); |
552 g_signal_connect(G_OBJECT(gtkblist->tipwindow), "expose_event", | |
553 G_CALLBACK(gaim_gtk_blist_paint_tip), buddy); | |
554 gtk_widget_ensure_style (gtkblist->tipwindow); | |
555 | |
556 layout = gtk_widget_create_pango_layout (gtkblist->tipwindow, NULL); | |
4733 | 557 pango_layout_set_wrap(layout, PANGO_WRAP_WORD); |
558 pango_layout_set_width(layout, 300000); | |
4724 | 559 pango_layout_set_markup(layout, tooltiptext, strlen(tooltiptext)); |
560 scr_w = gdk_screen_width(); | |
561 scr_h = gdk_screen_height(); | |
562 pango_layout_get_size (layout, &w, &h); | |
563 w = PANGO_PIXELS(w) + 8; | |
564 h = PANGO_PIXELS(h) + 8; | |
565 | |
566 /* 38 is the size of a large status icon plus 4 pixels padding on each side. | |
567 I should #define this or something */ | |
568 w = w + 38; | |
569 h = MAX(h, 38); | |
570 | |
571 gdk_window_get_pointer(NULL, &x, &y, NULL); | |
572 if (GTK_WIDGET_NO_WINDOW(gtkblist->window)) | |
573 y+=gtkblist->window->allocation.y; | |
574 | |
575 x -= ((w >> 1) + 4); | |
576 | |
577 if ((x + w) > scr_w) | |
578 x -= (x + w) - scr_w; | |
579 else if (x < 0) | |
580 x = 0; | |
581 | |
582 if ((y + h + 4) > scr_h) | |
583 y = y - h; | |
584 else | |
585 y = y + 6; | |
586 g_object_unref (layout); | |
587 g_free(tooltiptext); | |
588 gtk_widget_set_size_request(gtkblist->tipwindow, w, h); | |
4729 | 589 gtk_window_move(GTK_WINDOW(gtkblist->tipwindow), x, y); |
4724 | 590 gtk_widget_show(gtkblist->tipwindow); |
591 } | |
4729 | 592 |
4724 | 593 gtk_tree_path_free(path); |
594 return FALSE; | |
595 } | |
596 | |
4730 | 597 static gboolean gaim_gtk_blist_motion_cb (GtkWidget *tv, GdkEventMotion *event, gpointer null) |
4724 | 598 { |
599 GtkTreePath *path; | |
600 if (gtkblist->timeout) { | |
601 if ((event->y > gtkblist->rect.y) && ((event->y - gtkblist->rect.height) < gtkblist->rect.y)) | |
4732 | 602 return FALSE; |
4724 | 603 /* We've left the cell. Remove the timeout and create a new one below */ |
604 if (gtkblist->tipwindow) { | |
605 gtk_widget_destroy(gtkblist->tipwindow); | |
606 gtkblist->tipwindow = NULL; | |
607 } | |
608 | |
609 g_source_remove(gtkblist->timeout); | |
610 } | |
611 | |
612 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL); | |
613 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, >kblist->rect); | |
614 if (path) | |
615 gtk_tree_path_free(path); | |
616 gtkblist->timeout = g_timeout_add(500, (GSourceFunc)gaim_gtk_blist_tooltip_timeout, tv); | |
4730 | 617 return FALSE; |
4724 | 618 } |
619 | |
620 static void gaim_gtk_blist_leave_cb (GtkWidget *w, GdkEventCrossing *e, gpointer n) | |
621 { | |
4978 | 622 if (gtkblist->timeout) { |
623 g_source_remove(gtkblist->timeout); | |
624 gtkblist->timeout = 0; | |
625 } | |
4724 | 626 if (gtkblist->tipwindow) { |
627 gtk_widget_destroy(gtkblist->tipwindow); | |
628 gtkblist->tipwindow = NULL; | |
629 } | |
4978 | 630 } |
4724 | 631 |
4687 | 632 /*************************************************** |
633 * Crap * | |
634 ***************************************************/ | |
635 static GtkItemFactoryEntry blist_menu[] = | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
636 { |
4687 | 637 /* Buddies menu */ |
638 { N_("/_Buddies"), NULL, NULL, 0, "<Branch>" }, | |
4916 | 639 { N_("/Buddies/New _Instant Message..."), "<CTL>I", show_im_dialog, 0, |
4687 | 640 "<StockItem>", GAIM_STOCK_IM }, |
641 { N_("/Buddies/Join a _Chat..."), "<CTL>C", join_chat, 0, | |
642 "<StockItem>", GAIM_STOCK_CHAT }, | |
4834 | 643 { "/Buddies/sep1", NULL, NULL, 0, "<Separator>" }, |
4687 | 644 { N_("/Buddies/Get _User Info..."), "<CTL>J", show_info_dialog, 0, |
645 "<StockItem>", GAIM_STOCK_INFO }, | |
4834 | 646 { "/Buddies/sep2", NULL, NULL, 0, "<Separator>" }, |
4983 | 647 { N_("/Buddies/_Show Offline Buddies"), NULL, gaim_gtk_blist_edit_mode_cb, 1, "<CheckItem>"}, |
648 { N_("/Buddies/_Add a Buddy..."), NULL, gaim_gtk_blist_add_buddy_cb, 0, "<StockItem>", GTK_STOCK_ADD }, | |
649 { N_("/Buddies/Add a _Group..."), NULL, show_add_group, 0, NULL}, | |
650 { "/Buddies/sep3", NULL, NULL, 0, "<Separator>" }, | |
4687 | 651 { N_("/Buddies/_Signoff"), "<CTL>D", signoff_all, 0, NULL }, |
652 { N_("/Buddies/_Quit"), "<CTL>Q", do_quit, 0, | |
653 "<StockItem>", GTK_STOCK_QUIT }, | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
654 |
4687 | 655 /* Tools */ |
656 { N_("/_Tools"), NULL, NULL, 0, "<Branch>" }, | |
657 { N_("/Tools/_Away"), NULL, NULL, 0, "<Branch>" }, | |
658 { N_("/Tools/Buddy _Pounce"), NULL, NULL, 0, "<Branch>" }, | |
4916 | 659 { N_("/Tools/sep1"), NULL, NULL, 0, "<Separator>" }, |
4698 | 660 { N_("/Tools/_File Transfers"), NULL, gaim_show_xfer_dialog, 0, |
4687 | 661 "<StockItem>", GTK_STOCK_REVERT_TO_SAVED }, |
4834 | 662 { "/Tools/sep2", NULL, NULL, 0, "<Separator>" }, |
4687 | 663 { N_("/Tools/P_rotocol Actions"), NULL, NULL, 0, "<Branch>" }, |
4697 | 664 { N_("/Tools/View System _Log"), NULL, gtk_blist_show_systemlog_cb, 0, NULL }, |
4983 | 665 { "/Tools/sep3", NULL, NULL, 0, "<Separator>" }, |
666 { N_("/Tools/A_ccounts"), "<CTL>A", account_editor, 0, NULL }, | |
667 { N_("/Tools/Preferences"), "<CTL>P", show_prefs, 0, | |
668 "<StockItem>", GTK_STOCK_PREFERENCES }, | |
669 { N_("/Tools/Pr_ivacy"), NULL, show_privacy_options, 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 : "", |
4980 | 740 !g_ascii_strcasecmp(b->name, "robflynn") ? "\n<b>Description:</b> Spooky" : ""); |
4968 | 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)) { |
4978 | 951 if ((b->idle > 0 && blist_options & OPT_BLIST_GREY_IDLERS && !selected) || b->present == 0) { |
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_pos.width != 0) { | |
1052 /* ...check position is on screen... */ | |
1053 if (blist_pos.x >= gdk_screen_width()) | |
1054 blist_pos.x = gdk_screen_width() - 100; | |
1055 else if (blist_pos.x < 0) | |
1056 blist_pos.x = 100; | |
1057 | |
1058 if (blist_pos.y >= gdk_screen_height()) | |
1059 blist_pos.y = gdk_screen_height() - 100; | |
1060 else if (blist_pos.y < 0) | |
1061 blist_pos.y = 100; | |
1062 | |
1063 /* ...and move it back. */ | |
1064 gtk_window_move(GTK_WINDOW(gtkblist->window), blist_pos.x, blist_pos.y); | |
1065 gtk_window_resize(GTK_WINDOW(gtkblist->window), blist_pos.width, blist_pos.height); | |
1066 } | |
1067 } | |
1068 | |
4944 | 1069 static gboolean gaim_gtk_blist_refresh_timer(struct gaim_buddy_list *list) |
1070 { | |
1071 GaimBlistNode *group = list->root; | |
1072 GaimBlistNode *buddy; | |
1073 | |
1074 while (group) { | |
1075 buddy = group->child; | |
1076 while (buddy) { | |
1077 if (((struct buddy *)buddy)->idle) | |
1078 gaim_gtk_blist_update(list, buddy); | |
1079 buddy = buddy->next; | |
1080 } | |
1081 group = group->next; | |
1082 } | |
1083 | |
1084 /* keep on going */ | |
1085 return TRUE; | |
1086 } | |
4840 | 1087 |
4687 | 1088 /********************************************************************************** |
1089 * Public API Functions * | |
1090 **********************************************************************************/ | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1091 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
|
1092 { |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1093 blist->ui_data = g_new0(struct gaim_gtk_buddy_list, 1); |
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 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1096 static void gaim_gtk_blist_new_node(GaimBlistNode *node) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1097 { |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1098 node->ui_data = g_new0(struct gaim_gtk_blist_node, 1); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1099 } |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1100 |
4729 | 1101 void gaim_gtk_blist_update_columns() |
1102 { | |
1103 if (blist_options & OPT_BLIST_SHOW_ICONS) { | |
1104 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, TRUE); | |
1105 gtk_tree_view_column_set_visible(gtkblist->idle_column, FALSE); | |
1106 gtk_tree_view_column_set_visible(gtkblist->warning_column, FALSE); | |
1107 } else { | |
1108 gtk_tree_view_column_set_visible(gtkblist->idle_column, blist_options & OPT_BLIST_SHOW_IDLETIME); | |
1109 gtk_tree_view_column_set_visible(gtkblist->warning_column, blist_options & OPT_BLIST_SHOW_WARN); | |
1110 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, FALSE); | |
1111 } | |
1112 } | |
1113 | |
4702 | 1114 enum {DRAG_BUDDY, DRAG_ROW}; |
1115 | |
4834 | 1116 static char * |
1117 item_factory_translate_func (const char *path, gpointer func_data) | |
1118 { | |
1119 return _(path); | |
1120 } | |
1121 | |
4687 | 1122 static void gaim_gtk_blist_show(struct gaim_buddy_list *list) |
1123 { | |
1124 GtkItemFactory *ift; | |
1125 GtkCellRenderer *rend; | |
1126 GtkTreeViewColumn *column; | |
1127 GtkWidget *sw; | |
1128 GtkWidget *button; | |
4973 | 1129 GtkTooltips *tooltips; |
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")); |
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")) { | |
4987 | 1788 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "gadu-gadu.png", NULL); |
4687 | 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 |