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