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