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