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