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