Mercurial > pidgin
annotate src/buddy.c @ 4801:ef6d17c83328
[gaim-migrate @ 5121]
(15:36:59) mbp: Hi Luke, I'm the Danish translator of gaim, I send you a couple of patches that you comitted. I have a new one (because of changes in the buddy list). Can you apply it?
(15:37:08) Luke: cando
(15:37:22) mbp: http://mbrix.dk/~mbp/da_po.diff
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sun, 16 Mar 2003 20:41:19 +0000 |
parents | 9561a1104131 |
children | 315ef59a5031 |
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 |
4698 | 59 /* Docklet nonsense */ |
60 static gboolean gaim_gtk_blist_obscured = FALSE; | |
61 | |
4687 | 62 static void gaim_gtk_blist_update(struct gaim_buddy_list *list, GaimBlistNode *node); |
4724 | 63 static char *gaim_get_tooltip_text(struct buddy *b); |
64 static GdkPixbuf *gaim_gtk_blist_get_status_icon(struct buddy *b, GaimStatusIconSize size); | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
65 |
4687 | 66 /*************************************************** |
67 * Callbacks * | |
68 ***************************************************/ | |
3869 | 69 |
4698 | 70 static void gaim_gtk_blist_destroy_cb() |
71 { | |
72 if (docklet_count) | |
73 gaim_blist_set_visible(FALSE); | |
74 else | |
75 do_quit(); | |
76 } | |
77 | |
4732 | 78 static void gtk_blist_menu_info_cb(GtkWidget *w, struct buddy *b) |
79 { | |
80 serv_get_info(b->account->gc, b->name); | |
81 } | |
82 | |
4697 | 83 static void gtk_blist_menu_im_cb(GtkWidget *w, struct buddy *b) |
84 { | |
85 gaim_conversation_new(GAIM_CONV_IM, b->account, b->name); | |
86 } | |
87 | |
88 static void gtk_blist_menu_alias_cb(GtkWidget *w, struct buddy *b) | |
89 { | |
90 alias_dialog_bud(b); | |
91 } | |
92 | |
93 static void gtk_blist_menu_bp_cb(GtkWidget *w, struct buddy *b) | |
94 { | |
95 show_new_bp(b->name, b->account->gc, b->idle, | |
96 b->uc & UC_UNAVAILABLE, NULL); | |
97 } | |
98 | |
99 static void gtk_blist_menu_showlog_cb(GtkWidget *w, struct buddy *b) | |
100 { | |
101 show_log(b->name); | |
102 } | |
103 | |
104 static void gtk_blist_show_systemlog_cb() | |
105 { | |
106 show_log(NULL); | |
107 } | |
108 | |
4776 | 109 static void gtk_blist_show_onlinehelp_cb() |
110 { | |
111 open_url(NULL, "http://gaim.sourceforge.net/documentation.php"); | |
112 } | |
113 | |
4692 | 114 static void gtk_blist_button_im_cb(GtkWidget *w, GtkTreeView *tv) |
115 { | |
116 GtkTreeIter iter; | |
117 GtkTreeModel *model = gtk_tree_view_get_model(tv); | |
118 GtkTreeSelection *sel = gtk_tree_view_get_selection(tv); | |
119 | |
120 if(gtk_tree_selection_get_selected(sel, &model, &iter)){ | |
121 GaimBlistNode *node; | |
122 | |
123 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
124 if (GAIM_BLIST_NODE_IS_BUDDY(node)) | |
125 gaim_conversation_new(GAIM_CONV_IM, ((struct buddy*)node)->account, ((struct buddy*)node)->name); | |
126 } | |
4694 | 127 } |
4692 | 128 |
4694 | 129 static void gtk_blist_button_info_cb(GtkWidget *w, GtkTreeView *tv) |
130 { | |
131 GtkTreeIter iter; | |
132 GtkTreeModel *model = gtk_tree_view_get_model(tv); | |
133 GtkTreeSelection *sel = gtk_tree_view_get_selection(tv); | |
4692 | 134 |
4694 | 135 if(gtk_tree_selection_get_selected(sel, &model, &iter)){ |
136 GaimBlistNode *node; | |
137 | |
138 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
139 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
140 serv_get_info(((struct buddy*)node)->account->gc, ((struct buddy*)node)->name); | |
141 return; | |
142 } | |
143 } | |
144 show_info_dialog(); | |
145 } | |
146 | |
147 static void gtk_blist_button_chat_cb(GtkWidget *w, gpointer data) | |
148 { | |
149 /* FIXME: someday, we can check to see if we've selected a chat node */ | |
150 join_chat(); | |
151 } | |
152 | |
153 static void gtk_blist_button_away_cb(GtkWidget *w, gpointer data) | |
154 { | |
155 gtk_menu_popup(GTK_MENU(awaymenu), NULL, NULL, NULL, NULL, 1, GDK_CURRENT_TIME); | |
4692 | 156 } |
157 | |
4687 | 158 static void gtk_blist_row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) { |
159 GaimBlistNode *node; | |
160 GtkTreeIter iter; | |
161 GValue val = { 0, }; | |
3154 | 162 |
4687 | 163 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); |
164 | |
165 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
166 node = g_value_get_pointer(&val); | |
167 | |
168 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
169 gaim_conversation_new(GAIM_CONV_IM, ((struct buddy*)node)->account, ((struct buddy*)node)->name); | |
4697 | 170 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { |
171 if (gtk_tree_view_row_expanded(tv, path)) | |
172 gtk_tree_view_collapse_row(tv, path); | |
173 else | |
174 gtk_tree_view_expand_row(tv,path,FALSE); | |
1 | 175 } |
176 } | |
177 | |
4687 | 178 static void gaim_proto_menu_cb(GtkMenuItem *item, struct buddy *b) |
1 | 179 { |
4687 | 180 struct proto_buddy_menu *pbm = g_object_get_data(G_OBJECT(item), "gaimcallback"); |
181 if (pbm->callback) | |
182 pbm->callback(pbm->gc, b->name); | |
1396
df7c3cacac92
[gaim-migrate @ 1406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1392
diff
changeset
|
183 } |
1 | 184 |
4687 | 185 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
|
186 { |
4687 | 187 GtkTreePath *path; |
188 GaimBlistNode *node; | |
189 GValue val = { 0, }; | |
190 GtkTreeIter iter; | |
191 GtkWidget *menu, *menuitem; | |
192 GtkWidget *image; | |
4702 | 193 GtkTreeSelection *sel; |
4687 | 194 GList *list; |
195 struct prpl *prpl; | |
1391
d606da211acb
[gaim-migrate @ 1401]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1376
diff
changeset
|
196 |
4687 | 197 if (event->button != 3) |
198 return FALSE; | |
4718 | 199 |
4687 | 200 /* Here we figure out which node was clicked */ |
201 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL)) | |
202 return FALSE; | |
203 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
204 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
205 node = g_value_get_pointer(&val); | |
4718 | 206 |
4721 | 207 if (!GAIM_BLIST_NODE_IS_BUDDY(node)) { |
208 gtk_tree_path_free(path); | |
4687 | 209 return FALSE; |
4721 | 210 } |
4718 | 211 |
4687 | 212 menu = gtk_menu_new(); |
3251 | 213 |
4687 | 214 /* Protocol specific options */ |
215 prpl = find_prpl(((struct buddy*)node)->account->protocol); | |
4732 | 216 |
217 if(prpl && prpl->get_info) { | |
218 menuitem = gtk_image_menu_item_new_with_mnemonic("_Get Info"); | |
219 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_info_cb), node); | |
220 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
221 } | |
222 | |
223 menuitem = gtk_image_menu_item_new_with_mnemonic("_IM"); | |
224 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_im_cb), node); | |
225 image = gtk_image_new_from_stock(GAIM_STOCK_IM, GTK_ICON_SIZE_MENU); | |
226 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); | |
227 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
228 | |
229 menuitem = gtk_image_menu_item_new_with_mnemonic("_Alias"); | |
230 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_alias_cb), node); | |
231 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
232 | |
233 menuitem = gtk_image_menu_item_new_with_mnemonic("Add Buddy _Pounce"); | |
234 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_bp_cb), node); | |
235 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
236 | |
237 menuitem = gtk_image_menu_item_new_with_mnemonic("View _Log"); | |
238 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_showlog_cb), node); | |
239 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
240 | |
4687 | 241 if (prpl) { |
242 list = prpl->buddy_menu(((struct buddy*)node)->account->gc, ((struct buddy*)node)->name); | |
243 while (list) { | |
244 struct proto_buddy_menu *pbm = list->data; | |
245 menuitem = gtk_menu_item_new_with_mnemonic(pbm->label); | |
246 g_object_set_data(G_OBJECT(menuitem), "gaimcallback", pbm); | |
247 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gaim_proto_menu_cb), node); | |
248 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
249 list = list->next; | |
3313 | 250 } |
3251 | 251 } |
1 | 252 |
4687 | 253 gtk_widget_show_all(menu); |
254 | |
255 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time); | |
1 | 256 |
4702 | 257 #if (1) /* This code only exists because GTK doesn't work. If we return FALSE here, as would be normal |
258 * the event propoagates down and somehow gets interpreted as the start of a drag event. */ | |
259 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv)); | |
260 gtk_tree_selection_select_path(sel, path); | |
4721 | 261 gtk_tree_path_free(path); |
4702 | 262 return TRUE; |
263 #endif | |
1 | 264 } |
265 | |
4687 | 266 /* This is called 10 seconds after the buddy logs in. It removes the "logged in" icon and replaces it with |
267 * the normal status icon */ | |
1072
81d19577285a
[gaim-migrate @ 1082]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1070
diff
changeset
|
268 |
4687 | 269 static gboolean gaim_reset_present_icon(GaimBlistNode *b) |
270 { | |
271 ((struct buddy*)b)->present = 1; | |
272 gaim_gtk_blist_update(NULL, b); | |
273 return FALSE; | |
577
aa9a8bcddd80
[gaim-migrate @ 587]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
544
diff
changeset
|
274 } |
aa9a8bcddd80
[gaim-migrate @ 587]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
544
diff
changeset
|
275 |
4687 | 276 static void gaim_gtk_blist_add_buddy_cb() |
935
5e6ca3dd4d02
[gaim-migrate @ 945]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
921
diff
changeset
|
277 { |
4690 | 278 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)); |
4687 | 279 GtkTreeIter iter; |
280 GaimBlistNode *node; | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4349
diff
changeset
|
281 |
4692 | 282 if(gtk_tree_selection_get_selected(sel, NULL, &iter)){ |
283 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
4691 | 284 if (GAIM_BLIST_NODE_IS_BUDDY(node)) |
285 show_add_buddy(NULL, NULL, ((struct group*)node->parent)->name, NULL); | |
286 else if (GAIM_BLIST_NODE_IS_GROUP(node)) | |
287 show_add_buddy(NULL, NULL, ((struct group*)node)->name, NULL); | |
288 } | |
4697 | 289 else { |
4692 | 290 show_add_buddy(NULL, NULL, NULL, NULL); |
291 } | |
1 | 292 } |
293 | |
4697 | 294 static void gaim_gtk_blist_update_toolbar_icons (GtkWidget *widget, gpointer data) { |
295 if (GTK_IS_IMAGE(widget)) { | |
296 if (blist_options & OPT_BLIST_SHOW_BUTTON_XPM) | |
297 gtk_widget_show(widget); | |
298 else | |
299 gtk_widget_hide(widget); | |
300 } else if (GTK_IS_CONTAINER(widget)) { | |
301 gtk_container_foreach(GTK_CONTAINER(widget), gaim_gtk_blist_update_toolbar_icons, NULL); | |
302 } | |
303 } | |
1 | 304 |
4702 | 305 static void gaim_gtk_blist_drag_data_get_cb (GtkWidget *widget, |
306 GdkDragContext *dc, | |
307 GtkSelectionData *data, | |
308 guint info, | |
309 guint time, | |
310 gpointer *null) | |
311 { | |
4781 | 312 if (data->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE)) { |
4702 | 313 GtkTreeRowReference *ref = g_object_get_data(G_OBJECT(dc), "gtk-tree-view-source-row"); |
314 GtkTreePath *sourcerow = gtk_tree_row_reference_get_path(ref); | |
315 GtkTreeIter iter; | |
316 GaimBlistNode *node = NULL; | |
317 GValue val = {0}; | |
318 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, sourcerow); | |
319 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
320 node = g_value_get_pointer(&val); | |
4781 | 321 gtk_selection_data_set (data, |
322 gdk_atom_intern ("GAIM_BLIST_NODE", FALSE), | |
323 8, /* bits */ | |
324 (void*)&node, | |
325 sizeof (node)); | |
326 | |
4721 | 327 gtk_tree_path_free(sourcerow); |
4702 | 328 } |
4781 | 329 |
4702 | 330 } |
331 | |
332 static void gaim_gtk_blist_drag_data_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, | |
333 GtkSelectionData *sd, guint info, guint t) | |
334 { | |
4781 | 335 if (sd->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE) && sd->data) { |
336 GaimBlistNode *n = NULL; | |
4702 | 337 GtkTreePath *path = NULL; |
4704 | 338 GtkTreeViewDropPosition position; |
4781 | 339 memcpy(&n, sd->data, sizeof(n)); |
4704 | 340 if(gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), x, y, &path, &position)) { |
341 /* if we're here, I think it means the drop is ok */ | |
4770 | 342 GtkTreeIter iter; |
343 GaimBlistNode *node; | |
344 GValue val = {0}; | |
345 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
346 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
347 node = g_value_get_pointer(&val); | |
4781 | 348 |
349 if (GAIM_BLIST_NODE_IS_BUDDY(n)) { | |
350 struct buddy *b = (struct buddy*)n; | |
351 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
4795 | 352 switch(position) { |
353 case GTK_TREE_VIEW_DROP_AFTER: | |
354 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
355 gaim_blist_add_buddy(b, (struct group*)node->parent, node); | |
356 break; | |
357 case GTK_TREE_VIEW_DROP_BEFORE: | |
358 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
359 gaim_blist_add_buddy(b, (struct group*)node->parent, node->prev); | |
360 break; | |
4781 | 361 } |
362 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
363 gaim_blist_add_buddy(b, (struct group*)node, NULL); | |
4795 | 364 } |
4781 | 365 } else if (GAIM_BLIST_NODE_IS_GROUP(n)) { |
366 struct group *g = (struct group*)n; | |
367 if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
368 switch (position) { | |
369 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
370 case GTK_TREE_VIEW_DROP_AFTER: | |
371 gaim_blist_add_group(g, node); | |
372 break; | |
373 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
374 case GTK_TREE_VIEW_DROP_BEFORE: | |
375 gaim_blist_add_group(g, node->prev); | |
376 break; | |
377 } | |
378 | |
4770 | 379 } |
4781 | 380 |
4777 | 381 } |
4781 | 382 |
4721 | 383 gtk_tree_path_free(path); |
4704 | 384 } |
4702 | 385 } |
386 } | |
387 | |
4724 | 388 static void gaim_gtk_blist_paint_tip(GtkWidget *widget, GdkEventExpose *event, struct buddy *b) |
389 { | |
390 GtkStyle *style; | |
391 GdkPixbuf *pixbuf = gaim_gtk_blist_get_status_icon(b, GAIM_STATUS_ICON_LARGE); | |
392 PangoLayout *layout; | |
393 char *tooltiptext = gaim_get_tooltip_text(b); | |
394 | |
395 layout = gtk_widget_create_pango_layout (gtkblist->tipwindow, NULL); | |
396 pango_layout_set_markup(layout, tooltiptext, strlen(tooltiptext)); | |
4732 | 397 pango_layout_set_wrap(layout, PANGO_WRAP_WORD); |
4733 | 398 pango_layout_set_width(layout, 300000); |
4724 | 399 style = gtkblist->tipwindow->style; |
4732 | 400 |
4724 | 401 gtk_paint_flat_box (style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, |
402 NULL, gtkblist->tipwindow, "tooltip", 0, 0, -1, -1); | |
4729 | 403 |
404 #if GTK_CHECK_VERSION(2,2,0) | |
4724 | 405 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, pixbuf, |
406 0, 0, 4, 4, -1 , -1, GDK_RGB_DITHER_NONE, 0, 0); | |
4729 | 407 #else |
4758 | 408 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 | 409 #endif |
4724 | 410 |
411 gtk_paint_layout (style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, TRUE, | |
412 NULL, gtkblist->tipwindow, "tooltip", 38, 4, layout); | |
413 | |
414 g_object_unref (pixbuf); | |
415 g_object_unref (layout); | |
416 g_free(tooltiptext); | |
417 return; | |
418 } | |
419 | |
420 static gboolean gaim_gtk_blist_tooltip_timeout(GtkWidget *tv) | |
421 { | |
422 GtkTreePath *path; | |
423 GtkTreeIter iter; | |
424 GaimBlistNode *node; | |
425 GValue val = {0}; | |
426 | |
427 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), gtkblist->rect.x, gtkblist->rect.y, &path, NULL, NULL, NULL)) | |
428 return FALSE; | |
429 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
430 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
431 node = g_value_get_pointer(&val); | |
432 | |
433 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
434 int scr_w,scr_h, w, h, x, y; | |
435 PangoLayout *layout; | |
436 struct buddy *buddy = (struct buddy*)node; | |
437 char *tooltiptext = gaim_get_tooltip_text(buddy); | |
438 gtkblist->tipwindow = gtk_window_new(GTK_WINDOW_POPUP); | |
439 gtk_widget_set_app_paintable(gtkblist->tipwindow, TRUE); | |
4729 | 440 gtk_window_set_resizable(GTK_WINDOW(gtkblist->tipwindow), FALSE); |
4724 | 441 gtk_widget_set_name(gtkblist->tipwindow, "gtk-tooltips"); |
442 g_signal_connect(G_OBJECT(gtkblist->tipwindow), "expose_event", | |
443 G_CALLBACK(gaim_gtk_blist_paint_tip), buddy); | |
444 gtk_widget_ensure_style (gtkblist->tipwindow); | |
445 | |
446 layout = gtk_widget_create_pango_layout (gtkblist->tipwindow, NULL); | |
4733 | 447 pango_layout_set_wrap(layout, PANGO_WRAP_WORD); |
448 pango_layout_set_width(layout, 300000); | |
4724 | 449 pango_layout_set_markup(layout, tooltiptext, strlen(tooltiptext)); |
450 scr_w = gdk_screen_width(); | |
451 scr_h = gdk_screen_height(); | |
452 pango_layout_get_size (layout, &w, &h); | |
453 w = PANGO_PIXELS(w) + 8; | |
454 h = PANGO_PIXELS(h) + 8; | |
455 | |
456 /* 38 is the size of a large status icon plus 4 pixels padding on each side. | |
457 I should #define this or something */ | |
458 w = w + 38; | |
459 h = MAX(h, 38); | |
460 | |
461 gdk_window_get_pointer(NULL, &x, &y, NULL); | |
462 if (GTK_WIDGET_NO_WINDOW(gtkblist->window)) | |
463 y+=gtkblist->window->allocation.y; | |
464 | |
465 x -= ((w >> 1) + 4); | |
466 | |
467 if ((x + w) > scr_w) | |
468 x -= (x + w) - scr_w; | |
469 else if (x < 0) | |
470 x = 0; | |
471 | |
472 if ((y + h + 4) > scr_h) | |
473 y = y - h; | |
474 else | |
475 y = y + 6; | |
476 g_object_unref (layout); | |
477 g_free(tooltiptext); | |
478 gtk_widget_set_size_request(gtkblist->tipwindow, w, h); | |
4729 | 479 gtk_window_move(GTK_WINDOW(gtkblist->tipwindow), x, y); |
4724 | 480 gtk_widget_show(gtkblist->tipwindow); |
481 } | |
4729 | 482 |
4724 | 483 gtk_tree_path_free(path); |
484 return FALSE; | |
485 } | |
486 | |
4730 | 487 static gboolean gaim_gtk_blist_motion_cb (GtkWidget *tv, GdkEventMotion *event, gpointer null) |
4724 | 488 { |
489 GtkTreePath *path; | |
490 | |
491 if (gtkblist->timeout) { | |
492 if ((event->y > gtkblist->rect.y) && ((event->y - gtkblist->rect.height) < gtkblist->rect.y)) | |
4732 | 493 return FALSE; |
4724 | 494 /* We've left the cell. Remove the timeout and create a new one below */ |
495 if (gtkblist->tipwindow) { | |
496 gtk_widget_destroy(gtkblist->tipwindow); | |
497 gtkblist->tipwindow = NULL; | |
498 } | |
499 | |
500 g_source_remove(gtkblist->timeout); | |
501 } | |
502 | |
503 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL); | |
504 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, >kblist->rect); | |
505 if (path) | |
506 gtk_tree_path_free(path); | |
507 gtkblist->timeout = g_timeout_add(500, (GSourceFunc)gaim_gtk_blist_tooltip_timeout, tv); | |
4730 | 508 return FALSE; |
4724 | 509 } |
510 | |
511 static void gaim_gtk_blist_leave_cb (GtkWidget *w, GdkEventCrossing *e, gpointer n) | |
512 { | |
513 if (gtkblist->timeout == 0) | |
514 return; | |
515 if (gtkblist->tipwindow) { | |
516 gtk_widget_destroy(gtkblist->tipwindow); | |
517 gtkblist->tipwindow = NULL; | |
518 } | |
519 g_source_remove(gtkblist->timeout); | |
520 gtkblist->timeout = 0; | |
521 } | |
522 | |
4687 | 523 /*************************************************** |
524 * Crap * | |
525 ***************************************************/ | |
526 static GtkItemFactoryEntry blist_menu[] = | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
527 { |
4687 | 528 /* Buddies menu */ |
529 { N_("/_Buddies"), NULL, NULL, 0, "<Branch>" }, | |
530 { N_("/Buddies/_Add A Buddy..."), "<CTL>B", gaim_gtk_blist_add_buddy_cb, 0, | |
531 "<StockItem>", GTK_STOCK_ADD }, | |
532 { N_("/Buddies/New _Instant Message..."), "<CTL>I", show_im_dialog, 0, | |
533 "<StockItem>", GAIM_STOCK_IM }, | |
534 { N_("/Buddies/Join a _Chat..."), "<CTL>C", join_chat, 0, | |
535 "<StockItem>", GAIM_STOCK_CHAT }, | |
536 { N_("/Buddies/sep1"), NULL, NULL, 0, "<Separator>" }, | |
537 { N_("/Buddies/Get _User Info..."), "<CTL>J", show_info_dialog, 0, | |
538 "<StockItem>", GAIM_STOCK_INFO }, | |
539 { N_("/Buddies/sep2"), NULL, NULL, 0, "<Separator>" }, | |
540 { N_("/Buddies/_Signoff"), "<CTL>D", signoff_all, 0, NULL }, | |
541 { N_("/Buddies/_Quit"), "<CTL>Q", do_quit, 0, | |
542 "<StockItem>", GTK_STOCK_QUIT }, | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
543 |
4687 | 544 /* Tools */ |
545 { N_("/_Tools"), NULL, NULL, 0, "<Branch>" }, | |
546 { N_("/Tools/_Away"), NULL, NULL, 0, "<Branch>" }, | |
547 { N_("/Tools/Buddy _Pounce"), NULL, NULL, 0, "<Branch>" }, | |
548 { N_("/Tools/sep1"), NULL, NULL, 0, "<Separator>" }, | |
549 { N_("/Tools/A_ccounts"), "<CTL>A", account_editor, 0, NULL }, | |
4694 | 550 { N_("/Tools/Preferences"), "<CTL>P", show_prefs, 0, |
4687 | 551 "<StockItem>", GTK_STOCK_PREFERENCES }, |
4698 | 552 { N_("/Tools/_File Transfers"), NULL, gaim_show_xfer_dialog, 0, |
4687 | 553 "<StockItem>", GTK_STOCK_REVERT_TO_SAVED }, |
554 { N_("/Tools/sep2"), NULL, NULL, 0, "<Separator>" }, | |
555 { N_("/Tools/P_rotocol Actions"), NULL, NULL, 0, "<Branch>" }, | |
556 { N_("/Tools/Pr_ivacy"), NULL, show_privacy_options, 0, NULL }, | |
4697 | 557 { N_("/Tools/View System _Log"), NULL, gtk_blist_show_systemlog_cb, 0, NULL }, |
3251 | 558 |
4687 | 559 /* Help */ |
560 { N_("/_Help"), NULL, NULL, 0, "<Branch>" }, | |
4776 | 561 { N_("/Help/Online _Help"), "F1", gtk_blist_show_onlinehelp_cb, 0, |
4687 | 562 "<StockItem>", GTK_STOCK_HELP }, |
4755 | 563 { N_("/Help/_Debug Window"), NULL, toggle_debug, 0, NULL }, |
4687 | 564 { N_("/Help/_About"), NULL, show_about, 0, NULL }, |
565 | |
566 }; | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
567 |
4687 | 568 /********************************************************* |
569 * Private Utility functions * | |
570 *********************************************************/ | |
571 | |
4724 | 572 static char *gaim_get_tooltip_text(struct buddy *b) |
573 { | |
574 char *text = NULL; | |
575 struct prpl* prpl = find_prpl(b->account->protocol); | |
576 char *statustext = NULL; | |
577 char *warning = NULL, *idletime = NULL; | |
578 | |
579 if (prpl->tooltip_text) { | |
4732 | 580 statustext = prpl->tooltip_text(b); |
4724 | 581 } |
4732 | 582 |
4724 | 583 if (b->idle) { |
584 int ihrs, imin; | |
585 time_t t; | |
586 time(&t); | |
587 ihrs = (t - b->idle) / 3600; | |
588 imin = ((t - b->idle) / 60) % 60; | |
589 if (ihrs) | |
4744 | 590 idletime = g_strdup_printf(_("%dh%02dm"), ihrs, imin); |
4724 | 591 else |
4744 | 592 idletime = g_strdup_printf(_("%dm"), imin); |
4724 | 593 } |
4732 | 594 |
4724 | 595 if (b->evil > 0) |
4744 | 596 warning = g_strdup_printf(_("%d%%"), b->evil); |
4732 | 597 |
4724 | 598 text = g_strdup_printf("<span size='larger' weight='bold'>%s</span>" |
4744 | 599 "%s %s" /* Alias */ |
600 "%s %s" /* Nickname */ | |
601 "%s %s" /* Idle */ | |
602 "%s %s" /* Warning */ | |
4741 | 603 "%s%s", /* Status */ |
4724 | 604 b->name, |
4744 | 605 b->alias && b->alias[0] ? _("\n<b>Alias:</b>") : "", b->alias ? b->alias : "", |
606 b->server_alias ? _("\n<b>Nickname:</b>") : "", b->server_alias ? b->server_alias : "", | |
607 b->idle ? _("\n<b>Idle:</b>") : "", b->idle ? idletime : "", | |
608 b->evil ? _("\n<b>Warned:</b>") : "", b->evil ? warning : "", | |
4724 | 609 statustext ? "\n" : "", statustext ? statustext : ""); |
4737 | 610 if(warning) |
611 g_free(warning); | |
612 if(idletime) | |
613 g_free(idletime); | |
614 if(statustext) | |
615 g_free(statustext); | |
616 | |
4724 | 617 return text; |
618 | |
619 } | |
620 | |
621 static GdkPixbuf *gaim_gtk_blist_get_status_icon(struct buddy *b, GaimStatusIconSize size) | |
4687 | 622 { |
623 GdkPixbuf *status = NULL; | |
624 GdkPixbuf *scale = NULL; | |
625 GdkPixbuf *emblem = NULL; | |
4737 | 626 gchar *filename = NULL; |
4687 | 627 const char *protoname = NULL; |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
628 |
4691 | 629 char *se = NULL, *sw = NULL ,*nw = NULL ,*ne = NULL; |
4737 | 630 |
4687 | 631 int scalesize = 30; |
632 | |
633 struct prpl* prpl = find_prpl(b->account->protocol); | |
634 if (prpl->list_icon) | |
635 protoname = prpl->list_icon(b->account, b); | |
636 if (prpl->list_emblems) | |
637 prpl->list_emblems(b, &se, &sw, &nw, &ne); | |
4737 | 638 |
4724 | 639 if (size == GAIM_STATUS_ICON_SMALL) { |
4687 | 640 scalesize = 15; |
641 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
|
642 } |
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
643 |
4701 | 644 |
4687 | 645 if (b->present == 2) { |
4701 | 646 struct gaim_gtk_blist_node *gtknode; |
4687 | 647 /* If b->present is 2, that means this buddy has just signed on. We use the "login" icon for the |
648 * status, and we set a timeout to change it to a normal icon after 10 seconds. */ | |
649 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "login.png", NULL); | |
650 status = gdk_pixbuf_new_from_file(filename,NULL); | |
651 g_free(filename); | |
4701 | 652 |
653 gtknode = GAIM_GTK_BLIST_NODE((GaimBlistNode*)b); | |
4773 | 654 if (gtknode->timer > 0) |
655 g_source_remove(gtknode->timer); | |
4701 | 656 gtknode->timer = g_timeout_add(10000, (GSourceFunc)gaim_reset_present_icon, b); |
657 | |
4737 | 658 /* "Hey, what's all this crap?" you ask. Status icons will be themeable too, and |
4687 | 659 then it will look up protoname from the theme */ |
660 } else { | |
661 char *image = g_strdup_printf("%s.png", protoname); | |
662 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
663 status = gdk_pixbuf_new_from_file(filename,NULL); | |
664 g_free(image); | |
665 g_free(filename); | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
666 |
4687 | 667 } |
4737 | 668 |
4687 | 669 if (!status) |
670 return NULL; | |
4737 | 671 |
4687 | 672 scale = gdk_pixbuf_scale_simple(status, scalesize, scalesize, GDK_INTERP_BILINEAR); |
4737 | 673 |
674 g_object_unref(G_OBJECT(status)); | |
675 | |
4687 | 676 /* Emblems */ |
4737 | 677 |
4687 | 678 /* Each protocol can specify up to four "emblems" to composite over the base icon. "away", "busy", "mobile user" |
679 * are all examples of states represented by emblems. I'm not even really sure I like this yet. */ | |
4737 | 680 |
4687 | 681 /* XXX Clean this crap up, yo. */ |
682 if (se) { | |
683 char *image = g_strdup_printf("%s.png", se); | |
684 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
685 g_free(image); | |
686 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
687 g_free(filename); | |
688 if (emblem) { | |
4724 | 689 if (size == GAIM_STATUS_ICON_LARGE) |
4687 | 690 gdk_pixbuf_composite (emblem, |
691 scale, 15, 15, | |
692 15, 15, | |
693 15, 15, | |
694 1, 1, | |
695 GDK_INTERP_BILINEAR, | |
696 255); | |
697 else | |
698 gdk_pixbuf_composite (emblem, | |
699 scale, 0, 0, | |
700 15, 15, | |
701 0, 0, | |
702 1, 1, | |
703 GDK_INTERP_BILINEAR, | |
704 255); | |
4737 | 705 g_object_unref(G_OBJECT(emblem)); |
4687 | 706 } |
707 } | |
708 if (sw) { | |
709 char *image = g_strdup_printf("%s.png", sw); | |
710 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
711 g_free(image); | |
712 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
713 g_free(filename); | |
714 if (emblem) { | |
4737 | 715 gdk_pixbuf_composite (emblem, |
716 scale, 0, 15, | |
717 15, 15, | |
718 0, 15, | |
719 1, 1, | |
720 GDK_INTERP_BILINEAR, | |
721 255); | |
722 g_object_unref(G_OBJECT(emblem)); | |
4687 | 723 } |
724 } | |
725 if (nw) { | |
726 char *image = g_strdup_printf("%s.png", nw); | |
727 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
728 g_free(image); | |
729 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
730 g_free(filename); | |
731 if (emblem) { | |
732 gdk_pixbuf_composite (emblem, | |
733 scale, 0, 0, | |
734 15, 15, | |
735 0, 0, | |
736 1, 1, | |
737 GDK_INTERP_BILINEAR, | |
738 255); | |
4737 | 739 g_object_unref(G_OBJECT(emblem)); |
4687 | 740 } |
741 } | |
742 if (ne) { | |
743 char *image = g_strdup_printf("%s.png", ne); | |
744 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
745 g_free(image); | |
746 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
747 g_free(filename); | |
748 if (emblem) { | |
749 gdk_pixbuf_composite (emblem, | |
750 scale, 15, 0, | |
751 15, 15, | |
752 15, 0, | |
753 1, 1, | |
754 GDK_INTERP_BILINEAR, | |
755 255); | |
756 } | |
4737 | 757 } |
4687 | 758 |
4737 | 759 |
4718 | 760 /* Idle grey buddies affects the whole row. This converts the status icon to greyscale. */ |
4699 | 761 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS) |
4687 | 762 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0, FALSE); |
763 return scale; | |
1 | 764 } |
765 | |
4737 | 766 static GdkPixbuf *gaim_gtk_blist_get_buddy_icon(struct buddy *b) |
1 | 767 { |
4687 | 768 /* This just opens a file from ~/.gaim/icons/screenname. This needs to change to be more gooder. */ |
4737 | 769 char *file; |
770 GdkPixbuf *buf, *ret; | |
771 | |
4687 | 772 if (!(blist_options & OPT_BLIST_SHOW_ICONS)) |
773 return NULL; | |
4737 | 774 |
4757 | 775 if ((file = gaim_buddy_get_setting(b, "buddy_icon")) == NULL) |
776 return NULL; | |
777 | |
4737 | 778 buf = gdk_pixbuf_new_from_file(file, NULL); |
779 g_free(file); | |
780 | |
781 | |
4687 | 782 if (buf) { |
4699 | 783 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS) { |
4687 | 784 gdk_pixbuf_saturate_and_pixelate(buf, buf, 0, FALSE); |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
785 } |
4737 | 786 ret = gdk_pixbuf_scale_simple(buf,30,30, GDK_INTERP_BILINEAR); |
787 g_object_unref(G_OBJECT(buf)); | |
788 return ret; | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
789 } |
4687 | 790 return NULL; |
2986 | 791 } |
792 | |
4687 | 793 static gchar *gaim_gtk_blist_get_name_markup(struct buddy *b) |
1 | 794 { |
4687 | 795 char *name = gaim_get_buddy_alias(b); |
796 char *esc = g_markup_escape_text(name, strlen(name)), *text = NULL; | |
4722 | 797 struct prpl* prpl = find_prpl(b->account->protocol); |
798 | |
4687 | 799 /* XXX Clean up this crap */ |
4699 | 800 |
4687 | 801 int ihrs, imin; |
4724 | 802 char *idletime = NULL, *warning = NULL, *statustext = NULL; |
4732 | 803 time_t t; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
804 |
4687 | 805 if (!(blist_options & OPT_BLIST_SHOW_ICONS)) { |
4699 | 806 if (b->idle > 0 && blist_options & OPT_BLIST_GREY_IDLERS) { |
4718 | 807 text = g_strdup_printf("<span color='dim grey'>%s</span>", |
4699 | 808 esc); |
4687 | 809 g_free(esc); |
810 return text; | |
811 } else { | |
812 return esc; | |
813 } | |
1 | 814 } |
815 | |
4687 | 816 time(&t); |
817 ihrs = (t - b->idle) / 3600; | |
818 imin = ((t - b->idle) / 60) % 60; | |
4699 | 819 |
4722 | 820 if (prpl->status_text) { |
4732 | 821 char *tmp = prpl->status_text(b); |
822 | |
823 if(tmp) { | |
824 if(strlen(tmp) > 20) | |
4757 | 825 statustext = g_strdup_printf("%.20s... ", tmp); |
4732 | 826 else |
4757 | 827 statustext = g_strdup_printf("%s ", tmp); |
4732 | 828 g_free(tmp); |
829 } | |
4722 | 830 } |
4732 | 831 |
4687 | 832 if (b->idle) { |
833 if (ihrs) | |
4757 | 834 idletime = g_strdup_printf(_("Idle (%dh%02dm) "), ihrs, imin); |
4687 | 835 else |
4757 | 836 idletime = g_strdup_printf(_("Idle (%dm) "), imin); |
4687 | 837 } |
4757 | 838 |
4687 | 839 if (b->evil > 0) |
4757 | 840 warning = g_strdup_printf(_("Warned (%d%%) "), b->evil); |
841 | |
4797 | 842 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS) { |
4757 | 843 text = g_strdup_printf("<span color='dim grey'>%s</span>\n<span color='dim grey' size='smaller'>%s%s%s</span>", |
4687 | 844 esc, |
4722 | 845 statustext != NULL ? statustext : "", |
846 idletime != NULL ? idletime : "", | |
847 warning != NULL ? warning : ""); | |
4797 | 848 } else if (statustext == NULL && idletime == NULL && warning == NULL) { |
849 text = g_strdup_printf("%s", esc); | |
850 } else { | |
4757 | 851 text = g_strdup_printf("%s\n<span color='dim grey' size='smaller'>%s%s%s</span>", esc, |
4722 | 852 statustext != NULL ? statustext : "", |
853 idletime != NULL ? idletime : "", | |
854 warning != NULL ? warning : ""); | |
4797 | 855 } |
4722 | 856 if (idletime) |
4687 | 857 g_free(idletime); |
4722 | 858 if (warning) |
4687 | 859 g_free(warning); |
4722 | 860 if (statustext) |
861 g_free(statustext); | |
4737 | 862 if (esc) |
863 g_free(esc); | |
4699 | 864 |
4687 | 865 return text; |
866 } | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
867 |
4687 | 868 /********************************************************************************** |
869 * Public API Functions * | |
870 **********************************************************************************/ | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
871 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
|
872 { |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
873 blist->ui_data = g_new0(struct gaim_gtk_buddy_list, 1); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
874 } |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
875 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
876 static void gaim_gtk_blist_new_node(GaimBlistNode *node) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
877 { |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
878 node->ui_data = g_new0(struct gaim_gtk_blist_node, 1); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
879 } |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
880 |
4729 | 881 void gaim_gtk_blist_update_columns() |
882 { | |
883 if (blist_options & OPT_BLIST_SHOW_ICONS) { | |
884 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, TRUE); | |
885 gtk_tree_view_column_set_visible(gtkblist->idle_column, FALSE); | |
886 gtk_tree_view_column_set_visible(gtkblist->warning_column, FALSE); | |
887 } else { | |
888 gtk_tree_view_column_set_visible(gtkblist->idle_column, blist_options & OPT_BLIST_SHOW_IDLETIME); | |
889 gtk_tree_view_column_set_visible(gtkblist->warning_column, blist_options & OPT_BLIST_SHOW_WARN); | |
890 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, FALSE); | |
891 } | |
892 } | |
893 | |
4702 | 894 enum {DRAG_BUDDY, DRAG_ROW}; |
895 | |
4687 | 896 static void gaim_gtk_blist_show(struct gaim_buddy_list *list) |
897 { | |
898 GtkItemFactory *ift; | |
899 GtkCellRenderer *rend; | |
900 GtkTreeViewColumn *column; | |
901 GtkWidget *sw; | |
902 GtkWidget *button; | |
4694 | 903 GtkSizeGroup *sg; |
4781 | 904 GtkTargetEntry gte[] = {{"GAIM_BLIST_NODE", GTK_TARGET_SAME_APP, DRAG_ROW}, |
4702 | 905 {"application/x-im-contact", 0, DRAG_BUDDY}}; |
4690 | 906 |
4745 | 907 if (gtkblist && gtkblist->window) { |
4687 | 908 gtk_widget_show(gtkblist->window); |
909 return; | |
910 } | |
4690 | 911 |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
912 gtkblist = GAIM_GTK_BLIST(list); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
913 |
4687 | 914 gtkblist->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
915 gtk_window_set_title(GTK_WINDOW(gtkblist->window), _("Buddy List")); | |
4690 | 916 |
4687 | 917 gtkblist->vbox = gtk_vbox_new(FALSE, 6); |
918 gtk_container_add(GTK_CONTAINER(gtkblist->window), gtkblist->vbox); | |
1 | 919 |
4698 | 920 g_signal_connect(G_OBJECT(gtkblist->window), "delete_event", G_CALLBACK(gaim_gtk_blist_destroy_cb), NULL); |
921 | |
4687 | 922 /******************************* Menu bar *************************************/ |
923 ift = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GaimMain>", NULL); | |
924 gtk_item_factory_create_items(ift, sizeof(blist_menu) / sizeof(*blist_menu), | |
925 blist_menu, NULL); | |
926 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtk_item_factory_get_widget(ift, "<GaimMain>"), FALSE, FALSE, 0); | |
1 | 927 |
4694 | 928 awaymenu = gtk_item_factory_get_widget(ift, "/Tools/Away"); |
929 do_away_menu(); | |
930 | |
4696 | 931 bpmenu = gtk_item_factory_get_widget(ift, "/Tools/Buddy Pounce"); |
932 do_bp_menu(); | |
933 | |
934 protomenu = gtk_item_factory_get_widget(ift, "/Tools/Protocol Actions"); | |
935 do_proto_menu(); | |
936 | |
4687 | 937 /****************************** GtkTreeView **********************************/ |
938 sw = gtk_scrolled_window_new(NULL,NULL); | |
939 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); | |
940 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
4690 | 941 gtk_widget_set_size_request(sw, 200, 200); |
4687 | 942 |
4729 | 943 gtkblist->treemodel = gtk_tree_store_new(BLIST_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, |
4687 | 944 G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_POINTER); |
4702 | 945 |
4687 | 946 gtkblist->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(gtkblist->treemodel)); |
4704 | 947 |
4702 | 948 /* Set up dnd */ |
949 gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(gtkblist->treeview), GDK_BUTTON1_MASK, gte, | |
950 2, GDK_ACTION_COPY); | |
4704 | 951 gtk_tree_view_enable_model_drag_dest(GTK_TREE_VIEW(gtkblist->treeview), gte, 2, |
4702 | 952 GDK_ACTION_COPY | GDK_ACTION_MOVE); |
4704 | 953 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-received", G_CALLBACK(gaim_gtk_blist_drag_data_rcv_cb), NULL); |
954 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-get", G_CALLBACK(gaim_gtk_blist_drag_data_get_cb), NULL); | |
955 | |
4724 | 956 /* Tooltips */ |
957 g_signal_connect(G_OBJECT(gtkblist->treeview), "motion-notify-event", G_CALLBACK(gaim_gtk_blist_motion_cb), NULL); | |
958 g_signal_connect(G_OBJECT(gtkblist->treeview), "leave-notify-event", G_CALLBACK(gaim_gtk_blist_leave_cb), NULL); | |
4687 | 959 |
960 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(gtkblist->treeview), FALSE); | |
1 | 961 |
4687 | 962 rend = gtk_cell_renderer_pixbuf_new(); |
963 column = gtk_tree_view_column_new_with_attributes("Status", rend, "pixbuf", STATUS_ICON_COLUMN, NULL); | |
964 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); | |
4796 | 965 g_object_set(rend, "ypad", 0, NULL); |
4706 | 966 |
4687 | 967 rend = gtk_cell_renderer_text_new(); |
968 column = gtk_tree_view_column_new_with_attributes("Name", rend, "markup", NAME_COLUMN, NULL); | |
969 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); | |
4797 | 970 g_object_set(rend, "ypad", 0, "yalign", 0.5, NULL); |
4706 | 971 |
4687 | 972 rend = gtk_cell_renderer_text_new(); |
4725 | 973 gtkblist->warning_column = gtk_tree_view_column_new_with_attributes("Warning", rend, "markup", WARNING_COLUMN, NULL); |
974 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->warning_column); | |
4796 | 975 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); |
4687 | 976 |
977 rend = gtk_cell_renderer_text_new(); | |
4725 | 978 gtkblist->idle_column = gtk_tree_view_column_new_with_attributes("Idle", rend, "markup", IDLE_COLUMN, NULL); |
979 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->idle_column); | |
4796 | 980 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); |
1 | 981 |
4687 | 982 rend = gtk_cell_renderer_pixbuf_new(); |
4725 | 983 gtkblist->buddy_icon_column = gtk_tree_view_column_new_with_attributes("Buddy Icon", rend, "pixbuf", BUDDY_ICON_COLUMN, NULL); |
4796 | 984 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); |
4725 | 985 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->buddy_icon_column); |
4718 | 986 |
4687 | 987 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-activated", G_CALLBACK(gtk_blist_row_activated_cb), NULL); |
988 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
|
989 |
4687 | 990 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), sw, TRUE, TRUE, 0); |
991 gtk_container_add(GTK_CONTAINER(sw), gtkblist->treeview); | |
4725 | 992 gaim_gtk_blist_update_columns(); |
4687 | 993 /**************************** Button Box **************************************/ |
4694 | 994 |
995 sg = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); | |
4687 | 996 gtkblist->bbox = gtk_hbox_new(TRUE, 0); |
997 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtkblist->bbox, FALSE, FALSE, 0); | |
998 button = gaim_pixbuf_button_from_stock(_("IM"), GAIM_STOCK_IM, GAIM_BUTTON_VERTICAL); | |
999 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
1000 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 1001 gtk_size_group_add_widget(sg, button); |
4692 | 1002 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_im_cb), |
4697 | 1003 gtkblist->treeview); |
1004 | |
4687 | 1005 button = gaim_pixbuf_button_from_stock(_("Get Info"), GAIM_STOCK_INFO, GAIM_BUTTON_VERTICAL); |
1006 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
1007 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 1008 gtk_size_group_add_widget(sg, button); |
1009 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_info_cb), | |
4697 | 1010 gtkblist->treeview); |
4729 | 1011 |
4687 | 1012 button = gaim_pixbuf_button_from_stock(_("Chat"), GAIM_STOCK_CHAT, GAIM_BUTTON_VERTICAL); |
1013 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
1014 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 1015 gtk_size_group_add_widget(sg, button); |
1016 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_chat_cb), NULL); | |
1017 | |
4687 | 1018 button = gaim_pixbuf_button_from_stock(_("Away"), GAIM_STOCK_AWAY, GAIM_BUTTON_VERTICAL); |
1019 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
1020 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 1021 gtk_size_group_add_widget(sg, button); |
1022 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_away_cb), NULL); | |
4687 | 1023 |
1024 /* OK... let's show this bad boy. */ | |
1025 gaim_gtk_blist_refresh(list); | |
1026 gtk_widget_show_all(gtkblist->window); | |
4729 | 1027 |
4697 | 1028 gaim_gtk_blist_update_toolbar(); |
1029 | |
4687 | 1030 } |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
1031 |
4687 | 1032 void gaim_gtk_blist_refresh(struct gaim_buddy_list *list) |
1033 { | |
1034 GaimBlistNode *group = list->root; | |
1035 GaimBlistNode *buddy; | |
4690 | 1036 |
4687 | 1037 while (group) { |
1038 gaim_gtk_blist_update(list, group); | |
1039 buddy = group->child; | |
1040 while (buddy) { | |
4699 | 1041 gaim_gtk_blist_update(list, buddy); |
4687 | 1042 buddy = buddy->next; |
1043 } | |
1044 group = group->next; | |
1045 } | |
1046 } | |
1 | 1047 |
4699 | 1048 static gboolean get_iter_from_node_helper(GaimBlistNode *node, GtkTreeIter *iter, GtkTreeIter *root) { |
1049 do { | |
1050 GaimBlistNode *n; | |
1051 GtkTreeIter child; | |
1052 | |
1053 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), root, NODE_COLUMN, &n, -1); | |
1054 if(n == node) { | |
1055 *iter = *root; | |
1056 return TRUE; | |
1057 } | |
1058 | |
1059 if(gtk_tree_model_iter_children(GTK_TREE_MODEL(gtkblist->treemodel), &child, root)) { | |
1060 if(get_iter_from_node_helper(node,iter,&child)) | |
1061 return TRUE; | |
1062 } | |
1063 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(gtkblist->treemodel), root)); | |
1064 | |
1065 return FALSE; | |
1066 } | |
1067 | |
1068 static gboolean get_iter_from_node(GaimBlistNode *node, GtkTreeIter *iter) { | |
1069 GtkTreeIter root; | |
1070 | |
1071 if (!gtkblist) | |
1072 return FALSE; | |
1073 | |
1074 if(!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(gtkblist->treemodel), &root)) | |
1075 return FALSE; | |
1076 | |
1077 return get_iter_from_node_helper(node, iter, &root); | |
1078 } | |
1079 | |
4697 | 1080 void gaim_gtk_blist_update_toolbar() { |
1081 if (!gtkblist) | |
1082 return; | |
4699 | 1083 |
4697 | 1084 gtk_container_foreach(GTK_CONTAINER(gtkblist->bbox), gaim_gtk_blist_update_toolbar_icons, NULL); |
4699 | 1085 |
4697 | 1086 if (blist_options & OPT_BLIST_NO_BUTTONS) |
1087 gtk_widget_hide(gtkblist->bbox); | |
1088 else | |
1089 gtk_widget_show_all(gtkblist->bbox); | |
1090 } | |
1091 | |
4701 | 1092 static void gaim_gtk_blist_remove(struct gaim_buddy_list *list, GaimBlistNode *node) |
1093 { | |
1094 struct gaim_gtk_blist_node *gtknode; | |
1095 GtkTreeIter iter; | |
1096 | |
1097 if (!node->ui_data) | |
1098 return; | |
1099 | |
1100 gtknode = (struct gaim_gtk_blist_node *)node->ui_data; | |
1101 | |
1102 if (gtknode->timer > 0) { | |
1103 g_source_remove(gtknode->timer); | |
1104 gtknode->timer = 0; | |
1105 } | |
1106 | |
1107 if (get_iter_from_node(node, &iter)) { | |
1108 gtk_tree_store_remove(gtkblist->treemodel, &iter); | |
1109 if(GAIM_BLIST_NODE_IS_BUDDY(node) && gaim_blist_get_group_online_count((struct group *)node->parent) == 0) { | |
1110 GtkTreeIter groupiter; | |
1111 if(get_iter_from_node(node->parent, &groupiter)) | |
1112 gtk_tree_store_remove(gtkblist->treemodel, &groupiter); | |
1113 } | |
1114 } | |
1115 } | |
1116 | |
1117 | |
4687 | 1118 static void gaim_gtk_blist_update(struct gaim_buddy_list *list, GaimBlistNode *node) |
1119 { | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1120 struct gaim_gtk_blist_node *gtknode; |
4699 | 1121 GtkTreeIter iter; |
4687 | 1122 gboolean expand = FALSE; |
4699 | 1123 gboolean new_entry = FALSE; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
1124 |
4687 | 1125 if (!gtkblist) |
1126 return; | |
4699 | 1127 |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1128 gtknode = GAIM_GTK_BLIST_NODE(node); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1129 |
4690 | 1130 |
4699 | 1131 if (!get_iter_from_node(node, &iter)) { /* This is a newly added node */ |
1132 new_entry = TRUE; | |
4687 | 1133 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { |
1134 if (((struct buddy*)node)->present) { | |
4699 | 1135 GtkTreeIter groupiter; |
1136 GaimBlistNode *oldersibling; | |
1137 GtkTreeIter oldersiblingiter; | |
4690 | 1138 |
4699 | 1139 if(node->parent && !get_iter_from_node(node->parent, &groupiter)) { |
1140 /* This buddy's group has not yet been added. We do that here */ | |
4757 | 1141 GdkPixbuf *groupicon = gtk_widget_render_icon(gtkblist->treeview, |
1142 GTK_STOCK_OPEN, GTK_ICON_SIZE_SMALL_TOOLBAR, NULL); | |
4794 | 1143 char *esc = g_markup_escape_text(((struct group*)node->parent)->name, -1); |
1144 char *mark = g_strdup_printf("<span weight='bold'>%s</span>", esc); | |
1145 g_free(esc); | |
4699 | 1146 oldersibling = node->parent->prev; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
1147 |
4687 | 1148 /* We traverse backwards through the buddy list to find the node in the tree to insert it after */ |
4699 | 1149 while (oldersibling && !get_iter_from_node(oldersibling, &oldersiblingiter)) |
1150 oldersibling = oldersibling->prev; | |
4690 | 1151 |
4687 | 1152 /* This is where we create the node and add it. */ |
4699 | 1153 gtk_tree_store_insert_after(gtkblist->treemodel, &groupiter, NULL, oldersibling ? &oldersiblingiter : NULL); |
1154 gtk_tree_store_set(gtkblist->treemodel, &groupiter, | |
4757 | 1155 STATUS_ICON_COLUMN, groupicon, |
4687 | 1156 NAME_COLUMN, mark, |
1157 NODE_COLUMN, node->parent, | |
1158 -1); | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1159 |
4737 | 1160 g_free(mark); |
4757 | 1161 g_object_unref(G_OBJECT(groupicon)); |
4737 | 1162 |
4687 | 1163 expand = TRUE; |
1164 } | |
4767 | 1165 |
4699 | 1166 oldersibling = node->prev; |
1167 while (oldersibling && !get_iter_from_node(oldersibling, &oldersiblingiter)) | |
1168 oldersibling = oldersibling->prev; | |
1169 | |
1170 gtk_tree_store_insert_after(gtkblist->treemodel, &iter, &groupiter, oldersibling ? &oldersiblingiter : NULL); | |
4767 | 1171 |
1172 if (blist_options & OPT_BLIST_POPUP) | |
1173 gtk_window_present(GTK_WINDOW(gtkblist->window)); | |
4699 | 1174 |
4687 | 1175 if (expand) { /* expand was set to true if this is the first element added to a group. In such case |
1176 * we expand the group node */ | |
4699 | 1177 GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &groupiter); |
1178 gtk_tree_view_expand_row(GTK_TREE_VIEW(gtkblist->treeview), path, TRUE); | |
4721 | 1179 gtk_tree_path_free(path); |
4687 | 1180 } |
4699 | 1181 } |
1182 } | |
1183 } | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1184 |
4687 | 1185 if (GAIM_BLIST_NODE_IS_BUDDY(node) && ((struct buddy*)node)->present) { |
1186 GdkPixbuf *status, *avatar; | |
1187 char *mark; | |
4697 | 1188 char *warning = NULL, *idle = NULL; |
1189 | |
4724 | 1190 status = gaim_gtk_blist_get_status_icon((struct buddy*)node, |
1191 blist_options & OPT_BLIST_SHOW_ICONS ? GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL); | |
4687 | 1192 avatar = gaim_gtk_blist_get_buddy_icon((struct buddy*)node); |
1193 mark = gaim_gtk_blist_get_name_markup((struct buddy*)node); | |
4697 | 1194 |
4725 | 1195 if (((struct buddy*)node)->idle > 0) { |
4697 | 1196 time_t t; |
1197 int ihrs, imin; | |
1198 time(&t); | |
1199 ihrs = (t - ((struct buddy *)node)->idle) / 3600; | |
1200 imin = ((t - ((struct buddy*)node)->idle) / 60) % 60; | |
4718 | 1201 if(ihrs > 0) |
1202 idle = g_strdup_printf("(%d:%02d)", ihrs, imin); | |
1203 else | |
1204 idle = g_strdup_printf("(%d)", imin); | |
4697 | 1205 } |
1206 | |
4725 | 1207 if (((struct buddy*)node)->evil > 0) |
4699 | 1208 warning = g_strdup_printf("%d%%", ((struct buddy*)node)->evil); |
4725 | 1209 |
4697 | 1210 |
4718 | 1211 if((blist_options & OPT_BLIST_GREY_IDLERS) |
1212 && ((struct buddy *)node)->idle) { | |
1213 if(warning) { | |
1214 char *w2 = g_strdup_printf("<span color='dim grey'>%s</span>", | |
1215 warning); | |
1216 g_free(warning); | |
1217 warning = w2; | |
1218 } | |
1219 | |
1220 if(idle) { | |
1221 char *i2 = g_strdup_printf("<span color='dim grey'>%s</span>", | |
1222 idle); | |
1223 g_free(idle); | |
1224 idle = i2; | |
1225 } | |
1226 } | |
1227 | |
1228 | |
4699 | 1229 gtk_tree_store_set(gtkblist->treemodel, &iter, |
4687 | 1230 STATUS_ICON_COLUMN, status, |
1231 NAME_COLUMN, mark, | |
4697 | 1232 WARNING_COLUMN, warning, |
1233 IDLE_COLUMN, idle, | |
4699 | 1234 BUDDY_ICON_COLUMN, avatar, |
4687 | 1235 NODE_COLUMN, node, |
1236 -1); | |
4699 | 1237 |
4687 | 1238 g_free(mark); |
4697 | 1239 if (idle) |
1240 g_free(idle); | |
1241 if (warning) | |
1242 g_free(warning); | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1243 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1244 if (status != NULL) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1245 g_object_unref(status); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1246 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1247 if (avatar != NULL) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1248 g_object_unref(avatar); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1249 |
4701 | 1250 } else if (GAIM_BLIST_NODE_IS_BUDDY(node) && !new_entry) { |
1251 gaim_gtk_blist_remove(list, node); | |
4767 | 1252 if (blist_options & OPT_BLIST_POPUP) |
1253 gtk_window_present(GTK_WINDOW(gtkblist->window)); | |
4781 | 1254 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { |
1255 GaimBlistNode *afsad = node->child; | |
1256 while (afsad) { | |
1257 gaim_gtk_blist_update(list, afsad); | |
1258 afsad = afsad->next; | |
1259 } | |
4687 | 1260 } |
4786 | 1261 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(gtkblist->treeview)); |
4687 | 1262 } |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
1263 |
4687 | 1264 static void gaim_gtk_blist_destroy(struct gaim_buddy_list *list) |
1265 { | |
4770 | 1266 if (!gtkblist) |
1267 return; | |
4687 | 1268 gtk_widget_destroy(gtkblist->window); |
4745 | 1269 |
1270 gtkblist->window = gtkblist->vbox = gtkblist->treeview = NULL; | |
1271 gtkblist->treemodel = NULL; | |
1272 gtkblist->idle_column = NULL; | |
1273 gtkblist->warning_column = gtkblist->buddy_icon_column = NULL; | |
1274 gtkblist->bbox = gtkblist->tipwindow = NULL; | |
1275 protomenu = NULL; | |
1276 awaymenu = NULL; | |
1277 bpmenu = NULL; | |
1278 | |
1279 gtkblist->timeout = 0; | |
4687 | 1280 } |
1 | 1281 |
4687 | 1282 static void gaim_gtk_blist_set_visible(struct gaim_buddy_list *list, gboolean show) |
1283 { | |
4698 | 1284 if (show) { |
4699 | 1285 gtk_window_present(GTK_WINDOW(gtkblist->window)); |
4698 | 1286 } else { |
1287 if (!connections || docklet_count) { | |
1288 #ifdef _WIN32 | |
4711
0c1f3e651d3e
[gaim-migrate @ 5022]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4706
diff
changeset
|
1289 wgaim_systray_minimize(gtkblist->window); |
4698 | 1290 #endif |
1291 gtk_widget_hide(gtkblist->window); | |
1292 } else { | |
1293 gtk_window_iconify(GTK_WINDOW(gtkblist->window)); | |
1294 } | |
1295 } | |
1296 } | |
1297 | |
1298 void gaim_gtk_blist_docklet_toggle() { | |
1299 /* Useful for the docklet plugin and also for the win32 tray icon*/ | |
1300 /* This is called when one of those is clicked--it will show/hide the | |
1301 buddy list/login window--depending on which is active */ | |
1302 if (connections && gtkblist) { | |
1303 if (GTK_WIDGET_VISIBLE(gtkblist->window)) { | |
1304 gaim_blist_set_visible(GAIM_WINDOW_ICONIFIED(gtkblist->window) || gaim_gtk_blist_obscured); | |
1305 } else { | |
1306 #if _WIN32 | |
4711
0c1f3e651d3e
[gaim-migrate @ 5022]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4706
diff
changeset
|
1307 wgaim_systray_maximize(gtkblist->window); |
4698 | 1308 #endif |
1309 gaim_blist_set_visible(TRUE); | |
1310 } | |
1311 } else if (connections) { | |
1312 /* we're logging in or something... do nothing */ | |
1313 debug_printf("docklet_toggle called with connections but no blist!\n"); | |
1314 } else { | |
1315 if (GTK_WIDGET_VISIBLE(mainwindow)) { | |
1316 if (GAIM_WINDOW_ICONIFIED(mainwindow)) { | |
1317 gtk_window_present(GTK_WINDOW(mainwindow)); | |
1318 } else { | |
1319 #if _WIN32 | |
1320 wgaim_systray_minimize(mainwindow); | |
1321 #endif | |
1322 gtk_widget_hide(mainwindow); | |
1323 } | |
1324 } else { | |
1325 #if _WIN32 | |
1326 wgaim_systray_maximize(mainwindow); | |
1327 #endif | |
1328 gtk_window_present(GTK_WINDOW(mainwindow)); | |
1329 } | |
1330 } | |
1331 } | |
1332 | |
1333 void gaim_gtk_blist_docklet_add() | |
1334 { | |
1335 docklet_count++; | |
1336 } | |
1337 | |
1338 void gaim_gtk_blist_docklet_remove() | |
1339 { | |
1340 docklet_count--; | |
1341 if (!docklet_count) { | |
1342 if (connections) { | |
1343 gaim_blist_set_visible(TRUE); | |
4745 | 1344 } else if(gtkblist && gtkblist->window) { |
4698 | 1345 gtk_window_present(GTK_WINDOW(gtkblist->window)); |
1346 } | |
1347 } | |
4687 | 1348 } |
1 | 1349 |
4687 | 1350 static struct gaim_blist_ui_ops blist_ui_ops = |
1351 { | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1352 gaim_gtk_blist_new_list, |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
1353 gaim_gtk_blist_new_node, |
4687 | 1354 gaim_gtk_blist_show, |
1355 gaim_gtk_blist_update, | |
1356 gaim_gtk_blist_remove, | |
1357 gaim_gtk_blist_destroy, | |
1358 gaim_gtk_blist_set_visible | |
1359 }; | |
1 | 1360 |
1361 | |
4687 | 1362 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
|
1363 { |
4687 | 1364 return &blist_ui_ops; |
1037
1c663beef29d
[gaim-migrate @ 1047]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1036
diff
changeset
|
1365 } |
1c663beef29d
[gaim-migrate @ 1047]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1036
diff
changeset
|
1366 |
3131 | 1367 |
1368 | |
4687 | 1369 /********************************************************************* |
1370 * Public utility functions * | |
1371 *********************************************************************/ | |
1058
4927ce25d8cc
[gaim-migrate @ 1068]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1372 |
4687 | 1373 GdkPixbuf * |
1374 create_prpl_icon(struct gaim_account *account) | |
4553
d03fcb3f4be2
[gaim-migrate @ 4833]
Christian Hammond <chipx86@chipx86.com>
parents:
4525
diff
changeset
|
1375 { |
4687 | 1376 struct prpl *prpl = find_prpl(account->protocol); |
1377 GdkPixbuf *status = NULL; | |
1378 char *filename = NULL; | |
1379 const char *protoname = prpl->list_icon(account, NULL); | |
1380 /* "Hey, what's all this crap?" you ask. Status icons will be themeable too, and | |
1381 then it will look up protoname from the theme */ | |
1382 if (!strcmp(protoname, "aim")) { | |
1383 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "aim.png", NULL); | |
1384 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1385 g_free(filename); | |
1386 } else if (!strcmp(protoname, "yahoo")) { | |
1387 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "yahoo.png", NULL); | |
1388 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1389 g_free(filename); | |
1390 } else if (!strcmp(protoname, "msn")) { | |
1391 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "msn.png", NULL); | |
1392 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1393 g_free(filename); | |
1394 } else if (!strcmp(protoname, "jabber")) { | |
1395 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "jabber.png", NULL); | |
1396 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1397 g_free(filename); | |
1398 } else if (!strcmp(protoname, "icq")) { | |
1399 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "icq.png", NULL); | |
1400 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1401 g_free(filename); | |
1402 } else if (!strcmp(protoname, "gadu-gadu")) { | |
1403 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "gadugadu.png", NULL); | |
1404 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1405 g_free(filename); | |
1406 } else if (!strcmp(protoname, "napster")) { | |
1407 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "napster.png", NULL); | |
1408 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1409 g_free(filename); | |
1410 } else if (!strcmp(protoname, "irc")) { | |
1411 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "irc.png", NULL); | |
1412 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1413 g_free(filename); | |
960
fa681641643d
[gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
945
diff
changeset
|
1414 } |
4687 | 1415 return status; |
1 | 1416 } |
4699 | 1417 |