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