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