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