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