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