Mercurial > pidgin
annotate src/buddy.c @ 4703:e4dda06a3143
[gaim-migrate @ 5014]
Changed a bunch of the window titles from "Gaim - What this window is" to
"What this window is". It's better like this.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Tue, 11 Mar 2003 08:17:22 +0000 |
parents | cb5b23dfd82b |
children | 56c70997fe5c |
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); |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
63 |
4687 | 64 /*************************************************** |
65 * Callbacks * | |
66 ***************************************************/ | |
3869 | 67 |
4698 | 68 static void gaim_gtk_blist_destroy_cb() |
69 { | |
70 if (docklet_count) | |
71 gaim_blist_set_visible(FALSE); | |
72 else | |
73 do_quit(); | |
74 } | |
75 | |
4697 | 76 static void gtk_blist_menu_im_cb(GtkWidget *w, struct buddy *b) |
77 { | |
78 gaim_conversation_new(GAIM_CONV_IM, b->account, b->name); | |
79 } | |
80 | |
81 static void gtk_blist_menu_alias_cb(GtkWidget *w, struct buddy *b) | |
82 { | |
83 alias_dialog_bud(b); | |
84 } | |
85 | |
86 static void gtk_blist_menu_bp_cb(GtkWidget *w, struct buddy *b) | |
87 { | |
88 show_new_bp(b->name, b->account->gc, b->idle, | |
89 b->uc & UC_UNAVAILABLE, NULL); | |
90 } | |
91 | |
92 static void gtk_blist_menu_showlog_cb(GtkWidget *w, struct buddy *b) | |
93 { | |
94 show_log(b->name); | |
95 } | |
96 | |
97 static void gtk_blist_show_systemlog_cb() | |
98 { | |
99 show_log(NULL); | |
100 } | |
101 | |
4692 | 102 static void gtk_blist_button_im_cb(GtkWidget *w, GtkTreeView *tv) |
103 { | |
104 GtkTreeIter iter; | |
105 GtkTreeModel *model = gtk_tree_view_get_model(tv); | |
106 GtkTreeSelection *sel = gtk_tree_view_get_selection(tv); | |
107 | |
108 if(gtk_tree_selection_get_selected(sel, &model, &iter)){ | |
109 GaimBlistNode *node; | |
110 | |
111 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
112 if (GAIM_BLIST_NODE_IS_BUDDY(node)) | |
113 gaim_conversation_new(GAIM_CONV_IM, ((struct buddy*)node)->account, ((struct buddy*)node)->name); | |
114 } | |
4694 | 115 } |
4692 | 116 |
4694 | 117 static void gtk_blist_button_info_cb(GtkWidget *w, GtkTreeView *tv) |
118 { | |
119 GtkTreeIter iter; | |
120 GtkTreeModel *model = gtk_tree_view_get_model(tv); | |
121 GtkTreeSelection *sel = gtk_tree_view_get_selection(tv); | |
4692 | 122 |
4694 | 123 if(gtk_tree_selection_get_selected(sel, &model, &iter)){ |
124 GaimBlistNode *node; | |
125 | |
126 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
127 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
128 serv_get_info(((struct buddy*)node)->account->gc, ((struct buddy*)node)->name); | |
129 return; | |
130 } | |
131 } | |
132 show_info_dialog(); | |
133 } | |
134 | |
135 static void gtk_blist_button_chat_cb(GtkWidget *w, gpointer data) | |
136 { | |
137 /* FIXME: someday, we can check to see if we've selected a chat node */ | |
138 join_chat(); | |
139 } | |
140 | |
141 static void gtk_blist_button_away_cb(GtkWidget *w, gpointer data) | |
142 { | |
143 gtk_menu_popup(GTK_MENU(awaymenu), NULL, NULL, NULL, NULL, 1, GDK_CURRENT_TIME); | |
4692 | 144 } |
145 | |
4687 | 146 static void gtk_blist_row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) { |
147 GaimBlistNode *node; | |
148 GtkTreeIter iter; | |
149 GValue val = { 0, }; | |
3154 | 150 |
4687 | 151 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); |
152 | |
153 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
154 node = g_value_get_pointer(&val); | |
155 | |
156 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
157 gaim_conversation_new(GAIM_CONV_IM, ((struct buddy*)node)->account, ((struct buddy*)node)->name); | |
4697 | 158 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { |
159 if (gtk_tree_view_row_expanded(tv, path)) | |
160 gtk_tree_view_collapse_row(tv, path); | |
161 else | |
162 gtk_tree_view_expand_row(tv,path,FALSE); | |
1 | 163 } |
164 } | |
165 | |
4687 | 166 static void gaim_proto_menu_cb(GtkMenuItem *item, struct buddy *b) |
1 | 167 { |
4687 | 168 struct proto_buddy_menu *pbm = g_object_get_data(G_OBJECT(item), "gaimcallback"); |
169 if (pbm->callback) | |
170 pbm->callback(pbm->gc, b->name); | |
1396
df7c3cacac92
[gaim-migrate @ 1406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1392
diff
changeset
|
171 } |
1 | 172 |
4687 | 173 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
|
174 { |
4687 | 175 GtkTreePath *path; |
176 GaimBlistNode *node; | |
177 GValue val = { 0, }; | |
178 GtkTreeIter iter; | |
179 GtkWidget *menu, *menuitem; | |
180 GtkWidget *image; | |
4702 | 181 GtkTreeSelection *sel; |
4687 | 182 GList *list; |
183 struct prpl *prpl; | |
1391
d606da211acb
[gaim-migrate @ 1401]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1376
diff
changeset
|
184 |
4687 | 185 if (event->button != 3) |
186 return FALSE; | |
187 | |
188 /* Here we figure out which node was clicked */ | |
189 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL)) | |
190 return FALSE; | |
191 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
192 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
193 node = g_value_get_pointer(&val); | |
194 | |
195 if (!GAIM_BLIST_NODE_IS_BUDDY(node)) | |
196 return FALSE; | |
197 | |
198 menu = gtk_menu_new(); | |
3251 | 199 |
4687 | 200 /* Protocol specific options */ |
201 prpl = find_prpl(((struct buddy*)node)->account->protocol); | |
202 if (prpl) { | |
203 list = prpl->buddy_menu(((struct buddy*)node)->account->gc, ((struct buddy*)node)->name); | |
204 while (list) { | |
205 struct proto_buddy_menu *pbm = list->data; | |
206 menuitem = gtk_menu_item_new_with_mnemonic(pbm->label); | |
207 g_object_set_data(G_OBJECT(menuitem), "gaimcallback", pbm); | |
208 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gaim_proto_menu_cb), node); | |
209 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
210 list = list->next; | |
3313 | 211 } |
3251 | 212 } |
4687 | 213 |
214 menuitem = gtk_image_menu_item_new_with_mnemonic("_IM"); | |
4697 | 215 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_im_cb), node); |
216 image = gtk_image_new_from_stock(GAIM_STOCK_IM, GTK_ICON_SIZE_MENU); | |
4687 | 217 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); |
218 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
219 | |
220 menuitem = gtk_image_menu_item_new_with_mnemonic("_Alias"); | |
4697 | 221 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_alias_cb), node); |
4687 | 222 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
223 | |
224 menuitem = gtk_image_menu_item_new_with_mnemonic("Add Buddy _Pounce"); | |
4697 | 225 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_bp_cb), node); |
4687 | 226 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
227 | |
228 menuitem = gtk_image_menu_item_new_with_mnemonic("View _Log"); | |
4697 | 229 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gtk_blist_menu_showlog_cb), node); |
4687 | 230 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
1 | 231 |
4687 | 232 gtk_widget_show_all(menu); |
233 | |
234 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time); | |
1 | 235 |
4702 | 236 #if (1) /* This code only exists because GTK doesn't work. If we return FALSE here, as would be normal |
237 * the event propoagates down and somehow gets interpreted as the start of a drag event. */ | |
238 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv)); | |
239 gtk_tree_selection_select_path(sel, path); | |
240 return TRUE; | |
241 #endif | |
1 | 242 } |
243 | |
4687 | 244 static void gaim_gtk_blist_reordered_cb(GtkTreeModel *model, |
245 GtkTreePath *path, | |
246 GtkTreeIter *iter, | |
247 gint *neworder, | |
248 gpointer null) | |
3111 | 249 { |
4687 | 250 debug_printf("This doesn't work because GTK is broken\n"); |
1 | 251 |
252 } | |
253 | |
4687 | 254 /* This is called 10 seconds after the buddy logs in. It removes the "logged in" icon and replaces it with |
255 * the normal status icon */ | |
1072
81d19577285a
[gaim-migrate @ 1082]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1070
diff
changeset
|
256 |
4687 | 257 static gboolean gaim_reset_present_icon(GaimBlistNode *b) |
258 { | |
259 ((struct buddy*)b)->present = 1; | |
260 gaim_gtk_blist_update(NULL, b); | |
261 return FALSE; | |
577
aa9a8bcddd80
[gaim-migrate @ 587]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
544
diff
changeset
|
262 } |
aa9a8bcddd80
[gaim-migrate @ 587]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
544
diff
changeset
|
263 |
4687 | 264 static void gaim_gtk_blist_add_buddy_cb() |
935
5e6ca3dd4d02
[gaim-migrate @ 945]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
921
diff
changeset
|
265 { |
4690 | 266 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)); |
4687 | 267 GtkTreeIter iter; |
268 GaimBlistNode *node; | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4349
diff
changeset
|
269 |
4692 | 270 if(gtk_tree_selection_get_selected(sel, NULL, &iter)){ |
271 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
4691 | 272 if (GAIM_BLIST_NODE_IS_BUDDY(node)) |
273 show_add_buddy(NULL, NULL, ((struct group*)node->parent)->name, NULL); | |
274 else if (GAIM_BLIST_NODE_IS_GROUP(node)) | |
275 show_add_buddy(NULL, NULL, ((struct group*)node)->name, NULL); | |
276 } | |
4697 | 277 else { |
4692 | 278 show_add_buddy(NULL, NULL, NULL, NULL); |
279 } | |
1 | 280 } |
281 | |
4697 | 282 static void gaim_gtk_blist_update_toolbar_icons (GtkWidget *widget, gpointer data) { |
283 if (GTK_IS_IMAGE(widget)) { | |
284 if (blist_options & OPT_BLIST_SHOW_BUTTON_XPM) | |
285 gtk_widget_show(widget); | |
286 else | |
287 gtk_widget_hide(widget); | |
288 } else if (GTK_IS_CONTAINER(widget)) { | |
289 gtk_container_foreach(GTK_CONTAINER(widget), gaim_gtk_blist_update_toolbar_icons, NULL); | |
290 } | |
291 } | |
1 | 292 |
4702 | 293 static void gaim_gtk_blist_drag_data_get_cb (GtkWidget *widget, |
294 GdkDragContext *dc, | |
295 GtkSelectionData *data, | |
296 guint info, | |
297 guint time, | |
298 gpointer *null) | |
299 { | |
300 if (data->target == gdk_atom_intern("GAIM_BUDDY", FALSE)) { | |
301 GtkTreeRowReference *ref = g_object_get_data(G_OBJECT(dc), "gtk-tree-view-source-row"); | |
302 GtkTreePath *sourcerow = gtk_tree_row_reference_get_path(ref); | |
303 GtkTreeIter iter; | |
304 GaimBlistNode *node = NULL; | |
305 GValue val = {0}; | |
306 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, sourcerow); | |
307 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
308 node = g_value_get_pointer(&val); | |
309 if (GAIM_BLIST_NODE_IS_BUDDY(node)) | |
310 gtk_selection_data_set (data, | |
311 gdk_atom_intern ("GAIM_BUDDY", FALSE), | |
312 8, /* bits */ | |
313 (void*)&node, | |
314 sizeof (node)); | |
315 } | |
316 | |
317 } | |
318 | |
319 static void gaim_gtk_blist_drag_data_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, | |
320 GtkSelectionData *sd, guint info, guint t) | |
321 { | |
322 if (sd->target == gdk_atom_intern("GAIM_BUDDY", FALSE)) { | |
323 struct buddy *b = NULL; | |
324 GtkTreePath *path = NULL; | |
325 memcpy(&b, sd->data, sizeof(b)); | |
326 gtk_tree_view_get_dest_row_at_pos(widget, x, y, &path, GTK_TREE_VIEW_DROP_INTO_OR_AFTER); | |
327 } | |
328 } | |
329 | |
4687 | 330 /*************************************************** |
331 * Crap * | |
332 ***************************************************/ | |
333 static GtkItemFactoryEntry blist_menu[] = | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
334 { |
4687 | 335 /* Buddies menu */ |
336 { N_("/_Buddies"), NULL, NULL, 0, "<Branch>" }, | |
337 { N_("/Buddies/_Add A Buddy..."), "<CTL>B", gaim_gtk_blist_add_buddy_cb, 0, | |
338 "<StockItem>", GTK_STOCK_ADD }, | |
339 { N_("/Buddies/New _Instant Message..."), "<CTL>I", show_im_dialog, 0, | |
340 "<StockItem>", GAIM_STOCK_IM }, | |
341 { N_("/Buddies/Join a _Chat..."), "<CTL>C", join_chat, 0, | |
342 "<StockItem>", GAIM_STOCK_CHAT }, | |
343 { N_("/Buddies/sep1"), NULL, NULL, 0, "<Separator>" }, | |
344 { N_("/Buddies/Get _User Info..."), "<CTL>J", show_info_dialog, 0, | |
345 "<StockItem>", GAIM_STOCK_INFO }, | |
346 { N_("/Buddies/sep2"), NULL, NULL, 0, "<Separator>" }, | |
347 { N_("/Buddies/_Signoff"), "<CTL>D", signoff_all, 0, NULL }, | |
348 { N_("/Buddies/_Quit"), "<CTL>Q", do_quit, 0, | |
349 "<StockItem>", GTK_STOCK_QUIT }, | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
350 |
4687 | 351 /* Tools */ |
352 { N_("/_Tools"), NULL, NULL, 0, "<Branch>" }, | |
353 { N_("/Tools/_Away"), NULL, NULL, 0, "<Branch>" }, | |
354 { N_("/Tools/Buddy _Pounce"), NULL, NULL, 0, "<Branch>" }, | |
355 { N_("/Tools/sep1"), NULL, NULL, 0, "<Separator>" }, | |
356 { N_("/Tools/A_ccounts"), "<CTL>A", account_editor, 0, NULL }, | |
4694 | 357 { N_("/Tools/Preferences"), "<CTL>P", show_prefs, 0, |
4687 | 358 "<StockItem>", GTK_STOCK_PREFERENCES }, |
4698 | 359 { N_("/Tools/_File Transfers"), NULL, gaim_show_xfer_dialog, 0, |
4687 | 360 "<StockItem>", GTK_STOCK_REVERT_TO_SAVED }, |
361 { N_("/Tools/sep2"), NULL, NULL, 0, "<Separator>" }, | |
362 { N_("/Tools/P_rotocol Actions"), NULL, NULL, 0, "<Branch>" }, | |
363 { N_("/Tools/Pr_ivacy"), NULL, show_privacy_options, 0, NULL }, | |
4697 | 364 { N_("/Tools/View System _Log"), NULL, gtk_blist_show_systemlog_cb, 0, NULL }, |
3251 | 365 |
4687 | 366 /* Help */ |
367 { N_("/_Help"), NULL, NULL, 0, "<Branch>" }, | |
368 { N_("/Help/Online _Help"), "F1", NULL, 0, | |
369 "<StockItem>", GTK_STOCK_HELP }, | |
4697 | 370 { N_("/Help/_Debug Window"), NULL, show_debug, 0, NULL }, |
4687 | 371 { N_("/Help/_About"), NULL, show_about, 0, NULL }, |
372 | |
373 }; | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
374 |
4687 | 375 /********************************************************* |
376 * Private Utility functions * | |
377 *********************************************************/ | |
378 | |
379 static GdkPixbuf *gaim_gtk_blist_get_status_icon(struct buddy *b) | |
380 { | |
381 GdkPixbuf *status = NULL; | |
382 GdkPixbuf *scale = NULL; | |
383 GdkPixbuf *emblem = NULL; | |
384 gchar *filename = NULL; | |
385 const char *protoname = NULL; | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
386 |
4691 | 387 char *se = NULL, *sw = NULL ,*nw = NULL ,*ne = NULL; |
4687 | 388 |
389 int scalesize = 30; | |
390 | |
391 struct prpl* prpl = find_prpl(b->account->protocol); | |
392 if (prpl->list_icon) | |
393 protoname = prpl->list_icon(b->account, b); | |
394 if (prpl->list_emblems) | |
395 prpl->list_emblems(b, &se, &sw, &nw, &ne); | |
396 | |
397 if (!(blist_options & OPT_BLIST_SHOW_ICONS)) { | |
398 scalesize = 15; | |
399 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
|
400 } |
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
401 |
4701 | 402 |
4687 | 403 if (b->present == 2) { |
4701 | 404 struct gaim_gtk_blist_node *gtknode; |
4687 | 405 /* If b->present is 2, that means this buddy has just signed on. We use the "login" icon for the |
406 * status, and we set a timeout to change it to a normal icon after 10 seconds. */ | |
407 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "login.png", NULL); | |
408 status = gdk_pixbuf_new_from_file(filename,NULL); | |
409 g_free(filename); | |
4701 | 410 |
411 gtknode = GAIM_GTK_BLIST_NODE((GaimBlistNode*)b); | |
412 gtknode->timer = g_timeout_add(10000, (GSourceFunc)gaim_reset_present_icon, b); | |
413 | |
4687 | 414 /* "Hey, what's all this crap?" you ask. Status icons will be themeable too, and |
415 then it will look up protoname from the theme */ | |
416 } else { | |
417 char *image = g_strdup_printf("%s.png", protoname); | |
418 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
419 status = gdk_pixbuf_new_from_file(filename,NULL); | |
420 g_free(image); | |
421 g_free(filename); | |
1929
d51ea669d84e
[gaim-migrate @ 1939]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1918
diff
changeset
|
422 |
4687 | 423 } |
424 | |
425 if (!status) | |
426 return NULL; | |
427 | |
428 scale = gdk_pixbuf_scale_simple(status, scalesize, scalesize, GDK_INTERP_BILINEAR); | |
429 | |
430 /* Emblems */ | |
431 | |
432 /* Each protocol can specify up to four "emblems" to composite over the base icon. "away", "busy", "mobile user" | |
433 * are all examples of states represented by emblems. I'm not even really sure I like this yet. */ | |
434 | |
435 /* XXX Clean this crap up, yo. */ | |
436 if (se) { | |
437 char *image = g_strdup_printf("%s.png", se); | |
438 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
439 g_free(image); | |
440 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
441 g_free(filename); | |
442 if (emblem) { | |
443 if (blist_options & OPT_BLIST_SHOW_ICONS) | |
444 gdk_pixbuf_composite (emblem, | |
445 scale, 15, 15, | |
446 15, 15, | |
447 15, 15, | |
448 1, 1, | |
449 GDK_INTERP_BILINEAR, | |
450 255); | |
451 else | |
452 gdk_pixbuf_composite (emblem, | |
453 scale, 0, 0, | |
454 15, 15, | |
455 0, 0, | |
456 1, 1, | |
457 GDK_INTERP_BILINEAR, | |
458 255); | |
459 } | |
460 } | |
461 if (sw) { | |
462 char *image = g_strdup_printf("%s.png", sw); | |
463 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
464 g_free(image); | |
465 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
466 g_free(filename); | |
467 if (emblem) { | |
468 gdk_pixbuf_composite (emblem, | |
469 scale, 0, 15, | |
470 15, 15, | |
471 0, 15, | |
472 1, 1, | |
473 GDK_INTERP_BILINEAR, | |
474 255); | |
475 } | |
476 } | |
477 if (nw) { | |
478 char *image = g_strdup_printf("%s.png", nw); | |
479 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
480 g_free(image); | |
481 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
482 g_free(filename); | |
483 if (emblem) { | |
484 gdk_pixbuf_composite (emblem, | |
485 scale, 0, 0, | |
486 15, 15, | |
487 0, 0, | |
488 1, 1, | |
489 GDK_INTERP_BILINEAR, | |
490 255); | |
491 } | |
492 } | |
493 if (ne) { | |
494 char *image = g_strdup_printf("%s.png", ne); | |
495 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
496 g_free(image); | |
497 emblem = gdk_pixbuf_new_from_file(filename,NULL); | |
498 g_free(filename); | |
499 if (emblem) { | |
500 gdk_pixbuf_composite (emblem, | |
501 scale, 15, 0, | |
502 15, 15, | |
503 15, 0, | |
504 1, 1, | |
505 GDK_INTERP_BILINEAR, | |
506 255); | |
507 } | |
508 } | |
509 | |
510 | |
511 /* Idle gray buddies affects the whole row. This converts the status icon to greyscale. */ | |
4699 | 512 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS) |
4687 | 513 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0, FALSE); |
514 return scale; | |
1 | 515 } |
516 | |
4687 | 517 static GdkPixbuf *gaim_gtk_blist_get_buddy_icon(struct buddy *b) |
1 | 518 { |
4687 | 519 /* This just opens a file from ~/.gaim/icons/screenname. This needs to change to be more gooder. */ |
520 char *file = g_build_filename(gaim_user_dir(), "icons", normalize(b->name), NULL); | |
521 GdkPixbuf *buf = gdk_pixbuf_new_from_file(file, NULL); | |
522 | |
523 if (!(blist_options & OPT_BLIST_SHOW_ICONS)) | |
524 return NULL; | |
525 | |
526 if (buf) { | |
4699 | 527 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS) { |
4687 | 528 gdk_pixbuf_saturate_and_pixelate(buf, buf, 0, FALSE); |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
529 } |
4687 | 530 return gdk_pixbuf_scale_simple(buf,30,30, GDK_INTERP_BILINEAR); |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
531 } |
4687 | 532 return NULL; |
2986 | 533 } |
534 | |
4687 | 535 static gchar *gaim_gtk_blist_get_name_markup(struct buddy *b) |
1 | 536 { |
4687 | 537 char *name = gaim_get_buddy_alias(b); |
538 char *esc = g_markup_escape_text(name, strlen(name)), *text = NULL; | |
539 /* XXX Clean up this crap */ | |
4699 | 540 |
4687 | 541 int ihrs, imin; |
542 char *idletime = ""; | |
543 char *warning = idletime; | |
4699 | 544 time_t t; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
545 |
4687 | 546 if (!(blist_options & OPT_BLIST_SHOW_ICONS)) { |
4699 | 547 if (b->idle > 0 && blist_options & OPT_BLIST_GREY_IDLERS) { |
4687 | 548 text = g_strdup_printf("<span color='gray'>%s</span>", |
4699 | 549 esc); |
4687 | 550 g_free(esc); |
551 return text; | |
552 } else { | |
553 return esc; | |
554 } | |
1 | 555 } |
556 | |
4687 | 557 time(&t); |
558 ihrs = (t - b->idle) / 3600; | |
559 imin = ((t - b->idle) / 60) % 60; | |
4699 | 560 |
4687 | 561 if (b->idle) { |
562 if (ihrs) | |
563 idletime = g_strdup_printf(_("Idle (%dh%02dm)"), ihrs, imin); | |
564 else | |
565 idletime = g_strdup_printf(_("Idle (%dm)"), imin); | |
566 } | |
4699 | 567 |
4687 | 568 if (b->evil > 0) |
569 warning = g_strdup_printf(_("Warned (%d%%)"), b->evil); | |
4699 | 570 |
571 if (b->idle && blist_options & OPT_BLIST_GREY_IDLERS) | |
4687 | 572 text = g_strdup_printf("<span color='grey'>%s</span>\n<span color='gray' size='smaller'>%s %s</span>", |
573 esc, | |
574 idletime, warning); | |
575 else | |
4699 | 576 text = g_strdup_printf("%s\n<span color='gray' size='smaller'>%s %s</span>", esc, idletime, warning); |
4687 | 577 |
578 if (idletime[0]) | |
579 g_free(idletime); | |
580 if (warning[0]) | |
581 g_free(warning); | |
4699 | 582 |
4687 | 583 return text; |
584 } | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
585 |
4687 | 586 /********************************************************************************** |
587 * Public API Functions * | |
588 **********************************************************************************/ | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
589 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
|
590 { |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
591 blist->ui_data = g_new0(struct gaim_gtk_buddy_list, 1); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
592 } |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
593 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
594 static void gaim_gtk_blist_new_node(GaimBlistNode *node) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
595 { |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
596 node->ui_data = g_new0(struct gaim_gtk_blist_node, 1); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
597 } |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
598 |
4702 | 599 enum {DRAG_BUDDY, DRAG_ROW}; |
600 | |
4687 | 601 static void gaim_gtk_blist_show(struct gaim_buddy_list *list) |
602 { | |
603 GtkItemFactory *ift; | |
604 GtkCellRenderer *rend; | |
605 GtkTreeViewColumn *column; | |
606 GtkWidget *sw; | |
607 GtkWidget *button; | |
4694 | 608 GtkSizeGroup *sg; |
4702 | 609 GtkTargetEntry gte[] = {{"GAIM_BUDDY", GTK_TARGET_SAME_APP, DRAG_ROW}, |
610 {"application/x-im-contact", 0, DRAG_BUDDY}}; | |
4690 | 611 |
4687 | 612 if (gtkblist) { |
613 gtk_widget_show(gtkblist->window); | |
614 return; | |
615 } | |
4690 | 616 |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
617 gtkblist = GAIM_GTK_BLIST(list); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
618 |
4687 | 619 gtkblist->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
620 gtk_window_set_title(GTK_WINDOW(gtkblist->window), _("Buddy List")); | |
4690 | 621 |
4687 | 622 gtkblist->vbox = gtk_vbox_new(FALSE, 6); |
623 gtk_container_add(GTK_CONTAINER(gtkblist->window), gtkblist->vbox); | |
1 | 624 |
4698 | 625 g_signal_connect(G_OBJECT(gtkblist->window), "delete_event", G_CALLBACK(gaim_gtk_blist_destroy_cb), NULL); |
626 | |
4687 | 627 /******************************* Menu bar *************************************/ |
628 ift = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GaimMain>", NULL); | |
629 gtk_item_factory_create_items(ift, sizeof(blist_menu) / sizeof(*blist_menu), | |
630 blist_menu, NULL); | |
631 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtk_item_factory_get_widget(ift, "<GaimMain>"), FALSE, FALSE, 0); | |
1 | 632 |
4694 | 633 awaymenu = gtk_item_factory_get_widget(ift, "/Tools/Away"); |
634 do_away_menu(); | |
635 | |
4696 | 636 bpmenu = gtk_item_factory_get_widget(ift, "/Tools/Buddy Pounce"); |
637 do_bp_menu(); | |
638 | |
639 protomenu = gtk_item_factory_get_widget(ift, "/Tools/Protocol Actions"); | |
640 do_proto_menu(); | |
641 | |
4687 | 642 /****************************** GtkTreeView **********************************/ |
643 sw = gtk_scrolled_window_new(NULL,NULL); | |
644 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); | |
645 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
4690 | 646 gtk_widget_set_size_request(sw, 200, 200); |
4687 | 647 |
648 gtkblist->treemodel = gtk_tree_store_new(BLIST_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, | |
649 G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_POINTER); | |
4702 | 650 |
4687 | 651 gtkblist->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(gtkblist->treemodel)); |
4702 | 652 |
653 /* Set up dnd */ | |
654 gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(gtkblist->treeview), GDK_BUTTON1_MASK, gte, | |
655 2, GDK_ACTION_COPY); | |
656 gtk_tree_view_enable_model_drag_dest(GTK_TREE_VIEW(gtkblist->treeview), gte, 2, | |
657 GDK_ACTION_COPY | GDK_ACTION_MOVE); | |
658 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-received", gaim_gtk_blist_drag_data_rcv_cb, NULL); | |
659 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-get", gaim_gtk_blist_drag_data_get_cb, NULL); | |
660 | |
4687 | 661 |
662 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(gtkblist->treeview), FALSE); | |
1 | 663 |
4687 | 664 rend = gtk_cell_renderer_pixbuf_new(); |
665 column = gtk_tree_view_column_new_with_attributes("Status", rend, "pixbuf", STATUS_ICON_COLUMN, NULL); | |
666 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); | |
667 | |
668 rend = gtk_cell_renderer_text_new(); | |
669 column = gtk_tree_view_column_new_with_attributes("Name", rend, "markup", NAME_COLUMN, NULL); | |
670 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); | |
671 | |
672 rend = gtk_cell_renderer_text_new(); | |
673 column = gtk_tree_view_column_new_with_attributes("Warning", rend, "text", WARNING_COLUMN, NULL); | |
674 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); | |
675 | |
676 rend = gtk_cell_renderer_text_new(); | |
677 column = gtk_tree_view_column_new_with_attributes("Idle", rend, "text", IDLE_COLUMN, NULL); | |
678 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); | |
1 | 679 |
4687 | 680 rend = gtk_cell_renderer_pixbuf_new(); |
681 column = gtk_tree_view_column_new_with_attributes("Buddy Icon", rend, "pixbuf", BUDDY_ICON_COLUMN, NULL); | |
682 g_object_set(rend, "xalign", 1.0, NULL); | |
683 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); | |
684 | |
685 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-activated", G_CALLBACK(gtk_blist_row_activated_cb), NULL); | |
686 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
|
687 |
4687 | 688 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), sw, TRUE, TRUE, 0); |
689 gtk_container_add(GTK_CONTAINER(sw), gtkblist->treeview); | |
690 | |
691 /**************************** Button Box **************************************/ | |
4694 | 692 |
693 sg = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); | |
4687 | 694 gtkblist->bbox = gtk_hbox_new(TRUE, 0); |
695 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtkblist->bbox, FALSE, FALSE, 0); | |
696 button = gaim_pixbuf_button_from_stock(_("IM"), GAIM_STOCK_IM, GAIM_BUTTON_VERTICAL); | |
697 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
698 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 699 gtk_size_group_add_widget(sg, button); |
4692 | 700 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_im_cb), |
4697 | 701 gtkblist->treeview); |
702 | |
4687 | 703 button = gaim_pixbuf_button_from_stock(_("Get Info"), GAIM_STOCK_INFO, GAIM_BUTTON_VERTICAL); |
704 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
705 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 706 gtk_size_group_add_widget(sg, button); |
707 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_info_cb), | |
4697 | 708 gtkblist->treeview); |
709 | |
4687 | 710 button = gaim_pixbuf_button_from_stock(_("Chat"), GAIM_STOCK_CHAT, GAIM_BUTTON_VERTICAL); |
711 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
712 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 713 gtk_size_group_add_widget(sg, button); |
714 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_chat_cb), NULL); | |
715 | |
4687 | 716 button = gaim_pixbuf_button_from_stock(_("Away"), GAIM_STOCK_AWAY, GAIM_BUTTON_VERTICAL); |
717 gtk_box_pack_start(GTK_BOX(gtkblist->bbox), button, FALSE, FALSE, 0); | |
718 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | |
4694 | 719 gtk_size_group_add_widget(sg, button); |
720 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtk_blist_button_away_cb), NULL); | |
4687 | 721 |
722 /* OK... let's show this bad boy. */ | |
723 gaim_gtk_blist_refresh(list); | |
724 gtk_widget_show_all(gtkblist->window); | |
4697 | 725 |
726 gaim_gtk_blist_update_toolbar(); | |
727 | |
4687 | 728 } |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
729 |
4687 | 730 void gaim_gtk_blist_refresh(struct gaim_buddy_list *list) |
731 { | |
732 GaimBlistNode *group = list->root; | |
733 GaimBlistNode *buddy; | |
4690 | 734 |
4687 | 735 while (group) { |
736 gaim_gtk_blist_update(list, group); | |
737 buddy = group->child; | |
738 while (buddy) { | |
4699 | 739 gaim_gtk_blist_update(list, buddy); |
4687 | 740 buddy = buddy->next; |
741 } | |
742 group = group->next; | |
743 } | |
744 } | |
1 | 745 |
4699 | 746 static gboolean get_iter_from_node_helper(GaimBlistNode *node, GtkTreeIter *iter, GtkTreeIter *root) { |
747 do { | |
748 GaimBlistNode *n; | |
749 GtkTreeIter child; | |
750 | |
751 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), root, NODE_COLUMN, &n, -1); | |
752 if(n == node) { | |
753 *iter = *root; | |
754 return TRUE; | |
755 } | |
756 | |
757 if(gtk_tree_model_iter_children(GTK_TREE_MODEL(gtkblist->treemodel), &child, root)) { | |
758 if(get_iter_from_node_helper(node,iter,&child)) | |
759 return TRUE; | |
760 } | |
761 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(gtkblist->treemodel), root)); | |
762 | |
763 return FALSE; | |
764 } | |
765 | |
766 static gboolean get_iter_from_node(GaimBlistNode *node, GtkTreeIter *iter) { | |
767 GtkTreeIter root; | |
768 | |
769 if (!gtkblist) | |
770 return FALSE; | |
771 | |
772 if(!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(gtkblist->treemodel), &root)) | |
773 return FALSE; | |
774 | |
775 return get_iter_from_node_helper(node, iter, &root); | |
776 } | |
777 | |
4697 | 778 void gaim_gtk_blist_update_toolbar() { |
779 if (!gtkblist) | |
780 return; | |
4699 | 781 |
4697 | 782 gtk_container_foreach(GTK_CONTAINER(gtkblist->bbox), gaim_gtk_blist_update_toolbar_icons, NULL); |
4699 | 783 |
4697 | 784 if (blist_options & OPT_BLIST_NO_BUTTONS) |
785 gtk_widget_hide(gtkblist->bbox); | |
786 else | |
787 gtk_widget_show_all(gtkblist->bbox); | |
788 } | |
789 | |
4701 | 790 static void gaim_gtk_blist_remove(struct gaim_buddy_list *list, GaimBlistNode *node) |
791 { | |
792 struct gaim_gtk_blist_node *gtknode; | |
793 GtkTreeIter iter; | |
794 | |
795 if (!node->ui_data) | |
796 return; | |
797 | |
798 gtknode = (struct gaim_gtk_blist_node *)node->ui_data; | |
799 | |
800 if (gtknode->timer > 0) { | |
801 g_source_remove(gtknode->timer); | |
802 gtknode->timer = 0; | |
803 } | |
804 | |
805 if (get_iter_from_node(node, &iter)) { | |
806 gtk_tree_store_remove(gtkblist->treemodel, &iter); | |
807 if(GAIM_BLIST_NODE_IS_BUDDY(node) && gaim_blist_get_group_online_count((struct group *)node->parent) == 0) { | |
808 GtkTreeIter groupiter; | |
809 if(get_iter_from_node(node->parent, &groupiter)) | |
810 gtk_tree_store_remove(gtkblist->treemodel, &groupiter); | |
811 } | |
812 } | |
813 } | |
814 | |
815 | |
4687 | 816 static void gaim_gtk_blist_update(struct gaim_buddy_list *list, GaimBlistNode *node) |
817 { | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
818 struct gaim_gtk_blist_node *gtknode; |
4699 | 819 GtkTreeIter iter; |
4687 | 820 gboolean expand = FALSE; |
4699 | 821 gboolean new_entry = FALSE; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
822 |
4687 | 823 if (!gtkblist) |
824 return; | |
4699 | 825 |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
826 gtknode = GAIM_GTK_BLIST_NODE(node); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
827 |
4690 | 828 |
4699 | 829 if (!get_iter_from_node(node, &iter)) { /* This is a newly added node */ |
830 new_entry = TRUE; | |
4687 | 831 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { |
832 if (((struct buddy*)node)->present) { | |
4699 | 833 GtkTreeIter groupiter; |
834 GaimBlistNode *oldersibling; | |
835 GtkTreeIter oldersiblingiter; | |
4690 | 836 |
4699 | 837 if(node->parent && !get_iter_from_node(node->parent, &groupiter)) { |
838 /* This buddy's group has not yet been added. We do that here */ | |
4687 | 839 char *mark = g_strdup_printf("<span weight='bold'>%s</span>", ((struct group*)node->parent)->name); |
4699 | 840 oldersibling = node->parent->prev; |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
841 |
4687 | 842 /* We traverse backwards through the buddy list to find the node in the tree to insert it after */ |
4699 | 843 while (oldersibling && !get_iter_from_node(oldersibling, &oldersiblingiter)) |
844 oldersibling = oldersibling->prev; | |
4690 | 845 |
4687 | 846 /* This is where we create the node and add it. */ |
4699 | 847 gtk_tree_store_insert_after(gtkblist->treemodel, &groupiter, NULL, oldersibling ? &oldersiblingiter : NULL); |
848 gtk_tree_store_set(gtkblist->treemodel, &groupiter, | |
4687 | 849 STATUS_ICON_COLUMN, gtk_widget_render_icon |
4691 | 850 (gtkblist->treeview,GTK_STOCK_OPEN,GTK_ICON_SIZE_SMALL_TOOLBAR,NULL), |
4687 | 851 NAME_COLUMN, mark, |
852 NODE_COLUMN, node->parent, | |
853 -1); | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
854 |
4687 | 855 expand = TRUE; |
856 } | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
857 |
4699 | 858 oldersibling = node->prev; |
859 while (oldersibling && !get_iter_from_node(oldersibling, &oldersiblingiter)) | |
860 oldersibling = oldersibling->prev; | |
861 | |
862 gtk_tree_store_insert_after(gtkblist->treemodel, &iter, &groupiter, oldersibling ? &oldersiblingiter : NULL); | |
863 | |
4687 | 864 if (expand) { /* expand was set to true if this is the first element added to a group. In such case |
865 * we expand the group node */ | |
4699 | 866 GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &groupiter); |
867 gtk_tree_view_expand_row(GTK_TREE_VIEW(gtkblist->treeview), path, TRUE); | |
4687 | 868 } |
4699 | 869 } |
870 } | |
871 } | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
872 |
4687 | 873 if (GAIM_BLIST_NODE_IS_BUDDY(node) && ((struct buddy*)node)->present) { |
874 GdkPixbuf *status, *avatar; | |
875 char *mark; | |
4697 | 876 char *warning = NULL, *idle = NULL; |
877 | |
4687 | 878 status = gaim_gtk_blist_get_status_icon((struct buddy*)node); |
879 avatar = gaim_gtk_blist_get_buddy_icon((struct buddy*)node); | |
880 mark = gaim_gtk_blist_get_name_markup((struct buddy*)node); | |
4697 | 881 |
4699 | 882 if ((((struct buddy*)node)->idle > 0) && |
4697 | 883 (!(blist_options & OPT_BLIST_SHOW_ICONS) && (blist_options & OPT_BLIST_SHOW_IDLETIME))) { |
884 time_t t; | |
885 int ihrs, imin; | |
886 time(&t); | |
887 ihrs = (t - ((struct buddy *)node)->idle) / 3600; | |
888 imin = ((t - ((struct buddy*)node)->idle) / 60) % 60; | |
4699 | 889 idle = g_strdup_printf("%d:%02d", ihrs, imin); |
4697 | 890 } |
891 | |
4699 | 892 if ((((struct buddy*)node)->evil > 0) && |
4697 | 893 (!(blist_options & OPT_BLIST_SHOW_ICONS) && (blist_options & OPT_BLIST_SHOW_WARN))) { |
4699 | 894 warning = g_strdup_printf("%d%%", ((struct buddy*)node)->evil); |
4697 | 895 } |
896 | |
4699 | 897 gtk_tree_store_set(gtkblist->treemodel, &iter, |
4687 | 898 STATUS_ICON_COLUMN, status, |
899 NAME_COLUMN, mark, | |
4697 | 900 WARNING_COLUMN, warning, |
901 IDLE_COLUMN, idle, | |
4699 | 902 BUDDY_ICON_COLUMN, avatar, |
4687 | 903 NODE_COLUMN, node, |
904 -1); | |
4699 | 905 |
4687 | 906 g_free(mark); |
4697 | 907 if (idle) |
908 g_free(idle); | |
909 if (warning) | |
910 g_free(warning); | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
911 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
912 if (status != NULL) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
913 g_object_unref(status); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
914 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
915 if (avatar != NULL) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
916 g_object_unref(avatar); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
917 |
4701 | 918 } else if (GAIM_BLIST_NODE_IS_BUDDY(node) && !new_entry) { |
919 gaim_gtk_blist_remove(list, node); | |
4687 | 920 } |
921 } | |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
922 |
4687 | 923 static void gaim_gtk_blist_destroy(struct gaim_buddy_list *list) |
924 { | |
925 gtk_widget_destroy(gtkblist->window); | |
926 } | |
1 | 927 |
4687 | 928 static void gaim_gtk_blist_set_visible(struct gaim_buddy_list *list, gboolean show) |
929 { | |
4698 | 930 if (show) { |
4699 | 931 gtk_window_present(GTK_WINDOW(gtkblist->window)); |
4698 | 932 } else { |
933 if (!connections || docklet_count) { | |
934 #ifdef _WIN32 | |
935 wgaim_systray_minimize(blist); | |
936 #endif | |
937 gtk_widget_hide(gtkblist->window); | |
938 } else { | |
939 gtk_window_iconify(GTK_WINDOW(gtkblist->window)); | |
940 } | |
941 } | |
942 } | |
943 | |
944 void gaim_gtk_blist_docklet_toggle() { | |
945 /* Useful for the docklet plugin and also for the win32 tray icon*/ | |
946 /* This is called when one of those is clicked--it will show/hide the | |
947 buddy list/login window--depending on which is active */ | |
948 if (connections && gtkblist) { | |
949 if (GTK_WIDGET_VISIBLE(gtkblist->window)) { | |
950 gaim_blist_set_visible(GAIM_WINDOW_ICONIFIED(gtkblist->window) || gaim_gtk_blist_obscured); | |
951 } else { | |
952 #if _WIN32 | |
953 wgaim_systray_maximize(blist); | |
954 #endif | |
955 gaim_blist_set_visible(TRUE); | |
956 } | |
957 } else if (connections) { | |
958 /* we're logging in or something... do nothing */ | |
959 debug_printf("docklet_toggle called with connections but no blist!\n"); | |
960 } else { | |
961 if (GTK_WIDGET_VISIBLE(mainwindow)) { | |
962 if (GAIM_WINDOW_ICONIFIED(mainwindow)) { | |
963 gtk_window_present(GTK_WINDOW(mainwindow)); | |
964 } else { | |
965 #if _WIN32 | |
966 wgaim_systray_minimize(mainwindow); | |
967 #endif | |
968 gtk_widget_hide(mainwindow); | |
969 } | |
970 } else { | |
971 #if _WIN32 | |
972 wgaim_systray_maximize(mainwindow); | |
973 #endif | |
974 gtk_window_present(GTK_WINDOW(mainwindow)); | |
975 } | |
976 } | |
977 } | |
978 | |
979 void gaim_gtk_blist_docklet_add() | |
980 { | |
981 docklet_count++; | |
982 } | |
983 | |
984 void gaim_gtk_blist_docklet_remove() | |
985 { | |
986 docklet_count--; | |
987 if (!docklet_count) { | |
988 if (connections) { | |
989 gaim_blist_set_visible(TRUE); | |
990 } else { | |
991 gtk_window_present(GTK_WINDOW(gtkblist->window)); | |
992 } | |
993 } | |
4687 | 994 } |
1 | 995 |
4687 | 996 static struct gaim_blist_ui_ops blist_ui_ops = |
997 { | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
998 gaim_gtk_blist_new_list, |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4694
diff
changeset
|
999 gaim_gtk_blist_new_node, |
4687 | 1000 gaim_gtk_blist_show, |
1001 gaim_gtk_blist_update, | |
1002 gaim_gtk_blist_remove, | |
1003 gaim_gtk_blist_destroy, | |
1004 gaim_gtk_blist_set_visible | |
1005 }; | |
1 | 1006 |
1007 | |
4687 | 1008 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
|
1009 { |
4687 | 1010 return &blist_ui_ops; |
1037
1c663beef29d
[gaim-migrate @ 1047]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1036
diff
changeset
|
1011 } |
1c663beef29d
[gaim-migrate @ 1047]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1036
diff
changeset
|
1012 |
3131 | 1013 |
1014 | |
4687 | 1015 /********************************************************************* |
1016 * Public utility functions * | |
1017 *********************************************************************/ | |
1058
4927ce25d8cc
[gaim-migrate @ 1068]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1057
diff
changeset
|
1018 |
4687 | 1019 GdkPixbuf * |
1020 create_prpl_icon(struct gaim_account *account) | |
4553
d03fcb3f4be2
[gaim-migrate @ 4833]
Christian Hammond <chipx86@chipx86.com>
parents:
4525
diff
changeset
|
1021 { |
4687 | 1022 struct prpl *prpl = find_prpl(account->protocol); |
1023 GdkPixbuf *status = NULL; | |
1024 char *filename = NULL; | |
1025 const char *protoname = prpl->list_icon(account, NULL); | |
1026 /* "Hey, what's all this crap?" you ask. Status icons will be themeable too, and | |
1027 then it will look up protoname from the theme */ | |
1028 if (!strcmp(protoname, "aim")) { | |
1029 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "aim.png", NULL); | |
1030 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1031 g_free(filename); | |
1032 } else if (!strcmp(protoname, "yahoo")) { | |
1033 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "yahoo.png", NULL); | |
1034 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1035 g_free(filename); | |
1036 } else if (!strcmp(protoname, "msn")) { | |
1037 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "msn.png", NULL); | |
1038 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1039 g_free(filename); | |
1040 } else if (!strcmp(protoname, "jabber")) { | |
1041 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "jabber.png", NULL); | |
1042 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1043 g_free(filename); | |
1044 } else if (!strcmp(protoname, "icq")) { | |
1045 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "icq.png", NULL); | |
1046 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1047 g_free(filename); | |
1048 } else if (!strcmp(protoname, "gadu-gadu")) { | |
1049 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "gadugadu.png", NULL); | |
1050 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1051 g_free(filename); | |
1052 } else if (!strcmp(protoname, "napster")) { | |
1053 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "napster.png", NULL); | |
1054 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1055 g_free(filename); | |
1056 } else if (!strcmp(protoname, "irc")) { | |
1057 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "irc.png", NULL); | |
1058 status = gdk_pixbuf_new_from_file(filename,NULL); | |
1059 g_free(filename); | |
960
fa681641643d
[gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
945
diff
changeset
|
1060 } |
4687 | 1061 return status; |
1 | 1062 } |
4699 | 1063 |