Mercurial > pidgin
annotate finch/gntblist.c @ 16107:1980273186a4
Make non-standard mode characters support connection-specific instead of
IRC prpl-wide.
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sat, 14 Apr 2007 16:32:42 +0000 |
parents | b73761ac005e |
children | 0f0832c13fcb |
rev | line source |
---|---|
15817 | 1 /** |
2 * @file gntblist.c GNT BuddyList API | |
3 * @ingroup gntui | |
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; | |
912 | |
15822 | 913 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) |
914 name = purple_contact_get_alias((PurpleContact*)node); | |
915 else if (PURPLE_BLIST_NODE_IS_BUDDY(node)) | |
916 name = purple_buddy_get_contact_alias((PurpleBuddy*)node); | |
917 else if (PURPLE_BLIST_NODE_IS_CHAT(node)) | |
918 name = purple_chat_get_name((PurpleChat*)node); | |
919 else if (PURPLE_BLIST_NODE_IS_GROUP(node)) | |
920 name = ((PurpleGroup*)node)->name; | |
15817 | 921 else |
922 g_return_if_reached(); | |
923 | |
924 prompt = g_strdup_printf(_("Please enter the new name for %s"), name); | |
925 | |
15822 | 926 purple_request_input(node, _("Rename"), prompt, _("Enter empty string to reset the name."), |
15817 | 927 name, FALSE, FALSE, NULL, _("Rename"), G_CALLBACK(rename_blist_node), |
928 _("Cancel"), NULL, node); | |
929 | |
930 g_free(prompt); | |
931 } | |
932 | |
15822 | 933 /* Xeroxed from gtkdialogs.c:purple_gtkdialogs_remove_group_cb*/ |
15817 | 934 static void |
15822 | 935 remove_group(PurpleGroup *group) |
15817 | 936 { |
15822 | 937 PurpleBlistNode *cnode, *bnode; |
15817 | 938 |
15822 | 939 cnode = ((PurpleBlistNode*)group)->child; |
15817 | 940 |
941 while (cnode) { | |
15822 | 942 if (PURPLE_BLIST_NODE_IS_CONTACT(cnode)) { |
15817 | 943 bnode = cnode->child; |
944 cnode = cnode->next; | |
945 while (bnode) { | |
15822 | 946 PurpleBuddy *buddy; |
947 if (PURPLE_BLIST_NODE_IS_BUDDY(bnode)) { | |
948 buddy = (PurpleBuddy*)bnode; | |
15817 | 949 bnode = bnode->next; |
15822 | 950 if (purple_account_is_connected(buddy->account)) { |
951 purple_account_remove_buddy(buddy->account, buddy, group); | |
952 purple_blist_remove_buddy(buddy); | |
15817 | 953 } |
954 } else { | |
955 bnode = bnode->next; | |
956 } | |
957 } | |
15822 | 958 } else if (PURPLE_BLIST_NODE_IS_CHAT(cnode)) { |
959 PurpleChat *chat = (PurpleChat *)cnode; | |
15817 | 960 cnode = cnode->next; |
15822 | 961 if (purple_account_is_connected(chat->account)) |
962 purple_blist_remove_chat(chat); | |
15817 | 963 } else { |
964 cnode = cnode->next; | |
965 } | |
966 } | |
967 | |
15822 | 968 purple_blist_remove_group(group); |
15817 | 969 } |
970 | |
971 static void | |
15822 | 972 finch_blist_remove_node(PurpleBlistNode *node) |
15817 | 973 { |
15822 | 974 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { |
975 remove_contact((PurpleContact*)node); | |
976 } else if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { | |
977 PurpleBuddy *buddy = (PurpleBuddy*)node; | |
978 PurpleGroup *group = purple_buddy_get_group(buddy); | |
979 purple_account_remove_buddy(purple_buddy_get_account(buddy), buddy, group); | |
980 purple_blist_remove_buddy(buddy); | |
981 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) { | |
982 purple_blist_remove_chat((PurpleChat*)node); | |
983 } else if (PURPLE_BLIST_NODE_IS_GROUP(node)) { | |
984 remove_group((PurpleGroup*)node); | |
15817 | 985 } |
986 } | |
987 | |
988 static void | |
15822 | 989 finch_blist_remove_node_cb(PurpleBlistNode *node, PurpleBlistNode *selected) |
15817 | 990 { |
991 char *primary; | |
992 const char *name, *sec = NULL; | |
993 | |
994 /* XXX: could be a contact */ | |
15822 | 995 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { |
996 PurpleContact *c = (PurpleContact*)node; | |
997 name = purple_contact_get_alias(c); | |
15817 | 998 if (c->totalsize > 1) |
999 sec = _("Removing this contact will also remove all the buddies in the contact"); | |
15822 | 1000 } else if (PURPLE_BLIST_NODE_IS_BUDDY(node)) |
1001 name = purple_buddy_get_name((PurpleBuddy*)node); | |
1002 else if (PURPLE_BLIST_NODE_IS_CHAT(node)) | |
1003 name = purple_chat_get_name((PurpleChat*)node); | |
1004 else if (PURPLE_BLIST_NODE_IS_GROUP(node)) | |
15817 | 1005 { |
15822 | 1006 name = ((PurpleGroup*)node)->name; |
15817 | 1007 sec = _("Removing this group will also remove all the buddies in the group"); |
1008 } | |
1009 else | |
1010 return; | |
1011 | |
1012 primary = g_strdup_printf(_("Are you sure you want to remove %s?"), name); | |
1013 | |
1014 /* XXX: anything to do with the returned ui-handle? */ | |
15822 | 1015 purple_request_action(node, _("Confirm Remove"), |
15817 | 1016 primary, sec, |
1017 1, node, 2, | |
1018 _("Remove"), finch_blist_remove_node, | |
1019 _("Cancel"), NULL); | |
1020 g_free(primary); | |
1021 } | |
1022 | |
1023 static void | |
15822 | 1024 finch_blist_toggle_tag_buddy(PurpleBlistNode *node) |
15817 | 1025 { |
1026 GList *iter; | |
1027 if (node == NULL) | |
1028 return; | |
15822 | 1029 if (PURPLE_BLIST_NODE_IS_CHAT(node) || PURPLE_BLIST_NODE_IS_GROUP(node)) |
15817 | 1030 return; |
1031 if (ggblist->tagged && (iter = g_list_find(ggblist->tagged, node)) != NULL) { | |
1032 ggblist->tagged = g_list_delete_link(ggblist->tagged, iter); | |
1033 } else { | |
1034 ggblist->tagged = g_list_prepend(ggblist->tagged, node); | |
1035 } | |
15822 | 1036 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) |
1037 node = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)node); | |
1038 update_buddy_display((PurpleBuddy*)node, ggblist); | |
15817 | 1039 } |
1040 | |
1041 static void | |
15822 | 1042 finch_blist_place_tagged(PurpleBlistNode *target) |
15817 | 1043 { |
15822 | 1044 PurpleGroup *tg = NULL; |
1045 PurpleContact *tc = NULL; | |
15817 | 1046 |
1047 if (target == NULL) | |
1048 return; | |
1049 | |
1050 /* This target resolution probably needs more clarification; for | |
1051 * example, if I tag a buddy in a contact, then place on | |
1052 * another buddy in the same contact, I probably intend to | |
1053 * place the tagged buddy immediately after (before?) the | |
1054 * target buddy -- this will simply move the tagged buddy | |
1055 * within the same contact without reference to position. */ | |
15822 | 1056 if (PURPLE_BLIST_NODE_IS_GROUP(target)) |
1057 tg = (PurpleGroup*)target; | |
1058 else if (PURPLE_BLIST_NODE_IS_CONTACT(target)) | |
1059 tc = (PurpleContact*)target; | |
15817 | 1060 else /* Buddy or Chat */ |
15822 | 1061 tc = (PurpleContact*)target->parent; |
15817 | 1062 |
1063 if (ggblist->tagged) { | |
1064 GList *list = ggblist->tagged; | |
1065 ggblist->tagged = NULL; | |
1066 | |
1067 while (list) { | |
15822 | 1068 PurpleBlistNode *node = list->data; |
15817 | 1069 list = g_list_delete_link(list, list); |
1070 if (tg) { | |
15822 | 1071 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) |
1072 purple_blist_add_contact((PurpleContact*)node, tg, NULL); | |
15817 | 1073 else |
15822 | 1074 purple_blist_add_buddy((PurpleBuddy*)node, NULL, tg, NULL); |
15817 | 1075 } else { |
15822 | 1076 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) |
1077 purple_blist_add_buddy((PurpleBuddy*)node, tc, | |
1078 purple_buddy_get_group(purple_contact_get_priority_buddy(tc)), NULL); | |
1079 else if (PURPLE_BLIST_NODE_IS_CONTACT(node)) | |
1080 purple_blist_merge_contact((PurpleContact*)node, target); | |
15817 | 1081 } |
1082 } | |
1083 } | |
1084 } | |
1085 | |
1086 static void | |
1087 context_menu_destroyed(GntWidget *widget, FinchBlist *ggblist) | |
1088 { | |
1089 ggblist->context = NULL; | |
1090 } | |
1091 | |
1092 static void | |
1093 draw_context_menu(FinchBlist *ggblist) | |
1094 { | |
15822 | 1095 PurpleBlistNode *node = NULL; |
15817 | 1096 GntWidget *context = NULL; |
1097 GntTree *tree = NULL; | |
1098 int x, y, top, width; | |
1099 char *title = NULL; | |
1100 | |
1101 tree = GNT_TREE(ggblist->tree); | |
1102 | |
1103 node = gnt_tree_get_selection_data(tree); | |
1104 | |
1105 if (ggblist->tooltip) | |
1106 remove_tooltip(ggblist); | |
1107 | |
1108 ggblist->cnode = node; | |
1109 | |
1110 ggblist->context = context = gnt_menu_new(GNT_MENU_POPUP); | |
1111 g_signal_connect(G_OBJECT(context), "destroy", G_CALLBACK(context_menu_destroyed), ggblist); | |
1112 | |
1113 if (!node) { | |
1114 create_group_menu(GNT_MENU(context), NULL); | |
1115 title = g_strdup(_("Buddy List")); | |
15822 | 1116 } else if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { |
15817 | 1117 create_buddy_menu(GNT_MENU(context), |
15822 | 1118 purple_contact_get_priority_buddy((PurpleContact*)node)); |
1119 title = g_strdup(purple_contact_get_alias((PurpleContact*)node)); | |
1120 } else if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { | |
1121 PurpleBuddy *buddy = (PurpleBuddy *)node; | |
15817 | 1122 create_buddy_menu(GNT_MENU(context), buddy); |
15822 | 1123 title = g_strdup(purple_buddy_get_name(buddy)); |
1124 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) { | |
1125 PurpleChat *chat = (PurpleChat*)node; | |
15817 | 1126 create_chat_menu(GNT_MENU(context), chat); |
15822 | 1127 title = g_strdup(purple_chat_get_name(chat)); |
1128 } else if (PURPLE_BLIST_NODE_IS_GROUP(node)) { | |
1129 PurpleGroup *group = (PurpleGroup *)node; | |
15817 | 1130 create_group_menu(GNT_MENU(context), group); |
1131 title = g_strdup(group->name); | |
1132 } | |
1133 | |
1134 append_extended_menu(GNT_MENU(context), node); | |
1135 | |
1136 /* These are common for everything */ | |
1137 if (node) { | |
1138 add_custom_action(GNT_MENU(context), _("Rename"), | |
15822 | 1139 PURPLE_CALLBACK(finch_blist_rename_node_cb), node); |
15817 | 1140 add_custom_action(GNT_MENU(context), _("Remove"), |
15822 | 1141 PURPLE_CALLBACK(finch_blist_remove_node_cb), node); |
15817 | 1142 |
15822 | 1143 if (ggblist->tagged && (PURPLE_BLIST_NODE_IS_CONTACT(node) |
1144 || PURPLE_BLIST_NODE_IS_GROUP(node))) { | |
15817 | 1145 add_custom_action(GNT_MENU(context), _("Place tagged"), |
15822 | 1146 PURPLE_CALLBACK(finch_blist_place_tagged), node); |
15817 | 1147 } |
1148 | |
15822 | 1149 if (PURPLE_BLIST_NODE_IS_BUDDY(node) || PURPLE_BLIST_NODE_IS_CONTACT(node)) { |
15817 | 1150 add_custom_action(GNT_MENU(context), _("Toggle Tag"), |
15822 | 1151 PURPLE_CALLBACK(finch_blist_toggle_tag_buddy), node); |
15817 | 1152 } |
1153 } | |
1154 | |
1155 /* Set the position for the popup */ | |
1156 gnt_widget_get_position(GNT_WIDGET(tree), &x, &y); | |
1157 gnt_widget_get_size(GNT_WIDGET(tree), &width, NULL); | |
1158 top = gnt_tree_get_selection_visible_line(tree); | |
1159 | |
1160 x += width; | |
1161 y += top - 1; | |
1162 | |
1163 gnt_widget_set_position(context, x, y); | |
1164 gnt_screen_menu_show(GNT_MENU(context)); | |
1165 g_free(title); | |
1166 } | |
1167 | |
1168 static void | |
15822 | 1169 tooltip_for_buddy(PurpleBuddy *buddy, GString *str) |
15817 | 1170 { |
15822 | 1171 PurplePlugin *prpl; |
1172 PurplePluginProtocolInfo *prpl_info; | |
1173 PurpleAccount *account; | |
1174 PurpleNotifyUserInfo *user_info; | |
1175 const char *alias = purple_buddy_get_alias(buddy); | |
15817 | 1176 char *tmp, *strip; |
1177 | |
15822 | 1178 user_info = purple_notify_user_info_new(); |
15817 | 1179 |
15822 | 1180 account = purple_buddy_get_account(buddy); |
15817 | 1181 |
15822 | 1182 if (g_utf8_collate(purple_buddy_get_name(buddy), alias)) |
1183 purple_notify_user_info_add_pair(user_info, _("Nickname"), alias); | |
15817 | 1184 |
1185 tmp = g_strdup_printf("%s (%s)", | |
15822 | 1186 purple_account_get_username(account), |
1187 purple_account_get_protocol_name(account)); | |
1188 purple_notify_user_info_add_pair(user_info, _("Account"), tmp); | |
15817 | 1189 g_free(tmp); |
1190 | |
15822 | 1191 prpl = purple_find_prpl(purple_account_get_protocol_id(account)); |
1192 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | |
15817 | 1193 if (prpl_info && prpl_info->tooltip_text) { |
1194 prpl_info->tooltip_text(buddy, user_info, TRUE); | |
1195 } | |
1196 | |
15822 | 1197 if (purple_prefs_get_bool("/purple/gnt/blist/idletime")) { |
1198 PurplePresence *pre = purple_buddy_get_presence(buddy); | |
1199 if (purple_presence_is_idle(pre)) { | |
1200 time_t idle = purple_presence_get_idle_time(pre); | |
15817 | 1201 if (idle > 0) { |
15822 | 1202 char *st = purple_str_seconds_to_string(time(NULL) - idle); |
1203 purple_notify_user_info_add_pair(user_info, _("Idle"), st); | |
15817 | 1204 g_free(st); |
1205 } | |
1206 } | |
1207 } | |
1208 | |
15822 | 1209 tmp = purple_notify_user_info_get_text_with_newline(user_info, "<BR>"); |
1210 purple_notify_user_info_destroy(user_info); | |
15817 | 1211 |
15822 | 1212 strip = purple_markup_strip_html(tmp); |
15817 | 1213 g_string_append(str, strip); |
1214 g_free(strip); | |
1215 g_free(tmp); | |
1216 } | |
1217 | |
1218 static GString* | |
1219 make_sure_text_fits(GString *string) | |
1220 { | |
1221 int maxw = getmaxx(stdscr) - 3; | |
1222 char *str = gnt_util_onscreen_fit_string(string->str, maxw); | |
1223 string = g_string_assign(string, str); | |
1224 g_free(str); | |
1225 return string; | |
1226 } | |
1227 | |
1228 static gboolean | |
1229 draw_tooltip_real(FinchBlist *ggblist) | |
1230 { | |
15822 | 1231 PurpleBlistNode *node; |
15817 | 1232 int x, y, top, width, w, h; |
1233 GString *str; | |
1234 GntTree *tree; | |
1235 GntWidget *widget, *box, *tv; | |
1236 char *title = NULL; | |
1237 int lastseen = 0; | |
1238 | |
1239 widget = ggblist->tree; | |
1240 tree = GNT_TREE(widget); | |
1241 | |
1242 if (!gnt_widget_has_focus(ggblist->tree) || | |
1243 (ggblist->context && !GNT_WIDGET_IS_FLAG_SET(ggblist->context, GNT_WIDGET_INVISIBLE))) | |
1244 return FALSE; | |
1245 | |
1246 if (ggblist->tooltip) | |
1247 { | |
1248 /* XXX: Once we can properly redraw on expose events, this can be removed at the end | |
1249 * to avoid the blinking*/ | |
1250 remove_tooltip(ggblist); | |
1251 } | |
1252 | |
1253 node = gnt_tree_get_selection_data(tree); | |
1254 if (!node) | |
1255 return FALSE; | |
1256 | |
1257 str = g_string_new(""); | |
1258 | |
15822 | 1259 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { |
1260 PurpleBuddy *pr = purple_contact_get_priority_buddy((PurpleContact*)node); | |
1261 gboolean offline = !PURPLE_BUDDY_IS_ONLINE(pr); | |
1262 gboolean showoffline = purple_prefs_get_bool(PREF_ROOT "/showoffline"); | |
1263 const char *name = purple_buddy_get_name(pr); | |
15817 | 1264 |
1265 title = g_strdup(name); | |
1266 tooltip_for_buddy(pr, str); | |
1267 for (node = node->child; node; node = node->next) { | |
15822 | 1268 PurpleBuddy *buddy = (PurpleBuddy*)node; |
15817 | 1269 if (offline) { |
15822 | 1270 int value = purple_blist_node_get_int(node, "last_seen"); |
15817 | 1271 if (value > lastseen) |
1272 lastseen = value; | |
1273 } | |
15822 | 1274 if (node == (PurpleBlistNode*)pr) |
15817 | 1275 continue; |
15822 | 1276 if (!purple_account_is_connected(buddy->account)) |
15817 | 1277 continue; |
15822 | 1278 if (!showoffline && !PURPLE_BUDDY_IS_ONLINE(buddy)) |
15817 | 1279 continue; |
1280 str = g_string_append(str, "\n----------\n"); | |
1281 tooltip_for_buddy(buddy, str); | |
1282 } | |
15822 | 1283 } else if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { |
1284 PurpleBuddy *buddy = (PurpleBuddy *)node; | |
15817 | 1285 tooltip_for_buddy(buddy, str); |
15822 | 1286 title = g_strdup(purple_buddy_get_name(buddy)); |
1287 if (!PURPLE_BUDDY_IS_ONLINE((PurpleBuddy*)node)) | |
1288 lastseen = purple_blist_node_get_int(node, "last_seen"); | |
1289 } else if (PURPLE_BLIST_NODE_IS_GROUP(node)) { | |
1290 PurpleGroup *group = (PurpleGroup *)node; | |
15817 | 1291 |
1292 g_string_append_printf(str, _("Online: %d\nTotal: %d"), | |
15822 | 1293 purple_blist_get_group_online_count(group), |
1294 purple_blist_get_group_size(group, FALSE)); | |
15817 | 1295 |
1296 title = g_strdup(group->name); | |
15822 | 1297 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) { |
1298 PurpleChat *chat = (PurpleChat *)node; | |
1299 PurpleAccount *account = chat->account; | |
15817 | 1300 |
1301 g_string_append_printf(str, _("Account: %s (%s)"), | |
15822 | 1302 purple_account_get_username(account), |
1303 purple_account_get_protocol_name(account)); | |
15817 | 1304 |
15822 | 1305 title = g_strdup(purple_chat_get_name(chat)); |
15817 | 1306 } else { |
1307 g_string_free(str, TRUE); | |
1308 return FALSE; | |
1309 } | |
1310 | |
1311 if (lastseen > 0) { | |
15822 | 1312 char *tmp = purple_str_seconds_to_string(time(NULL) - lastseen); |
15817 | 1313 g_string_append_printf(str, _("\nLast Seen: %s ago"), tmp); |
1314 g_free(tmp); | |
1315 } | |
1316 | |
1317 gnt_widget_get_position(widget, &x, &y); | |
1318 gnt_widget_get_size(widget, &width, NULL); | |
1319 top = gnt_tree_get_selection_visible_line(tree); | |
1320 | |
1321 x += width; | |
1322 y += top - 1; | |
1323 | |
1324 box = gnt_box_new(FALSE, FALSE); | |
1325 gnt_box_set_toplevel(GNT_BOX(box), TRUE); | |
1326 GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_NO_SHADOW); | |
1327 gnt_box_set_title(GNT_BOX(box), title); | |
1328 | |
1329 str = make_sure_text_fits(str); | |
1330 gnt_util_get_text_bound(str->str, &w, &h); | |
1331 h = MAX(2, h); | |
1332 tv = gnt_text_view_new(); | |
1333 gnt_widget_set_size(tv, w + 1, h); | |
1334 gnt_box_add_widget(GNT_BOX(box), tv); | |
1335 | |
1336 gnt_widget_set_position(box, x, y); | |
1337 GNT_WIDGET_UNSET_FLAGS(box, GNT_WIDGET_CAN_TAKE_FOCUS); | |
1338 GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_TRANSIENT); | |
1339 gnt_widget_draw(box); | |
1340 | |
1341 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(tv), str->str, GNT_TEXT_FLAG_NORMAL); | |
1342 gnt_text_view_scroll(GNT_TEXT_VIEW(tv), 0); | |
1343 | |
1344 g_free(title); | |
1345 g_string_free(str, TRUE); | |
1346 ggblist->tooltip = box; | |
1347 ggblist->tnode = node; | |
1348 | |
1349 gnt_widget_set_name(ggblist->tooltip, "tooltip"); | |
1350 return FALSE; | |
1351 } | |
1352 | |
1353 static void | |
1354 draw_tooltip(FinchBlist *ggblist) | |
1355 { | |
1356 /* When an account has signed off, it removes one buddy at a time. | |
1357 * Drawing the tooltip after removing each buddy is expensive. On | |
1358 * top of that, if the selected buddy belongs to the disconnected | |
1359 * account, then retreiving the tooltip for that causes crash. So | |
1360 * let's make sure we wait for all the buddies to be removed first.*/ | |
1361 int id = g_timeout_add(0, (GSourceFunc)draw_tooltip_real, ggblist); | |
1362 g_object_set_data_full(G_OBJECT(ggblist->window), "draw_tooltip_calback", | |
1363 GINT_TO_POINTER(id), (GDestroyNotify)g_source_remove); | |
1364 } | |
1365 | |
1366 static void | |
1367 selection_changed(GntWidget *widget, gpointer old, gpointer current, FinchBlist *ggblist) | |
1368 { | |
1369 draw_tooltip(ggblist); | |
1370 } | |
1371 | |
1372 static gboolean | |
1373 context_menu(GntWidget *widget, FinchBlist *ggblist) | |
1374 { | |
1375 draw_context_menu(ggblist); | |
1376 return TRUE; | |
1377 } | |
1378 | |
1379 static gboolean | |
1380 key_pressed(GntWidget *widget, const char *text, FinchBlist *ggblist) | |
1381 { | |
1382 if (text[0] == 27 && text[1] == 0) { | |
1383 /* Escape was pressed */ | |
1384 remove_peripherals(ggblist); | |
1385 } else if (strcmp(text, GNT_KEY_CTRL_O) == 0) { | |
15822 | 1386 purple_prefs_set_bool(PREF_ROOT "/showoffline", |
1387 !purple_prefs_get_bool(PREF_ROOT "/showoffline")); | |
15817 | 1388 } else if (GNT_TREE(ggblist->tree)->search == NULL) { |
1389 if (strcmp(text, "t") == 0) { | |
1390 finch_blist_toggle_tag_buddy(gnt_tree_get_selection_data(GNT_TREE(ggblist->tree))); | |
1391 gnt_bindable_perform_action_named(GNT_BINDABLE(ggblist->tree), "move-down"); | |
1392 } else if (strcmp(text, "a") == 0) { | |
1393 finch_blist_place_tagged(gnt_tree_get_selection_data(GNT_TREE(ggblist->tree))); | |
1394 } else | |
1395 return FALSE; | |
1396 } else | |
1397 return FALSE; | |
1398 | |
1399 return TRUE; | |
1400 } | |
1401 | |
1402 static void | |
15822 | 1403 update_buddy_display(PurpleBuddy *buddy, FinchBlist *ggblist) |
15817 | 1404 { |
15822 | 1405 PurpleContact *contact; |
15817 | 1406 GntTextFormatFlags bflag = 0, cflag = 0; |
1407 | |
15822 | 1408 contact = purple_buddy_get_contact(buddy); |
15817 | 1409 |
15822 | 1410 gnt_tree_change_text(GNT_TREE(ggblist->tree), buddy, 0, get_display_name((PurpleBlistNode*)buddy)); |
1411 gnt_tree_change_text(GNT_TREE(ggblist->tree), contact, 0, get_display_name((PurpleBlistNode*)contact)); | |
15817 | 1412 |
1413 if (ggblist->tagged && g_list_find(ggblist->tagged, buddy)) | |
1414 bflag |= GNT_TEXT_FLAG_BOLD; | |
1415 if (ggblist->tagged && g_list_find(ggblist->tagged, contact)) | |
1416 cflag |= GNT_TEXT_FLAG_BOLD; | |
1417 | |
15822 | 1418 if (ggblist->tnode == (PurpleBlistNode*)buddy) |
15817 | 1419 draw_tooltip(ggblist); |
1420 | |
15822 | 1421 if (purple_presence_is_idle(purple_buddy_get_presence(buddy))) { |
15817 | 1422 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, bflag | GNT_TEXT_FLAG_DIM); |
1423 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), contact, cflag | GNT_TEXT_FLAG_DIM); | |
1424 } else { | |
1425 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, bflag); | |
1426 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), contact, cflag); | |
1427 } | |
1428 } | |
1429 | |
1430 static void | |
15822 | 1431 buddy_status_changed(PurpleBuddy *buddy, PurpleStatus *old, PurpleStatus *now, FinchBlist *ggblist) |
15817 | 1432 { |
1433 update_buddy_display(buddy, ggblist); | |
1434 } | |
1435 | |
1436 static void | |
15822 | 1437 buddy_idle_changed(PurpleBuddy *buddy, int old, int new, FinchBlist *ggblist) |
15817 | 1438 { |
1439 update_buddy_display(buddy, ggblist); | |
1440 } | |
1441 | |
1442 static void | |
1443 remove_peripherals(FinchBlist *ggblist) | |
1444 { | |
1445 if (ggblist->tooltip) | |
1446 remove_tooltip(ggblist); | |
1447 else if (ggblist->context) | |
1448 gnt_widget_destroy(ggblist->context); | |
1449 } | |
1450 | |
1451 static void | |
1452 size_changed_cb(GntWidget *w, int wi, int h) | |
1453 { | |
1454 int width, height; | |
1455 gnt_widget_get_size(w, &width, &height); | |
15822 | 1456 purple_prefs_set_int(PREF_ROOT "/size/width", width); |
1457 purple_prefs_set_int(PREF_ROOT "/size/height", height); | |
15817 | 1458 } |
1459 | |
1460 static void | |
1461 save_position_cb(GntWidget *w, int x, int y) | |
1462 { | |
15822 | 1463 purple_prefs_set_int(PREF_ROOT "/position/x", x); |
1464 purple_prefs_set_int(PREF_ROOT "/position/y", y); | |
15817 | 1465 } |
1466 | |
1467 static void | |
1468 reset_blist_window(GntWidget *window, gpointer null) | |
1469 { | |
15822 | 1470 PurpleBlistNode *node; |
1471 purple_signals_disconnect_by_handle(finch_blist_get_handle()); | |
1472 purple_get_blist()->ui_data = NULL; | |
15817 | 1473 |
15822 | 1474 node = purple_blist_get_root(); |
15817 | 1475 while (node) { |
1476 node->ui_data = NULL; | |
15822 | 1477 node = purple_blist_node_next(node, TRUE); |
15817 | 1478 } |
1479 | |
1480 if (ggblist->typing) | |
1481 g_source_remove(ggblist->typing); | |
1482 remove_peripherals(ggblist); | |
1483 if (ggblist->tagged) | |
1484 g_list_free(ggblist->tagged); | |
1485 g_free(ggblist); | |
1486 ggblist = NULL; | |
1487 } | |
1488 | |
1489 static void | |
1490 populate_buddylist() | |
1491 { | |
15822 | 1492 PurpleBlistNode *node; |
1493 PurpleBuddyList *list; | |
15817 | 1494 |
15822 | 1495 if (strcmp(purple_prefs_get_string(PREF_ROOT "/sort_type"), "text") == 0) { |
15817 | 1496 gnt_tree_set_compare_func(GNT_TREE(ggblist->tree), |
1497 (GCompareFunc)blist_node_compare_text); | |
15822 | 1498 } else if (strcmp(purple_prefs_get_string(PREF_ROOT "/sort_type"), "status") == 0) { |
15817 | 1499 gnt_tree_set_compare_func(GNT_TREE(ggblist->tree), |
1500 (GCompareFunc)blist_node_compare_status); | |
15822 | 1501 } else if (strcmp(purple_prefs_get_string(PREF_ROOT "/sort_type"), "log") == 0) { |
15817 | 1502 gnt_tree_set_compare_func(GNT_TREE(ggblist->tree), |
1503 (GCompareFunc)blist_node_compare_log); | |
1504 } | |
1505 | |
15822 | 1506 list = purple_get_blist(); |
1507 node = purple_blist_get_root(); | |
15817 | 1508 while (node) |
1509 { | |
1510 node_update(list, node); | |
15822 | 1511 node = purple_blist_node_next(node, FALSE); |
15817 | 1512 } |
1513 } | |
1514 | |
1515 static void | |
1516 destroy_status_list(GList *list) | |
1517 { | |
1518 g_list_foreach(list, (GFunc)g_free, NULL); | |
1519 g_list_free(list); | |
1520 } | |
1521 | |
1522 static void | |
1523 populate_status_dropdown() | |
1524 { | |
1525 int i; | |
1526 GList *iter; | |
1527 GList *items = NULL; | |
1528 StatusBoxItem *item = NULL; | |
1529 | |
1530 /* First the primitives */ | |
15822 | 1531 PurpleStatusPrimitive prims[] = {PURPLE_STATUS_AVAILABLE, PURPLE_STATUS_AWAY, |
1532 PURPLE_STATUS_INVISIBLE, PURPLE_STATUS_OFFLINE, PURPLE_STATUS_UNSET}; | |
15817 | 1533 |
1534 gnt_combo_box_remove_all(GNT_COMBO_BOX(ggblist->status)); | |
1535 | |
15822 | 1536 for (i = 0; prims[i] != PURPLE_STATUS_UNSET; i++) |
15817 | 1537 { |
1538 item = g_new0(StatusBoxItem, 1); | |
1539 item->type = STATUS_PRIMITIVE; | |
1540 item->u.prim = prims[i]; | |
1541 items = g_list_prepend(items, item); | |
1542 gnt_combo_box_add_data(GNT_COMBO_BOX(ggblist->status), item, | |
15822 | 1543 purple_primitive_get_name_from_type(prims[i])); |
15817 | 1544 } |
1545 | |
1546 /* Now the popular statuses */ | |
15822 | 1547 for (iter = purple_savedstatuses_get_popular(6); iter; iter = iter->next) |
15817 | 1548 { |
1549 item = g_new0(StatusBoxItem, 1); | |
1550 item->type = STATUS_SAVED_POPULAR; | |
1551 item->u.saved = iter->data; | |
1552 items = g_list_prepend(items, item); | |
1553 gnt_combo_box_add_data(GNT_COMBO_BOX(ggblist->status), item, | |
15822 | 1554 purple_savedstatus_get_title(iter->data)); |
15817 | 1555 } |
1556 | |
1557 /* New savedstatus */ | |
1558 item = g_new0(StatusBoxItem, 1); | |
1559 item->type = STATUS_SAVED_NEW; | |
1560 items = g_list_prepend(items, item); | |
1561 gnt_combo_box_add_data(GNT_COMBO_BOX(ggblist->status), item, | |
1562 _("New...")); | |
1563 | |
1564 /* More savedstatuses */ | |
1565 item = g_new0(StatusBoxItem, 1); | |
1566 item->type = STATUS_SAVED_ALL; | |
1567 items = g_list_prepend(items, item); | |
1568 gnt_combo_box_add_data(GNT_COMBO_BOX(ggblist->status), item, | |
1569 _("Saved...")); | |
1570 | |
1571 /* The keys for the combobox are created here, and never used | |
1572 * anywhere else. So make sure the keys are freed when the widget | |
1573 * is destroyed. */ | |
1574 g_object_set_data_full(G_OBJECT(ggblist->status), "list of statuses", | |
1575 items, (GDestroyNotify)destroy_status_list); | |
1576 } | |
1577 | |
1578 static void | |
15822 | 1579 redraw_blist(const char *name, PurplePrefType type, gconstpointer val, gpointer data) |
15817 | 1580 { |
15822 | 1581 PurpleBlistNode *node, *sel; |
15817 | 1582 if (ggblist == NULL || ggblist->window == NULL) |
1583 return; | |
1584 | |
1585 sel = gnt_tree_get_selection_data(GNT_TREE(ggblist->tree)); | |
1586 gnt_tree_remove_all(GNT_TREE(ggblist->tree)); | |
15822 | 1587 node = purple_blist_get_root(); |
1588 for (; node; node = purple_blist_node_next(node, TRUE)) | |
15817 | 1589 node->ui_data = NULL; |
1590 populate_buddylist(); | |
1591 gnt_tree_set_selected(GNT_TREE(ggblist->tree), sel); | |
1592 draw_tooltip(ggblist); | |
1593 } | |
1594 | |
1595 void finch_blist_init() | |
1596 { | |
15822 | 1597 purple_prefs_add_none(PREF_ROOT); |
1598 purple_prefs_add_none(PREF_ROOT "/size"); | |
1599 purple_prefs_add_int(PREF_ROOT "/size/width", 20); | |
1600 purple_prefs_add_int(PREF_ROOT "/size/height", 17); | |
1601 purple_prefs_add_none(PREF_ROOT "/position"); | |
1602 purple_prefs_add_int(PREF_ROOT "/position/x", 0); | |
1603 purple_prefs_add_int(PREF_ROOT "/position/y", 0); | |
1604 purple_prefs_add_bool(PREF_ROOT "/idletime", TRUE); | |
1605 purple_prefs_add_bool(PREF_ROOT "/showoffline", FALSE); | |
1606 purple_prefs_add_string(PREF_ROOT "/sort_type", "text"); | |
15817 | 1607 |
15822 | 1608 purple_prefs_connect_callback(finch_blist_get_handle(), |
15817 | 1609 PREF_ROOT "/showoffline", redraw_blist, NULL); |
15822 | 1610 purple_prefs_connect_callback(finch_blist_get_handle(), |
15817 | 1611 PREF_ROOT "/sort_type", redraw_blist, NULL); |
1612 | |
15822 | 1613 purple_signal_connect(purple_connections_get_handle(), "signed-on", purple_blist_get_handle(), |
15817 | 1614 G_CALLBACK(account_signed_on_cb), NULL); |
1615 return; | |
1616 } | |
1617 | |
1618 static gboolean | |
1619 remove_typing_cb(gpointer null) | |
1620 { | |
15822 | 1621 PurpleSavedStatus *current; |
15817 | 1622 const char *message, *newmessage; |
15822 | 1623 PurpleStatusPrimitive prim, newprim; |
15817 | 1624 StatusBoxItem *item; |
1625 | |
15822 | 1626 current = purple_savedstatus_get_current(); |
1627 message = purple_savedstatus_get_message(current); | |
1628 prim = purple_savedstatus_get_type(current); | |
15817 | 1629 |
1630 newmessage = gnt_entry_get_text(GNT_ENTRY(ggblist->statustext)); | |
1631 item = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(ggblist->status)); | |
1632 g_return_val_if_fail(item->type == STATUS_PRIMITIVE, FALSE); | |
1633 newprim = item->u.prim; | |
1634 | |
1635 if (newprim != prim || ((message && !newmessage) || | |
1636 (!message && newmessage) || | |
1637 (message && newmessage && g_utf8_collate(message, newmessage) != 0))) | |
1638 { | |
15822 | 1639 PurpleSavedStatus *status = purple_savedstatus_find_transient_by_type_and_message(newprim, newmessage); |
15817 | 1640 /* Holy Crap! That's a LAWNG function name */ |
1641 if (status == NULL) | |
1642 { | |
15822 | 1643 status = purple_savedstatus_new(NULL, newprim); |
1644 purple_savedstatus_set_message(status, newmessage); | |
15817 | 1645 } |
1646 | |
15822 | 1647 purple_savedstatus_activate(status); |
15817 | 1648 } |
1649 | |
1650 gnt_box_give_focus_to_child(GNT_BOX(ggblist->window), ggblist->tree); | |
1651 if (ggblist->typing) | |
1652 g_source_remove(ggblist->typing); | |
1653 ggblist->typing = 0; | |
1654 return FALSE; | |
1655 } | |
1656 | |
1657 static void | |
1658 status_selection_changed(GntComboBox *box, StatusBoxItem *old, StatusBoxItem *now, gpointer null) | |
1659 { | |
1660 gnt_entry_set_text(GNT_ENTRY(ggblist->statustext), NULL); | |
1661 if (now->type == STATUS_SAVED_POPULAR) | |
1662 { | |
1663 /* Set the status immediately */ | |
15822 | 1664 purple_savedstatus_activate(now->u.saved); |
15817 | 1665 } |
1666 else if (now->type == STATUS_PRIMITIVE) | |
1667 { | |
1668 /* Move the focus to the entry box */ | |
1669 /* XXX: Make sure the selected status can have a message */ | |
1670 gnt_box_move_focus(GNT_BOX(ggblist->window), 1); | |
1671 ggblist->typing = g_timeout_add(TYPING_TIMEOUT, (GSourceFunc)remove_typing_cb, NULL); | |
1672 } | |
1673 else if (now->type == STATUS_SAVED_ALL) | |
1674 { | |
1675 /* Restore the selection to reflect current status. */ | |
15822 | 1676 savedstatus_changed(purple_savedstatus_get_current(), NULL); |
15817 | 1677 gnt_box_give_focus_to_child(GNT_BOX(ggblist->window), ggblist->tree); |
1678 finch_savedstatus_show_all(); | |
1679 } | |
1680 else if (now->type == STATUS_SAVED_NEW) | |
1681 { | |
15822 | 1682 savedstatus_changed(purple_savedstatus_get_current(), NULL); |
15817 | 1683 gnt_box_give_focus_to_child(GNT_BOX(ggblist->window), ggblist->tree); |
1684 finch_savedstatus_edit(NULL); | |
1685 } | |
1686 else | |
1687 g_return_if_reached(); | |
1688 } | |
1689 | |
1690 static gboolean | |
1691 status_text_changed(GntEntry *entry, const char *text, gpointer null) | |
1692 { | |
1693 if ((text[0] == 27 || (text[0] == '\t' && text[1] == '\0')) && ggblist->typing == 0) | |
1694 return FALSE; | |
1695 | |
1696 if (ggblist->typing) | |
1697 g_source_remove(ggblist->typing); | |
1698 ggblist->typing = 0; | |
1699 | |
1700 if (text[0] == '\r' && text[1] == 0) | |
1701 { | |
1702 /* Set the status only after you press 'Enter' */ | |
1703 remove_typing_cb(NULL); | |
1704 return TRUE; | |
1705 } | |
1706 | |
1707 ggblist->typing = g_timeout_add(TYPING_TIMEOUT, (GSourceFunc)remove_typing_cb, NULL); | |
1708 return FALSE; | |
1709 } | |
1710 | |
1711 static void | |
15822 | 1712 savedstatus_changed(PurpleSavedStatus *now, PurpleSavedStatus *old) |
15817 | 1713 { |
1714 GList *list; | |
15822 | 1715 PurpleStatusPrimitive prim; |
15817 | 1716 const char *message; |
1717 gboolean found = FALSE, saved = TRUE; | |
1718 | |
1719 if (!ggblist) | |
1720 return; | |
1721 | |
1722 /* Block the signals we don't want to emit */ | |
1723 g_signal_handlers_block_matched(ggblist->status, G_SIGNAL_MATCH_FUNC, | |
1724 0, 0, NULL, status_selection_changed, NULL); | |
1725 g_signal_handlers_block_matched(ggblist->statustext, G_SIGNAL_MATCH_FUNC, | |
1726 0, 0, NULL, status_text_changed, NULL); | |
1727 | |
15822 | 1728 prim = purple_savedstatus_get_type(now); |
1729 message = purple_savedstatus_get_message(now); | |
15817 | 1730 |
1731 /* Rebuild the status dropdown */ | |
1732 populate_status_dropdown(); | |
1733 | |
1734 while (!found) { | |
1735 list = g_object_get_data(G_OBJECT(ggblist->status), "list of statuses"); | |
1736 for (; list; list = list->next) | |
1737 { | |
1738 StatusBoxItem *item = list->data; | |
1739 if ((saved && item->type != STATUS_PRIMITIVE && item->u.saved == now) || | |
1740 (!saved && item->type == STATUS_PRIMITIVE && item->u.prim == prim)) | |
1741 { | |
15822 | 1742 char *mess = purple_unescape_html(message); |
15817 | 1743 gnt_combo_box_set_selected(GNT_COMBO_BOX(ggblist->status), item); |
1744 gnt_entry_set_text(GNT_ENTRY(ggblist->statustext), mess); | |
1745 gnt_widget_draw(ggblist->status); | |
1746 g_free(mess); | |
1747 found = TRUE; | |
1748 break; | |
1749 } | |
1750 } | |
1751 if (!saved) | |
1752 break; | |
1753 saved = FALSE; | |
1754 } | |
1755 | |
1756 g_signal_handlers_unblock_matched(ggblist->status, G_SIGNAL_MATCH_FUNC, | |
1757 0, 0, NULL, status_selection_changed, NULL); | |
1758 g_signal_handlers_unblock_matched(ggblist->statustext, G_SIGNAL_MATCH_FUNC, | |
1759 0, 0, NULL, status_text_changed, NULL); | |
1760 } | |
1761 | |
1762 static int | |
15822 | 1763 blist_node_compare_text(PurpleBlistNode *n1, PurpleBlistNode *n2) |
15817 | 1764 { |
1765 const char *s1, *s2; | |
1766 char *us1, *us2; | |
1767 int ret; | |
1768 | |
1769 g_return_val_if_fail(n1->type == n2->type, -1); | |
1770 | |
1771 switch (n1->type) | |
1772 { | |
15822 | 1773 case PURPLE_BLIST_GROUP_NODE: |
1774 s1 = ((PurpleGroup*)n1)->name; | |
1775 s2 = ((PurpleGroup*)n2)->name; | |
15817 | 1776 break; |
15822 | 1777 case PURPLE_BLIST_CHAT_NODE: |
1778 s1 = purple_chat_get_name((PurpleChat*)n1); | |
1779 s2 = purple_chat_get_name((PurpleChat*)n2); | |
15817 | 1780 break; |
15822 | 1781 case PURPLE_BLIST_BUDDY_NODE: |
1782 return purple_presence_compare(purple_buddy_get_presence((PurpleBuddy*)n1), | |
1783 purple_buddy_get_presence((PurpleBuddy*)n2)); | |
15817 | 1784 break; |
15822 | 1785 case PURPLE_BLIST_CONTACT_NODE: |
1786 s1 = purple_contact_get_alias((PurpleContact*)n1); | |
1787 s2 = purple_contact_get_alias((PurpleContact*)n2); | |
15817 | 1788 break; |
1789 default: | |
1790 return -1; | |
1791 } | |
1792 | |
1793 us1 = g_utf8_strup(s1, -1); | |
1794 us2 = g_utf8_strup(s2, -1); | |
1795 ret = g_utf8_collate(us1, us2); | |
1796 g_free(us1); | |
1797 g_free(us2); | |
1798 | |
1799 return ret; | |
1800 } | |
1801 | |
1802 static int | |
15822 | 1803 blist_node_compare_status(PurpleBlistNode *n1, PurpleBlistNode *n2) |
15817 | 1804 { |
1805 int ret; | |
1806 | |
1807 g_return_val_if_fail(n1->type == n2->type, -1); | |
1808 | |
1809 switch (n1->type) { | |
15822 | 1810 case PURPLE_BLIST_CONTACT_NODE: |
1811 n1 = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)n1); | |
1812 n2 = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)n2); | |
15817 | 1813 /* now compare the presence of the priority buddies */ |
15822 | 1814 case PURPLE_BLIST_BUDDY_NODE: |
1815 ret = purple_presence_compare(purple_buddy_get_presence((PurpleBuddy*)n1), | |
1816 purple_buddy_get_presence((PurpleBuddy*)n2)); | |
15817 | 1817 if (ret != 0) |
1818 return ret; | |
1819 break; | |
1820 default: | |
1821 break; | |
1822 } | |
1823 | |
1824 /* Sort alphabetically if presence is not comparable */ | |
1825 ret = blist_node_compare_text(n1, n2); | |
1826 | |
1827 return ret; | |
1828 } | |
1829 | |
1830 static int | |
15822 | 1831 get_contact_log_size(PurpleBlistNode *c) |
15817 | 1832 { |
1833 int log = 0; | |
15822 | 1834 PurpleBlistNode *node; |
15817 | 1835 |
1836 for (node = c->child; node; node = node->next) { | |
15822 | 1837 PurpleBuddy *b = (PurpleBuddy*)node; |
1838 log += purple_log_get_total_size(PURPLE_LOG_IM, b->name, b->account); | |
15817 | 1839 } |
1840 | |
1841 return log; | |
1842 } | |
1843 | |
1844 static int | |
15822 | 1845 blist_node_compare_log(PurpleBlistNode *n1, PurpleBlistNode *n2) |
15817 | 1846 { |
1847 int ret; | |
15822 | 1848 PurpleBuddy *b1, *b2; |
15817 | 1849 |
1850 g_return_val_if_fail(n1->type == n2->type, -1); | |
1851 | |
1852 switch (n1->type) { | |
15822 | 1853 case PURPLE_BLIST_BUDDY_NODE: |
1854 b1 = (PurpleBuddy*)n1; | |
1855 b2 = (PurpleBuddy*)n2; | |
1856 ret = purple_log_get_total_size(PURPLE_LOG_IM, b2->name, b2->account) - | |
1857 purple_log_get_total_size(PURPLE_LOG_IM, b1->name, b1->account); | |
15817 | 1858 if (ret != 0) |
1859 return ret; | |
1860 break; | |
15822 | 1861 case PURPLE_BLIST_CONTACT_NODE: |
15817 | 1862 ret = get_contact_log_size(n2) - get_contact_log_size(n1); |
1863 if (ret != 0) | |
1864 return ret; | |
1865 break; | |
1866 default: | |
1867 break; | |
1868 } | |
1869 ret = blist_node_compare_text(n1, n2); | |
1870 return ret; | |
1871 } | |
1872 | |
1873 static gboolean | |
1874 blist_clicked(GntTree *tree, GntMouseEvent event, int x, int y, gpointer ggblist) | |
1875 { | |
1876 if (event == GNT_RIGHT_MOUSE_DOWN) { | |
1877 draw_context_menu(ggblist); | |
1878 } | |
1879 return FALSE; | |
1880 } | |
1881 | |
1882 static void | |
1883 plugin_action(GntMenuItem *item, gpointer data) | |
1884 { | |
15822 | 1885 PurplePluginAction *action = data; |
15817 | 1886 if (action && action->callback) |
1887 action->callback(action); | |
1888 } | |
1889 | |
1890 static void | |
15822 | 1891 build_plugin_actions(GntMenuItem *item, PurplePlugin *plugin, gpointer context) |
15817 | 1892 { |
1893 GntWidget *sub = gnt_menu_new(GNT_MENU_POPUP); | |
1894 GList *actions; | |
1895 GntMenuItem *menuitem; | |
1896 | |
1897 gnt_menuitem_set_submenu(item, GNT_MENU(sub)); | |
15822 | 1898 for (actions = PURPLE_PLUGIN_ACTIONS(plugin, context); actions; |
15817 | 1899 actions = g_list_delete_link(actions, actions)) { |
1900 if (actions->data) { | |
15822 | 1901 PurplePluginAction *action = actions->data; |
15817 | 1902 action->plugin = plugin; |
1903 action->context = context; | |
1904 menuitem = gnt_menuitem_new(action->label); | |
1905 gnt_menu_add_item(GNT_MENU(sub), menuitem); | |
1906 | |
1907 gnt_menuitem_set_callback(menuitem, plugin_action, action); | |
1908 g_object_set_data_full(G_OBJECT(menuitem), "plugin_action", | |
15822 | 1909 action, (GDestroyNotify)purple_plugin_action_free); |
15817 | 1910 } |
1911 } | |
1912 } | |
1913 | |
1914 static void | |
1915 reconstruct_plugins_menu() | |
1916 { | |
1917 GntWidget *sub; | |
1918 GntMenuItem *plg; | |
1919 GList *iter; | |
1920 | |
1921 if (!ggblist) | |
1922 return; | |
1923 | |
1924 if (ggblist->plugins == NULL) | |
1925 ggblist->plugins = gnt_menuitem_new(_("Plugins")); | |
1926 | |
1927 plg = ggblist->plugins; | |
1928 sub = gnt_menu_new(GNT_MENU_POPUP); | |
1929 gnt_menuitem_set_submenu(plg, GNT_MENU(sub)); | |
1930 | |
15822 | 1931 for (iter = purple_plugins_get_loaded(); iter; iter = iter->next) { |
1932 PurplePlugin *plugin = iter->data; | |
15817 | 1933 GntMenuItem *item; |
15822 | 1934 if (PURPLE_IS_PROTOCOL_PLUGIN(plugin)) |
15817 | 1935 continue; |
1936 | |
15822 | 1937 if (!PURPLE_PLUGIN_HAS_ACTIONS(plugin)) |
15817 | 1938 continue; |
1939 | |
1940 item = gnt_menuitem_new(_(plugin->info->name)); | |
1941 gnt_menu_add_item(GNT_MENU(sub), item); | |
1942 build_plugin_actions(item, plugin, NULL); | |
1943 } | |
1944 } | |
1945 | |
1946 static void | |
1947 reconstruct_accounts_menu() | |
1948 { | |
1949 GntWidget *sub; | |
1950 GntMenuItem *acc, *item; | |
1951 GList *iter; | |
1952 | |
1953 if (!ggblist) | |
1954 return; | |
1955 | |
1956 if (ggblist->accounts == NULL) | |
1957 ggblist->accounts = gnt_menuitem_new(_("Accounts")); | |
1958 | |
1959 acc = ggblist->accounts; | |
1960 sub = gnt_menu_new(GNT_MENU_POPUP); | |
1961 gnt_menuitem_set_submenu(acc, GNT_MENU(sub)); | |
1962 | |
15822 | 1963 for (iter = purple_accounts_get_all_active(); iter; |
15817 | 1964 iter = g_list_delete_link(iter, iter)) { |
15822 | 1965 PurpleAccount *account = iter->data; |
1966 PurpleConnection *gc = purple_account_get_connection(account); | |
1967 PurplePlugin *prpl; | |
15817 | 1968 |
15822 | 1969 if (!gc || !PURPLE_CONNECTION_IS_CONNECTED(gc)) |
15817 | 1970 continue; |
1971 prpl = gc->prpl; | |
1972 | |
15822 | 1973 if (PURPLE_PLUGIN_HAS_ACTIONS(prpl)) { |
1974 item = gnt_menuitem_new(purple_account_get_username(account)); | |
15817 | 1975 gnt_menu_add_item(GNT_MENU(sub), item); |
1976 build_plugin_actions(item, prpl, gc); | |
1977 } | |
1978 } | |
1979 } | |
1980 | |
1981 static void | |
1982 account_signed_on_cb() | |
1983 { | |
15822 | 1984 PurpleBlistNode *node; |
15817 | 1985 |
15822 | 1986 for (node = purple_blist_get_root(); node; |
1987 node = purple_blist_node_next(node, FALSE)) { | |
1988 if (PURPLE_BLIST_NODE_IS_CHAT(node)) { | |
1989 PurpleChat *chat = (PurpleChat*)node; | |
1990 if (purple_blist_node_get_bool(node, "gnt-autojoin")) | |
1991 serv_join_chat(purple_account_get_connection(chat->account), chat->components); | |
15817 | 1992 } |
1993 } | |
1994 } | |
1995 | |
1996 static void show_offline_cb(GntMenuItem *item, gpointer n) | |
1997 { | |
15822 | 1998 purple_prefs_set_bool(PREF_ROOT "/showoffline", |
1999 !purple_prefs_get_bool(PREF_ROOT "/showoffline")); | |
15817 | 2000 } |
2001 | |
2002 static void sort_blist_change_cb(GntMenuItem *item, gpointer n) | |
2003 { | |
15822 | 2004 purple_prefs_set_string(PREF_ROOT "/sort_type", n); |
15817 | 2005 } |
2006 | |
2007 /* XXX: send_im_select* -- Xerox */ | |
2008 static void | |
15822 | 2009 send_im_select_cb(gpointer data, PurpleRequestFields *fields) |
15817 | 2010 { |
15822 | 2011 PurpleAccount *account; |
15817 | 2012 const char *username; |
2013 | |
15822 | 2014 account = purple_request_fields_get_account(fields, "account"); |
2015 username = purple_request_fields_get_string(fields, "screenname"); | |
15817 | 2016 |
15822 | 2017 purple_conversation_new(PURPLE_CONV_TYPE_IM, account, username); |
15817 | 2018 } |
2019 | |
2020 static void | |
2021 send_im_select(GntMenuItem *item, gpointer n) | |
2022 { | |
15822 | 2023 PurpleRequestFields *fields; |
2024 PurpleRequestFieldGroup *group; | |
2025 PurpleRequestField *field; | |
15817 | 2026 |
15822 | 2027 fields = purple_request_fields_new(); |
15817 | 2028 |
15822 | 2029 group = purple_request_field_group_new(NULL); |
2030 purple_request_fields_add_group(fields, group); | |
15817 | 2031 |
15822 | 2032 field = purple_request_field_string_new("screenname", _("_Name"), NULL, FALSE); |
2033 purple_request_field_set_type_hint(field, "screenname"); | |
2034 purple_request_field_set_required(field, TRUE); | |
2035 purple_request_field_group_add_field(group, field); | |
15817 | 2036 |
15822 | 2037 field = purple_request_field_account_new("account", _("_Account"), NULL); |
2038 purple_request_field_set_type_hint(field, "account"); | |
2039 purple_request_field_set_visible(field, | |
2040 (purple_connections_get_all() != NULL && | |
2041 purple_connections_get_all()->next != NULL)); | |
2042 purple_request_field_set_required(field, TRUE); | |
2043 purple_request_field_group_add_field(group, field); | |
15817 | 2044 |
15822 | 2045 purple_request_fields(purple_get_blist(), _("New Instant Message"), |
15817 | 2046 NULL, |
2047 _("Please enter the screen name or alias of the person " | |
2048 "you would like to IM."), | |
2049 fields, | |
2050 _("OK"), G_CALLBACK(send_im_select_cb), | |
2051 _("Cancel"), NULL, | |
2052 NULL); | |
2053 } | |
2054 | |
2055 static void | |
2056 create_menu() | |
2057 { | |
2058 GntWidget *menu, *sub; | |
2059 GntMenuItem *item; | |
2060 GntWindow *window; | |
2061 | |
2062 if (!ggblist) | |
2063 return; | |
2064 | |
2065 window = GNT_WINDOW(ggblist->window); | |
2066 ggblist->menu = menu = gnt_menu_new(GNT_MENU_TOPLEVEL); | |
2067 gnt_window_set_menu(window, GNT_MENU(menu)); | |
2068 | |
2069 item = gnt_menuitem_new(_("Options")); | |
2070 gnt_menu_add_item(GNT_MENU(menu), item); | |
2071 | |
2072 sub = gnt_menu_new(GNT_MENU_POPUP); | |
2073 gnt_menuitem_set_submenu(item, GNT_MENU(sub)); | |
2074 | |
2075 item = gnt_menuitem_new(_("Send IM...")); | |
2076 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
|
2077 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), send_im_select, NULL); |
15817 | 2078 |
2079 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
|
2080 gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(item), |
15822 | 2081 purple_prefs_get_bool(PREF_ROOT "/showoffline")); |
15817 | 2082 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
|
2083 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), show_offline_cb, NULL); |
15817 | 2084 |
2085 item = gnt_menuitem_new(_("Sort by status")); | |
2086 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
|
2087 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), sort_blist_change_cb, "status"); |
15817 | 2088 |
2089 item = gnt_menuitem_new(_("Sort alphabetically")); | |
2090 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
|
2091 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), sort_blist_change_cb, "text"); |
15817 | 2092 |
2093 item = gnt_menuitem_new(_("Sort by log size")); | |
2094 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
|
2095 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), sort_blist_change_cb, "log"); |
15817 | 2096 |
2097 reconstruct_accounts_menu(); | |
2098 gnt_menu_add_item(GNT_MENU(menu), ggblist->accounts); | |
2099 | |
2100 reconstruct_plugins_menu(); | |
2101 gnt_menu_add_item(GNT_MENU(menu), ggblist->plugins); | |
2102 } | |
2103 | |
2104 void finch_blist_show() | |
2105 { | |
15822 | 2106 blist_show(purple_get_blist()); |
15817 | 2107 } |
2108 | |
2109 static void | |
16105
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
2110 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
|
2111 { |
16106 | 2112 if (PURPLE_BLIST_NODE_IS_GROUP(node)) |
2113 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
|
2114 } |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
2115 |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
2116 static void |
15822 | 2117 blist_show(PurpleBuddyList *list) |
15817 | 2118 { |
2119 if (ggblist == NULL) | |
2120 new_list(list); | |
2121 else if (ggblist->window) | |
2122 return; | |
2123 | |
2124 ggblist->window = gnt_vwindow_new(FALSE); | |
2125 gnt_widget_set_name(ggblist->window, "buddylist"); | |
2126 gnt_box_set_toplevel(GNT_BOX(ggblist->window), TRUE); | |
2127 gnt_box_set_title(GNT_BOX(ggblist->window), _("Buddy List")); | |
2128 gnt_box_set_pad(GNT_BOX(ggblist->window), 0); | |
2129 | |
2130 ggblist->tree = gnt_tree_new(); | |
2131 | |
2132 GNT_WIDGET_SET_FLAGS(ggblist->tree, GNT_WIDGET_NO_BORDER); | |
15822 | 2133 gnt_widget_set_size(ggblist->tree, purple_prefs_get_int(PREF_ROOT "/size/width"), |
2134 purple_prefs_get_int(PREF_ROOT "/size/height")); | |
2135 gnt_widget_set_position(ggblist->window, purple_prefs_get_int(PREF_ROOT "/position/x"), | |
2136 purple_prefs_get_int(PREF_ROOT "/position/y")); | |
15817 | 2137 |
2138 gnt_tree_set_col_width(GNT_TREE(ggblist->tree), 0, | |
15822 | 2139 purple_prefs_get_int(PREF_ROOT "/size/width") - 1); |
15817 | 2140 |
2141 gnt_box_add_widget(GNT_BOX(ggblist->window), ggblist->tree); | |
2142 | |
2143 ggblist->status = gnt_combo_box_new(); | |
2144 gnt_box_add_widget(GNT_BOX(ggblist->window), ggblist->status); | |
2145 ggblist->statustext = gnt_entry_new(NULL); | |
2146 gnt_box_add_widget(GNT_BOX(ggblist->window), ggblist->statustext); | |
2147 | |
2148 gnt_widget_show(ggblist->window); | |
2149 | |
15822 | 2150 purple_signal_connect(purple_connections_get_handle(), "signed-on", finch_blist_get_handle(), |
2151 PURPLE_CALLBACK(reconstruct_accounts_menu), NULL); | |
2152 purple_signal_connect(purple_connections_get_handle(), "signed-off", finch_blist_get_handle(), | |
2153 PURPLE_CALLBACK(reconstruct_accounts_menu), NULL); | |
2154 purple_signal_connect(purple_blist_get_handle(), "buddy-status-changed", finch_blist_get_handle(), | |
2155 PURPLE_CALLBACK(buddy_status_changed), ggblist); | |
2156 purple_signal_connect(purple_blist_get_handle(), "buddy-idle-changed", finch_blist_get_handle(), | |
2157 PURPLE_CALLBACK(buddy_idle_changed), ggblist); | |
15817 | 2158 |
15822 | 2159 purple_signal_connect(purple_plugins_get_handle(), "plugin-load", finch_blist_get_handle(), |
2160 PURPLE_CALLBACK(reconstruct_plugins_menu), NULL); | |
2161 purple_signal_connect(purple_plugins_get_handle(), "plugin-unload", finch_blist_get_handle(), | |
2162 PURPLE_CALLBACK(reconstruct_plugins_menu), NULL); | |
15817 | 2163 |
2164 #if 0 | |
15822 | 2165 purple_signal_connect(purple_blist_get_handle(), "buddy-signed-on", finch_blist_get_handle(), |
2166 PURPLE_CALLBACK(buddy_signed_on), ggblist); | |
2167 purple_signal_connect(purple_blist_get_handle(), "buddy-signed-off", finch_blist_get_handle(), | |
2168 PURPLE_CALLBACK(buddy_signed_off), ggblist); | |
15817 | 2169 |
2170 /* These I plan to use to indicate unread-messages etc. */ | |
15822 | 2171 purple_signal_connect(purple_conversations_get_handle(), "received-im-msg", finch_blist_get_handle(), |
2172 PURPLE_CALLBACK(received_im_msg), list); | |
2173 purple_signal_connect(purple_conversations_get_handle(), "sent-im-msg", finch_blist_get_handle(), | |
2174 PURPLE_CALLBACK(sent_im_msg), NULL); | |
15817 | 2175 |
15822 | 2176 purple_signal_connect(purple_conversations_get_handle(), "received-chat-msg", finch_blist_get_handle(), |
2177 PURPLE_CALLBACK(received_chat_msg), list); | |
15817 | 2178 #endif |
2179 | |
2180 g_signal_connect(G_OBJECT(ggblist->tree), "selection_changed", G_CALLBACK(selection_changed), ggblist); | |
2181 g_signal_connect(G_OBJECT(ggblist->tree), "key_pressed", G_CALLBACK(key_pressed), ggblist); | |
2182 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
|
2183 g_signal_connect(G_OBJECT(ggblist->tree), "collapse-toggled", G_CALLBACK(group_collapsed), NULL); |
15817 | 2184 g_signal_connect_after(G_OBJECT(ggblist->tree), "clicked", G_CALLBACK(blist_clicked), ggblist); |
2185 g_signal_connect(G_OBJECT(ggblist->tree), "activate", G_CALLBACK(selection_activate), ggblist); | |
2186 g_signal_connect_data(G_OBJECT(ggblist->tree), "gained-focus", G_CALLBACK(draw_tooltip), | |
2187 ggblist, 0, G_CONNECT_AFTER | G_CONNECT_SWAPPED); | |
2188 g_signal_connect_data(G_OBJECT(ggblist->tree), "lost-focus", G_CALLBACK(remove_peripherals), | |
2189 ggblist, 0, G_CONNECT_AFTER | G_CONNECT_SWAPPED); | |
2190 g_signal_connect(G_OBJECT(ggblist->tree), "size_changed", G_CALLBACK(size_changed_cb), NULL); | |
2191 g_signal_connect(G_OBJECT(ggblist->window), "position_set", G_CALLBACK(save_position_cb), NULL); | |
2192 g_signal_connect(G_OBJECT(ggblist->window), "destroy", G_CALLBACK(reset_blist_window), NULL); | |
2193 | |
2194 /* Status signals */ | |
15822 | 2195 purple_signal_connect(purple_savedstatuses_get_handle(), "savedstatus-changed", finch_blist_get_handle(), |
2196 PURPLE_CALLBACK(savedstatus_changed), NULL); | |
15817 | 2197 g_signal_connect(G_OBJECT(ggblist->status), "selection_changed", |
2198 G_CALLBACK(status_selection_changed), NULL); | |
2199 g_signal_connect(G_OBJECT(ggblist->statustext), "key_pressed", | |
2200 G_CALLBACK(status_text_changed), NULL); | |
2201 | |
2202 create_menu(); | |
2203 | |
2204 populate_buddylist(); | |
2205 | |
15822 | 2206 savedstatus_changed(purple_savedstatus_get_current(), NULL); |
15817 | 2207 } |
2208 | |
2209 void finch_blist_uninit() | |
2210 { | |
2211 if (ggblist == NULL) | |
2212 return; | |
2213 | |
2214 gnt_widget_destroy(ggblist->window); | |
2215 g_free(ggblist); | |
2216 ggblist = NULL; | |
2217 } | |
2218 | |
2219 gboolean finch_blist_get_position(int *x, int *y) | |
2220 { | |
2221 if (!ggblist || !ggblist->window) | |
2222 return FALSE; | |
2223 gnt_widget_get_position(ggblist->window, x, y); | |
2224 return TRUE; | |
2225 } | |
2226 | |
2227 void finch_blist_set_position(int x, int y) | |
2228 { | |
2229 gnt_widget_set_position(ggblist->window, x, y); | |
2230 } | |
2231 | |
2232 gboolean finch_blist_get_size(int *width, int *height) | |
2233 { | |
2234 if (!ggblist || !ggblist->window) | |
2235 return FALSE; | |
2236 gnt_widget_get_size(ggblist->window, width, height); | |
2237 return TRUE; | |
2238 } | |
2239 | |
2240 void finch_blist_set_size(int width, int height) | |
2241 { | |
2242 gnt_widget_set_size(ggblist->window, width, height); | |
2243 } | |
2244 |