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