Mercurial > pidgin
annotate src/gtkblist.c @ 11868:4b71193448b3
[gaim-migrate @ 14159]
Sean used tabs, not spaces.
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Thu, 27 Oct 2005 21:48:05 +0000 |
parents | 01c3eec6ea3c |
children | fdb78734e2ae |
rev | line source |
---|---|
5228 | 1 /* |
10297
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10288
diff
changeset
|
2 * @file gtkblist.c GTK+ BuddyList API |
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10288
diff
changeset
|
3 * @ingroup gtkui |
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10288
diff
changeset
|
4 * |
5228 | 5 * gaim |
6 * | |
8046 | 7 * Gaim is the legal property of its developers, whose names are too numerous |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
5228 | 10 * |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 * | |
25 */ | |
9791 | 26 #include "internal.h" |
27 #include "gtkgaim.h" | |
7620 | 28 |
29 #include "account.h" | |
9015 | 30 #include "connection.h" |
7620 | 31 #include "core.h" |
32 #include "debug.h" | |
33 #include "notify.h" | |
34 #include "prpl.h" | |
35 #include "prefs.h" | |
8986 | 36 #include "plugin.h" |
7620 | 37 #include "request.h" |
38 #include "signals.h" | |
10297
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10288
diff
changeset
|
39 #include "gtkstock.h" |
7620 | 40 #include "util.h" |
41 | |
42 #include "gtkaccount.h" | |
43 #include "gtkblist.h" | |
44 #include "gtkconv.h" | |
45 #include "gtkdebug.h" | |
9709 | 46 #include "gtkdialogs.h" |
7620 | 47 #include "gtkft.h" |
48 #include "gtklog.h" | |
49 #include "gtkpounce.h" | |
11740 | 50 #include "gtkplugin.h" |
7620 | 51 #include "gtkprefs.h" |
52 #include "gtkprivacy.h" | |
8113 | 53 #include "gtkroomlist.h" |
10643 | 54 #include "gtkstatusbox.h" |
7620 | 55 #include "gtkutils.h" |
56 | |
5228 | 57 #include <gdk/gdkkeysyms.h> |
58 #include <gtk/gtk.h> | |
7620 | 59 #include <gdk/gdk.h> |
60 | |
61 typedef struct | |
62 { | |
63 GaimAccount *account; | |
64 | |
65 GtkWidget *window; | |
66 GtkWidget *combo; | |
67 GtkWidget *entry; | |
68 GtkWidget *entry_for_alias; | |
69 GtkWidget *account_box; | |
70 | |
71 } GaimGtkAddBuddyData; | |
72 | |
73 typedef struct | |
74 { | |
9811 | 75 GaimAccount *account; |
9812 | 76 gchar *default_chat_name; |
9811 | 77 |
78 GtkWidget *window; | |
7620 | 79 GtkWidget *account_menu; |
80 GtkWidget *alias_entry; | |
81 GtkWidget *group_combo; | |
82 GtkWidget *entries_box; | |
83 GtkSizeGroup *sg; | |
84 | |
85 GList *entries; | |
86 | |
87 } GaimGtkAddChatData; | |
88 | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
89 typedef struct |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
90 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
91 GaimAccount *account; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
92 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
93 GtkWidget *window; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
94 GtkWidget *account_menu; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
95 GtkWidget *entries_box; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
96 GtkSizeGroup *sg; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
97 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
98 GList *entries; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
99 } GaimGtkJoinChatData; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
100 |
7620 | 101 |
9949 | 102 static GtkWidget *protomenu = NULL; |
5228 | 103 |
11796 | 104 static GList *gaim_gtk_blist_sort_methods = NULL; |
5422 | 105 static struct gaim_gtk_blist_sort_method *current_sort_method = NULL; |
7620 | 106 static GtkTreeIter sort_method_none(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur); |
107 | |
108 /* The functions we use for sorting aren't available in gtk 2.0.x, and | |
109 * segfault in 2.2.0. 2.2.1 is known to work, so I'll require that */ | |
110 #if GTK_CHECK_VERSION(2,2,1) | |
111 static GtkTreeIter sort_method_alphabetical(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur); | |
112 static GtkTreeIter sort_method_status(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur); | |
113 static GtkTreeIter sort_method_log(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur); | |
114 #endif | |
115 static GaimGtkBuddyList *gtkblist = NULL; | |
5228 | 116 |
117 /* part of the best damn Docklet code this side of Tahiti */ | |
118 static gboolean gaim_gtk_blist_obscured = FALSE; | |
119 | |
120 static void gaim_gtk_blist_selection_changed(GtkTreeSelection *selection, gpointer data); | |
7620 | 121 static void gaim_gtk_blist_update(GaimBuddyList *list, GaimBlistNode *node); |
5234 | 122 static char *gaim_get_tooltip_text(GaimBlistNode *node); |
5228 | 123 static char *item_factory_translate_func (const char *path, gpointer func_data); |
5273 | 124 static gboolean get_iter_from_node(GaimBlistNode *node, GtkTreeIter *iter); |
7620 | 125 static void redo_buddy_list(GaimBuddyList *list, gboolean remove); |
126 static void gaim_gtk_blist_collapse_contact_cb(GtkWidget *w, GaimBlistNode *node); | |
127 | |
11059
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
128 static void gaim_gtk_blist_tooltip_destroy(); |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
129 |
5256 | 130 struct _gaim_gtk_blist_node { |
131 GtkTreeRowReference *row; | |
7620 | 132 gboolean contact_expanded; |
5256 | 133 }; |
134 | |
10968
e0d5038fbb7e
[gaim-migrate @ 12789]
Christopher O'Brien <siege@pidgin.im>
parents:
10924
diff
changeset
|
135 |
10118 | 136 static char dim_grey_string[8] = ""; |
10144 | 137 static char *dim_grey() |
10118 | 138 { |
139 if (!gtkblist) | |
140 return "dim grey"; | |
141 if (!dim_grey_string[0]) { | |
142 GtkStyle *style = gtk_widget_get_style(gtkblist->treeview); | |
143 snprintf(dim_grey_string, sizeof(dim_grey_string), "#%02x%02x%02x", | |
144 style->text_aa[GTK_STATE_NORMAL].red >> 8, | |
145 style->text_aa[GTK_STATE_NORMAL].green >> 8, | |
146 style->text_aa[GTK_STATE_NORMAL].blue >> 8); | |
147 } | |
148 return dim_grey_string; | |
149 } | |
10144 | 150 |
5228 | 151 /*************************************************** |
152 * Callbacks * | |
153 ***************************************************/ | |
154 | |
155 static gboolean gtk_blist_delete_cb(GtkWidget *w, GdkEventAny *event, gpointer data) | |
156 { | |
11709
cae2fb7e8594
[gaim-migrate @ 14000]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11692
diff
changeset
|
157 gaim_core_quit(); |
5228 | 158 |
159 /* we handle everything, event should not propogate further */ | |
160 return TRUE; | |
161 } | |
162 | |
163 static gboolean gtk_blist_configure_cb(GtkWidget *w, GdkEventConfigure *event, gpointer data) | |
164 { | |
165 /* unfortunately GdkEventConfigure ignores the window gravity, but * | |
166 * the only way we have of setting the position doesn't. we have to * | |
7620 | 167 * call get_position because it does pay attention to the gravity. * |
168 * this is inefficient and I agree it sucks, but it's more likely * | |
169 * to work correctly. - Robot101 */ | |
5228 | 170 gint x, y; |
171 | |
172 /* check for visibility because when we aren't visible, this will * | |
173 * give us bogus (0,0) coordinates. - xOr */ | |
7620 | 174 if (GTK_WIDGET_VISIBLE(w)) |
5228 | 175 gtk_window_get_position(GTK_WINDOW(w), &x, &y); |
7620 | 176 else |
177 return FALSE; /* carry on normally */ | |
178 | |
179 /* don't save if nothing changed */ | |
180 if (x == gaim_prefs_get_int("/gaim/gtk/blist/x") && | |
181 y == gaim_prefs_get_int("/gaim/gtk/blist/y") && | |
182 event->width == gaim_prefs_get_int("/gaim/gtk/blist/width") && | |
183 event->height == gaim_prefs_get_int("/gaim/gtk/blist/height")) { | |
184 | |
185 return FALSE; /* carry on normally */ | |
5228 | 186 } |
187 | |
7620 | 188 /* don't save off-screen positioning */ |
189 if (x + event->width < 0 || | |
9811 | 190 y + event->height < 0 || |
191 x > gdk_screen_width() || | |
192 y > gdk_screen_height()) { | |
7620 | 193 |
194 return FALSE; /* carry on normally */ | |
195 } | |
196 | |
197 /* store the position */ | |
198 gaim_prefs_set_int("/gaim/gtk/blist/x", x); | |
199 gaim_prefs_set_int("/gaim/gtk/blist/y", y); | |
200 gaim_prefs_set_int("/gaim/gtk/blist/width", event->width); | |
201 gaim_prefs_set_int("/gaim/gtk/blist/height", event->height); | |
202 | |
5228 | 203 /* continue to handle event normally */ |
204 return FALSE; | |
205 } | |
206 | |
207 static gboolean gtk_blist_visibility_cb(GtkWidget *w, GdkEventVisibility *event, gpointer data) | |
208 { | |
209 if (event->state == GDK_VISIBILITY_FULLY_OBSCURED) | |
210 gaim_gtk_blist_obscured = TRUE; | |
211 else | |
212 gaim_gtk_blist_obscured = FALSE; | |
213 | |
214 /* continue to handle event normally */ | |
215 return FALSE; | |
216 } | |
217 | |
7620 | 218 static void gtk_blist_menu_info_cb(GtkWidget *w, GaimBuddy *b) |
5228 | 219 { |
220 serv_get_info(b->account->gc, b->name); | |
221 } | |
222 | |
7620 | 223 static void gtk_blist_menu_im_cb(GtkWidget *w, GaimBuddy *b) |
5228 | 224 { |
9728 | 225 gaim_gtkdialogs_im_with_user(b->account, b->name); |
5228 | 226 } |
227 | |
9466 | 228 static void gtk_blist_menu_send_file_cb(GtkWidget *w, GaimBuddy *b) |
229 { | |
230 serv_send_file(b->account->gc, b->name, NULL); | |
231 } | |
232 | |
7620 | 233 static void gtk_blist_menu_autojoin_cb(GtkWidget *w, GaimChat *chat) |
234 { | |
7693 | 235 gaim_blist_node_set_bool((GaimBlistNode*)chat, "gtk-autojoin", |
236 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w))); | |
7620 | 237 } |
238 | |
239 static void gtk_blist_menu_join_cb(GtkWidget *w, GaimChat *chat) | |
5228 | 240 { |
5234 | 241 serv_join_chat(chat->account->gc, chat->components); |
242 } | |
243 | |
11016 | 244 static void gtk_blist_renderer_edited_cb(GtkCellRendererText *text_rend, char *arg1, |
245 char *arg2, gpointer nada) | |
246 { | |
247 GtkTreeIter iter; | |
248 GtkTreePath *path; | |
249 GValue val = {0,}; | |
250 GaimBlistNode *node; | |
251 | |
252 path = gtk_tree_path_new_from_string (arg1); | |
253 gtk_tree_model_get_iter (GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
254 gtk_tree_path_free (path); | |
255 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
256 node = g_value_get_pointer(&val); | |
257 gtk_tree_view_set_enable_search (GTK_TREE_VIEW(gtkblist->treeview), TRUE); | |
258 g_object_set(G_OBJECT(gtkblist->text_rend), "editable", FALSE, NULL); | |
259 switch (node->type){ | |
260 case GAIM_BLIST_CONTACT_NODE: | |
261 gaim_blist_alias_buddy(gaim_contact_get_priority_buddy((GaimContact*)node), arg2); | |
262 break; | |
263 case GAIM_BLIST_BUDDY_NODE: | |
264 gaim_blist_alias_buddy((GaimBuddy*)node, arg2); | |
265 break; | |
266 case GAIM_BLIST_GROUP_NODE: | |
267 gaim_blist_rename_group((GaimGroup*)node, arg2); | |
268 break; | |
269 case GAIM_BLIST_CHAT_NODE: | |
270 gaim_blist_alias_chat((GaimChat*)node, arg2); | |
271 break; | |
272 default: | |
273 break; | |
274 } | |
275 } | |
276 | |
5234 | 277 static void gtk_blist_menu_alias_cb(GtkWidget *w, GaimBlistNode *node) |
278 { | |
11016 | 279 GtkTreeIter iter; |
280 GtkTreePath *path; | |
11258 | 281 const char *text = NULL; |
11494 | 282 |
11258 | 283 if (!(get_iter_from_node(node, &iter))) { |
11016 | 284 /* This is either a bug, or the buddy is in a collapsed contact */ |
285 node = node->parent; | |
286 if (!get_iter_from_node(node, &iter)) | |
287 /* Now it's definitely a bug */ | |
288 return; | |
289 } | |
11258 | 290 |
291 switch (node->type) { | |
292 case GAIM_BLIST_BUDDY_NODE: | |
293 text = gaim_buddy_get_alias((GaimBuddy *)node); | |
294 break; | |
295 case GAIM_BLIST_CONTACT_NODE: | |
296 text = gaim_buddy_get_alias(gaim_contact_get_priority_buddy((GaimContact *)node)); | |
297 break; | |
298 case GAIM_BLIST_GROUP_NODE: | |
299 text = ((GaimGroup *)node)->name; | |
300 break; | |
301 case GAIM_BLIST_CHAT_NODE: | |
302 text = gaim_chat_get_name((GaimChat *)node); | |
303 break; | |
304 default: | |
305 g_return_if_reached(); | |
306 } | |
307 | |
308 gtk_tree_store_set(gtkblist->treemodel, &iter, NAME_COLUMN, text, -1); | |
309 | |
11016 | 310 path = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &iter); |
311 g_object_set(G_OBJECT(gtkblist->text_rend), "editable", TRUE, NULL); | |
312 gtk_tree_view_set_enable_search (GTK_TREE_VIEW(gtkblist->treeview), FALSE); | |
313 gtk_widget_grab_focus(gtkblist->treeview); | |
314 gtk_tree_view_set_cursor(GTK_TREE_VIEW(gtkblist->treeview), path, gtkblist->text_column, TRUE); | |
315 gtk_tree_path_free(path); | |
5228 | 316 } |
317 | |
7620 | 318 static void gtk_blist_menu_bp_cb(GtkWidget *w, GaimBuddy *b) |
5228 | 319 { |
7620 | 320 gaim_gtkpounce_dialog_show(b->account, b->name, NULL); |
5228 | 321 } |
322 | |
9917 | 323 static void gtk_blist_menu_showlog_cb(GtkWidget *w, GaimBlistNode *node) |
5228 | 324 { |
9917 | 325 GaimLogType type; |
326 GaimAccount *account; | |
327 char *name = NULL; | |
10663 | 328 |
9917 | 329 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { |
330 GaimBuddy *b = (GaimBuddy*) node; | |
331 type = GAIM_LOG_IM; | |
332 name = g_strdup(b->name); | |
333 account = b->account; | |
334 } else if (GAIM_BLIST_NODE_IS_CHAT(node)) { | |
335 GaimChat *c = (GaimChat*) node; | |
336 GaimPluginProtocolInfo *prpl_info = NULL; | |
337 type = GAIM_LOG_CHAT; | |
338 account = c->account; | |
339 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gaim_find_prpl(gaim_account_get_protocol_id(account))); | |
340 if (prpl_info && prpl_info->get_chat_name) { | |
341 name = prpl_info->get_chat_name(c->components); | |
342 } | |
10663 | 343 } else if (GAIM_BLIST_NODE_IS_CONTACT(node)) { |
344 gaim_gtk_log_show_contact((GaimContact *)node); | |
345 return; | |
9917 | 346 } else |
347 return; | |
348 | |
349 if (name && account) { | |
350 gaim_gtk_log_show(type, name, account); | |
351 g_free(name); | |
352 } | |
7620 | 353 } |
354 | |
5228 | 355 static void gtk_blist_show_systemlog_cb() |
356 { | |
8573 | 357 gaim_gtk_syslog_show(); |
5228 | 358 } |
359 | |
360 static void gtk_blist_show_onlinehelp_cb() | |
361 { | |
10240
95ca0db2d01d
[gaim-migrate @ 11377]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
10229
diff
changeset
|
362 gaim_notify_uri(NULL, GAIM_WEBSITE "documentation.php"); |
5228 | 363 } |
364 | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
365 static void |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
366 do_join_chat(GaimGtkJoinChatData *data) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
367 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
368 if (data) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
369 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
370 GHashTable *components = |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
371 g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
372 GList *tmp; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
373 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
374 for (tmp = data->entries; tmp != NULL; tmp = tmp->next) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
375 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
376 if (g_object_get_data(tmp->data, "is_spin")) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
377 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
378 g_hash_table_replace(components, |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
379 g_strdup(g_object_get_data(tmp->data, "identifier")), |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
380 g_strdup_printf("%d", |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
381 gtk_spin_button_get_value_as_int(tmp->data))); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
382 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
383 else |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
384 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
385 g_hash_table_replace(components, |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
386 g_strdup(g_object_get_data(tmp->data, "identifier")), |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
387 g_strdup(gtk_entry_get_text(tmp->data))); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
388 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
389 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
390 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
391 serv_join_chat(gaim_account_get_connection(data->account), components); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
392 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
393 g_hash_table_destroy(components); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
394 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
395 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
396 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
397 static void |
8940 | 398 do_joinchat(GtkWidget *dialog, int id, GaimGtkJoinChatData *info) |
399 { | |
400 switch(id) | |
401 { | |
402 case GTK_RESPONSE_OK: | |
403 do_join_chat(info); | |
404 | |
405 break; | |
406 } | |
407 | |
408 gtk_widget_destroy(GTK_WIDGET(dialog)); | |
409 g_list_free(info->entries); | |
410 g_free(info); | |
411 } | |
412 | |
10475 | 413 /* |
414 * Check the values of all the text entry boxes. If any required input | |
415 * strings are empty then don't allow the user to click on "OK." | |
416 */ | |
417 static void | |
418 joinchat_set_sensitive_if_input_cb(GtkWidget *entry, gpointer user_data) | |
419 { | |
420 GaimGtkJoinChatData *data; | |
421 GList *tmp; | |
422 const char *text; | |
423 gboolean required; | |
424 gboolean sensitive = TRUE; | |
425 | |
426 data = user_data; | |
427 | |
428 for (tmp = data->entries; tmp != NULL; tmp = tmp->next) | |
429 { | |
430 if (!g_object_get_data(tmp->data, "is_spin")) | |
431 { | |
432 required = GPOINTER_TO_INT(g_object_get_data(tmp->data, "required")); | |
433 text = gtk_entry_get_text(tmp->data); | |
434 if (required && (*text == '\0')) | |
435 sensitive = FALSE; | |
436 } | |
437 } | |
438 | |
439 gtk_dialog_set_response_sensitive(GTK_DIALOG(data->window), GTK_RESPONSE_OK, sensitive); | |
440 } | |
441 | |
8940 | 442 static void |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
443 rebuild_joinchat_entries(GaimGtkJoinChatData *data) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
444 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
445 GaimConnection *gc; |
9959 | 446 GList *list = NULL, *tmp = NULL; |
9770 | 447 GHashTable *defaults = NULL; |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
448 struct proto_chat_entry *pce; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
449 gboolean focus = TRUE; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
450 |
10127 | 451 g_return_if_fail(data->account != NULL); |
452 | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
453 gc = gaim_account_get_connection(data->account); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
454 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
455 while (GTK_BOX(data->entries_box)->children) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
456 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
457 gtk_container_remove(GTK_CONTAINER(data->entries_box), |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
458 ((GtkBoxChild *)GTK_BOX(data->entries_box)->children->data)->widget); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
459 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
460 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
461 if (data->entries != NULL) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
462 g_list_free(data->entries); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
463 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
464 data->entries = NULL; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
465 |
9987 | 466 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info != NULL) |
9959 | 467 list = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info(gc); |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
468 |
9770 | 469 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults != NULL) |
470 defaults = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, NULL); | |
471 | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
472 for (tmp = list; tmp; tmp = tmp->next) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
473 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
474 GtkWidget *label; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
475 GtkWidget *rowbox; |
10475 | 476 GtkWidget *input; |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
477 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
478 pce = tmp->data; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
479 |
11243 | 480 rowbox = gtk_hbox_new(FALSE, GAIM_HIG_BORDER); |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
481 gtk_box_pack_start(GTK_BOX(data->entries_box), rowbox, FALSE, FALSE, 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
482 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
483 label = gtk_label_new_with_mnemonic(pce->label); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
484 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
485 gtk_size_group_add_widget(data->sg, label); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
486 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
487 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
488 if (pce->is_int) |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
489 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
490 GtkObject *adjust; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
491 adjust = gtk_adjustment_new(pce->min, pce->min, pce->max, |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
492 1, 10, 10); |
10475 | 493 input = gtk_spin_button_new(GTK_ADJUSTMENT(adjust), 1, 0); |
494 gtk_widget_set_size_request(input, 50, -1); | |
495 gtk_box_pack_end(GTK_BOX(rowbox), input, FALSE, FALSE, 0); | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
496 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
497 else |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
498 { |
9770 | 499 char *value; |
10475 | 500 input = gtk_entry_new(); |
501 gtk_entry_set_activates_default(GTK_ENTRY(input), TRUE); | |
9770 | 502 value = g_hash_table_lookup(defaults, pce->identifier); |
503 if (value != NULL) | |
10475 | 504 gtk_entry_set_text(GTK_ENTRY(input), value); |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
505 if (pce->secret) |
10475 | 506 gtk_entry_set_visibility(GTK_ENTRY(input), FALSE); |
507 gtk_box_pack_end(GTK_BOX(rowbox), input, TRUE, TRUE, 0); | |
508 g_signal_connect(G_OBJECT(input), "changed", | |
509 G_CALLBACK(joinchat_set_sensitive_if_input_cb), data); | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
510 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
511 |
10475 | 512 /* Do the following for any type of input widget */ |
513 if (focus) | |
514 { | |
515 gtk_widget_grab_focus(input); | |
516 focus = FALSE; | |
517 } | |
518 gtk_label_set_mnemonic_widget(GTK_LABEL(label), input); | |
519 gaim_set_accessible_label(input, label); | |
520 g_object_set_data(G_OBJECT(input), "identifier", pce->identifier); | |
521 g_object_set_data(G_OBJECT(input), "is_spin", GINT_TO_POINTER(pce->is_int)); | |
522 g_object_set_data(G_OBJECT(input), "required", GINT_TO_POINTER(pce->required)); | |
523 data->entries = g_list_append(data->entries, input); | |
524 | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
525 g_free(pce); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
526 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
527 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
528 g_list_free(list); |
10475 | 529 g_hash_table_destroy(defaults); |
530 | |
531 /* Set whether the "OK" button should be clickable initially */ | |
532 joinchat_set_sensitive_if_input_cb(NULL, data); | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
533 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
534 gtk_widget_show_all(data->entries_box); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
535 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
536 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
537 static void |
8940 | 538 joinchat_select_account_cb(GObject *w, GaimAccount *account, |
10475 | 539 GaimGtkJoinChatData *data) |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
540 { |
9460 | 541 if (strcmp(gaim_account_get_protocol_id(data->account), |
10475 | 542 gaim_account_get_protocol_id(account)) == 0) |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
543 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
544 data->account = account; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
545 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
546 else |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
547 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
548 data->account = account; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
549 rebuild_joinchat_entries(data); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
550 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
551 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
552 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
553 static gboolean |
9987 | 554 chat_account_filter_func(GaimAccount *account) |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
555 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
556 GaimConnection *gc = gaim_account_get_connection(account); |
8940 | 557 GaimPluginProtocolInfo *prpl_info = NULL; |
558 | |
559 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
560 | |
561 return (prpl_info->chat_info != NULL); | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
562 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
563 |
8940 | 564 gboolean |
565 gaim_gtk_blist_joinchat_is_showable() | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
566 { |
8940 | 567 GList *c; |
568 GaimConnection *gc; | |
569 | |
570 for (c = gaim_connections_get_all(); c != NULL; c = c->next) { | |
571 gc = c->data; | |
572 | |
9987 | 573 if (chat_account_filter_func(gaim_connection_get_account(gc))) |
8940 | 574 return TRUE; |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
575 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
576 |
8940 | 577 return FALSE; |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
578 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
579 |
8305
57bdd25752c1
[gaim-migrate @ 9029]
Christian Hammond <chipx86@chipx86.com>
parents:
8303
diff
changeset
|
580 void |
8940 | 581 gaim_gtk_blist_joinchat_show(void) |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
582 { |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
583 GtkWidget *hbox, *vbox; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
584 GtkWidget *rowbox; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
585 GtkWidget *label; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
586 GaimGtkBuddyList *gtkblist; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
587 GtkWidget *img = NULL; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
588 GaimGtkJoinChatData *data = NULL; |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
589 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
590 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
591 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
592 GTK_ICON_SIZE_DIALOG); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
593 data = g_new0(GaimGtkJoinChatData, 1); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
594 |
8975 | 595 data->window = gtk_dialog_new_with_buttons(_("Join a Chat"), |
596 NULL, GTK_DIALOG_NO_SEPARATOR, | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
597 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
8308 | 598 GAIM_STOCK_CHAT, GTK_RESPONSE_OK, NULL); |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
599 gtk_dialog_set_default_response(GTK_DIALOG(data->window), GTK_RESPONSE_OK); |
11243 | 600 gtk_container_set_border_width(GTK_CONTAINER(data->window), GAIM_HIG_BOX_SPACE); |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
601 gtk_window_set_resizable(GTK_WINDOW(data->window), FALSE); |
11243 | 602 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(data->window)->vbox), GAIM_HIG_BORDER); |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
603 gtk_container_set_border_width( |
11243 | 604 GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), GAIM_HIG_BOX_SPACE); |
8975 | 605 gtk_window_set_role(GTK_WINDOW(data->window), "join_chat"); |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
606 |
11243 | 607 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BORDER); |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
608 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), hbox); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
609 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
610 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
611 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
612 vbox = gtk_vbox_new(FALSE, 5); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
613 gtk_container_set_border_width(GTK_CONTAINER(vbox), 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
614 gtk_container_add(GTK_CONTAINER(hbox), vbox); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
615 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
616 label = gtk_label_new(_("Please enter the appropriate information " |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
617 "about the chat you would like to join.\n")); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
618 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
619 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
620 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
621 |
11243 | 622 rowbox = gtk_hbox_new(FALSE, GAIM_HIG_BORDER); |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
623 gtk_box_pack_start(GTK_BOX(vbox), rowbox, TRUE, TRUE, 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
624 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
625 data->sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
626 |
8940 | 627 label = gtk_label_new_with_mnemonic(_("_Account:")); |
628 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
629 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); | |
630 gtk_size_group_add_widget(data->sg, label); | |
631 | |
632 data->account_menu = gaim_gtk_account_option_menu_new(NULL, FALSE, | |
633 G_CALLBACK(joinchat_select_account_cb), | |
9987 | 634 chat_account_filter_func, data); |
8940 | 635 gtk_box_pack_start(GTK_BOX(rowbox), data->account_menu, TRUE, TRUE, 0); |
636 gtk_label_set_mnemonic_widget(GTK_LABEL(label), | |
637 GTK_WIDGET(data->account_menu)); | |
638 gaim_set_accessible_label (data->account_menu, label); | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
639 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
640 data->entries_box = gtk_vbox_new(FALSE, 5); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
641 gtk_container_add(GTK_CONTAINER(vbox), data->entries_box); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
642 gtk_container_set_border_width(GTK_CONTAINER(data->entries_box), 0); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
643 |
8940 | 644 data->account = gaim_gtk_account_option_menu_get_selected(data->account_menu); |
645 | |
8303
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
646 rebuild_joinchat_entries(data); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
647 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
648 g_signal_connect(G_OBJECT(data->window), "response", |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
649 G_CALLBACK(do_joinchat), data); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
650 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
651 g_object_unref(data->sg); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
652 |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
653 gtk_widget_show_all(data->window); |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
654 } |
4eb4b2a6c604
[gaim-migrate @ 9027]
Christian Hammond <chipx86@chipx86.com>
parents:
8302
diff
changeset
|
655 |
5228 | 656 static void gtk_blist_row_expanded_cb(GtkTreeView *tv, GtkTreeIter *iter, GtkTreePath *path, gpointer user_data) { |
657 GaimBlistNode *node; | |
658 GValue val = {0,}; | |
659 | |
660 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), iter, NODE_COLUMN, &val); | |
661 | |
662 node = g_value_get_pointer(&val); | |
663 | |
664 if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
7693 | 665 gaim_blist_node_set_bool(node, "collapsed", FALSE); |
5228 | 666 } |
667 } | |
668 | |
669 static void gtk_blist_row_collapsed_cb(GtkTreeView *tv, GtkTreeIter *iter, GtkTreePath *path, gpointer user_data) { | |
670 GaimBlistNode *node; | |
671 GValue val = {0,}; | |
672 | |
673 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), iter, NODE_COLUMN, &val); | |
674 | |
675 node = g_value_get_pointer(&val); | |
676 | |
677 if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
7693 | 678 gaim_blist_node_set_bool(node, "collapsed", TRUE); |
7620 | 679 } else if(GAIM_BLIST_NODE_IS_CONTACT(node)) { |
680 gaim_gtk_blist_collapse_contact_cb(NULL, node); | |
5228 | 681 } |
682 } | |
683 | |
684 static void gtk_blist_row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) { | |
685 GaimBlistNode *node; | |
686 GtkTreeIter iter; | |
687 GValue val = { 0, }; | |
688 | |
689 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
690 | |
691 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
692 node = g_value_get_pointer(&val); | |
693 | |
7620 | 694 if(GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_BUDDY(node)) { |
695 GaimBuddy *buddy; | |
696 | |
697 if(GAIM_BLIST_NODE_IS_CONTACT(node)) | |
698 buddy = gaim_contact_get_priority_buddy((GaimContact*)node); | |
699 else | |
700 buddy = (GaimBuddy*)node; | |
701 | |
9728 | 702 gaim_gtkdialogs_im_with_user(buddy->account, buddy->name); |
5234 | 703 } else if (GAIM_BLIST_NODE_IS_CHAT(node)) { |
7620 | 704 serv_join_chat(((GaimChat *)node)->account->gc, ((GaimChat *)node)->components); |
5228 | 705 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { |
706 if (gtk_tree_view_row_expanded(tv, path)) | |
707 gtk_tree_view_collapse_row(tv, path); | |
708 else | |
709 gtk_tree_view_expand_row(tv,path,FALSE); | |
710 } | |
711 } | |
712 | |
5234 | 713 static void gaim_gtk_blist_add_chat_cb() |
714 { | |
715 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)); | |
716 GtkTreeIter iter; | |
717 GaimBlistNode *node; | |
718 | |
719 if(gtk_tree_selection_get_selected(sel, NULL, &iter)){ | |
720 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
7620 | 721 if (GAIM_BLIST_NODE_IS_BUDDY(node)) |
9754 | 722 gaim_blist_request_add_chat(NULL, (GaimGroup*)node->parent->parent, NULL, NULL); |
7620 | 723 if (GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_CHAT(node)) |
9754 | 724 gaim_blist_request_add_chat(NULL, (GaimGroup*)node->parent, NULL, NULL); |
5234 | 725 else if (GAIM_BLIST_NODE_IS_GROUP(node)) |
9754 | 726 gaim_blist_request_add_chat(NULL, (GaimGroup*)node, NULL, NULL); |
5234 | 727 } |
728 else { | |
9754 | 729 gaim_blist_request_add_chat(NULL, NULL, NULL, NULL); |
5234 | 730 } |
731 } | |
732 | |
5228 | 733 static void gaim_gtk_blist_add_buddy_cb() |
734 { | |
735 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)); | |
736 GtkTreeIter iter; | |
737 GaimBlistNode *node; | |
738 | |
739 if(gtk_tree_selection_get_selected(sel, NULL, &iter)){ | |
740 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &node, -1); | |
7620 | 741 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { |
742 gaim_blist_request_add_buddy(NULL, NULL, ((GaimGroup*)node->parent->parent)->name, | |
743 NULL); | |
744 } else if (GAIM_BLIST_NODE_IS_CONTACT(node) | |
745 || GAIM_BLIST_NODE_IS_CHAT(node)) { | |
746 gaim_blist_request_add_buddy(NULL, NULL, ((GaimGroup*)node->parent)->name, NULL); | |
747 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
748 gaim_blist_request_add_buddy(NULL, NULL, ((GaimGroup*)node)->name, NULL); | |
749 } | |
5228 | 750 } |
751 else { | |
7620 | 752 gaim_blist_request_add_buddy(NULL, NULL, NULL, NULL); |
753 } | |
754 } | |
755 | |
756 static void | |
757 gaim_gtk_blist_remove_cb (GtkWidget *w, GaimBlistNode *node) | |
758 { | |
759 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
9730 | 760 gaim_gtkdialogs_remove_buddy((GaimBuddy*)node); |
7620 | 761 } else if (GAIM_BLIST_NODE_IS_CHAT(node)) { |
9730 | 762 gaim_gtkdialogs_remove_chat((GaimChat*)node); |
7620 | 763 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { |
9730 | 764 gaim_gtkdialogs_remove_group((GaimGroup*)node); |
7620 | 765 } else if (GAIM_BLIST_NODE_IS_CONTACT(node)) { |
9730 | 766 gaim_gtkdialogs_remove_contact((GaimContact*)node); |
5228 | 767 } |
768 } | |
769 | |
770 static void | |
7620 | 771 gaim_gtk_blist_expand_contact_cb(GtkWidget *w, GaimBlistNode *node) |
5228 | 772 { |
7620 | 773 struct _gaim_gtk_blist_node *gtknode; |
9632 | 774 GtkTreeIter iter, parent; |
7620 | 775 GaimBlistNode *bnode; |
10325 | 776 GtkTreePath *path; |
7620 | 777 |
778 if(!GAIM_BLIST_NODE_IS_CONTACT(node)) | |
779 return; | |
780 | |
781 gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; | |
782 | |
783 gtknode->contact_expanded = TRUE; | |
784 | |
785 for(bnode = node->child; bnode; bnode = bnode->next) { | |
786 gaim_gtk_blist_update(NULL, bnode); | |
787 } | |
10353 | 788 |
9632 | 789 /* This ensures that the bottom buddy is visible, i.e. not scrolled off the alignment */ |
790 get_iter_from_node(node, &parent); | |
10353 | 791 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(gtkblist->treemodel), &iter, &parent, |
9811 | 792 gtk_tree_model_iter_n_children(GTK_TREE_MODEL(gtkblist->treemodel), &parent) -1); |
9632 | 793 path = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &iter); |
794 /* Let the treeview draw so it knows where to scroll */ | |
795 while (gtk_events_pending()) | |
796 gtk_main_iteration(); | |
10353 | 797 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW(gtkblist->treeview), path, NULL, FALSE, 0, 0); |
798 | |
9632 | 799 |
7620 | 800 gaim_gtk_blist_update(NULL, node); |
9632 | 801 gtk_tree_path_free(path); |
7620 | 802 } |
803 | |
804 static void | |
805 gaim_gtk_blist_collapse_contact_cb(GtkWidget *w, GaimBlistNode *node) | |
806 { | |
807 GaimBlistNode *bnode; | |
808 struct _gaim_gtk_blist_node *gtknode; | |
809 | |
810 if(!GAIM_BLIST_NODE_IS_CONTACT(node)) | |
811 return; | |
812 | |
813 gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; | |
814 | |
815 gtknode->contact_expanded = FALSE; | |
816 | |
817 for(bnode = node->child; bnode; bnode = bnode->next) { | |
818 gaim_gtk_blist_update(NULL, bnode); | |
5228 | 819 } |
820 } | |
821 | |
9030 | 822 |
823 static void | |
824 blist_node_menu_cb(GtkMenuItem *item, GaimBlistNode *node) | |
825 { | |
11638 | 826 void (*callback)(GaimBlistNode *, gpointer); |
827 gpointer data; | |
828 callback = g_object_get_data(G_OBJECT(item), "gaimcallback"); | |
829 data = g_object_get_data(G_OBJECT(item), "gaimcallbackdata"); | |
830 if (callback) | |
831 callback(node, data); | |
9030 | 832 } |
833 | |
834 | |
835 static void | |
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
836 append_blist_node_action(GtkWidget *menu, GaimBlistNodeAction *act, |
9030 | 837 GaimBlistNode *node, gboolean *dup_separator) |
5228 | 838 { |
9030 | 839 if(act == NULL) { |
840 if(! *dup_separator) { | |
841 gaim_separator(menu); | |
842 *dup_separator = TRUE; | |
843 } | |
844 } else { | |
845 GtkWidget *menuitem; | |
846 | |
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
847 if (act->children == NULL) { |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
848 *dup_separator = FALSE; |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
849 |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
850 menuitem = gtk_menu_item_new_with_mnemonic(act->label); |
11038
aedd557f46dd
[gaim-migrate @ 12935]
Richard Laager <rlaager@wiktel.com>
parents:
11033
diff
changeset
|
851 if (act->callback != NULL) { |
aedd557f46dd
[gaim-migrate @ 12935]
Richard Laager <rlaager@wiktel.com>
parents:
11033
diff
changeset
|
852 g_object_set_data(G_OBJECT(menuitem), "gaimcallback", |
11638 | 853 act->callback); |
854 g_object_set_data(G_OBJECT(menuitem), "gaimcallbackdata", | |
855 act->data); | |
11038
aedd557f46dd
[gaim-migrate @ 12935]
Richard Laager <rlaager@wiktel.com>
parents:
11033
diff
changeset
|
856 g_signal_connect(G_OBJECT(menuitem), "activate", |
aedd557f46dd
[gaim-migrate @ 12935]
Richard Laager <rlaager@wiktel.com>
parents:
11033
diff
changeset
|
857 G_CALLBACK(blist_node_menu_cb), node); |
aedd557f46dd
[gaim-migrate @ 12935]
Richard Laager <rlaager@wiktel.com>
parents:
11033
diff
changeset
|
858 } else { |
aedd557f46dd
[gaim-migrate @ 12935]
Richard Laager <rlaager@wiktel.com>
parents:
11033
diff
changeset
|
859 gtk_widget_set_sensitive(menuitem, FALSE); |
aedd557f46dd
[gaim-migrate @ 12935]
Richard Laager <rlaager@wiktel.com>
parents:
11033
diff
changeset
|
860 } |
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
861 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
862 } else { |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
863 GtkWidget *submenu = NULL; |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
864 GList *l = NULL; |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
865 |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
866 menuitem = gtk_menu_item_new_with_mnemonic(act->label); |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
867 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
868 |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
869 submenu = gtk_menu_new(); |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
870 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
871 |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
872 for (l = act->children; l; l = l->next) { |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
873 GaimBlistNodeAction *act = (GaimBlistNodeAction *) l->data; |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
874 |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
875 append_blist_node_action(submenu, act, node, dup_separator); |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
876 } |
11638 | 877 g_list_free(act->children); |
878 act->children = NULL; | |
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
879 } |
11638 | 880 g_free(act); |
9030 | 881 } |
5228 | 882 } |
883 | |
9030 | 884 |
9051 | 885 void |
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
886 gaim_gtk_append_blist_node_proto_menu(GtkWidget *menu, GaimConnection *gc, |
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10643
diff
changeset
|
887 GaimBlistNode *node) |
9030 | 888 { |
889 GList *l, *ll; | |
890 gboolean dup_separator = FALSE; | |
891 GaimPluginProtocolInfo *prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
892 | |
893 if(!prpl_info || !prpl_info->blist_node_menu) | |
894 return; | |
895 | |
896 for(l = ll = prpl_info->blist_node_menu(node); l; l = l->next) { | |
897 GaimBlistNodeAction *act = (GaimBlistNodeAction *) l->data; | |
898 append_blist_node_action(menu, act, node, &dup_separator); | |
899 } | |
900 g_list_free(ll); | |
901 } | |
902 | |
903 | |
9051 | 904 void |
905 gaim_gtk_append_blist_node_extended_menu (GtkWidget *menu, GaimBlistNode *node) | |
9030 | 906 { |
907 GList *l, *ll; | |
908 gboolean dup_separator = FALSE; | |
909 | |
910 for(l = ll = gaim_blist_node_get_extended_menu(node); l; l = l->next) { | |
911 GaimBlistNodeAction *act = (GaimBlistNodeAction *) l->data; | |
912 append_blist_node_action(menu, act, node, &dup_separator); | |
913 } | |
914 g_list_free(ll); | |
915 } | |
916 | |
917 | |
9774 | 918 void |
10484 | 919 gaim_gtk_blist_make_buddy_menu(GtkWidget *menu, GaimBuddy *buddy, gboolean sub) { |
9774 | 920 GaimPluginProtocolInfo *prpl_info; |
10663 | 921 GaimContact *contact; |
922 gboolean contact_expanded = FALSE; | |
9774 | 923 |
924 g_return_if_fail(menu); | |
925 g_return_if_fail(buddy); | |
926 | |
927 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(buddy->account->gc->prpl); | |
928 | |
10663 | 929 contact = gaim_buddy_get_contact(buddy); |
930 if (contact) { | |
931 contact_expanded = ((struct _gaim_gtk_blist_node *)(((GaimBlistNode*)contact)->ui_data))->contact_expanded; | |
932 } | |
933 | |
7620 | 934 if (prpl_info && prpl_info->get_info) { |
8137 | 935 gaim_new_item_from_stock(menu, _("Get _Info"), GAIM_STOCK_INFO, |
9774 | 936 G_CALLBACK(gtk_blist_menu_info_cb), buddy, 0, 0, NULL); |
7620 | 937 } |
8137 | 938 gaim_new_item_from_stock(menu, _("I_M"), GAIM_STOCK_IM, |
9774 | 939 G_CALLBACK(gtk_blist_menu_im_cb), buddy, 0, 0, NULL); |
9466 | 940 if (prpl_info && prpl_info->send_file) { |
9774 | 941 if (!prpl_info->can_receive_file || |
942 prpl_info->can_receive_file(buddy->account->gc, buddy->name)) | |
943 { | |
944 gaim_new_item_from_stock(menu, _("_Send File"), | |
945 GAIM_STOCK_FILE_TRANSFER, | |
946 G_CALLBACK(gtk_blist_menu_send_file_cb), | |
947 buddy, 0, 0, NULL); | |
9466 | 948 } |
949 } | |
7620 | 950 gaim_new_item_from_stock(menu, _("Add Buddy _Pounce"), NULL, |
9774 | 951 G_CALLBACK(gtk_blist_menu_bp_cb), buddy, 0, 0, NULL); |
10663 | 952 |
953 if(((GaimBlistNode*)buddy)->parent->child->next && !sub && !contact_expanded) { | |
954 gaim_new_item_from_stock(menu, _("View _Log"), NULL, | |
955 G_CALLBACK(gtk_blist_menu_showlog_cb), | |
956 contact, 0, 0, NULL); | |
957 } else if (!sub) { | |
958 gaim_new_item_from_stock(menu, _("View _Log"), NULL, | |
959 G_CALLBACK(gtk_blist_menu_showlog_cb), buddy, 0, 0, NULL); | |
960 } | |
9774 | 961 |
962 gaim_gtk_append_blist_node_proto_menu(menu, buddy->account->gc, | |
963 (GaimBlistNode *)buddy); | |
964 gaim_gtk_append_blist_node_extended_menu(menu, (GaimBlistNode *)buddy); | |
7620 | 965 |
966 gaim_separator(menu); | |
9030 | 967 |
10663 | 968 if(((GaimBlistNode*)buddy)->parent->child->next && !sub && !contact_expanded) { |
9925 | 969 gaim_new_item_from_stock(menu, _("_Alias Buddy..."), GAIM_STOCK_ALIAS, |
970 G_CALLBACK(gtk_blist_menu_alias_cb), buddy, 0, 0, NULL); | |
971 gaim_new_item_from_stock(menu, _("_Remove Buddy"), GTK_STOCK_REMOVE, | |
972 G_CALLBACK(gaim_gtk_blist_remove_cb), buddy, 0, 0, NULL); | |
973 gaim_new_item_from_stock(menu, _("Alias Contact..."), GAIM_STOCK_ALIAS, | |
974 G_CALLBACK(gtk_blist_menu_alias_cb), | |
10663 | 975 contact, 0, 0, NULL); |
9925 | 976 gaim_new_item_from_stock(menu, _("Remove Contact"), GTK_STOCK_REMOVE, |
977 G_CALLBACK(gaim_gtk_blist_remove_cb), | |
10663 | 978 contact, 0, 0, NULL); |
9925 | 979 } else { |
980 gaim_new_item_from_stock(menu, _("_Alias..."), GAIM_STOCK_ALIAS, | |
981 G_CALLBACK(gtk_blist_menu_alias_cb), buddy, 0, 0, NULL); | |
982 gaim_new_item_from_stock(menu, _("_Remove"), GTK_STOCK_REMOVE, | |
983 G_CALLBACK(gaim_gtk_blist_remove_cb), buddy, | |
984 0, 0, NULL); | |
985 } | |
7620 | 986 } |
987 | |
9774 | 988 static gboolean |
989 gtk_blist_key_press_cb(GtkWidget *tv, GdkEventKey *event, gpointer data) { | |
7620 | 990 GaimBlistNode *node; |
991 GValue val = { 0, }; | |
992 GtkTreeIter iter; | |
993 GtkTreeSelection *sel; | |
994 | |
995 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv)); | |
996 if(!gtk_tree_selection_get_selected(sel, NULL, &iter)) | |
997 return FALSE; | |
998 | |
999 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), &iter, | |
1000 NODE_COLUMN, &val); | |
1001 node = g_value_get_pointer(&val); | |
1002 | |
1003 if(event->state & GDK_CONTROL_MASK && | |
1004 (event->keyval == 'o' || event->keyval == 'O')) { | |
1005 GaimBuddy *buddy; | |
1006 | |
1007 if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
1008 buddy = gaim_contact_get_priority_buddy((GaimContact*)node); | |
1009 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
1010 buddy = (GaimBuddy*)node; | |
1011 } else { | |
1012 return FALSE; | |
1013 } | |
1014 if(buddy) | |
1015 serv_get_info(buddy->account->gc, buddy->name); | |
1016 } | |
1017 | |
1018 return FALSE; | |
1019 } | |
1020 | |
9013 | 1021 |
8143 | 1022 static GtkWidget * |
8952 | 1023 create_group_menu (GaimBlistNode *node, GaimGroup *g) |
8143 | 1024 { |
1025 GtkWidget *menu; | |
1026 | |
1027 menu = gtk_menu_new(); | |
1028 gaim_new_item_from_stock(menu, _("Add a _Buddy"), GTK_STOCK_ADD, | |
1029 G_CALLBACK(gaim_gtk_blist_add_buddy_cb), node, 0, 0, NULL); | |
1030 gaim_new_item_from_stock(menu, _("Add a C_hat"), GTK_STOCK_ADD, | |
1031 G_CALLBACK(gaim_gtk_blist_add_chat_cb), node, 0, 0, NULL); | |
1032 gaim_new_item_from_stock(menu, _("_Delete Group"), GTK_STOCK_REMOVE, | |
1033 G_CALLBACK(gaim_gtk_blist_remove_cb), node, 0, 0, NULL); | |
1034 gaim_new_item_from_stock(menu, _("_Rename"), NULL, | |
11016 | 1035 G_CALLBACK(gtk_blist_menu_alias_cb), node, 0, 0, NULL); |
8952 | 1036 |
9051 | 1037 gaim_gtk_append_blist_node_extended_menu(menu, node); |
8952 | 1038 |
8143 | 1039 return menu; |
1040 } | |
1041 | |
8586 | 1042 |
8143 | 1043 static GtkWidget * |
9774 | 1044 create_chat_menu(GaimBlistNode *node, GaimChat *c) { |
8143 | 1045 GtkWidget *menu; |
9030 | 1046 gboolean autojoin; |
8143 | 1047 |
1048 menu = gtk_menu_new(); | |
9030 | 1049 autojoin = (gaim_blist_node_get_bool(node, "gtk-autojoin") || |
1050 (gaim_blist_node_get_string(node, "gtk-autojoin") != NULL)); | |
1051 | |
8143 | 1052 gaim_new_item_from_stock(menu, _("_Join"), GAIM_STOCK_CHAT, |
9030 | 1053 G_CALLBACK(gtk_blist_menu_join_cb), node, 0, 0, NULL); |
8143 | 1054 gaim_new_check_item(menu, _("Auto-Join"), |
9030 | 1055 G_CALLBACK(gtk_blist_menu_autojoin_cb), node, autojoin); |
9917 | 1056 gaim_new_item_from_stock(menu, _("View _Log"), NULL, |
1057 G_CALLBACK(gtk_blist_menu_showlog_cb), node, 0, 0, NULL); | |
9030 | 1058 |
9051 | 1059 gaim_gtk_append_blist_node_proto_menu(menu, c->account->gc, node); |
1060 gaim_gtk_append_blist_node_extended_menu(menu, node); | |
8586 | 1061 |
1062 gaim_separator(menu); | |
9030 | 1063 |
8302
462ead6fc1a0
[gaim-migrate @ 9026]
Christian Hammond <chipx86@chipx86.com>
parents:
8259
diff
changeset
|
1064 gaim_new_item_from_stock(menu, _("_Alias..."), GAIM_STOCK_ALIAS, |
8143 | 1065 G_CALLBACK(gtk_blist_menu_alias_cb), node, 0, 0, NULL); |
1066 gaim_new_item_from_stock(menu, _("_Remove"), GTK_STOCK_REMOVE, | |
1067 G_CALLBACK(gaim_gtk_blist_remove_cb), node, 0, 0, NULL); | |
8586 | 1068 |
8143 | 1069 return menu; |
1070 } | |
1071 | |
1072 static GtkWidget * | |
1073 create_contact_menu (GaimBlistNode *node) | |
1074 { | |
1075 GtkWidget *menu; | |
1076 | |
1077 menu = gtk_menu_new(); | |
10663 | 1078 |
1079 gaim_new_item_from_stock(menu, _("View _Log"), NULL, | |
1080 G_CALLBACK(gtk_blist_menu_showlog_cb), | |
1081 node, 0, 0, NULL); | |
1082 | |
1083 gaim_separator(menu); | |
1084 | |
8302
462ead6fc1a0
[gaim-migrate @ 9026]
Christian Hammond <chipx86@chipx86.com>
parents:
8259
diff
changeset
|
1085 gaim_new_item_from_stock(menu, _("_Alias..."), GAIM_STOCK_ALIAS, |
8143 | 1086 G_CALLBACK(gtk_blist_menu_alias_cb), node, 0, 0, NULL); |
10663 | 1087 gaim_new_item_from_stock(menu, _("_Remove"), GTK_STOCK_REMOVE, |
1088 G_CALLBACK(gaim_gtk_blist_remove_cb), node, 0, 0, NULL); | |
1089 | |
1090 gaim_separator(menu); | |
1091 | |
8143 | 1092 gaim_new_item_from_stock(menu, _("_Collapse"), GTK_STOCK_ZOOM_OUT, |
1093 G_CALLBACK(gaim_gtk_blist_collapse_contact_cb), | |
1094 node, 0, 0, NULL); | |
9051 | 1095 |
1096 gaim_gtk_append_blist_node_extended_menu(menu, node); | |
1097 | |
8143 | 1098 return menu; |
1099 } | |
1100 | |
1101 static GtkWidget * | |
9774 | 1102 create_buddy_menu(GaimBlistNode *node, GaimBuddy *b) { |
8143 | 1103 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; |
1104 GtkWidget *menu; | |
1105 GtkWidget *menuitem; | |
1106 gboolean show_offline = gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies"); | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
1107 |
8143 | 1108 menu = gtk_menu_new(); |
10484 | 1109 gaim_gtk_blist_make_buddy_menu(menu, b, FALSE); |
8143 | 1110 |
1111 if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
1112 gaim_separator(menu); | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
1113 |
8143 | 1114 if(gtknode->contact_expanded) { |
1115 gaim_new_item_from_stock(menu, _("_Collapse"), | |
1116 GTK_STOCK_ZOOM_OUT, | |
1117 G_CALLBACK(gaim_gtk_blist_collapse_contact_cb), | |
1118 node, 0, 0, NULL); | |
1119 } else { | |
1120 gaim_new_item_from_stock(menu, _("_Expand"), | |
1121 GTK_STOCK_ZOOM_IN, | |
1122 G_CALLBACK(gaim_gtk_blist_expand_contact_cb), node, | |
1123 0, 0, NULL); | |
1124 } | |
1125 if(node->child->next) { | |
1126 GaimBlistNode *bnode; | |
1127 | |
1128 for(bnode = node->child; bnode; bnode = bnode->next) { | |
1129 GaimBuddy *buddy = (GaimBuddy*)bnode; | |
9340 | 1130 GdkPixbuf *buf; |
8143 | 1131 GtkWidget *submenu; |
1132 GtkWidget *image; | |
1133 | |
1134 if(buddy == b) | |
1135 continue; | |
1136 if(!buddy->account->gc) | |
1137 continue; | |
1138 if(!show_offline && !GAIM_BUDDY_IS_ONLINE(buddy)) | |
1139 continue; | |
1140 | |
1141 menuitem = gtk_image_menu_item_new_with_label(buddy->name); | |
9340 | 1142 buf = gaim_gtk_blist_get_status_icon(bnode, |
1143 GAIM_STATUS_ICON_SMALL); | |
1144 image = gtk_image_new_from_pixbuf(buf); | |
1145 g_object_unref(G_OBJECT(buf)); | |
8143 | 1146 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), |
9811 | 1147 image); |
8143 | 1148 gtk_widget_show(image); |
1149 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
1150 gtk_widget_show(menuitem); | |
1151 | |
1152 submenu = gtk_menu_new(); | |
1153 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); | |
1154 gtk_widget_show(submenu); | |
1155 | |
10484 | 1156 gaim_gtk_blist_make_buddy_menu(submenu, buddy, TRUE); |
8143 | 1157 } |
1158 } | |
1159 } | |
1160 return menu; | |
1161 } | |
1162 | |
1163 static gboolean | |
1164 gaim_gtk_blist_show_context_menu(GaimBlistNode *node, | |
1165 GtkMenuPositionFunc func, | |
1166 GtkWidget *tv, | |
1167 guint button, | |
1168 guint32 time) | |
1169 { | |
1170 struct _gaim_gtk_blist_node *gtknode; | |
1171 GtkWidget *menu = NULL; | |
1172 gboolean handled = FALSE; | |
1173 | |
1174 gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; | |
1175 | |
1176 /* Create a menu based on the thing we right-clicked on */ | |
1177 if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
8952 | 1178 GaimGroup *g = (GaimGroup *)node; |
9774 | 1179 |
8952 | 1180 menu = create_group_menu(node, g); |
8143 | 1181 } else if (GAIM_BLIST_NODE_IS_CHAT(node)) { |
8586 | 1182 GaimChat *c = (GaimChat *)node; |
9774 | 1183 |
1184 menu = create_chat_menu(node, c); | |
8143 | 1185 } else if ((GAIM_BLIST_NODE_IS_CONTACT(node)) && (gtknode->contact_expanded)) { |
1186 menu = create_contact_menu(node); | |
1187 } else if (GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
1188 GaimBuddy *b; | |
1189 | |
1190 if (GAIM_BLIST_NODE_IS_CONTACT(node)) | |
1191 b = gaim_contact_get_priority_buddy((GaimContact*)node); | |
1192 else | |
1193 b = (GaimBuddy *)node; | |
1194 | |
9774 | 1195 menu = create_buddy_menu(node, b); |
8143 | 1196 } |
1197 | |
11059
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1198 #ifdef _WIN32 |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1199 /* Unhook the tooltip-timeout since we don't want a tooltip |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1200 * to appear and obscure the context menu we are about to show |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1201 This is a workaround for GTK+ bug 107320. */ |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1202 if (gtkblist->timeout) { |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1203 g_source_remove(gtkblist->timeout); |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1204 gtkblist->timeout = 0; |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1205 } |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1206 #endif |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1207 |
8143 | 1208 /* Now display the menu */ |
1209 if (menu != NULL) { | |
1210 gtk_widget_show_all(menu); | |
1211 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, func, tv, button, time); | |
1212 handled = TRUE; | |
1213 } | |
1214 | |
1215 return handled; | |
1216 } | |
1217 | |
1218 static gboolean gtk_blist_button_press_cb(GtkWidget *tv, GdkEventButton *event, gpointer user_data) | |
5228 | 1219 { |
1220 GtkTreePath *path; | |
1221 GaimBlistNode *node; | |
1222 GValue val = { 0, }; | |
1223 GtkTreeIter iter; | |
1224 GtkTreeSelection *sel; | |
1225 GaimPlugin *prpl = NULL; | |
1226 GaimPluginProtocolInfo *prpl_info = NULL; | |
7620 | 1227 struct _gaim_gtk_blist_node *gtknode; |
1228 gboolean handled = FALSE; | |
5228 | 1229 |
1230 /* Here we figure out which node was clicked */ | |
1231 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL)) | |
1232 return FALSE; | |
1233 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
8143 | 1234 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); |
5228 | 1235 node = g_value_get_pointer(&val); |
7620 | 1236 gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; |
1237 | |
8143 | 1238 /* Right click draws a context menu */ |
1239 if ((event->button == 3) && (event->type == GDK_BUTTON_PRESS)) { | |
1240 handled = gaim_gtk_blist_show_context_menu(node, NULL, tv, 3, event->time); | |
1241 | |
1242 /* CTRL+middle click expands or collapse a contact */ | |
1243 } else if ((event->button == 2) && (event->type == GDK_BUTTON_PRESS) && | |
1244 (event->state & GDK_CONTROL_MASK) && (GAIM_BLIST_NODE_IS_CONTACT(node))) { | |
1245 if (gtknode->contact_expanded) | |
7620 | 1246 gaim_gtk_blist_collapse_contact_cb(NULL, node); |
1247 else | |
1248 gaim_gtk_blist_expand_contact_cb(NULL, node); | |
1249 handled = TRUE; | |
8143 | 1250 |
1251 /* Double middle click gets info */ | |
1252 } else if ((event->button == 2) && (event->type == GDK_2BUTTON_PRESS) && | |
1253 ((GAIM_BLIST_NODE_IS_CONTACT(node)) || (GAIM_BLIST_NODE_IS_BUDDY(node)))) { | |
7620 | 1254 GaimBuddy *b; |
1255 if(GAIM_BLIST_NODE_IS_CONTACT(node)) | |
1256 b = gaim_contact_get_priority_buddy((GaimContact*)node); | |
1257 else | |
1258 b = (GaimBuddy *)node; | |
1259 | |
7956 | 1260 prpl = gaim_find_prpl(gaim_account_get_protocol_id(b->account)); |
5228 | 1261 if (prpl != NULL) |
1262 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
1263 | |
8143 | 1264 if (prpl && prpl_info->get_info) |
1265 serv_get_info(b->account->gc, b->name); | |
1266 handled = TRUE; | |
5228 | 1267 } |
1268 | |
8143 | 1269 #if (1) |
1270 /* | |
10814
364a2ef907ae
[gaim-migrate @ 12468]
Luke Schierer <lschiere@pidgin.im>
parents:
10780
diff
changeset
|
1271 * This code only exists because GTK+ doesn't work. If we return |
8143 | 1272 * FALSE here, as would be normal the event propoagates down and |
1273 * somehow gets interpreted as the start of a drag event. | |
1274 * | |
1275 * Um, isn't it _normal_ to return TRUE here? Since the event | |
1276 * was handled? --Mark | |
1277 */ | |
7620 | 1278 if(handled) { |
1279 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv)); | |
1280 gtk_tree_selection_select_path(sel, path); | |
1281 gtk_tree_path_free(path); | |
1282 return TRUE; | |
1283 } | |
5228 | 1284 #endif |
7753 | 1285 gtk_tree_path_free(path); |
8143 | 1286 |
7620 | 1287 return FALSE; |
5228 | 1288 } |
1289 | |
8143 | 1290 static gboolean |
1291 gaim_gtk_blist_popup_menu_cb(GtkWidget *tv, void *user_data) | |
1292 { | |
1293 GaimBlistNode *node; | |
1294 GValue val = { 0, }; | |
1295 GtkTreeIter iter; | |
1296 GtkTreeSelection *sel; | |
1297 gboolean handled = FALSE; | |
1298 | |
1299 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv)); | |
1300 if (!gtk_tree_selection_get_selected(sel, NULL, &iter)) | |
1301 return FALSE; | |
1302 | |
1303 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), | |
1304 &iter, NODE_COLUMN, &val); | |
1305 node = g_value_get_pointer(&val); | |
1306 | |
1307 /* Shift+F10 draws a context menu */ | |
1308 handled = gaim_gtk_blist_show_context_menu(node, gaim_gtk_treeview_popup_menu_position_func, tv, 0, GDK_CURRENT_TIME); | |
1309 | |
1310 return handled; | |
1311 } | |
1312 | |
11796 | 1313 static void gaim_gtk_blist_buddy_details_cb(gpointer data, guint action, GtkWidget *item) |
1314 { | |
1315 gaim_prefs_set_bool("/gaim/gtk/blist/show_buddy_icons", | |
1316 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item))); | |
1317 } | |
1318 | |
5228 | 1319 static void gaim_gtk_blist_show_empty_groups_cb(gpointer data, guint action, GtkWidget *item) |
1320 { | |
7620 | 1321 gaim_prefs_set_bool("/gaim/gtk/blist/show_empty_groups", |
1322 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item))); | |
5228 | 1323 } |
1324 | |
1325 static void gaim_gtk_blist_edit_mode_cb(gpointer callback_data, guint callback_action, | |
1326 GtkWidget *checkitem) { | |
1327 if(gtkblist->window->window) { | |
1328 GdkCursor *cursor = gdk_cursor_new(GDK_WATCH); | |
1329 gdk_window_set_cursor(gtkblist->window->window, cursor); | |
1330 while (gtk_events_pending()) | |
1331 gtk_main_iteration(); | |
1332 gdk_cursor_unref(cursor); | |
1333 } | |
1334 | |
7620 | 1335 gaim_prefs_set_bool("/gaim/gtk/blist/show_offline_buddies", |
1336 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(checkitem))); | |
5228 | 1337 |
1338 if(gtkblist->window->window) { | |
1339 GdkCursor *cursor = gdk_cursor_new(GDK_LEFT_PTR); | |
1340 gdk_window_set_cursor(gtkblist->window->window, cursor); | |
1341 gdk_cursor_unref(cursor); | |
1342 } | |
1343 } | |
1344 | |
10074 | 1345 static void gaim_gtk_blist_mute_sounds_cb(gpointer data, guint action, GtkWidget *item) |
1346 { | |
1347 gaim_prefs_set_bool("/gaim/gtk/sound/mute", GTK_CHECK_MENU_ITEM(item)->active); | |
1348 } | |
1349 | |
1350 static void gaim_gtk_blist_mute_pref_cb(const char *name, GaimPrefType type, gpointer value, gpointer data) | |
1351 { | |
1352 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(gtkblist->ift, | |
1353 N_("/Tools/Mute Sounds"))), (gboolean)GPOINTER_TO_INT(value)); | |
1354 } | |
1355 | |
1356 static void gaim_gtk_blist_sound_method_pref_cb(const char *name, GaimPrefType type, gpointer value, gpointer data) | |
1357 { | |
1358 gboolean sensitive = TRUE; | |
1359 | |
1360 if(!strcmp(value, "none")) | |
1361 sensitive = FALSE; | |
1362 | |
1363 gtk_widget_set_sensitive(gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Mute Sounds")), sensitive); | |
1364 } | |
1365 | |
8089 | 1366 static void |
1367 add_buddies_from_vcard(const char *prpl_id, GaimGroup *group, GList *list, | |
1368 const char *alias) | |
1369 { | |
1370 GList *l; | |
1371 GaimAccount *account = NULL; | |
1372 GaimConnection *gc; | |
1373 | |
1374 if (list == NULL) | |
1375 return; | |
1376 | |
1377 for (l = gaim_connections_get_all(); l != NULL; l = l->next) | |
1378 { | |
1379 gc = (GaimConnection *)l->data; | |
1380 account = gaim_connection_get_account(gc); | |
1381 | |
1382 if (!strcmp(gaim_account_get_protocol_id(account), prpl_id)) | |
1383 break; | |
1384 | |
1385 account = NULL; | |
1386 } | |
1387 | |
1388 if (account != NULL) | |
1389 { | |
1390 for (l = list; l != NULL; l = l->next) | |
1391 { | |
1392 gaim_blist_request_add_buddy(account, l->data, | |
1393 (group ? group->name : NULL), | |
1394 alias); | |
1395 } | |
1396 } | |
1397 | |
1398 g_list_foreach(list, (GFunc)g_free, NULL); | |
1399 g_list_free(list); | |
1400 } | |
1401 | |
1402 static gboolean | |
1403 parse_vcard(const char *vcard, GaimGroup *group) | |
1404 { | |
1405 char *temp_vcard; | |
1406 char *s, *c; | |
1407 char *alias = NULL; | |
1408 GList *aims = NULL; | |
1409 GList *icqs = NULL; | |
1410 GList *yahoos = NULL; | |
1411 GList *msns = NULL; | |
1412 GList *jabbers = NULL; | |
1413 | |
1414 s = temp_vcard = g_strdup(vcard); | |
1415 | |
1416 while (*s != '\0' && strncmp(s, "END:vCard", strlen("END:vCard"))) | |
1417 { | |
1418 char *field, *value; | |
1419 | |
1420 field = s; | |
1421 | |
1422 /* Grab the field */ | |
1423 while (*s != '\r' && *s != '\n' && *s != '\0' && *s != ':') | |
1424 s++; | |
1425 | |
1426 if (*s == '\r') s++; | |
1427 if (*s == '\n') | |
1428 { | |
1429 s++; | |
1430 continue; | |
1431 } | |
1432 | |
1433 if (*s != '\0') *s++ = '\0'; | |
1434 | |
1435 if ((c = strchr(field, ';')) != NULL) | |
1436 *c = '\0'; | |
1437 | |
1438 /* Proceed to the end of the line */ | |
1439 value = s; | |
1440 | |
1441 while (*s != '\r' && *s != '\n' && *s != '\0') | |
1442 s++; | |
1443 | |
1444 if (*s == '\r') *s++ = '\0'; | |
1445 if (*s == '\n') *s++ = '\0'; | |
1446 | |
1447 /* We only want to worry about a few fields here. */ | |
1448 if (!strcmp(field, "FN")) | |
1449 alias = g_strdup(value); | |
1450 else if (!strcmp(field, "X-AIM") || !strcmp(field, "X-ICQ") || | |
1451 !strcmp(field, "X-YAHOO") || !strcmp(field, "X-MSN") || | |
1452 !strcmp(field, "X-JABBER")) | |
1453 { | |
1454 char **values = g_strsplit(value, ":", 0); | |
1455 char **im; | |
1456 | |
1457 for (im = values; *im != NULL; im++) | |
1458 { | |
1459 if (!strcmp(field, "X-AIM")) | |
1460 aims = g_list_append(aims, g_strdup(*im)); | |
1461 else if (!strcmp(field, "X-ICQ")) | |
1462 icqs = g_list_append(icqs, g_strdup(*im)); | |
1463 else if (!strcmp(field, "X-YAHOO")) | |
1464 yahoos = g_list_append(yahoos, g_strdup(*im)); | |
1465 else if (!strcmp(field, "X-MSN")) | |
1466 msns = g_list_append(msns, g_strdup(*im)); | |
1467 else if (!strcmp(field, "X-JABBER")) | |
1468 jabbers = g_list_append(jabbers, g_strdup(*im)); | |
1469 } | |
1470 | |
1471 g_strfreev(values); | |
1472 } | |
1473 } | |
1474 | |
1475 g_free(temp_vcard); | |
1476 | |
1477 if (aims == NULL && icqs == NULL && yahoos == NULL && | |
1478 msns == NULL && jabbers == NULL) | |
1479 { | |
1480 if (alias != NULL) | |
1481 g_free(alias); | |
1482 | |
1483 return FALSE; | |
1484 } | |
1485 | |
1486 add_buddies_from_vcard("prpl-oscar", group, aims, alias); | |
1487 add_buddies_from_vcard("prpl-oscar", group, icqs, alias); | |
1488 add_buddies_from_vcard("prpl-yahoo", group, yahoos, alias); | |
1489 add_buddies_from_vcard("prpl-msn", group, msns, alias); | |
1490 add_buddies_from_vcard("prpl-jabber", group, jabbers, alias); | |
1491 | |
1492 if (alias != NULL) | |
1493 g_free(alias); | |
1494 | |
1495 return TRUE; | |
1496 } | |
1497 | |
11059
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1498 #ifdef _WIN32 |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1499 static void gaim_gtk_blist_drag_begin(GtkWidget *widget, |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1500 GdkDragContext *drag_context, gpointer user_data) |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1501 { |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1502 gaim_gtk_blist_tooltip_destroy(); |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1503 |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1504 |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1505 /* Unhook the tooltip-timeout since we don't want a tooltip |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1506 * to appear and obscure the dragging operation. |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1507 * This is a workaround for GTK+ bug 107320. */ |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1508 if (gtkblist->timeout) { |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1509 g_source_remove(gtkblist->timeout); |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1510 gtkblist->timeout = 0; |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1511 } |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1512 } |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1513 #endif |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1514 |
9811 | 1515 static void gaim_gtk_blist_drag_data_get_cb(GtkWidget *widget, |
1516 GdkDragContext *dc, | |
1517 GtkSelectionData *data, | |
1518 guint info, | |
1519 guint time, | |
11059
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1520 gpointer null) |
5228 | 1521 { |
11059
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
1522 |
8089 | 1523 if (data->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE)) |
1524 { | |
5228 | 1525 GtkTreeRowReference *ref = g_object_get_data(G_OBJECT(dc), "gtk-tree-view-source-row"); |
1526 GtkTreePath *sourcerow = gtk_tree_row_reference_get_path(ref); | |
1527 GtkTreeIter iter; | |
1528 GaimBlistNode *node = NULL; | |
1529 GValue val = {0}; | |
5273 | 1530 if(!sourcerow) |
1531 return; | |
5228 | 1532 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, sourcerow); |
1533 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
1534 node = g_value_get_pointer(&val); | |
1535 gtk_selection_data_set (data, | |
1536 gdk_atom_intern ("GAIM_BLIST_NODE", FALSE), | |
1537 8, /* bits */ | |
1538 (void*)&node, | |
1539 sizeof (node)); | |
5273 | 1540 |
5228 | 1541 gtk_tree_path_free(sourcerow); |
1542 } | |
8089 | 1543 else if (data->target == gdk_atom_intern("application/x-im-contact", FALSE)) |
1544 { | |
7706 | 1545 GtkTreeRowReference *ref; |
1546 GtkTreePath *sourcerow; | |
1547 GtkTreeIter iter; | |
1548 GaimBlistNode *node = NULL; | |
1549 GaimBuddy *buddy; | |
1550 GaimConnection *gc; | |
1551 GValue val = {0}; | |
1552 GString *str; | |
1553 const char *protocol; | |
1554 char *mime_str; | |
1555 | |
1556 ref = g_object_get_data(G_OBJECT(dc), "gtk-tree-view-source-row"); | |
1557 sourcerow = gtk_tree_row_reference_get_path(ref); | |
1558 | |
1559 if (!sourcerow) | |
1560 return; | |
1561 | |
1562 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, | |
1563 sourcerow); | |
1564 gtk_tree_model_get_value(GTK_TREE_MODEL(gtkblist->treemodel), &iter, | |
1565 NODE_COLUMN, &val); | |
1566 | |
1567 node = g_value_get_pointer(&val); | |
1568 | |
1569 if (GAIM_BLIST_NODE_IS_CONTACT(node)) | |
1570 { | |
1571 buddy = gaim_contact_get_priority_buddy((GaimContact *)node); | |
1572 } | |
1573 else if (!GAIM_BLIST_NODE_IS_BUDDY(node)) | |
1574 { | |
1575 gtk_tree_path_free(sourcerow); | |
1576 return; | |
1577 } | |
1578 else | |
1579 { | |
1580 buddy = (GaimBuddy *)node; | |
1581 } | |
1582 | |
1583 gc = gaim_account_get_connection(buddy->account); | |
1584 | |
1585 if (gc == NULL) | |
1586 { | |
1587 gtk_tree_path_free(sourcerow); | |
1588 return; | |
1589 } | |
1590 | |
1591 protocol = | |
1592 GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->list_icon(buddy->account, | |
1593 buddy); | |
1594 | |
1595 str = g_string_new(NULL); | |
1596 g_string_printf(str, | |
1597 "MIME-Version: 1.0\r\n" | |
1598 "Content-Type: application/x-im-contact\r\n" | |
1599 "X-IM-Protocol: %s\r\n" | |
1600 "X-IM-Username: %s\r\n", | |
1601 protocol, | |
1602 buddy->name); | |
1603 | |
1604 if (buddy->alias != NULL) | |
1605 { | |
1606 g_string_append_printf(str, | |
1607 "X-IM-Alias: %s\r\n", | |
1608 buddy->alias); | |
1609 } | |
1610 | |
1611 str = g_string_append(str, "\r\n"); | |
1612 | |
1613 mime_str = g_string_free(str, FALSE); | |
1614 | |
1615 gtk_selection_data_set(data, | |
1616 gdk_atom_intern("application/x-im-contact", FALSE), | |
1617 8, /* bits */ | |
11137 | 1618 (const guchar *)mime_str, |
7706 | 1619 strlen(mime_str) + 1); |
1620 | |
1621 g_free(mime_str); | |
1622 gtk_tree_path_free(sourcerow); | |
1623 } | |
5228 | 1624 } |
1625 | |
1626 static void gaim_gtk_blist_drag_data_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, | |
1627 GtkSelectionData *sd, guint info, guint t) | |
7620 | 1628 { |
5228 | 1629 if (sd->target == gdk_atom_intern("GAIM_BLIST_NODE", FALSE) && sd->data) { |
1630 GaimBlistNode *n = NULL; | |
1631 GtkTreePath *path = NULL; | |
1632 GtkTreeViewDropPosition position; | |
1633 memcpy(&n, sd->data, sizeof(n)); | |
1634 if(gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), x, y, &path, &position)) { | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
1635 /* if we're here, I think it means the drop is ok */ |
7642 | 1636 GtkTreeIter iter; |
5228 | 1637 GaimBlistNode *node; |
1638 GValue val = {0}; | |
7620 | 1639 struct _gaim_gtk_blist_node *gtknode; |
1640 | |
1641 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), | |
1642 &iter, path); | |
1643 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), | |
1644 &iter, NODE_COLUMN, &val); | |
5228 | 1645 node = g_value_get_pointer(&val); |
7620 | 1646 gtknode = node->ui_data; |
1647 | |
1648 if (GAIM_BLIST_NODE_IS_CONTACT(n)) { | |
1649 GaimContact *c = (GaimContact*)n; | |
1650 if (GAIM_BLIST_NODE_IS_CONTACT(node) && gtknode->contact_expanded) { | |
1651 gaim_blist_merge_contact(c, node); | |
1652 } else if (GAIM_BLIST_NODE_IS_CONTACT(node) || | |
5234 | 1653 GAIM_BLIST_NODE_IS_CHAT(node)) { |
5228 | 1654 switch(position) { |
1655 case GTK_TREE_VIEW_DROP_AFTER: | |
1656 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
7620 | 1657 gaim_blist_add_contact(c, (GaimGroup*)node->parent, |
1658 node); | |
1659 break; | |
1660 case GTK_TREE_VIEW_DROP_BEFORE: | |
1661 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
1662 gaim_blist_add_contact(c, (GaimGroup*)node->parent, | |
1663 node->prev); | |
1664 break; | |
1665 } | |
1666 } else if(GAIM_BLIST_NODE_IS_GROUP(node)) { | |
1667 gaim_blist_add_contact(c, (GaimGroup*)node, NULL); | |
1668 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
1669 gaim_blist_merge_contact(c, node); | |
1670 } | |
1671 } else if (GAIM_BLIST_NODE_IS_BUDDY(n)) { | |
1672 GaimBuddy *b = (GaimBuddy*)n; | |
1673 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
1674 switch(position) { | |
1675 case GTK_TREE_VIEW_DROP_AFTER: | |
1676 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
1677 gaim_blist_add_buddy(b, (GaimContact*)node->parent, | |
1678 (GaimGroup*)node->parent->parent, node); | |
5228 | 1679 break; |
1680 case GTK_TREE_VIEW_DROP_BEFORE: | |
1681 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
7620 | 1682 gaim_blist_add_buddy(b, (GaimContact*)node->parent, |
1683 (GaimGroup*)node->parent->parent, | |
1684 node->prev); | |
5228 | 1685 break; |
1686 } | |
7620 | 1687 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) { |
1688 gaim_blist_add_buddy(b, NULL, (GaimGroup*)node->parent, | |
1689 NULL); | |
5228 | 1690 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { |
7620 | 1691 gaim_blist_add_buddy(b, NULL, (GaimGroup*)node, NULL); |
1692 } else if (GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
1693 if(gtknode->contact_expanded) { | |
1694 switch(position) { | |
1695 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
1696 case GTK_TREE_VIEW_DROP_AFTER: | |
1697 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
1698 gaim_blist_add_buddy(b, (GaimContact*)node, | |
1699 (GaimGroup*)node->parent, NULL); | |
1700 break; | |
1701 case GTK_TREE_VIEW_DROP_BEFORE: | |
1702 gaim_blist_add_buddy(b, NULL, | |
1703 (GaimGroup*)node->parent, node->prev); | |
1704 break; | |
1705 } | |
1706 } else { | |
1707 switch(position) { | |
1708 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
1709 case GTK_TREE_VIEW_DROP_AFTER: | |
1710 gaim_blist_add_buddy(b, NULL, | |
1711 (GaimGroup*)node->parent, NULL); | |
1712 break; | |
1713 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
1714 case GTK_TREE_VIEW_DROP_BEFORE: | |
1715 gaim_blist_add_buddy(b, NULL, | |
1716 (GaimGroup*)node->parent, node->prev); | |
1717 break; | |
1718 } | |
1719 } | |
5228 | 1720 } |
5234 | 1721 } else if (GAIM_BLIST_NODE_IS_CHAT(n)) { |
7620 | 1722 GaimChat *chat = (GaimChat *)n; |
1723 if (GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
1724 switch(position) { | |
1725 case GTK_TREE_VIEW_DROP_AFTER: | |
1726 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
1727 gaim_blist_add_chat(chat, | |
1728 (GaimGroup*)node->parent->parent, node); | |
1729 break; | |
1730 case GTK_TREE_VIEW_DROP_BEFORE: | |
1731 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
1732 gaim_blist_add_chat(chat, | |
1733 (GaimGroup*)node->parent->parent, | |
1734 node->prev); | |
1735 break; | |
1736 } | |
1737 } else if(GAIM_BLIST_NODE_IS_CONTACT(node) || | |
5234 | 1738 GAIM_BLIST_NODE_IS_CHAT(node)) { |
1739 switch(position) { | |
1740 case GTK_TREE_VIEW_DROP_AFTER: | |
1741 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
7620 | 1742 gaim_blist_add_chat(chat, (GaimGroup*)node->parent, node); |
5234 | 1743 break; |
1744 case GTK_TREE_VIEW_DROP_BEFORE: | |
1745 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
7620 | 1746 gaim_blist_add_chat(chat, (GaimGroup*)node->parent, node->prev); |
5234 | 1747 break; |
1748 } | |
1749 } else if (GAIM_BLIST_NODE_IS_GROUP(node)) { | |
7620 | 1750 gaim_blist_add_chat(chat, (GaimGroup*)node, NULL); |
5234 | 1751 } |
5228 | 1752 } else if (GAIM_BLIST_NODE_IS_GROUP(n)) { |
7620 | 1753 GaimGroup *g = (GaimGroup*)n; |
5228 | 1754 if (GAIM_BLIST_NODE_IS_GROUP(node)) { |
1755 switch (position) { | |
1756 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
1757 case GTK_TREE_VIEW_DROP_AFTER: | |
1758 gaim_blist_add_group(g, node); | |
1759 break; | |
1760 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
1761 case GTK_TREE_VIEW_DROP_BEFORE: | |
1762 gaim_blist_add_group(g, node->prev); | |
1763 break; | |
1764 } | |
7620 | 1765 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) { |
1766 gaim_blist_add_group(g, node->parent->parent); | |
1767 } else if(GAIM_BLIST_NODE_IS_CONTACT(node) || | |
5234 | 1768 GAIM_BLIST_NODE_IS_CHAT(node)) { |
5228 | 1769 gaim_blist_add_group(g, node->parent); |
1770 } | |
1771 } | |
1772 | |
1773 gtk_tree_path_free(path); | |
7620 | 1774 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); |
5228 | 1775 } |
1776 } | |
7706 | 1777 else if (sd->target == gdk_atom_intern("application/x-im-contact", |
1778 FALSE) && sd->data) | |
1779 { | |
1780 GaimGroup *group = NULL; | |
1781 GtkTreePath *path = NULL; | |
1782 GtkTreeViewDropPosition position; | |
7712
2823111061ba
[gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents:
7706
diff
changeset
|
1783 GaimAccount *account; |
7706 | 1784 char *protocol = NULL; |
1785 char *username = NULL; | |
1786 char *alias = NULL; | |
1787 | |
1788 if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), | |
1789 x, y, &path, &position)) | |
1790 { | |
1791 GtkTreeIter iter; | |
1792 GaimBlistNode *node; | |
1793 GValue val = {0}; | |
1794 | |
1795 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), | |
1796 &iter, path); | |
1797 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), | |
1798 &iter, NODE_COLUMN, &val); | |
1799 node = g_value_get_pointer(&val); | |
1800 | |
1801 if (GAIM_BLIST_NODE_IS_BUDDY(node)) | |
1802 { | |
1803 group = (GaimGroup *)node->parent->parent; | |
1804 } | |
1805 else if (GAIM_BLIST_NODE_IS_CHAT(node) || | |
1806 GAIM_BLIST_NODE_IS_CONTACT(node)) | |
1807 { | |
1808 group = (GaimGroup *)node->parent; | |
1809 } | |
1810 else if (GAIM_BLIST_NODE_IS_GROUP(node)) | |
1811 { | |
1812 group = (GaimGroup *)node; | |
1813 } | |
1814 } | |
1815 | |
11137 | 1816 if (gaim_gtk_parse_x_im_contact((const char *)sd->data, FALSE, &account, |
7712
2823111061ba
[gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents:
7706
diff
changeset
|
1817 &protocol, &username, &alias)) |
7706 | 1818 { |
1819 if (account == NULL) | |
1820 { | |
1821 gaim_notify_error(NULL, NULL, | |
1822 _("You are not currently signed on with an account that " | |
1823 "can add that buddy."), NULL); | |
1824 } | |
1825 else | |
1826 { | |
1827 gaim_blist_request_add_buddy(account, username, | |
1828 (group ? group->name : NULL), | |
1829 alias); | |
1830 } | |
1831 } | |
1832 | |
1833 if (username != NULL) g_free(username); | |
1834 if (protocol != NULL) g_free(protocol); | |
1835 if (alias != NULL) g_free(alias); | |
1836 | |
1837 if (path != NULL) | |
1838 gtk_tree_path_free(path); | |
1839 | |
1840 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); | |
1841 } | |
8089 | 1842 else if (sd->target == gdk_atom_intern("text/x-vcard", FALSE) && sd->data) |
1843 { | |
1844 gboolean result; | |
1845 GaimGroup *group = NULL; | |
1846 GtkTreePath *path = NULL; | |
1847 GtkTreeViewDropPosition position; | |
1848 | |
1849 if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), | |
1850 x, y, &path, &position)) | |
1851 { | |
1852 GtkTreeIter iter; | |
1853 GaimBlistNode *node; | |
1854 GValue val = {0}; | |
1855 | |
1856 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), | |
1857 &iter, path); | |
1858 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), | |
1859 &iter, NODE_COLUMN, &val); | |
1860 node = g_value_get_pointer(&val); | |
1861 | |
1862 if (GAIM_BLIST_NODE_IS_BUDDY(node)) | |
1863 { | |
1864 group = (GaimGroup *)node->parent->parent; | |
1865 } | |
1866 else if (GAIM_BLIST_NODE_IS_CHAT(node) || | |
1867 GAIM_BLIST_NODE_IS_CONTACT(node)) | |
1868 { | |
1869 group = (GaimGroup *)node->parent; | |
1870 } | |
1871 else if (GAIM_BLIST_NODE_IS_GROUP(node)) | |
1872 { | |
1873 group = (GaimGroup *)node; | |
1874 } | |
1875 } | |
1876 | |
11137 | 1877 result = parse_vcard((const gchar *)sd->data, group); |
8089 | 1878 |
1879 gtk_drag_finish(dc, result, (dc->action == GDK_ACTION_MOVE), t); | |
9525 | 1880 } else if (sd->target == gdk_atom_intern("text/uri-list", FALSE) && sd->data) { |
9495 | 1881 GtkTreePath *path = NULL; |
1882 GtkTreeViewDropPosition position; | |
1883 | |
1884 if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), | |
9811 | 1885 x, y, &path, &position)) |
9495 | 1886 { |
1887 GtkTreeIter iter; | |
1888 GaimBlistNode *node; | |
1889 GValue val = {0}; | |
10382
9f28196ed769
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10357
diff
changeset
|
1890 |
9495 | 1891 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), |
1892 &iter, path); | |
1893 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), | |
1894 &iter, NODE_COLUMN, &val); | |
1895 node = g_value_get_pointer(&val); | |
10382
9f28196ed769
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10357
diff
changeset
|
1896 |
9495 | 1897 if (GAIM_BLIST_NODE_IS_BUDDY(node) || GAIM_BLIST_NODE_IS_CONTACT(node)) { |
1898 GaimBuddy *b = GAIM_BLIST_NODE_IS_BUDDY(node) ? (GaimBuddy*)node : gaim_contact_get_priority_buddy((GaimContact*)node); | |
10229 | 1899 gaim_dnd_file_manage(sd, b->account, b->name); |
1900 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); | |
1901 } else { | |
1902 gtk_drag_finish(dc, FALSE, FALSE, t); | |
9495 | 1903 } |
10382
9f28196ed769
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10357
diff
changeset
|
1904 } |
8089 | 1905 } |
5228 | 1906 } |
1907 | |
10482 | 1908 static GdkPixbuf *gaim_gtk_blist_get_buddy_icon(GaimBlistNode *node, |
1909 gboolean scaled, gboolean greyed) | |
1910 { | |
10483 | 1911 GdkPixbuf *buf, *ret = NULL; |
10482 | 1912 GdkPixbufLoader *loader; |
1913 GaimBuddyIcon *icon; | |
11137 | 1914 const guchar *data; |
1915 gsize len; | |
10482 | 1916 GaimBuddy *buddy = (GaimBuddy *)node; |
1917 | |
1918 if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
1919 buddy = gaim_contact_get_priority_buddy((GaimContact*)node); | |
1920 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
1921 buddy = (GaimBuddy*)node; | |
1922 } else { | |
1923 return NULL; | |
1924 } | |
1925 | |
1926 #if 0 | |
1927 if (!gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")) | |
1928 return NULL; | |
1929 #endif | |
1930 | |
1931 if (!(icon = gaim_buddy_get_icon(buddy))) | |
1932 if (!(icon = gaim_buddy_icons_find(buddy->account, buddy->name))) /* Not sure I like this...*/ | |
1933 return NULL; | |
1934 | |
1935 loader = gdk_pixbuf_loader_new(); | |
1936 data = gaim_buddy_icon_get_data(icon, &len); | |
1937 gdk_pixbuf_loader_write(loader, data, len, NULL); | |
1938 buf = gdk_pixbuf_loader_get_pixbuf(loader); | |
1939 if (buf) | |
1940 g_object_ref(G_OBJECT(buf)); | |
1941 gdk_pixbuf_loader_close(loader, NULL); | |
1942 g_object_unref(G_OBJECT(loader)); | |
1943 | |
1944 if (buf) { | |
10544 | 1945 GaimAccount *account = gaim_buddy_get_account(buddy); |
1946 GaimPluginProtocolInfo *prpl_info = NULL; | |
1947 int orig_width, orig_height; | |
1948 int scale_width, scale_height; | |
1949 | |
1950 if(account && account->gc) | |
1951 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(account->gc->prpl); | |
1952 | |
10482 | 1953 if (greyed) { |
1954 GaimPresence *presence = gaim_buddy_get_presence(buddy); | |
1955 if (!GAIM_BUDDY_IS_ONLINE(buddy)) | |
1956 gdk_pixbuf_saturate_and_pixelate(buf, buf, 0.0, FALSE); | |
1957 if (gaim_presence_is_idle(presence)) | |
1958 gdk_pixbuf_saturate_and_pixelate(buf, buf, 0.25, FALSE); | |
1959 } | |
1960 | |
10544 | 1961 /* i'd use the gaim_gtk_buddy_icon_get_scale_size() thing, |
1962 * but it won't tell me the original size, which I need for scaling | |
1963 * purposes */ | |
1964 scale_width = orig_width = gdk_pixbuf_get_width(buf); | |
1965 scale_height = orig_height = gdk_pixbuf_get_height(buf); | |
1966 | |
1967 gaim_buddy_icon_get_scale_size(prpl_info ? &prpl_info->icon_spec : NULL, &scale_width, &scale_height); | |
1968 | |
10482 | 1969 if (scaled) { |
10544 | 1970 if(scale_height > scale_width) { |
1971 scale_width = 30.0 * (double)scale_width / (double)scale_height; | |
1972 scale_height = 30; | |
1973 } else { | |
1974 scale_height = 30.0 * (double)scale_height / (double)scale_width; | |
1975 scale_width = 30; | |
1976 } | |
1977 | |
1978 ret = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 30, 30); | |
1979 gdk_pixbuf_fill(ret, 0x00000000); | |
1980 gdk_pixbuf_scale(buf, ret, (30-scale_width)/2, (30-scale_height)/2, scale_width, scale_height, (30-scale_width)/2, (30-scale_height)/2, (double)scale_width/(double)orig_width, (double)scale_height/(double)orig_height, GDK_INTERP_BILINEAR); | |
10483 | 1981 } else { |
1982 ret = gdk_pixbuf_scale_simple(buf,scale_width,scale_height, GDK_INTERP_BILINEAR); | |
1983 } | |
10544 | 1984 g_object_unref(G_OBJECT(buf)); |
10482 | 1985 } |
1986 | |
10483 | 1987 return ret; |
10482 | 1988 } |
1989 | |
5234 | 1990 static void gaim_gtk_blist_paint_tip(GtkWidget *widget, GdkEventExpose *event, GaimBlistNode *node) |
5228 | 1991 { |
1992 GtkStyle *style; | |
5234 | 1993 GdkPixbuf *pixbuf = gaim_gtk_blist_get_status_icon(node, GAIM_STATUS_ICON_LARGE); |
5228 | 1994 PangoLayout *layout; |
10482 | 1995 GdkPixbuf *avatar = NULL; |
1996 int layout_width, layout_height; | |
5228 | 1997 |
11636 | 1998 if(gtkblist->tooltiptext == NULL) |
7620 | 1999 return; |
2000 | |
10482 | 2001 avatar = gaim_gtk_blist_get_buddy_icon(node, FALSE, FALSE); |
2002 | |
5228 | 2003 layout = gtk_widget_create_pango_layout (gtkblist->tipwindow, NULL); |
11636 | 2004 pango_layout_set_markup(layout, gtkblist->tooltiptext, strlen(gtkblist->tooltiptext)); |
5228 | 2005 pango_layout_set_wrap(layout, PANGO_WRAP_WORD); |
2006 pango_layout_set_width(layout, 300000); | |
10482 | 2007 { |
2008 int w, h; | |
2009 pango_layout_get_size (layout, &w, &h); | |
2010 layout_width = PANGO_PIXELS(w) + 8; | |
2011 layout_height = PANGO_PIXELS(h) + 8; | |
2012 } | |
5228 | 2013 style = gtkblist->tipwindow->style; |
2014 | |
9811 | 2015 gtk_paint_flat_box(style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, |
2016 NULL, gtkblist->tipwindow, "tooltip", 0, 0, -1, -1); | |
5228 | 2017 |
2018 #if GTK_CHECK_VERSION(2,2,0) | |
2019 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, pixbuf, | |
2020 0, 0, 4, 4, -1 , -1, GDK_RGB_DITHER_NONE, 0, 0); | |
10482 | 2021 if(avatar) |
2022 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, | |
2023 avatar, 0, 0, layout_width + 38 + 4, 4, -1 , -1, GDK_RGB_DITHER_NONE, 0, 0); | |
5228 | 2024 #else |
2025 gdk_pixbuf_render_to_drawable(pixbuf, GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, 0, 0, 4, 4, -1, -1, GDK_RGB_DITHER_NONE, 0, 0); | |
10482 | 2026 if(avatar) |
2027 gdk_pixbuf_render_to_drawable(avatar, | |
2028 GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, 0, 0, layout_width + 38 + 4, | |
2029 4, -1, -1, GDK_RGB_DITHER_NONE, 0, 0); | |
5228 | 2030 #endif |
2031 | |
10778 | 2032 gtk_paint_layout (style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, FALSE, |
10482 | 2033 NULL, gtkblist->tipwindow, "tooltip", 38 + 4, 4, layout); |
2034 | |
2035 if(avatar) | |
2036 g_object_unref (avatar); | |
5228 | 2037 |
2038 g_object_unref (pixbuf); | |
2039 g_object_unref (layout); | |
7620 | 2040 |
5228 | 2041 return; |
2042 } | |
2043 | |
8254 | 2044 static void gaim_gtk_blist_tooltip_destroy() |
2045 { | |
11636 | 2046 g_free(gtkblist->tooltiptext); |
2047 gtkblist->tooltiptext = NULL; | |
2048 | |
8254 | 2049 if (gtkblist->tipwindow == NULL) |
2050 return; | |
2051 | |
2052 gtk_widget_destroy(gtkblist->tipwindow); | |
2053 gtkblist->tipwindow = NULL; | |
2054 } | |
2055 | |
10354 | 2056 static gboolean gaim_gtk_blist_expand_timeout(GtkWidget *tv) |
2057 { | |
2058 GtkTreePath *path; | |
2059 GtkTreeIter iter; | |
2060 GaimBlistNode *node; | |
2061 GValue val = {0}; | |
2062 struct _gaim_gtk_blist_node *gtknode; | |
2063 | |
2064 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), gtkblist->tip_rect.x, gtkblist->tip_rect.y, &path, NULL, NULL, NULL)) | |
2065 return FALSE; | |
2066 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
2067 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
2068 node = g_value_get_pointer(&val); | |
2069 | |
10504 | 2070 if(!GAIM_BLIST_NODE_IS_CONTACT(node)) { |
2071 gtk_tree_path_free(path); | |
10354 | 2072 return FALSE; |
10504 | 2073 } |
10354 | 2074 |
2075 gtknode = node->ui_data; | |
2076 | |
2077 if (!gtknode->contact_expanded) { | |
2078 GtkTreeIter i; | |
10382
9f28196ed769
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10357
diff
changeset
|
2079 |
10354 | 2080 gaim_gtk_blist_expand_contact_cb(NULL, node); |
10382
9f28196ed769
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10357
diff
changeset
|
2081 |
10354 | 2082 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, >kblist->contact_rect); |
2083 gdk_drawable_get_size(GDK_DRAWABLE(tv->window), &(gtkblist->contact_rect.width), NULL); | |
2084 gtkblist->mouseover_contact = node; | |
2085 gtk_tree_path_down (path); | |
2086 while (gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &i, path)) { | |
2087 GdkRectangle rect; | |
2088 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, &rect); | |
2089 gtkblist->contact_rect.height += rect.height; | |
2090 gtk_tree_path_next(path); | |
2091 } | |
2092 } | |
2093 gtk_tree_path_free(path); | |
2094 return FALSE; | |
2095 } | |
2096 | |
5228 | 2097 static gboolean gaim_gtk_blist_tooltip_timeout(GtkWidget *tv) |
2098 { | |
2099 GtkTreePath *path; | |
2100 GtkTreeIter iter; | |
2101 GaimBlistNode *node; | |
2102 GValue val = {0}; | |
9869 | 2103 int scr_w, scr_h, w, h, x, y; |
2104 #if GTK_CHECK_VERSION(2,2,0) | |
2105 int mon_num; | |
2106 GdkScreen *screen = NULL; | |
2107 #endif | |
5234 | 2108 PangoLayout *layout; |
7636 | 2109 gboolean tooltip_top = FALSE; |
2110 struct _gaim_gtk_blist_node *gtknode; | |
9773 | 2111 GdkRectangle mon_size; |
5228 | 2112 |
11636 | 2113 /* |
2114 * Attempt to free the previous tooltip. I have a feeling | |
2115 * this is never needed... but just in case. | |
2116 */ | |
2117 gaim_gtk_blist_tooltip_destroy(); | |
2118 | |
7636 | 2119 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), gtkblist->tip_rect.x, gtkblist->tip_rect.y, &path, NULL, NULL, NULL)) |
5228 | 2120 return FALSE; |
2121 gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path); | |
2122 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); | |
2123 node = g_value_get_pointer(&val); | |
7620 | 2124 |
10504 | 2125 gtk_tree_path_free(path); |
2126 | |
7620 | 2127 if(!GAIM_BLIST_NODE_IS_CONTACT(node) && !GAIM_BLIST_NODE_IS_BUDDY(node) |
2128 && !GAIM_BLIST_NODE_IS_CHAT(node)) | |
5234 | 2129 return FALSE; |
5228 | 2130 |
7636 | 2131 gtknode = node->ui_data; |
2132 | |
11636 | 2133 gtkblist->tooltiptext = gaim_get_tooltip_text(node); |
2134 if (gtkblist->tooltiptext == NULL) | |
7620 | 2135 return FALSE; |
2136 | |
5234 | 2137 gtkblist->tipwindow = gtk_window_new(GTK_WINDOW_POPUP); |
2138 gtk_widget_set_app_paintable(gtkblist->tipwindow, TRUE); | |
2139 gtk_window_set_resizable(GTK_WINDOW(gtkblist->tipwindow), FALSE); | |
2140 gtk_widget_set_name(gtkblist->tipwindow, "gtk-tooltips"); | |
2141 g_signal_connect(G_OBJECT(gtkblist->tipwindow), "expose_event", | |
2142 G_CALLBACK(gaim_gtk_blist_paint_tip), node); | |
2143 gtk_widget_ensure_style (gtkblist->tipwindow); | |
7837 | 2144 |
5234 | 2145 layout = gtk_widget_create_pango_layout (gtkblist->tipwindow, NULL); |
2146 pango_layout_set_wrap(layout, PANGO_WRAP_WORD); | |
2147 pango_layout_set_width(layout, 300000); | |
11636 | 2148 pango_layout_set_markup(layout, gtkblist->tooltiptext, strlen(gtkblist->tooltiptext)); |
5234 | 2149 pango_layout_get_size (layout, &w, &h); |
9773 | 2150 |
9869 | 2151 #if GTK_CHECK_VERSION(2,2,0) |
9773 | 2152 gdk_display_get_pointer(gdk_display_get_default(), &screen, &x, &y, NULL); |
2153 mon_num = gdk_screen_get_monitor_at_point(screen, x, y); | |
2154 gdk_screen_get_monitor_geometry(screen, mon_num, &mon_size); | |
2155 | |
2156 scr_w = mon_size.width + mon_size.x; | |
2157 scr_h = mon_size.height + mon_size.y; | |
9869 | 2158 #else |
2159 scr_w = gdk_screen_width(); | |
2160 scr_h = gdk_screen_height(); | |
2161 gdk_window_get_pointer(NULL, &x, &y, NULL); | |
2162 mon_size.x = 0; | |
2163 mon_size.y = 0; | |
2164 #endif | |
9773 | 2165 |
5234 | 2166 w = PANGO_PIXELS(w) + 8; |
2167 h = PANGO_PIXELS(h) + 8; | |
5228 | 2168 |
5234 | 2169 /* 38 is the size of a large status icon plus 4 pixels padding on each side. |
2170 * I should #define this or something */ | |
2171 w = w + 38; | |
2172 h = MAX(h, 38); | |
2173 | |
10482 | 2174 /* Now the size of the buddy icon */ |
2175 { | |
2176 GdkPixbuf *avatar = NULL; | |
2177 | |
2178 if ((avatar = gaim_gtk_blist_get_buddy_icon(node, FALSE, FALSE))) { | |
2179 w += gdk_pixbuf_get_width(avatar) + 8; | |
2180 h = MAX(h, gdk_pixbuf_get_height(avatar) + 8); | |
2181 g_object_unref(avatar); | |
2182 } | |
2183 } | |
2184 | |
9869 | 2185 #if GTK_CHECK_VERSION(2,2,0) |
10046 | 2186 if (w > mon_size.width) |
9773 | 2187 w = mon_size.width - 10; |
2188 | |
10046 | 2189 if (h > mon_size.height) |
9773 | 2190 h = mon_size.height - 10; |
9869 | 2191 #endif |
9773 | 2192 |
5234 | 2193 if (GTK_WIDGET_NO_WINDOW(gtkblist->window)) |
2194 y+=gtkblist->window->allocation.y; | |
2195 | |
2196 x -= ((w >> 1) + 4); | |
5228 | 2197 |
7636 | 2198 if ((y + h + 4) > scr_h || tooltip_top) |
7620 | 2199 y = y - h - 5; |
5234 | 2200 else |
2201 y = y + 6; | |
7620 | 2202 |
9773 | 2203 if (y < mon_size.y) |
2204 y = mon_size.y; | |
2205 | |
2206 if (y != mon_size.y) { | |
7719 | 2207 if ((x + w) > scr_w) |
2208 x -= (x + w + 5) - scr_w; | |
9773 | 2209 else if (x < mon_size.x) |
2210 x = mon_size.x; | |
7719 | 2211 } else { |
2212 x -= (w / 2 + 10); | |
9773 | 2213 if (x < mon_size.x) |
2214 x = mon_size.x; | |
7719 | 2215 } |
2216 | |
5234 | 2217 g_object_unref (layout); |
2218 gtk_widget_set_size_request(gtkblist->tipwindow, w, h); | |
2219 gtk_window_move(GTK_WINDOW(gtkblist->tipwindow), x, y); | |
2220 gtk_widget_show(gtkblist->tipwindow); | |
5228 | 2221 |
2222 return FALSE; | |
2223 } | |
2224 | |
10354 | 2225 static gboolean gaim_gtk_blist_drag_motion_cb(GtkWidget *tv, GdkDragContext *drag_context, |
2226 gint x, gint y, guint time, gpointer user_data) | |
2227 { | |
2228 GtkTreePath *path; | |
2229 int delay; | |
2230 | |
2231 delay = 500; | |
2232 | |
2233 if (gtkblist->drag_timeout) { | |
2234 if ((y > gtkblist->tip_rect.y) && ((y - gtkblist->tip_rect.height) < gtkblist->tip_rect.y)) | |
2235 return FALSE; | |
2236 /* We've left the cell. Remove the timeout and create a new one below */ | |
2237 g_source_remove(gtkblist->drag_timeout); | |
2238 } | |
2239 | |
2240 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), x, y, &path, NULL, NULL, NULL); | |
2241 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, >kblist->tip_rect); | |
2242 | |
2243 if (path) | |
2244 gtk_tree_path_free(path); | |
2245 gtkblist->drag_timeout = g_timeout_add(delay, (GSourceFunc)gaim_gtk_blist_expand_timeout, tv); | |
2246 | |
2247 if (gtkblist->mouseover_contact) { | |
2248 if ((y < gtkblist->contact_rect.y) || ((y - gtkblist->contact_rect.height) > gtkblist->contact_rect.y)) { | |
2249 gaim_gtk_blist_collapse_contact_cb(NULL, gtkblist->mouseover_contact); | |
2250 gtkblist->mouseover_contact = NULL; | |
2251 } | |
2252 } | |
2253 | |
2254 return FALSE; | |
2255 } | |
2256 | |
5228 | 2257 static gboolean gaim_gtk_blist_motion_cb (GtkWidget *tv, GdkEventMotion *event, gpointer null) |
2258 { | |
2259 GtkTreePath *path; | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2260 int delay; |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2261 |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2262 delay = gaim_prefs_get_int("/gaim/gtk/blist/tooltip_delay"); |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2263 |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2264 if (delay == 0) |
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2265 return FALSE; |
8083 | 2266 |
5228 | 2267 if (gtkblist->timeout) { |
7636 | 2268 if ((event->y > gtkblist->tip_rect.y) && ((event->y - gtkblist->tip_rect.height) < gtkblist->tip_rect.y)) |
5228 | 2269 return FALSE; |
2270 /* We've left the cell. Remove the timeout and create a new one below */ | |
8254 | 2271 gaim_gtk_blist_tooltip_destroy(); |
5228 | 2272 g_source_remove(gtkblist->timeout); |
2273 } | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2274 |
5228 | 2275 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), event->x, event->y, &path, NULL, NULL, NULL); |
7636 | 2276 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, >kblist->tip_rect); |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2277 |
5228 | 2278 if (path) |
2279 gtk_tree_path_free(path); | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2280 gtkblist->timeout = g_timeout_add(delay, (GSourceFunc)gaim_gtk_blist_tooltip_timeout, tv); |
7636 | 2281 |
2282 if (gtkblist->mouseover_contact) { | |
2283 if ((event->y < gtkblist->contact_rect.y) || ((event->y - gtkblist->contact_rect.height) > gtkblist->contact_rect.y)) { | |
2284 gaim_gtk_blist_collapse_contact_cb(NULL, gtkblist->mouseover_contact); | |
2285 gtkblist->mouseover_contact = NULL; | |
2286 } | |
2287 } | |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2288 |
5228 | 2289 return FALSE; |
2290 } | |
2291 | |
2292 static void gaim_gtk_blist_leave_cb (GtkWidget *w, GdkEventCrossing *e, gpointer n) | |
2293 { | |
8083 | 2294 |
5228 | 2295 if (gtkblist->timeout) { |
2296 g_source_remove(gtkblist->timeout); | |
2297 gtkblist->timeout = 0; | |
2298 } | |
10382
9f28196ed769
[gaim-migrate @ 11608]
Luke Schierer <lschiere@pidgin.im>
parents:
10357
diff
changeset
|
2299 |
10354 | 2300 if (gtkblist->drag_timeout) { |
2301 g_source_remove(gtkblist->drag_timeout); | |
2302 gtkblist->drag_timeout = 0; | |
2303 } | |
2304 | |
8254 | 2305 gaim_gtk_blist_tooltip_destroy(); |
7720 | 2306 |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2307 if (gtkblist->mouseover_contact && |
9811 | 2308 !((e->x > gtkblist->contact_rect.x) && (e->x < (gtkblist->contact_rect.x + gtkblist->contact_rect.width)) && |
2309 (e->y > gtkblist->contact_rect.y) && (e->y < (gtkblist->contact_rect.y + gtkblist->contact_rect.height)))) { | |
2310 gaim_gtk_blist_collapse_contact_cb(NULL, gtkblist->mouseover_contact); | |
7636 | 2311 gtkblist->mouseover_contact = NULL; |
2312 } | |
5228 | 2313 } |
2314 | |
2315 static void | |
2316 toggle_debug(void) | |
2317 { | |
7620 | 2318 gaim_prefs_set_bool("/gaim/gtk/debug/enabled", |
2319 !gaim_prefs_get_bool("/gaim/gtk/debug/enabled")); | |
5228 | 2320 } |
2321 | |
2322 | |
2323 /*************************************************** | |
2324 * Crap * | |
2325 ***************************************************/ | |
2326 static GtkItemFactoryEntry blist_menu[] = | |
2327 { | |
2328 /* Buddies menu */ | |
2329 { N_("/_Buddies"), NULL, NULL, 0, "<Branch>" }, | |
9714 | 2330 { N_("/Buddies/New Instant _Message..."), "<CTL>M", gaim_gtkdialogs_im, 0, "<StockItem>", GAIM_STOCK_IM }, |
8940 | 2331 { N_("/Buddies/Join a _Chat..."), "<CTL>C", gaim_gtk_blist_joinchat_show, 0, "<StockItem>", GAIM_STOCK_CHAT }, |
9714 | 2332 { N_("/Buddies/Get User _Info..."), "<CTL>I", gaim_gtkdialogs_info, 0, "<StockItem>", GAIM_STOCK_INFO }, |
2333 { N_("/Buddies/View User _Log..."), "<CTL>L", gaim_gtkdialogs_log, 0, NULL }, | |
5228 | 2334 { "/Buddies/sep1", NULL, NULL, 0, "<Separator>" }, |
11025 | 2335 { N_("/Buddies/Show _Offline Buddies"), NULL, gaim_gtk_blist_edit_mode_cb, 1, "<CheckItem>"}, |
2336 { N_("/Buddies/Show _Empty Groups"), NULL, gaim_gtk_blist_show_empty_groups_cb, 1, "<CheckItem>"}, | |
11796 | 2337 { N_("/Buddies/Show Buddy _Details"), NULL, gaim_gtk_blist_buddy_details_cb, 1, "<CheckItem>"}, |
11798
01c3eec6ea3c
[gaim-migrate @ 14089]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11797
diff
changeset
|
2338 { N_("/Buddies/Sort Buddies"), NULL, NULL, 0, "<Branch>" }, |
11796 | 2339 { "/Buddies/sep2", NULL, NULL, 0, "<Separator>" }, |
7853 | 2340 { N_("/Buddies/_Add Buddy..."), "<CTL>B", gaim_gtk_blist_add_buddy_cb, 0, "<StockItem>", GTK_STOCK_ADD }, |
2341 { N_("/Buddies/Add C_hat..."), NULL, gaim_gtk_blist_add_chat_cb, 0, "<StockItem>", GTK_STOCK_ADD }, | |
2342 { N_("/Buddies/Add _Group..."), NULL, gaim_blist_request_add_group, 0, "<StockItem>", GTK_STOCK_ADD }, | |
11796 | 2343 { "/Buddies/sep3", NULL, NULL, 0, "<Separator>" }, |
7620 | 2344 { N_("/Buddies/_Quit"), "<CTL>Q", gaim_core_quit, 0, "<StockItem>", GTK_STOCK_QUIT }, |
5228 | 2345 |
8470
9949b752d1ab
[gaim-migrate @ 9203]
Christian Hammond <chipx86@chipx86.com>
parents:
8444
diff
changeset
|
2346 /* Tools */ |
5228 | 2347 { N_("/_Tools"), NULL, NULL, 0, "<Branch>" }, |
2348 { N_("/Tools/Buddy _Pounce"), NULL, NULL, 0, "<Branch>" }, | |
8845 | 2349 { N_("/Tools/Account Ac_tions"), NULL, NULL, 0, "<Branch>" }, |
5228 | 2350 { "/Tools/sep1", NULL, NULL, 0, "<Separator>" }, |
7620 | 2351 { N_("/Tools/A_ccounts"), "<CTL>A", gaim_gtk_accounts_window_show, 0, "<StockItem>", GAIM_STOCK_ACCOUNTS }, |
10325 | 2352 { N_("/Tools/Pr_eferences"), "<CTL>P", gaim_gtk_prefs_show, 0, "<StockItem>", GTK_STOCK_PREFERENCES }, |
11740 | 2353 { N_("/Tools/P_lugins"), NULL, gaim_gtk_plugin_dialog_show, 0, NULL }, |
10694 | 2354 { N_("/Tools/Pr_ivacy"), NULL, gaim_gtk_privacy_dialog_show, 0, "<StockItem>", GTK_STOCK_DIALOG_ERROR }, |
10019
8cc6f0bfa215
[gaim-migrate @ 10943]
Luke Schierer <lschiere@pidgin.im>
parents:
10018
diff
changeset
|
2355 { N_("/Tools/_File Transfers"), "<CTL>T", gaim_show_xfer_dialog, 0, "<StockItem>", GAIM_STOCK_FILE_TRANSFER }, |
10694 | 2356 { N_("/Tools/R_oom List"), NULL, gaim_gtk_roomlist_dialog_show, 0, "<StockItem>", GTK_STOCK_INDEX }, |
10325 | 2357 { "/Tools/sep2", NULL, NULL, 0, "<Separator>" }, |
10074 | 2358 { N_("/Tools/Mute _Sounds"), "<CTL>S", gaim_gtk_blist_mute_sounds_cb, 0, "<CheckItem>"}, |
7620 | 2359 { N_("/Tools/View System _Log"), NULL, gtk_blist_show_systemlog_cb, 0, NULL }, |
5228 | 2360 |
2361 /* Help */ | |
2362 { N_("/_Help"), NULL, NULL, 0, "<Branch>" }, | |
2363 { N_("/Help/Online _Help"), "F1", gtk_blist_show_onlinehelp_cb, 0, "<StockItem>", GTK_STOCK_HELP }, | |
7620 | 2364 { N_("/Help/_Debug Window"), NULL, toggle_debug, 0, NULL }, |
9753 | 2365 { N_("/Help/_About"), NULL, gaim_gtkdialogs_about, 0, "<StockItem>", GAIM_STOCK_ABOUT }, |
5228 | 2366 }; |
2367 | |
2368 /********************************************************* | |
2369 * Private Utility functions * | |
2370 *********************************************************/ | |
2371 | |
5234 | 2372 static char *gaim_get_tooltip_text(GaimBlistNode *node) |
5228 | 2373 { |
10475 | 2374 GString *str = g_string_new(""); |
5237 | 2375 GaimPlugin *prpl; |
2376 GaimPluginProtocolInfo *prpl_info = NULL; | |
10475 | 2377 char *tmp; |
2378 | |
2379 if (GAIM_BLIST_NODE_IS_CHAT(node)) | |
2380 { | |
2381 GaimChat *chat; | |
2382 GList *cur; | |
5274 | 2383 struct proto_chat_entry *pce; |
10475 | 2384 char *name, *value; |
2385 | |
2386 chat = (GaimChat *)node; | |
7956 | 2387 prpl = gaim_find_prpl(gaim_account_get_protocol_id(chat->account)); |
5274 | 2388 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
2389 | |
10475 | 2390 tmp = g_markup_escape_text(gaim_chat_get_name(chat), -1); |
2391 g_string_append_printf(str, "<span size='larger' weight='bold'>%s</span>", tmp); | |
2392 g_free(tmp); | |
2393 | |
2394 if (g_list_length(gaim_connections_get_all()) > 1) | |
2395 { | |
2396 tmp = g_markup_escape_text(chat->account->username, -1); | |
2397 g_string_append_printf(str, _("\n<b>Account:</b> %s"), tmp); | |
2398 g_free(tmp); | |
2399 } | |
2400 | |
9959 | 2401 if (prpl_info->chat_info != NULL) |
10475 | 2402 cur = prpl_info->chat_info(chat->account->gc); |
2403 else | |
2404 cur = NULL; | |
2405 | |
2406 while (cur != NULL) | |
2407 { | |
2408 pce = cur->data; | |
2409 | |
2410 if (!pce->secret && (!pce->required && | |
2411 g_hash_table_lookup(chat->components, pce->identifier) == NULL)) | |
2412 { | |
2413 tmp = gaim_text_strip_mnemonic(pce->label); | |
2414 name = g_markup_escape_text(tmp, -1); | |
2415 g_free(tmp); | |
2416 value = g_markup_escape_text(g_hash_table_lookup( | |
2417 chat->components, pce->identifier), -1); | |
10924
7a82d86ab44a
[gaim-migrate @ 12695]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10918
diff
changeset
|
2418 g_string_append_printf(str, "\n<b>%s</b> %s", |
7a82d86ab44a
[gaim-migrate @ 12695]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10918
diff
changeset
|
2419 name ? name : "", |
7a82d86ab44a
[gaim-migrate @ 12695]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10918
diff
changeset
|
2420 value ? value : ""); |
10475 | 2421 g_free(name); |
8020 | 2422 g_free(value); |
2423 } | |
10475 | 2424 |
5274 | 2425 g_free(pce); |
10475 | 2426 cur = g_list_remove(cur, pce); |
5274 | 2427 } |
10475 | 2428 } |
2429 else if (GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_BUDDY(node)) | |
2430 { | |
2431 GaimContact *c; | |
7620 | 2432 GaimBuddy *b; |
9944 | 2433 GaimPresence *presence; |
10475 | 2434 char *tmp; |
9944 | 2435 gboolean idle; |
10567 | 2436 time_t idle_secs, signon; |
10475 | 2437 |
2438 if (GAIM_BLIST_NODE_IS_CONTACT(node)) | |
2439 { | |
2440 c = (GaimContact *)node; | |
2441 b = gaim_contact_get_priority_buddy(c); | |
2442 } | |
2443 else | |
2444 { | |
7620 | 2445 b = (GaimBuddy *)node; |
10475 | 2446 c = gaim_buddy_get_contact(b); |
7620 | 2447 } |
2448 | |
7956 | 2449 prpl = gaim_find_prpl(gaim_account_get_protocol_id(b->account)); |
5234 | 2450 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
2451 | |
10475 | 2452 presence = gaim_buddy_get_presence(b); |
2453 | |
2454 /* Buddy Name */ | |
2455 tmp = g_markup_escape_text(gaim_buddy_get_name(b), -1); | |
2456 g_string_append_printf(str, "<span size='larger' weight='bold'>%s</span>", tmp); | |
2457 g_free(tmp); | |
2458 | |
2459 /* Account */ | |
2460 if (g_list_length(gaim_connections_get_all()) > 1) | |
2461 { | |
2462 tmp = g_markup_escape_text(gaim_account_get_username( | |
2463 gaim_buddy_get_account(b)), -1); | |
2464 g_string_append_printf(str, _("\n<b>Account:</b> %s"), tmp); | |
2465 g_free(tmp); | |
2466 } | |
2467 | |
2468 /* Contact Alias */ | |
2469 if (GAIM_BLIST_NODE_IS_CONTACT(node) && | |
10499 | 2470 (c->alias != NULL)) |
10475 | 2471 { |
10499 | 2472 tmp = g_markup_escape_text(c->alias, -1); |
10475 | 2473 g_string_append_printf(str, _("\n<b>Contact Alias:</b> %s"), tmp); |
2474 g_free(tmp); | |
2475 } | |
2476 | |
2477 /* Alias */ | |
2478 if ((b->alias != NULL) && (b->alias[0] != '\0')) | |
2479 { | |
2480 tmp = g_markup_escape_text(b->alias, -1); | |
2481 g_string_append_printf(str, _("\n<b>Alias:</b> %s"), tmp); | |
2482 g_free(tmp); | |
2483 } | |
2484 | |
2485 /* Nickname/Server Alias */ | |
2486 if (b->server_alias != NULL) | |
2487 { | |
2488 tmp = g_markup_escape_text(b->server_alias, -1); | |
2489 g_string_append_printf(str, _("\n<b>Nickname:</b> %s"), tmp); | |
2490 g_free(tmp); | |
2491 } | |
2492 | |
2493 /* Logged In */ | |
10567 | 2494 signon = gaim_presence_get_login_time(presence); |
10992
2bda44d66641
[gaim-migrate @ 12830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10968
diff
changeset
|
2495 if (GAIM_BUDDY_IS_ONLINE(b) && signon > 0) |
10475 | 2496 { |
10567 | 2497 tmp = gaim_str_seconds_to_string(time(NULL) - signon); |
10475 | 2498 g_string_append_printf(str, _("\n<b>Logged In:</b> %s"), tmp); |
2499 g_free(tmp); | |
2500 } | |
2501 | |
2502 /* Idle */ | |
2503 idle = gaim_presence_is_idle(presence); | |
2504 if (idle) | |
2505 { | |
2506 idle_secs = gaim_presence_get_idle_time(presence); | |
2507 if (idle_secs > 0) | |
2508 { | |
2509 tmp = gaim_str_seconds_to_string(time(NULL) - idle_secs); | |
2510 g_string_append_printf(str, _("\n<b>Idle:</b> %s"), tmp); | |
2511 g_free(tmp); | |
2512 } | |
2513 } | |
2514 | |
2515 /* Last Seen */ | |
11437
1c20849fc716
[gaim-migrate @ 13674]
Richard Laager <rlaager@wiktel.com>
parents:
11436
diff
changeset
|
2516 if ((!GAIM_BUDDY_IS_ONLINE(b) && b->present != GAIM_BUDDY_SIGNING_OFF) || |
1c20849fc716
[gaim-migrate @ 13674]
Richard Laager <rlaager@wiktel.com>
parents:
11436
diff
changeset
|
2517 b->present == GAIM_BUDDY_SIGNING_ON) |
10475 | 2518 { |
11023 | 2519 struct _gaim_gtk_blist_node *gtknode = ((GaimBlistNode *)c)->ui_data; |
2520 GaimBlistNode *bnode; | |
2521 int lastseen = 0; | |
2522 | |
2523 if (!gtknode->contact_expanded || GAIM_BLIST_NODE_IS_CONTACT(node)) | |
2524 { | |
11437
1c20849fc716
[gaim-migrate @ 13674]
Richard Laager <rlaager@wiktel.com>
parents:
11436
diff
changeset
|
2525 /* We're either looking at a buddy for a collapsed contact or |
11438
5451fe2d89c0
[gaim-migrate @ 13675]
Richard Laager <rlaager@wiktel.com>
parents:
11437
diff
changeset
|
2526 * an expanded contact itself so we show the most recent |
11023 | 2527 * (largest) last_seen time for any of the buddies under |
2528 * the contact. */ | |
2529 for (bnode = ((GaimBlistNode *)c)->child ; bnode != NULL ; bnode = bnode->next) | |
2530 { | |
2531 int value = gaim_blist_node_get_int(bnode, "last_seen"); | |
2532 if (value > lastseen) | |
2533 lastseen = value; | |
2534 } | |
2535 } | |
2536 else | |
2537 { | |
2538 /* We're dealing with a buddy under an expanded contact, | |
2539 * so we show the last_seen time for the buddy. */ | |
2540 lastseen = gaim_blist_node_get_int(&b->node, "last_seen"); | |
2541 } | |
2542 | |
10475 | 2543 if (lastseen > 0) |
2544 { | |
2545 tmp = gaim_str_seconds_to_string(time(NULL) - lastseen); | |
2546 g_string_append_printf(str, _("\n<b>Last Seen:</b> %s ago"), tmp); | |
2547 g_free(tmp); | |
5234 | 2548 } |
2549 } | |
2550 | |
10475 | 2551 |
2552 /* Offline? */ | |
2553 if (!GAIM_BUDDY_IS_ONLINE(b)) { | |
2554 g_string_append_printf(str, _("\n<b>Status:</b> Offline")); | |
2555 } | |
10992
2bda44d66641
[gaim-migrate @ 12830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10968
diff
changeset
|
2556 |
2bda44d66641
[gaim-migrate @ 12830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10968
diff
changeset
|
2557 if (prpl_info && prpl_info->tooltip_text) |
10475 | 2558 { |
2559 /* Additional text from the PRPL */ | |
2560 const char *end; | |
2561 tmp = prpl_info->tooltip_text(b); | |
2562 | |
2563 if (tmp && !g_utf8_validate(tmp, -1, &end)) | |
2564 { | |
2565 char *new = g_strndup(tmp, g_utf8_pointer_to_offset(tmp, end)); | |
2566 g_free(tmp); | |
2567 tmp = new; | |
2568 } | |
2569 | |
11634 | 2570 if (tmp != NULL) |
2571 g_string_append(str, tmp); | |
10476 | 2572 g_free(tmp); |
10475 | 2573 } |
2574 | |
2575 /* These are Easter Eggs. Patches to remove them will be rejected. */ | |
2576 if (!g_ascii_strcasecmp(b->name, "robflynn")) | |
2577 g_string_append(str, _("\n<b>Description:</b> Spooky")); | |
2578 if (!g_ascii_strcasecmp(b->name, "seanegn")) | |
2579 g_string_append(str, _("\n<b>Status:</b> Awesome")); | |
2580 if (!g_ascii_strcasecmp(b->name, "chipx86")) | |
2581 g_string_append(str, _("\n<b>Status:</b> Rockin'")); | |
5234 | 2582 } |
10475 | 2583 |
8824 | 2584 gaim_signal_emit(gaim_gtk_blist_get_handle(), |
10477 | 2585 "drawing-tooltip", node, str); |
10475 | 2586 |
2587 return g_string_free(str, FALSE); | |
5228 | 2588 } |
2589 | |
7620 | 2590 struct _emblem_data { |
9954 | 2591 const char *filename; |
7620 | 2592 int x; |
2593 int y; | |
2594 }; | |
2595 | |
9944 | 2596 GdkPixbuf * |
2597 gaim_gtk_blist_get_status_icon(GaimBlistNode *node, GaimStatusIconSize size) | |
5228 | 2598 { |
7620 | 2599 GdkPixbuf *scale, *status = NULL; |
2600 int i, scalesize = 30; | |
2601 char *filename; | |
5228 | 2602 const char *protoname = NULL; |
7620 | 2603 struct _gaim_gtk_blist_node *gtknode = node->ui_data; |
2604 struct _emblem_data emblems[4] = {{NULL, 15, 15}, {NULL, 0, 15}, | |
2605 {NULL, 0, 0}, {NULL, 15, 0}}; | |
9944 | 2606 GaimPresence *presence = NULL; |
7620 | 2607 GaimBuddy *buddy = NULL; |
2608 GaimChat *chat = NULL; | |
2609 | |
2610 if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
2611 if(!gtknode->contact_expanded) | |
2612 buddy = gaim_contact_get_priority_buddy((GaimContact*)node); | |
2613 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
2614 buddy = (GaimBuddy*)node; | |
2615 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) { | |
2616 chat = (GaimChat*)node; | |
2617 } else { | |
5228 | 2618 return NULL; |
5234 | 2619 } |
2620 | |
7620 | 2621 if(buddy || chat) { |
2622 GaimAccount *account; | |
2623 GaimPlugin *prpl; | |
2624 GaimPluginProtocolInfo *prpl_info; | |
2625 | |
2626 if(buddy) | |
2627 account = buddy->account; | |
2628 else | |
2629 account = chat->account; | |
2630 | |
7956 | 2631 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); |
7620 | 2632 if(!prpl) |
2633 return NULL; | |
2634 | |
2635 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
2636 | |
2637 if(prpl_info && prpl_info->list_icon) { | |
2638 protoname = prpl_info->list_icon(account, buddy); | |
2639 } | |
2640 if(prpl_info && prpl_info->list_emblems && buddy) { | |
2641 if(buddy->present != GAIM_BUDDY_SIGNING_OFF) | |
2642 prpl_info->list_emblems(buddy, &emblems[0].filename, | |
2643 &emblems[1].filename, &emblems[2].filename, | |
2644 &emblems[3].filename); | |
2645 } | |
5234 | 2646 } |
5228 | 2647 |
7620 | 2648 if(size == GAIM_STATUS_ICON_SMALL) { |
5228 | 2649 scalesize = 15; |
7620 | 2650 /* So that only the se icon will composite */ |
2651 emblems[1].filename = emblems[2].filename = emblems[3].filename = NULL; | |
5228 | 2652 } |
2653 | |
7620 | 2654 if(buddy && buddy->present == GAIM_BUDDY_SIGNING_ON) { |
2655 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "login.png", NULL); | |
2656 } else if(buddy && buddy->present == GAIM_BUDDY_SIGNING_OFF) { | |
2657 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "logout.png", NULL); | |
2658 } else if(buddy || chat) { | |
5228 | 2659 char *image = g_strdup_printf("%s.png", protoname); |
2660 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
2661 g_free(image); | |
7620 | 2662 } else { |
2663 /* gaim dude */ | |
2664 filename = g_build_filename(DATADIR, "pixmaps", "gaim.png", NULL); | |
5228 | 2665 } |
7620 | 2666 |
2667 status = gdk_pixbuf_new_from_file(filename, NULL); | |
2668 g_free(filename); | |
2669 | |
2670 if(!status) | |
2671 return NULL; | |
2672 | |
2673 scale = gdk_pixbuf_scale_simple(status, scalesize, scalesize, | |
2674 GDK_INTERP_BILINEAR); | |
2675 g_object_unref(status); | |
2676 | |
2677 for(i=0; i<4; i++) { | |
2678 if(emblems[i].filename) { | |
2679 GdkPixbuf *emblem; | |
2680 char *image = g_strdup_printf("%s.png", emblems[i].filename); | |
2681 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", image, NULL); | |
2682 g_free(image); | |
2683 emblem = gdk_pixbuf_new_from_file(filename, NULL); | |
2684 g_free(filename); | |
2685 if(emblem) { | |
2686 if(i == 0 && size == GAIM_STATUS_ICON_SMALL) { | |
2687 gdk_pixbuf_composite(emblem, | |
2688 scale, 5, 5, | |
2689 10, 10, | |
2690 5, 5, | |
2691 .6, .6, | |
2692 GDK_INTERP_BILINEAR, | |
2693 255); | |
2694 } else { | |
2695 gdk_pixbuf_composite(emblem, | |
2696 scale, emblems[i].x, emblems[i].y, | |
2697 15, 15, | |
2698 emblems[i].x, emblems[i].y, | |
2699 1, 1, | |
2700 GDK_INTERP_BILINEAR, | |
2701 255); | |
2702 } | |
2703 g_object_unref(emblem); | |
2704 } | |
5228 | 2705 } |
2706 } | |
7620 | 2707 |
2708 if(buddy) { | |
9944 | 2709 presence = gaim_buddy_get_presence(buddy); |
2710 | |
2711 if (!GAIM_BUDDY_IS_ONLINE(buddy)) | |
7620 | 2712 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE); |
10118 | 2713 else if (gaim_presence_is_idle(presence)) |
9944 | 2714 { |
7620 | 2715 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.25, FALSE); |
9944 | 2716 } |
11111
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2717 |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2718 if (!gaim_privacy_check(buddy->account, gaim_buddy_get_name(buddy))) |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2719 { |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2720 GdkPixbuf *emblem; |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2721 char *filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "blocked.png", NULL); |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2722 |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2723 emblem = gdk_pixbuf_new_from_file(filename, NULL); |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2724 g_free(filename); |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2725 |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2726 if (emblem) |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2727 { |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2728 gdk_pixbuf_composite(emblem, scale, |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2729 0, 0, scalesize, scalesize, |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2730 0, 0, |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2731 (double)scalesize / gdk_pixbuf_get_width(emblem), |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2732 (double)scalesize / gdk_pixbuf_get_height(emblem), |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2733 GDK_INTERP_BILINEAR, |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2734 224); |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2735 g_object_unref(emblem); |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2736 } |
f03dce7ea408
[gaim-migrate @ 13163]
Richard Laager <rlaager@wiktel.com>
parents:
11059
diff
changeset
|
2737 } |
5228 | 2738 } |
7620 | 2739 |
5228 | 2740 return scale; |
2741 } | |
2742 | |
7620 | 2743 static gchar *gaim_gtk_blist_get_name_markup(GaimBuddy *b, gboolean selected) |
5228 | 2744 { |
7620 | 2745 const char *name; |
2746 char *esc, *text = NULL; | |
5228 | 2747 GaimPlugin *prpl; |
2748 GaimPluginProtocolInfo *prpl_info = NULL; | |
7620 | 2749 GaimContact *contact; |
9944 | 2750 GaimPresence *presence; |
7620 | 2751 struct _gaim_gtk_blist_node *gtkcontactnode = NULL; |
11257 | 2752 char *idletime = NULL, *statustext = NULL; |
5228 | 2753 time_t t; |
7620 | 2754 /* XXX Clean up this crap */ |
2755 | |
2756 contact = (GaimContact*)((GaimBlistNode*)b)->parent; | |
2757 if(contact) | |
2758 gtkcontactnode = ((GaimBlistNode*)contact)->ui_data; | |
2759 | |
2760 if(gtkcontactnode && !gtkcontactnode->contact_expanded && contact->alias) | |
2761 name = contact->alias; | |
2762 else | |
9620 | 2763 name = gaim_buddy_get_alias(b); |
7620 | 2764 esc = g_markup_escape_text(name, strlen(name)); |
2765 | |
7956 | 2766 prpl = gaim_find_prpl(gaim_account_get_protocol_id(b->account)); |
5228 | 2767 |
2768 if (prpl != NULL) | |
2769 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
2770 | |
9944 | 2771 presence = gaim_buddy_get_presence(b); |
2772 | |
7620 | 2773 if (!gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")) { |
9944 | 2774 |
10118 | 2775 if ((gaim_presence_is_idle(presence) || !GAIM_BUDDY_IS_ONLINE(b)) && !selected) |
9944 | 2776 { |
10118 | 2777 text = g_strdup_printf("<span color='%s'>%s</span>", |
2778 dim_grey(), esc); | |
5228 | 2779 g_free(esc); |
2780 return text; | |
7620 | 2781 } |
9944 | 2782 else |
5228 | 2783 return esc; |
2784 } | |
2785 | |
8122
36674144c510
[gaim-migrate @ 8826]
Christian Hammond <chipx86@chipx86.com>
parents:
8113
diff
changeset
|
2786 if (prpl_info && prpl_info->status_text && b->account->gc) { |
5228 | 2787 char *tmp = prpl_info->status_text(b); |
2788 const char *end; | |
2789 | |
2790 if(tmp && !g_utf8_validate(tmp, -1, &end)) { | |
2791 char *new = g_strndup(tmp, | |
2792 g_utf8_pointer_to_offset(tmp, end)); | |
2793 g_free(tmp); | |
2794 tmp = new; | |
2795 } | |
2796 | |
10288 | 2797 #if !GTK_CHECK_VERSION(2,6,0) |
5228 | 2798 if(tmp) { |
2799 char buf[32]; | |
2800 char *c = tmp; | |
2801 int length = 0, vis=0; | |
2802 gboolean inside = FALSE; | |
2803 g_strdelimit(tmp, "\n", ' '); | |
7620 | 2804 gaim_str_strip_cr(tmp); |
5228 | 2805 |
2806 while(*c && vis < 20) { | |
2807 if(*c == '&') | |
2808 inside = TRUE; | |
2809 else if(*c == ';') | |
2810 inside = FALSE; | |
2811 if(!inside) | |
2812 vis++; | |
7620 | 2813 c = g_utf8_next_char(c); /* this is fun */ |
5228 | 2814 } |
2815 | |
7620 | 2816 length = c - tmp; |
2817 | |
5228 | 2818 if(vis == 20) |
2819 g_snprintf(buf, sizeof(buf), "%%.%ds...", length); | |
2820 else | |
2821 g_snprintf(buf, sizeof(buf), "%%s "); | |
2822 | |
2823 statustext = g_strdup_printf(buf, tmp); | |
2824 | |
2825 g_free(tmp); | |
2826 } | |
10288 | 2827 #else |
2828 statustext = tmp; | |
2829 #endif | |
5228 | 2830 } |
2831 | |
10351 | 2832 if (gaim_presence_is_idle(presence)) { |
9944 | 2833 time_t idle_secs = gaim_presence_get_idle_time(presence); |
2834 | |
10351 | 2835 if (idle_secs > 0) { |
9944 | 2836 int ihrs, imin; |
2837 | |
2838 time(&t); | |
2839 ihrs = (t - idle_secs) / 3600; | |
2840 imin = ((t - idle_secs) / 60) % 60; | |
2841 | |
2842 if (ihrs) | |
11134
f78e7e982cf4
[gaim-migrate @ 13195]
Richard Laager <rlaager@wiktel.com>
parents:
11111
diff
changeset
|
2843 idletime = g_strdup_printf(_("Idle (%dh %02dm) "), ihrs, imin); |
9944 | 2844 else |
2845 idletime = g_strdup_printf(_("Idle (%dm) "), imin); | |
2846 } | |
5228 | 2847 else |
9944 | 2848 idletime = g_strdup(_("Idle ")); |
5228 | 2849 } |
2850 | |
2851 if(!GAIM_BUDDY_IS_ONLINE(b) && !statustext) | |
7620 | 2852 statustext = g_strdup(_("Offline ")); |
2853 | |
10118 | 2854 if (gaim_presence_is_idle(presence) && !selected) { |
2855 text = g_strdup_printf("<span color='%s'>%s</span>\n" | |
11257 | 2856 "<span color='%s' size='smaller'>%s%s%s</span>", |
10118 | 2857 dim_grey(), esc, dim_grey(), |
5228 | 2858 statustext != NULL ? statustext : "", |
11134
f78e7e982cf4
[gaim-migrate @ 13195]
Richard Laager <rlaager@wiktel.com>
parents:
11111
diff
changeset
|
2859 (idletime != NULL && statustext != NULL) ? " - " : "", |
11257 | 2860 idletime != NULL ? idletime : ""); |
2861 } else if (statustext == NULL && idletime == NULL && GAIM_BUDDY_IS_ONLINE(b)) { | |
5228 | 2862 text = g_strdup(esc); |
2863 } else { | |
10118 | 2864 if (selected) |
2865 text = g_strdup_printf("%s\n" | |
11257 | 2866 "<span size='smaller'>%s%s%s</span>", esc, |
10118 | 2867 statustext != NULL ? statustext : "", |
11134
f78e7e982cf4
[gaim-migrate @ 13195]
Richard Laager <rlaager@wiktel.com>
parents:
11111
diff
changeset
|
2868 (idletime != NULL && statustext != NULL) ? " - " : "", |
11257 | 2869 idletime != NULL ? idletime : ""); |
10118 | 2870 else |
2871 text = g_strdup_printf("%s\n" | |
11257 | 2872 "<span color='%s' size='smaller'>%s%s%s</span>", esc, |
10144 | 2873 dim_grey(), |
10118 | 2874 statustext != NULL ? statustext : "", |
11134
f78e7e982cf4
[gaim-migrate @ 13195]
Richard Laager <rlaager@wiktel.com>
parents:
11111
diff
changeset
|
2875 (idletime != NULL && statustext != NULL) ? " - " : "", |
11257 | 2876 idletime != NULL ? idletime : ""); |
5228 | 2877 } |
2878 if (idletime) | |
2879 g_free(idletime); | |
2880 if (statustext) | |
2881 g_free(statustext); | |
2882 if (esc) | |
2883 g_free(esc); | |
2884 | |
2885 return text; | |
2886 } | |
2887 | |
2888 static void gaim_gtk_blist_restore_position() | |
2889 { | |
7620 | 2890 int blist_x, blist_y, blist_width, blist_height; |
2891 | |
2892 blist_width = gaim_prefs_get_int("/gaim/gtk/blist/width"); | |
2893 | |
2894 /* if the window exists, is hidden, we're saving positions, and the | |
2895 * position is sane... */ | |
2896 if (gtkblist && gtkblist->window && | |
2897 !GTK_WIDGET_VISIBLE(gtkblist->window) && blist_width != 0) { | |
2898 | |
2899 blist_x = gaim_prefs_get_int("/gaim/gtk/blist/x"); | |
2900 blist_y = gaim_prefs_get_int("/gaim/gtk/blist/y"); | |
2901 blist_height = gaim_prefs_get_int("/gaim/gtk/blist/height"); | |
2902 | |
5228 | 2903 /* ...check position is on screen... */ |
7620 | 2904 if (blist_x >= gdk_screen_width()) |
2905 blist_x = gdk_screen_width() - 100; | |
2906 else if (blist_x + blist_width < 0) | |
2907 blist_x = 100; | |
2908 | |
2909 if (blist_y >= gdk_screen_height()) | |
2910 blist_y = gdk_screen_height() - 100; | |
2911 else if (blist_y + blist_height < 0) | |
2912 blist_y = 100; | |
2913 | |
5228 | 2914 /* ...and move it back. */ |
7620 | 2915 gtk_window_move(GTK_WINDOW(gtkblist->window), blist_x, blist_y); |
2916 gtk_window_resize(GTK_WINDOW(gtkblist->window), blist_width, blist_height); | |
5228 | 2917 } |
2918 } | |
2919 | |
7620 | 2920 static gboolean gaim_gtk_blist_refresh_timer(GaimBuddyList *list) |
5228 | 2921 { |
7620 | 2922 GaimBlistNode *gnode, *cnode; |
2923 | |
2924 for(gnode = list->root; gnode; gnode = gnode->next) { | |
2925 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
5234 | 2926 continue; |
7620 | 2927 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
2928 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
9944 | 2929 GaimBuddy *buddy; |
2930 | |
2931 buddy = gaim_contact_get_priority_buddy((GaimContact*)cnode); | |
10012 | 2932 |
2933 if (buddy && | |
2934 gaim_presence_is_idle(gaim_buddy_get_presence(buddy))) | |
9944 | 2935 gaim_gtk_blist_update(list, cnode); |
7620 | 2936 } |
5228 | 2937 } |
2938 } | |
2939 | |
2940 /* keep on going */ | |
2941 return TRUE; | |
2942 } | |
2943 | |
7620 | 2944 static void gaim_gtk_blist_hide_node(GaimBuddyList *list, GaimBlistNode *node) |
5260 | 2945 { |
2946 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; | |
2947 GtkTreeIter iter; | |
2948 | |
2949 if (!gtknode || !gtknode->row || !gtkblist) | |
2950 return; | |
2951 | |
2952 if(gtkblist->selected_node == node) | |
2953 gtkblist->selected_node = NULL; | |
2954 | |
2955 if (get_iter_from_node(node, &iter)) { | |
2956 gtk_tree_store_remove(gtkblist->treemodel, &iter); | |
7620 | 2957 if(GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_BUDDY(node) |
2958 || GAIM_BLIST_NODE_IS_CHAT(node)) { | |
5260 | 2959 gaim_gtk_blist_update(list, node->parent); |
2960 } | |
2961 } | |
2962 gtk_tree_row_reference_free(gtknode->row); | |
2963 gtknode->row = NULL; | |
2964 } | |
2965 | |
10352 | 2966 static const char *require_connection[] = |
7620 | 2967 { |
10352 | 2968 N_("/Buddies/New Instant Message..."), |
2969 N_("/Buddies/Join a Chat..."), | |
2970 N_("/Buddies/Get User Info..."), | |
2971 N_("/Buddies/Add Buddy..."), | |
2972 N_("/Buddies/Add Chat..."), | |
2973 N_("/Buddies/Add Group..."), | |
2974 }; | |
2975 | |
10357 | 2976 static const int require_connection_size = sizeof(require_connection) |
2977 / sizeof(*require_connection); | |
10352 | 2978 |
2979 /** | |
2980 * Rebuild dynamic menus and make menu items sensitive/insensitive | |
2981 * where appropriate. | |
2982 */ | |
2983 static void | |
2984 update_menu_bar(GaimGtkBuddyList *gtkblist) | |
2985 { | |
8937 | 2986 GtkWidget *widget; |
10352 | 2987 gboolean sensitive; |
2988 int i; | |
2989 | |
2990 g_return_if_fail(gtkblist != NULL); | |
8259
4f9f68ab8770
[gaim-migrate @ 8982]
Christian Hammond <chipx86@chipx86.com>
parents:
8254
diff
changeset
|
2991 |
7620 | 2992 gaim_gtk_blist_update_protocol_actions(); |
8235 | 2993 gaim_gtkpounce_menu_build(gtkblist->bpmenu); |
8937 | 2994 |
10352 | 2995 sensitive = (gaim_connections_get_all() != NULL); |
2996 | |
10357 | 2997 for (i = 0; i < require_connection_size; i++) |
10352 | 2998 { |
2999 widget = gtk_item_factory_get_widget(gtkblist->ift, require_connection[i]); | |
3000 gtk_widget_set_sensitive(widget, sensitive); | |
3001 } | |
3002 | |
8940 | 3003 widget = gtk_item_factory_get_widget(gtkblist->ift, N_("/Buddies/Join a Chat...")); |
3004 gtk_widget_set_sensitive(widget, gaim_gtk_blist_joinchat_is_showable()); | |
3005 | |
8937 | 3006 widget = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Room List")); |
8939 | 3007 gtk_widget_set_sensitive(widget, gaim_gtk_roomlist_is_showable()); |
8938 | 3008 |
3009 widget = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Privacy")); | |
3010 gtk_widget_set_sensitive(widget, gaim_gtk_privacy_is_showable()); | |
7620 | 3011 } |
3012 | |
10352 | 3013 static void |
3014 sign_on_off_cb(GaimConnection *gc, GaimBuddyList *blist) | |
3015 { | |
3016 GaimGtkBuddyList *gtkblist = GAIM_GTK_BLIST(blist); | |
3017 | |
3018 update_menu_bar(gtkblist); | |
3019 } | |
8986 | 3020 |
3021 static void | |
3022 plugin_changed_cb(GaimPlugin *p, gpointer *data) | |
3023 { | |
3024 gaim_gtk_blist_update_plugin_actions(); | |
3025 } | |
3026 | |
5228 | 3027 /********************************************************************************** |
3028 * Public API Functions * | |
3029 **********************************************************************************/ | |
9774 | 3030 |
7620 | 3031 static void gaim_gtk_blist_new_list(GaimBuddyList *blist) |
5228 | 3032 { |
7620 | 3033 GaimGtkBuddyList *gtkblist; |
3034 | |
3035 gtkblist = g_new0(GaimGtkBuddyList, 1); | |
3036 blist->ui_data = gtkblist; | |
5228 | 3037 } |
3038 | |
5256 | 3039 static void gaim_gtk_blist_new_node(GaimBlistNode *node) |
3040 { | |
3041 node->ui_data = g_new0(struct _gaim_gtk_blist_node, 1); | |
3042 } | |
3043 | |
11018 | 3044 gboolean gaim_gtk_blist_node_is_contact_expanded(GaimBlistNode *node) |
3045 { | |
3046 if GAIM_BLIST_NODE_IS_BUDDY(node) | |
3047 node = node->parent; | |
3048 | |
3049 g_return_val_if_fail(GAIM_BLIST_NODE_IS_CONTACT(node), FALSE); | |
3050 | |
3051 return ((struct _gaim_gtk_blist_node *)node->ui_data)->contact_expanded; | |
3052 } | |
3053 | |
5228 | 3054 void gaim_gtk_blist_update_columns() |
3055 { | |
3056 if(!gtkblist) | |
3057 return; | |
3058 | |
7620 | 3059 if (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")) { |
5228 | 3060 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, TRUE); |
3061 gtk_tree_view_column_set_visible(gtkblist->idle_column, FALSE); | |
3062 } else { | |
10351 | 3063 gtk_tree_view_column_set_visible(gtkblist->idle_column, TRUE); |
5228 | 3064 gtk_tree_view_column_set_visible(gtkblist->buddy_icon_column, FALSE); |
3065 } | |
3066 } | |
3067 | |
10433 | 3068 enum { |
3069 DRAG_BUDDY, | |
3070 DRAG_ROW, | |
3071 DRAG_VCARD, | |
3072 DRAG_TEXT, | |
3073 DRAG_URI, | |
3074 NUM_TARGETS | |
3075 }; | |
5228 | 3076 |
3077 static char * | |
3078 item_factory_translate_func (const char *path, gpointer func_data) | |
3079 { | |
7620 | 3080 return _((char *)path); |
5228 | 3081 } |
3082 | |
5422 | 3083 void gaim_gtk_blist_setup_sort_methods() |
3084 { | |
11798
01c3eec6ea3c
[gaim-migrate @ 14089]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11797
diff
changeset
|
3085 gaim_gtk_blist_sort_method_reg("none", _("Manually"), sort_method_none); |
7620 | 3086 #if GTK_CHECK_VERSION(2,2,1) |
11798
01c3eec6ea3c
[gaim-migrate @ 14089]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11797
diff
changeset
|
3087 gaim_gtk_blist_sort_method_reg("alphabetical", _("Alphabetically"), sort_method_alphabetical); |
7620 | 3088 gaim_gtk_blist_sort_method_reg("status", _("By status"), sort_method_status); |
3089 gaim_gtk_blist_sort_method_reg("log_size", _("By log size"), sort_method_log); | |
3090 #endif | |
3091 gaim_gtk_blist_sort_method_set(gaim_prefs_get_string("/gaim/gtk/blist/sort_type")); | |
3092 } | |
3093 | |
10433 | 3094 static void _prefs_change_redo_list() |
3095 { | |
7620 | 3096 redo_buddy_list(gaim_get_blist(), TRUE); |
3097 } | |
3098 | |
3099 static void _prefs_change_sort_method(const char *pref_name, GaimPrefType type, | |
10433 | 3100 gpointer val, gpointer data) |
3101 { | |
7620 | 3102 if(!strcmp(pref_name, "/gaim/gtk/blist/sort_type")) |
3103 gaim_gtk_blist_sort_method_set(val); | |
3104 } | |
3105 | |
10433 | 3106 /* |
3107 * "This is so dead sexy." | |
3108 * "Two thumbs up." | |
3109 * "Best movie of the year." | |
3110 * | |
3111 * This is the function that handles CTRL+F searching in the buddy list. | |
3112 * It finds the top-most buddy/group/chat/whatever containing the | |
3113 * entered string. | |
3114 * | |
3115 * It's somewhat ineffecient, because we strip all the HTML from the | |
3116 * "name" column of the buddy list (because the GtkTreeModel does not | |
3117 * contain the screen name in a non-markedup format). But the alternative | |
3118 * is to add an extra column to the GtkTreeModel. And this function is | |
3119 * used rarely, so it shouldn't matter TOO much. | |
3120 */ | |
3121 static gboolean | |
3122 _search_func(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer search_data) | |
3123 { | |
10435 | 3124 gboolean result; |
10433 | 3125 gchar *enteredstring; |
10439 | 3126 gchar *withmarkup; |
10433 | 3127 gchar *nomarkup; |
11490 | 3128 gchar *normalized; |
10435 | 3129 |
3130 gtk_tree_model_get(model, iter, column, &withmarkup, -1); | |
10433 | 3131 |
11490 | 3132 enteredstring = g_utf8_casefold(gaim_normalize(NULL, key), -1); |
10433 | 3133 nomarkup = gaim_markup_strip_html(withmarkup); |
11490 | 3134 normalized = g_utf8_casefold(gaim_normalize(NULL, nomarkup), -1); |
10433 | 3135 |
3136 result = (g_strstr_len(normalized, strlen(normalized), enteredstring) == NULL); | |
3137 | |
10439 | 3138 g_free(withmarkup); |
10433 | 3139 g_free(enteredstring); |
3140 g_free(nomarkup); | |
11490 | 3141 g_free(normalized); |
10433 | 3142 |
3143 return result; | |
3144 } | |
3145 | |
7620 | 3146 static void gaim_gtk_blist_show(GaimBuddyList *list) |
5228 | 3147 { |
10087 | 3148 void *handle; |
5228 | 3149 GtkCellRenderer *rend; |
3150 GtkTreeViewColumn *column; | |
10178
96a850ab30c8
[gaim-migrate @ 11293]
Christian Hammond <chipx86@chipx86.com>
parents:
10144
diff
changeset
|
3151 GtkWidget *menu; |
5228 | 3152 GtkWidget *sw; |
3153 GtkAccelGroup *accel_group; | |
3154 GtkTreeSelection *selection; | |
9556 | 3155 GtkTargetEntry dte[] = {{"GAIM_BLIST_NODE", GTK_TARGET_SAME_APP, DRAG_ROW}, |
8089 | 3156 {"application/x-im-contact", 0, DRAG_BUDDY}, |
9495 | 3157 {"text/x-vcard", 0, DRAG_VCARD }, |
9525 | 3158 {"text/uri-list", 0, DRAG_URI}, |
3159 {"text/plain", 0, DRAG_TEXT}}; | |
9556 | 3160 GtkTargetEntry ste[] = {{"GAIM_BLIST_NODE", GTK_TARGET_SAME_APP, DRAG_ROW}, |
3161 {"application/x-im-contact", 0, DRAG_BUDDY}, | |
3162 {"text/x-vcard", 0, DRAG_VCARD }}; | |
5228 | 3163 if (gtkblist && gtkblist->window) { |
11709
cae2fb7e8594
[gaim-migrate @ 14000]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11692
diff
changeset
|
3164 if (gaim_prefs_get_bool("/gaim/gtk/blist/list_visible")) |
10282 | 3165 gtk_widget_show(gtkblist->window); |
5228 | 3166 return; |
3167 } | |
3168 | |
3169 gtkblist = GAIM_GTK_BLIST(list); | |
3170 | |
3171 gtkblist->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
3172 gtk_window_set_role(GTK_WINDOW(gtkblist->window), "buddy_list"); | |
9746 | 3173 gtk_window_set_title(GTK_WINDOW(gtkblist->window), _("Buddy List")); |
5228 | 3174 |
3175 gtkblist->vbox = gtk_vbox_new(FALSE, 0); | |
10178
96a850ab30c8
[gaim-migrate @ 11293]
Christian Hammond <chipx86@chipx86.com>
parents:
10144
diff
changeset
|
3176 gtk_widget_show(gtkblist->vbox); |
5228 | 3177 gtk_container_add(GTK_CONTAINER(gtkblist->window), gtkblist->vbox); |
3178 | |
11709
cae2fb7e8594
[gaim-migrate @ 14000]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11692
diff
changeset
|
3179 g_signal_connect_after(G_OBJECT(gtkblist->window), "delete_event", G_CALLBACK(gtk_blist_delete_cb), NULL); |
5228 | 3180 g_signal_connect(G_OBJECT(gtkblist->window), "configure_event", G_CALLBACK(gtk_blist_configure_cb), NULL); |
3181 g_signal_connect(G_OBJECT(gtkblist->window), "visibility_notify_event", G_CALLBACK(gtk_blist_visibility_cb), NULL); | |
3182 gtk_widget_add_events(gtkblist->window, GDK_VISIBILITY_NOTIFY_MASK); | |
3183 | |
3184 /******************************* Menu bar *************************************/ | |
3185 accel_group = gtk_accel_group_new(); | |
3186 gtk_window_add_accel_group(GTK_WINDOW (gtkblist->window), accel_group); | |
3187 g_object_unref(accel_group); | |
5427 | 3188 gtkblist->ift = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GaimMain>", accel_group); |
9811 | 3189 gtk_item_factory_set_translate_func(gtkblist->ift, |
3190 item_factory_translate_func, | |
3191 NULL, NULL); | |
5427 | 3192 gtk_item_factory_create_items(gtkblist->ift, sizeof(blist_menu) / sizeof(*blist_menu), |
9811 | 3193 blist_menu, NULL); |
7620 | 3194 gaim_gtk_load_accels(); |
3195 g_signal_connect(G_OBJECT(accel_group), "accel-changed", | |
3196 G_CALLBACK(gaim_gtk_save_accels_cb), NULL); | |
10178
96a850ab30c8
[gaim-migrate @ 11293]
Christian Hammond <chipx86@chipx86.com>
parents:
10144
diff
changeset
|
3197 menu = gtk_item_factory_get_widget(gtkblist->ift, "<GaimMain>"); |
96a850ab30c8
[gaim-migrate @ 11293]
Christian Hammond <chipx86@chipx86.com>
parents:
10144
diff
changeset
|
3198 gtk_widget_show(menu); |
96a850ab30c8
[gaim-migrate @ 11293]
Christian Hammond <chipx86@chipx86.com>
parents:
10144
diff
changeset
|
3199 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), menu, FALSE, FALSE, 0); |
5228 | 3200 |
5427 | 3201 gtkblist->bpmenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Buddy Pounce")); |
8844 | 3202 protomenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Account Actions")); |
10352 | 3203 |
5228 | 3204 /****************************** GtkTreeView **********************************/ |
3205 sw = gtk_scrolled_window_new(NULL,NULL); | |
10178
96a850ab30c8
[gaim-migrate @ 11293]
Christian Hammond <chipx86@chipx86.com>
parents:
10144
diff
changeset
|
3206 gtk_widget_show(sw); |
5228 | 3207 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); |
3208 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
3209 | |
7620 | 3210 gtkblist->treemodel = gtk_tree_store_new(BLIST_COLUMNS, |
11494 | 3211 GDK_TYPE_PIXBUF, G_TYPE_BOOLEAN, |
11257 | 3212 G_TYPE_STRING, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_POINTER); |
5228 | 3213 |
3214 gtkblist->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(gtkblist->treemodel)); | |
10178
96a850ab30c8
[gaim-migrate @ 11293]
Christian Hammond <chipx86@chipx86.com>
parents:
10144
diff
changeset
|
3215 gtk_widget_show(gtkblist->treeview); |
9176 | 3216 gtk_widget_set_name(gtkblist->treeview, "gaim_gtkblist_treeview"); |
5228 | 3217 |
3218 /* Set up selection stuff */ | |
3219 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)); | |
3220 g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(gaim_gtk_blist_selection_changed), NULL); | |
3221 | |
3222 /* Set up dnd */ | |
7650 | 3223 gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(gtkblist->treeview), |
9811 | 3224 GDK_BUTTON1_MASK, ste, 3, |
3225 GDK_ACTION_COPY); | |
7650 | 3226 gtk_tree_view_enable_model_drag_dest(GTK_TREE_VIEW(gtkblist->treeview), |
9811 | 3227 dte, 5, |
3228 GDK_ACTION_COPY | GDK_ACTION_MOVE); | |
7636 | 3229 |
10544 | 3230 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-received", G_CALLBACK(gaim_gtk_blist_drag_data_rcv_cb), NULL); |
5228 | 3231 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-data-get", G_CALLBACK(gaim_gtk_blist_drag_data_get_cb), NULL); |
11059
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
3232 #ifdef _WIN32 |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
3233 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-begin", G_CALLBACK(gaim_gtk_blist_drag_begin), NULL); |
c86d423df757
[gaim-migrate @ 13012]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11038
diff
changeset
|
3234 #endif |
10433 | 3235 |
10354 | 3236 g_signal_connect(G_OBJECT(gtkblist->treeview), "drag-motion", G_CALLBACK(gaim_gtk_blist_drag_motion_cb), NULL); |
5228 | 3237 |
3238 /* Tooltips */ | |
3239 g_signal_connect(G_OBJECT(gtkblist->treeview), "motion-notify-event", G_CALLBACK(gaim_gtk_blist_motion_cb), NULL); | |
3240 g_signal_connect(G_OBJECT(gtkblist->treeview), "leave-notify-event", G_CALLBACK(gaim_gtk_blist_leave_cb), NULL); | |
3241 | |
3242 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(gtkblist->treeview), FALSE); | |
3243 | |
11016 | 3244 gtkblist->text_column = column = gtk_tree_view_column_new (); |
5228 | 3245 |
3246 rend = gtk_cell_renderer_pixbuf_new(); | |
9811 | 3247 gtk_tree_view_column_pack_start(column, rend, FALSE); |
3248 gtk_tree_view_column_set_attributes(column, rend, | |
3249 "pixbuf", STATUS_ICON_COLUMN, | |
3250 "visible", STATUS_ICON_VISIBLE_COLUMN, | |
3251 NULL); | |
5228 | 3252 g_object_set(rend, "xalign", 0.0, "ypad", 0, NULL); |
3253 | |
11016 | 3254 gtkblist->text_rend = rend = gtk_cell_renderer_text_new(); |
5228 | 3255 gtk_tree_view_column_pack_start (column, rend, TRUE); |
9811 | 3256 gtk_tree_view_column_set_attributes(column, rend, |
3257 "markup", NAME_COLUMN, | |
3258 NULL); | |
11016 | 3259 g_signal_connect(G_OBJECT(rend), "edited", G_CALLBACK(gtk_blist_renderer_edited_cb), NULL); |
5228 | 3260 g_object_set(rend, "ypad", 0, "yalign", 0.5, NULL); |
10285 | 3261 #if GTK_CHECK_VERSION(2,6,0) |
3262 gtk_tree_view_column_set_expand (column, TRUE); | |
10501 | 3263 g_object_set(rend, "ellipsize", PANGO_ELLIPSIZE_END, NULL); |
10285 | 3264 #endif |
5228 | 3265 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), column); |
3266 | |
3267 rend = gtk_cell_renderer_text_new(); | |
10351 | 3268 gtkblist->idle_column = gtk_tree_view_column_new_with_attributes("Idle", rend, "markup", IDLE_COLUMN, NULL); |
3269 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->idle_column); | |
5228 | 3270 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); |
3271 | |
3272 rend = gtk_cell_renderer_pixbuf_new(); | |
3273 gtkblist->buddy_icon_column = gtk_tree_view_column_new_with_attributes("Buddy Icon", rend, "pixbuf", BUDDY_ICON_COLUMN, NULL); | |
3274 g_object_set(rend, "xalign", 1.0, "ypad", 0, NULL); | |
3275 gtk_tree_view_append_column(GTK_TREE_VIEW(gtkblist->treeview), gtkblist->buddy_icon_column); | |
3276 | |
3277 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-activated", G_CALLBACK(gtk_blist_row_activated_cb), NULL); | |
3278 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-expanded", G_CALLBACK(gtk_blist_row_expanded_cb), NULL); | |
3279 g_signal_connect(G_OBJECT(gtkblist->treeview), "row-collapsed", G_CALLBACK(gtk_blist_row_collapsed_cb), NULL); | |
3280 g_signal_connect(G_OBJECT(gtkblist->treeview), "button-press-event", G_CALLBACK(gtk_blist_button_press_cb), NULL); | |
7620 | 3281 g_signal_connect(G_OBJECT(gtkblist->treeview), "key-press-event", G_CALLBACK(gtk_blist_key_press_cb), NULL); |
8143 | 3282 g_signal_connect(G_OBJECT(gtkblist->treeview), "popup-menu", G_CALLBACK(gaim_gtk_blist_popup_menu_cb), NULL); |
5228 | 3283 |
5419 | 3284 /* Enable CTRL+F searching */ |
3285 gtk_tree_view_set_search_column(GTK_TREE_VIEW(gtkblist->treeview), NAME_COLUMN); | |
10433 | 3286 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(gtkblist->treeview), _search_func, NULL, NULL); |
5419 | 3287 |
5228 | 3288 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), sw, TRUE, TRUE, 0); |
3289 gtk_container_add(GTK_CONTAINER(sw), gtkblist->treeview); | |
3290 gaim_gtk_blist_update_columns(); | |
3291 | |
11732 | 3292 /* TODO: functionize this */ |
3293 { | |
11768
a9e9b76905b4
[gaim-migrate @ 14059]
Gary Kramlich <grim@reaperworld.com>
parents:
11745
diff
changeset
|
3294 #if 0 |
11732 | 3295 GList *accounts, *l; |
11768
a9e9b76905b4
[gaim-migrate @ 14059]
Gary Kramlich <grim@reaperworld.com>
parents:
11745
diff
changeset
|
3296 #endif |
11732 | 3297 /* Set up some per account status boxes */ |
3298 gtkblist->statusboxbox = gtk_vbox_new(FALSE, 0); | |
3299 gtkblist->statusboxes = NULL; | |
3300 #if 0 | |
3301 for (l = accounts = gaim_accounts_get_all_active(); l; l = l->next) { | |
3302 GtkWidget *statusbox = gtk_gaim_status_box_new_with_account(l->data); | |
3303 gtkblist->statusboxes = g_list_append(gtkblist->statusboxes, statusbox); | |
3304 gtk_box_pack_start(GTK_BOX(gtkblist->statusboxbox), statusbox, FALSE, TRUE, 0); | |
3305 gtk_widget_show(statusbox); | |
3306 } | |
3307 g_list_free(accounts); | |
3308 #endif | |
3309 gtk_widget_show(gtkblist->statusboxbox); | |
3310 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtkblist->statusboxbox, FALSE, TRUE, 0); | |
3311 | |
3312 gtkblist->statusbox = gtk_gaim_status_box_new(); | |
3313 | |
3314 gtk_widget_show(gtkblist->statusbox); | |
3315 gtk_box_pack_start(GTK_BOX(gtkblist->vbox), gtkblist->statusbox, FALSE, TRUE, 0); | |
3316 | |
3317 } | |
10178
96a850ab30c8
[gaim-migrate @ 11293]
Christian Hammond <chipx86@chipx86.com>
parents:
10144
diff
changeset
|
3318 |
5228 | 3319 /* set the Show Offline Buddies option. must be done |
3320 * after the treeview or faceprint gets mad. -Robot101 | |
3321 */ | |
5427 | 3322 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Buddies/Show Offline Buddies"))), |
7620 | 3323 gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies")); |
5427 | 3324 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Buddies/Show Empty Groups"))), |
7620 | 3325 gaim_prefs_get_bool("/gaim/gtk/blist/show_empty_groups")); |
10074 | 3326 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Tools/Mute Sounds"))), |
3327 gaim_prefs_get_bool("/gaim/gtk/sound/mute")); | |
11796 | 3328 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Buddies/Show Buddy Details"))), |
3329 gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")); | |
10074 | 3330 if(!strcmp(gaim_prefs_get_string("/gaim/gtk/sound/method"), "none")) |
11494 | 3331 gtk_widget_set_sensitive(gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Mute Sounds")), FALSE); |
5228 | 3332 |
10353 | 3333 /* Update some dynamic things */ |
3334 update_menu_bar(gtkblist); | |
3335 gaim_gtk_blist_update_plugin_actions(); | |
11796 | 3336 gaim_gtk_blist_update_sort_methods(); |
10353 | 3337 |
5228 | 3338 /* OK... let's show this bad boy. */ |
11709
cae2fb7e8594
[gaim-migrate @ 14000]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11692
diff
changeset
|
3339 if (gaim_prefs_get_bool("/gaim/gtk/blist/list_visible")) { |
10282 | 3340 gaim_gtk_blist_refresh(list); |
3341 gaim_gtk_blist_restore_position(); | |
3342 gtk_widget_show(gtkblist->window); | |
3343 } | |
5228 | 3344 |
3345 /* start the refresh timer */ | |
10351 | 3346 gtkblist->refresh_timer = g_timeout_add(30000, (GSourceFunc)gaim_gtk_blist_refresh_timer, list); |
10353 | 3347 |
10087 | 3348 handle = gaim_gtk_blist_get_handle(); |
3349 | |
7620 | 3350 /* things that affect how buddies are displayed */ |
10087 | 3351 gaim_prefs_connect_callback(handle, "/gaim/gtk/blist/show_buddy_icons", |
3352 _prefs_change_redo_list, NULL); | |
3353 gaim_prefs_connect_callback(handle, "/gaim/gtk/blist/show_empty_groups", | |
3354 _prefs_change_redo_list, NULL); | |
3355 gaim_prefs_connect_callback(handle, "/gaim/gtk/blist/show_offline_buddies", | |
3356 _prefs_change_redo_list, NULL); | |
7620 | 3357 |
3358 /* sorting */ | |
10087 | 3359 gaim_prefs_connect_callback(handle, "/gaim/gtk/blist/sort_type", |
3360 _prefs_change_sort_method, NULL); | |
7620 | 3361 |
3362 /* things that affect what columns are displayed */ | |
10087 | 3363 gaim_prefs_connect_callback(handle, "/gaim/gtk/blist/show_buddy_icons", |
3364 gaim_gtk_blist_update_columns, NULL); | |
8259
4f9f68ab8770
[gaim-migrate @ 8982]
Christian Hammond <chipx86@chipx86.com>
parents:
8254
diff
changeset
|
3365 |
10074 | 3366 /* menus */ |
10087 | 3367 gaim_prefs_connect_callback(handle, "/gaim/gtk/sound/mute", |
3368 gaim_gtk_blist_mute_pref_cb, NULL); | |
3369 gaim_prefs_connect_callback(handle, "/gaim/gtk/sound/method", | |
3370 gaim_gtk_blist_sound_method_pref_cb, NULL); | |
10074 | 3371 |
8259
4f9f68ab8770
[gaim-migrate @ 8982]
Christian Hammond <chipx86@chipx86.com>
parents:
8254
diff
changeset
|
3372 /* Setup some gaim signal handlers. */ |
8937 | 3373 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", |
3374 gtkblist, GAIM_CALLBACK(sign_on_off_cb), list); | |
3375 gaim_signal_connect(gaim_connections_get_handle(), "signed-off", | |
3376 gtkblist, GAIM_CALLBACK(sign_on_off_cb), list); | |
8815 | 3377 |
8986 | 3378 gaim_signal_connect(gaim_plugins_get_handle(), "plugin-load", |
3379 gtkblist, GAIM_CALLBACK(plugin_changed_cb), NULL); | |
3380 gaim_signal_connect(gaim_plugins_get_handle(), "plugin-unload", | |
3381 gtkblist, GAIM_CALLBACK(plugin_changed_cb), NULL); | |
3382 | |
8815 | 3383 /* emit our created signal */ |
10087 | 3384 gaim_signal_emit(handle, "gtkblist-created", list); |
5228 | 3385 } |
3386 | |
7620 | 3387 /* XXX: does this need fixing? */ |
3388 static void redo_buddy_list(GaimBuddyList *list, gboolean remove) | |
5228 | 3389 { |
7620 | 3390 GaimBlistNode *gnode, *cnode, *bnode; |
3391 | |
3392 for(gnode = list->root; gnode; gnode = gnode->next) { | |
3393 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
5234 | 3394 continue; |
7620 | 3395 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
3396 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
3397 if(remove) | |
3398 gaim_gtk_blist_hide_node(list, cnode); | |
3399 | |
3400 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
3401 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
3402 continue; | |
3403 if(remove) | |
3404 gaim_gtk_blist_hide_node(list, bnode); | |
3405 gaim_gtk_blist_update(list, bnode); | |
3406 } | |
3407 | |
3408 gaim_gtk_blist_update(list, cnode); | |
3409 } else if(GAIM_BLIST_NODE_IS_CHAT(cnode)) { | |
3410 if(remove) | |
3411 gaim_gtk_blist_hide_node(list, cnode); | |
3412 | |
3413 gaim_gtk_blist_update(list, cnode); | |
3414 } | |
5228 | 3415 } |
7620 | 3416 gaim_gtk_blist_update(list, gnode); |
5228 | 3417 } |
3418 } | |
3419 | |
7620 | 3420 void gaim_gtk_blist_refresh(GaimBuddyList *list) |
5422 | 3421 { |
3422 redo_buddy_list(list, FALSE); | |
3423 } | |
3424 | |
5297 | 3425 void |
3426 gaim_gtk_blist_update_refresh_timeout() | |
3427 { | |
7620 | 3428 GaimBuddyList *blist; |
3429 GaimGtkBuddyList *gtkblist; | |
5297 | 3430 |
3431 blist = gaim_get_blist(); | |
3432 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); | |
3433 | |
10351 | 3434 gtkblist->refresh_timer = g_timeout_add(30000,(GSourceFunc)gaim_gtk_blist_refresh_timer, blist); |
5297 | 3435 } |
3436 | |
5256 | 3437 static gboolean get_iter_from_node(GaimBlistNode *node, GtkTreeIter *iter) { |
3438 struct _gaim_gtk_blist_node *gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; | |
3439 GtkTreePath *path; | |
5228 | 3440 |
5263 | 3441 if (!gtknode) { |
3442 return FALSE; | |
3443 } | |
3444 | |
3445 if (!gtkblist) { | |
10006 | 3446 gaim_debug_error("gtkblist", "get_iter_from_node was called, but we don't seem to have a blist\n"); |
5263 | 3447 return FALSE; |
3448 } | |
3449 | |
3450 if (!gtknode->row) | |
5228 | 3451 return FALSE; |
11494 | 3452 |
5228 | 3453 |
5256 | 3454 if ((path = gtk_tree_row_reference_get_path(gtknode->row)) == NULL) |
5228 | 3455 return FALSE; |
11016 | 3456 |
5256 | 3457 if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), iter, path)) { |
3458 gtk_tree_path_free(path); | |
3459 return FALSE; | |
3460 } | |
3461 gtk_tree_path_free(path); | |
3462 return TRUE; | |
5228 | 3463 } |
3464 | |
7620 | 3465 static void gaim_gtk_blist_remove(GaimBuddyList *list, GaimBlistNode *node) |
5228 | 3466 { |
10222 | 3467 gaim_request_close_with_handle(node); |
3468 | |
5260 | 3469 gaim_gtk_blist_hide_node(list, node); |
5228 | 3470 |
7620 | 3471 if(node->parent) |
3472 gaim_gtk_blist_update(list, node->parent); | |
3473 | |
10504 | 3474 /* There's something I don't understand here - Ethan */ |
3475 /* Ethan said that back in 2003, but this g_free has been left commented | |
3476 * out ever since. I can't find any reason at all why this is bad and | |
3477 * valgrind found several reasons why it's good. If this causes problems | |
3478 * comment it out again. Stu */ | |
10510 | 3479 /* Of course it still causes problems - this breaks dragging buddies into |
10515 | 3480 * contacts, the dragged buddy mysteriously 'disappears'. Stu. */ |
3481 /* I think it's fixed now. Stu. */ | |
10504 | 3482 g_free(node->ui_data); |
10515 | 3483 node->ui_data = NULL; |
5228 | 3484 } |
3485 | |
3486 static gboolean do_selection_changed(GaimBlistNode *new_selection) | |
3487 { | |
5254 | 3488 GaimBlistNode *old_selection = NULL; |
5228 | 3489 |
5254 | 3490 /* test for gtkblist because crazy timeout means we can be called after the blist is gone */ |
3491 if (gtkblist && new_selection != gtkblist->selected_node) { | |
3492 old_selection = gtkblist->selected_node; | |
5228 | 3493 gtkblist->selected_node = new_selection; |
3494 if(new_selection) | |
3495 gaim_gtk_blist_update(NULL, new_selection); | |
3496 if(old_selection) | |
3497 gaim_gtk_blist_update(NULL, old_selection); | |
3498 } | |
3499 | |
3500 return FALSE; | |
3501 } | |
3502 | |
3503 static void gaim_gtk_blist_selection_changed(GtkTreeSelection *selection, gpointer data) | |
3504 { | |
3505 GaimBlistNode *new_selection = NULL; | |
3506 GtkTreeIter iter; | |
3507 | |
3508 if(gtk_tree_selection_get_selected(selection, NULL, &iter)){ | |
3509 gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, | |
3510 NODE_COLUMN, &new_selection, -1); | |
3511 } | |
5254 | 3512 |
5228 | 3513 /* we set this up as a timeout, otherwise the blist flickers */ |
3514 g_timeout_add(0, (GSourceFunc)do_selection_changed, new_selection); | |
3515 } | |
3516 | |
8252 | 3517 static gboolean insert_node(GaimBuddyList *list, GaimBlistNode *node, GtkTreeIter *iter) |
7620 | 3518 { |
3519 GtkTreeIter parent_iter, cur, *curptr = NULL; | |
3520 struct _gaim_gtk_blist_node *gtknode = node->ui_data; | |
5256 | 3521 GtkTreePath *newpath; |
7620 | 3522 |
10515 | 3523 if(!iter) |
8252 | 3524 return FALSE; |
7620 | 3525 |
3526 if(node->parent && !get_iter_from_node(node->parent, &parent_iter)) | |
8252 | 3527 return FALSE; |
7620 | 3528 |
3529 if(get_iter_from_node(node, &cur)) | |
3530 curptr = &cur; | |
3531 | |
3532 if(GAIM_BLIST_NODE_IS_CONTACT(node) || GAIM_BLIST_NODE_IS_CHAT(node)) { | |
3533 *iter = current_sort_method->func(node, list, parent_iter, curptr); | |
3534 } else { | |
3535 *iter = sort_method_none(node, list, parent_iter, curptr); | |
5228 | 3536 } |
3537 | |
10515 | 3538 if(gtknode != NULL) { |
3539 gtk_tree_row_reference_free(gtknode->row); | |
3540 } else { | |
3541 gaim_gtk_blist_new_node(node); | |
3542 gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; | |
3543 } | |
3544 | |
7620 | 3545 newpath = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), |
3546 iter); | |
3547 gtknode->row = | |
3548 gtk_tree_row_reference_new(GTK_TREE_MODEL(gtkblist->treemodel), | |
3549 newpath); | |
11494 | 3550 |
5256 | 3551 gtk_tree_path_free(newpath); |
3552 | |
5228 | 3553 gtk_tree_store_set(gtkblist->treemodel, iter, |
3554 NODE_COLUMN, node, | |
3555 -1); | |
7620 | 3556 |
3557 if(node->parent) { | |
3558 GtkTreePath *expand = NULL; | |
3559 struct _gaim_gtk_blist_node *gtkparentnode = node->parent->ui_data; | |
3560 | |
3561 if(GAIM_BLIST_NODE_IS_GROUP(node->parent)) { | |
7693 | 3562 if(!gaim_blist_node_get_bool(node->parent, "collapsed")) |
7620 | 3563 expand = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &parent_iter); |
3564 } else if(GAIM_BLIST_NODE_IS_CONTACT(node->parent) && | |
3565 gtkparentnode->contact_expanded) { | |
3566 expand = gtk_tree_model_get_path(GTK_TREE_MODEL(gtkblist->treemodel), &parent_iter); | |
3567 } | |
3568 if(expand) { | |
7693 | 3569 gtk_tree_view_expand_row(GTK_TREE_VIEW(gtkblist->treeview), expand, FALSE); |
7620 | 3570 gtk_tree_path_free(expand); |
3571 } | |
3572 } | |
3573 | |
8252 | 3574 return TRUE; |
5228 | 3575 } |
3576 | |
7620 | 3577 static void gaim_gtk_blist_update_group(GaimBuddyList *list, GaimBlistNode *node) |
3578 { | |
3579 GaimGroup *group; | |
8203 | 3580 int count; |
7620 | 3581 |
3582 g_return_if_fail(GAIM_BLIST_NODE_IS_GROUP(node)); | |
3583 | |
3584 group = (GaimGroup*)node; | |
3585 | |
8203 | 3586 if(gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies")) |
3587 count = gaim_blist_get_group_size(group, FALSE); | |
3588 else | |
3589 count = gaim_blist_get_group_online_count(group); | |
3590 if(gaim_prefs_get_bool("/gaim/gtk/blist/show_empty_groups") || count > 0) { | |
7620 | 3591 char *mark, *esc; |
3592 GtkTreeIter iter; | |
3593 | |
8252 | 3594 if(!insert_node(list, node, &iter)) |
3595 return; | |
7620 | 3596 |
3597 esc = g_markup_escape_text(group->name, -1); | |
8945 | 3598 mark = g_strdup_printf("<span weight='bold'>%s</span> (%d/%d)", |
3599 esc, gaim_blist_get_group_online_count(group), | |
3600 gaim_blist_get_group_size(group, FALSE)); | |
7620 | 3601 g_free(esc); |
3602 | |
3603 gtk_tree_store_set(gtkblist->treemodel, &iter, | |
3604 STATUS_ICON_COLUMN, NULL, | |
3605 STATUS_ICON_VISIBLE_COLUMN, FALSE, | |
3606 NAME_COLUMN, mark, | |
3607 NODE_COLUMN, node, | |
3608 -1); | |
3609 g_free(mark); | |
3610 } else { | |
3611 gaim_gtk_blist_hide_node(list, node); | |
3612 } | |
3613 } | |
3614 | |
3615 static void buddy_node(GaimBuddy *buddy, GtkTreeIter *iter, GaimBlistNode *node) | |
5228 | 3616 { |
9944 | 3617 GaimPresence *presence; |
7620 | 3618 GdkPixbuf *status, *avatar; |
3619 char *mark; | |
11257 | 3620 char *idle = NULL; |
7620 | 3621 gboolean selected = (gtkblist->selected_node == node); |
3622 | |
9944 | 3623 presence = gaim_buddy_get_presence(buddy); |
3624 | |
7620 | 3625 status = gaim_gtk_blist_get_status_icon((GaimBlistNode*)buddy, |
3626 (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons") | |
3627 ? GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL)); | |
3628 | |
10482 | 3629 avatar = gaim_gtk_blist_get_buddy_icon((GaimBlistNode *)buddy, TRUE, TRUE); |
7620 | 3630 mark = gaim_gtk_blist_get_name_markup(buddy, selected); |
3631 | |
9944 | 3632 if (gaim_presence_is_idle(presence)) |
3633 { | |
3634 time_t idle_secs = gaim_presence_get_idle_time(presence); | |
3635 | |
3636 if (idle_secs > 0) | |
3637 { | |
3638 time_t t; | |
3639 int ihrs, imin; | |
3640 time(&t); | |
3641 ihrs = (t - idle_secs) / 3600; | |
3642 imin = ((t - idle_secs) / 60) % 60; | |
3643 | |
3644 if (ihrs > 0) | |
3645 idle = g_strdup_printf("(%d:%02d)", ihrs, imin); | |
3646 else | |
3647 idle = g_strdup_printf("(%d)", imin); | |
3648 } | |
7620 | 3649 } |
3650 | |
10118 | 3651 if (gaim_presence_is_idle(presence)) |
9944 | 3652 { |
3653 if (idle && !selected) { | |
10118 | 3654 char *i2 = g_strdup_printf("<span color='%s'>%s</span>", |
3655 dim_grey(), idle); | |
7620 | 3656 g_free(idle); |
3657 idle = i2; | |
5228 | 3658 } |
7620 | 3659 } |
3660 | |
3661 gtk_tree_store_set(gtkblist->treemodel, iter, | |
3662 STATUS_ICON_COLUMN, status, | |
3663 STATUS_ICON_VISIBLE_COLUMN, TRUE, | |
3664 NAME_COLUMN, mark, | |
3665 IDLE_COLUMN, idle, | |
3666 BUDDY_ICON_COLUMN, avatar, | |
3667 -1); | |
3668 | |
3669 g_free(mark); | |
3670 if(idle) | |
3671 g_free(idle); | |
3672 if(status) | |
3673 g_object_unref(status); | |
3674 if(avatar) | |
3675 g_object_unref(avatar); | |
3676 } | |
3677 | |
3678 static void gaim_gtk_blist_update_contact(GaimBuddyList *list, GaimBlistNode *node) | |
3679 { | |
3680 GaimContact *contact; | |
3681 GaimBuddy *buddy; | |
3682 struct _gaim_gtk_blist_node *gtknode; | |
3683 | |
3684 g_return_if_fail(GAIM_BLIST_NODE_IS_CONTACT(node)); | |
3685 | |
3686 /* First things first, update the group */ | |
3687 gaim_gtk_blist_update_group(list, node->parent); | |
3688 | |
3689 contact = (GaimContact*)node; | |
3690 buddy = gaim_contact_get_priority_buddy(contact); | |
3691 | |
11577 | 3692 if (buddy && gaim_account_is_connected(buddy->account) && |
3693 (gaim_presence_is_online(buddy->presence) || | |
11434
f191b5bc199b
[gaim-migrate @ 13671]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11338
diff
changeset
|
3694 buddy->present == GAIM_BUDDY_SIGNING_OFF || |
11577 | 3695 gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies") || |
10006 | 3696 gaim_blist_node_get_bool(node, "show_offline"))) |
3697 { | |
7620 | 3698 GtkTreeIter iter; |
3699 | |
8252 | 3700 if(!insert_node(list, node, &iter)) |
3701 return; | |
7620 | 3702 |
10515 | 3703 gtknode = (struct _gaim_gtk_blist_node *)node->ui_data; |
3704 | |
7620 | 3705 if(gtknode->contact_expanded) { |
3706 GdkPixbuf *status; | |
5228 | 3707 char *mark; |
3708 | |
7620 | 3709 status = gaim_gtk_blist_get_status_icon(node, |
3710 (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons") ? | |
3711 GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL)); | |
3712 | |
3713 mark = g_markup_escape_text(gaim_contact_get_alias(contact), -1); | |
3714 | |
5228 | 3715 gtk_tree_store_set(gtkblist->treemodel, &iter, |
7620 | 3716 STATUS_ICON_COLUMN, status, |
3717 STATUS_ICON_VISIBLE_COLUMN, TRUE, | |
5228 | 3718 NAME_COLUMN, mark, |
7620 | 3719 IDLE_COLUMN, NULL, |
3720 BUDDY_ICON_COLUMN, NULL, | |
5228 | 3721 -1); |
3722 g_free(mark); | |
7620 | 3723 if(status) |
3724 g_object_unref(status); | |
3725 } else { | |
3726 buddy_node(buddy, &iter, node); | |
5228 | 3727 } |
7620 | 3728 } else { |
3729 gaim_gtk_blist_hide_node(list, node); | |
5228 | 3730 } |
7620 | 3731 } |
3732 | |
3733 static void gaim_gtk_blist_update_buddy(GaimBuddyList *list, GaimBlistNode *node) | |
3734 { | |
3735 GaimContact *contact; | |
3736 GaimBuddy *buddy; | |
3737 struct _gaim_gtk_blist_node *gtkparentnode; | |
3738 | |
3739 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
3740 | |
3741 buddy = (GaimBuddy*)node; | |
3742 contact = (GaimContact*)node->parent; | |
3743 | |
11624 | 3744 if (contact == NULL) |
3745 return; | |
3746 | |
7620 | 3747 /* First things first, update the contact */ |
3748 gaim_gtk_blist_update_contact(list, node->parent); | |
3749 | |
10918 | 3750 gtkparentnode = (struct _gaim_gtk_blist_node *)node->parent->ui_data; |
3751 | |
10006 | 3752 if (gtkparentnode->contact_expanded && |
3753 (gaim_presence_is_online(buddy->presence) || | |
11434
f191b5bc199b
[gaim-migrate @ 13671]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11338
diff
changeset
|
3754 buddy->present == GAIM_BUDDY_SIGNING_OFF || |
7620 | 3755 (gaim_account_is_connected(buddy->account) && |
10006 | 3756 gaim_prefs_get_bool("/gaim/gtk/blist/show_offline_buddies")) || |
3757 gaim_blist_node_get_bool(node->parent, "show_offline"))) | |
3758 { | |
7620 | 3759 GtkTreeIter iter; |
3760 | |
10006 | 3761 if (!insert_node(list, node, &iter)) |
8252 | 3762 return; |
3763 | |
7620 | 3764 buddy_node(buddy, &iter, node); |
3765 | |
3766 } else { | |
3767 gaim_gtk_blist_hide_node(list, node); | |
3768 } | |
3769 | |
3770 } | |
3771 | |
3772 static void gaim_gtk_blist_update_chat(GaimBuddyList *list, GaimBlistNode *node) | |
3773 { | |
3774 GaimChat *chat; | |
3775 | |
3776 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node)); | |
3777 | |
3778 /* First things first, update the group */ | |
3779 gaim_gtk_blist_update_group(list, node->parent); | |
3780 | |
3781 chat = (GaimChat*)node; | |
3782 | |
3783 if(gaim_account_is_connected(chat->account)) { | |
3784 GtkTreeIter iter; | |
5234 | 3785 GdkPixbuf *status; |
7620 | 3786 char *mark; |
3787 | |
8252 | 3788 if(!insert_node(list, node, &iter)) |
3789 return; | |
5234 | 3790 |
3791 status = gaim_gtk_blist_get_status_icon(node, | |
7620 | 3792 (gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons") ? |
3793 GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL)); | |
3794 | |
3795 mark = g_markup_escape_text(gaim_chat_get_name(chat), -1); | |
5234 | 3796 |
3797 gtk_tree_store_set(gtkblist->treemodel, &iter, | |
7620 | 3798 STATUS_ICON_COLUMN, status, |
3799 STATUS_ICON_VISIBLE_COLUMN, TRUE, | |
3800 NAME_COLUMN, mark, | |
3801 -1); | |
5228 | 3802 |
3803 g_free(mark); | |
7620 | 3804 if(status) |
5228 | 3805 g_object_unref(status); |
7620 | 3806 } else { |
5260 | 3807 gaim_gtk_blist_hide_node(list, node); |
5228 | 3808 } |
7620 | 3809 } |
3810 | |
3811 static void gaim_gtk_blist_update(GaimBuddyList *list, GaimBlistNode *node) | |
3812 { | |
3813 if(!gtkblist) | |
3814 return; | |
3815 | |
3816 switch(node->type) { | |
3817 case GAIM_BLIST_GROUP_NODE: | |
3818 gaim_gtk_blist_update_group(list, node); | |
3819 break; | |
3820 case GAIM_BLIST_CONTACT_NODE: | |
3821 gaim_gtk_blist_update_contact(list, node); | |
3822 break; | |
3823 case GAIM_BLIST_BUDDY_NODE: | |
3824 gaim_gtk_blist_update_buddy(list, node); | |
3825 break; | |
3826 case GAIM_BLIST_CHAT_NODE: | |
3827 gaim_gtk_blist_update_chat(list, node); | |
3828 break; | |
3829 case GAIM_BLIST_OTHER_NODE: | |
3830 return; | |
3831 } | |
5234 | 3832 |
5228 | 3833 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(gtkblist->treeview)); |
3834 } | |
3835 | |
7620 | 3836 |
3837 static void gaim_gtk_blist_destroy(GaimBuddyList *list) | |
5228 | 3838 { |
3839 if (!gtkblist) | |
3840 return; | |
3841 | |
8937 | 3842 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-on", |
3843 gtkblist, GAIM_CALLBACK(sign_on_off_cb)); | |
3844 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-off", | |
3845 gtkblist, GAIM_CALLBACK(sign_on_off_cb)); | |
8259
4f9f68ab8770
[gaim-migrate @ 8982]
Christian Hammond <chipx86@chipx86.com>
parents:
8254
diff
changeset
|
3846 |
5228 | 3847 gtk_widget_destroy(gtkblist->window); |
7620 | 3848 |
8254 | 3849 gaim_gtk_blist_tooltip_destroy(); |
7620 | 3850 |
5228 | 3851 if (gtkblist->refresh_timer) |
3852 g_source_remove(gtkblist->refresh_timer); | |
3853 if (gtkblist->timeout) | |
3854 g_source_remove(gtkblist->timeout); | |
10354 | 3855 if (gtkblist->drag_timeout) |
3856 g_source_remove(gtkblist->drag_timeout); | |
5228 | 3857 |
3858 gtkblist->refresh_timer = 0; | |
3859 gtkblist->timeout = 0; | |
10354 | 3860 gtkblist->drag_timeout = 0; |
5228 | 3861 gtkblist->window = gtkblist->vbox = gtkblist->treeview = NULL; |
3862 gtkblist->treemodel = NULL; | |
3863 gtkblist->idle_column = NULL; | |
11257 | 3864 gtkblist->buddy_icon_column = NULL; |
5427 | 3865 g_object_unref(G_OBJECT(gtkblist->ift)); |
5228 | 3866 protomenu = NULL; |
3867 gtkblist = NULL; | |
7620 | 3868 |
10087 | 3869 gaim_prefs_disconnect_by_handle(gaim_gtk_blist_get_handle()); |
5228 | 3870 } |
3871 | |
7620 | 3872 static void gaim_gtk_blist_set_visible(GaimBuddyList *list, gboolean show) |
5228 | 3873 { |
3874 if (!(gtkblist && gtkblist->window)) | |
3875 return; | |
10325 | 3876 |
10282 | 3877 gaim_prefs_set_bool("/gaim/gtk/blist/list_visible", show); |
10325 | 3878 |
5228 | 3879 if (show) { |
3880 gaim_gtk_blist_restore_position(); | |
3881 gtk_window_present(GTK_WINDOW(gtkblist->window)); | |
3882 } else { | |
11709
cae2fb7e8594
[gaim-migrate @ 14000]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11692
diff
changeset
|
3883 gtk_window_iconify(GTK_WINDOW(gtkblist->window)); |
5228 | 3884 } |
3885 } | |
3886 | |
7620 | 3887 static GList * |
3888 groups_tree(void) | |
3889 { | |
3890 GList *tmp = NULL; | |
3891 char *tmp2; | |
3892 GaimGroup *g; | |
3893 GaimBlistNode *gnode; | |
3894 | |
3895 if (gaim_get_blist()->root == NULL) | |
3896 { | |
3897 tmp2 = g_strdup(_("Buddies")); | |
3898 tmp = g_list_append(tmp, tmp2); | |
3899 } | |
3900 else | |
3901 { | |
3902 for (gnode = gaim_get_blist()->root; | |
3903 gnode != NULL; | |
3904 gnode = gnode->next) | |
3905 { | |
3906 if (GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
3907 { | |
3908 g = (GaimGroup *)gnode; | |
3909 tmp2 = g->name; | |
3910 tmp = g_list_append(tmp, tmp2); | |
3911 } | |
3912 } | |
3913 } | |
3914 | |
3915 return tmp; | |
3916 } | |
3917 | |
3918 static void | |
3919 add_buddy_select_account_cb(GObject *w, GaimAccount *account, | |
3920 GaimGtkAddBuddyData *data) | |
3921 { | |
3922 /* Save our account */ | |
3923 data->account = account; | |
3924 } | |
3925 | |
3926 static void | |
3927 destroy_add_buddy_dialog_cb(GtkWidget *win, GaimGtkAddBuddyData *data) | |
3928 { | |
3929 g_free(data); | |
3930 } | |
3931 | |
3932 static void | |
3933 add_buddy_cb(GtkWidget *w, int resp, GaimGtkAddBuddyData *data) | |
3934 { | |
3935 const char *grp, *who, *whoalias; | |
3936 GaimConversation *c; | |
3937 GaimBuddy *b; | |
3938 GaimGroup *g; | |
3939 | |
3940 if (resp == GTK_RESPONSE_OK) | |
3941 { | |
3942 who = gtk_entry_get_text(GTK_ENTRY(data->entry)); | |
3943 grp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(data->combo)->entry)); | |
3944 whoalias = gtk_entry_get_text(GTK_ENTRY(data->entry_for_alias)); | |
9658 | 3945 if (*whoalias == '\0') |
3946 whoalias = NULL; | |
7620 | 3947 |
3948 if ((g = gaim_find_group(grp)) == NULL) | |
3949 { | |
3950 g = gaim_group_new(grp); | |
3951 gaim_blist_add_group(g, NULL); | |
3952 } | |
3953 | |
3954 b = gaim_buddy_new(data->account, who, whoalias); | |
3955 gaim_blist_add_buddy(b, NULL, g, NULL); | |
11643 | 3956 gaim_account_add_buddy(data->account, b); |
7620 | 3957 |
7887 | 3958 /* |
9285 | 3959 * XXX |
11643 | 3960 * It really seems like it would be better if the call to |
3961 * gaim_account_add_buddy() and gaim_conversation_update() were done in | |
3962 * blist.c, possibly in the gaim_blist_add_buddy() function. Maybe | |
3963 * gaim_account_add_buddy() should be renamed to | |
3964 * gaim_blist_add_new_buddy() or something, and have it call | |
7887 | 3965 * gaim_blist_add_buddy() after it creates it. --Mark |
9285 | 3966 * |
3967 * No that's not good. blist.c should only deal with adding nodes to the | |
11643 | 3968 * local list. We need a new, non-gtk file that calls both |
3969 * gaim_account_add_buddy and gaim_blist_add_buddy(). | |
3970 * Or something. --Mark | |
7887 | 3971 */ |
3972 | |
11338 | 3973 c = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, who, data->account); |
7620 | 3974 if (c != NULL) { |
3975 gaim_buddy_icon_update(gaim_conv_im_get_icon(GAIM_CONV_IM(c))); | |
3976 gaim_conversation_update(c, GAIM_CONV_UPDATE_ADD); | |
3977 } | |
3978 } | |
3979 | |
3980 gtk_widget_destroy(data->window); | |
3981 } | |
3982 | |
3983 static void | |
3984 gaim_gtk_blist_request_add_buddy(GaimAccount *account, const char *username, | |
3985 const char *group, const char *alias) | |
3986 { | |
3987 GtkWidget *table; | |
3988 GtkWidget *label; | |
3989 GtkWidget *hbox; | |
3990 GtkWidget *vbox; | |
3991 GtkWidget *img; | |
3992 GaimGtkBuddyList *gtkblist; | |
3993 GaimGtkAddBuddyData *data = g_new0(GaimGtkAddBuddyData, 1); | |
3994 | |
3995 data->account = | |
3996 (account != NULL | |
3997 ? account | |
3998 : gaim_connection_get_account(gaim_connections_get_all()->data)); | |
3999 | |
4000 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, | |
4001 GTK_ICON_SIZE_DIALOG); | |
4002 | |
4003 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); | |
4004 | |
4005 data->window = gtk_dialog_new_with_buttons(_("Add Buddy"), | |
8975 | 4006 NULL, GTK_DIALOG_NO_SEPARATOR, |
7620 | 4007 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
4008 GTK_STOCK_ADD, GTK_RESPONSE_OK, | |
4009 NULL); | |
4010 | |
4011 gtk_dialog_set_default_response(GTK_DIALOG(data->window), GTK_RESPONSE_OK); | |
11243 | 4012 gtk_container_set_border_width(GTK_CONTAINER(data->window), GAIM_HIG_BOX_SPACE); |
7620 | 4013 gtk_window_set_resizable(GTK_WINDOW(data->window), FALSE); |
11243 | 4014 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(data->window)->vbox), GAIM_HIG_BORDER); |
4015 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), GAIM_HIG_BOX_SPACE); | |
7620 | 4016 gtk_window_set_role(GTK_WINDOW(data->window), "add_buddy"); |
8975 | 4017 gtk_window_set_type_hint(GTK_WINDOW(data->window), |
9811 | 4018 GDK_WINDOW_TYPE_HINT_DIALOG); |
7620 | 4019 |
11243 | 4020 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BORDER); |
7620 | 4021 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), hbox); |
4022 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
4023 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
4024 | |
4025 vbox = gtk_vbox_new(FALSE, 0); | |
4026 gtk_container_add(GTK_CONTAINER(hbox), vbox); | |
4027 | |
4028 label = gtk_label_new( | |
4029 _("Please enter the screen name of the person you would like " | |
4030 "to add to your buddy list. You may optionally enter an alias, " | |
4031 "or nickname, for the buddy. The alias will be displayed in " | |
4032 "place of the screen name whenever possible.\n")); | |
4033 | |
4034 gtk_widget_set_size_request(GTK_WIDGET(label), 400, -1); | |
4035 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
4036 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
4037 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
4038 | |
11243 | 4039 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
7620 | 4040 gtk_container_add(GTK_CONTAINER(vbox), hbox); |
4041 | |
4042 g_signal_connect(G_OBJECT(data->window), "destroy", | |
4043 G_CALLBACK(destroy_add_buddy_dialog_cb), data); | |
4044 | |
4045 table = gtk_table_new(4, 2, FALSE); | |
4046 gtk_table_set_row_spacings(GTK_TABLE(table), 5); | |
4047 gtk_table_set_col_spacings(GTK_TABLE(table), 5); | |
4048 gtk_container_set_border_width(GTK_CONTAINER(table), 0); | |
4049 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); | |
4050 | |
4051 label = gtk_label_new(_("Screen Name:")); | |
4052 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
4053 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); | |
4054 | |
4055 data->entry = gtk_entry_new(); | |
4056 gtk_table_attach_defaults(GTK_TABLE(table), data->entry, 1, 2, 0, 1); | |
4057 gtk_widget_grab_focus(data->entry); | |
4058 | |
4059 if (username != NULL) | |
4060 gtk_entry_set_text(GTK_ENTRY(data->entry), username); | |
4061 | |
4062 gtk_entry_set_activates_default (GTK_ENTRY(data->entry), TRUE); | |
8137 | 4063 gaim_set_accessible_label (data->entry, label); |
7620 | 4064 |
4065 label = gtk_label_new(_("Alias:")); | |
4066 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
4067 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2); | |
4068 | |
4069 data->entry_for_alias = gtk_entry_new(); | |
4070 gtk_table_attach_defaults(GTK_TABLE(table), | |
4071 data->entry_for_alias, 1, 2, 1, 2); | |
4072 | |
4073 if (alias != NULL) | |
4074 gtk_entry_set_text(GTK_ENTRY(data->entry_for_alias), alias); | |
4075 | |
10734
8b2c81d9b271
[gaim-migrate @ 12336]
Luke Schierer <lschiere@pidgin.im>
parents:
10694
diff
changeset
|
4076 if (username != NULL) |
8b2c81d9b271
[gaim-migrate @ 12336]
Luke Schierer <lschiere@pidgin.im>
parents:
10694
diff
changeset
|
4077 gtk_widget_grab_focus(GTK_WIDGET(data->entry_for_alias)); |
8b2c81d9b271
[gaim-migrate @ 12336]
Luke Schierer <lschiere@pidgin.im>
parents:
10694
diff
changeset
|
4078 |
7620 | 4079 gtk_entry_set_activates_default (GTK_ENTRY(data->entry_for_alias), TRUE); |
8137 | 4080 gaim_set_accessible_label (data->entry_for_alias, label); |
7620 | 4081 |
4082 label = gtk_label_new(_("Group:")); | |
4083 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
4084 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3); | |
4085 | |
4086 data->combo = gtk_combo_new(); | |
4087 gtk_combo_set_popdown_strings(GTK_COMBO(data->combo), groups_tree()); | |
4088 gtk_table_attach_defaults(GTK_TABLE(table), data->combo, 1, 2, 2, 3); | |
8137 | 4089 gaim_set_accessible_label (data->combo, label); |
7620 | 4090 |
4091 /* Set up stuff for the account box */ | |
4092 label = gtk_label_new(_("Account:")); | |
4093 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
4094 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4); | |
4095 | |
4096 data->account_box = gaim_gtk_account_option_menu_new(account, FALSE, | |
4097 G_CALLBACK(add_buddy_select_account_cb), NULL, data); | |
4098 | |
4099 gtk_table_attach_defaults(GTK_TABLE(table), data->account_box, 1, 2, 3, 4); | |
8137 | 4100 gaim_set_accessible_label (data->account_box, label); |
7620 | 4101 /* End of account box */ |
4102 | |
4103 g_signal_connect(G_OBJECT(data->window), "response", | |
4104 G_CALLBACK(add_buddy_cb), data); | |
4105 | |
4106 gtk_widget_show_all(data->window); | |
4107 | |
4108 if (group != NULL) | |
4109 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(data->combo)->entry), group); | |
4110 } | |
4111 | |
4112 static void | |
4113 add_chat_cb(GtkWidget *w, GaimGtkAddChatData *data) | |
4114 { | |
4115 GHashTable *components; | |
4116 GList *tmp; | |
4117 GaimChat *chat; | |
4118 GaimGroup *group; | |
4119 const char *group_name; | |
9918 | 4120 char *chat_name = NULL; |
4121 GaimConversation *conv = NULL; | |
10475 | 4122 const char *value; |
7620 | 4123 |
4124 components = g_hash_table_new_full(g_str_hash, g_str_equal, | |
4125 g_free, g_free); | |
4126 | |
4127 for (tmp = data->entries; tmp; tmp = tmp->next) | |
4128 { | |
4129 if (g_object_get_data(tmp->data, "is_spin")) | |
4130 { | |
4131 g_hash_table_replace(components, | |
4132 g_strdup(g_object_get_data(tmp->data, "identifier")), | |
4133 g_strdup_printf("%d", | |
4134 gtk_spin_button_get_value_as_int(tmp->data))); | |
4135 } | |
4136 else | |
4137 { | |
10475 | 4138 value = gtk_entry_get_text(tmp->data); |
4139 if (*value != '\0') | |
4140 g_hash_table_replace(components, | |
4141 g_strdup(g_object_get_data(tmp->data, "identifier")), | |
4142 g_strdup(value)); | |
7620 | 4143 } |
4144 } | |
4145 | |
4146 chat = gaim_chat_new(data->account, | |
4147 gtk_entry_get_text(GTK_ENTRY(data->alias_entry)), | |
4148 components); | |
4149 | |
4150 group_name = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(data->group_combo)->entry)); | |
4151 | |
4152 if ((group = gaim_find_group(group_name)) == NULL) | |
4153 { | |
4154 group = gaim_group_new(group_name); | |
4155 gaim_blist_add_group(group, NULL); | |
4156 } | |
4157 | |
4158 if (chat != NULL) | |
4159 { | |
4160 gaim_blist_add_chat(chat, group, NULL); | |
9918 | 4161 |
4162 if (GAIM_PLUGIN_PROTOCOL_INFO(data->account->gc->prpl)->get_chat_name != NULL) | |
4163 chat_name = GAIM_PLUGIN_PROTOCOL_INFO( | |
4164 data->account->gc->prpl)->get_chat_name(chat->components); | |
10246 | 4165 |
9918 | 4166 if (chat_name != NULL) { |
11338 | 4167 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, |
10246 | 4168 chat_name, |
4169 data->account); | |
9918 | 4170 g_free(chat_name); |
4171 } | |
4172 | |
4173 if (conv != NULL) | |
4174 gaim_conversation_update(conv, GAIM_CONV_UPDATE_ADD); | |
7620 | 4175 } |
4176 | |
4177 gtk_widget_destroy(data->window); | |
9812 | 4178 g_free(data->default_chat_name); |
7620 | 4179 g_list_free(data->entries); |
4180 g_free(data); | |
4181 } | |
4182 | |
4183 static void | |
4184 add_chat_resp_cb(GtkWidget *w, int resp, GaimGtkAddChatData *data) | |
4185 { | |
4186 if (resp == GTK_RESPONSE_OK) | |
4187 { | |
4188 add_chat_cb(NULL, data); | |
4189 } | |
4190 else | |
4191 { | |
4192 gtk_widget_destroy(data->window); | |
9812 | 4193 g_free(data->default_chat_name); |
7620 | 4194 g_list_free(data->entries); |
4195 g_free(data); | |
4196 } | |
4197 } | |
4198 | |
10475 | 4199 /* |
4200 * Check the values of all the text entry boxes. If any required input | |
4201 * strings are empty then don't allow the user to click on "OK." | |
4202 */ | |
4203 static void | |
4204 addchat_set_sensitive_if_input_cb(GtkWidget *entry, gpointer user_data) | |
4205 { | |
4206 GaimGtkAddChatData *data; | |
4207 GList *tmp; | |
4208 const char *text; | |
4209 gboolean required; | |
4210 gboolean sensitive = TRUE; | |
4211 | |
4212 data = user_data; | |
4213 | |
4214 for (tmp = data->entries; tmp != NULL; tmp = tmp->next) | |
4215 { | |
4216 if (!g_object_get_data(tmp->data, "is_spin")) | |
4217 { | |
4218 required = GPOINTER_TO_INT(g_object_get_data(tmp->data, "required")); | |
4219 text = gtk_entry_get_text(tmp->data); | |
4220 if (required && (*text == '\0')) | |
4221 sensitive = FALSE; | |
4222 } | |
4223 } | |
4224 | |
4225 gtk_dialog_set_response_sensitive(GTK_DIALOG(data->window), GTK_RESPONSE_OK, sensitive); | |
4226 } | |
4227 | |
7620 | 4228 static void |
4229 rebuild_addchat_entries(GaimGtkAddChatData *data) | |
4230 { | |
4231 GaimConnection *gc; | |
9959 | 4232 GList *list = NULL, *tmp = NULL; |
9754 | 4233 GHashTable *defaults = NULL; |
7620 | 4234 struct proto_chat_entry *pce; |
4235 gboolean focus = TRUE; | |
4236 | |
10127 | 4237 g_return_if_fail(data->account != NULL); |
4238 | |
7620 | 4239 gc = gaim_account_get_connection(data->account); |
4240 | |
4241 while (GTK_BOX(data->entries_box)->children) | |
4242 { | |
4243 gtk_container_remove(GTK_CONTAINER(data->entries_box), | |
10475 | 4244 ((GtkBoxChild *)GTK_BOX(data->entries_box)->children->data)->widget); |
7620 | 4245 } |
4246 | |
4247 if (data->entries != NULL) | |
4248 g_list_free(data->entries); | |
4249 | |
4250 data->entries = NULL; | |
4251 | |
9959 | 4252 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info != NULL) |
4253 list = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info(gc); | |
7620 | 4254 |
9754 | 4255 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults != NULL) |
10475 | 4256 defaults = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, data->default_chat_name); |
9754 | 4257 |
7620 | 4258 for (tmp = list; tmp; tmp = tmp->next) |
4259 { | |
4260 GtkWidget *label; | |
4261 GtkWidget *rowbox; | |
10475 | 4262 GtkWidget *input; |
7620 | 4263 |
4264 pce = tmp->data; | |
4265 | |
4266 rowbox = gtk_hbox_new(FALSE, 5); | |
4267 gtk_box_pack_start(GTK_BOX(data->entries_box), rowbox, FALSE, FALSE, 0); | |
4268 | |
7889 | 4269 label = gtk_label_new_with_mnemonic(pce->label); |
7620 | 4270 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); |
4271 gtk_size_group_add_widget(data->sg, label); | |
4272 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); | |
4273 | |
4274 if (pce->is_int) | |
4275 { | |
4276 GtkObject *adjust; | |
4277 adjust = gtk_adjustment_new(pce->min, pce->min, pce->max, | |
4278 1, 10, 10); | |
10475 | 4279 input = gtk_spin_button_new(GTK_ADJUSTMENT(adjust), 1, 0); |
4280 gtk_widget_set_size_request(input, 50, -1); | |
4281 gtk_box_pack_end(GTK_BOX(rowbox), input, FALSE, FALSE, 0); | |
7620 | 4282 } |
4283 else | |
4284 { | |
9754 | 4285 char *value; |
10475 | 4286 input = gtk_entry_new(); |
4287 gtk_entry_set_activates_default(GTK_ENTRY(input), TRUE); | |
9754 | 4288 value = g_hash_table_lookup(defaults, pce->identifier); |
4289 if (value != NULL) | |
10475 | 4290 gtk_entry_set_text(GTK_ENTRY(input), value); |
7620 | 4291 if (pce->secret) |
10475 | 4292 gtk_entry_set_visibility(GTK_ENTRY(input), FALSE); |
4293 gtk_box_pack_end(GTK_BOX(rowbox), input, TRUE, TRUE, 0); | |
4294 g_signal_connect(G_OBJECT(input), "changed", | |
4295 G_CALLBACK(addchat_set_sensitive_if_input_cb), data); | |
7620 | 4296 } |
4297 | |
10475 | 4298 /* Do the following for any type of input widget */ |
4299 if (focus) | |
4300 { | |
4301 gtk_widget_grab_focus(input); | |
4302 focus = FALSE; | |
4303 } | |
4304 gtk_label_set_mnemonic_widget(GTK_LABEL(label), input); | |
4305 gaim_set_accessible_label(input, label); | |
4306 g_object_set_data(G_OBJECT(input), "identifier", pce->identifier); | |
4307 g_object_set_data(G_OBJECT(input), "is_spin", GINT_TO_POINTER(pce->is_int)); | |
4308 g_object_set_data(G_OBJECT(input), "required", GINT_TO_POINTER(pce->required)); | |
4309 data->entries = g_list_append(data->entries, input); | |
4310 | |
7620 | 4311 g_free(pce); |
4312 } | |
4313 | |
4314 g_list_free(list); | |
9754 | 4315 g_hash_table_destroy(defaults); |
7620 | 4316 |
10475 | 4317 /* Set whether the "OK" button should be clickable initially */ |
4318 addchat_set_sensitive_if_input_cb(NULL, data); | |
4319 | |
7620 | 4320 gtk_widget_show_all(data->entries_box); |
4321 } | |
4322 | |
4323 static void | |
10475 | 4324 addchat_select_account_cb(GObject *w, GaimAccount *account, |
7620 | 4325 GaimGtkAddChatData *data) |
4326 { | |
9460 | 4327 if (strcmp(gaim_account_get_protocol_id(data->account), |
4328 gaim_account_get_protocol_id(account)) == 0) | |
7620 | 4329 { |
4330 data->account = account; | |
4331 } | |
4332 else | |
4333 { | |
4334 data->account = account; | |
4335 rebuild_addchat_entries(data); | |
4336 } | |
4337 } | |
4338 | |
4339 void | |
7859 | 4340 gaim_gtk_blist_request_add_chat(GaimAccount *account, GaimGroup *group, |
9754 | 4341 const char *alias, const char *name) |
7620 | 4342 { |
4343 GaimGtkAddChatData *data; | |
8975 | 4344 GaimGtkBuddyList *gtkblist; |
4345 GList *l; | |
4346 GaimConnection *gc; | |
7620 | 4347 GtkWidget *label; |
4348 GtkWidget *rowbox; | |
4349 GtkWidget *hbox; | |
4350 GtkWidget *vbox; | |
4351 GtkWidget *img; | |
4352 | |
9812 | 4353 if (account != NULL) { |
4354 gc = gaim_account_get_connection(account); | |
4355 | |
4356 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->join_chat == NULL) { | |
4357 gaim_notify_error(gc, NULL, _("This protocol does not support chat rooms."), NULL); | |
4358 return; | |
4359 } | |
4360 } else { | |
4361 /* Find an account with chat capabilities */ | |
4362 for (l = gaim_connections_get_all(); l != NULL; l = l->next) { | |
4363 gc = (GaimConnection *)l->data; | |
4364 | |
4365 if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->join_chat != NULL) { | |
4366 account = gaim_connection_get_account(gc); | |
4367 break; | |
4368 } | |
4369 } | |
4370 | |
4371 if (account == NULL) { | |
4372 gaim_notify_error(NULL, NULL, | |
4373 _("You are not currently signed on with any " | |
4374 "protocols that have the ability to chat."), NULL); | |
4375 return; | |
4376 } | |
4377 } | |
4378 | |
7620 | 4379 data = g_new0(GaimGtkAddChatData, 1); |
9812 | 4380 data->account = account; |
4381 data->default_chat_name = g_strdup(name); | |
7620 | 4382 |
4383 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, | |
4384 GTK_ICON_SIZE_DIALOG); | |
4385 | |
8975 | 4386 gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); |
4387 | |
7620 | 4388 data->sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); |
4389 | |
8975 | 4390 data->window = gtk_dialog_new_with_buttons(_("Add Chat"), |
4391 NULL, GTK_DIALOG_NO_SEPARATOR, | |
4392 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
4393 GTK_STOCK_ADD, GTK_RESPONSE_OK, | |
4394 NULL); | |
4395 | |
4396 gtk_dialog_set_default_response(GTK_DIALOG(data->window), GTK_RESPONSE_OK); | |
11243 | 4397 gtk_container_set_border_width(GTK_CONTAINER(data->window), GAIM_HIG_BOX_SPACE); |
8975 | 4398 gtk_window_set_resizable(GTK_WINDOW(data->window), FALSE); |
11243 | 4399 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(data->window)->vbox), GAIM_HIG_BORDER); |
4400 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), GAIM_HIG_BOX_SPACE); | |
7620 | 4401 gtk_window_set_role(GTK_WINDOW(data->window), "add_chat"); |
8975 | 4402 gtk_window_set_type_hint(GTK_WINDOW(data->window), |
9811 | 4403 GDK_WINDOW_TYPE_HINT_DIALOG); |
7620 | 4404 |
11243 | 4405 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BORDER); |
7620 | 4406 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(data->window)->vbox), hbox); |
4407 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
4408 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
4409 | |
4410 vbox = gtk_vbox_new(FALSE, 5); | |
4411 gtk_container_add(GTK_CONTAINER(hbox), vbox); | |
4412 | |
4413 label = gtk_label_new( | |
4414 _("Please enter an alias, and the appropriate information " | |
4415 "about the chat you would like to add to your buddy list.\n")); | |
4416 gtk_widget_set_size_request(label, 400, -1); | |
4417 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
4418 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
4419 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
4420 | |
4421 rowbox = gtk_hbox_new(FALSE, 5); | |
4422 gtk_box_pack_start(GTK_BOX(vbox), rowbox, FALSE, FALSE, 0); | |
4423 | |
4424 label = gtk_label_new(_("Account:")); | |
4425 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
4426 gtk_size_group_add_widget(data->sg, label); | |
4427 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); | |
4428 | |
4429 data->account_menu = gaim_gtk_account_option_menu_new(account, FALSE, | |
10475 | 4430 G_CALLBACK(addchat_select_account_cb), |
9987 | 4431 chat_account_filter_func, data); |
7620 | 4432 gtk_box_pack_start(GTK_BOX(rowbox), data->account_menu, TRUE, TRUE, 0); |
8137 | 4433 gaim_set_accessible_label (data->account_menu, label); |
7620 | 4434 |
4435 data->entries_box = gtk_vbox_new(FALSE, 5); | |
9811 | 4436 gtk_container_set_border_width(GTK_CONTAINER(data->entries_box), 0); |
7620 | 4437 gtk_box_pack_start(GTK_BOX(vbox), data->entries_box, TRUE, TRUE, 0); |
4438 | |
4439 rebuild_addchat_entries(data); | |
4440 | |
4441 rowbox = gtk_hbox_new(FALSE, 5); | |
4442 gtk_box_pack_start(GTK_BOX(vbox), rowbox, FALSE, FALSE, 0); | |
4443 | |
4444 label = gtk_label_new(_("Alias:")); | |
4445 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
4446 gtk_size_group_add_widget(data->sg, label); | |
4447 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); | |
4448 | |
4449 data->alias_entry = gtk_entry_new(); | |
7859 | 4450 if (alias != NULL) |
4451 gtk_entry_set_text(GTK_ENTRY(data->alias_entry), alias); | |
7620 | 4452 gtk_box_pack_end(GTK_BOX(rowbox), data->alias_entry, TRUE, TRUE, 0); |
10311 | 4453 gtk_entry_set_activates_default(GTK_ENTRY(data->alias_entry), TRUE); |
8137 | 4454 gaim_set_accessible_label (data->alias_entry, label); |
7620 | 4455 |
4456 rowbox = gtk_hbox_new(FALSE, 5); | |
4457 gtk_box_pack_start(GTK_BOX(vbox), rowbox, FALSE, FALSE, 0); | |
4458 | |
9811 | 4459 label = gtk_label_new(_("Group:")); |
7620 | 4460 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); |
4461 gtk_size_group_add_widget(data->sg, label); | |
4462 gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); | |
4463 | |
9811 | 4464 data->group_combo = gtk_combo_new(); |
4465 gtk_combo_set_popdown_strings(GTK_COMBO(data->group_combo), groups_tree()); | |
7620 | 4466 gtk_box_pack_end(GTK_BOX(rowbox), data->group_combo, TRUE, TRUE, 0); |
4467 | |
4468 if (group) | |
4469 { | |
4470 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(data->group_combo)->entry), | |
4471 group->name); | |
4472 } | |
8137 | 4473 gaim_set_accessible_label (data->group_combo, label); |
7620 | 4474 |
4475 g_signal_connect(G_OBJECT(data->window), "response", | |
4476 G_CALLBACK(add_chat_resp_cb), data); | |
4477 | |
4478 gtk_widget_show_all(data->window); | |
4479 } | |
4480 | |
4481 static void | |
4482 add_group_cb(GaimConnection *gc, const char *group_name) | |
4483 { | |
9285 | 4484 GaimGroup *group; |
4485 | |
4486 group = gaim_group_new(group_name); | |
4487 gaim_blist_add_group(group, NULL); | |
7620 | 4488 } |
4489 | |
4490 void | |
4491 gaim_gtk_blist_request_add_group(void) | |
4492 { | |
7853 | 4493 gaim_request_input(NULL, _("Add Group"), NULL, |
7620 | 4494 _("Please enter the name of the group to be added."), |
8697 | 4495 NULL, FALSE, FALSE, NULL, |
7620 | 4496 _("Add"), G_CALLBACK(add_group_cb), |
4497 _("Cancel"), NULL, NULL); | |
4498 } | |
4499 | |
4500 static GaimBlistUiOps blist_ui_ops = | |
5228 | 4501 { |
4502 gaim_gtk_blist_new_list, | |
5256 | 4503 gaim_gtk_blist_new_node, |
5228 | 4504 gaim_gtk_blist_show, |
4505 gaim_gtk_blist_update, | |
4506 gaim_gtk_blist_remove, | |
4507 gaim_gtk_blist_destroy, | |
7620 | 4508 gaim_gtk_blist_set_visible, |
4509 gaim_gtk_blist_request_add_buddy, | |
4510 gaim_gtk_blist_request_add_chat, | |
10012 | 4511 gaim_gtk_blist_request_add_group |
5228 | 4512 }; |
4513 | |
4514 | |
7620 | 4515 GaimBlistUiOps * |
4516 gaim_gtk_blist_get_ui_ops(void) | |
5228 | 4517 { |
4518 return &blist_ui_ops; | |
4519 } | |
4520 | |
10643 | 4521 GaimGtkBuddyList *gaim_gtk_blist_get_default_gtk_blist() |
4522 { | |
4523 return gtkblist; | |
4524 } | |
4525 | |
7620 | 4526 static void account_signon_cb(GaimConnection *gc, gpointer z) |
4527 { | |
4528 GaimAccount *account = gaim_connection_get_account(gc); | |
4529 GaimBlistNode *gnode, *cnode; | |
4530 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) | |
4531 { | |
4532 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
4533 continue; | |
4534 for(cnode = gnode->child; cnode; cnode = cnode->next) | |
4535 { | |
4536 GaimChat *chat; | |
4537 | |
4538 if(!GAIM_BLIST_NODE_IS_CHAT(cnode)) | |
4539 continue; | |
4540 | |
4541 chat = (GaimChat *)cnode; | |
4542 | |
4543 if(chat->account != account) | |
4544 continue; | |
4545 | |
8197 | 4546 if(gaim_blist_node_get_bool((GaimBlistNode*)chat, "gtk-autojoin") || |
8198 | 4547 (gaim_blist_node_get_string((GaimBlistNode*)chat, |
4548 "gtk-autojoin") != NULL)) | |
7620 | 4549 serv_join_chat(gc, chat->components); |
4550 } | |
4551 } | |
4552 } | |
4553 | |
8815 | 4554 void * |
4555 gaim_gtk_blist_get_handle() { | |
4556 static int handle; | |
4557 | |
4558 return &handle; | |
4559 } | |
4560 | |
7620 | 4561 void gaim_gtk_blist_init(void) |
4562 { | |
8815 | 4563 void *gtk_blist_handle = gaim_gtk_blist_get_handle(); |
7620 | 4564 |
4565 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", | |
8815 | 4566 gtk_blist_handle, GAIM_CALLBACK(account_signon_cb), |
7620 | 4567 NULL); |
7731 | 4568 |
4569 /* Initialize prefs */ | |
8819 | 4570 gaim_prefs_add_none("/gaim/gtk/blist"); |
4571 gaim_prefs_add_bool("/gaim/gtk/blist/show_buddy_icons", TRUE); | |
4572 gaim_prefs_add_bool("/gaim/gtk/blist/show_empty_groups", FALSE); | |
4573 gaim_prefs_add_bool("/gaim/gtk/blist/show_offline_buddies", FALSE); | |
10282 | 4574 gaim_prefs_add_bool("/gaim/gtk/blist/list_visible", TRUE); |
9711 | 4575 gaim_prefs_add_string("/gaim/gtk/blist/sort_type", "alphabetical"); |
8819 | 4576 gaim_prefs_add_int("/gaim/gtk/blist/x", 0); |
4577 gaim_prefs_add_int("/gaim/gtk/blist/y", 0); | |
9778 | 4578 gaim_prefs_add_int("/gaim/gtk/blist/width", 309); /* Golden ratio, baby */ |
4579 gaim_prefs_add_int("/gaim/gtk/blist/height", 500); /* Golden ratio, baby */ | |
8819 | 4580 gaim_prefs_add_int("/gaim/gtk/blist/tooltip_delay", 500); |
7731 | 4581 |
8815 | 4582 /* Register our signals */ |
4583 gaim_signal_register(gtk_blist_handle, "gtkblist-created", | |
9811 | 4584 gaim_marshal_VOID__POINTER, NULL, 1, |
4585 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
4586 GAIM_SUBTYPE_BLIST)); | |
8819 | 4587 |
4588 gaim_signal_register(gtk_blist_handle, "drawing-tooltip", | |
9811 | 4589 gaim_marshal_VOID__POINTER_POINTER, NULL, 2, |
4590 gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_BLIST_NODE), | |
10477 | 4591 gaim_value_new_outgoing(GAIM_TYPE_BOXED, "GString *")); |
7620 | 4592 } |
4593 | |
8815 | 4594 void |
4595 gaim_gtk_blist_uninit(void) { | |
4596 gaim_signals_unregister_by_instance(gaim_gtk_blist_get_handle()); | |
4597 } | |
5228 | 4598 |
4599 /********************************************************************* | |
4600 * Public utility functions * | |
4601 *********************************************************************/ | |
4602 | |
4603 GdkPixbuf * | |
10884 | 4604 gaim_gtk_create_prpl_icon(GaimAccount *account) |
5228 | 4605 { |
4606 GaimPlugin *prpl; | |
4607 GaimPluginProtocolInfo *prpl_info = NULL; | |
4608 GdkPixbuf *status = NULL; | |
4609 char *filename = NULL; | |
4610 const char *protoname = NULL; | |
4611 char buf[256]; | |
4612 | |
10046 | 4613 g_return_val_if_fail(account != NULL, NULL); |
4614 | |
7956 | 4615 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); |
5228 | 4616 |
4617 if (prpl != NULL) { | |
4618 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
4619 | |
4620 if (prpl_info->list_icon != NULL) | |
4621 protoname = prpl_info->list_icon(account, NULL); | |
4622 } | |
4623 | |
4624 if (protoname == NULL) | |
4625 return NULL; | |
4626 | |
4627 /* | |
4628 * Status icons will be themeable too, and then it will look up | |
4629 * protoname from the theme | |
4630 */ | |
4631 g_snprintf(buf, sizeof(buf), "%s.png", protoname); | |
4632 | |
4633 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", | |
4634 "default", buf, NULL); | |
4635 status = gdk_pixbuf_new_from_file(filename, NULL); | |
4636 g_free(filename); | |
4637 | |
4638 return status; | |
4639 } | |
4640 | |
5422 | 4641 |
4642 /********************************************************************* | |
9811 | 4643 * Buddy List sorting functions * |
5422 | 4644 *********************************************************************/ |
4645 | |
11796 | 4646 GList *gaim_gtk_blist_get_sort_methods() |
4647 { | |
4648 return gaim_gtk_blist_sort_methods; | |
4649 } | |
4650 | |
7620 | 4651 void gaim_gtk_blist_sort_method_reg(const char *id, const char *name, gaim_gtk_blist_sort_function func) |
5422 | 4652 { |
4653 struct gaim_gtk_blist_sort_method *method = g_new0(struct gaim_gtk_blist_sort_method, 1); | |
7620 | 4654 method->id = g_strdup(id); |
5422 | 4655 method->name = g_strdup(name); |
9775 | 4656 method->func = func; |
11796 | 4657 gaim_gtk_blist_sort_methods = g_list_append(gaim_gtk_blist_sort_methods, method); |
4658 gaim_gtk_blist_update_sort_methods(); | |
5422 | 4659 } |
4660 | |
7620 | 4661 void gaim_gtk_blist_sort_method_unreg(const char *id){ |
11796 | 4662 GList *l = gaim_gtk_blist_sort_methods; |
7620 | 4663 |
4664 while(l) { | |
4665 struct gaim_gtk_blist_sort_method *method = l->data; | |
4666 if(!strcmp(method->id, id)) { | |
11796 | 4667 gaim_gtk_blist_sort_methods = g_list_delete_link(gaim_gtk_blist_sort_methods, l); |
7620 | 4668 g_free(method->id); |
4669 g_free(method->name); | |
4670 g_free(method); | |
4671 break; | |
4672 } | |
4673 } | |
11796 | 4674 gaim_gtk_blist_update_sort_methods(); |
5422 | 4675 } |
4676 | |
7620 | 4677 void gaim_gtk_blist_sort_method_set(const char *id){ |
11796 | 4678 GList *l = gaim_gtk_blist_sort_methods; |
7620 | 4679 |
4680 if(!id) | |
4681 id = "none"; | |
4682 | |
4683 while (l && strcmp(((struct gaim_gtk_blist_sort_method*)l->data)->id, id)) | |
5422 | 4684 l = l->next; |
7620 | 4685 |
5422 | 4686 if (l) { |
4687 current_sort_method = l->data; | |
4688 } else if (!current_sort_method) { | |
7620 | 4689 gaim_gtk_blist_sort_method_set("none"); |
5422 | 4690 return; |
4691 } | |
4692 redo_buddy_list(gaim_get_blist(), TRUE); | |
4693 | |
4694 } | |
4695 | |
4696 /****************************************** | |
4697 ** Sort Methods | |
4698 ******************************************/ | |
4699 | |
7620 | 4700 static GtkTreeIter sort_method_none(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter parent_iter, GtkTreeIter *cur) |
5422 | 4701 { |
7620 | 4702 GtkTreeIter iter; |
4703 GaimBlistNode *sibling = node->prev; | |
4704 GtkTreeIter sibling_iter; | |
4705 | |
4706 if(cur) | |
5422 | 4707 return *cur; |
7620 | 4708 |
4709 while (sibling && !get_iter_from_node(sibling, &sibling_iter)) { | |
4710 sibling = sibling->prev; | |
5422 | 4711 } |
7620 | 4712 |
4713 gtk_tree_store_insert_after(gtkblist->treemodel, &iter, | |
4714 node->parent ? &parent_iter : NULL, | |
4715 sibling ? &sibling_iter : NULL); | |
4716 | |
5422 | 4717 return iter; |
4718 } | |
4719 | |
7620 | 4720 #if GTK_CHECK_VERSION(2,2,1) |
4721 | |
4722 static GtkTreeIter sort_method_alphabetical(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur) | |
5422 | 4723 { |
4724 GtkTreeIter more_z, iter; | |
4725 GaimBlistNode *n; | |
4726 GValue val = {0,}; | |
7620 | 4727 |
4728 const char *my_name; | |
4729 | |
4730 if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
4731 my_name = gaim_contact_get_alias((GaimContact*)node); | |
4732 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) { | |
4733 my_name = gaim_chat_get_name((GaimChat*)node); | |
4734 } else { | |
4735 return sort_method_none(node, blist, groupiter, cur); | |
4736 } | |
4737 | |
5422 | 4738 |
4739 if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(gtkblist->treemodel), &more_z, &groupiter)) { | |
4740 gtk_tree_store_insert(gtkblist->treemodel, &iter, &groupiter, 0); | |
7620 | 4741 return iter; |
4742 } | |
4743 | |
4744 do { | |
4745 const char *this_name; | |
4746 int cmp; | |
4747 | |
4748 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &more_z, NODE_COLUMN, &val); | |
4749 n = g_value_get_pointer(&val); | |
4750 | |
4751 if(GAIM_BLIST_NODE_IS_CONTACT(n)) { | |
4752 this_name = gaim_contact_get_alias((GaimContact*)n); | |
4753 } else if(GAIM_BLIST_NODE_IS_CHAT(n)) { | |
4754 this_name = gaim_chat_get_name((GaimChat*)n); | |
4755 } else { | |
4756 this_name = NULL; | |
4757 } | |
4758 | |
4759 cmp = gaim_utf8_strcasecmp(my_name, this_name); | |
4760 | |
4761 if(this_name && (cmp < 0 || (cmp == 0 && node < n))) { | |
4762 if(cur) { | |
4763 gtk_tree_store_move_before(gtkblist->treemodel, cur, &more_z); | |
4764 return *cur; | |
4765 } else { | |
4766 gtk_tree_store_insert_before(gtkblist->treemodel, &iter, | |
4767 &groupiter, &more_z); | |
4768 return iter; | |
4769 } | |
4770 } | |
4771 g_value_unset(&val); | |
4772 } while (gtk_tree_model_iter_next (GTK_TREE_MODEL(gtkblist->treemodel), &more_z)); | |
4773 | |
4774 if(cur) { | |
4775 gtk_tree_store_move_before(gtkblist->treemodel, cur, NULL); | |
4776 return *cur; | |
4777 } else { | |
4778 gtk_tree_store_append(gtkblist->treemodel, &iter, &groupiter); | |
4779 return iter; | |
4780 } | |
4781 } | |
4782 | |
4783 static GtkTreeIter sort_method_status(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur) | |
4784 { | |
4785 GtkTreeIter more_z, iter; | |
4786 GaimBlistNode *n; | |
4787 GValue val = {0,}; | |
4788 | |
4789 GaimBuddy *my_buddy, *this_buddy; | |
4790 | |
4791 if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
4792 my_buddy = gaim_contact_get_priority_buddy((GaimContact*)node); | |
4793 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) { | |
4794 if(cur) | |
4795 return *cur; | |
4796 | |
4797 gtk_tree_store_append(gtkblist->treemodel, &iter, &groupiter); | |
4798 return iter; | |
4799 } else { | |
4800 return sort_method_none(node, blist, groupiter, cur); | |
4801 } | |
4802 | |
4803 | |
4804 if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(gtkblist->treemodel), &more_z, &groupiter)) { | |
4805 gtk_tree_store_insert(gtkblist->treemodel, &iter, &groupiter, 0); | |
5422 | 4806 return iter; |
4807 } | |
4808 | |
4809 do { | |
9944 | 4810 gint name_cmp; |
4811 gint presence_cmp; | |
7620 | 4812 |
5422 | 4813 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &more_z, NODE_COLUMN, &val); |
4814 n = g_value_get_pointer(&val); | |
7620 | 4815 |
4816 if(GAIM_BLIST_NODE_IS_CONTACT(n)) { | |
4817 this_buddy = gaim_contact_get_priority_buddy((GaimContact*)n); | |
4818 } else { | |
4819 this_buddy = NULL; | |
4820 } | |
4821 | |
9944 | 4822 name_cmp = gaim_utf8_strcasecmp( |
4823 (my_buddy | |
4824 ? gaim_contact_get_alias(gaim_buddy_get_contact(my_buddy)) | |
4825 : NULL), | |
4826 (this_buddy | |
4827 ? gaim_contact_get_alias(gaim_buddy_get_contact(this_buddy)) | |
4828 : NULL)); | |
4829 | |
4830 presence_cmp = gaim_presence_compare( | |
4831 gaim_buddy_get_presence(my_buddy), | |
4832 gaim_buddy_get_presence(this_buddy)); | |
4833 | |
4834 if (this_buddy == NULL || | |
10860 | 4835 (presence_cmp < 0 || |
9944 | 4836 (presence_cmp == 0 && |
4837 (name_cmp < 0 || (name_cmp == 0 && node < n))))) | |
4838 { | |
4839 if (cur != NULL) | |
4840 { | |
7620 | 4841 gtk_tree_store_move_before(gtkblist->treemodel, cur, &more_z); |
4842 return *cur; | |
9944 | 4843 } |
4844 else | |
4845 { | |
7620 | 4846 gtk_tree_store_insert_before(gtkblist->treemodel, &iter, |
9944 | 4847 &groupiter, &more_z); |
7620 | 4848 return iter; |
4849 } | |
5422 | 4850 } |
9944 | 4851 |
5422 | 4852 g_value_unset(&val); |
9944 | 4853 } |
4854 while (gtk_tree_model_iter_next(GTK_TREE_MODEL(gtkblist->treemodel), | |
4855 &more_z)); | |
7620 | 4856 |
4857 if(cur) { | |
4858 gtk_tree_store_move_before(gtkblist->treemodel, cur, NULL); | |
4859 return *cur; | |
4860 } else { | |
4861 gtk_tree_store_append(gtkblist->treemodel, &iter, &groupiter); | |
4862 return iter; | |
4863 } | |
5422 | 4864 } |
4865 | |
7620 | 4866 static GtkTreeIter sort_method_log(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur) |
5422 | 4867 { |
4868 GtkTreeIter more_z, iter; | |
7620 | 4869 GaimBlistNode *n = NULL, *n2; |
5422 | 4870 GValue val = {0,}; |
7620 | 4871 |
4872 int log_size = 0, this_log_size = 0; | |
4873 const char *buddy_name, *this_buddy_name; | |
4874 | |
4875 if(cur && (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(gtkblist->treemodel), &groupiter) == 1)) | |
4876 return *cur; | |
4877 | |
4878 if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
4879 for (n = node->child; n; n = n->next) | |
8898 | 4880 log_size += gaim_log_get_total_size(GAIM_LOG_IM, ((GaimBuddy*)(n))->name, ((GaimBuddy*)(n))->account); |
7620 | 4881 buddy_name = gaim_contact_get_alias((GaimContact*)node); |
4882 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) { | |
4883 /* we don't have a reliable way of getting the log filename | |
4884 * from the chat info in the blist, yet */ | |
4885 if(cur) | |
4886 return *cur; | |
4887 | |
4888 gtk_tree_store_append(gtkblist->treemodel, &iter, &groupiter); | |
4889 return iter; | |
4890 } else { | |
4891 return sort_method_none(node, blist, groupiter, cur); | |
4892 } | |
4893 | |
4894 | |
5422 | 4895 if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(gtkblist->treemodel), &more_z, &groupiter)) { |
4896 gtk_tree_store_insert(gtkblist->treemodel, &iter, &groupiter, 0); | |
4897 return iter; | |
4898 } | |
4899 | |
4900 do { | |
7620 | 4901 int cmp; |
4902 | |
5422 | 4903 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &more_z, NODE_COLUMN, &val); |
4904 n = g_value_get_pointer(&val); | |
7620 | 4905 this_log_size = 0; |
4906 | |
4907 if(GAIM_BLIST_NODE_IS_CONTACT(n)) { | |
4908 for (n2 = n->child; n2; n2 = n2->next) | |
8898 | 4909 this_log_size += gaim_log_get_total_size(GAIM_LOG_IM, ((GaimBuddy*)(n2))->name, ((GaimBuddy*)(n2))->account); |
7620 | 4910 this_buddy_name = gaim_contact_get_alias((GaimContact*)n); |
4911 } else { | |
4912 this_buddy_name = NULL; | |
5422 | 4913 } |
7620 | 4914 |
4915 cmp = gaim_utf8_strcasecmp(buddy_name, this_buddy_name); | |
4916 | |
4917 if (!GAIM_BLIST_NODE_IS_CONTACT(n) || log_size > this_log_size || | |
4918 ((log_size == this_log_size) && | |
4919 (cmp < 0 || (cmp == 0 && node < n)))) { | |
4920 if(cur) { | |
4921 gtk_tree_store_move_before(gtkblist->treemodel, cur, &more_z); | |
4922 return *cur; | |
4923 } else { | |
4924 gtk_tree_store_insert_before(gtkblist->treemodel, &iter, | |
4925 &groupiter, &more_z); | |
4926 return iter; | |
4927 } | |
5422 | 4928 } |
4929 g_value_unset(&val); | |
4930 } while (gtk_tree_model_iter_next (GTK_TREE_MODEL(gtkblist->treemodel), &more_z)); | |
7620 | 4931 |
4932 if(cur) { | |
4933 gtk_tree_store_move_before(gtkblist->treemodel, cur, NULL); | |
4934 return *cur; | |
4935 } else { | |
4936 gtk_tree_store_append(gtkblist->treemodel, &iter, &groupiter); | |
4937 return iter; | |
4938 } | |
4939 } | |
4940 | |
4941 #endif | |
4942 | |
4943 static void | |
9015 | 4944 plugin_act(GtkObject *obk, GaimPluginAction *pam) |
7620 | 4945 { |
10352 | 4946 if (pam->callback) |
4947 pam->callback(pam); | |
5422 | 4948 } |
7620 | 4949 |
11742 | 4950 static GList *plugin_menu_items = NULL; |
4951 static int plugin_menu_index = 8; | |
4952 | |
8986 | 4953 static void |
9015 | 4954 build_plugin_actions(GtkWidget *menu, GaimPlugin *plugin, gpointer context) |
8986 | 4955 { |
9015 | 4956 GtkWidget *menuitem = NULL; |
4957 GaimPluginAction *action = NULL; | |
4958 GList *l, *ll; | |
4959 | |
4960 for (l = ll = GAIM_PLUGIN_ACTIONS(plugin, context); l; l = l->next) { | |
4961 if (l->data) { | |
4962 action = (GaimPluginAction *) l->data; | |
4963 action->plugin = plugin; | |
4964 action->context = context; | |
4965 | |
4966 menuitem = gtk_menu_item_new_with_label(action->label); | |
11745 | 4967 if (context) { |
4968 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | |
4969 } else { | |
4970 plugin_menu_items = g_list_append(plugin_menu_items, menuitem); | |
4971 plugin_menu_index++; | |
4972 gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, plugin_menu_index); | |
4973 } | |
9015 | 4974 g_signal_connect(G_OBJECT(menuitem), "activate", |
4975 G_CALLBACK(plugin_act), action); | |
4976 g_object_set_data(G_OBJECT(menuitem), "plugin_action", action); | |
4977 gtk_widget_show(menuitem); | |
4978 } | |
4979 else | |
4980 gaim_separator(menu); | |
4981 } | |
4982 | |
4983 g_list_free(ll); | |
8986 | 4984 } |
4985 | |
4986 | |
7620 | 4987 void |
4988 gaim_gtk_blist_update_protocol_actions(void) | |
4989 { | |
9015 | 4990 GtkWidget *menuitem, *submenu; |
7620 | 4991 GList *l; |
4992 GaimConnection *gc = NULL; | |
9015 | 4993 GaimPlugin *plugin = NULL; |
7620 | 4994 int count = 0; |
9015 | 4995 |
9019 | 4996 if (protomenu == NULL) |
7620 | 4997 return; |
4998 | |
9019 | 4999 /* Clear the old Account Actions menu */ |
9015 | 5000 for (l = gtk_container_get_children(GTK_CONTAINER(protomenu)); l; l = l->next) { |
5001 GaimPluginAction *action; | |
9987 | 5002 |
7620 | 5003 menuitem = l->data; |
9015 | 5004 action = (GaimPluginAction *) g_object_get_data(G_OBJECT(menuitem), |
5005 "plugin_action"); | |
5006 g_free(action); | |
7620 | 5007 |
5008 gtk_container_remove(GTK_CONTAINER(protomenu), GTK_WIDGET(menuitem)); | |
5009 } | |
5010 | |
9019 | 5011 /* Count the number of accounts with actions */ |
9015 | 5012 for (l = gaim_connections_get_all(); l; l = l->next) { |
5013 gc = l->data; | |
5014 plugin = gc->prpl; | |
5015 | |
9019 | 5016 if (GAIM_CONNECTION_IS_CONNECTED(gc) && GAIM_PLUGIN_HAS_ACTIONS(plugin)) |
5017 count++; | |
5018 | |
9015 | 5019 /* no need to count past 2, so don't */ |
9019 | 5020 if (count > 1) |
9015 | 5021 break; |
7620 | 5022 } |
5023 | |
9015 | 5024 if (count == 0) { |
5025 menuitem = gtk_menu_item_new_with_label(_("No actions available")); | |
7620 | 5026 gtk_menu_shell_append(GTK_MENU_SHELL(protomenu), menuitem); |
9015 | 5027 gtk_widget_set_sensitive(menuitem, FALSE); |
7620 | 5028 gtk_widget_show(menuitem); |
5029 } | |
9019 | 5030 |
5031 else if (count == 1) { | |
5032 /* Find the one account that has actions */ | |
5033 for (l = gaim_connections_get_all(); l; l = l->next) { | |
5034 gc = l->data; | |
5035 plugin = gc->prpl; | |
5036 | |
5037 if (GAIM_CONNECTION_IS_CONNECTED(gc) && GAIM_PLUGIN_HAS_ACTIONS(plugin)) | |
5038 break; | |
5039 } | |
5040 | |
9015 | 5041 build_plugin_actions(protomenu, plugin, gc); |
7620 | 5042 } |
9019 | 5043 |
7620 | 5044 else { |
9015 | 5045 for (l = gaim_connections_get_all(); l; l = l->next) { |
7620 | 5046 GaimAccount *account; |
5047 GdkPixbuf *pixbuf, *scale; | |
5048 GtkWidget *image; | |
9015 | 5049 char *buf; |
5050 | |
5051 gc = l->data; | |
5052 plugin = gc->prpl; | |
5053 | |
9019 | 5054 if (!GAIM_CONNECTION_IS_CONNECTED(gc) || !GAIM_PLUGIN_HAS_ACTIONS(plugin)) |
7620 | 5055 continue; |
5056 | |
5057 account = gaim_connection_get_account(gc); | |
9015 | 5058 buf = g_strconcat(gaim_account_get_username(account), " (", |
5059 plugin->info->name, ")", NULL); | |
7620 | 5060 menuitem = gtk_image_menu_item_new_with_label(buf); |
9015 | 5061 g_free(buf); |
5062 | |
10884 | 5063 pixbuf = gaim_gtk_create_prpl_icon(account); |
9019 | 5064 if (pixbuf) { |
7620 | 5065 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, |
5066 GDK_INTERP_BILINEAR); | |
5067 image = gtk_image_new_from_pixbuf(scale); | |
5068 g_object_unref(G_OBJECT(pixbuf)); | |
5069 g_object_unref(G_OBJECT(scale)); | |
5070 gtk_widget_show(image); | |
9015 | 5071 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); |
7620 | 5072 } |
5073 | |
5074 gtk_menu_shell_append(GTK_MENU_SHELL(protomenu), menuitem); | |
5075 gtk_widget_show(menuitem); | |
5076 | |
5077 submenu = gtk_menu_new(); | |
5078 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); | |
5079 gtk_widget_show(submenu); | |
5080 | |
9015 | 5081 build_plugin_actions(submenu, plugin, gc); |
7620 | 5082 } |
5083 } | |
5084 } | |
8986 | 5085 |
5086 void | |
5087 gaim_gtk_blist_update_plugin_actions(void) | |
5088 { | |
11742 | 5089 GtkWidget *menuitem; |
9015 | 5090 GaimPlugin *plugin = NULL; |
8986 | 5091 GList *l; |
5092 int count = 0; | |
5093 | |
11742 | 5094 GtkWidget *pluginmenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools")); |
5095 | |
9019 | 5096 if (pluginmenu == NULL) |
8986 | 5097 return; |
5098 | |
9019 | 5099 /* Clear the old Account Actions menu */ |
11742 | 5100 for (l = plugin_menu_items; l; l = l->next) { |
9015 | 5101 GaimPluginAction *action; |
11742 | 5102 plugin_menu_index--; |
8986 | 5103 menuitem = l->data; |
9015 | 5104 action = g_object_get_data(G_OBJECT(menuitem), "plugin_action"); |
5105 g_free(action); | |
8986 | 5106 |
5107 gtk_container_remove(GTK_CONTAINER(pluginmenu), GTK_WIDGET(menuitem)); | |
5108 } | |
11742 | 5109 g_list_free(plugin_menu_items); |
5110 plugin_menu_items = NULL; | |
8986 | 5111 |
9019 | 5112 /* Count the number of plugins with actions */ |
9015 | 5113 for (l = gaim_plugins_get_loaded(); l; l = l->next) { |
5114 plugin = (GaimPlugin *) l->data; | |
5115 | |
9019 | 5116 if (!GAIM_IS_PROTOCOL_PLUGIN(plugin) && GAIM_PLUGIN_HAS_ACTIONS(plugin)) |
5117 count++; | |
5118 | |
5119 /* no need to count past 2, so don't */ | |
5120 if (count > 1) | |
9015 | 5121 break; |
8986 | 5122 } |
5123 | |
11742 | 5124 for (l = gaim_plugins_get_loaded(); l; l = l->next) { |
5125 | |
5126 plugin = (GaimPlugin *) l->data; | |
5127 | |
5128 if (GAIM_IS_PROTOCOL_PLUGIN(plugin)) | |
5129 continue; | |
5130 | |
5131 if (!GAIM_PLUGIN_HAS_ACTIONS(plugin)) | |
5132 continue; | |
9019 | 5133 |
9015 | 5134 build_plugin_actions(pluginmenu, plugin, NULL); |
11742 | 5135 |
8986 | 5136 } |
5137 } | |
11796 | 5138 |
5139 void sortmethod_act(GtkCheckMenuItem *checkmenuitem, char *id) | |
5140 { | |
5141 if (gtk_check_menu_item_get_active(checkmenuitem)) | |
5142 gaim_gtk_blist_sort_method_set(id); | |
5143 } | |
5144 | |
5145 void | |
5146 gaim_gtk_blist_update_sort_methods(void) | |
5147 { | |
5148 GtkWidget *menuitem = NULL, *activeitem = NULL; | |
5149 GaimGtkBlistSortMethod *method = NULL; | |
5150 GList *l; | |
5151 GSList *sl = NULL; | |
5152 GtkWidget *sortmenu; | |
11797 | 5153 const char *m = gaim_prefs_get_string("/gaim/gtk/blist/sort_type"); |
11796 | 5154 |
5155 if (gtkblist == NULL) | |
5156 return; | |
5157 | |
11798
01c3eec6ea3c
[gaim-migrate @ 14089]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11797
diff
changeset
|
5158 sortmenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Buddies/Sort Buddies")); |
11796 | 5159 |
5160 if (sortmenu == NULL) | |
5161 return; | |
5162 | |
5163 /* Clear the old menu */ | |
5164 for (l = gtk_container_get_children(GTK_CONTAINER(sortmenu)); l; l = l->next) { | |
5165 menuitem = l->data; | |
5166 gtk_widget_destroy(GTK_WIDGET(menuitem)); | |
5167 } | |
5168 | |
5169 for (l = gaim_gtk_blist_sort_methods; l; l = l->next) { | |
5170 method = (GaimGtkBlistSortMethod *) l->data; | |
5171 menuitem = gtk_radio_menu_item_new_with_label(sl, _(method->name)); | |
5172 if (!strcmp(m, method->id)) | |
5173 activeitem = menuitem; | |
5174 sl = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(menuitem)); | |
5175 gtk_menu_shell_append(GTK_MENU_SHELL(sortmenu), menuitem); | |
5176 g_signal_connect(G_OBJECT(menuitem), "toggled", | |
5177 G_CALLBACK(sortmethod_act), method->id); | |
5178 gtk_widget_show(menuitem); | |
5179 } | |
5180 if (activeitem) | |
5181 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(activeitem), TRUE); | |
5182 | |
5183 } |