Mercurial > pidgin.yaz
annotate finch/gntblist.c @ 16310:8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 22 Apr 2007 23:55:24 +0000 |
parents | 31dad9806e9d |
children | 4999bbc52881 |
rev | line source |
---|---|
15818 | 1 /** |
2 * @file gntblist.c GNT BuddyList API | |
16194
0f0832c13fcb
Rename the Doxygen group from gntui to finch and define the finch group
Richard Laager <rlaager@wiktel.com>
parents:
16106
diff
changeset
|
3 * @ingroup finch |
15818 | 4 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15844
diff
changeset
|
5 * finch |
15818 | 6 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15844
diff
changeset
|
7 * Finch is the legal property of its developers, whose names are too numerous |
15818 | 8 * to list here. Please refer to the COPYRIGHT file distributed with this |
9 * source distribution. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
25 #include <account.h> | |
26 #include <blist.h> | |
27 #include <notify.h> | |
28 #include <request.h> | |
29 #include <savedstatuses.h> | |
30 #include <server.h> | |
31 #include <signal.h> | |
32 #include <status.h> | |
33 #include <util.h> | |
34 #include "debug.h" | |
35 | |
15823 | 36 #include "finch.h" |
15818 | 37 #include "gntbox.h" |
38 #include "gntcombobox.h" | |
39 #include "gntentry.h" | |
40 #include "gntft.h" | |
41 #include "gntlabel.h" | |
42 #include "gntline.h" | |
43 #include "gntmenu.h" | |
44 #include "gntmenuitem.h" | |
45 #include "gntmenuitemcheck.h" | |
46 #include "gntpounce.h" | |
47 #include "gnttree.h" | |
48 #include "gntutils.h" | |
49 #include "gntwindow.h" | |
50 | |
51 #include "gntblist.h" | |
52 #include "gntconv.h" | |
53 #include "gntstatus.h" | |
54 #include <string.h> | |
55 | |
15823 | 56 #define PREF_ROOT "/purple/gnt/blist" |
15818 | 57 #define TYPING_TIMEOUT 4000 |
58 | |
59 typedef struct | |
60 { | |
61 GntWidget *window; | |
62 GntWidget *tree; | |
63 | |
64 GntWidget *tooltip; | |
15823 | 65 PurpleBlistNode *tnode; /* Who is the tooltip being displayed for? */ |
15818 | 66 GList *tagged; /* A list of tagged blistnodes */ |
67 | |
68 GntWidget *context; | |
15823 | 69 PurpleBlistNode *cnode; |
15818 | 70 |
71 /* XXX: I am KISSing */ | |
72 GntWidget *status; /* Dropdown with the statuses */ | |
73 GntWidget *statustext; /* Status message */ | |
74 int typing; | |
75 | |
76 GntWidget *menu; | |
77 /* These are the menuitems that get regenerated */ | |
78 GntMenuItem *accounts; | |
79 GntMenuItem *plugins; | |
80 } FinchBlist; | |
81 | |
82 typedef enum | |
83 { | |
84 STATUS_PRIMITIVE = 0, | |
85 STATUS_SAVED_POPULAR, | |
86 STATUS_SAVED_ALL, | |
87 STATUS_SAVED_NEW | |
88 } StatusType; | |
89 | |
90 typedef struct | |
91 { | |
92 StatusType type; | |
93 union | |
94 { | |
15823 | 95 PurpleStatusPrimitive prim; |
96 PurpleSavedStatus *saved; | |
15818 | 97 } u; |
98 } StatusBoxItem; | |
99 | |
100 FinchBlist *ggblist; | |
101 | |
15823 | 102 static void add_buddy(PurpleBuddy *buddy, FinchBlist *ggblist); |
103 static void add_contact(PurpleContact *contact, FinchBlist *ggblist); | |
104 static void add_group(PurpleGroup *group, FinchBlist *ggblist); | |
105 static void add_chat(PurpleChat *chat, FinchBlist *ggblist); | |
106 static void add_node(PurpleBlistNode *node, FinchBlist *ggblist); | |
15818 | 107 static void draw_tooltip(FinchBlist *ggblist); |
108 static gboolean remove_typing_cb(gpointer null); | |
109 static void remove_peripherals(FinchBlist *ggblist); | |
15823 | 110 static const char * get_display_name(PurpleBlistNode *node); |
111 static void savedstatus_changed(PurpleSavedStatus *now, PurpleSavedStatus *old); | |
112 static void blist_show(PurpleBuddyList *list); | |
113 static void update_buddy_display(PurpleBuddy *buddy, FinchBlist *ggblist); | |
15818 | 114 static void account_signed_on_cb(void); |
115 | |
116 /* Sort functions */ | |
15823 | 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); | |
15818 | 120 |
121 static gboolean | |
15823 | 122 is_contact_online(PurpleContact *contact) |
15818 | 123 { |
15823 | 124 PurpleBlistNode *node; |
125 for (node = ((PurpleBlistNode*)contact)->child; node; node = node->next) { | |
126 if (PURPLE_BUDDY_IS_ONLINE((PurpleBuddy*)node)) | |
15818 | 127 return TRUE; |
128 } | |
129 return FALSE; | |
130 } | |
131 | |
132 static gboolean | |
15823 | 133 is_group_online(PurpleGroup *group) |
15818 | 134 { |
15823 | 135 PurpleBlistNode *node; |
136 for (node = ((PurpleBlistNode*)group)->child; node; node = node->next) { | |
137 if (PURPLE_BLIST_NODE_IS_CHAT(node)) | |
15818 | 138 return TRUE; |
15823 | 139 else if (is_contact_online((PurpleContact*)node)) |
15818 | 140 return TRUE; |
141 } | |
142 return FALSE; | |
143 } | |
144 | |
145 static void | |
15823 | 146 new_node(PurpleBlistNode *node) |
15818 | 147 { |
148 } | |
149 | |
15823 | 150 static void add_node(PurpleBlistNode *node, FinchBlist *ggblist) |
15818 | 151 { |
15823 | 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); | |
15818 | 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 | |
15823 | 172 node_remove(PurpleBuddyList *list, PurpleBlistNode *node) |
15818 | 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 | |
15823 | 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)) || | |
15818 | 187 contact->currentsize < 1) |
15823 | 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)) || | |
15818 | 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 | |
15823 | 202 node_update(PurpleBuddyList *list, PurpleBlistNode *node) |
15818 | 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 | |
15823 | 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); | |
15818 | 223 else |
15823 | 224 node_remove(purple_get_blist(), node); |
15818 | 225 |
226 node_update(list, node->parent); | |
15823 | 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)) || | |
15818 | 232 contact->currentsize < 1) |
15823 | 233 node_remove(purple_get_blist(), node); |
15818 | 234 else |
235 add_node(node, list->ui_data); | |
15823 | 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)) || | |
15818 | 239 group->currentsize < 1) |
240 node_remove(list, node); | |
241 } | |
242 } | |
243 | |
244 static void | |
15823 | 245 new_list(PurpleBuddyList *list) |
15818 | 246 { |
247 if (ggblist) | |
248 return; | |
249 | |
250 ggblist = g_new0(FinchBlist, 1); | |
251 list->ui_data = ggblist; | |
252 } | |
253 | |
254 static void | |
15823 | 255 add_buddy_cb(void *data, PurpleRequestFields *allfields) |
15818 | 256 { |
15823 | 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"); | |
15818 | 261 const char *error = NULL; |
15823 | 262 PurpleGroup *grp; |
263 PurpleBuddy *buddy; | |
15818 | 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 { | |
15823 | 274 purple_notify_error(NULL, _("Error"), _("Error adding buddy"), error); |
15818 | 275 return; |
276 } | |
277 | |
15823 | 278 grp = purple_find_group(group); |
15818 | 279 if (!grp) |
280 { | |
15823 | 281 grp = purple_group_new(group); |
282 purple_blist_add_group(grp, NULL); | |
15818 | 283 } |
284 | |
15823 | 285 buddy = purple_buddy_new(account, username, alias); |
286 purple_blist_add_buddy(buddy, NULL, grp, NULL); | |
287 purple_account_add_buddy(account, buddy); | |
15818 | 288 } |
289 | |
290 static void | |
15823 | 291 finch_request_add_buddy(PurpleAccount *account, const char *username, const char *grp, const char *alias) |
15818 | 292 { |
15823 | 293 PurpleRequestFields *fields = purple_request_fields_new(); |
294 PurpleRequestFieldGroup *group = purple_request_field_group_new(NULL); | |
295 PurpleRequestField *field; | |
15818 | 296 |
15823 | 297 purple_request_fields_add_group(fields, group); |
15818 | 298 |
15823 | 299 field = purple_request_field_string_new("screenname", _("Screen Name"), username, FALSE); |
300 purple_request_field_group_add_field(group, field); | |
15818 | 301 |
15823 | 302 field = purple_request_field_string_new("alias", _("Alias"), alias, FALSE); |
303 purple_request_field_group_add_field(group, field); | |
15818 | 304 |
15823 | 305 field = purple_request_field_string_new("group", _("Group"), grp, FALSE); |
306 purple_request_field_group_add_field(group, field); | |
15844
e74c2488448b
Group autocomplete for buddy adding
Richard Nelson <wabz@pidgin.im>
parents:
15823
diff
changeset
|
307 purple_request_field_set_type_hint(field, "group"); |
15818 | 308 |
15823 | 309 field = purple_request_field_account_new("account", _("Account"), NULL); |
310 purple_request_field_account_set_show_all(field, FALSE); | |
15818 | 311 if (account) |
15823 | 312 purple_request_field_account_set_value(field, account); |
313 purple_request_field_group_add_field(group, field); | |
15818 | 314 |
15823 | 315 purple_request_fields(NULL, _("Add Buddy"), NULL, _("Please enter buddy information."), |
15818 | 316 fields, _("Add"), G_CALLBACK(add_buddy_cb), _("Cancel"), NULL, NULL); |
317 } | |
318 | |
319 static void | |
15823 | 320 add_chat_cb(void *data, PurpleRequestFields *allfields) |
15818 | 321 { |
15823 | 322 PurpleAccount *account; |
15818 | 323 const char *alias, *name, *group; |
15823 | 324 PurpleChat *chat; |
325 PurpleGroup *grp; | |
15818 | 326 GHashTable *hash = NULL; |
15823 | 327 PurpleConnection *gc; |
15818 | 328 |
15823 | 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"); | |
15818 | 333 |
15823 | 334 if (!purple_account_is_connected(account) || !name || !*name) |
15818 | 335 return; |
336 | |
337 if (!group || !*group) | |
338 group = _("Chats"); | |
339 | |
15823 | 340 gc = purple_account_get_connection(account); |
15818 | 341 |
15823 | 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); | |
15818 | 344 |
15823 | 345 chat = purple_chat_new(account, name, hash); |
15818 | 346 |
347 if (chat != NULL) { | |
15823 | 348 if ((grp = purple_find_group(group)) == NULL) { |
349 grp = purple_group_new(group); | |
350 purple_blist_add_group(grp, NULL); | |
15818 | 351 } |
15823 | 352 purple_blist_add_chat(chat, grp, NULL); |
353 purple_blist_alias_chat(chat, alias); | |
15818 | 354 } |
355 } | |
356 | |
357 static void | |
15823 | 358 finch_request_add_chat(PurpleAccount *account, PurpleGroup *grp, const char *alias, const char *name) |
15818 | 359 { |
15823 | 360 PurpleRequestFields *fields = purple_request_fields_new(); |
361 PurpleRequestFieldGroup *group = purple_request_field_group_new(NULL); | |
362 PurpleRequestField *field; | |
15818 | 363 |
15823 | 364 purple_request_fields_add_group(fields, group); |
15818 | 365 |
15823 | 366 field = purple_request_field_account_new("account", _("Account"), NULL); |
367 purple_request_field_account_set_show_all(field, FALSE); | |
15818 | 368 if (account) |
15823 | 369 purple_request_field_account_set_value(field, account); |
370 purple_request_field_group_add_field(group, field); | |
15818 | 371 |
15823 | 372 field = purple_request_field_string_new("name", _("Name"), name, FALSE); |
373 purple_request_field_group_add_field(group, field); | |
15818 | 374 |
15823 | 375 field = purple_request_field_string_new("alias", _("Alias"), alias, FALSE); |
376 purple_request_field_group_add_field(group, field); | |
15818 | 377 |
15823 | 378 field = purple_request_field_string_new("group", _("Group"), grp ? grp->name : NULL, FALSE); |
379 purple_request_field_group_add_field(group, field); | |
15818 | 380 |
15823 | 381 purple_request_fields(NULL, _("Add Chat"), NULL, |
15818 | 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 { | |
15823 | 389 PurpleGroup *grp; |
15818 | 390 |
391 if (!group || !*group) | |
392 { | |
15823 | 393 purple_notify_error(NULL, _("Error"), _("Error adding group"), |
15818 | 394 _("You must give a name for the group to add.")); |
395 return; | |
396 } | |
397 | |
15823 | 398 grp = purple_find_group(group); |
15818 | 399 if (!grp) |
400 { | |
15823 | 401 grp = purple_group_new(group); |
402 purple_blist_add_group(grp, NULL); | |
15818 | 403 } |
404 else | |
405 { | |
15823 | 406 purple_notify_error(NULL, _("Error"), _("Error adding group"), |
15818 | 407 _("A group with the name already exists.")); |
408 } | |
409 } | |
410 | |
411 static void | |
412 finch_request_add_group() | |
413 { | |
15823 | 414 purple_request_input(NULL, _("Add Group"), NULL, _("Enter the name of the group"), |
15818 | 415 NULL, FALSE, FALSE, NULL, |
416 _("Add"), G_CALLBACK(add_group_cb), _("Cancel"), NULL, NULL); | |
417 } | |
418 | |
15823 | 419 static PurpleBlistUiOps blist_ui_ops = |
15818 | 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 | |
15823 | 442 add_group(PurpleGroup *group, FinchBlist *ggblist) |
15818 | 443 { |
15823 | 444 PurpleBlistNode *node = (PurpleBlistNode *)group; |
15818 | 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:
15931
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:
15931
diff
changeset
|
450 !purple_blist_node_get_bool(node, "collapsed")); |
15818 | 451 } |
452 | |
453 static const char * | |
15823 | 454 get_display_name(PurpleBlistNode *node) |
15818 | 455 { |
456 static char text[2096]; | |
457 char status[8] = " "; | |
458 const char *name = NULL; | |
459 | |
15823 | 460 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) |
461 node = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)node); /* XXX: this can return NULL?! */ | |
15818 | 462 |
463 if (node == NULL) | |
464 return NULL; | |
465 | |
15823 | 466 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) |
15818 | 467 { |
15823 | 468 PurpleBuddy *buddy = (PurpleBuddy *)node; |
469 PurpleStatusPrimitive prim; | |
470 PurplePresence *presence; | |
471 PurpleStatus *now; | |
15818 | 472 gboolean ascii = gnt_ascii_only(); |
473 | |
15823 | 474 presence = purple_buddy_get_presence(buddy); |
475 now = purple_presence_get_active_status(presence); | |
15818 | 476 |
15823 | 477 prim = purple_status_type_get_primitive(purple_status_get_type(now)); |
15818 | 478 |
479 switch(prim) | |
480 { | |
15823 | 481 case PURPLE_STATUS_OFFLINE: |
15818 | 482 strncpy(status, ascii ? "x" : "⊗", sizeof(status) - 1); |
483 break; | |
15823 | 484 case PURPLE_STATUS_AVAILABLE: |
15818 | 485 strncpy(status, ascii ? "o" : "â—¯", sizeof(status) - 1); |
486 break; | |
487 default: | |
488 strncpy(status, ascii ? "." : "⊖", sizeof(status) - 1); | |
489 break; | |
490 } | |
15823 | 491 name = purple_buddy_get_alias(buddy); |
15818 | 492 } |
15823 | 493 else if (PURPLE_BLIST_NODE_IS_CHAT(node)) |
15818 | 494 { |
15823 | 495 PurpleChat *chat = (PurpleChat*)node; |
496 name = purple_chat_get_name(chat); | |
15818 | 497 |
498 strncpy(status, "~", sizeof(status) - 1); | |
499 } | |
15823 | 500 else if (PURPLE_BLIST_NODE_IS_GROUP(node)) |
501 return ((PurpleGroup*)node)->name; | |
15818 | 502 |
503 snprintf(text, sizeof(text) - 1, "%s %s", status, name); | |
504 | |
505 return text; | |
506 } | |
507 | |
508 static void | |
15823 | 509 add_chat(PurpleChat *chat, FinchBlist *ggblist) |
15818 | 510 { |
15823 | 511 PurpleGroup *group; |
512 PurpleBlistNode *node = (PurpleBlistNode *)chat; | |
15818 | 513 if (node->ui_data) |
514 return; | |
15823 | 515 if (!purple_account_is_connected(chat->account)) |
15818 | 516 return; |
517 | |
15823 | 518 group = purple_chat_get_group(chat); |
519 add_node((PurpleBlistNode*)group, ggblist); | |
15818 | 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 | |
15823 | 527 add_contact(PurpleContact *contact, FinchBlist *ggblist) |
15818 | 528 { |
15823 | 529 PurpleGroup *group; |
530 PurpleBlistNode *node = (PurpleBlistNode*)contact; | |
15818 | 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 | |
15823 | 540 group = (PurpleGroup*)node->parent; |
541 add_node((PurpleBlistNode*)group, ggblist); | |
15818 | 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 | |
15823 | 551 add_buddy(PurpleBuddy *buddy, FinchBlist *ggblist) |
15818 | 552 { |
15823 | 553 PurpleContact *contact; |
554 PurpleBlistNode *node = (PurpleBlistNode *)buddy; | |
15818 | 555 if (node->ui_data) |
556 return; | |
557 | |
15823 | 558 contact = (PurpleContact*)node->parent; |
15818 | 559 if (!contact) /* When a new buddy is added and show-offline is set */ |
560 return; | |
15823 | 561 add_node((PurpleBlistNode*)contact, ggblist); |
15818 | 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); | |
15823 | 566 if (purple_presence_is_idle(purple_buddy_get_presence(buddy))) { |
15818 | 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 | |
15823 | 577 buddy_signed_on(PurpleBuddy *buddy, FinchBlist *ggblist) |
15818 | 578 { |
15823 | 579 add_node((PurpleBlistNode*)buddy, ggblist); |
15818 | 580 } |
581 | |
582 static void | |
15823 | 583 buddy_signed_off(PurpleBuddy *buddy, FinchBlist *ggblist) |
15818 | 584 { |
15823 | 585 node_remove(purple_get_blist(), (PurpleBlistNode*)buddy); |
15818 | 586 } |
587 #endif | |
588 | |
15823 | 589 PurpleBlistUiOps *finch_blist_get_ui_ops() |
15818 | 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); | |
15823 | 598 PurpleBlistNode *node = gnt_tree_get_selection_data(tree); |
15818 | 599 |
600 if (!node) | |
601 return; | |
602 | |
15823 | 603 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) |
604 node = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)node); | |
15818 | 605 |
15823 | 606 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) |
15818 | 607 { |
15823 | 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)); | |
15818 | 612 finch_conversation_set_active(conv); |
613 } | |
15823 | 614 else if (PURPLE_BLIST_NODE_IS_CHAT(node)) |
15818 | 615 { |
15823 | 616 PurpleChat *chat = (PurpleChat*)node; |
15818 | 617 serv_join_chat(chat->account->gc, chat->components); |
618 } | |
619 } | |
620 | |
621 static void | |
622 context_menu_callback(GntMenuItem *item, gpointer data) | |
623 { | |
15823 | 624 PurpleMenuAction *action = data; |
625 PurpleBlistNode *node = ggblist->cnode; | |
15818 | 626 if (action) { |
15823 | 627 void (*callback)(PurpleBlistNode *, gpointer); |
628 callback = (void (*)(PurpleBlistNode *, gpointer))action->callback; | |
15818 | 629 if (callback) |
630 callback(action->data, node); | |
631 else | |
632 return; | |
633 } | |
634 } | |
635 | |
636 static void | |
15823 | 637 gnt_append_menu_action(GntMenu *menu, PurpleMenuAction *action, gpointer parent) |
15818 | 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) | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
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:
15871
diff
changeset
|
648 gnt_menu_add_item(menu, GNT_MENU_ITEM(item)); |
15818 | 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 | |
15823 | 659 append_proto_menu(GntMenu *menu, PurpleConnection *gc, PurpleBlistNode *node) |
15818 | 660 { |
661 GList *list; | |
15823 | 662 PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl); |
15818 | 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 { | |
15823 | 670 PurpleMenuAction *act = (PurpleMenuAction *) list->data; |
15818 | 671 act->data = node; |
672 gnt_append_menu_action(menu, act, NULL); | |
673 } | |
674 } | |
675 | |
676 static void | |
15823 | 677 add_custom_action(GntMenu *menu, const char *label, PurpleCallback callback, |
15818 | 678 gpointer data) |
679 { | |
15823 | 680 PurpleMenuAction *action = purple_menu_action_new(label, callback, data, NULL); |
15818 | 681 gnt_append_menu_action(menu, action, NULL); |
682 g_signal_connect_swapped(G_OBJECT(menu), "destroy", | |
15823 | 683 G_CALLBACK(purple_menu_action_free), action); |
15818 | 684 } |
685 | |
686 static void | |
15823 | 687 chat_components_edit_ok(PurpleChat *chat, PurpleRequestFields *allfields) |
15818 | 688 { |
689 GList *groups, *fields; | |
690 | |
15823 | 691 for (groups = purple_request_fields_get_groups(allfields); groups; groups = groups->next) { |
692 fields = purple_request_field_group_get_fields(groups->data); | |
15818 | 693 for (; fields; fields = fields->next) { |
15823 | 694 PurpleRequestField *field = fields->data; |
15818 | 695 const char *id; |
696 char *val; | |
697 | |
15823 | 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)); | |
15818 | 701 else |
15823 | 702 val = g_strdup(purple_request_field_string_get_value(field)); |
15818 | 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 | |
15823 | 710 chat_components_edit(PurpleChat *chat, PurpleBlistNode *selected) |
15818 | 711 { |
15823 | 712 PurpleRequestFields *fields = purple_request_fields_new(); |
713 PurpleRequestFieldGroup *group = purple_request_field_group_new(NULL); | |
714 PurpleRequestField *field; | |
15818 | 715 GList *parts, *iter; |
716 struct proto_chat_entry *pce; | |
717 | |
15823 | 718 purple_request_fields_add_group(fields, group); |
15818 | 719 |
15823 | 720 parts = PURPLE_PLUGIN_PROTOCOL_INFO(chat->account->gc->prpl)->chat_info(chat->account->gc); |
15818 | 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; | |
15823 | 729 field = purple_request_field_int_new(pce->identifier, pce->label, val); |
15818 | 730 } else { |
15823 | 731 field = purple_request_field_string_new(pce->identifier, pce->label, |
15818 | 732 g_hash_table_lookup(chat->components, pce->identifier), FALSE); |
733 } | |
734 | |
15823 | 735 purple_request_field_group_add_field(group, field); |
15818 | 736 g_free(pce); |
737 } | |
738 | |
739 g_list_free(parts); | |
740 | |
15823 | 741 purple_request_fields(NULL, _("Edit Chat"), NULL, _("Please Update the necessary fields."), |
15818 | 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 { | |
15823 | 748 PurpleMenuAction *action = data; |
749 purple_blist_node_set_bool(action->data, "gnt-autojoin", | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
750 gnt_menuitem_check_get_checked(GNT_MENU_ITEM_CHECK(item))); |
15818 | 751 } |
752 | |
753 static void | |
15823 | 754 create_chat_menu(GntMenu *menu, PurpleChat *chat) |
15818 | 755 { |
15823 | 756 PurpleMenuAction *action = purple_menu_action_new(_("Auto-join"), NULL, chat, NULL); |
15818 | 757 GntMenuItem *check = gnt_menuitem_check_new(action->label); |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
758 gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(check), |
15823 | 759 purple_blist_node_get_bool((PurpleBlistNode*)chat, "gnt-autojoin")); |
15818 | 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", | |
15823 | 763 G_CALLBACK(purple_menu_action_free), action); |
15818 | 764 |
15823 | 765 add_custom_action(menu, _("Edit Settings"), (PurpleCallback)chat_components_edit, chat); |
15818 | 766 } |
767 | |
768 static void | |
15823 | 769 finch_add_buddy(PurpleGroup *grp, PurpleBlistNode *selected) |
15818 | 770 { |
15823 | 771 purple_blist_request_add_buddy(NULL, NULL, grp ? grp->name : NULL, NULL); |
15818 | 772 } |
773 | |
774 static void | |
15823 | 775 finch_add_group(PurpleGroup *grp, PurpleBlistNode *selected) |
15818 | 776 { |
15823 | 777 purple_blist_request_add_group(); |
15818 | 778 } |
779 | |
780 static void | |
15823 | 781 finch_add_chat(PurpleGroup *grp, PurpleBlistNode *selected) |
15818 | 782 { |
15823 | 783 purple_blist_request_add_chat(NULL, grp, NULL, NULL); |
15818 | 784 } |
785 | |
786 static void | |
15823 | 787 create_group_menu(GntMenu *menu, PurpleGroup *group) |
15818 | 788 { |
789 add_custom_action(menu, _("Add Buddy"), | |
15823 | 790 PURPLE_CALLBACK(finch_add_buddy), group); |
15818 | 791 add_custom_action(menu, _("Add Chat"), |
15823 | 792 PURPLE_CALLBACK(finch_add_chat), group); |
15818 | 793 add_custom_action(menu, _("Add Group"), |
15823 | 794 PURPLE_CALLBACK(finch_add_group), group); |
15818 | 795 } |
796 | |
797 static void | |
15823 | 798 finch_blist_get_buddy_info_cb(PurpleBuddy *buddy, PurpleBlistNode *selected) |
15818 | 799 { |
15823 | 800 serv_get_info(buddy->account->gc, purple_buddy_get_name(buddy)); |
15818 | 801 } |
802 | |
803 static void | |
15823 | 804 finch_blist_menu_send_file_cb(PurpleBuddy *buddy, PurpleBlistNode *selected) |
15818 | 805 { |
806 serv_send_file(buddy->account->gc, buddy->name, NULL); | |
807 } | |
808 | |
809 static void | |
15823 | 810 finch_blist_pounce_node_cb(PurpleBlistNode *node, PurpleBlistNode *selected) |
15818 | 811 { |
15823 | 812 PurpleBuddy *b; |
813 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) | |
814 b = purple_contact_get_priority_buddy((PurpleContact *)node); | |
15818 | 815 else |
15823 | 816 b = (PurpleBuddy *)node; |
15818 | 817 finch_pounce_editor_show(b->account, b->name, NULL); |
818 } | |
819 | |
820 | |
821 static void | |
15823 | 822 create_buddy_menu(GntMenu *menu, PurpleBuddy *buddy) |
15818 | 823 { |
15823 | 824 PurplePluginProtocolInfo *prpl_info; |
15818 | 825 |
15823 | 826 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(buddy->account->gc->prpl); |
15818 | 827 if (prpl_info && prpl_info->get_info) |
828 { | |
829 add_custom_action(menu, _("Get Info"), | |
15823 | 830 PURPLE_CALLBACK(finch_blist_get_buddy_info_cb), buddy); |
15818 | 831 } |
832 | |
833 add_custom_action(menu, _("Add Buddy Pounce"), | |
15823 | 834 PURPLE_CALLBACK(finch_blist_pounce_node_cb), buddy); |
15818 | 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"), | |
15823 | 841 PURPLE_CALLBACK(finch_blist_menu_send_file_cb), buddy); |
15818 | 842 } |
843 #if 0 | |
844 add_custom_action(tree, _("View Log"), | |
15823 | 845 PURPLE_CALLBACK(finch_blist_view_log_cb)), buddy); |
15818 | 846 #endif |
847 | |
848 /* Protocol actions */ | |
849 append_proto_menu(menu, | |
15823 | 850 purple_account_get_connection(purple_buddy_get_account(buddy)), |
851 (PurpleBlistNode*)buddy); | |
15818 | 852 } |
853 | |
854 static void | |
15823 | 855 append_extended_menu(GntMenu *menu, PurpleBlistNode *node) |
15818 | 856 { |
857 GList *iter; | |
858 | |
15823 | 859 for (iter = purple_blist_node_get_extended_menu(node); |
15818 | 860 iter; iter = g_list_delete_link(iter, iter)) |
861 { | |
862 gnt_append_menu_action(menu, iter->data, NULL); | |
863 } | |
864 } | |
865 | |
15823 | 866 /* Xerox'd from gtkdialogs.c:purple_gtkdialogs_remove_contact_cb */ |
15818 | 867 static void |
15823 | 868 remove_contact(PurpleContact *contact) |
15818 | 869 { |
15823 | 870 PurpleBlistNode *bnode, *cnode; |
871 PurpleGroup *group; | |
15818 | 872 |
15823 | 873 cnode = (PurpleBlistNode *)contact; |
874 group = (PurpleGroup*)cnode->parent; | |
15818 | 875 for (bnode = cnode->child; bnode; bnode = bnode->next) { |
15823 | 876 PurpleBuddy *buddy = (PurpleBuddy*)bnode; |
877 if (purple_account_is_connected(buddy->account)) | |
878 purple_account_remove_buddy(buddy->account, buddy, group); | |
15818 | 879 } |
15823 | 880 purple_blist_remove_contact(contact); |
15818 | 881 } |
882 | |
883 static void | |
15823 | 884 rename_blist_node(PurpleBlistNode *node, const char *newname) |
15818 | 885 { |
886 const char *name = newname; | |
887 if (name && !*name) | |
888 name = NULL; | |
889 | |
15823 | 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); | |
15818 | 895 serv_alias_buddy(buddy); |
15823 | 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); | |
15818 | 903 else |
904 g_return_if_reached(); | |
905 } | |
906 | |
907 static void | |
15823 | 908 finch_blist_rename_node_cb(PurpleBlistNode *node, PurpleBlistNode *selected) |
15818 | 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; |
15818 | 913 |
15823 | 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; | |
15818 | 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), |
15818 | 930 _("Cancel"), NULL, node); |
931 | |
932 g_free(prompt); | |
933 } | |
934 | |
15823 | 935 /* Xeroxed from gtkdialogs.c:purple_gtkdialogs_remove_group_cb*/ |
15818 | 936 static void |
15823 | 937 remove_group(PurpleGroup *group) |
15818 | 938 { |
15823 | 939 PurpleBlistNode *cnode, *bnode; |
15818 | 940 |
15823 | 941 cnode = ((PurpleBlistNode*)group)->child; |
15818 | 942 |
943 while (cnode) { | |
15823 | 944 if (PURPLE_BLIST_NODE_IS_CONTACT(cnode)) { |
15818 | 945 bnode = cnode->child; |
946 cnode = cnode->next; | |
947 while (bnode) { | |
15823 | 948 PurpleBuddy *buddy; |
949 if (PURPLE_BLIST_NODE_IS_BUDDY(bnode)) { | |
950 buddy = (PurpleBuddy*)bnode; | |
15818 | 951 bnode = bnode->next; |
15823 | 952 if (purple_account_is_connected(buddy->account)) { |
953 purple_account_remove_buddy(buddy->account, buddy, group); | |
954 purple_blist_remove_buddy(buddy); | |
15818 | 955 } |
956 } else { | |
957 bnode = bnode->next; | |
958 } | |
959 } | |
15823 | 960 } else if (PURPLE_BLIST_NODE_IS_CHAT(cnode)) { |
961 PurpleChat *chat = (PurpleChat *)cnode; | |
15818 | 962 cnode = cnode->next; |
15823 | 963 if (purple_account_is_connected(chat->account)) |
964 purple_blist_remove_chat(chat); | |
15818 | 965 } else { |
966 cnode = cnode->next; | |
967 } | |
968 } | |
969 | |
15823 | 970 purple_blist_remove_group(group); |
15818 | 971 } |
972 | |
973 static void | |
15823 | 974 finch_blist_remove_node(PurpleBlistNode *node) |
15818 | 975 { |
15823 | 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); | |
15818 | 987 } |
988 } | |
989 | |
990 static void | |
15823 | 991 finch_blist_remove_node_cb(PurpleBlistNode *node, PurpleBlistNode *selected) |
15818 | 992 { |
993 char *primary; | |
994 const char *name, *sec = NULL; | |
995 | |
996 /* XXX: could be a contact */ | |
15823 | 997 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { |
998 PurpleContact *c = (PurpleContact*)node; | |
999 name = purple_contact_get_alias(c); | |
15818 | 1000 if (c->totalsize > 1) |
1001 sec = _("Removing this contact will also remove all the buddies in the contact"); | |
15823 | 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)) | |
15818 | 1007 { |
15823 | 1008 name = ((PurpleGroup*)node)->name; |
15818 | 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? */ | |
15823 | 1017 purple_request_action(node, _("Confirm Remove"), |
15818 | 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 | |
15823 | 1026 finch_blist_toggle_tag_buddy(PurpleBlistNode *node) |
15818 | 1027 { |
1028 GList *iter; | |
1029 if (node == NULL) | |
1030 return; | |
15823 | 1031 if (PURPLE_BLIST_NODE_IS_CHAT(node) || PURPLE_BLIST_NODE_IS_GROUP(node)) |
15818 | 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 } | |
15823 | 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); | |
15818 | 1041 } |
1042 | |
1043 static void | |
15823 | 1044 finch_blist_place_tagged(PurpleBlistNode *target) |
15818 | 1045 { |
15823 | 1046 PurpleGroup *tg = NULL; |
1047 PurpleContact *tc = NULL; | |
15818 | 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. */ | |
15823 | 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; | |
15818 | 1062 else /* Buddy or Chat */ |
15823 | 1063 tc = (PurpleContact*)target->parent; |
15818 | 1064 |
1065 if (ggblist->tagged) { | |
1066 GList *list = ggblist->tagged; | |
1067 ggblist->tagged = NULL; | |
1068 | |
1069 while (list) { | |
15823 | 1070 PurpleBlistNode *node = list->data; |
15818 | 1071 list = g_list_delete_link(list, list); |
1072 if (tg) { | |
15823 | 1073 if (PURPLE_BLIST_NODE_IS_CONTACT(node)) |
1074 purple_blist_add_contact((PurpleContact*)node, tg, NULL); | |
15818 | 1075 else |
15823 | 1076 purple_blist_add_buddy((PurpleBuddy*)node, NULL, tg, NULL); |
15818 | 1077 } else { |
15823 | 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); | |
15818 | 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 { | |
15823 | 1097 PurpleBlistNode *node = NULL; |
15818 | 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")); | |
15823 | 1118 } else if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { |
15818 | 1119 create_buddy_menu(GNT_MENU(context), |
15823 | 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; | |
15818 | 1124 create_buddy_menu(GNT_MENU(context), buddy); |
15823 | 1125 title = g_strdup(purple_buddy_get_name(buddy)); |
1126 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) { | |
1127 PurpleChat *chat = (PurpleChat*)node; | |
15818 | 1128 create_chat_menu(GNT_MENU(context), chat); |
15823 | 1129 title = g_strdup(purple_chat_get_name(chat)); |
1130 } else if (PURPLE_BLIST_NODE_IS_GROUP(node)) { | |
1131 PurpleGroup *group = (PurpleGroup *)node; | |
15818 | 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"), |
15823 | 1142 PURPLE_CALLBACK(finch_blist_rename_node_cb), node); |
15818 | 1143 add_custom_action(GNT_MENU(context), _("Remove"), |
15823 | 1144 PURPLE_CALLBACK(finch_blist_remove_node_cb), node); |
15818 | 1145 |
15823 | 1146 if (ggblist->tagged && (PURPLE_BLIST_NODE_IS_CONTACT(node) |
1147 || PURPLE_BLIST_NODE_IS_GROUP(node))) { | |
15818 | 1148 add_custom_action(GNT_MENU(context), _("Place tagged"), |
15823 | 1149 PURPLE_CALLBACK(finch_blist_place_tagged), node); |
15818 | 1150 } |
1151 | |
15823 | 1152 if (PURPLE_BLIST_NODE_IS_BUDDY(node) || PURPLE_BLIST_NODE_IS_CONTACT(node)) { |
15818 | 1153 add_custom_action(GNT_MENU(context), _("Toggle Tag"), |
15823 | 1154 PURPLE_CALLBACK(finch_blist_toggle_tag_buddy), node); |
15818 | 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 | |
15823 | 1172 tooltip_for_buddy(PurpleBuddy *buddy, GString *str) |
15818 | 1173 { |
15823 | 1174 PurplePlugin *prpl; |
1175 PurplePluginProtocolInfo *prpl_info; | |
1176 PurpleAccount *account; | |
1177 PurpleNotifyUserInfo *user_info; | |
1178 const char *alias = purple_buddy_get_alias(buddy); | |
15818 | 1179 char *tmp, *strip; |
1180 | |
15823 | 1181 user_info = purple_notify_user_info_new(); |
15818 | 1182 |
15823 | 1183 account = purple_buddy_get_account(buddy); |
15818 | 1184 |
15823 | 1185 if (g_utf8_collate(purple_buddy_get_name(buddy), alias)) |
1186 purple_notify_user_info_add_pair(user_info, _("Nickname"), alias); | |
15818 | 1187 |
1188 tmp = g_strdup_printf("%s (%s)", | |
15823 | 1189 purple_account_get_username(account), |
1190 purple_account_get_protocol_name(account)); | |
1191 purple_notify_user_info_add_pair(user_info, _("Account"), tmp); | |
15818 | 1192 g_free(tmp); |
1193 | |
15823 | 1194 prpl = purple_find_prpl(purple_account_get_protocol_id(account)); |
1195 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | |
15818 | 1196 if (prpl_info && prpl_info->tooltip_text) { |
1197 prpl_info->tooltip_text(buddy, user_info, TRUE); | |
1198 } | |
1199 | |
15823 | 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); | |
15818 | 1204 if (idle > 0) { |
15823 | 1205 char *st = purple_str_seconds_to_string(time(NULL) - idle); |
1206 purple_notify_user_info_add_pair(user_info, _("Idle"), st); | |
15818 | 1207 g_free(st); |
1208 } | |
1209 } | |
1210 } | |
1211 | |
15823 | 1212 tmp = purple_notify_user_info_get_text_with_newline(user_info, "<BR>"); |
1213 purple_notify_user_info_destroy(user_info); | |
15818 | 1214 |
15823 | 1215 strip = purple_markup_strip_html(tmp); |
15818 | 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 { | |
15823 | 1234 PurpleBlistNode *node; |
15818 | 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 | |
15823 | 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); | |
15818 | 1267 |
1268 title = g_strdup(name); | |
1269 tooltip_for_buddy(pr, str); | |
1270 for (node = node->child; node; node = node->next) { | |
15823 | 1271 PurpleBuddy *buddy = (PurpleBuddy*)node; |
15818 | 1272 if (offline) { |
15823 | 1273 int value = purple_blist_node_get_int(node, "last_seen"); |
15818 | 1274 if (value > lastseen) |
1275 lastseen = value; | |
1276 } | |
15823 | 1277 if (node == (PurpleBlistNode*)pr) |
15818 | 1278 continue; |
15823 | 1279 if (!purple_account_is_connected(buddy->account)) |
15818 | 1280 continue; |
15823 | 1281 if (!showoffline && !PURPLE_BUDDY_IS_ONLINE(buddy)) |
15818 | 1282 continue; |
1283 str = g_string_append(str, "\n----------\n"); | |
1284 tooltip_for_buddy(buddy, str); | |
1285 } | |
15823 | 1286 } else if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { |
1287 PurpleBuddy *buddy = (PurpleBuddy *)node; | |
15818 | 1288 tooltip_for_buddy(buddy, str); |
15823 | 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; | |
15818 | 1294 |
1295 g_string_append_printf(str, _("Online: %d\nTotal: %d"), | |
15823 | 1296 purple_blist_get_group_online_count(group), |
1297 purple_blist_get_group_size(group, FALSE)); | |
15818 | 1298 |
1299 title = g_strdup(group->name); | |
15823 | 1300 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) { |
1301 PurpleChat *chat = (PurpleChat *)node; | |
1302 PurpleAccount *account = chat->account; | |
15818 | 1303 |
1304 g_string_append_printf(str, _("Account: %s (%s)"), | |
15823 | 1305 purple_account_get_username(account), |
1306 purple_account_get_protocol_name(account)); | |
15818 | 1307 |
15823 | 1308 title = g_strdup(purple_chat_get_name(chat)); |
15818 | 1309 } else { |
1310 g_string_free(str, TRUE); | |
1311 return FALSE; | |
1312 } | |
1313 | |
1314 if (lastseen > 0) { | |
15823 | 1315 char *tmp = purple_str_seconds_to_string(time(NULL) - lastseen); |
15818 | 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) { | |
15823 | 1389 purple_prefs_set_bool(PREF_ROOT "/showoffline", |
1390 !purple_prefs_get_bool(PREF_ROOT "/showoffline")); | |
15818 | 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 | |
15823 | 1406 update_buddy_display(PurpleBuddy *buddy, FinchBlist *ggblist) |
15818 | 1407 { |
15823 | 1408 PurpleContact *contact; |
15818 | 1409 GntTextFormatFlags bflag = 0, cflag = 0; |
1410 | |
15823 | 1411 contact = purple_buddy_get_contact(buddy); |
15818 | 1412 |
15823 | 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)); | |
15818 | 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 | |
15823 | 1421 if (ggblist->tnode == (PurpleBlistNode*)buddy) |
15818 | 1422 draw_tooltip(ggblist); |
1423 | |
15823 | 1424 if (purple_presence_is_idle(purple_buddy_get_presence(buddy))) { |
15818 | 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 | |
15823 | 1434 buddy_status_changed(PurpleBuddy *buddy, PurpleStatus *old, PurpleStatus *now, FinchBlist *ggblist) |
15818 | 1435 { |
1436 update_buddy_display(buddy, ggblist); | |
1437 } | |
1438 | |
1439 static void | |
15823 | 1440 buddy_idle_changed(PurpleBuddy *buddy, int old, int new, FinchBlist *ggblist) |
15818 | 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); | |
15823 | 1459 purple_prefs_set_int(PREF_ROOT "/size/width", width); |
1460 purple_prefs_set_int(PREF_ROOT "/size/height", height); | |
15818 | 1461 } |
1462 | |
1463 static void | |
1464 save_position_cb(GntWidget *w, int x, int y) | |
1465 { | |
15823 | 1466 purple_prefs_set_int(PREF_ROOT "/position/x", x); |
1467 purple_prefs_set_int(PREF_ROOT "/position/y", y); | |
15818 | 1468 } |
1469 | |
1470 static void | |
1471 reset_blist_window(GntWidget *window, gpointer null) | |
1472 { | |
15823 | 1473 PurpleBlistNode *node; |
1474 purple_signals_disconnect_by_handle(finch_blist_get_handle()); | |
1475 purple_get_blist()->ui_data = NULL; | |
15818 | 1476 |
15823 | 1477 node = purple_blist_get_root(); |
15818 | 1478 while (node) { |
1479 node->ui_data = NULL; | |
15823 | 1480 node = purple_blist_node_next(node, TRUE); |
15818 | 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 { | |
15823 | 1495 PurpleBlistNode *node; |
1496 PurpleBuddyList *list; | |
15818 | 1497 |
15823 | 1498 if (strcmp(purple_prefs_get_string(PREF_ROOT "/sort_type"), "text") == 0) { |
15818 | 1499 gnt_tree_set_compare_func(GNT_TREE(ggblist->tree), |
1500 (GCompareFunc)blist_node_compare_text); | |
15823 | 1501 } else if (strcmp(purple_prefs_get_string(PREF_ROOT "/sort_type"), "status") == 0) { |
15818 | 1502 gnt_tree_set_compare_func(GNT_TREE(ggblist->tree), |
1503 (GCompareFunc)blist_node_compare_status); | |
15823 | 1504 } else if (strcmp(purple_prefs_get_string(PREF_ROOT "/sort_type"), "log") == 0) { |
15818 | 1505 gnt_tree_set_compare_func(GNT_TREE(ggblist->tree), |
1506 (GCompareFunc)blist_node_compare_log); | |
1507 } | |
1508 | |
15823 | 1509 list = purple_get_blist(); |
1510 node = purple_blist_get_root(); | |
15818 | 1511 while (node) |
1512 { | |
1513 node_update(list, node); | |
15823 | 1514 node = purple_blist_node_next(node, FALSE); |
15818 | 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 */ | |
15823 | 1534 PurpleStatusPrimitive prims[] = {PURPLE_STATUS_AVAILABLE, PURPLE_STATUS_AWAY, |
1535 PURPLE_STATUS_INVISIBLE, PURPLE_STATUS_OFFLINE, PURPLE_STATUS_UNSET}; | |
15818 | 1536 |
1537 gnt_combo_box_remove_all(GNT_COMBO_BOX(ggblist->status)); | |
1538 | |
15823 | 1539 for (i = 0; prims[i] != PURPLE_STATUS_UNSET; i++) |
15818 | 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, | |
15823 | 1546 purple_primitive_get_name_from_type(prims[i])); |
15818 | 1547 } |
1548 | |
1549 /* Now the popular statuses */ | |
15823 | 1550 for (iter = purple_savedstatuses_get_popular(6); iter; iter = iter->next) |
15818 | 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, | |
15823 | 1557 purple_savedstatus_get_title(iter->data)); |
15818 | 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 | |
15823 | 1582 redraw_blist(const char *name, PurplePrefType type, gconstpointer val, gpointer data) |
15818 | 1583 { |
15823 | 1584 PurpleBlistNode *node, *sel; |
15818 | 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)); | |
15823 | 1590 node = purple_blist_get_root(); |
1591 for (; node; node = purple_blist_node_next(node, TRUE)) | |
15818 | 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 { | |
15823 | 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"); | |
15818 | 1610 |
15823 | 1611 purple_prefs_connect_callback(finch_blist_get_handle(), |
15818 | 1612 PREF_ROOT "/showoffline", redraw_blist, NULL); |
15823 | 1613 purple_prefs_connect_callback(finch_blist_get_handle(), |
15818 | 1614 PREF_ROOT "/sort_type", redraw_blist, NULL); |
1615 | |
15823 | 1616 purple_signal_connect(purple_connections_get_handle(), "signed-on", purple_blist_get_handle(), |
15818 | 1617 G_CALLBACK(account_signed_on_cb), NULL); |
1618 return; | |
1619 } | |
1620 | |
1621 static gboolean | |
1622 remove_typing_cb(gpointer null) | |
1623 { | |
15823 | 1624 PurpleSavedStatus *current; |
15818 | 1625 const char *message, *newmessage; |
15823 | 1626 PurpleStatusPrimitive prim, newprim; |
15818 | 1627 StatusBoxItem *item; |
1628 | |
15823 | 1629 current = purple_savedstatus_get_current(); |
1630 message = purple_savedstatus_get_message(current); | |
1631 prim = purple_savedstatus_get_type(current); | |
15818 | 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 { | |
15823 | 1642 PurpleSavedStatus *status = purple_savedstatus_find_transient_by_type_and_message(newprim, newmessage); |
15818 | 1643 /* Holy Crap! That's a LAWNG function name */ |
1644 if (status == NULL) | |
1645 { | |
15823 | 1646 status = purple_savedstatus_new(NULL, newprim); |
1647 purple_savedstatus_set_message(status, newmessage); | |
15818 | 1648 } |
1649 | |
15823 | 1650 purple_savedstatus_activate(status); |
15818 | 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 */ | |
15823 | 1667 purple_savedstatus_activate(now->u.saved); |
15818 | 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. */ | |
15823 | 1679 savedstatus_changed(purple_savedstatus_get_current(), NULL); |
15818 | 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 { | |
15823 | 1685 savedstatus_changed(purple_savedstatus_get_current(), NULL); |
15818 | 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 | |
15823 | 1715 savedstatus_changed(PurpleSavedStatus *now, PurpleSavedStatus *old) |
15818 | 1716 { |
1717 GList *list; | |
15823 | 1718 PurpleStatusPrimitive prim; |
15818 | 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 | |
15823 | 1731 prim = purple_savedstatus_get_type(now); |
1732 message = purple_savedstatus_get_message(now); | |
15818 | 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 { | |
15823 | 1745 char *mess = purple_unescape_html(message); |
15818 | 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 | |
15823 | 1766 blist_node_compare_text(PurpleBlistNode *n1, PurpleBlistNode *n2) |
15818 | 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 { | |
15823 | 1776 case PURPLE_BLIST_GROUP_NODE: |
1777 s1 = ((PurpleGroup*)n1)->name; | |
1778 s2 = ((PurpleGroup*)n2)->name; | |
15818 | 1779 break; |
15823 | 1780 case PURPLE_BLIST_CHAT_NODE: |
1781 s1 = purple_chat_get_name((PurpleChat*)n1); | |
1782 s2 = purple_chat_get_name((PurpleChat*)n2); | |
15818 | 1783 break; |
15823 | 1784 case PURPLE_BLIST_BUDDY_NODE: |
1785 return purple_presence_compare(purple_buddy_get_presence((PurpleBuddy*)n1), | |
1786 purple_buddy_get_presence((PurpleBuddy*)n2)); | |
15818 | 1787 break; |
15823 | 1788 case PURPLE_BLIST_CONTACT_NODE: |
1789 s1 = purple_contact_get_alias((PurpleContact*)n1); | |
1790 s2 = purple_contact_get_alias((PurpleContact*)n2); | |
15818 | 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 | |
15823 | 1806 blist_node_compare_status(PurpleBlistNode *n1, PurpleBlistNode *n2) |
15818 | 1807 { |
1808 int ret; | |
1809 | |
1810 g_return_val_if_fail(n1->type == n2->type, -1); | |
1811 | |
1812 switch (n1->type) { | |
15823 | 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); | |
15818 | 1816 /* now compare the presence of the priority buddies */ |
15823 | 1817 case PURPLE_BLIST_BUDDY_NODE: |
1818 ret = purple_presence_compare(purple_buddy_get_presence((PurpleBuddy*)n1), | |
1819 purple_buddy_get_presence((PurpleBuddy*)n2)); | |
15818 | 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 | |
15823 | 1834 get_contact_log_size(PurpleBlistNode *c) |
15818 | 1835 { |
1836 int log = 0; | |
15823 | 1837 PurpleBlistNode *node; |
15818 | 1838 |
1839 for (node = c->child; node; node = node->next) { | |
15823 | 1840 PurpleBuddy *b = (PurpleBuddy*)node; |
1841 log += purple_log_get_total_size(PURPLE_LOG_IM, b->name, b->account); | |
15818 | 1842 } |
1843 | |
1844 return log; | |
1845 } | |
1846 | |
1847 static int | |
15823 | 1848 blist_node_compare_log(PurpleBlistNode *n1, PurpleBlistNode *n2) |
15818 | 1849 { |
1850 int ret; | |
15823 | 1851 PurpleBuddy *b1, *b2; |
15818 | 1852 |
1853 g_return_val_if_fail(n1->type == n2->type, -1); | |
1854 | |
1855 switch (n1->type) { | |
15823 | 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); | |
15818 | 1861 if (ret != 0) |
1862 return ret; | |
1863 break; | |
15823 | 1864 case PURPLE_BLIST_CONTACT_NODE: |
15818 | 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 { | |
15823 | 1888 PurplePluginAction *action = data; |
15818 | 1889 if (action && action->callback) |
1890 action->callback(action); | |
1891 } | |
1892 | |
1893 static void | |
15823 | 1894 build_plugin_actions(GntMenuItem *item, PurplePlugin *plugin, gpointer context) |
15818 | 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)); | |
15823 | 1901 for (actions = PURPLE_PLUGIN_ACTIONS(plugin, context); actions; |
15818 | 1902 actions = g_list_delete_link(actions, actions)) { |
1903 if (actions->data) { | |
15823 | 1904 PurplePluginAction *action = actions->data; |
15818 | 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", | |
15823 | 1912 action, (GDestroyNotify)purple_plugin_action_free); |
15818 | 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 | |
15823 | 1934 for (iter = purple_plugins_get_loaded(); iter; iter = iter->next) { |
1935 PurplePlugin *plugin = iter->data; | |
15818 | 1936 GntMenuItem *item; |
15823 | 1937 if (PURPLE_IS_PROTOCOL_PLUGIN(plugin)) |
15818 | 1938 continue; |
1939 | |
15823 | 1940 if (!PURPLE_PLUGIN_HAS_ACTIONS(plugin)) |
15818 | 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 | |
15823 | 1966 for (iter = purple_accounts_get_all_active(); iter; |
15818 | 1967 iter = g_list_delete_link(iter, iter)) { |
15823 | 1968 PurpleAccount *account = iter->data; |
1969 PurpleConnection *gc = purple_account_get_connection(account); | |
1970 PurplePlugin *prpl; | |
15818 | 1971 |
15823 | 1972 if (!gc || !PURPLE_CONNECTION_IS_CONNECTED(gc)) |
15818 | 1973 continue; |
1974 prpl = gc->prpl; | |
1975 | |
15823 | 1976 if (PURPLE_PLUGIN_HAS_ACTIONS(prpl)) { |
1977 item = gnt_menuitem_new(purple_account_get_username(account)); | |
15818 | 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 { | |
15823 | 1987 PurpleBlistNode *node; |
15818 | 1988 |
15823 | 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); | |
15818 | 1995 } |
1996 } | |
1997 } | |
1998 | |
1999 static void show_offline_cb(GntMenuItem *item, gpointer n) | |
2000 { | |
15823 | 2001 purple_prefs_set_bool(PREF_ROOT "/showoffline", |
2002 !purple_prefs_get_bool(PREF_ROOT "/showoffline")); | |
15818 | 2003 } |
2004 | |
2005 static void sort_blist_change_cb(GntMenuItem *item, gpointer n) | |
2006 { | |
15823 | 2007 purple_prefs_set_string(PREF_ROOT "/sort_type", n); |
15818 | 2008 } |
2009 | |
2010 /* XXX: send_im_select* -- Xerox */ | |
2011 static void | |
15823 | 2012 send_im_select_cb(gpointer data, PurpleRequestFields *fields) |
15818 | 2013 { |
15823 | 2014 PurpleAccount *account; |
15818 | 2015 const char *username; |
2016 | |
15823 | 2017 account = purple_request_fields_get_account(fields, "account"); |
2018 username = purple_request_fields_get_string(fields, "screenname"); | |
15818 | 2019 |
15823 | 2020 purple_conversation_new(PURPLE_CONV_TYPE_IM, account, username); |
15818 | 2021 } |
2022 | |
2023 static void | |
2024 send_im_select(GntMenuItem *item, gpointer n) | |
2025 { | |
15823 | 2026 PurpleRequestFields *fields; |
2027 PurpleRequestFieldGroup *group; | |
2028 PurpleRequestField *field; | |
15818 | 2029 |
15823 | 2030 fields = purple_request_fields_new(); |
15818 | 2031 |
15823 | 2032 group = purple_request_field_group_new(NULL); |
2033 purple_request_fields_add_group(fields, group); | |
15818 | 2034 |
15823 | 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); | |
15818 | 2039 |
15823 | 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); | |
15818 | 2047 |
15823 | 2048 purple_request_fields(purple_get_blist(), _("New Instant Message"), |
15818 | 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); | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
2080 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), send_im_select, NULL); |
15818 | 2081 |
2082 item = gnt_menuitem_check_new(_("Toggle offline buddies")); | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
2083 gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(item), |
15823 | 2084 purple_prefs_get_bool(PREF_ROOT "/showoffline")); |
15818 | 2085 gnt_menu_add_item(GNT_MENU(sub), item); |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
2086 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), show_offline_cb, NULL); |
15818 | 2087 |
2088 item = gnt_menuitem_new(_("Sort by status")); | |
2089 gnt_menu_add_item(GNT_MENU(sub), item); | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
2090 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), sort_blist_change_cb, "status"); |
15818 | 2091 |
2092 item = gnt_menuitem_new(_("Sort alphabetically")); | |
2093 gnt_menu_add_item(GNT_MENU(sub), item); | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
2094 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), sort_blist_change_cb, "text"); |
15818 | 2095 |
2096 item = gnt_menuitem_new(_("Sort by log size")); | |
2097 gnt_menu_add_item(GNT_MENU(sub), item); | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15871
diff
changeset
|
2098 gnt_menuitem_set_callback(GNT_MENU_ITEM(item), sort_blist_change_cb, "log"); |
15818 | 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 { | |
15823 | 2109 blist_show(purple_get_blist()); |
15818 | 2110 } |
2111 | |
2112 static void | |
16105
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15931
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:
15931
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:
15931
diff
changeset
|
2117 } |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
2118 |
1983ecd15174
Remember the collapsed state of groups in the blist
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
2119 static void |
15823 | 2120 blist_show(PurpleBuddyList *list) |
15818 | 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); | |
15823 | 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")); | |
15818 | 2140 |
2141 gnt_tree_set_col_width(GNT_TREE(ggblist->tree), 0, | |
15823 | 2142 purple_prefs_get_int(PREF_ROOT "/size/width") - 1); |
15818 | 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 | |
15823 | 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); | |
15818 | 2161 |
15823 | 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); | |
15818 | 2166 |
2167 #if 0 | |
15823 | 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); | |
15818 | 2172 |
2173 /* These I plan to use to indicate unread-messages etc. */ | |
15823 | 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); | |
15818 | 2178 |
15823 | 2179 purple_signal_connect(purple_conversations_get_handle(), "received-chat-msg", finch_blist_get_handle(), |
2180 PURPLE_CALLBACK(received_chat_msg), list); | |
15818 | 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:
15931
diff
changeset
|
2186 g_signal_connect(G_OBJECT(ggblist->tree), "collapse-toggled", G_CALLBACK(group_collapsed), NULL); |
15818 | 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 */ | |
15823 | 2198 purple_signal_connect(purple_savedstatuses_get_handle(), "savedstatus-changed", finch_blist_get_handle(), |
2199 PURPLE_CALLBACK(savedstatus_changed), NULL); | |
15818 | 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 | |
15823 | 2209 savedstatus_changed(purple_savedstatus_get_current(), NULL); |
15818 | 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 |