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