Mercurial > pidgin
annotate finch/gntblist.c @ 18031:23a65f460e34
ChangeLog.API updates
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sat, 02 Jun 2007 18:12:27 +0000 |
parents | 29b3dc9cc8c5 |
children | 995f31f5432a |
rev | line source |
---|---|
15817 | 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 |
15817 | 4 * |
15870
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15843
diff
changeset
|
5 * finch |
15817 | 6 * |
15870
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15843
diff
changeset
|
7 * Finch is the legal property of its developers, whose names are too numerous |
15817 | 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 | |
15822 | 36 #include "finch.h" |
15817 | 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 | |
16424
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" |
15817 | 57 #define TYPING_TIMEOUT 4000 |
58 | |
59 typedef struct | |
60 { | |
61 GntWidget *window; | |
62 GntWidget *tree; | |
63 | |
64 GntWidget *tooltip; | |
15822 | 65 PurpleBlistNode *tnode; /* Who is the tooltip being displayed for? */ |
15817 | 66 GList *tagged; /* A list of tagged blistnodes */ |
67 | |
68 GntWidget *context; | |
15822 | 69 PurpleBlistNode *cnode; |
15817 | 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 { | |
15822 | 95 PurpleStatusPrimitive prim; |
96 PurpleSavedStatus *saved; | |
15817 | 97 } u; |
98 } StatusBoxItem; | |
99 | |
100 FinchBlist *ggblist; | |
101 | |
15822 | 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); | |
15817 | 107 static void draw_tooltip(FinchBlist *ggblist); |
108 static gboolean remove_typing_cb(gpointer null); | |
109 static void remove_peripherals(FinchBlist *ggblist); | |
15822 | 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); | |
16567
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:
16483
diff
changeset
|
113 static void update_node_display(PurpleBlistNode *buddy, FinchBlist *ggblist); |
15822 | 114 static void update_buddy_display(PurpleBuddy *buddy, FinchBlist *ggblist); |
16771
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:
16655
diff
changeset
|
115 static void account_signed_on_cb(PurpleConnection *pc, gpointer null); |
17203
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:
17091
diff
changeset
|
116 static void finch_request_add_buddy(PurpleAccount *account, const char *username, const char *grp, const char *alias); |
15817 | 117 |
118 /* Sort functions */ | |
16483
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
119 static int blist_node_compare_position(PurpleBlistNode *n1, PurpleBlistNode *n2); |
15822 | 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); | |
15817 | 123 |
124 static gboolean | |
15822 | 125 is_contact_online(PurpleContact *contact) |
15817 | 126 { |
15822 | 127 PurpleBlistNode *node; |
128 for (node = ((PurpleBlistNode*)contact)->child; node; node = node->next) { | |
129 if (PURPLE_BUDDY_IS_ONLINE((PurpleBuddy*)node)) | |
15817 | 130 return TRUE; |
131 } | |
132 return FALSE; | |
133 } | |
134 | |
135 static gboolean | |
15822 | 136 is_group_online(PurpleGroup *group) |
15817 | 137 { |
15822 | 138 PurpleBlistNode *node; |
139 for (node = ((PurpleBlistNode*)group)->child; node; node = node->next) { | |
140 if (PURPLE_BLIST_NODE_IS_CHAT(node)) | |
15817 | 141 return TRUE; |
15822 | 142 else if (is_contact_online((PurpleContact*)node)) |
15817 | 143 return TRUE; |
144 } | |
145 return FALSE; | |
146 } | |
147 | |
148 static void | |
15822 | 149 new_node(PurpleBlistNode *node) |
15817 | 150 { |
151 } | |
152 | |
15822 | 153 static void add_node(PurpleBlistNode *node, FinchBlist *ggblist) |
15817 | 154 { |
15822 | 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); | |
15817 | 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 | |
15822 | 175 node_remove(PurpleBuddyList *list, PurpleBlistNode *node) |
15817 | 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 | |
15822 | 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)) || | |
15817 | 190 contact->currentsize < 1) |
15822 | 191 node_remove(list, (PurpleBlistNode*)contact); |
16567
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:
16483
diff
changeset
|
192 } else if (!PURPLE_BLIST_NODE_IS_GROUP(node)) { |
15822 | 193 PurpleGroup *group = (PurpleGroup*)node->parent; |
194 if ((!purple_prefs_get_bool(PREF_ROOT "/showoffline") && !is_group_online(group)) || | |
15817 | 195 group->currentsize < 1) |
196 node_remove(list, node->parent); | |
197 for (node = node->child; node; node = node->next) | |
198 node->ui_data = NULL; | |
16567
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:
16483
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:
16483
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:
16483
diff
changeset
|
201 node_remove(list, node); |
15817 | 202 } |
203 | |
204 draw_tooltip(ggblist); | |
205 } | |
206 | |
207 static void | |
15822 | 208 node_update(PurpleBuddyList *list, PurpleBlistNode *node) |
15817 | 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 | |
15822 | 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); | |
15817 | 229 else |
15822 | 230 node_remove(purple_get_blist(), node); |
15817 | 231 |
232 node_update(list, node->parent); | |
15822 | 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)) || | |
15817 | 238 contact->currentsize < 1) |
15822 | 239 node_remove(purple_get_blist(), node); |
16567
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
diff
changeset
|
246 } |
15822 | 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)) || | |
15817 | 250 group->currentsize < 1) |
251 node_remove(list, node); | |
16567
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:
16483
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:
16483
diff
changeset
|
253 add_node(node, list->ui_data); |
15817 | 254 } |
255 } | |
256 | |
257 static void | |
15822 | 258 new_list(PurpleBuddyList *list) |
15817 | 259 { |
260 if (ggblist) | |
261 return; | |
262 | |
263 ggblist = g_new0(FinchBlist, 1); | |
264 list->ui_data = ggblist; | |
265 } | |
266 | |
267 static void | |
15822 | 268 add_buddy_cb(void *data, PurpleRequestFields *allfields) |
15817 | 269 { |
15822 | 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"); | |
15817 | 274 const char *error = NULL; |
15822 | 275 PurpleGroup *grp; |
276 PurpleBuddy *buddy; | |
15817 | 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."); | |
16926
7e4a22162bb6
Show an error message when trying to add a buddy from an offline account.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16925
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:
16925
diff
changeset
|
285 error = _("The selected account is not online."); |
15817 | 286 |
287 if (error) | |
288 { | |
17203
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:
17091
diff
changeset
|
289 finch_request_add_buddy(account, username, group, alias); |
15822 | 290 purple_notify_error(NULL, _("Error"), _("Error adding buddy"), error); |
15817 | 291 return; |
292 } | |
293 | |
15822 | 294 grp = purple_find_group(group); |
15817 | 295 if (!grp) |
296 { | |
15822 | 297 grp = purple_group_new(group); |
298 purple_blist_add_group(grp, NULL); | |
15817 | 299 } |
300 | |
15822 | 301 buddy = purple_buddy_new(account, username, alias); |
302 purple_blist_add_buddy(buddy, NULL, grp, NULL); | |
303 purple_account_add_buddy(account, buddy); | |
15817 | 304 } |
305 | |
306 static void | |
15822 | 307 finch_request_add_buddy(PurpleAccount *account, const char *username, const char *grp, const char *alias) |
15817 | 308 { |
15822 | 309 PurpleRequestFields *fields = purple_request_fields_new(); |
310 PurpleRequestFieldGroup *group = purple_request_field_group_new(NULL); | |
311 PurpleRequestField *field; | |
15817 | 312 |
15822 | 313 purple_request_fields_add_group(fields, group); |
15817 | 314 |
15822 | 315 field = purple_request_field_string_new("screenname", _("Screen Name"), username, FALSE); |
316 purple_request_field_group_add_field(group, field); | |
15817 | 317 |
15822 | 318 field = purple_request_field_string_new("alias", _("Alias"), alias, FALSE); |
319 purple_request_field_group_add_field(group, field); | |
15817 | 320 |
15822 | 321 field = purple_request_field_string_new("group", _("Group"), grp, FALSE); |
322 purple_request_field_group_add_field(group, field); | |
15843
e74c2488448b
Group autocomplete for buddy adding
Richard Nelson <wabz@pidgin.im>
parents:
15822
diff
changeset
|
323 purple_request_field_set_type_hint(field, "group"); |
15817 | 324 |
15822 | 325 field = purple_request_field_account_new("account", _("Account"), NULL); |
326 purple_request_field_account_set_show_all(field, FALSE); | |
15817 | 327 if (account) |
15822 | 328 purple_request_field_account_set_value(field, account); |
329 purple_request_field_group_add_field(group, field); | |
15817 | 330 |
15822 | 331 purple_request_fields(NULL, _("Add Buddy"), NULL, _("Please enter buddy information."), |
16439
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:
16424
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:
16424
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:
16424
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:
16424
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:
16424
diff
changeset
|
336 NULL); |
15817 | 337 } |
338 | |
339 static void | |
15822 | 340 add_chat_cb(void *data, PurpleRequestFields *allfields) |
15817 | 341 { |
15822 | 342 PurpleAccount *account; |
15817 | 343 const char *alias, *name, *group; |
15822 | 344 PurpleChat *chat; |
345 PurpleGroup *grp; | |
15817 | 346 GHashTable *hash = NULL; |
15822 | 347 PurpleConnection *gc; |
15817 | 348 |
15822 | 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"); | |
15817 | 353 |
15822 | 354 if (!purple_account_is_connected(account) || !name || !*name) |
15817 | 355 return; |
356 | |
357 if (!group || !*group) | |
358 group = _("Chats"); | |
359 | |
15822 | 360 gc = purple_account_get_connection(account); |
15817 | 361 |
15822 | 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); | |
15817 | 364 |
15822 | 365 chat = purple_chat_new(account, name, hash); |
15817 | 366 |
367 if (chat != NULL) { | |
15822 | 368 if ((grp = purple_find_group(group)) == NULL) { |
369 grp = purple_group_new(group); | |
370 purple_blist_add_group(grp, NULL); | |
15817 | 371 } |
15822 | 372 purple_blist_add_chat(chat, grp, NULL); |
373 purple_blist_alias_chat(chat, alias); | |
15817 | 374 } |
375 } | |
376 | |
377 static void | |
15822 | 378 finch_request_add_chat(PurpleAccount *account, PurpleGroup *grp, const char *alias, const char *name) |
15817 | 379 { |
15822 | 380 PurpleRequestFields *fields = purple_request_fields_new(); |
381 PurpleRequestFieldGroup *group = purple_request_field_group_new(NULL); | |
382 PurpleRequestField *field; | |
15817 | 383 |
15822 | 384 purple_request_fields_add_group(fields, group); |
15817 | 385 |
15822 | 386 field = purple_request_field_account_new("account", _("Account"), NULL); |
387 purple_request_field_account_set_show_all(field, FALSE); | |
15817 | 388 if (account) |
15822 | 389 purple_request_field_account_set_value(field, account); |
390 purple_request_field_group_add_field(group, field); | |
15817 | 391 |
15822 | 392 field = purple_request_field_string_new("name", _("Name"), name, FALSE); |
393 purple_request_field_group_add_field(group, field); | |
15817 | 394 |
15822 | 395 field = purple_request_field_string_new("alias", _("Alias"), alias, FALSE); |
396 purple_request_field_group_add_field(group, field); | |
15817 | 397 |
15822 | 398 field = purple_request_field_string_new("group", _("Group"), grp ? grp->name : NULL, FALSE); |
399 purple_request_field_group_add_field(group, field); | |
15817 | 400 |
15822 | 401 purple_request_fields(NULL, _("Add Chat"), NULL, |
15817 | 402 _("You can edit more information from the context menu later."), |
16439
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:
16424
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:
16424
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:
16424
diff
changeset
|
405 NULL); |
15817 | 406 } |
407 | |
408 static void | |
409 add_group_cb(gpointer null, const char *group) | |
410 { | |
15822 | 411 PurpleGroup *grp; |
15817 | 412 |
413 if (!group || !*group) | |
414 { | |
15822 | 415 purple_notify_error(NULL, _("Error"), _("Error adding group"), |
15817 | 416 _("You must give a name for the group to add.")); |
417 return; | |
418 } | |
419 | |
15822 | 420 grp = purple_find_group(group); |
15817 | 421 if (!grp) |
422 { | |
15822 | 423 grp = purple_group_new(group); |
424 purple_blist_add_group(grp, NULL); | |
15817 | 425 } |
426 else | |
427 { | |
15822 | 428 purple_notify_error(NULL, _("Error"), _("Error adding group"), |
15817 | 429 _("A group with the name already exists.")); |
430 } | |
431 } | |
432 | |
433 static void | |
434 finch_request_add_group() | |
435 { | |
15822 | 436 purple_request_input(NULL, _("Add Group"), NULL, _("Enter the name of the group"), |
15817 | 437 NULL, FALSE, FALSE, NULL, |
16439
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:
16424
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:
16424
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:
16424
diff
changeset
|
440 NULL); |
15817 | 441 } |
442 | |
15822 | 443 static PurpleBlistUiOps blist_ui_ops = |
15817 | 444 { |
445 new_list, | |
446 new_node, | |
447 blist_show, | |
448 node_update, | |
449 node_remove, | |
450 NULL, | |
451 NULL, | |
17091
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16958
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:
16958
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:
16958
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:
16958
diff
changeset
|
455 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16958
diff
changeset
|
456 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16958
diff
changeset
|
457 NULL, |
46f2f86e08e4
Death to more futuristic struct initialization. This should be the last.
Richard Laager <rlaager@wiktel.com>
parents:
16958
diff
changeset
|
458 NULL |
15817 | 459 }; |
460 | |
461 static gpointer | |
462 finch_blist_get_handle() | |
463 { | |
464 static int handle; | |
465 | |
466 return &handle; | |
467 } | |
468 | |
469 static void | |
15822 | 470 add_group(PurpleGroup *group, FinchBlist *ggblist) |
15817 | 471 { |
15822 | 472 PurpleBlistNode *node = (PurpleBlistNode *)group; |
15817 | 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:
15928
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:
15928
diff
changeset
|
478 !purple_blist_node_get_bool(node, "collapsed")); |
15817 | 479 } |
480 | |
481 static const char * | |
15822 | 482 get_display_name(PurpleBlistNode *node) |
15817 | 483 { |
484 static char text[2096]; | |
485 char status[8] = " "; | |
486 const char *name = NULL; | |
487 | |
15822 | 488 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) |
489 node = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)node); /* XXX: this can return NULL?! */ | |
15817 | 490 |
491 if (node == NULL) | |
492 return NULL; | |
493 | |
15822 | 494 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) |
15817 | 495 { |
15822 | 496 PurpleBuddy *buddy = (PurpleBuddy *)node; |
497 PurpleStatusPrimitive prim; | |
498 PurplePresence *presence; | |
499 PurpleStatus *now; | |
15817 | 500 gboolean ascii = gnt_ascii_only(); |
501 | |
15822 | 502 presence = purple_buddy_get_presence(buddy); |
503 now = purple_presence_get_active_status(presence); | |
15817 | 504 |
15822 | 505 prim = purple_status_type_get_primitive(purple_status_get_type(now)); |
15817 | 506 |
507 switch(prim) | |
508 { | |
15822 | 509 case PURPLE_STATUS_OFFLINE: |
15817 | 510 strncpy(status, ascii ? "x" : "⊗", sizeof(status) - 1); |
511 break; | |
15822 | 512 case PURPLE_STATUS_AVAILABLE: |
15817 | 513 strncpy(status, ascii ? "o" : "â—¯", sizeof(status) - 1); |
514 break; | |
515 default: | |
516 strncpy(status, ascii ? "." : "⊖", sizeof(status) - 1); | |
517 break; | |
518 } | |
15822 | 519 name = purple_buddy_get_alias(buddy); |
15817 | 520 } |
15822 | 521 else if (PURPLE_BLIST_NODE_IS_CHAT(node)) |
15817 | 522 { |
15822 | 523 PurpleChat *chat = (PurpleChat*)node; |
524 name = purple_chat_get_name(chat); | |
15817 | 525 |
526 strncpy(status, "~", sizeof(status) - 1); | |
527 } | |
15822 | 528 else if (PURPLE_BLIST_NODE_IS_GROUP(node)) |
529 return ((PurpleGroup*)node)->name; | |
15817 | 530 |
531 snprintf(text, sizeof(text) - 1, "%s %s", status, name); | |
532 | |
533 return text; | |
534 } | |
535 | |
536 static void | |
15822 | 537 add_chat(PurpleChat *chat, FinchBlist *ggblist) |
15817 | 538 { |
15822 | 539 PurpleGroup *group; |
540 PurpleBlistNode *node = (PurpleBlistNode *)chat; | |
15817 | 541 if (node->ui_data) |
542 return; | |
15822 | 543 if (!purple_account_is_connected(chat->account)) |
15817 | 544 return; |
545 | |
15822 | 546 group = purple_chat_get_group(chat); |
547 add_node((PurpleBlistNode*)group, ggblist); | |
15817 | 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 | |
15822 | 555 add_contact(PurpleContact *contact, FinchBlist *ggblist) |
15817 | 556 { |
15822 | 557 PurpleGroup *group; |
558 PurpleBlistNode *node = (PurpleBlistNode*)contact; | |
15817 | 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 | |
15822 | 568 group = (PurpleGroup*)node->parent; |
569 add_node((PurpleBlistNode*)group, ggblist); | |
15817 | 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 | |
15822 | 579 add_buddy(PurpleBuddy *buddy, FinchBlist *ggblist) |
15817 | 580 { |
15822 | 581 PurpleContact *contact; |
582 PurpleBlistNode *node = (PurpleBlistNode *)buddy; | |
15817 | 583 if (node->ui_data) |
584 return; | |
585 | |
15822 | 586 contact = (PurpleContact*)node->parent; |
15817 | 587 if (!contact) /* When a new buddy is added and show-offline is set */ |
588 return; | |
15822 | 589 add_node((PurpleBlistNode*)contact, ggblist); |
15817 | 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); | |
15822 | 594 if (purple_presence_is_idle(purple_buddy_get_presence(buddy))) { |
15817 | 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 | |
15822 | 605 buddy_signed_on(PurpleBuddy *buddy, FinchBlist *ggblist) |
15817 | 606 { |
15822 | 607 add_node((PurpleBlistNode*)buddy, ggblist); |
15817 | 608 } |
609 | |
610 static void | |
15822 | 611 buddy_signed_off(PurpleBuddy *buddy, FinchBlist *ggblist) |
15817 | 612 { |
15822 | 613 node_remove(purple_get_blist(), (PurpleBlistNode*)buddy); |
15817 | 614 } |
615 #endif | |
616 | |
15822 | 617 PurpleBlistUiOps *finch_blist_get_ui_ops() |
15817 | 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); | |
15822 | 626 PurpleBlistNode *node = gnt_tree_get_selection_data(tree); |
15817 | 627 |
628 if (!node) | |
629 return; | |
630 | |
15822 | 631 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) |
632 node = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)node); | |
15817 | 633 |
15822 | 634 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) |
15817 | 635 { |
15822 | 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)); | |
15817 | 640 finch_conversation_set_active(conv); |
641 } | |
15822 | 642 else if (PURPLE_BLIST_NODE_IS_CHAT(node)) |
15817 | 643 { |
15822 | 644 PurpleChat *chat = (PurpleChat*)node; |
15817 | 645 serv_join_chat(chat->account->gc, chat->components); |
646 } | |
647 } | |
648 | |
649 static void | |
650 context_menu_callback(GntMenuItem *item, gpointer data) | |
651 { | |
15822 | 652 PurpleMenuAction *action = data; |
653 PurpleBlistNode *node = ggblist->cnode; | |
15817 | 654 if (action) { |
15822 | 655 void (*callback)(PurpleBlistNode *, gpointer); |
656 callback = (void (*)(PurpleBlistNode *, gpointer))action->callback; | |
15817 | 657 if (callback) |
658 callback(action->data, node); | |
659 else | |
660 return; | |
661 } | |
662 } | |
663 | |
664 static void | |
15822 | 665 gnt_append_menu_action(GntMenu *menu, PurpleMenuAction *action, gpointer parent) |
15817 | 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) | |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15870
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:
15870
diff
changeset
|
676 gnt_menu_add_item(menu, GNT_MENU_ITEM(item)); |
15817 | 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 | |
15822 | 687 append_proto_menu(GntMenu *menu, PurpleConnection *gc, PurpleBlistNode *node) |
15817 | 688 { |
689 GList *list; | |
15822 | 690 PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl); |
15817 | 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 { | |
15822 | 698 PurpleMenuAction *act = (PurpleMenuAction *) list->data; |
15817 | 699 act->data = node; |
700 gnt_append_menu_action(menu, act, NULL); | |
701 } | |
702 } | |
703 | |
704 static void | |
15822 | 705 add_custom_action(GntMenu *menu, const char *label, PurpleCallback callback, |
15817 | 706 gpointer data) |
707 { | |
15822 | 708 PurpleMenuAction *action = purple_menu_action_new(label, callback, data, NULL); |
15817 | 709 gnt_append_menu_action(menu, action, NULL); |
710 g_signal_connect_swapped(G_OBJECT(menu), "destroy", | |
15822 | 711 G_CALLBACK(purple_menu_action_free), action); |
15817 | 712 } |
713 | |
714 static void | |
15822 | 715 chat_components_edit_ok(PurpleChat *chat, PurpleRequestFields *allfields) |
15817 | 716 { |
717 GList *groups, *fields; | |
718 | |
15822 | 719 for (groups = purple_request_fields_get_groups(allfields); groups; groups = groups->next) { |
720 fields = purple_request_field_group_get_fields(groups->data); | |
15817 | 721 for (; fields; fields = fields->next) { |
15822 | 722 PurpleRequestField *field = fields->data; |
15817 | 723 const char *id; |
724 char *val; | |
725 | |
15822 | 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)); | |
15817 | 729 else |
15822 | 730 val = g_strdup(purple_request_field_string_get_value(field)); |
15817 | 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 | |
15822 | 738 chat_components_edit(PurpleChat *chat, PurpleBlistNode *selected) |
15817 | 739 { |
15822 | 740 PurpleRequestFields *fields = purple_request_fields_new(); |
741 PurpleRequestFieldGroup *group = purple_request_field_group_new(NULL); | |
742 PurpleRequestField *field; | |
15817 | 743 GList *parts, *iter; |
744 struct proto_chat_entry *pce; | |
745 | |
15822 | 746 purple_request_fields_add_group(fields, group); |
15817 | 747 |
15822 | 748 parts = PURPLE_PLUGIN_PROTOCOL_INFO(chat->account->gc->prpl)->chat_info(chat->account->gc); |
15817 | 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; | |
15822 | 757 field = purple_request_field_int_new(pce->identifier, pce->label, val); |
15817 | 758 } else { |
15822 | 759 field = purple_request_field_string_new(pce->identifier, pce->label, |
15817 | 760 g_hash_table_lookup(chat->components, pce->identifier), FALSE); |
761 } | |
762 | |
15822 | 763 purple_request_field_group_add_field(group, field); |
15817 | 764 g_free(pce); |
765 } | |
766 | |
767 g_list_free(parts); | |
768 | |
15822 | 769 purple_request_fields(NULL, _("Edit Chat"), NULL, _("Please Update the necessary fields."), |
16439
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:
16424
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:
16424
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:
16424
diff
changeset
|
772 chat); |
15817 | 773 } |
774 | |
775 static void | |
776 autojoin_toggled(GntMenuItem *item, gpointer data) | |
777 { | |
15822 | 778 PurpleMenuAction *action = data; |
779 purple_blist_node_set_bool(action->data, "gnt-autojoin", | |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15870
diff
changeset
|
780 gnt_menuitem_check_get_checked(GNT_MENU_ITEM_CHECK(item))); |
15817 | 781 } |
782 | |
783 static void | |
15822 | 784 create_chat_menu(GntMenu *menu, PurpleChat *chat) |
15817 | 785 { |
15822 | 786 PurpleMenuAction *action = purple_menu_action_new(_("Auto-join"), NULL, chat, NULL); |
15817 | 787 GntMenuItem *check = gnt_menuitem_check_new(action->label); |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15870
diff
changeset
|
788 gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(check), |
15822 | 789 purple_blist_node_get_bool((PurpleBlistNode*)chat, "gnt-autojoin")); |
15817 | 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", | |
15822 | 793 G_CALLBACK(purple_menu_action_free), action); |
15817 | 794 |
15822 | 795 add_custom_action(menu, _("Edit Settings"), (PurpleCallback)chat_components_edit, chat); |
15817 | 796 } |
797 | |
798 static void | |
15822 | 799 finch_add_buddy(PurpleGroup *grp, PurpleBlistNode *selected) |
15817 | 800 { |
15822 | 801 purple_blist_request_add_buddy(NULL, NULL, grp ? grp->name : NULL, NULL); |
15817 | 802 } |
803 | |
804 static void | |
15822 | 805 finch_add_group(PurpleGroup *grp, PurpleBlistNode *selected) |
15817 | 806 { |
15822 | 807 purple_blist_request_add_group(); |
15817 | 808 } |
809 | |
810 static void | |
15822 | 811 finch_add_chat(PurpleGroup *grp, PurpleBlistNode *selected) |
15817 | 812 { |
15822 | 813 purple_blist_request_add_chat(NULL, grp, NULL, NULL); |
15817 | 814 } |
815 | |
816 static void | |
15822 | 817 create_group_menu(GntMenu *menu, PurpleGroup *group) |
15817 | 818 { |
819 add_custom_action(menu, _("Add Buddy"), | |
15822 | 820 PURPLE_CALLBACK(finch_add_buddy), group); |
15817 | 821 add_custom_action(menu, _("Add Chat"), |
15822 | 822 PURPLE_CALLBACK(finch_add_chat), group); |
15817 | 823 add_custom_action(menu, _("Add Group"), |
15822 | 824 PURPLE_CALLBACK(finch_add_group), group); |
15817 | 825 } |
826 | |
827 static void | |
15822 | 828 finch_blist_get_buddy_info_cb(PurpleBuddy *buddy, PurpleBlistNode *selected) |
15817 | 829 { |
16925
9a568611fa4a
When getting information, show "Information: Retrieving..." before the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16924
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:
16924
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:
16924
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:
16924
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:
16924
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:
16924
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:
16924
diff
changeset
|
836 |
15822 | 837 serv_get_info(buddy->account->gc, purple_buddy_get_name(buddy)); |
15817 | 838 } |
839 | |
840 static void | |
15822 | 841 finch_blist_menu_send_file_cb(PurpleBuddy *buddy, PurpleBlistNode *selected) |
15817 | 842 { |
843 serv_send_file(buddy->account->gc, buddy->name, NULL); | |
844 } | |
845 | |
846 static void | |
15822 | 847 finch_blist_pounce_node_cb(PurpleBlistNode *node, PurpleBlistNode *selected) |
15817 | 848 { |
15822 | 849 PurpleBuddy *b; |
850 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) | |
851 b = purple_contact_get_priority_buddy((PurpleContact *)node); | |
15817 | 852 else |
15822 | 853 b = (PurpleBuddy *)node; |
15817 | 854 finch_pounce_editor_show(b->account, b->name, NULL); |
855 } | |
856 | |
857 | |
858 static void | |
15822 | 859 create_buddy_menu(GntMenu *menu, PurpleBuddy *buddy) |
15817 | 860 { |
15822 | 861 PurplePluginProtocolInfo *prpl_info; |
15817 | 862 |
15822 | 863 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(buddy->account->gc->prpl); |
15817 | 864 if (prpl_info && prpl_info->get_info) |
865 { | |
866 add_custom_action(menu, _("Get Info"), | |
15822 | 867 PURPLE_CALLBACK(finch_blist_get_buddy_info_cb), buddy); |
15817 | 868 } |
869 | |
870 add_custom_action(menu, _("Add Buddy Pounce"), | |
15822 | 871 PURPLE_CALLBACK(finch_blist_pounce_node_cb), buddy); |
15817 | 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"), | |
15822 | 878 PURPLE_CALLBACK(finch_blist_menu_send_file_cb), buddy); |
15817 | 879 } |
880 #if 0 | |
881 add_custom_action(tree, _("View Log"), | |
15822 | 882 PURPLE_CALLBACK(finch_blist_view_log_cb)), buddy); |
15817 | 883 #endif |
884 | |
885 /* Protocol actions */ | |
886 append_proto_menu(menu, | |
15822 | 887 purple_account_get_connection(purple_buddy_get_account(buddy)), |
888 (PurpleBlistNode*)buddy); | |
15817 | 889 } |
890 | |
891 static void | |
15822 | 892 append_extended_menu(GntMenu *menu, PurpleBlistNode *node) |
15817 | 893 { |
894 GList *iter; | |
895 | |
15822 | 896 for (iter = purple_blist_node_get_extended_menu(node); |
15817 | 897 iter; iter = g_list_delete_link(iter, iter)) |
898 { | |
899 gnt_append_menu_action(menu, iter->data, NULL); | |
900 } | |
901 } | |
902 | |
15822 | 903 /* Xerox'd from gtkdialogs.c:purple_gtkdialogs_remove_contact_cb */ |
15817 | 904 static void |
15822 | 905 remove_contact(PurpleContact *contact) |
15817 | 906 { |
15822 | 907 PurpleBlistNode *bnode, *cnode; |
908 PurpleGroup *group; | |
15817 | 909 |
15822 | 910 cnode = (PurpleBlistNode *)contact; |
911 group = (PurpleGroup*)cnode->parent; | |
15817 | 912 for (bnode = cnode->child; bnode; bnode = bnode->next) { |
15822 | 913 PurpleBuddy *buddy = (PurpleBuddy*)bnode; |
914 if (purple_account_is_connected(buddy->account)) | |
915 purple_account_remove_buddy(buddy->account, buddy, group); | |
15817 | 916 } |
15822 | 917 purple_blist_remove_contact(contact); |
15817 | 918 } |
919 | |
920 static void | |
15822 | 921 rename_blist_node(PurpleBlistNode *node, const char *newname) |
15817 | 922 { |
923 const char *name = newname; | |
924 if (name && !*name) | |
925 name = NULL; | |
926 | |
15822 | 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); | |
15817 | 932 serv_alias_buddy(buddy); |
15822 | 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); | |
15817 | 940 else |
941 g_return_if_reached(); | |
942 } | |
943 | |
944 static void | |
15822 | 945 finch_blist_rename_node_cb(PurpleBlistNode *node, PurpleBlistNode *selected) |
15817 | 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; |
15817 | 950 |
15822 | 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; | |
15817 | 959 else |
960 g_return_if_reached(); | |
961 | |
962 prompt = g_strdup_printf(_("Please enter the new name for %s"), name); | |
963 | |
16958
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:
16926
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), |
16439
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:
16424
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:
16424
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:
16424
diff
changeset
|
969 node); |
15817 | 970 |
971 g_free(prompt); | |
972 } | |
973 | |
15822 | 974 /* Xeroxed from gtkdialogs.c:purple_gtkdialogs_remove_group_cb*/ |
15817 | 975 static void |
15822 | 976 remove_group(PurpleGroup *group) |
15817 | 977 { |
15822 | 978 PurpleBlistNode *cnode, *bnode; |
15817 | 979 |
15822 | 980 cnode = ((PurpleBlistNode*)group)->child; |
15817 | 981 |
982 while (cnode) { | |
15822 | 983 if (PURPLE_BLIST_NODE_IS_CONTACT(cnode)) { |
15817 | 984 bnode = cnode->child; |
985 cnode = cnode->next; | |
986 while (bnode) { | |
15822 | 987 PurpleBuddy *buddy; |
988 if (PURPLE_BLIST_NODE_IS_BUDDY(bnode)) { | |
989 buddy = (PurpleBuddy*)bnode; | |
15817 | 990 bnode = bnode->next; |
15822 | 991 if (purple_account_is_connected(buddy->account)) { |
992 purple_account_remove_buddy(buddy->account, buddy, group); | |
993 purple_blist_remove_buddy(buddy); | |
15817 | 994 } |
995 } else { | |
996 bnode = bnode->next; | |
997 } | |
998 } | |
15822 | 999 } else if (PURPLE_BLIST_NODE_IS_CHAT(cnode)) { |
1000 PurpleChat *chat = (PurpleChat *)cnode; | |
15817 | 1001 cnode = cnode->next; |
15822 | 1002 if (purple_account_is_connected(chat->account)) |
1003 purple_blist_remove_chat(chat); | |
15817 | 1004 } else { |
1005 cnode = cnode->next; | |
1006 } | |
1007 } | |
1008 | |
15822 | 1009 purple_blist_remove_group(group); |
15817 | 1010 } |
1011 | |
1012 static void | |
15822 | 1013 finch_blist_remove_node(PurpleBlistNode *node) |
15817 | 1014 { |
15822 | 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); | |
15817 | 1026 } |
1027 } | |
1028 | |
1029 static void | |
15822 | 1030 finch_blist_remove_node_cb(PurpleBlistNode *node, PurpleBlistNode *selected) |
15817 | 1031 { |
16439
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:
16424
diff
changeset
|
1032 PurpleAccount *account = NULL; |
15817 | 1033 char *primary; |
1034 const char *name, *sec = NULL; | |
1035 | |
1036 /* XXX: could be a contact */ | |
15822 | 1037 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { |
1038 PurpleContact *c = (PurpleContact*)node; | |
1039 name = purple_contact_get_alias(c); | |
15817 | 1040 if (c->totalsize > 1) |
1041 sec = _("Removing this contact will also remove all the buddies in the contact"); | |
16439
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:
16424
diff
changeset
|
1042 } else if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { |
15822 | 1043 name = purple_buddy_get_name((PurpleBuddy*)node); |
16439
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:
16424
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:
16424
diff
changeset
|
1045 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) { |
15822 | 1046 name = purple_chat_get_name((PurpleChat*)node); |
16439
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:
16424
diff
changeset
|
1047 } else if (PURPLE_BLIST_NODE_IS_GROUP(node)) { |
15822 | 1048 name = ((PurpleGroup*)node)->name; |
15817 | 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? */ | |
15822 | 1057 purple_request_action(node, _("Confirm Remove"), |
15817 | 1058 primary, sec, |
16439
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:
16424
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:
16424
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:
16424
diff
changeset
|
1061 node, 2, |
15817 | 1062 _("Remove"), finch_blist_remove_node, |
1063 _("Cancel"), NULL); | |
1064 g_free(primary); | |
1065 } | |
1066 | |
1067 static void | |
15822 | 1068 finch_blist_toggle_tag_buddy(PurpleBlistNode *node) |
15817 | 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 } | |
15822 | 1078 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) |
1079 node = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)node); | |
16567
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:
16483
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:
16483
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:
16483
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:
16483
diff
changeset
|
1083 update_node_display(node, ggblist); |
15817 | 1084 } |
1085 | |
1086 static void | |
15822 | 1087 finch_blist_place_tagged(PurpleBlistNode *target) |
15817 | 1088 { |
15822 | 1089 PurpleGroup *tg = NULL; |
1090 PurpleContact *tc = NULL; | |
15817 | 1091 |
1092 if (target == NULL) | |
1093 return; | |
1094 | |
15822 | 1095 if (PURPLE_BLIST_NODE_IS_GROUP(target)) |
1096 tg = (PurpleGroup*)target; | |
16567
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:
16483
diff
changeset
|
1097 else if (PURPLE_BLIST_NODE_IS_BUDDY(target)) { |
15822 | 1098 tc = (PurpleContact*)target->parent; |
16567
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
diff
changeset
|
1104 } |
15817 | 1105 |
1106 if (ggblist->tagged) { | |
1107 GList *list = ggblist->tagged; | |
1108 ggblist->tagged = NULL; | |
1109 while (list) { | |
15822 | 1110 PurpleBlistNode *node = list->data; |
15817 | 1111 list = g_list_delete_link(list, list); |
16567
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
diff
changeset
|
1120 /* The target is a group, just add the contact to the group. */ |
15822 | 1121 purple_blist_add_contact((PurpleContact*)node, tg, NULL); |
16567
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
diff
changeset
|
1132 /* The target is a group. Add this buddy in a new contact under this group. */ |
15822 | 1133 purple_blist_add_buddy((PurpleBuddy*)node, NULL, tg, NULL); |
16567
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
diff
changeset
|
1149 purple_blist_add_chat((PurpleChat*)node, NULL, target); |
15817 | 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 { | |
15822 | 1164 PurpleBlistNode *node = NULL; |
15817 | 1165 GntWidget *context = NULL; |
1166 GntTree *tree = NULL; | |
1167 int x, y, top, width; | |
1168 char *title = NULL; | |
1169 | |
16813
e79555933fc6
Do not build the context menu if one is already being shown.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
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:
16781
diff
changeset
|
1171 return; |
e79555933fc6
Do not build the context menu if one is already being shown.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
1172 |
15817 | 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")); | |
15822 | 1188 } else if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { |
15817 | 1189 create_buddy_menu(GNT_MENU(context), |
15822 | 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; | |
15817 | 1194 create_buddy_menu(GNT_MENU(context), buddy); |
15822 | 1195 title = g_strdup(purple_buddy_get_name(buddy)); |
1196 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) { | |
1197 PurpleChat *chat = (PurpleChat*)node; | |
15817 | 1198 create_chat_menu(GNT_MENU(context), chat); |
15822 | 1199 title = g_strdup(purple_chat_get_name(chat)); |
1200 } else if (PURPLE_BLIST_NODE_IS_GROUP(node)) { | |
1201 PurpleGroup *group = (PurpleGroup *)node; | |
15817 | 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"), |
15822 | 1212 PURPLE_CALLBACK(finch_blist_rename_node_cb), node); |
15817 | 1213 add_custom_action(GNT_MENU(context), _("Remove"), |
15822 | 1214 PURPLE_CALLBACK(finch_blist_remove_node_cb), node); |
15817 | 1215 |
15822 | 1216 if (ggblist->tagged && (PURPLE_BLIST_NODE_IS_CONTACT(node) |
1217 || PURPLE_BLIST_NODE_IS_GROUP(node))) { | |
15817 | 1218 add_custom_action(GNT_MENU(context), _("Place tagged"), |
15822 | 1219 PURPLE_CALLBACK(finch_blist_place_tagged), node); |
15817 | 1220 } |
1221 | |
15822 | 1222 if (PURPLE_BLIST_NODE_IS_BUDDY(node) || PURPLE_BLIST_NODE_IS_CONTACT(node)) { |
15817 | 1223 add_custom_action(GNT_MENU(context), _("Toggle Tag"), |
15822 | 1224 PURPLE_CALLBACK(finch_blist_toggle_tag_buddy), node); |
15817 | 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 | |
15822 | 1242 tooltip_for_buddy(PurpleBuddy *buddy, GString *str) |
15817 | 1243 { |
15822 | 1244 PurplePlugin *prpl; |
1245 PurplePluginProtocolInfo *prpl_info; | |
1246 PurpleAccount *account; | |
1247 PurpleNotifyUserInfo *user_info; | |
1248 const char *alias = purple_buddy_get_alias(buddy); | |
15817 | 1249 char *tmp, *strip; |
1250 | |
15822 | 1251 user_info = purple_notify_user_info_new(); |
15817 | 1252 |
15822 | 1253 account = purple_buddy_get_account(buddy); |
15817 | 1254 |
15822 | 1255 if (g_utf8_collate(purple_buddy_get_name(buddy), alias)) |
1256 purple_notify_user_info_add_pair(user_info, _("Nickname"), alias); | |
15817 | 1257 |
1258 tmp = g_strdup_printf("%s (%s)", | |
15822 | 1259 purple_account_get_username(account), |
1260 purple_account_get_protocol_name(account)); | |
1261 purple_notify_user_info_add_pair(user_info, _("Account"), tmp); | |
15817 | 1262 g_free(tmp); |
1263 | |
15822 | 1264 prpl = purple_find_prpl(purple_account_get_protocol_id(account)); |
1265 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | |
15817 | 1266 if (prpl_info && prpl_info->tooltip_text) { |
1267 prpl_info->tooltip_text(buddy, user_info, TRUE); | |
1268 } | |
1269 | |
16424
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")) { |
15822 | 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); | |
15817 | 1274 if (idle > 0) { |
15822 | 1275 char *st = purple_str_seconds_to_string(time(NULL) - idle); |
1276 purple_notify_user_info_add_pair(user_info, _("Idle"), st); | |
15817 | 1277 g_free(st); |
1278 } | |
1279 } | |
1280 } | |
1281 | |
15822 | 1282 tmp = purple_notify_user_info_get_text_with_newline(user_info, "<BR>"); |
1283 purple_notify_user_info_destroy(user_info); | |
15817 | 1284 |
15822 | 1285 strip = purple_markup_strip_html(tmp); |
15817 | 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 { | |
15822 | 1304 PurpleBlistNode *node; |
15817 | 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 | |
15822 | 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); | |
15817 | 1337 |
1338 title = g_strdup(name); | |
1339 tooltip_for_buddy(pr, str); | |
1340 for (node = node->child; node; node = node->next) { | |
15822 | 1341 PurpleBuddy *buddy = (PurpleBuddy*)node; |
15817 | 1342 if (offline) { |
15822 | 1343 int value = purple_blist_node_get_int(node, "last_seen"); |
15817 | 1344 if (value > lastseen) |
1345 lastseen = value; | |
1346 } | |
15822 | 1347 if (node == (PurpleBlistNode*)pr) |
15817 | 1348 continue; |
15822 | 1349 if (!purple_account_is_connected(buddy->account)) |
15817 | 1350 continue; |
15822 | 1351 if (!showoffline && !PURPLE_BUDDY_IS_ONLINE(buddy)) |
15817 | 1352 continue; |
1353 str = g_string_append(str, "\n----------\n"); | |
1354 tooltip_for_buddy(buddy, str); | |
1355 } | |
15822 | 1356 } else if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { |
1357 PurpleBuddy *buddy = (PurpleBuddy *)node; | |
15817 | 1358 tooltip_for_buddy(buddy, str); |
15822 | 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; | |
15817 | 1364 |
1365 g_string_append_printf(str, _("Online: %d\nTotal: %d"), | |
15822 | 1366 purple_blist_get_group_online_count(group), |
1367 purple_blist_get_group_size(group, FALSE)); | |
15817 | 1368 |
1369 title = g_strdup(group->name); | |
15822 | 1370 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) { |
1371 PurpleChat *chat = (PurpleChat *)node; | |
1372 PurpleAccount *account = chat->account; | |
15817 | 1373 |
1374 g_string_append_printf(str, _("Account: %s (%s)"), | |
15822 | 1375 purple_account_get_username(account), |
1376 purple_account_get_protocol_name(account)); | |
15817 | 1377 |
15822 | 1378 title = g_strdup(purple_chat_get_name(chat)); |
15817 | 1379 } else { |
1380 g_string_free(str, TRUE); | |
1381 return FALSE; | |
1382 } | |
1383 | |
1384 if (lastseen > 0) { | |
15822 | 1385 char *tmp = purple_str_seconds_to_string(time(NULL) - lastseen); |
15817 | 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 { | |
16781
d0f9b2b217cf
Fix context menu unusualness in the buddylist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16771
diff
changeset
|
1442 remove_peripherals(ggblist); |
15817 | 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) { | |
15822 | 1460 purple_prefs_set_bool(PREF_ROOT "/showoffline", |
1461 !purple_prefs_get_bool(PREF_ROOT "/showoffline")); | |
15817 | 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 | |
16567
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
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:
16483
diff
changeset
|
1485 static void |
15822 | 1486 update_buddy_display(PurpleBuddy *buddy, FinchBlist *ggblist) |
15817 | 1487 { |
15822 | 1488 PurpleContact *contact; |
15817 | 1489 GntTextFormatFlags bflag = 0, cflag = 0; |
1490 | |
15822 | 1491 contact = purple_buddy_get_contact(buddy); |
15817 | 1492 |
15822 | 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)); | |
15817 | 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 | |
15822 | 1501 if (ggblist->tnode == (PurpleBlistNode*)buddy) |
15817 | 1502 draw_tooltip(ggblist); |
1503 | |
15822 | 1504 if (purple_presence_is_idle(purple_buddy_get_presence(buddy))) { |
15817 | 1505 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, bflag | GNT_TEXT_FLAG_DIM); |
16567
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:
16483
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:
16483
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:
16483
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:
16483
diff
changeset
|
1509 update_buddy_display(purple_contact_get_priority_buddy(contact), ggblist); |
15817 | 1510 } else { |
1511 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, bflag); | |
16567
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:
16483
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:
16483
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:
16483
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:
16483
diff
changeset
|
1515 update_buddy_display(purple_contact_get_priority_buddy(contact), ggblist); |
15817 | 1516 } |
1517 } | |
1518 | |
1519 static void | |
15822 | 1520 buddy_status_changed(PurpleBuddy *buddy, PurpleStatus *old, PurpleStatus *now, FinchBlist *ggblist) |
15817 | 1521 { |
1522 update_buddy_display(buddy, ggblist); | |
1523 } | |
1524 | |
1525 static void | |
15822 | 1526 buddy_idle_changed(PurpleBuddy *buddy, int old, int new, FinchBlist *ggblist) |
15817 | 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); | |
15822 | 1545 purple_prefs_set_int(PREF_ROOT "/size/width", width); |
1546 purple_prefs_set_int(PREF_ROOT "/size/height", height); | |
15817 | 1547 } |
1548 | |
1549 static void | |
1550 save_position_cb(GntWidget *w, int x, int y) | |
1551 { | |
15822 | 1552 purple_prefs_set_int(PREF_ROOT "/position/x", x); |
1553 purple_prefs_set_int(PREF_ROOT "/position/y", y); | |
15817 | 1554 } |
1555 | |
1556 static void | |
1557 reset_blist_window(GntWidget *window, gpointer null) | |
1558 { | |
15822 | 1559 PurpleBlistNode *node; |
1560 purple_signals_disconnect_by_handle(finch_blist_get_handle()); | |
1561 purple_get_blist()->ui_data = NULL; | |
15817 | 1562 |
15822 | 1563 node = purple_blist_get_root(); |
15817 | 1564 while (node) { |
1565 node->ui_data = NULL; | |
15822 | 1566 node = purple_blist_node_next(node, TRUE); |
15817 | 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 { | |
15822 | 1581 PurpleBlistNode *node; |
1582 PurpleBuddyList *list; | |
15817 | 1583 |
15822 | 1584 if (strcmp(purple_prefs_get_string(PREF_ROOT "/sort_type"), "text") == 0) { |
15817 | 1585 gnt_tree_set_compare_func(GNT_TREE(ggblist->tree), |
1586 (GCompareFunc)blist_node_compare_text); | |
15822 | 1587 } else if (strcmp(purple_prefs_get_string(PREF_ROOT "/sort_type"), "status") == 0) { |
15817 | 1588 gnt_tree_set_compare_func(GNT_TREE(ggblist->tree), |
1589 (GCompareFunc)blist_node_compare_status); | |
15822 | 1590 } else if (strcmp(purple_prefs_get_string(PREF_ROOT "/sort_type"), "log") == 0) { |
15817 | 1591 gnt_tree_set_compare_func(GNT_TREE(ggblist->tree), |
1592 (GCompareFunc)blist_node_compare_log); | |
1593 } | |
1594 | |
15822 | 1595 list = purple_get_blist(); |
1596 node = purple_blist_get_root(); | |
15817 | 1597 while (node) |
1598 { | |
1599 node_update(list, node); | |
15822 | 1600 node = purple_blist_node_next(node, FALSE); |
15817 | 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 */ | |
15822 | 1620 PurpleStatusPrimitive prims[] = {PURPLE_STATUS_AVAILABLE, PURPLE_STATUS_AWAY, |
1621 PURPLE_STATUS_INVISIBLE, PURPLE_STATUS_OFFLINE, PURPLE_STATUS_UNSET}; | |
15817 | 1622 |
1623 gnt_combo_box_remove_all(GNT_COMBO_BOX(ggblist->status)); | |
1624 | |
15822 | 1625 for (i = 0; prims[i] != PURPLE_STATUS_UNSET; i++) |
15817 | 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, | |
15822 | 1632 purple_primitive_get_name_from_type(prims[i])); |
15817 | 1633 } |
1634 | |
1635 /* Now the popular statuses */ | |
15822 | 1636 for (iter = purple_savedstatuses_get_popular(6); iter; iter = iter->next) |
15817 | 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, | |
15822 | 1643 purple_savedstatus_get_title(iter->data)); |
15817 | 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 | |
15822 | 1668 redraw_blist(const char *name, PurplePrefType type, gconstpointer val, gpointer data) |
15817 | 1669 { |
15822 | 1670 PurpleBlistNode *node, *sel; |
15817 | 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)); | |
15822 | 1676 node = purple_blist_get_root(); |
1677 for (; node; node = purple_blist_node_next(node, TRUE)) | |
15817 | 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 { | |
15822 | 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"); | |
15817 | 1696 |
15822 | 1697 purple_prefs_connect_callback(finch_blist_get_handle(), |
15817 | 1698 PREF_ROOT "/showoffline", redraw_blist, NULL); |
15822 | 1699 purple_prefs_connect_callback(finch_blist_get_handle(), |
15817 | 1700 PREF_ROOT "/sort_type", redraw_blist, NULL); |
1701 | |
15822 | 1702 purple_signal_connect(purple_connections_get_handle(), "signed-on", purple_blist_get_handle(), |
15817 | 1703 G_CALLBACK(account_signed_on_cb), NULL); |
1704 return; | |
1705 } | |
1706 | |
1707 static gboolean | |
1708 remove_typing_cb(gpointer null) | |
1709 { | |
15822 | 1710 PurpleSavedStatus *current; |
15817 | 1711 const char *message, *newmessage; |
15822 | 1712 PurpleStatusPrimitive prim, newprim; |
15817 | 1713 StatusBoxItem *item; |
1714 | |
15822 | 1715 current = purple_savedstatus_get_current(); |
1716 message = purple_savedstatus_get_message(current); | |
1717 prim = purple_savedstatus_get_type(current); | |
15817 | 1718 |
1719 newmessage = gnt_entry_get_text(GNT_ENTRY(ggblist->statustext)); | |
1720 item = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(ggblist->status)); | |
16655
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16567
diff
changeset
|
1721 |
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16567
diff
changeset
|
1722 switch (item->type) { |
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16567
diff
changeset
|
1723 case STATUS_PRIMITIVE: |
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16567
diff
changeset
|
1724 newprim = item->u.prim; |
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16567
diff
changeset
|
1725 break; |
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16567
diff
changeset
|
1726 case STATUS_SAVED_POPULAR: |
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16567
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:
16567
diff
changeset
|
1728 break; |
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16567
diff
changeset
|
1729 default: |
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16567
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:
16567
diff
changeset
|
1731 } |
15817 | 1732 |
1733 if (newprim != prim || ((message && !newmessage) || | |
1734 (!message && newmessage) || | |
1735 (message && newmessage && g_utf8_collate(message, newmessage) != 0))) | |
1736 { | |
15822 | 1737 PurpleSavedStatus *status = purple_savedstatus_find_transient_by_type_and_message(newprim, newmessage); |
15817 | 1738 /* Holy Crap! That's a LAWNG function name */ |
1739 if (status == NULL) | |
1740 { | |
15822 | 1741 status = purple_savedstatus_new(NULL, newprim); |
1742 purple_savedstatus_set_message(status, newmessage); | |
15817 | 1743 } |
1744 | |
15822 | 1745 purple_savedstatus_activate(status); |
15817 | 1746 } |
1747 | |
1748 gnt_box_give_focus_to_child(GNT_BOX(ggblist->window), ggblist->tree); | |
16655
1c9835f8b29c
A rare crash fix for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16567
diff
changeset
|
1749 end: |
15817 | 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 */ | |
15822 | 1763 purple_savedstatus_activate(now->u.saved); |
15817 | 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. */ | |
15822 | 1775 savedstatus_changed(purple_savedstatus_get_current(), NULL); |
15817 | 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 { | |
15822 | 1781 savedstatus_changed(purple_savedstatus_get_current(), NULL); |
15817 | 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 | |
15822 | 1811 savedstatus_changed(PurpleSavedStatus *now, PurpleSavedStatus *old) |
15817 | 1812 { |
1813 GList *list; | |
15822 | 1814 PurpleStatusPrimitive prim; |
15817 | 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 | |
15822 | 1827 prim = purple_savedstatus_get_type(now); |
1828 message = purple_savedstatus_get_message(now); | |
15817 | 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 { | |
15822 | 1841 char *mess = purple_unescape_html(message); |
15817 | 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 | |
16483
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
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:
16439
diff
changeset
|
1863 { |
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
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:
16439
diff
changeset
|
1865 if (n1 == n2) |
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
1866 return 1; |
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
1867 return -1; |
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
1868 } |
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
1869 |
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
1870 static int |
15822 | 1871 blist_node_compare_text(PurpleBlistNode *n1, PurpleBlistNode *n2) |
15817 | 1872 { |
1873 const char *s1, *s2; | |
1874 char *us1, *us2; | |
1875 int ret; | |
17240
29b3dc9cc8c5
It's valid for different types to be compared. In that case, use existing positions.
Richard Nelson <wabz@pidgin.im>
parents:
17203
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:
17203
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:
17203
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:
17203
diff
changeset
|
1879 |
15817 | 1880 switch (n1->type) |
1881 { | |
15822 | 1882 case PURPLE_BLIST_CHAT_NODE: |
1883 s1 = purple_chat_get_name((PurpleChat*)n1); | |
1884 s2 = purple_chat_get_name((PurpleChat*)n2); | |
15817 | 1885 break; |
15822 | 1886 case PURPLE_BLIST_BUDDY_NODE: |
1887 return purple_presence_compare(purple_buddy_get_presence((PurpleBuddy*)n1), | |
1888 purple_buddy_get_presence((PurpleBuddy*)n2)); | |
15817 | 1889 break; |
15822 | 1890 case PURPLE_BLIST_CONTACT_NODE: |
1891 s1 = purple_contact_get_alias((PurpleContact*)n1); | |
1892 s2 = purple_contact_get_alias((PurpleContact*)n2); | |
15817 | 1893 break; |
1894 default: | |
16483
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
1895 return blist_node_compare_position(n1, n2); |
15817 | 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 | |
15822 | 1908 blist_node_compare_status(PurpleBlistNode *n1, PurpleBlistNode *n2) |
15817 | 1909 { |
1910 int ret; | |
1911 | |
17240
29b3dc9cc8c5
It's valid for different types to be compared. In that case, use existing positions.
Richard Nelson <wabz@pidgin.im>
parents:
17203
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:
17203
diff
changeset
|
1913 return blist_node_compare_position(n1, n2); |
15817 | 1914 |
1915 switch (n1->type) { | |
15822 | 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); | |
15817 | 1919 /* now compare the presence of the priority buddies */ |
15822 | 1920 case PURPLE_BLIST_BUDDY_NODE: |
1921 ret = purple_presence_compare(purple_buddy_get_presence((PurpleBuddy*)n1), | |
1922 purple_buddy_get_presence((PurpleBuddy*)n2)); | |
15817 | 1923 if (ret != 0) |
1924 return ret; | |
1925 break; | |
1926 default: | |
16483
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
1927 return blist_node_compare_position(n1, n2); |
15817 | 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 | |
15822 | 1938 get_contact_log_size(PurpleBlistNode *c) |
15817 | 1939 { |
1940 int log = 0; | |
15822 | 1941 PurpleBlistNode *node; |
15817 | 1942 |
1943 for (node = c->child; node; node = node->next) { | |
15822 | 1944 PurpleBuddy *b = (PurpleBuddy*)node; |
1945 log += purple_log_get_total_size(PURPLE_LOG_IM, b->name, b->account); | |
15817 | 1946 } |
1947 | |
1948 return log; | |
1949 } | |
1950 | |
1951 static int | |
15822 | 1952 blist_node_compare_log(PurpleBlistNode *n1, PurpleBlistNode *n2) |
15817 | 1953 { |
1954 int ret; | |
15822 | 1955 PurpleBuddy *b1, *b2; |
15817 | 1956 |
17240
29b3dc9cc8c5
It's valid for different types to be compared. In that case, use existing positions.
Richard Nelson <wabz@pidgin.im>
parents:
17203
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:
17203
diff
changeset
|
1958 return blist_node_compare_position(n1, n2); |
15817 | 1959 |
1960 switch (n1->type) { | |
15822 | 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); | |
15817 | 1966 if (ret != 0) |
1967 return ret; | |
1968 break; | |
15822 | 1969 case PURPLE_BLIST_CONTACT_NODE: |
15817 | 1970 ret = get_contact_log_size(n2) - get_contact_log_size(n1); |
1971 if (ret != 0) | |
1972 return ret; | |
1973 break; | |
1974 default: | |
16483
0b97b224a829
Never change the orders of chats or the groups.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
1975 return blist_node_compare_position(n1, n2); |
15817 | 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 { | |
15822 | 1993 PurplePluginAction *action = data; |
15817 | 1994 if (action && action->callback) |
1995 action->callback(action); | |
1996 } | |
1997 | |
1998 static void | |
15822 | 1999 build_plugin_actions(GntMenuItem *item, PurplePlugin *plugin, gpointer context) |
15817 | 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)); | |
15822 | 2006 for (actions = PURPLE_PLUGIN_ACTIONS(plugin, context); actions; |
15817 | 2007 actions = g_list_delete_link(actions, actions)) { |
2008 if (actions->data) { | |
15822 | 2009 PurplePluginAction *action = actions->data; |
15817 | 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", | |
15822 | 2017 action, (GDestroyNotify)purple_plugin_action_free); |
15817 | 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 | |
15822 | 2039 for (iter = purple_plugins_get_loaded(); iter; iter = iter->next) { |
2040 PurplePlugin *plugin = iter->data; | |
15817 | 2041 GntMenuItem *item; |
15822 | 2042 if (PURPLE_IS_PROTOCOL_PLUGIN(plugin)) |
15817 | 2043 continue; |
2044 | |
15822 | 2045 if (!PURPLE_PLUGIN_HAS_ACTIONS(plugin)) |
15817 | 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 | |
15822 | 2071 for (iter = purple_accounts_get_all_active(); iter; |
15817 | 2072 iter = g_list_delete_link(iter, iter)) { |
15822 | 2073 PurpleAccount *account = iter->data; |
2074 PurpleConnection *gc = purple_account_get_connection(account); | |
2075 PurplePlugin *prpl; | |
15817 | 2076 |
15822 | 2077 if (!gc || !PURPLE_CONNECTION_IS_CONNECTED(gc)) |
15817 | 2078 continue; |
2079 prpl = gc->prpl; | |
2080 | |
15822 | 2081 if (PURPLE_PLUGIN_HAS_ACTIONS(prpl)) { |
2082 item = gnt_menuitem_new(purple_account_get_username(account)); | |
15817 | 2083 gnt_menu_add_item(GNT_MENU(sub), item); |
2084 build_plugin_actions(item, prpl, gc); | |
2085 } | |
2086 } | |
2087 } | |
2088 | |
2089 static void | |
16771
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:
16655
diff
changeset
|
2090 account_signed_on_cb(PurpleConnection *pc, gpointer null) |
15817 | 2091 { |
15822 | 2092 PurpleBlistNode *node; |
15817 | 2093 |
15822 | 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; | |
16771
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:
16655
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:
16655
diff
changeset
|
2099 purple_blist_node_get_bool(node, "gnt-autojoin")) |
15822 | 2100 serv_join_chat(purple_account_get_connection(chat->account), chat->components); |
15817 | 2101 } |
2102 } | |
2103 } | |
2104 | |
2105 static void show_offline_cb(GntMenuItem *item, gpointer n) | |
2106 { | |
15822 | 2107 purple_prefs_set_bool(PREF_ROOT "/showoffline", |
2108 !purple_prefs_get_bool(PREF_ROOT "/showoffline")); | |
15817 | 2109 } |
2110 | |
2111 static void sort_blist_change_cb(GntMenuItem *item, gpointer n) | |
2112 { | |
15822 | 2113 purple_prefs_set_string(PREF_ROOT "/sort_type", n); |
15817 | 2114 } |
2115 | |
2116 /* XXX: send_im_select* -- Xerox */ | |
2117 static void | |
15822 | 2118 send_im_select_cb(gpointer data, PurpleRequestFields *fields) |
15817 | 2119 { |
15822 | 2120 PurpleAccount *account; |
15817 | 2121 const char *username; |
2122 | |
15822 | 2123 account = purple_request_fields_get_account(fields, "account"); |
2124 username = purple_request_fields_get_string(fields, "screenname"); | |
15817 | 2125 |
15822 | 2126 purple_conversation_new(PURPLE_CONV_TYPE_IM, account, username); |
15817 | 2127 } |
2128 | |
2129 static void | |
2130 send_im_select(GntMenuItem *item, gpointer n) | |
2131 { | |
15822 | 2132 PurpleRequestFields *fields; |
2133 PurpleRequestFieldGroup *group; | |
2134 PurpleRequestField *field; | |
15817 | 2135 |
15822 | 2136 fields = purple_request_fields_new(); |
15817 | 2137 |
15822 | 2138 group = purple_request_field_group_new(NULL); |
2139 purple_request_fields_add_group(fields, group); | |
15817 | 2140 |
15822 | 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); | |
15817 | 2145 |
15822 | 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); | |
15817 | 2153 |
15822 | 2154 purple_request_fields(purple_get_blist(), _("New Instant Message"), |
15817 | 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, | |
16439
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:
16424
diff
changeset
|
2161 NULL, NULL, NULL, |
15817 | 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); | |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15870
diff
changeset
|
2187 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), send_im_select, NULL); |
15817 | 2188 |
16924
49f66fab6b31
Change a string.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16813
diff
changeset
|
2189 item = gnt_menuitem_check_new(_("Show offline buddies")); |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15870
diff
changeset
|
2190 gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(item), |
15822 | 2191 purple_prefs_get_bool(PREF_ROOT "/showoffline")); |
15817 | 2192 gnt_menu_add_item(GNT_MENU(sub), item); |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15870
diff
changeset
|
2193 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), show_offline_cb, NULL); |
15817 | 2194 |
2195 item = gnt_menuitem_new(_("Sort by status")); | |
2196 gnt_menu_add_item(GNT_MENU(sub), item); | |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15870
diff
changeset
|
2197 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), sort_blist_change_cb, "status"); |
15817 | 2198 |
2199 item = gnt_menuitem_new(_("Sort alphabetically")); | |
2200 gnt_menu_add_item(GNT_MENU(sub), item); | |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15870
diff
changeset
|
2201 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), sort_blist_change_cb, "text"); |
15817 | 2202 |
2203 item = gnt_menuitem_new(_("Sort by log size")); | |
2204 gnt_menu_add_item(GNT_MENU(sub), item); | |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15870
diff
changeset
|
2205 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), sort_blist_change_cb, "log"); |
15817 | 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 { | |
15822 | 2216 blist_show(purple_get_blist()); |
15817 | 2217 } |
2218 | |
2219 static void | |
16105
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15928
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:
15928
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:
15928
diff
changeset
|
2224 } |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
2225 |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
2226 static void |
15822 | 2227 blist_show(PurpleBuddyList *list) |
15817 | 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); | |
15822 | 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")); | |
15817 | 2247 |
2248 gnt_tree_set_col_width(GNT_TREE(ggblist->tree), 0, | |
15822 | 2249 purple_prefs_get_int(PREF_ROOT "/size/width") - 1); |
15817 | 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 | |
15822 | 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); | |
15817 | 2268 |
15822 | 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); | |
15817 | 2273 |
2274 #if 0 | |
15822 | 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); | |
15817 | 2279 |
2280 /* These I plan to use to indicate unread-messages etc. */ | |
15822 | 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); | |
15817 | 2285 |
15822 | 2286 purple_signal_connect(purple_conversations_get_handle(), "received-chat-msg", finch_blist_get_handle(), |
2287 PURPLE_CALLBACK(received_chat_msg), list); | |
15817 | 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:
15928
diff
changeset
|
2293 g_signal_connect(G_OBJECT(ggblist->tree), "collapse-toggled", G_CALLBACK(group_collapsed), NULL); |
15817 | 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 */ | |
15822 | 2305 purple_signal_connect(purple_savedstatuses_get_handle(), "savedstatus-changed", finch_blist_get_handle(), |
2306 PURPLE_CALLBACK(savedstatus_changed), NULL); | |
15817 | 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 | |
15822 | 2316 savedstatus_changed(purple_savedstatus_get_current(), NULL); |
15817 | 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 |