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