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