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