Mercurial > pidgin.yaz
annotate finch/gntblist.c @ 17789:f13334f5717e
show the "Retrieving..." window whenever we request user info. Fixes #1617.
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Sun, 10 Jun 2007 15:50:19 +0000 |
parents | 29b3dc9cc8c5 |
children | 995f31f5432a |
rev | line source |
---|---|
15818 | 1 /** |
2 * @file gntblist.c GNT BuddyList API | |
16194
0f0832c13fcb
Rename the Doxygen group from gntui to finch and define the finch group
Richard Laager <rlaager@wiktel.com>
parents:
16106
diff
changeset
|
3 * @ingroup finch |
15818 | 4 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15844
diff
changeset
|
5 * finch |
15818 | 6 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15844
diff
changeset
|
7 * Finch is the legal property of its developers, whose names are too numerous |
15818 | 8 * to list here. Please refer to the COPYRIGHT file distributed with this |
9 * source distribution. | |
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 #include <account.h> | |
26 #include <blist.h> | |
27 #include <notify.h> | |
28 #include <request.h> | |
29 #include <savedstatuses.h> | |
30 #include <server.h> | |
31 #include <signal.h> | |
32 #include <status.h> | |
33 #include <util.h> | |
34 #include "debug.h" | |
35 | |
15823 | 36 #include "finch.h" |
15818 | 37 #include "gntbox.h" |
38 #include "gntcombobox.h" | |
39 #include "gntentry.h" | |
40 #include "gntft.h" | |
41 #include "gntlabel.h" | |
42 #include "gntline.h" | |
43 #include "gntmenu.h" | |
44 #include "gntmenuitem.h" | |
45 #include "gntmenuitemcheck.h" | |
46 #include "gntpounce.h" | |
47 #include "gnttree.h" | |
48 #include "gntutils.h" | |
49 #include "gntwindow.h" | |
50 | |
51 #include "gntblist.h" | |
52 #include "gntconv.h" | |
53 #include "gntstatus.h" | |
54 #include <string.h> | |
55 | |
16427
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16276
diff
changeset
|
56 #define PREF_ROOT "/finch/blist" |
15818 | 57 #define TYPING_TIMEOUT 4000 |
58 | |
59 typedef struct | |
60 { | |
61 GntWidget *window; | |
62 GntWidget *tree; | |
63 | |
64 GntWidget *tooltip; | |
15823 | 65 PurpleBlistNode *tnode; /* Who is the tooltip being displayed for? */ |
15818 | 66 GList *tagged; /* A list of tagged blistnodes */ |
67 | |
68 GntWidget *context; | |
15823 | 69 PurpleBlistNode *cnode; |
15818 | 70 |
71 /* XXX: I am KISSing */ | |
72 GntWidget *status; /* Dropdown with the statuses */ | |
73 GntWidget *statustext; /* Status message */ | |
74 int typing; | |
75 | |
76 GntWidget *menu; | |
77 /* These are the menuitems that get regenerated */ | |
78 GntMenuItem *accounts; | |
79 GntMenuItem *plugins; | |
80 } FinchBlist; | |
81 | |
82 typedef enum | |
83 { | |
84 STATUS_PRIMITIVE = 0, | |
85 STATUS_SAVED_POPULAR, | |
86 STATUS_SAVED_ALL, | |
87 STATUS_SAVED_NEW | |
88 } StatusType; | |
89 | |
90 typedef struct | |
91 { | |
92 StatusType type; | |
93 union | |
94 { | |
15823 | 95 PurpleStatusPrimitive prim; |
96 PurpleSavedStatus *saved; | |
15818 | 97 } u; |
98 } StatusBoxItem; | |
99 | |
100 FinchBlist *ggblist; | |
101 | |
15823 | 102 static void add_buddy(PurpleBuddy *buddy, FinchBlist *ggblist); |
103 static void add_contact(PurpleContact *contact, FinchBlist *ggblist); | |
104 static void add_group(PurpleGroup *group, FinchBlist *ggblist); | |
105 static void add_chat(PurpleChat *chat, FinchBlist *ggblist); | |
106 static void add_node(PurpleBlistNode *node, FinchBlist *ggblist); | |
15818 | 107 static void draw_tooltip(FinchBlist *ggblist); |
108 static gboolean remove_typing_cb(gpointer null); | |
109 static void remove_peripherals(FinchBlist *ggblist); | |
15823 | 110 static const char * get_display_name(PurpleBlistNode *node); |
111 static void savedstatus_changed(PurpleSavedStatus *now, PurpleSavedStatus *old); | |
112 static void blist_show(PurpleBuddyList *list); | |
16575
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
113 static void update_node_display(PurpleBlistNode *buddy, FinchBlist *ggblist); |
15823 | 114 static void update_buddy_display(PurpleBuddy *buddy, FinchBlist *ggblist); |
16782
d7ad8013b914
Fix this spectacularly braindead code. I must've been on the good stuff when I wrote this. Fixes #364.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16663
diff
changeset
|
115 static void account_signed_on_cb(PurpleConnection *pc, gpointer null); |
17254
0d9fba04fc85
Re-show the add buddy request dialog if something went wrong. It's easy to lose the buddy who just added you otherwise.
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
116 static void finch_request_add_buddy(PurpleAccount *account, const char *username, const char *grp, const char *alias); |
15818 | 117 |
118 /* Sort functions */ | |
16491
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
119 static int blist_node_compare_position(PurpleBlistNode *n1, PurpleBlistNode *n2); |
15823 | 120 static int blist_node_compare_text(PurpleBlistNode *n1, PurpleBlistNode *n2); |
121 static int blist_node_compare_status(PurpleBlistNode *n1, PurpleBlistNode *n2); | |
122 static int blist_node_compare_log(PurpleBlistNode *n1, PurpleBlistNode *n2); | |
15818 | 123 |
124 static gboolean | |
15823 | 125 is_contact_online(PurpleContact *contact) |
15818 | 126 { |
15823 | 127 PurpleBlistNode *node; |
128 for (node = ((PurpleBlistNode*)contact)->child; node; node = node->next) { | |
129 if (PURPLE_BUDDY_IS_ONLINE((PurpleBuddy*)node)) | |
15818 | 130 return TRUE; |
131 } | |
132 return FALSE; | |
133 } | |
134 | |
135 static gboolean | |
15823 | 136 is_group_online(PurpleGroup *group) |
15818 | 137 { |
15823 | 138 PurpleBlistNode *node; |
139 for (node = ((PurpleBlistNode*)group)->child; node; node = node->next) { | |
140 if (PURPLE_BLIST_NODE_IS_CHAT(node)) | |
15818 | 141 return TRUE; |
15823 | 142 else if (is_contact_online((PurpleContact*)node)) |
15818 | 143 return TRUE; |
144 } | |
145 return FALSE; | |
146 } | |
147 | |
148 static void | |
15823 | 149 new_node(PurpleBlistNode *node) |
15818 | 150 { |
151 } | |
152 | |
15823 | 153 static void add_node(PurpleBlistNode *node, FinchBlist *ggblist) |
15818 | 154 { |
15823 | 155 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) |
156 add_buddy((PurpleBuddy*)node, ggblist); | |
157 else if (PURPLE_BLIST_NODE_IS_CONTACT(node)) | |
158 add_contact((PurpleContact*)node, ggblist); | |
159 else if (PURPLE_BLIST_NODE_IS_GROUP(node)) | |
160 add_group((PurpleGroup*)node, ggblist); | |
161 else if (PURPLE_BLIST_NODE_IS_CHAT(node)) | |
162 add_chat((PurpleChat *)node, ggblist); | |
15818 | 163 draw_tooltip(ggblist); |
164 } | |
165 | |
166 static void | |
167 remove_tooltip(FinchBlist *ggblist) | |
168 { | |
169 gnt_widget_destroy(ggblist->tooltip); | |
170 ggblist->tooltip = NULL; | |
171 ggblist->tnode = NULL; | |
172 } | |
173 | |
174 static void | |
15823 | 175 node_remove(PurpleBuddyList *list, PurpleBlistNode *node) |
15818 | 176 { |
177 FinchBlist *ggblist = list->ui_data; | |
178 | |
179 if (ggblist == NULL || node->ui_data == NULL) | |
180 return; | |
181 | |
182 gnt_tree_remove(GNT_TREE(ggblist->tree), node); | |
183 node->ui_data = NULL; | |
184 if (ggblist->tagged) | |
185 ggblist->tagged = g_list_remove(ggblist->tagged, node); | |
186 | |
15823 | 187 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { |
188 PurpleContact *contact = (PurpleContact*)node->parent; | |
189 if ((!purple_prefs_get_bool(PREF_ROOT "/showoffline") && !is_contact_online(contact)) || | |
15818 | 190 contact->currentsize < 1) |
15823 | 191 node_remove(list, (PurpleBlistNode*)contact); |
16575
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
192 } else if (!PURPLE_BLIST_NODE_IS_GROUP(node)) { |
15823 | 193 PurpleGroup *group = (PurpleGroup*)node->parent; |
194 if ((!purple_prefs_get_bool(PREF_ROOT "/showoffline") && !is_group_online(group)) || | |
15818 | 195 group->currentsize < 1) |
196 node_remove(list, node->parent); | |
197 for (node = node->child; node; node = node->next) | |
198 node->ui_data = NULL; | |
16575
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
199 } else { |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
200 for (node = node->child; node; node = node->next) |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
201 node_remove(list, node); |
15818 | 202 } |
203 | |
204 draw_tooltip(ggblist); | |
205 } | |
206 | |
207 static void | |
15823 | 208 node_update(PurpleBuddyList *list, PurpleBlistNode *node) |
15818 | 209 { |
210 /* It really looks like this should never happen ... but it does. | |
211 This will at least emit a warning to the log when it | |
212 happens, so maybe someone will figure it out. */ | |
213 g_return_if_fail(node != NULL); | |
214 | |
215 if (list->ui_data == NULL) | |
216 return; /* XXX: this is probably the place to auto-join chats */ | |
217 | |
218 if (node->ui_data != NULL) { | |
219 gnt_tree_change_text(GNT_TREE(ggblist->tree), node, | |
220 0, get_display_name(node)); | |
221 gnt_tree_sort_row(GNT_TREE(ggblist->tree), node); | |
222 } | |
223 | |
15823 | 224 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { |
225 PurpleBuddy *buddy = (PurpleBuddy*)node; | |
226 if (purple_account_is_connected(buddy->account) && | |
227 (PURPLE_BUDDY_IS_ONLINE(buddy) || purple_prefs_get_bool(PREF_ROOT "/showoffline"))) | |
228 add_node((PurpleBlistNode*)buddy, list->ui_data); | |
15818 | 229 else |
15823 | 230 node_remove(purple_get_blist(), node); |
15818 | 231 |
232 node_update(list, node->parent); | |
15823 | 233 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) { |
234 add_chat((PurpleChat *)node, list->ui_data); | |
235 } else if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { | |
236 PurpleContact *contact = (PurpleContact*)node; | |
237 if ((!purple_prefs_get_bool(PREF_ROOT "/showoffline") && !is_contact_online(contact)) || | |
15818 | 238 contact->currentsize < 1) |
15823 | 239 node_remove(purple_get_blist(), node); |
16575
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
240 else { |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
241 if (node->ui_data == NULL) { |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
242 /* The core seems to expect the UI to add the buddies. */ |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
243 for (node = node->child; node; node = node->next) |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
244 add_node(node, list->ui_data); |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
245 } |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
246 } |
15823 | 247 } else if (PURPLE_BLIST_NODE_IS_GROUP(node)) { |
248 PurpleGroup *group = (PurpleGroup*)node; | |
249 if ((!purple_prefs_get_bool(PREF_ROOT "/showoffline") && !is_group_online(group)) || | |
15818 | 250 group->currentsize < 1) |
251 node_remove(list, node); | |
16575
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
252 else |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
253 add_node(node, list->ui_data); |
15818 | 254 } |
255 } | |
256 | |
257 static void | |
15823 | 258 new_list(PurpleBuddyList *list) |
15818 | 259 { |
260 if (ggblist) | |
261 return; | |
262 | |
263 ggblist = g_new0(FinchBlist, 1); | |
264 list->ui_data = ggblist; | |
265 } | |
266 | |
267 static void | |
15823 | 268 add_buddy_cb(void *data, PurpleRequestFields *allfields) |
15818 | 269 { |
15823 | 270 const char *username = purple_request_fields_get_string(allfields, "screenname"); |
271 const char *alias = purple_request_fields_get_string(allfields, "alias"); | |
272 const char *group = purple_request_fields_get_string(allfields, "group"); | |
273 PurpleAccount *account = purple_request_fields_get_account(allfields, "account"); | |
15818 | 274 const char *error = NULL; |
15823 | 275 PurpleGroup *grp; |
276 PurpleBuddy *buddy; | |
15818 | 277 |
278 if (!username) | |
279 error = _("You must provide a screename for the buddy."); | |
280 else if (!group) | |
281 error = _("You must provide a group."); | |
282 else if (!account) | |
283 error = _("You must select an account."); | |
16937
7e4a22162bb6
Show an error message when trying to add a buddy from an offline account.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16936
diff
changeset
|
284 else if (!purple_account_is_connected(account)) |
7e4a22162bb6
Show an error message when trying to add a buddy from an offline account.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16936
diff
changeset
|
285 error = _("The selected account is not online."); |
15818 | 286 |
287 if (error) | |
288 { | |
17254
0d9fba04fc85
Re-show the add buddy request dialog if something went wrong. It's easy to lose the buddy who just added you otherwise.
Richard Nelson <wabz@pidgin.im>
parents:
17104
diff
changeset
|
289 finch_request_add_buddy(account, username, group, alias); |
15823 | 290 purple_notify_error(NULL, _("Error"), _("Error adding buddy"), error); |
15818 | 291 return; |
292 } | |
293 | |
15823 | 294 grp = purple_find_group(group); |
15818 | 295 if (!grp) |
296 { | |
15823 | 297 grp = purple_group_new(group); |
298 purple_blist_add_group(grp, NULL); | |
15818 | 299 } |
300 | |
15823 | 301 buddy = purple_buddy_new(account, username, alias); |
302 purple_blist_add_buddy(buddy, NULL, grp, NULL); | |
303 purple_account_add_buddy(account, buddy); | |
15818 | 304 } |
305 | |
306 static void | |
15823 | 307 finch_request_add_buddy(PurpleAccount *account, const char *username, const char *grp, const char *alias) |
15818 | 308 { |
15823 | 309 PurpleRequestFields *fields = purple_request_fields_new(); |
310 PurpleRequestFieldGroup *group = purple_request_field_group_new(NULL); | |
311 PurpleRequestField *field; | |
15818 | 312 |
15823 | 313 purple_request_fields_add_group(fields, group); |
15818 | 314 |
15823 | 315 field = purple_request_field_string_new("screenname", _("Screen Name"), username, FALSE); |
316 purple_request_field_group_add_field(group, field); | |
15818 | 317 |
15823 | 318 field = purple_request_field_string_new("alias", _("Alias"), alias, FALSE); |
319 purple_request_field_group_add_field(group, field); | |
15818 | 320 |
15823 | 321 field = purple_request_field_string_new("group", _("Group"), grp, FALSE); |
322 purple_request_field_group_add_field(group, field); | |
15844
e74c2488448b
Group autocomplete for buddy adding
Richard Nelson <wabz@pidgin.im>
parents:
15823
diff
changeset
|
323 purple_request_field_set_type_hint(field, "group"); |
15818 | 324 |
15823 | 325 field = purple_request_field_account_new("account", _("Account"), NULL); |
326 purple_request_field_account_set_show_all(field, FALSE); | |
15818 | 327 if (account) |
15823 | 328 purple_request_field_account_set_value(field, account); |
329 purple_request_field_group_add_field(group, field); | |
15818 | 330 |
15823 | 331 purple_request_fields(NULL, _("Add Buddy"), NULL, _("Please enter buddy information."), |
16442
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
332 fields, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
333 _("Add"), G_CALLBACK(add_buddy_cb), |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
334 _("Cancel"), NULL, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
335 account, NULL, NULL, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
336 NULL); |
15818 | 337 } |
338 | |
339 static void | |
15823 | 340 add_chat_cb(void *data, PurpleRequestFields *allfields) |
15818 | 341 { |
15823 | 342 PurpleAccount *account; |
15818 | 343 const char *alias, *name, *group; |
15823 | 344 PurpleChat *chat; |
345 PurpleGroup *grp; | |
15818 | 346 GHashTable *hash = NULL; |
15823 | 347 PurpleConnection *gc; |
15818 | 348 |
15823 | 349 account = purple_request_fields_get_account(allfields, "account"); |
350 name = purple_request_fields_get_string(allfields, "name"); | |
351 alias = purple_request_fields_get_string(allfields, "alias"); | |
352 group = purple_request_fields_get_string(allfields, "group"); | |
15818 | 353 |
15823 | 354 if (!purple_account_is_connected(account) || !name || !*name) |
15818 | 355 return; |
356 | |
357 if (!group || !*group) | |
358 group = _("Chats"); | |
359 | |
15823 | 360 gc = purple_account_get_connection(account); |
15818 | 361 |
15823 | 362 if (PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults != NULL) |
363 hash = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, name); | |
15818 | 364 |
15823 | 365 chat = purple_chat_new(account, name, hash); |
15818 | 366 |
367 if (chat != NULL) { | |
15823 | 368 if ((grp = purple_find_group(group)) == NULL) { |
369 grp = purple_group_new(group); | |
370 purple_blist_add_group(grp, NULL); | |
15818 | 371 } |
15823 | 372 purple_blist_add_chat(chat, grp, NULL); |
373 purple_blist_alias_chat(chat, alias); | |
15818 | 374 } |
375 } | |
376 | |
377 static void | |
15823 | 378 finch_request_add_chat(PurpleAccount *account, PurpleGroup *grp, const char *alias, const char *name) |
15818 | 379 { |
15823 | 380 PurpleRequestFields *fields = purple_request_fields_new(); |
381 PurpleRequestFieldGroup *group = purple_request_field_group_new(NULL); | |
382 PurpleRequestField *field; | |
15818 | 383 |
15823 | 384 purple_request_fields_add_group(fields, group); |
15818 | 385 |
15823 | 386 field = purple_request_field_account_new("account", _("Account"), NULL); |
387 purple_request_field_account_set_show_all(field, FALSE); | |
15818 | 388 if (account) |
15823 | 389 purple_request_field_account_set_value(field, account); |
390 purple_request_field_group_add_field(group, field); | |
15818 | 391 |
15823 | 392 field = purple_request_field_string_new("name", _("Name"), name, FALSE); |
393 purple_request_field_group_add_field(group, field); | |
15818 | 394 |
15823 | 395 field = purple_request_field_string_new("alias", _("Alias"), alias, FALSE); |
396 purple_request_field_group_add_field(group, field); | |
15818 | 397 |
15823 | 398 field = purple_request_field_string_new("group", _("Group"), grp ? grp->name : NULL, FALSE); |
399 purple_request_field_group_add_field(group, field); | |
15818 | 400 |
15823 | 401 purple_request_fields(NULL, _("Add Chat"), NULL, |
15818 | 402 _("You can edit more information from the context menu later."), |
16442
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
403 fields, _("Add"), G_CALLBACK(add_chat_cb), _("Cancel"), NULL, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
404 NULL, NULL, NULL, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
405 NULL); |
15818 | 406 } |
407 | |
408 static void | |
409 add_group_cb(gpointer null, const char *group) | |
410 { | |
15823 | 411 PurpleGroup *grp; |
15818 | 412 |
413 if (!group || !*group) | |
414 { | |
15823 | 415 purple_notify_error(NULL, _("Error"), _("Error adding group"), |
15818 | 416 _("You must give a name for the group to add.")); |
417 return; | |
418 } | |
419 | |
15823 | 420 grp = purple_find_group(group); |
15818 | 421 if (!grp) |
422 { | |
15823 | 423 grp = purple_group_new(group); |
424 purple_blist_add_group(grp, NULL); | |
15818 | 425 } |
426 else | |
427 { | |
15823 | 428 purple_notify_error(NULL, _("Error"), _("Error adding group"), |
15818 | 429 _("A group with the name already exists.")); |
430 } | |
431 } | |
432 | |
433 static void | |
434 finch_request_add_group() | |
435 { | |
15823 | 436 purple_request_input(NULL, _("Add Group"), NULL, _("Enter the name of the group"), |
15818 | 437 NULL, FALSE, FALSE, NULL, |
16442
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
438 _("Add"), G_CALLBACK(add_group_cb), _("Cancel"), NULL, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
439 NULL, NULL, NULL, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
440 NULL); |
15818 | 441 } |
442 | |
15823 | 443 static PurpleBlistUiOps blist_ui_ops = |
15818 | 444 { |
445 new_list, | |
446 new_node, | |
447 blist_show, | |
448 node_update, | |
449 node_remove, | |
450 NULL, | |
451 NULL, | |
17104
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16969
diff
changeset
|
452 finch_request_add_buddy, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16969
diff
changeset
|
453 finch_request_add_chat, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16969
diff
changeset
|
454 finch_request_add_group, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16969
diff
changeset
|
455 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16969
diff
changeset
|
456 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16969
diff
changeset
|
457 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16969
diff
changeset
|
458 NULL |
15818 | 459 }; |
460 | |
461 static gpointer | |
462 finch_blist_get_handle() | |
463 { | |
464 static int handle; | |
465 | |
466 return &handle; | |
467 } | |
468 | |
469 static void | |
15823 | 470 add_group(PurpleGroup *group, FinchBlist *ggblist) |
15818 | 471 { |
15823 | 472 PurpleBlistNode *node = (PurpleBlistNode *)group; |
15818 | 473 if (node->ui_data) |
474 return; | |
475 node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), group, | |
476 gnt_tree_create_row(GNT_TREE(ggblist->tree), get_display_name(node)), NULL, NULL); | |
16105
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
477 gnt_tree_set_expanded(GNT_TREE(ggblist->tree), node, |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
478 !purple_blist_node_get_bool(node, "collapsed")); |
15818 | 479 } |
480 | |
481 static const char * | |
15823 | 482 get_display_name(PurpleBlistNode *node) |
15818 | 483 { |
484 static char text[2096]; | |
485 char status[8] = " "; | |
486 const char *name = NULL; | |
487 | |
15823 | 488 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) |
489 node = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)node); /* XXX: this can return NULL?! */ | |
15818 | 490 |
491 if (node == NULL) | |
492 return NULL; | |
493 | |
15823 | 494 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) |
15818 | 495 { |
15823 | 496 PurpleBuddy *buddy = (PurpleBuddy *)node; |
497 PurpleStatusPrimitive prim; | |
498 PurplePresence *presence; | |
499 PurpleStatus *now; | |
15818 | 500 gboolean ascii = gnt_ascii_only(); |
501 | |
15823 | 502 presence = purple_buddy_get_presence(buddy); |
503 now = purple_presence_get_active_status(presence); | |
15818 | 504 |
15823 | 505 prim = purple_status_type_get_primitive(purple_status_get_type(now)); |
15818 | 506 |
507 switch(prim) | |
508 { | |
15823 | 509 case PURPLE_STATUS_OFFLINE: |
15818 | 510 strncpy(status, ascii ? "x" : "⊗", sizeof(status) - 1); |
511 break; | |
15823 | 512 case PURPLE_STATUS_AVAILABLE: |
15818 | 513 strncpy(status, ascii ? "o" : "â—¯", sizeof(status) - 1); |
514 break; | |
515 default: | |
516 strncpy(status, ascii ? "." : "⊖", sizeof(status) - 1); | |
517 break; | |
518 } | |
15823 | 519 name = purple_buddy_get_alias(buddy); |
15818 | 520 } |
15823 | 521 else if (PURPLE_BLIST_NODE_IS_CHAT(node)) |
15818 | 522 { |
15823 | 523 PurpleChat *chat = (PurpleChat*)node; |
524 name = purple_chat_get_name(chat); | |
15818 | 525 |
526 strncpy(status, "~", sizeof(status) - 1); | |
527 } | |
15823 | 528 else if (PURPLE_BLIST_NODE_IS_GROUP(node)) |
529 return ((PurpleGroup*)node)->name; | |
15818 | 530 |
531 snprintf(text, sizeof(text) - 1, "%s %s", status, name); | |
532 | |
533 return text; | |
534 } | |
535 | |
536 static void | |
15823 | 537 add_chat(PurpleChat *chat, FinchBlist *ggblist) |
15818 | 538 { |
15823 | 539 PurpleGroup *group; |
540 PurpleBlistNode *node = (PurpleBlistNode *)chat; | |
15818 | 541 if (node->ui_data) |
542 return; | |
15823 | 543 if (!purple_account_is_connected(chat->account)) |
15818 | 544 return; |
545 | |
15823 | 546 group = purple_chat_get_group(chat); |
547 add_node((PurpleBlistNode*)group, ggblist); | |
15818 | 548 |
549 node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), chat, | |
550 gnt_tree_create_row(GNT_TREE(ggblist->tree), get_display_name(node)), | |
551 group, NULL); | |
552 } | |
553 | |
554 static void | |
15823 | 555 add_contact(PurpleContact *contact, FinchBlist *ggblist) |
15818 | 556 { |
15823 | 557 PurpleGroup *group; |
558 PurpleBlistNode *node = (PurpleBlistNode*)contact; | |
15818 | 559 const char *name; |
560 | |
561 if (node->ui_data) | |
562 return; | |
563 | |
564 name = get_display_name(node); | |
565 if (name == NULL) | |
566 return; | |
567 | |
15823 | 568 group = (PurpleGroup*)node->parent; |
569 add_node((PurpleBlistNode*)group, ggblist); | |
15818 | 570 |
571 node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), contact, | |
572 gnt_tree_create_row(GNT_TREE(ggblist->tree), name), | |
573 group, NULL); | |
574 | |
575 gnt_tree_set_expanded(GNT_TREE(ggblist->tree), contact, FALSE); | |
576 } | |
577 | |
578 static void | |
15823 | 579 add_buddy(PurpleBuddy *buddy, FinchBlist *ggblist) |
15818 | 580 { |
15823 | 581 PurpleContact *contact; |
582 PurpleBlistNode *node = (PurpleBlistNode *)buddy; | |
15818 | 583 if (node->ui_data) |
584 return; | |
585 | |
15823 | 586 contact = (PurpleContact*)node->parent; |
15818 | 587 if (!contact) /* When a new buddy is added and show-offline is set */ |
588 return; | |
15823 | 589 add_node((PurpleBlistNode*)contact, ggblist); |
15818 | 590 |
591 node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), buddy, | |
592 gnt_tree_create_row(GNT_TREE(ggblist->tree), get_display_name(node)), | |
593 contact, NULL); | |
15823 | 594 if (purple_presence_is_idle(purple_buddy_get_presence(buddy))) { |
15818 | 595 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, GNT_TEXT_FLAG_DIM); |
596 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), contact, GNT_TEXT_FLAG_DIM); | |
597 } else { | |
598 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, 0); | |
599 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), contact, 0); | |
600 } | |
601 } | |
602 | |
603 #if 0 | |
604 static void | |
15823 | 605 buddy_signed_on(PurpleBuddy *buddy, FinchBlist *ggblist) |
15818 | 606 { |
15823 | 607 add_node((PurpleBlistNode*)buddy, ggblist); |
15818 | 608 } |
609 | |
610 static void | |
15823 | 611 buddy_signed_off(PurpleBuddy *buddy, FinchBlist *ggblist) |
15818 | 612 { |
15823 | 613 node_remove(purple_get_blist(), (PurpleBlistNode*)buddy); |
15818 | 614 } |
615 #endif | |
616 | |
15823 | 617 PurpleBlistUiOps *finch_blist_get_ui_ops() |
15818 | 618 { |
619 return &blist_ui_ops; | |
620 } | |
621 | |
622 static void | |
623 selection_activate(GntWidget *widget, FinchBlist *ggblist) | |
624 { | |
625 GntTree *tree = GNT_TREE(ggblist->tree); | |
15823 | 626 PurpleBlistNode *node = gnt_tree_get_selection_data(tree); |
15818 | 627 |
628 if (!node) | |
629 return; | |
630 | |
15823 | 631 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) |
632 node = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)node); | |
15818 | 633 |
15823 | 634 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) |
15818 | 635 { |
15823 | 636 PurpleBuddy *buddy = (PurpleBuddy *)node; |
637 PurpleConversation *conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, | |
638 purple_buddy_get_account(buddy), | |
639 purple_buddy_get_name(buddy)); | |
15818 | 640 finch_conversation_set_active(conv); |
641 } | |
15823 | 642 else if (PURPLE_BLIST_NODE_IS_CHAT(node)) |
15818 | 643 { |
15823 | 644 PurpleChat *chat = (PurpleChat*)node; |
15818 | 645 serv_join_chat(chat->account->gc, chat->components); |
646 } | |
647 } | |
648 | |
649 static void | |
650 context_menu_callback(GntMenuItem *item, gpointer data) | |
651 { | |
15823 | 652 PurpleMenuAction *action = data; |
653 PurpleBlistNode *node = ggblist->cnode; | |
15818 | 654 if (action) { |
15823 | 655 void (*callback)(PurpleBlistNode *, gpointer); |
656 callback = (void (*)(PurpleBlistNode *, gpointer))action->callback; | |
15818 | 657 if (callback) |
658 callback(action->data, node); | |
659 else | |
660 return; | |
661 } | |
662 } | |
663 | |
664 static void | |
15823 | 665 gnt_append_menu_action(GntMenu *menu, PurpleMenuAction *action, gpointer parent) |
15818 | 666 { |
667 GList *list; | |
668 GntMenuItem *item; | |
669 | |
670 if (action == NULL) | |
671 return; | |
672 | |
673 item = gnt_menuitem_new(action->label); | |
674 if (action->callback) | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
675 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), context_menu_callback, action); |
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
676 gnt_menu_add_item(menu, GNT_MENU_ITEM(item)); |
15818 | 677 |
678 if (action->children) { | |
679 GntWidget *sub = gnt_menu_new(GNT_MENU_POPUP); | |
680 gnt_menuitem_set_submenu(item, GNT_MENU(sub)); | |
681 for (list = action->children; list; list = list->next) | |
682 gnt_append_menu_action(GNT_MENU(sub), list->data, action); | |
683 } | |
684 } | |
685 | |
686 static void | |
15823 | 687 append_proto_menu(GntMenu *menu, PurpleConnection *gc, PurpleBlistNode *node) |
15818 | 688 { |
689 GList *list; | |
15823 | 690 PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl); |
15818 | 691 |
692 if(!prpl_info || !prpl_info->blist_node_menu) | |
693 return; | |
694 | |
695 for(list = prpl_info->blist_node_menu(node); list; | |
696 list = g_list_delete_link(list, list)) | |
697 { | |
15823 | 698 PurpleMenuAction *act = (PurpleMenuAction *) list->data; |
15818 | 699 act->data = node; |
700 gnt_append_menu_action(menu, act, NULL); | |
701 } | |
702 } | |
703 | |
704 static void | |
15823 | 705 add_custom_action(GntMenu *menu, const char *label, PurpleCallback callback, |
15818 | 706 gpointer data) |
707 { | |
15823 | 708 PurpleMenuAction *action = purple_menu_action_new(label, callback, data, NULL); |
15818 | 709 gnt_append_menu_action(menu, action, NULL); |
710 g_signal_connect_swapped(G_OBJECT(menu), "destroy", | |
15823 | 711 G_CALLBACK(purple_menu_action_free), action); |
15818 | 712 } |
713 | |
714 static void | |
15823 | 715 chat_components_edit_ok(PurpleChat *chat, PurpleRequestFields *allfields) |
15818 | 716 { |
717 GList *groups, *fields; | |
718 | |
15823 | 719 for (groups = purple_request_fields_get_groups(allfields); groups; groups = groups->next) { |
720 fields = purple_request_field_group_get_fields(groups->data); | |
15818 | 721 for (; fields; fields = fields->next) { |
15823 | 722 PurpleRequestField *field = fields->data; |
15818 | 723 const char *id; |
724 char *val; | |
725 | |
15823 | 726 id = purple_request_field_get_id(field); |
727 if (purple_request_field_get_type(field) == PURPLE_REQUEST_FIELD_INTEGER) | |
728 val = g_strdup_printf("%d", purple_request_field_int_get_value(field)); | |
15818 | 729 else |
15823 | 730 val = g_strdup(purple_request_field_string_get_value(field)); |
15818 | 731 |
732 g_hash_table_replace(chat->components, g_strdup(id), val); /* val should not be free'd */ | |
733 } | |
734 } | |
735 } | |
736 | |
737 static void | |
15823 | 738 chat_components_edit(PurpleChat *chat, PurpleBlistNode *selected) |
15818 | 739 { |
15823 | 740 PurpleRequestFields *fields = purple_request_fields_new(); |
741 PurpleRequestFieldGroup *group = purple_request_field_group_new(NULL); | |
742 PurpleRequestField *field; | |
15818 | 743 GList *parts, *iter; |
744 struct proto_chat_entry *pce; | |
745 | |
15823 | 746 purple_request_fields_add_group(fields, group); |
15818 | 747 |
15823 | 748 parts = PURPLE_PLUGIN_PROTOCOL_INFO(chat->account->gc->prpl)->chat_info(chat->account->gc); |
15818 | 749 |
750 for (iter = parts; iter; iter = iter->next) { | |
751 pce = iter->data; | |
752 if (pce->is_int) { | |
753 int val; | |
754 const char *str = g_hash_table_lookup(chat->components, pce->identifier); | |
755 if (!str || sscanf(str, "%d", &val) != 1) | |
756 val = pce->min; | |
15823 | 757 field = purple_request_field_int_new(pce->identifier, pce->label, val); |
15818 | 758 } else { |
15823 | 759 field = purple_request_field_string_new(pce->identifier, pce->label, |
15818 | 760 g_hash_table_lookup(chat->components, pce->identifier), FALSE); |
761 } | |
762 | |
15823 | 763 purple_request_field_group_add_field(group, field); |
15818 | 764 g_free(pce); |
765 } | |
766 | |
767 g_list_free(parts); | |
768 | |
15823 | 769 purple_request_fields(NULL, _("Edit Chat"), NULL, _("Please Update the necessary fields."), |
16442
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
770 fields, _("Edit"), G_CALLBACK(chat_components_edit_ok), _("Cancel"), NULL, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
771 NULL, NULL, NULL, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
772 chat); |
15818 | 773 } |
774 | |
775 static void | |
776 autojoin_toggled(GntMenuItem *item, gpointer data) | |
777 { | |
15823 | 778 PurpleMenuAction *action = data; |
779 purple_blist_node_set_bool(action->data, "gnt-autojoin", | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
780 gnt_menuitem_check_get_checked(GNT_MENU_ITEM_CHECK(item))); |
15818 | 781 } |
782 | |
783 static void | |
15823 | 784 create_chat_menu(GntMenu *menu, PurpleChat *chat) |
15818 | 785 { |
15823 | 786 PurpleMenuAction *action = purple_menu_action_new(_("Auto-join"), NULL, chat, NULL); |
15818 | 787 GntMenuItem *check = gnt_menuitem_check_new(action->label); |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
788 gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(check), |
15823 | 789 purple_blist_node_get_bool((PurpleBlistNode*)chat, "gnt-autojoin")); |
15818 | 790 gnt_menu_add_item(menu, check); |
791 gnt_menuitem_set_callback(check, autojoin_toggled, action); | |
792 g_signal_connect_swapped(G_OBJECT(menu), "destroy", | |
15823 | 793 G_CALLBACK(purple_menu_action_free), action); |
15818 | 794 |
15823 | 795 add_custom_action(menu, _("Edit Settings"), (PurpleCallback)chat_components_edit, chat); |
15818 | 796 } |
797 | |
798 static void | |
15823 | 799 finch_add_buddy(PurpleGroup *grp, PurpleBlistNode *selected) |
15818 | 800 { |
15823 | 801 purple_blist_request_add_buddy(NULL, NULL, grp ? grp->name : NULL, NULL); |
15818 | 802 } |
803 | |
804 static void | |
15823 | 805 finch_add_group(PurpleGroup *grp, PurpleBlistNode *selected) |
15818 | 806 { |
15823 | 807 purple_blist_request_add_group(); |
15818 | 808 } |
809 | |
810 static void | |
15823 | 811 finch_add_chat(PurpleGroup *grp, PurpleBlistNode *selected) |
15818 | 812 { |
15823 | 813 purple_blist_request_add_chat(NULL, grp, NULL, NULL); |
15818 | 814 } |
815 | |
816 static void | |
15823 | 817 create_group_menu(GntMenu *menu, PurpleGroup *group) |
15818 | 818 { |
819 add_custom_action(menu, _("Add Buddy"), | |
15823 | 820 PURPLE_CALLBACK(finch_add_buddy), group); |
15818 | 821 add_custom_action(menu, _("Add Chat"), |
15823 | 822 PURPLE_CALLBACK(finch_add_chat), group); |
15818 | 823 add_custom_action(menu, _("Add Group"), |
15823 | 824 PURPLE_CALLBACK(finch_add_group), group); |
15818 | 825 } |
826 | |
827 static void | |
15823 | 828 finch_blist_get_buddy_info_cb(PurpleBuddy *buddy, PurpleBlistNode *selected) |
15818 | 829 { |
16936
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16935
diff
changeset
|
830 /* Add a userinfo with a "Retrieving information", which will later be updated |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16935
diff
changeset
|
831 * when the server finally returns the information. */ |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16935
diff
changeset
|
832 PurpleNotifyUserInfo *info = purple_notify_user_info_new(); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16935
diff
changeset
|
833 purple_notify_user_info_add_pair(info, _("Information"), _("Retrieving...")); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16935
diff
changeset
|
834 purple_notify_userinfo(buddy->account->gc, purple_buddy_get_name(buddy), info, NULL, NULL); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16935
diff
changeset
|
835 purple_notify_user_info_destroy(info); |
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16935
diff
changeset
|
836 |
15823 | 837 serv_get_info(buddy->account->gc, purple_buddy_get_name(buddy)); |
15818 | 838 } |
839 | |
840 static void | |
15823 | 841 finch_blist_menu_send_file_cb(PurpleBuddy *buddy, PurpleBlistNode *selected) |
15818 | 842 { |
843 serv_send_file(buddy->account->gc, buddy->name, NULL); | |
844 } | |
845 | |
846 static void | |
15823 | 847 finch_blist_pounce_node_cb(PurpleBlistNode *node, PurpleBlistNode *selected) |
15818 | 848 { |
15823 | 849 PurpleBuddy *b; |
850 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) | |
851 b = purple_contact_get_priority_buddy((PurpleContact *)node); | |
15818 | 852 else |
15823 | 853 b = (PurpleBuddy *)node; |
15818 | 854 finch_pounce_editor_show(b->account, b->name, NULL); |
855 } | |
856 | |
857 | |
858 static void | |
15823 | 859 create_buddy_menu(GntMenu *menu, PurpleBuddy *buddy) |
15818 | 860 { |
15823 | 861 PurplePluginProtocolInfo *prpl_info; |
15818 | 862 |
15823 | 863 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(buddy->account->gc->prpl); |
15818 | 864 if (prpl_info && prpl_info->get_info) |
865 { | |
866 add_custom_action(menu, _("Get Info"), | |
15823 | 867 PURPLE_CALLBACK(finch_blist_get_buddy_info_cb), buddy); |
15818 | 868 } |
869 | |
870 add_custom_action(menu, _("Add Buddy Pounce"), | |
15823 | 871 PURPLE_CALLBACK(finch_blist_pounce_node_cb), buddy); |
15818 | 872 |
873 if (prpl_info && prpl_info->send_file) | |
874 { | |
875 if (!prpl_info->can_receive_file || | |
876 prpl_info->can_receive_file(buddy->account->gc, buddy->name)) | |
877 add_custom_action(menu, _("Send File"), | |
15823 | 878 PURPLE_CALLBACK(finch_blist_menu_send_file_cb), buddy); |
15818 | 879 } |
880 #if 0 | |
881 add_custom_action(tree, _("View Log"), | |
15823 | 882 PURPLE_CALLBACK(finch_blist_view_log_cb)), buddy); |
15818 | 883 #endif |
884 | |
885 /* Protocol actions */ | |
886 append_proto_menu(menu, | |
15823 | 887 purple_account_get_connection(purple_buddy_get_account(buddy)), |
888 (PurpleBlistNode*)buddy); | |
15818 | 889 } |
890 | |
891 static void | |
15823 | 892 append_extended_menu(GntMenu *menu, PurpleBlistNode *node) |
15818 | 893 { |
894 GList *iter; | |
895 | |
15823 | 896 for (iter = purple_blist_node_get_extended_menu(node); |
15818 | 897 iter; iter = g_list_delete_link(iter, iter)) |
898 { | |
899 gnt_append_menu_action(menu, iter->data, NULL); | |
900 } | |
901 } | |
902 | |
15823 | 903 /* Xerox'd from gtkdialogs.c:purple_gtkdialogs_remove_contact_cb */ |
15818 | 904 static void |
15823 | 905 remove_contact(PurpleContact *contact) |
15818 | 906 { |
15823 | 907 PurpleBlistNode *bnode, *cnode; |
908 PurpleGroup *group; | |
15818 | 909 |
15823 | 910 cnode = (PurpleBlistNode *)contact; |
911 group = (PurpleGroup*)cnode->parent; | |
15818 | 912 for (bnode = cnode->child; bnode; bnode = bnode->next) { |
15823 | 913 PurpleBuddy *buddy = (PurpleBuddy*)bnode; |
914 if (purple_account_is_connected(buddy->account)) | |
915 purple_account_remove_buddy(buddy->account, buddy, group); | |
15818 | 916 } |
15823 | 917 purple_blist_remove_contact(contact); |
15818 | 918 } |
919 | |
920 static void | |
15823 | 921 rename_blist_node(PurpleBlistNode *node, const char *newname) |
15818 | 922 { |
923 const char *name = newname; | |
924 if (name && !*name) | |
925 name = NULL; | |
926 | |
15823 | 927 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { |
928 PurpleContact *contact = (PurpleContact*)node; | |
929 PurpleBuddy *buddy = purple_contact_get_priority_buddy(contact); | |
930 purple_blist_alias_contact(contact, name); | |
931 purple_blist_alias_buddy(buddy, name); | |
15818 | 932 serv_alias_buddy(buddy); |
15823 | 933 } else if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { |
934 purple_blist_alias_buddy((PurpleBuddy*)node, name); | |
935 serv_alias_buddy((PurpleBuddy*)node); | |
936 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) | |
937 purple_blist_alias_chat((PurpleChat*)node, name); | |
938 else if (PURPLE_BLIST_NODE_IS_GROUP(node) && (name != NULL)) | |
939 purple_blist_rename_group((PurpleGroup*)node, name); | |
15818 | 940 else |
941 g_return_if_reached(); | |
942 } | |
943 | |
944 static void | |
15823 | 945 finch_blist_rename_node_cb(PurpleBlistNode *node, PurpleBlistNode *selected) |
15818 | 946 { |
947 const char *name = NULL; | |
948 char *prompt; | |
16276
31dad9806e9d
Use 'alias' instead of 'rename' for non-group nodes. Thankfully, this does not introduce new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
949 const char *text; |
15818 | 950 |
15823 | 951 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) |
952 name = purple_contact_get_alias((PurpleContact*)node); | |
953 else if (PURPLE_BLIST_NODE_IS_BUDDY(node)) | |
954 name = purple_buddy_get_contact_alias((PurpleBuddy*)node); | |
955 else if (PURPLE_BLIST_NODE_IS_CHAT(node)) | |
956 name = purple_chat_get_name((PurpleChat*)node); | |
957 else if (PURPLE_BLIST_NODE_IS_GROUP(node)) | |
958 name = ((PurpleGroup*)node)->name; | |
15818 | 959 else |
960 g_return_if_reached(); | |
961 | |
962 prompt = g_strdup_printf(_("Please enter the new name for %s"), name); | |
963 | |
16969
1a336cfc410e
Change a string, and make sure non-functional items are not added in the conversation window menu.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16937
diff
changeset
|
964 text = PURPLE_BLIST_NODE_IS_GROUP(node) ? _("Rename") : _("Set Alias"); |
16276
31dad9806e9d
Use 'alias' instead of 'rename' for non-group nodes. Thankfully, this does not introduce new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
965 purple_request_input(node, text, prompt, _("Enter empty string to reset the name."), |
31dad9806e9d
Use 'alias' instead of 'rename' for non-group nodes. Thankfully, this does not introduce new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
966 name, FALSE, FALSE, NULL, text, G_CALLBACK(rename_blist_node), |
16442
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
967 _("Cancel"), NULL, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
968 NULL, NULL, NULL, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
969 node); |
15818 | 970 |
971 g_free(prompt); | |
972 } | |
973 | |
15823 | 974 /* Xeroxed from gtkdialogs.c:purple_gtkdialogs_remove_group_cb*/ |
15818 | 975 static void |
15823 | 976 remove_group(PurpleGroup *group) |
15818 | 977 { |
15823 | 978 PurpleBlistNode *cnode, *bnode; |
15818 | 979 |
15823 | 980 cnode = ((PurpleBlistNode*)group)->child; |
15818 | 981 |
982 while (cnode) { | |
15823 | 983 if (PURPLE_BLIST_NODE_IS_CONTACT(cnode)) { |
15818 | 984 bnode = cnode->child; |
985 cnode = cnode->next; | |
986 while (bnode) { | |
15823 | 987 PurpleBuddy *buddy; |
988 if (PURPLE_BLIST_NODE_IS_BUDDY(bnode)) { | |
989 buddy = (PurpleBuddy*)bnode; | |
15818 | 990 bnode = bnode->next; |
15823 | 991 if (purple_account_is_connected(buddy->account)) { |
992 purple_account_remove_buddy(buddy->account, buddy, group); | |
993 purple_blist_remove_buddy(buddy); | |
15818 | 994 } |
995 } else { | |
996 bnode = bnode->next; | |
997 } | |
998 } | |
15823 | 999 } else if (PURPLE_BLIST_NODE_IS_CHAT(cnode)) { |
1000 PurpleChat *chat = (PurpleChat *)cnode; | |
15818 | 1001 cnode = cnode->next; |
15823 | 1002 if (purple_account_is_connected(chat->account)) |
1003 purple_blist_remove_chat(chat); | |
15818 | 1004 } else { |
1005 cnode = cnode->next; | |
1006 } | |
1007 } | |
1008 | |
15823 | 1009 purple_blist_remove_group(group); |
15818 | 1010 } |
1011 | |
1012 static void | |
15823 | 1013 finch_blist_remove_node(PurpleBlistNode *node) |
15818 | 1014 { |
15823 | 1015 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { |
1016 remove_contact((PurpleContact*)node); | |
1017 } else if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { | |
1018 PurpleBuddy *buddy = (PurpleBuddy*)node; | |
1019 PurpleGroup *group = purple_buddy_get_group(buddy); | |
1020 purple_account_remove_buddy(purple_buddy_get_account(buddy), buddy, group); | |
1021 purple_blist_remove_buddy(buddy); | |
1022 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) { | |
1023 purple_blist_remove_chat((PurpleChat*)node); | |
1024 } else if (PURPLE_BLIST_NODE_IS_GROUP(node)) { | |
1025 remove_group((PurpleGroup*)node); | |
15818 | 1026 } |
1027 } | |
1028 | |
1029 static void | |
15823 | 1030 finch_blist_remove_node_cb(PurpleBlistNode *node, PurpleBlistNode *selected) |
15818 | 1031 { |
16442
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
1032 PurpleAccount *account = NULL; |
15818 | 1033 char *primary; |
1034 const char *name, *sec = NULL; | |
1035 | |
1036 /* XXX: could be a contact */ | |
15823 | 1037 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { |
1038 PurpleContact *c = (PurpleContact*)node; | |
1039 name = purple_contact_get_alias(c); | |
15818 | 1040 if (c->totalsize > 1) |
1041 sec = _("Removing this contact will also remove all the buddies in the contact"); | |
16442
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
1042 } else if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { |
15823 | 1043 name = purple_buddy_get_name((PurpleBuddy*)node); |
16442
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
1044 account = purple_buddy_get_account((PurpleBuddy*)node); |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
1045 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) { |
15823 | 1046 name = purple_chat_get_name((PurpleChat*)node); |
16442
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
1047 } else if (PURPLE_BLIST_NODE_IS_GROUP(node)) { |
15823 | 1048 name = ((PurpleGroup*)node)->name; |
15818 | 1049 sec = _("Removing this group will also remove all the buddies in the group"); |
1050 } | |
1051 else | |
1052 return; | |
1053 | |
1054 primary = g_strdup_printf(_("Are you sure you want to remove %s?"), name); | |
1055 | |
1056 /* XXX: anything to do with the returned ui-handle? */ | |
15823 | 1057 purple_request_action(node, _("Confirm Remove"), |
15818 | 1058 primary, sec, |
16442
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
1059 1, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
1060 account, name, NULL, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
1061 node, 2, |
15818 | 1062 _("Remove"), finch_blist_remove_node, |
1063 _("Cancel"), NULL); | |
1064 g_free(primary); | |
1065 } | |
1066 | |
1067 static void | |
15823 | 1068 finch_blist_toggle_tag_buddy(PurpleBlistNode *node) |
15818 | 1069 { |
1070 GList *iter; | |
1071 if (node == NULL) | |
1072 return; | |
1073 if (ggblist->tagged && (iter = g_list_find(ggblist->tagged, node)) != NULL) { | |
1074 ggblist->tagged = g_list_delete_link(ggblist->tagged, iter); | |
1075 } else { | |
1076 ggblist->tagged = g_list_prepend(ggblist->tagged, node); | |
1077 } | |
15823 | 1078 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) |
1079 node = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)node); | |
16575
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1080 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1081 update_buddy_display((PurpleBuddy*)node, ggblist); |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1082 else |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1083 update_node_display(node, ggblist); |
15818 | 1084 } |
1085 | |
1086 static void | |
15823 | 1087 finch_blist_place_tagged(PurpleBlistNode *target) |
15818 | 1088 { |
15823 | 1089 PurpleGroup *tg = NULL; |
1090 PurpleContact *tc = NULL; | |
15818 | 1091 |
1092 if (target == NULL) | |
1093 return; | |
1094 | |
15823 | 1095 if (PURPLE_BLIST_NODE_IS_GROUP(target)) |
1096 tg = (PurpleGroup*)target; | |
16575
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1097 else if (PURPLE_BLIST_NODE_IS_BUDDY(target)) { |
15823 | 1098 tc = (PurpleContact*)target->parent; |
16575
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1099 tg = (PurpleGroup*)target->parent->parent; |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1100 } else { |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1101 if (PURPLE_BLIST_NODE_IS_CONTACT(target)) |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1102 tc = (PurpleContact*)target; |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1103 tg = (PurpleGroup*)target->parent; |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1104 } |
15818 | 1105 |
1106 if (ggblist->tagged) { | |
1107 GList *list = ggblist->tagged; | |
1108 ggblist->tagged = NULL; | |
1109 while (list) { | |
15823 | 1110 PurpleBlistNode *node = list->data; |
15818 | 1111 list = g_list_delete_link(list, list); |
16575
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1112 |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1113 if (PURPLE_BLIST_NODE_IS_GROUP(node)) { |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1114 update_node_display(node, ggblist); |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1115 /* Add the group after the current group */ |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1116 purple_blist_add_group((PurpleGroup*)node, (PurpleBlistNode*)tg); |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1117 } else if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1118 update_buddy_display(purple_contact_get_priority_buddy((PurpleContact*)node), ggblist); |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1119 if ((PurpleBlistNode*)tg == target) { |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1120 /* The target is a group, just add the contact to the group. */ |
15823 | 1121 purple_blist_add_contact((PurpleContact*)node, tg, NULL); |
16575
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1122 } else if (tc) { |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1123 /* The target is either a buddy, or a contact. Merge with that contact. */ |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1124 purple_blist_merge_contact((PurpleContact*)node, (PurpleBlistNode*)tc); |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1125 } else { |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1126 /* The target is a chat. Add the contact to the group after this chat. */ |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1127 purple_blist_add_contact((PurpleContact*)node, NULL, target); |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1128 } |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1129 } else if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1130 update_buddy_display((PurpleBuddy*)node, ggblist); |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1131 if ((PurpleBlistNode*)tg == target) { |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1132 /* The target is a group. Add this buddy in a new contact under this group. */ |
15823 | 1133 purple_blist_add_buddy((PurpleBuddy*)node, NULL, tg, NULL); |
16575
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1134 } else if (PURPLE_BLIST_NODE_IS_CONTACT(target)) { |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1135 /* Add to the contact. */ |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1136 purple_blist_add_buddy((PurpleBuddy*)node, tc, NULL, NULL); |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1137 } else if (PURPLE_BLIST_NODE_IS_BUDDY(target)) { |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1138 /* Add to the contact after the selected buddy. */ |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1139 purple_blist_add_buddy((PurpleBuddy*)node, NULL, NULL, target); |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1140 } else if (PURPLE_BLIST_NODE_IS_CHAT(target)) { |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1141 /* Add to the selected chat's group. */ |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1142 purple_blist_add_buddy((PurpleBuddy*)node, NULL, tg, NULL); |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1143 } |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1144 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) { |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1145 update_node_display(node, ggblist); |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1146 if ((PurpleBlistNode*)tg == target) |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1147 purple_blist_add_chat((PurpleChat*)node, tg, NULL); |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1148 else |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1149 purple_blist_add_chat((PurpleChat*)node, NULL, target); |
15818 | 1150 } |
1151 } | |
1152 } | |
1153 } | |
1154 | |
1155 static void | |
1156 context_menu_destroyed(GntWidget *widget, FinchBlist *ggblist) | |
1157 { | |
1158 ggblist->context = NULL; | |
1159 } | |
1160 | |
1161 static void | |
1162 draw_context_menu(FinchBlist *ggblist) | |
1163 { | |
15823 | 1164 PurpleBlistNode *node = NULL; |
15818 | 1165 GntWidget *context = NULL; |
1166 GntTree *tree = NULL; | |
1167 int x, y, top, width; | |
1168 char *title = NULL; | |
1169 | |
16824
e79555933fc6
Do not build the context menu if one is already being shown.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
1170 if (ggblist->context) |
e79555933fc6
Do not build the context menu if one is already being shown.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
1171 return; |
e79555933fc6
Do not build the context menu if one is already being shown.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
1172 |
15818 | 1173 tree = GNT_TREE(ggblist->tree); |
1174 | |
1175 node = gnt_tree_get_selection_data(tree); | |
1176 | |
1177 if (ggblist->tooltip) | |
1178 remove_tooltip(ggblist); | |
1179 | |
1180 ggblist->cnode = node; | |
1181 | |
1182 ggblist->context = context = gnt_menu_new(GNT_MENU_POPUP); | |
1183 g_signal_connect(G_OBJECT(context), "destroy", G_CALLBACK(context_menu_destroyed), ggblist); | |
1184 | |
1185 if (!node) { | |
1186 create_group_menu(GNT_MENU(context), NULL); | |
1187 title = g_strdup(_("Buddy List")); | |
15823 | 1188 } else if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { |
15818 | 1189 create_buddy_menu(GNT_MENU(context), |
15823 | 1190 purple_contact_get_priority_buddy((PurpleContact*)node)); |
1191 title = g_strdup(purple_contact_get_alias((PurpleContact*)node)); | |
1192 } else if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { | |
1193 PurpleBuddy *buddy = (PurpleBuddy *)node; | |
15818 | 1194 create_buddy_menu(GNT_MENU(context), buddy); |
15823 | 1195 title = g_strdup(purple_buddy_get_name(buddy)); |
1196 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) { | |
1197 PurpleChat *chat = (PurpleChat*)node; | |
15818 | 1198 create_chat_menu(GNT_MENU(context), chat); |
15823 | 1199 title = g_strdup(purple_chat_get_name(chat)); |
1200 } else if (PURPLE_BLIST_NODE_IS_GROUP(node)) { | |
1201 PurpleGroup *group = (PurpleGroup *)node; | |
15818 | 1202 create_group_menu(GNT_MENU(context), group); |
1203 title = g_strdup(group->name); | |
1204 } | |
1205 | |
1206 append_extended_menu(GNT_MENU(context), node); | |
1207 | |
1208 /* These are common for everything */ | |
1209 if (node) { | |
16276
31dad9806e9d
Use 'alias' instead of 'rename' for non-group nodes. Thankfully, this does not introduce new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
1210 add_custom_action(GNT_MENU(context), |
31dad9806e9d
Use 'alias' instead of 'rename' for non-group nodes. Thankfully, this does not introduce new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
1211 PURPLE_BLIST_NODE_IS_GROUP(node) ? _("Rename") : _("Alias"), |
15823 | 1212 PURPLE_CALLBACK(finch_blist_rename_node_cb), node); |
15818 | 1213 add_custom_action(GNT_MENU(context), _("Remove"), |
15823 | 1214 PURPLE_CALLBACK(finch_blist_remove_node_cb), node); |
15818 | 1215 |
15823 | 1216 if (ggblist->tagged && (PURPLE_BLIST_NODE_IS_CONTACT(node) |
1217 || PURPLE_BLIST_NODE_IS_GROUP(node))) { | |
15818 | 1218 add_custom_action(GNT_MENU(context), _("Place tagged"), |
15823 | 1219 PURPLE_CALLBACK(finch_blist_place_tagged), node); |
15818 | 1220 } |
1221 | |
15823 | 1222 if (PURPLE_BLIST_NODE_IS_BUDDY(node) || PURPLE_BLIST_NODE_IS_CONTACT(node)) { |
15818 | 1223 add_custom_action(GNT_MENU(context), _("Toggle Tag"), |
15823 | 1224 PURPLE_CALLBACK(finch_blist_toggle_tag_buddy), node); |
15818 | 1225 } |
1226 } | |
1227 | |
1228 /* Set the position for the popup */ | |
1229 gnt_widget_get_position(GNT_WIDGET(tree), &x, &y); | |
1230 gnt_widget_get_size(GNT_WIDGET(tree), &width, NULL); | |
1231 top = gnt_tree_get_selection_visible_line(tree); | |
1232 | |
1233 x += width; | |
1234 y += top - 1; | |
1235 | |
1236 gnt_widget_set_position(context, x, y); | |
1237 gnt_screen_menu_show(GNT_MENU(context)); | |
1238 g_free(title); | |
1239 } | |
1240 | |
1241 static void | |
15823 | 1242 tooltip_for_buddy(PurpleBuddy *buddy, GString *str) |
15818 | 1243 { |
15823 | 1244 PurplePlugin *prpl; |
1245 PurplePluginProtocolInfo *prpl_info; | |
1246 PurpleAccount *account; | |
1247 PurpleNotifyUserInfo *user_info; | |
1248 const char *alias = purple_buddy_get_alias(buddy); | |
15818 | 1249 char *tmp, *strip; |
1250 | |
15823 | 1251 user_info = purple_notify_user_info_new(); |
15818 | 1252 |
15823 | 1253 account = purple_buddy_get_account(buddy); |
15818 | 1254 |
15823 | 1255 if (g_utf8_collate(purple_buddy_get_name(buddy), alias)) |
1256 purple_notify_user_info_add_pair(user_info, _("Nickname"), alias); | |
15818 | 1257 |
1258 tmp = g_strdup_printf("%s (%s)", | |
15823 | 1259 purple_account_get_username(account), |
1260 purple_account_get_protocol_name(account)); | |
1261 purple_notify_user_info_add_pair(user_info, _("Account"), tmp); | |
15818 | 1262 g_free(tmp); |
1263 | |
15823 | 1264 prpl = purple_find_prpl(purple_account_get_protocol_id(account)); |
1265 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | |
15818 | 1266 if (prpl_info && prpl_info->tooltip_text) { |
1267 prpl_info->tooltip_text(buddy, user_info, TRUE); | |
1268 } | |
1269 | |
16427
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16276
diff
changeset
|
1270 if (purple_prefs_get_bool("/finch/blist/idletime")) { |
15823 | 1271 PurplePresence *pre = purple_buddy_get_presence(buddy); |
1272 if (purple_presence_is_idle(pre)) { | |
1273 time_t idle = purple_presence_get_idle_time(pre); | |
15818 | 1274 if (idle > 0) { |
15823 | 1275 char *st = purple_str_seconds_to_string(time(NULL) - idle); |
1276 purple_notify_user_info_add_pair(user_info, _("Idle"), st); | |
15818 | 1277 g_free(st); |
1278 } | |
1279 } | |
1280 } | |
1281 | |
15823 | 1282 tmp = purple_notify_user_info_get_text_with_newline(user_info, "<BR>"); |
1283 purple_notify_user_info_destroy(user_info); | |
15818 | 1284 |
15823 | 1285 strip = purple_markup_strip_html(tmp); |
15818 | 1286 g_string_append(str, strip); |
1287 g_free(strip); | |
1288 g_free(tmp); | |
1289 } | |
1290 | |
1291 static GString* | |
1292 make_sure_text_fits(GString *string) | |
1293 { | |
1294 int maxw = getmaxx(stdscr) - 3; | |
1295 char *str = gnt_util_onscreen_fit_string(string->str, maxw); | |
1296 string = g_string_assign(string, str); | |
1297 g_free(str); | |
1298 return string; | |
1299 } | |
1300 | |
1301 static gboolean | |
1302 draw_tooltip_real(FinchBlist *ggblist) | |
1303 { | |
15823 | 1304 PurpleBlistNode *node; |
15818 | 1305 int x, y, top, width, w, h; |
1306 GString *str; | |
1307 GntTree *tree; | |
1308 GntWidget *widget, *box, *tv; | |
1309 char *title = NULL; | |
1310 int lastseen = 0; | |
1311 | |
1312 widget = ggblist->tree; | |
1313 tree = GNT_TREE(widget); | |
1314 | |
1315 if (!gnt_widget_has_focus(ggblist->tree) || | |
1316 (ggblist->context && !GNT_WIDGET_IS_FLAG_SET(ggblist->context, GNT_WIDGET_INVISIBLE))) | |
1317 return FALSE; | |
1318 | |
1319 if (ggblist->tooltip) | |
1320 { | |
1321 /* XXX: Once we can properly redraw on expose events, this can be removed at the end | |
1322 * to avoid the blinking*/ | |
1323 remove_tooltip(ggblist); | |
1324 } | |
1325 | |
1326 node = gnt_tree_get_selection_data(tree); | |
1327 if (!node) | |
1328 return FALSE; | |
1329 | |
1330 str = g_string_new(""); | |
1331 | |
15823 | 1332 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { |
1333 PurpleBuddy *pr = purple_contact_get_priority_buddy((PurpleContact*)node); | |
1334 gboolean offline = !PURPLE_BUDDY_IS_ONLINE(pr); | |
1335 gboolean showoffline = purple_prefs_get_bool(PREF_ROOT "/showoffline"); | |
1336 const char *name = purple_buddy_get_name(pr); | |
15818 | 1337 |
1338 title = g_strdup(name); | |
1339 tooltip_for_buddy(pr, str); | |
1340 for (node = node->child; node; node = node->next) { | |
15823 | 1341 PurpleBuddy *buddy = (PurpleBuddy*)node; |
15818 | 1342 if (offline) { |
15823 | 1343 int value = purple_blist_node_get_int(node, "last_seen"); |
15818 | 1344 if (value > lastseen) |
1345 lastseen = value; | |
1346 } | |
15823 | 1347 if (node == (PurpleBlistNode*)pr) |
15818 | 1348 continue; |
15823 | 1349 if (!purple_account_is_connected(buddy->account)) |
15818 | 1350 continue; |
15823 | 1351 if (!showoffline && !PURPLE_BUDDY_IS_ONLINE(buddy)) |
15818 | 1352 continue; |
1353 str = g_string_append(str, "\n----------\n"); | |
1354 tooltip_for_buddy(buddy, str); | |
1355 } | |
15823 | 1356 } else if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { |
1357 PurpleBuddy *buddy = (PurpleBuddy *)node; | |
15818 | 1358 tooltip_for_buddy(buddy, str); |
15823 | 1359 title = g_strdup(purple_buddy_get_name(buddy)); |
1360 if (!PURPLE_BUDDY_IS_ONLINE((PurpleBuddy*)node)) | |
1361 lastseen = purple_blist_node_get_int(node, "last_seen"); | |
1362 } else if (PURPLE_BLIST_NODE_IS_GROUP(node)) { | |
1363 PurpleGroup *group = (PurpleGroup *)node; | |
15818 | 1364 |
1365 g_string_append_printf(str, _("Online: %d\nTotal: %d"), | |
15823 | 1366 purple_blist_get_group_online_count(group), |
1367 purple_blist_get_group_size(group, FALSE)); | |
15818 | 1368 |
1369 title = g_strdup(group->name); | |
15823 | 1370 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) { |
1371 PurpleChat *chat = (PurpleChat *)node; | |
1372 PurpleAccount *account = chat->account; | |
15818 | 1373 |
1374 g_string_append_printf(str, _("Account: %s (%s)"), | |
15823 | 1375 purple_account_get_username(account), |
1376 purple_account_get_protocol_name(account)); | |
15818 | 1377 |
15823 | 1378 title = g_strdup(purple_chat_get_name(chat)); |
15818 | 1379 } else { |
1380 g_string_free(str, TRUE); | |
1381 return FALSE; | |
1382 } | |
1383 | |
1384 if (lastseen > 0) { | |
15823 | 1385 char *tmp = purple_str_seconds_to_string(time(NULL) - lastseen); |
15818 | 1386 g_string_append_printf(str, _("\nLast Seen: %s ago"), tmp); |
1387 g_free(tmp); | |
1388 } | |
1389 | |
1390 gnt_widget_get_position(widget, &x, &y); | |
1391 gnt_widget_get_size(widget, &width, NULL); | |
1392 top = gnt_tree_get_selection_visible_line(tree); | |
1393 | |
1394 x += width; | |
1395 y += top - 1; | |
1396 | |
1397 box = gnt_box_new(FALSE, FALSE); | |
1398 gnt_box_set_toplevel(GNT_BOX(box), TRUE); | |
1399 GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_NO_SHADOW); | |
1400 gnt_box_set_title(GNT_BOX(box), title); | |
1401 | |
1402 str = make_sure_text_fits(str); | |
1403 gnt_util_get_text_bound(str->str, &w, &h); | |
1404 h = MAX(2, h); | |
1405 tv = gnt_text_view_new(); | |
1406 gnt_widget_set_size(tv, w + 1, h); | |
1407 gnt_box_add_widget(GNT_BOX(box), tv); | |
1408 | |
1409 gnt_widget_set_position(box, x, y); | |
1410 GNT_WIDGET_UNSET_FLAGS(box, GNT_WIDGET_CAN_TAKE_FOCUS); | |
1411 GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_TRANSIENT); | |
1412 gnt_widget_draw(box); | |
1413 | |
1414 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(tv), str->str, GNT_TEXT_FLAG_NORMAL); | |
1415 gnt_text_view_scroll(GNT_TEXT_VIEW(tv), 0); | |
1416 | |
1417 g_free(title); | |
1418 g_string_free(str, TRUE); | |
1419 ggblist->tooltip = box; | |
1420 ggblist->tnode = node; | |
1421 | |
1422 gnt_widget_set_name(ggblist->tooltip, "tooltip"); | |
1423 return FALSE; | |
1424 } | |
1425 | |
1426 static void | |
1427 draw_tooltip(FinchBlist *ggblist) | |
1428 { | |
1429 /* When an account has signed off, it removes one buddy at a time. | |
1430 * Drawing the tooltip after removing each buddy is expensive. On | |
1431 * top of that, if the selected buddy belongs to the disconnected | |
1432 * account, then retreiving the tooltip for that causes crash. So | |
1433 * let's make sure we wait for all the buddies to be removed first.*/ | |
1434 int id = g_timeout_add(0, (GSourceFunc)draw_tooltip_real, ggblist); | |
1435 g_object_set_data_full(G_OBJECT(ggblist->window), "draw_tooltip_calback", | |
1436 GINT_TO_POINTER(id), (GDestroyNotify)g_source_remove); | |
1437 } | |
1438 | |
1439 static void | |
1440 selection_changed(GntWidget *widget, gpointer old, gpointer current, FinchBlist *ggblist) | |
1441 { | |
16792
d0f9b2b217cf
Fix context menu unusualness in the buddylist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16782
diff
changeset
|
1442 remove_peripherals(ggblist); |
15818 | 1443 draw_tooltip(ggblist); |
1444 } | |
1445 | |
1446 static gboolean | |
1447 context_menu(GntWidget *widget, FinchBlist *ggblist) | |
1448 { | |
1449 draw_context_menu(ggblist); | |
1450 return TRUE; | |
1451 } | |
1452 | |
1453 static gboolean | |
1454 key_pressed(GntWidget *widget, const char *text, FinchBlist *ggblist) | |
1455 { | |
1456 if (text[0] == 27 && text[1] == 0) { | |
1457 /* Escape was pressed */ | |
1458 remove_peripherals(ggblist); | |
1459 } else if (strcmp(text, GNT_KEY_CTRL_O) == 0) { | |
15823 | 1460 purple_prefs_set_bool(PREF_ROOT "/showoffline", |
1461 !purple_prefs_get_bool(PREF_ROOT "/showoffline")); | |
15818 | 1462 } else if (GNT_TREE(ggblist->tree)->search == NULL) { |
1463 if (strcmp(text, "t") == 0) { | |
1464 finch_blist_toggle_tag_buddy(gnt_tree_get_selection_data(GNT_TREE(ggblist->tree))); | |
1465 gnt_bindable_perform_action_named(GNT_BINDABLE(ggblist->tree), "move-down"); | |
1466 } else if (strcmp(text, "a") == 0) { | |
1467 finch_blist_place_tagged(gnt_tree_get_selection_data(GNT_TREE(ggblist->tree))); | |
1468 } else | |
1469 return FALSE; | |
1470 } else | |
1471 return FALSE; | |
1472 | |
1473 return TRUE; | |
1474 } | |
1475 | |
1476 static void | |
16575
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1477 update_node_display(PurpleBlistNode *node, FinchBlist *ggblist) |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1478 { |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1479 GntTextFormatFlags flag = 0; |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1480 if (ggblist->tagged && g_list_find(ggblist->tagged, node)) |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1481 flag |= GNT_TEXT_FLAG_BOLD; |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1482 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), node, flag); |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1483 } |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1484 |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1485 static void |
15823 | 1486 update_buddy_display(PurpleBuddy *buddy, FinchBlist *ggblist) |
15818 | 1487 { |
15823 | 1488 PurpleContact *contact; |
15818 | 1489 GntTextFormatFlags bflag = 0, cflag = 0; |
1490 | |
15823 | 1491 contact = purple_buddy_get_contact(buddy); |
15818 | 1492 |
15823 | 1493 gnt_tree_change_text(GNT_TREE(ggblist->tree), buddy, 0, get_display_name((PurpleBlistNode*)buddy)); |
1494 gnt_tree_change_text(GNT_TREE(ggblist->tree), contact, 0, get_display_name((PurpleBlistNode*)contact)); | |
15818 | 1495 |
1496 if (ggblist->tagged && g_list_find(ggblist->tagged, buddy)) | |
1497 bflag |= GNT_TEXT_FLAG_BOLD; | |
1498 if (ggblist->tagged && g_list_find(ggblist->tagged, contact)) | |
1499 cflag |= GNT_TEXT_FLAG_BOLD; | |
1500 | |
15823 | 1501 if (ggblist->tnode == (PurpleBlistNode*)buddy) |
15818 | 1502 draw_tooltip(ggblist); |
1503 | |
15823 | 1504 if (purple_presence_is_idle(purple_buddy_get_presence(buddy))) { |
15818 | 1505 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, bflag | GNT_TEXT_FLAG_DIM); |
16575
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1506 if (buddy == purple_contact_get_priority_buddy(contact)) |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1507 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), contact, cflag | GNT_TEXT_FLAG_DIM); |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1508 else |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1509 update_buddy_display(purple_contact_get_priority_buddy(contact), ggblist); |
15818 | 1510 } else { |
1511 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, bflag); | |
16575
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1512 if (buddy == purple_contact_get_priority_buddy(contact)) |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1513 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), contact, cflag); |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1514 else |
7b692d5dd704
This makes it possible to rearrange chats and groups using the tag+attach system. Thanks a bunch to wabz for testing this. Fixes #379.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16491
diff
changeset
|
1515 update_buddy_display(purple_contact_get_priority_buddy(contact), ggblist); |
15818 | 1516 } |
1517 } | |
1518 | |
1519 static void | |
15823 | 1520 buddy_status_changed(PurpleBuddy *buddy, PurpleStatus *old, PurpleStatus *now, FinchBlist *ggblist) |
15818 | 1521 { |
1522 update_buddy_display(buddy, ggblist); | |
1523 } | |
1524 | |
1525 static void | |
15823 | 1526 buddy_idle_changed(PurpleBuddy *buddy, int old, int new, FinchBlist *ggblist) |
15818 | 1527 { |
1528 update_buddy_display(buddy, ggblist); | |
1529 } | |
1530 | |
1531 static void | |
1532 remove_peripherals(FinchBlist *ggblist) | |
1533 { | |
1534 if (ggblist->tooltip) | |
1535 remove_tooltip(ggblist); | |
1536 else if (ggblist->context) | |
1537 gnt_widget_destroy(ggblist->context); | |
1538 } | |
1539 | |
1540 static void | |
1541 size_changed_cb(GntWidget *w, int wi, int h) | |
1542 { | |
1543 int width, height; | |
1544 gnt_widget_get_size(w, &width, &height); | |
15823 | 1545 purple_prefs_set_int(PREF_ROOT "/size/width", width); |
1546 purple_prefs_set_int(PREF_ROOT "/size/height", height); | |
15818 | 1547 } |
1548 | |
1549 static void | |
1550 save_position_cb(GntWidget *w, int x, int y) | |
1551 { | |
15823 | 1552 purple_prefs_set_int(PREF_ROOT "/position/x", x); |
1553 purple_prefs_set_int(PREF_ROOT "/position/y", y); | |
15818 | 1554 } |
1555 | |
1556 static void | |
1557 reset_blist_window(GntWidget *window, gpointer null) | |
1558 { | |
15823 | 1559 PurpleBlistNode *node; |
1560 purple_signals_disconnect_by_handle(finch_blist_get_handle()); | |
1561 purple_get_blist()->ui_data = NULL; | |
15818 | 1562 |
15823 | 1563 node = purple_blist_get_root(); |
15818 | 1564 while (node) { |
1565 node->ui_data = NULL; | |
15823 | 1566 node = purple_blist_node_next(node, TRUE); |
15818 | 1567 } |
1568 | |
1569 if (ggblist->typing) | |
1570 g_source_remove(ggblist->typing); | |
1571 remove_peripherals(ggblist); | |
1572 if (ggblist->tagged) | |
1573 g_list_free(ggblist->tagged); | |
1574 g_free(ggblist); | |
1575 ggblist = NULL; | |
1576 } | |
1577 | |
1578 static void | |
1579 populate_buddylist() | |
1580 { | |
15823 | 1581 PurpleBlistNode *node; |
1582 PurpleBuddyList *list; | |
15818 | 1583 |
15823 | 1584 if (strcmp(purple_prefs_get_string(PREF_ROOT "/sort_type"), "text") == 0) { |
15818 | 1585 gnt_tree_set_compare_func(GNT_TREE(ggblist->tree), |
1586 (GCompareFunc)blist_node_compare_text); | |
15823 | 1587 } else if (strcmp(purple_prefs_get_string(PREF_ROOT "/sort_type"), "status") == 0) { |
15818 | 1588 gnt_tree_set_compare_func(GNT_TREE(ggblist->tree), |
1589 (GCompareFunc)blist_node_compare_status); | |
15823 | 1590 } else if (strcmp(purple_prefs_get_string(PREF_ROOT "/sort_type"), "log") == 0) { |
15818 | 1591 gnt_tree_set_compare_func(GNT_TREE(ggblist->tree), |
1592 (GCompareFunc)blist_node_compare_log); | |
1593 } | |
1594 | |
15823 | 1595 list = purple_get_blist(); |
1596 node = purple_blist_get_root(); | |
15818 | 1597 while (node) |
1598 { | |
1599 node_update(list, node); | |
15823 | 1600 node = purple_blist_node_next(node, FALSE); |
15818 | 1601 } |
1602 } | |
1603 | |
1604 static void | |
1605 destroy_status_list(GList *list) | |
1606 { | |
1607 g_list_foreach(list, (GFunc)g_free, NULL); | |
1608 g_list_free(list); | |
1609 } | |
1610 | |
1611 static void | |
1612 populate_status_dropdown() | |
1613 { | |
1614 int i; | |
1615 GList *iter; | |
1616 GList *items = NULL; | |
1617 StatusBoxItem *item = NULL; | |
1618 | |
1619 /* First the primitives */ | |
15823 | 1620 PurpleStatusPrimitive prims[] = {PURPLE_STATUS_AVAILABLE, PURPLE_STATUS_AWAY, |
1621 PURPLE_STATUS_INVISIBLE, PURPLE_STATUS_OFFLINE, PURPLE_STATUS_UNSET}; | |
15818 | 1622 |
1623 gnt_combo_box_remove_all(GNT_COMBO_BOX(ggblist->status)); | |
1624 | |
15823 | 1625 for (i = 0; prims[i] != PURPLE_STATUS_UNSET; i++) |
15818 | 1626 { |
1627 item = g_new0(StatusBoxItem, 1); | |
1628 item->type = STATUS_PRIMITIVE; | |
1629 item->u.prim = prims[i]; | |
1630 items = g_list_prepend(items, item); | |
1631 gnt_combo_box_add_data(GNT_COMBO_BOX(ggblist->status), item, | |
15823 | 1632 purple_primitive_get_name_from_type(prims[i])); |
15818 | 1633 } |
1634 | |
1635 /* Now the popular statuses */ | |
15823 | 1636 for (iter = purple_savedstatuses_get_popular(6); iter; iter = iter->next) |
15818 | 1637 { |
1638 item = g_new0(StatusBoxItem, 1); | |
1639 item->type = STATUS_SAVED_POPULAR; | |
1640 item->u.saved = iter->data; | |
1641 items = g_list_prepend(items, item); | |
1642 gnt_combo_box_add_data(GNT_COMBO_BOX(ggblist->status), item, | |
15823 | 1643 purple_savedstatus_get_title(iter->data)); |
15818 | 1644 } |
1645 | |
1646 /* New savedstatus */ | |
1647 item = g_new0(StatusBoxItem, 1); | |
1648 item->type = STATUS_SAVED_NEW; | |
1649 items = g_list_prepend(items, item); | |
1650 gnt_combo_box_add_data(GNT_COMBO_BOX(ggblist->status), item, | |
1651 _("New...")); | |
1652 | |
1653 /* More savedstatuses */ | |
1654 item = g_new0(StatusBoxItem, 1); | |
1655 item->type = STATUS_SAVED_ALL; | |
1656 items = g_list_prepend(items, item); | |
1657 gnt_combo_box_add_data(GNT_COMBO_BOX(ggblist->status), item, | |
1658 _("Saved...")); | |
1659 | |
1660 /* The keys for the combobox are created here, and never used | |
1661 * anywhere else. So make sure the keys are freed when the widget | |
1662 * is destroyed. */ | |
1663 g_object_set_data_full(G_OBJECT(ggblist->status), "list of statuses", | |
1664 items, (GDestroyNotify)destroy_status_list); | |
1665 } | |
1666 | |
1667 static void | |
15823 | 1668 redraw_blist(const char *name, PurplePrefType type, gconstpointer val, gpointer data) |
15818 | 1669 { |
15823 | 1670 PurpleBlistNode *node, *sel; |
15818 | 1671 if (ggblist == NULL || ggblist->window == NULL) |
1672 return; | |
1673 | |
1674 sel = gnt_tree_get_selection_data(GNT_TREE(ggblist->tree)); | |
1675 gnt_tree_remove_all(GNT_TREE(ggblist->tree)); | |
15823 | 1676 node = purple_blist_get_root(); |
1677 for (; node; node = purple_blist_node_next(node, TRUE)) | |
15818 | 1678 node->ui_data = NULL; |
1679 populate_buddylist(); | |
1680 gnt_tree_set_selected(GNT_TREE(ggblist->tree), sel); | |
1681 draw_tooltip(ggblist); | |
1682 } | |
1683 | |
1684 void finch_blist_init() | |
1685 { | |
15823 | 1686 purple_prefs_add_none(PREF_ROOT); |
1687 purple_prefs_add_none(PREF_ROOT "/size"); | |
1688 purple_prefs_add_int(PREF_ROOT "/size/width", 20); | |
1689 purple_prefs_add_int(PREF_ROOT "/size/height", 17); | |
1690 purple_prefs_add_none(PREF_ROOT "/position"); | |
1691 purple_prefs_add_int(PREF_ROOT "/position/x", 0); | |
1692 purple_prefs_add_int(PREF_ROOT "/position/y", 0); | |
1693 purple_prefs_add_bool(PREF_ROOT "/idletime", TRUE); | |
1694 purple_prefs_add_bool(PREF_ROOT "/showoffline", FALSE); | |
1695 purple_prefs_add_string(PREF_ROOT "/sort_type", "text"); | |
15818 | 1696 |
15823 | 1697 purple_prefs_connect_callback(finch_blist_get_handle(), |
15818 | 1698 PREF_ROOT "/showoffline", redraw_blist, NULL); |
15823 | 1699 purple_prefs_connect_callback(finch_blist_get_handle(), |
15818 | 1700 PREF_ROOT "/sort_type", redraw_blist, NULL); |
1701 | |
15823 | 1702 purple_signal_connect(purple_connections_get_handle(), "signed-on", purple_blist_get_handle(), |
15818 | 1703 G_CALLBACK(account_signed_on_cb), NULL); |
1704 return; | |
1705 } | |
1706 | |
1707 static gboolean | |
1708 remove_typing_cb(gpointer null) | |
1709 { | |
15823 | 1710 PurpleSavedStatus *current; |
15818 | 1711 const char *message, *newmessage; |
15823 | 1712 PurpleStatusPrimitive prim, newprim; |
15818 | 1713 StatusBoxItem *item; |
1714 | |
15823 | 1715 current = purple_savedstatus_get_current(); |
1716 message = purple_savedstatus_get_message(current); | |
1717 prim = purple_savedstatus_get_type(current); | |
15818 | 1718 |
1719 newmessage = gnt_entry_get_text(GNT_ENTRY(ggblist->statustext)); | |
1720 item = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(ggblist->status)); | |
16663
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16575
diff
changeset
|
1721 |
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16575
diff
changeset
|
1722 switch (item->type) { |
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16575
diff
changeset
|
1723 case STATUS_PRIMITIVE: |
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16575
diff
changeset
|
1724 newprim = item->u.prim; |
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16575
diff
changeset
|
1725 break; |
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16575
diff
changeset
|
1726 case STATUS_SAVED_POPULAR: |
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16575
diff
changeset
|
1727 newprim = purple_savedstatus_get_type(item->u.saved); |
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16575
diff
changeset
|
1728 break; |
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16575
diff
changeset
|
1729 default: |
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16575
diff
changeset
|
1730 goto end; /* 'New' or 'Saved' is selected, but this should never happen. */ |
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16575
diff
changeset
|
1731 } |
15818 | 1732 |
1733 if (newprim != prim || ((message && !newmessage) || | |
1734 (!message && newmessage) || | |
1735 (message && newmessage && g_utf8_collate(message, newmessage) != 0))) | |
1736 { | |
15823 | 1737 PurpleSavedStatus *status = purple_savedstatus_find_transient_by_type_and_message(newprim, newmessage); |
15818 | 1738 /* Holy Crap! That's a LAWNG function name */ |
1739 if (status == NULL) | |
1740 { | |
15823 | 1741 status = purple_savedstatus_new(NULL, newprim); |
1742 purple_savedstatus_set_message(status, newmessage); | |
15818 | 1743 } |
1744 | |
15823 | 1745 purple_savedstatus_activate(status); |
15818 | 1746 } |
1747 | |
1748 gnt_box_give_focus_to_child(GNT_BOX(ggblist->window), ggblist->tree); | |
16663
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16575
diff
changeset
|
1749 end: |
15818 | 1750 if (ggblist->typing) |
1751 g_source_remove(ggblist->typing); | |
1752 ggblist->typing = 0; | |
1753 return FALSE; | |
1754 } | |
1755 | |
1756 static void | |
1757 status_selection_changed(GntComboBox *box, StatusBoxItem *old, StatusBoxItem *now, gpointer null) | |
1758 { | |
1759 gnt_entry_set_text(GNT_ENTRY(ggblist->statustext), NULL); | |
1760 if (now->type == STATUS_SAVED_POPULAR) | |
1761 { | |
1762 /* Set the status immediately */ | |
15823 | 1763 purple_savedstatus_activate(now->u.saved); |
15818 | 1764 } |
1765 else if (now->type == STATUS_PRIMITIVE) | |
1766 { | |
1767 /* Move the focus to the entry box */ | |
1768 /* XXX: Make sure the selected status can have a message */ | |
1769 gnt_box_move_focus(GNT_BOX(ggblist->window), 1); | |
1770 ggblist->typing = g_timeout_add(TYPING_TIMEOUT, (GSourceFunc)remove_typing_cb, NULL); | |
1771 } | |
1772 else if (now->type == STATUS_SAVED_ALL) | |
1773 { | |
1774 /* Restore the selection to reflect current status. */ | |
15823 | 1775 savedstatus_changed(purple_savedstatus_get_current(), NULL); |
15818 | 1776 gnt_box_give_focus_to_child(GNT_BOX(ggblist->window), ggblist->tree); |
1777 finch_savedstatus_show_all(); | |
1778 } | |
1779 else if (now->type == STATUS_SAVED_NEW) | |
1780 { | |
15823 | 1781 savedstatus_changed(purple_savedstatus_get_current(), NULL); |
15818 | 1782 gnt_box_give_focus_to_child(GNT_BOX(ggblist->window), ggblist->tree); |
1783 finch_savedstatus_edit(NULL); | |
1784 } | |
1785 else | |
1786 g_return_if_reached(); | |
1787 } | |
1788 | |
1789 static gboolean | |
1790 status_text_changed(GntEntry *entry, const char *text, gpointer null) | |
1791 { | |
1792 if ((text[0] == 27 || (text[0] == '\t' && text[1] == '\0')) && ggblist->typing == 0) | |
1793 return FALSE; | |
1794 | |
1795 if (ggblist->typing) | |
1796 g_source_remove(ggblist->typing); | |
1797 ggblist->typing = 0; | |
1798 | |
1799 if (text[0] == '\r' && text[1] == 0) | |
1800 { | |
1801 /* Set the status only after you press 'Enter' */ | |
1802 remove_typing_cb(NULL); | |
1803 return TRUE; | |
1804 } | |
1805 | |
1806 ggblist->typing = g_timeout_add(TYPING_TIMEOUT, (GSourceFunc)remove_typing_cb, NULL); | |
1807 return FALSE; | |
1808 } | |
1809 | |
1810 static void | |
15823 | 1811 savedstatus_changed(PurpleSavedStatus *now, PurpleSavedStatus *old) |
15818 | 1812 { |
1813 GList *list; | |
15823 | 1814 PurpleStatusPrimitive prim; |
15818 | 1815 const char *message; |
1816 gboolean found = FALSE, saved = TRUE; | |
1817 | |
1818 if (!ggblist) | |
1819 return; | |
1820 | |
1821 /* Block the signals we don't want to emit */ | |
1822 g_signal_handlers_block_matched(ggblist->status, G_SIGNAL_MATCH_FUNC, | |
1823 0, 0, NULL, status_selection_changed, NULL); | |
1824 g_signal_handlers_block_matched(ggblist->statustext, G_SIGNAL_MATCH_FUNC, | |
1825 0, 0, NULL, status_text_changed, NULL); | |
1826 | |
15823 | 1827 prim = purple_savedstatus_get_type(now); |
1828 message = purple_savedstatus_get_message(now); | |
15818 | 1829 |
1830 /* Rebuild the status dropdown */ | |
1831 populate_status_dropdown(); | |
1832 | |
1833 while (!found) { | |
1834 list = g_object_get_data(G_OBJECT(ggblist->status), "list of statuses"); | |
1835 for (; list; list = list->next) | |
1836 { | |
1837 StatusBoxItem *item = list->data; | |
1838 if ((saved && item->type != STATUS_PRIMITIVE && item->u.saved == now) || | |
1839 (!saved && item->type == STATUS_PRIMITIVE && item->u.prim == prim)) | |
1840 { | |
15823 | 1841 char *mess = purple_unescape_html(message); |
15818 | 1842 gnt_combo_box_set_selected(GNT_COMBO_BOX(ggblist->status), item); |
1843 gnt_entry_set_text(GNT_ENTRY(ggblist->statustext), mess); | |
1844 gnt_widget_draw(ggblist->status); | |
1845 g_free(mess); | |
1846 found = TRUE; | |
1847 break; | |
1848 } | |
1849 } | |
1850 if (!saved) | |
1851 break; | |
1852 saved = FALSE; | |
1853 } | |
1854 | |
1855 g_signal_handlers_unblock_matched(ggblist->status, G_SIGNAL_MATCH_FUNC, | |
1856 0, 0, NULL, status_selection_changed, NULL); | |
1857 g_signal_handlers_unblock_matched(ggblist->statustext, G_SIGNAL_MATCH_FUNC, | |
1858 0, 0, NULL, status_text_changed, NULL); | |
1859 } | |
1860 | |
1861 static int | |
16491
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
1862 blist_node_compare_position(PurpleBlistNode *n1, PurpleBlistNode *n2) |
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
1863 { |
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
1864 while ((n1 = n1->prev) != NULL) |
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
1865 if (n1 == n2) |
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
1866 return 1; |
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
1867 return -1; |
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
1868 } |
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
1869 |
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
1870 static int |
15823 | 1871 blist_node_compare_text(PurpleBlistNode *n1, PurpleBlistNode *n2) |
15818 | 1872 { |
1873 const char *s1, *s2; | |
1874 char *us1, *us2; | |
1875 int ret; | |
17297
29b3dc9cc8c5
It's valid for different types to be compared. In that case, use existing positions.
Richard Nelson <wabz@pidgin.im>
parents:
17254
diff
changeset
|
1876 |
29b3dc9cc8c5
It's valid for different types to be compared. In that case, use existing positions.
Richard Nelson <wabz@pidgin.im>
parents:
17254
diff
changeset
|
1877 if (n1->type != n2->type) |
29b3dc9cc8c5
It's valid for different types to be compared. In that case, use existing positions.
Richard Nelson <wabz@pidgin.im>
parents:
17254
diff
changeset
|
1878 return blist_node_compare_position(n1, n2); |
29b3dc9cc8c5
It's valid for different types to be compared. In that case, use existing positions.
Richard Nelson <wabz@pidgin.im>
parents:
17254
diff
changeset
|
1879 |
15818 | 1880 switch (n1->type) |
1881 { | |
15823 | 1882 case PURPLE_BLIST_CHAT_NODE: |
1883 s1 = purple_chat_get_name((PurpleChat*)n1); | |
1884 s2 = purple_chat_get_name((PurpleChat*)n2); | |
15818 | 1885 break; |
15823 | 1886 case PURPLE_BLIST_BUDDY_NODE: |
1887 return purple_presence_compare(purple_buddy_get_presence((PurpleBuddy*)n1), | |
1888 purple_buddy_get_presence((PurpleBuddy*)n2)); | |
15818 | 1889 break; |
15823 | 1890 case PURPLE_BLIST_CONTACT_NODE: |
1891 s1 = purple_contact_get_alias((PurpleContact*)n1); | |
1892 s2 = purple_contact_get_alias((PurpleContact*)n2); | |
15818 | 1893 break; |
1894 default: | |
16491
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
1895 return blist_node_compare_position(n1, n2); |
15818 | 1896 } |
1897 | |
1898 us1 = g_utf8_strup(s1, -1); | |
1899 us2 = g_utf8_strup(s2, -1); | |
1900 ret = g_utf8_collate(us1, us2); | |
1901 g_free(us1); | |
1902 g_free(us2); | |
1903 | |
1904 return ret; | |
1905 } | |
1906 | |
1907 static int | |
15823 | 1908 blist_node_compare_status(PurpleBlistNode *n1, PurpleBlistNode *n2) |
15818 | 1909 { |
1910 int ret; | |
1911 | |
17297
29b3dc9cc8c5
It's valid for different types to be compared. In that case, use existing positions.
Richard Nelson <wabz@pidgin.im>
parents:
17254
diff
changeset
|
1912 if (n1->type != n2->type) |
29b3dc9cc8c5
It's valid for different types to be compared. In that case, use existing positions.
Richard Nelson <wabz@pidgin.im>
parents:
17254
diff
changeset
|
1913 return blist_node_compare_position(n1, n2); |
15818 | 1914 |
1915 switch (n1->type) { | |
15823 | 1916 case PURPLE_BLIST_CONTACT_NODE: |
1917 n1 = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)n1); | |
1918 n2 = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)n2); | |
15818 | 1919 /* now compare the presence of the priority buddies */ |
15823 | 1920 case PURPLE_BLIST_BUDDY_NODE: |
1921 ret = purple_presence_compare(purple_buddy_get_presence((PurpleBuddy*)n1), | |
1922 purple_buddy_get_presence((PurpleBuddy*)n2)); | |
15818 | 1923 if (ret != 0) |
1924 return ret; | |
1925 break; | |
1926 default: | |
16491
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
1927 return blist_node_compare_position(n1, n2); |
15818 | 1928 break; |
1929 } | |
1930 | |
1931 /* Sort alphabetically if presence is not comparable */ | |
1932 ret = blist_node_compare_text(n1, n2); | |
1933 | |
1934 return ret; | |
1935 } | |
1936 | |
1937 static int | |
15823 | 1938 get_contact_log_size(PurpleBlistNode *c) |
15818 | 1939 { |
1940 int log = 0; | |
15823 | 1941 PurpleBlistNode *node; |
15818 | 1942 |
1943 for (node = c->child; node; node = node->next) { | |
15823 | 1944 PurpleBuddy *b = (PurpleBuddy*)node; |
1945 log += purple_log_get_total_size(PURPLE_LOG_IM, b->name, b->account); | |
15818 | 1946 } |
1947 | |
1948 return log; | |
1949 } | |
1950 | |
1951 static int | |
15823 | 1952 blist_node_compare_log(PurpleBlistNode *n1, PurpleBlistNode *n2) |
15818 | 1953 { |
1954 int ret; | |
15823 | 1955 PurpleBuddy *b1, *b2; |
15818 | 1956 |
17297
29b3dc9cc8c5
It's valid for different types to be compared. In that case, use existing positions.
Richard Nelson <wabz@pidgin.im>
parents:
17254
diff
changeset
|
1957 if (n1->type != n2->type) |
29b3dc9cc8c5
It's valid for different types to be compared. In that case, use existing positions.
Richard Nelson <wabz@pidgin.im>
parents:
17254
diff
changeset
|
1958 return blist_node_compare_position(n1, n2); |
15818 | 1959 |
1960 switch (n1->type) { | |
15823 | 1961 case PURPLE_BLIST_BUDDY_NODE: |
1962 b1 = (PurpleBuddy*)n1; | |
1963 b2 = (PurpleBuddy*)n2; | |
1964 ret = purple_log_get_total_size(PURPLE_LOG_IM, b2->name, b2->account) - | |
1965 purple_log_get_total_size(PURPLE_LOG_IM, b1->name, b1->account); | |
15818 | 1966 if (ret != 0) |
1967 return ret; | |
1968 break; | |
15823 | 1969 case PURPLE_BLIST_CONTACT_NODE: |
15818 | 1970 ret = get_contact_log_size(n2) - get_contact_log_size(n1); |
1971 if (ret != 0) | |
1972 return ret; | |
1973 break; | |
1974 default: | |
16491
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
1975 return blist_node_compare_position(n1, n2); |
15818 | 1976 } |
1977 ret = blist_node_compare_text(n1, n2); | |
1978 return ret; | |
1979 } | |
1980 | |
1981 static gboolean | |
1982 blist_clicked(GntTree *tree, GntMouseEvent event, int x, int y, gpointer ggblist) | |
1983 { | |
1984 if (event == GNT_RIGHT_MOUSE_DOWN) { | |
1985 draw_context_menu(ggblist); | |
1986 } | |
1987 return FALSE; | |
1988 } | |
1989 | |
1990 static void | |
1991 plugin_action(GntMenuItem *item, gpointer data) | |
1992 { | |
15823 | 1993 PurplePluginAction *action = data; |
15818 | 1994 if (action && action->callback) |
1995 action->callback(action); | |
1996 } | |
1997 | |
1998 static void | |
15823 | 1999 build_plugin_actions(GntMenuItem *item, PurplePlugin *plugin, gpointer context) |
15818 | 2000 { |
2001 GntWidget *sub = gnt_menu_new(GNT_MENU_POPUP); | |
2002 GList *actions; | |
2003 GntMenuItem *menuitem; | |
2004 | |
2005 gnt_menuitem_set_submenu(item, GNT_MENU(sub)); | |
15823 | 2006 for (actions = PURPLE_PLUGIN_ACTIONS(plugin, context); actions; |
15818 | 2007 actions = g_list_delete_link(actions, actions)) { |
2008 if (actions->data) { | |
15823 | 2009 PurplePluginAction *action = actions->data; |
15818 | 2010 action->plugin = plugin; |
2011 action->context = context; | |
2012 menuitem = gnt_menuitem_new(action->label); | |
2013 gnt_menu_add_item(GNT_MENU(sub), menuitem); | |
2014 | |
2015 gnt_menuitem_set_callback(menuitem, plugin_action, action); | |
2016 g_object_set_data_full(G_OBJECT(menuitem), "plugin_action", | |
15823 | 2017 action, (GDestroyNotify)purple_plugin_action_free); |
15818 | 2018 } |
2019 } | |
2020 } | |
2021 | |
2022 static void | |
2023 reconstruct_plugins_menu() | |
2024 { | |
2025 GntWidget *sub; | |
2026 GntMenuItem *plg; | |
2027 GList *iter; | |
2028 | |
2029 if (!ggblist) | |
2030 return; | |
2031 | |
2032 if (ggblist->plugins == NULL) | |
2033 ggblist->plugins = gnt_menuitem_new(_("Plugins")); | |
2034 | |
2035 plg = ggblist->plugins; | |
2036 sub = gnt_menu_new(GNT_MENU_POPUP); | |
2037 gnt_menuitem_set_submenu(plg, GNT_MENU(sub)); | |
2038 | |
15823 | 2039 for (iter = purple_plugins_get_loaded(); iter; iter = iter->next) { |
2040 PurplePlugin *plugin = iter->data; | |
15818 | 2041 GntMenuItem *item; |
15823 | 2042 if (PURPLE_IS_PROTOCOL_PLUGIN(plugin)) |
15818 | 2043 continue; |
2044 | |
15823 | 2045 if (!PURPLE_PLUGIN_HAS_ACTIONS(plugin)) |
15818 | 2046 continue; |
2047 | |
2048 item = gnt_menuitem_new(_(plugin->info->name)); | |
2049 gnt_menu_add_item(GNT_MENU(sub), item); | |
2050 build_plugin_actions(item, plugin, NULL); | |
2051 } | |
2052 } | |
2053 | |
2054 static void | |
2055 reconstruct_accounts_menu() | |
2056 { | |
2057 GntWidget *sub; | |
2058 GntMenuItem *acc, *item; | |
2059 GList *iter; | |
2060 | |
2061 if (!ggblist) | |
2062 return; | |
2063 | |
2064 if (ggblist->accounts == NULL) | |
2065 ggblist->accounts = gnt_menuitem_new(_("Accounts")); | |
2066 | |
2067 acc = ggblist->accounts; | |
2068 sub = gnt_menu_new(GNT_MENU_POPUP); | |
2069 gnt_menuitem_set_submenu(acc, GNT_MENU(sub)); | |
2070 | |
15823 | 2071 for (iter = purple_accounts_get_all_active(); iter; |
15818 | 2072 iter = g_list_delete_link(iter, iter)) { |
15823 | 2073 PurpleAccount *account = iter->data; |
2074 PurpleConnection *gc = purple_account_get_connection(account); | |
2075 PurplePlugin *prpl; | |
15818 | 2076 |
15823 | 2077 if (!gc || !PURPLE_CONNECTION_IS_CONNECTED(gc)) |
15818 | 2078 continue; |
2079 prpl = gc->prpl; | |
2080 | |
15823 | 2081 if (PURPLE_PLUGIN_HAS_ACTIONS(prpl)) { |
2082 item = gnt_menuitem_new(purple_account_get_username(account)); | |
15818 | 2083 gnt_menu_add_item(GNT_MENU(sub), item); |
2084 build_plugin_actions(item, prpl, gc); | |
2085 } | |
2086 } | |
2087 } | |
2088 | |
2089 static void | |
16782
d7ad8013b914
Fix this spectacularly braindead code. I must've been on the good stuff when I wrote this. Fixes #364.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16663
diff
changeset
|
2090 account_signed_on_cb(PurpleConnection *pc, gpointer null) |
15818 | 2091 { |
15823 | 2092 PurpleBlistNode *node; |
15818 | 2093 |
15823 | 2094 for (node = purple_blist_get_root(); node; |
2095 node = purple_blist_node_next(node, FALSE)) { | |
2096 if (PURPLE_BLIST_NODE_IS_CHAT(node)) { | |
2097 PurpleChat *chat = (PurpleChat*)node; | |
16782
d7ad8013b914
Fix this spectacularly braindead code. I must've been on the good stuff when I wrote this. Fixes #364.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16663
diff
changeset
|
2098 if (chat->account == purple_connection_get_account(pc) && |
d7ad8013b914
Fix this spectacularly braindead code. I must've been on the good stuff when I wrote this. Fixes #364.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16663
diff
changeset
|
2099 purple_blist_node_get_bool(node, "gnt-autojoin")) |
15823 | 2100 serv_join_chat(purple_account_get_connection(chat->account), chat->components); |
15818 | 2101 } |
2102 } | |
2103 } | |
2104 | |
2105 static void show_offline_cb(GntMenuItem *item, gpointer n) | |
2106 { | |
15823 | 2107 purple_prefs_set_bool(PREF_ROOT "/showoffline", |
2108 !purple_prefs_get_bool(PREF_ROOT "/showoffline")); | |
15818 | 2109 } |
2110 | |
2111 static void sort_blist_change_cb(GntMenuItem *item, gpointer n) | |
2112 { | |
15823 | 2113 purple_prefs_set_string(PREF_ROOT "/sort_type", n); |
15818 | 2114 } |
2115 | |
2116 /* XXX: send_im_select* -- Xerox */ | |
2117 static void | |
15823 | 2118 send_im_select_cb(gpointer data, PurpleRequestFields *fields) |
15818 | 2119 { |
15823 | 2120 PurpleAccount *account; |
15818 | 2121 const char *username; |
2122 | |
15823 | 2123 account = purple_request_fields_get_account(fields, "account"); |
2124 username = purple_request_fields_get_string(fields, "screenname"); | |
15818 | 2125 |
15823 | 2126 purple_conversation_new(PURPLE_CONV_TYPE_IM, account, username); |
15818 | 2127 } |
2128 | |
2129 static void | |
2130 send_im_select(GntMenuItem *item, gpointer n) | |
2131 { | |
15823 | 2132 PurpleRequestFields *fields; |
2133 PurpleRequestFieldGroup *group; | |
2134 PurpleRequestField *field; | |
15818 | 2135 |
15823 | 2136 fields = purple_request_fields_new(); |
15818 | 2137 |
15823 | 2138 group = purple_request_field_group_new(NULL); |
2139 purple_request_fields_add_group(fields, group); | |
15818 | 2140 |
15823 | 2141 field = purple_request_field_string_new("screenname", _("_Name"), NULL, FALSE); |
2142 purple_request_field_set_type_hint(field, "screenname"); | |
2143 purple_request_field_set_required(field, TRUE); | |
2144 purple_request_field_group_add_field(group, field); | |
15818 | 2145 |
15823 | 2146 field = purple_request_field_account_new("account", _("_Account"), NULL); |
2147 purple_request_field_set_type_hint(field, "account"); | |
2148 purple_request_field_set_visible(field, | |
2149 (purple_connections_get_all() != NULL && | |
2150 purple_connections_get_all()->next != NULL)); | |
2151 purple_request_field_set_required(field, TRUE); | |
2152 purple_request_field_group_add_field(group, field); | |
15818 | 2153 |
15823 | 2154 purple_request_fields(purple_get_blist(), _("New Instant Message"), |
15818 | 2155 NULL, |
2156 _("Please enter the screen name or alias of the person " | |
2157 "you would like to IM."), | |
2158 fields, | |
2159 _("OK"), G_CALLBACK(send_im_select_cb), | |
2160 _("Cancel"), NULL, | |
16442
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16427
diff
changeset
|
2161 NULL, NULL, NULL, |
15818 | 2162 NULL); |
2163 } | |
2164 | |
2165 static void | |
2166 create_menu() | |
2167 { | |
2168 GntWidget *menu, *sub; | |
2169 GntMenuItem *item; | |
2170 GntWindow *window; | |
2171 | |
2172 if (!ggblist) | |
2173 return; | |
2174 | |
2175 window = GNT_WINDOW(ggblist->window); | |
2176 ggblist->menu = menu = gnt_menu_new(GNT_MENU_TOPLEVEL); | |
2177 gnt_window_set_menu(window, GNT_MENU(menu)); | |
2178 | |
2179 item = gnt_menuitem_new(_("Options")); | |
2180 gnt_menu_add_item(GNT_MENU(menu), item); | |
2181 | |
2182 sub = gnt_menu_new(GNT_MENU_POPUP); | |
2183 gnt_menuitem_set_submenu(item, GNT_MENU(sub)); | |
2184 | |
2185 item = gnt_menuitem_new(_("Send IM...")); | |
2186 gnt_menu_add_item(GNT_MENU(sub), item); | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
2187 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), send_im_select, NULL); |
15818 | 2188 |
16935
49f66fab6b31
Change a string.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16824
diff
changeset
|
2189 item = gnt_menuitem_check_new(_("Show offline buddies")); |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
2190 gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(item), |
15823 | 2191 purple_prefs_get_bool(PREF_ROOT "/showoffline")); |
15818 | 2192 gnt_menu_add_item(GNT_MENU(sub), item); |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
2193 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), show_offline_cb, NULL); |
15818 | 2194 |
2195 item = gnt_menuitem_new(_("Sort by status")); | |
2196 gnt_menu_add_item(GNT_MENU(sub), item); | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
2197 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), sort_blist_change_cb, "status"); |
15818 | 2198 |
2199 item = gnt_menuitem_new(_("Sort alphabetically")); | |
2200 gnt_menu_add_item(GNT_MENU(sub), item); | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
2201 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), sort_blist_change_cb, "text"); |
15818 | 2202 |
2203 item = gnt_menuitem_new(_("Sort by log size")); | |
2204 gnt_menu_add_item(GNT_MENU(sub), item); | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
2205 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), sort_blist_change_cb, "log"); |
15818 | 2206 |
2207 reconstruct_accounts_menu(); | |
2208 gnt_menu_add_item(GNT_MENU(menu), ggblist->accounts); | |
2209 | |
2210 reconstruct_plugins_menu(); | |
2211 gnt_menu_add_item(GNT_MENU(menu), ggblist->plugins); | |
2212 } | |
2213 | |
2214 void finch_blist_show() | |
2215 { | |
15823 | 2216 blist_show(purple_get_blist()); |
15818 | 2217 } |
2218 | |
2219 static void | |
16105
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
2220 group_collapsed(GntWidget *widget, PurpleBlistNode *node, gboolean collapsed, gpointer null) |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
2221 { |
16106 | 2222 if (PURPLE_BLIST_NODE_IS_GROUP(node)) |
2223 purple_blist_node_set_bool(node, "collapsed", collapsed); | |
16105
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
2224 } |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
2225 |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
2226 static void |
15823 | 2227 blist_show(PurpleBuddyList *list) |
15818 | 2228 { |
2229 if (ggblist == NULL) | |
2230 new_list(list); | |
2231 else if (ggblist->window) | |
2232 return; | |
2233 | |
2234 ggblist->window = gnt_vwindow_new(FALSE); | |
2235 gnt_widget_set_name(ggblist->window, "buddylist"); | |
2236 gnt_box_set_toplevel(GNT_BOX(ggblist->window), TRUE); | |
2237 gnt_box_set_title(GNT_BOX(ggblist->window), _("Buddy List")); | |
2238 gnt_box_set_pad(GNT_BOX(ggblist->window), 0); | |
2239 | |
2240 ggblist->tree = gnt_tree_new(); | |
2241 | |
2242 GNT_WIDGET_SET_FLAGS(ggblist->tree, GNT_WIDGET_NO_BORDER); | |
15823 | 2243 gnt_widget_set_size(ggblist->tree, purple_prefs_get_int(PREF_ROOT "/size/width"), |
2244 purple_prefs_get_int(PREF_ROOT "/size/height")); | |
2245 gnt_widget_set_position(ggblist->window, purple_prefs_get_int(PREF_ROOT "/position/x"), | |
2246 purple_prefs_get_int(PREF_ROOT "/position/y")); | |
15818 | 2247 |
2248 gnt_tree_set_col_width(GNT_TREE(ggblist->tree), 0, | |
15823 | 2249 purple_prefs_get_int(PREF_ROOT "/size/width") - 1); |
15818 | 2250 |
2251 gnt_box_add_widget(GNT_BOX(ggblist->window), ggblist->tree); | |
2252 | |
2253 ggblist->status = gnt_combo_box_new(); | |
2254 gnt_box_add_widget(GNT_BOX(ggblist->window), ggblist->status); | |
2255 ggblist->statustext = gnt_entry_new(NULL); | |
2256 gnt_box_add_widget(GNT_BOX(ggblist->window), ggblist->statustext); | |
2257 | |
2258 gnt_widget_show(ggblist->window); | |
2259 | |
15823 | 2260 purple_signal_connect(purple_connections_get_handle(), "signed-on", finch_blist_get_handle(), |
2261 PURPLE_CALLBACK(reconstruct_accounts_menu), NULL); | |
2262 purple_signal_connect(purple_connections_get_handle(), "signed-off", finch_blist_get_handle(), | |
2263 PURPLE_CALLBACK(reconstruct_accounts_menu), NULL); | |
2264 purple_signal_connect(purple_blist_get_handle(), "buddy-status-changed", finch_blist_get_handle(), | |
2265 PURPLE_CALLBACK(buddy_status_changed), ggblist); | |
2266 purple_signal_connect(purple_blist_get_handle(), "buddy-idle-changed", finch_blist_get_handle(), | |
2267 PURPLE_CALLBACK(buddy_idle_changed), ggblist); | |
15818 | 2268 |
15823 | 2269 purple_signal_connect(purple_plugins_get_handle(), "plugin-load", finch_blist_get_handle(), |
2270 PURPLE_CALLBACK(reconstruct_plugins_menu), NULL); | |
2271 purple_signal_connect(purple_plugins_get_handle(), "plugin-unload", finch_blist_get_handle(), | |
2272 PURPLE_CALLBACK(reconstruct_plugins_menu), NULL); | |
15818 | 2273 |
2274 #if 0 | |
15823 | 2275 purple_signal_connect(purple_blist_get_handle(), "buddy-signed-on", finch_blist_get_handle(), |
2276 PURPLE_CALLBACK(buddy_signed_on), ggblist); | |
2277 purple_signal_connect(purple_blist_get_handle(), "buddy-signed-off", finch_blist_get_handle(), | |
2278 PURPLE_CALLBACK(buddy_signed_off), ggblist); | |
15818 | 2279 |
2280 /* These I plan to use to indicate unread-messages etc. */ | |
15823 | 2281 purple_signal_connect(purple_conversations_get_handle(), "received-im-msg", finch_blist_get_handle(), |
2282 PURPLE_CALLBACK(received_im_msg), list); | |
2283 purple_signal_connect(purple_conversations_get_handle(), "sent-im-msg", finch_blist_get_handle(), | |
2284 PURPLE_CALLBACK(sent_im_msg), NULL); | |
15818 | 2285 |
15823 | 2286 purple_signal_connect(purple_conversations_get_handle(), "received-chat-msg", finch_blist_get_handle(), |
2287 PURPLE_CALLBACK(received_chat_msg), list); | |
15818 | 2288 #endif |
2289 | |
2290 g_signal_connect(G_OBJECT(ggblist->tree), "selection_changed", G_CALLBACK(selection_changed), ggblist); | |
2291 g_signal_connect(G_OBJECT(ggblist->tree), "key_pressed", G_CALLBACK(key_pressed), ggblist); | |
2292 g_signal_connect(G_OBJECT(ggblist->tree), "context-menu", G_CALLBACK(context_menu), ggblist); | |
16105
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
2293 g_signal_connect(G_OBJECT(ggblist->tree), "collapse-toggled", G_CALLBACK(group_collapsed), NULL); |
15818 | 2294 g_signal_connect_after(G_OBJECT(ggblist->tree), "clicked", G_CALLBACK(blist_clicked), ggblist); |
2295 g_signal_connect(G_OBJECT(ggblist->tree), "activate", G_CALLBACK(selection_activate), ggblist); | |
2296 g_signal_connect_data(G_OBJECT(ggblist->tree), "gained-focus", G_CALLBACK(draw_tooltip), | |
2297 ggblist, 0, G_CONNECT_AFTER | G_CONNECT_SWAPPED); | |
2298 g_signal_connect_data(G_OBJECT(ggblist->tree), "lost-focus", G_CALLBACK(remove_peripherals), | |
2299 ggblist, 0, G_CONNECT_AFTER | G_CONNECT_SWAPPED); | |
2300 g_signal_connect(G_OBJECT(ggblist->tree), "size_changed", G_CALLBACK(size_changed_cb), NULL); | |
2301 g_signal_connect(G_OBJECT(ggblist->window), "position_set", G_CALLBACK(save_position_cb), NULL); | |
2302 g_signal_connect(G_OBJECT(ggblist->window), "destroy", G_CALLBACK(reset_blist_window), NULL); | |
2303 | |
2304 /* Status signals */ | |
15823 | 2305 purple_signal_connect(purple_savedstatuses_get_handle(), "savedstatus-changed", finch_blist_get_handle(), |
2306 PURPLE_CALLBACK(savedstatus_changed), NULL); | |
15818 | 2307 g_signal_connect(G_OBJECT(ggblist->status), "selection_changed", |
2308 G_CALLBACK(status_selection_changed), NULL); | |
2309 g_signal_connect(G_OBJECT(ggblist->statustext), "key_pressed", | |
2310 G_CALLBACK(status_text_changed), NULL); | |
2311 | |
2312 create_menu(); | |
2313 | |
2314 populate_buddylist(); | |
2315 | |
15823 | 2316 savedstatus_changed(purple_savedstatus_get_current(), NULL); |
15818 | 2317 } |
2318 | |
2319 void finch_blist_uninit() | |
2320 { | |
2321 if (ggblist == NULL) | |
2322 return; | |
2323 | |
2324 gnt_widget_destroy(ggblist->window); | |
2325 g_free(ggblist); | |
2326 ggblist = NULL; | |
2327 } | |
2328 | |
2329 gboolean finch_blist_get_position(int *x, int *y) | |
2330 { | |
2331 if (!ggblist || !ggblist->window) | |
2332 return FALSE; | |
2333 gnt_widget_get_position(ggblist->window, x, y); | |
2334 return TRUE; | |
2335 } | |
2336 | |
2337 void finch_blist_set_position(int x, int y) | |
2338 { | |
2339 gnt_widget_set_position(ggblist->window, x, y); | |
2340 } | |
2341 | |
2342 gboolean finch_blist_get_size(int *width, int *height) | |
2343 { | |
2344 if (!ggblist || !ggblist->window) | |
2345 return FALSE; | |
2346 gnt_widget_get_size(ggblist->window, width, height); | |
2347 return TRUE; | |
2348 } | |
2349 | |
2350 void finch_blist_set_size(int width, int height) | |
2351 { | |
2352 gnt_widget_set_size(ggblist->window, width, height); | |
2353 } | |
2354 |