Mercurial > pidgin
annotate src/blist.c @ 10007:267a2b69e36e
[gaim-migrate @ 10924]
Better i18nability and more uniform code?
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 10 Sep 2004 04:30:37 +0000 |
parents | 4d2269c6c673 |
children | e6e68b9db19b |
rev | line source |
---|---|
5228 | 1 /* |
2 * gaim | |
3 * | |
8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
5228 | 7 * |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 * | |
22 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
23 #include "internal.h" |
5228 | 24 #include "blist.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
25 #include "conversation.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
26 #include "debug.h" |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
27 #include "notify.h" |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
28 #include "prefs.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
29 #include "privacy.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
30 #include "prpl.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
31 #include "server.h" |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
32 #include "signals.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
33 #include "util.h" |
7132 | 34 #include "xmlnode.h" |
5228 | 35 |
36 #define PATHSIZE 1024 | |
37 | |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
38 GaimBuddyList *gaimbuddylist = NULL; |
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
39 static GaimBlistUiOps *blist_ui_ops = NULL; |
9285 | 40 static guint blist_save_timer = 0; |
5228 | 41 |
7693 | 42 struct gaim_blist_node_setting { |
43 enum { | |
44 GAIM_BLIST_NODE_SETTING_BOOL, | |
45 GAIM_BLIST_NODE_SETTING_INT, | |
46 GAIM_BLIST_NODE_SETTING_STRING | |
47 } type; | |
48 union { | |
49 gboolean boolean; | |
50 int integer; | |
51 char *string; | |
52 } value; | |
53 }; | |
54 | |
55 | |
6846
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
56 |
5228 | 57 /***************************************************************************** |
58 * Private Utility functions * | |
59 *****************************************************************************/ | |
60 static GaimBlistNode *gaim_blist_get_last_sibling(GaimBlistNode *node) | |
61 { | |
62 GaimBlistNode *n = node; | |
63 if (!n) | |
64 return NULL; | |
65 while (n->next) | |
66 n = n->next; | |
67 return n; | |
68 } | |
6695 | 69 |
5228 | 70 static GaimBlistNode *gaim_blist_get_last_child(GaimBlistNode *node) |
71 { | |
72 if (!node) | |
73 return NULL; | |
74 return gaim_blist_get_last_sibling(node->child); | |
75 } | |
76 | |
5247 | 77 struct _gaim_hbuddy { |
78 char *name; | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
79 GaimAccount *account; |
5758 | 80 GaimBlistNode *group; |
5247 | 81 }; |
82 | |
9285 | 83 static guint _gaim_blist_hbuddy_hash(struct _gaim_hbuddy *hb) |
5247 | 84 { |
85 return g_str_hash(hb->name); | |
86 } | |
87 | |
9285 | 88 static guint _gaim_blist_hbuddy_equal(struct _gaim_hbuddy *hb1, struct _gaim_hbuddy *hb2) |
5247 | 89 { |
5758 | 90 return ((!strcmp(hb1->name, hb2->name)) && hb1->account == hb2->account && hb1->group == hb2->group); |
5247 | 91 } |
92 | |
6742 | 93 static void _gaim_blist_hbuddy_free_key(struct _gaim_hbuddy *hb) |
94 { | |
95 g_free(hb->name); | |
96 g_free(hb); | |
97 } | |
98 | |
9285 | 99 static void blist_pref_cb(const char *name, GaimPrefType type, gpointer value, gpointer data) |
6006 | 100 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
101 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
6695 | 102 GaimBlistNode *gnode, *cnode, *bnode; |
6012 | 103 |
9285 | 104 if (!ops || !ops->update) |
6012 | 105 return; |
106 | |
9285 | 107 for (gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { |
108 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
6012 | 109 continue; |
9285 | 110 for (cnode = gnode->child; cnode; cnode = cnode->next) { |
111 if (GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
112 for (bnode = cnode->child; bnode; bnode = bnode->next) { | |
113 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
6695 | 114 continue; |
115 ops->update(gaimbuddylist, bnode); | |
116 } | |
9285 | 117 } else if (GAIM_BLIST_NODE_IS_CHAT(cnode)) { |
6695 | 118 ops->update(gaimbuddylist, cnode); |
119 } | |
6012 | 120 } |
121 } | |
6006 | 122 } |
123 | |
9949 | 124 void gaim_contact_compute_priority_buddy(GaimContact *contact) |
6843 | 125 { |
126 GaimBlistNode *bnode; | |
9949 | 127 GaimBuddy *new_priority = NULL; |
9285 | 128 |
129 g_return_if_fail(contact != NULL); | |
130 | |
6870 | 131 contact->priority = NULL; |
9949 | 132 for (bnode = ((GaimBlistNode*)contact)->child; |
133 bnode != NULL; | |
134 bnode = bnode->next) | |
135 { | |
6843 | 136 GaimBuddy *buddy; |
9949 | 137 GaimPresence *presence; |
7420 | 138 |
9285 | 139 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode)) |
6843 | 140 continue; |
9949 | 141 |
6843 | 142 buddy = (GaimBuddy*)bnode; |
9949 | 143 |
9285 | 144 if (!gaim_account_is_connected(buddy->account)) |
6843 | 145 continue; |
9949 | 146 if (new_priority == NULL) |
147 new_priority = buddy; | |
148 else | |
149 { | |
150 int cmp; | |
151 | |
152 presence = gaim_buddy_get_presence(buddy); | |
153 | |
154 cmp = gaim_presence_compare(gaim_buddy_get_presence(new_priority), | |
155 gaim_buddy_get_presence(buddy)); | |
156 | |
157 if (cmp > 0 || (cmp == 0 && | |
158 gaim_prefs_get_bool("/core/contact/last_match"))) | |
159 { | |
160 new_priority = buddy; | |
161 } | |
162 } | |
6843 | 163 } |
9949 | 164 |
165 contact->priority = new_priority; | |
6843 | 166 } |
167 | |
9285 | 168 static gboolean blist_save_callback(gpointer data) |
169 { | |
170 gaim_blist_sync(); | |
171 blist_save_timer = 0; | |
172 return FALSE; | |
173 } | |
174 | |
9741 | 175 static void schedule_blist_save() |
9285 | 176 { |
177 if (blist_save_timer != 0) | |
178 gaim_timeout_remove(blist_save_timer); | |
179 blist_save_timer = gaim_timeout_add(1000, blist_save_callback, NULL); | |
180 } | |
181 | |
6843 | 182 |
5228 | 183 /***************************************************************************** |
184 * Public API functions * | |
185 *****************************************************************************/ | |
186 | |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
187 GaimBuddyList *gaim_blist_new() |
5228 | 188 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
189 GaimBuddyList *gbl = g_new0(GaimBuddyList, 1); |
5228 | 190 |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
191 gbl->ui_ops = gaim_blist_get_ui_ops(); |
5228 | 192 |
6742 | 193 gbl->buddies = g_hash_table_new_full((GHashFunc)_gaim_blist_hbuddy_hash, |
194 (GEqualFunc)_gaim_blist_hbuddy_equal, | |
195 (GDestroyNotify)_gaim_blist_hbuddy_free_key, NULL); | |
5247 | 196 |
5228 | 197 if (gbl->ui_ops != NULL && gbl->ui_ops->new_list != NULL) |
198 gbl->ui_ops->new_list(gbl); | |
199 | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
200 gaim_prefs_connect_callback("/core/buddies/use_server_alias", |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
201 blist_pref_cb, NULL); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
202 |
5228 | 203 return gbl; |
204 } | |
205 | |
206 void | |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
207 gaim_set_blist(GaimBuddyList *list) |
5228 | 208 { |
209 gaimbuddylist = list; | |
210 } | |
211 | |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
212 GaimBuddyList * |
9285 | 213 gaim_get_blist() |
5228 | 214 { |
215 return gaimbuddylist; | |
216 } | |
217 | |
9285 | 218 void gaim_blist_show() |
5228 | 219 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
220 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
9285 | 221 |
222 if (ops && ops->show) | |
5228 | 223 ops->show(gaimbuddylist); |
224 } | |
225 | |
226 void gaim_blist_destroy() | |
227 { | |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
228 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
9285 | 229 |
8259
4f9f68ab8770
[gaim-migrate @ 8982]
Christian Hammond <chipx86@chipx86.com>
parents:
8200
diff
changeset
|
230 gaim_debug(GAIM_DEBUG_INFO, "blist", "Destroying\n"); |
9285 | 231 |
232 if (ops && ops->destroy) | |
5228 | 233 ops->destroy(gaimbuddylist); |
234 } | |
235 | |
9285 | 236 void gaim_blist_set_visible(gboolean show) |
5228 | 237 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
238 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
9285 | 239 |
240 if (ops && ops->set_visible) | |
5228 | 241 ops->set_visible(gaimbuddylist, show); |
242 } | |
243 | |
9285 | 244 void gaim_blist_update_buddy_status(GaimBuddy *buddy, int status) |
5228 | 245 { |
9949 | 246 #if 0 |
9285 | 247 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
248 int old_status; | |
249 | |
250 g_return_if_fail(buddy != NULL); | |
251 | |
252 old_status = buddy->uc; | |
8129
52cdf2740654
[gaim-migrate @ 8834]
Christian Hammond <chipx86@chipx86.com>
parents:
8071
diff
changeset
|
253 if (old_status != status) { |
52cdf2740654
[gaim-migrate @ 8834]
Christian Hammond <chipx86@chipx86.com>
parents:
8071
diff
changeset
|
254 buddy->uc = status; |
52cdf2740654
[gaim-migrate @ 8834]
Christian Hammond <chipx86@chipx86.com>
parents:
8071
diff
changeset
|
255 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); |
52cdf2740654
[gaim-migrate @ 8834]
Christian Hammond <chipx86@chipx86.com>
parents:
8071
diff
changeset
|
256 |
52cdf2740654
[gaim-migrate @ 8834]
Christian Hammond <chipx86@chipx86.com>
parents:
8071
diff
changeset
|
257 if ((status & UC_UNAVAILABLE) != (old_status & UC_UNAVAILABLE)) { |
7549 | 258 if (status & UC_UNAVAILABLE) |
259 gaim_signal_emit(gaim_blist_get_handle(), "buddy-away", buddy); | |
260 else | |
261 gaim_signal_emit(gaim_blist_get_handle(), "buddy-back", buddy); | |
262 } | |
5305 | 263 } |
8129
52cdf2740654
[gaim-migrate @ 8834]
Christian Hammond <chipx86@chipx86.com>
parents:
8071
diff
changeset
|
264 |
9285 | 265 if (ops && ops->update) |
5228 | 266 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); |
9949 | 267 #endif |
5228 | 268 } |
269 | |
9285 | 270 static gboolean presence_update_timeout_cb(GaimBuddy *buddy) |
271 { | |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
272 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
6640
314111e7b601
[gaim-migrate @ 7165]
Christian Hammond <chipx86@chipx86.com>
parents:
6564
diff
changeset
|
273 GaimConversation *conv; |
314111e7b601
[gaim-migrate @ 7165]
Christian Hammond <chipx86@chipx86.com>
parents:
6564
diff
changeset
|
274 |
9285 | 275 g_return_val_if_fail(buddy != NULL, FALSE); |
276 | |
277 if (buddy->present == GAIM_BUDDY_SIGNING_ON) { | |
5228 | 278 buddy->present = GAIM_BUDDY_ONLINE; |
9285 | 279 } else if (buddy->present == GAIM_BUDDY_SIGNING_OFF) { |
5228 | 280 buddy->present = GAIM_BUDDY_OFFLINE; |
6860 | 281 ((GaimContact*)((GaimBlistNode*)buddy)->parent)->online--; |
9285 | 282 if (((GaimContact*)((GaimBlistNode*)buddy)->parent)->online == 0) |
6860 | 283 ((GaimGroup *)((GaimBlistNode *)buddy)->parent->parent)->online--; |
5228 | 284 } |
285 | |
286 buddy->timer = 0; | |
287 | |
9285 | 288 if (ops && ops->update) |
5228 | 289 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); |
290 | |
9285 | 291 conv = gaim_find_conversation_with_account(buddy->name, buddy->account); |
6392
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
292 if (conv) { |
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
293 if (buddy->present == GAIM_BUDDY_ONLINE) |
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
294 gaim_conversation_update(conv, GAIM_CONV_ACCOUNT_ONLINE); |
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
295 else if (buddy->present == GAIM_BUDDY_OFFLINE) |
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
296 gaim_conversation_update(conv, GAIM_CONV_ACCOUNT_OFFLINE); |
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
297 } |
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
298 |
5228 | 299 return FALSE; |
300 } | |
301 | |
9927 | 302 void gaim_blist_update_buddy_presence(GaimBuddy *buddy, gboolean online) |
9285 | 303 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
304 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
9285 | 305 gboolean did_something = FALSE; |
306 | |
307 g_return_if_fail(buddy != NULL); | |
5228 | 308 |
9927 | 309 if (!GAIM_BUDDY_IS_ONLINE(buddy) && online) { |
6901 | 310 int old_present = buddy->present; |
5228 | 311 buddy->present = GAIM_BUDDY_SIGNING_ON; |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
312 gaim_signal_emit(gaim_blist_get_handle(), "buddy-signed-on", buddy); |
9285 | 313 did_something = TRUE; |
314 | |
315 if (old_present != GAIM_BUDDY_SIGNING_OFF) { | |
6901 | 316 ((GaimContact*)((GaimBlistNode*)buddy)->parent)->online++; |
9285 | 317 if (((GaimContact*)((GaimBlistNode*)buddy)->parent)->online == 1) |
6901 | 318 ((GaimGroup *)((GaimBlistNode *)buddy)->parent->parent)->online++; |
319 } | |
9927 | 320 } else if (GAIM_BUDDY_IS_ONLINE(buddy) && !online) { |
5228 | 321 buddy->present = GAIM_BUDDY_SIGNING_OFF; |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
322 gaim_signal_emit(gaim_blist_get_handle(), "buddy-signed-off", buddy); |
9285 | 323 did_something = TRUE; |
5228 | 324 } |
325 | |
9285 | 326 if (did_something) { |
327 if (buddy->timer > 0) | |
8287
ef881489396e
[gaim-migrate @ 9011]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
328 gaim_timeout_remove(buddy->timer); |
8273
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8259
diff
changeset
|
329 buddy->timer = gaim_timeout_add(10000, (GSourceFunc)presence_update_timeout_cb, buddy); |
6961 | 330 |
331 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); | |
9285 | 332 if (ops && ops->update) |
333 ops->update(gaimbuddylist, (GaimBlistNode *)buddy); | |
5228 | 334 } |
335 } | |
336 | |
9285 | 337 void gaim_blist_update_buddy_signon(GaimBuddy *buddy, time_t signon) |
7950 | 338 { |
339 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; | |
9285 | 340 |
341 g_return_if_fail(buddy != NULL); | |
342 | |
343 if (buddy->signon == signon) | |
7950 | 344 return; |
345 | |
346 buddy->signon = signon; | |
9285 | 347 |
348 if (ops && ops->update) | |
349 ops->update(gaimbuddylist, (GaimBlistNode *)buddy); | |
7950 | 350 } |
5228 | 351 |
9285 | 352 void gaim_blist_update_buddy_icon(GaimBuddy *buddy) |
5228 | 353 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
354 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
9285 | 355 |
356 g_return_if_fail(buddy != NULL); | |
357 | |
358 if (ops && ops->update) | |
359 ops->update(gaimbuddylist, (GaimBlistNode *)buddy); | |
360 } | |
361 | |
362 /* | |
363 * XXX - Maybe remove the call to this from server.c and call it | |
364 * from oscar.c and toc.c instead? | |
365 */ | |
366 void gaim_blist_rename_buddy(GaimBuddy *buddy, const char *name) | |
367 { | |
368 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; | |
369 struct _gaim_hbuddy *hb; | |
370 | |
371 g_return_if_fail(buddy != NULL); | |
372 | |
373 hb = g_new(struct _gaim_hbuddy, 1); | |
8675 | 374 hb->name = g_strdup(gaim_normalize(buddy->account, buddy->name)); |
375 hb->account = buddy->account; | |
376 hb->group = ((GaimBlistNode *)buddy)->parent->parent; | |
377 g_hash_table_remove(gaimbuddylist->buddies, hb); | |
378 | |
379 g_free(hb->name); | |
380 hb->name = g_strdup(gaim_normalize(buddy->account, name)); | |
381 g_hash_table_replace(gaimbuddylist->buddies, hb, buddy); | |
382 | |
5634 | 383 g_free(buddy->name); |
5228 | 384 buddy->name = g_strdup(name); |
9285 | 385 |
386 schedule_blist_save(); | |
387 | |
388 if (ops && ops->update) | |
389 ops->update(gaimbuddylist, (GaimBlistNode *)buddy); | |
5228 | 390 } |
5234 | 391 |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
392 void gaim_blist_alias_chat(GaimChat *chat, const char *alias) |
5234 | 393 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
394 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
5234 | 395 |
9285 | 396 g_return_if_fail(chat != NULL); |
397 | |
5237 | 398 g_free(chat->alias); |
9285 | 399 if ((alias != NULL) && (*alias != '\0')) |
5237 | 400 chat->alias = g_strdup(alias); |
401 else | |
402 chat->alias = NULL; | |
403 | |
9285 | 404 schedule_blist_save(); |
405 | |
406 if (ops && ops->update) | |
407 ops->update(gaimbuddylist, (GaimBlistNode *)chat); | |
5234 | 408 } |
409 | |
9285 | 410 void gaim_blist_alias_buddy(GaimBuddy *buddy, const char *alias) |
5228 | 411 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
412 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5634
diff
changeset
|
413 GaimConversation *conv; |
5228 | 414 |
9285 | 415 g_return_if_fail(buddy != NULL); |
416 | |
5228 | 417 g_free(buddy->alias); |
9285 | 418 if ((alias != NULL) && (*alias != '\0')) |
5228 | 419 buddy->alias = g_strdup(alias); |
420 else | |
421 buddy->alias = NULL; | |
422 | |
9285 | 423 schedule_blist_save(); |
424 | |
425 if (ops && ops->update) | |
426 ops->update(gaimbuddylist, (GaimBlistNode *)buddy); | |
5228 | 427 |
428 conv = gaim_find_conversation_with_account(buddy->name, buddy->account); | |
429 if (conv) | |
430 gaim_conversation_autoset_title(conv); | |
431 } | |
432 | |
9285 | 433 void gaim_blist_server_alias_buddy(GaimBuddy *buddy, const char *alias) |
6058 | 434 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
435 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
6058 | 436 GaimConversation *conv; |
437 | |
9285 | 438 g_return_if_fail(buddy != NULL); |
439 | |
6058 | 440 g_free(buddy->server_alias); |
9285 | 441 if ((alias != NULL) && (*alias != '\0') && g_utf8_validate(alias, -1, NULL)) |
6058 | 442 buddy->server_alias = g_strdup(alias); |
443 else | |
444 buddy->server_alias = NULL; | |
445 | |
9285 | 446 schedule_blist_save(); |
447 | |
448 if (ops && ops->update) | |
449 ops->update(gaimbuddylist, (GaimBlistNode *)buddy); | |
6058 | 450 |
451 conv = gaim_find_conversation_with_account(buddy->name, buddy->account); | |
452 if (conv) | |
453 gaim_conversation_autoset_title(conv); | |
454 } | |
455 | |
9285 | 456 /* |
457 * XXX - If merging, prompt the user if they want to merge. | |
458 */ | |
459 void gaim_blist_rename_group(GaimGroup *source, const char *new_name) | |
5228 | 460 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
461 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
9285 | 462 GaimGroup *dest; |
463 gchar *old_name; | |
464 GList *moved_buddies = NULL; | |
5346 | 465 GSList *accts; |
466 | |
9285 | 467 g_return_if_fail(source != NULL); |
468 g_return_if_fail(new_name != NULL); | |
469 | |
470 if (*new_name == '\0' || !strcmp(new_name, source->name)) | |
5346 | 471 return; |
9285 | 472 |
473 dest = gaim_find_group(new_name); | |
474 if (dest != NULL) { | |
475 /* We're merging two groups */ | |
476 GaimBlistNode *prev, *child, *next; | |
477 | |
478 prev = gaim_blist_get_last_child((GaimBlistNode*)dest); | |
479 child = ((GaimBlistNode*)source)->child; | |
480 | |
481 /* | |
482 * XXX - This seems like a dumb way to do this... why not just | |
483 * append all children from the old group to the end of the new | |
484 * one? PRPLs might be expecting to receive an add_buddy() for | |
485 * each moved buddy... | |
486 */ | |
487 while (child) | |
5346 | 488 { |
489 next = child->next; | |
9285 | 490 if (GAIM_BLIST_NODE_IS_CONTACT(child)) { |
6695 | 491 GaimBlistNode *bnode; |
9285 | 492 gaim_blist_add_contact((GaimContact *)child, dest, prev); |
493 for (bnode = child->child; bnode != NULL; bnode = bnode->next) { | |
494 gaim_blist_add_buddy((GaimBuddy *)bnode, (GaimContact *)child, | |
6695 | 495 NULL, bnode->prev); |
9285 | 496 moved_buddies = g_list_append(moved_buddies, bnode); |
497 } | |
5346 | 498 prev = child; |
9285 | 499 } else if (GAIM_BLIST_NODE_IS_CHAT(child)) { |
500 gaim_blist_add_chat((GaimChat *)child, dest, prev); | |
5346 | 501 prev = child; |
502 } else { | |
503 gaim_debug(GAIM_DEBUG_ERROR, "blist", | |
9285 | 504 "Unknown child type in group %s\n", source->name); |
5346 | 505 } |
506 child = next; | |
507 } | |
9285 | 508 |
509 /* Make a copy of the old group name and then delete the old group */ | |
510 old_name = g_strdup(source->name); | |
511 gaim_blist_remove_group(source); | |
5346 | 512 } else { |
9285 | 513 /* A simple rename */ |
514 GaimBlistNode *cnode, *bnode; | |
515 | |
516 /* Build a GList of all buddies in this group */ | |
517 for (cnode = ((GaimBlistNode *)source)->child; cnode != NULL; cnode = cnode->next) { | |
518 if (GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
519 for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) | |
520 moved_buddies = g_list_append(moved_buddies, bnode); | |
5346 | 521 } |
9285 | 522 |
523 old_name = source->name; | |
524 source->name = g_strdup(new_name); | |
525 | |
5346 | 526 } |
9285 | 527 |
528 /* Save our changes */ | |
529 schedule_blist_save(); | |
530 | |
531 /* Update the UI */ | |
532 if (ops && ops->update) | |
533 ops->update(gaimbuddylist, (GaimBlistNode*)source); | |
534 | |
535 /* Notify all PRPLs */ | |
536 for (accts = gaim_group_get_accounts(source); accts; accts = g_slist_remove(accts, accts->data)) { | |
537 GaimAccount *account = accts->data; | |
538 serv_rename_group(account->gc, old_name, source, moved_buddies); | |
539 } | |
540 g_list_free(moved_buddies); | |
541 g_free(old_name); | |
5228 | 542 } |
5234 | 543 |
9285 | 544 static void gaim_blist_node_initialize_settings(GaimBlistNode *node); |
7693 | 545 |
7125 | 546 GaimChat *gaim_chat_new(GaimAccount *account, const char *alias, GHashTable *components) |
5234 | 547 { |
9285 | 548 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
549 GaimChat *chat; |
9285 | 550 |
551 g_return_val_if_fail(account != NULL, FALSE); | |
552 g_return_val_if_fail(components != NULL, FALSE); | |
5234 | 553 |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
554 chat = g_new0(GaimChat, 1); |
5234 | 555 chat->account = account; |
9285 | 556 if ((alias != NULL) && (*alias != '\0')) |
5237 | 557 chat->alias = g_strdup(alias); |
5234 | 558 chat->components = components; |
9285 | 559 gaim_blist_node_initialize_settings((GaimBlistNode *)chat); |
560 ((GaimBlistNode *)chat)->type = GAIM_BLIST_CHAT_NODE; | |
5234 | 561 |
562 if (ops != NULL && ops->new_node != NULL) | |
563 ops->new_node((GaimBlistNode *)chat); | |
564 | |
565 return chat; | |
566 } | |
567 | |
7125 | 568 char *gaim_chat_get_display_name(GaimChat *chat) |
6034 | 569 { |
570 char *name; | |
571 | |
9285 | 572 g_return_val_if_fail(chat != NULL, FALSE); |
573 | |
574 if (chat->alias != NULL) { | |
6034 | 575 name = g_strdup(chat->alias); |
9285 | 576 } else { |
6034 | 577 GList *parts; |
578 GaimPlugin *prpl; | |
579 GaimPluginProtocolInfo *prpl_info; | |
580 struct proto_chat_entry *pce; | |
581 | |
7956 | 582 prpl = gaim_find_prpl(gaim_account_get_protocol_id(chat->account)); |
6034 | 583 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
584 | |
585 parts = prpl_info->chat_info(chat->account->gc); | |
586 | |
587 pce = parts->data; | |
588 name = g_markup_escape_text(g_hash_table_lookup(chat->components, | |
589 pce->identifier), -1); | |
590 g_list_free(parts); | |
591 } | |
592 | |
593 return name; | |
594 } | |
595 | |
6695 | 596 GaimBuddy *gaim_buddy_new(GaimAccount *account, const char *screenname, const char *alias) |
5228 | 597 { |
9285 | 598 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
599 GaimBuddy *buddy; | |
600 | |
601 g_return_val_if_fail(account != NULL, FALSE); | |
602 g_return_val_if_fail(screenname != NULL, FALSE); | |
603 | |
604 buddy = g_new0(GaimBuddy, 1); | |
9949 | 605 buddy->account = account; |
606 buddy->name = g_strdup(screenname); | |
607 buddy->alias = g_strdup(alias); | |
608 buddy->presence = gaim_presence_new_for_buddy(buddy); | |
609 | |
9285 | 610 gaim_blist_node_initialize_settings((GaimBlistNode *)buddy); |
611 ((GaimBlistNode *)buddy)->type = GAIM_BLIST_BUDDY_NODE; | |
612 | |
613 if (ops && ops->new_node) | |
614 ops->new_node((GaimBlistNode *)buddy); | |
615 | |
616 return buddy; | |
5228 | 617 } |
5634 | 618 |
6846
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
619 void |
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
620 gaim_buddy_set_icon(GaimBuddy *buddy, GaimBuddyIcon *icon) |
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
621 { |
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
622 g_return_if_fail(buddy != NULL); |
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
623 |
9261
77fdeb4c459f
[gaim-migrate @ 10060]
Christian Hammond <chipx86@chipx86.com>
parents:
9153
diff
changeset
|
624 if (buddy->icon != icon) |
77fdeb4c459f
[gaim-migrate @ 10060]
Christian Hammond <chipx86@chipx86.com>
parents:
9153
diff
changeset
|
625 { |
77fdeb4c459f
[gaim-migrate @ 10060]
Christian Hammond <chipx86@chipx86.com>
parents:
9153
diff
changeset
|
626 if (buddy->icon != NULL) |
77fdeb4c459f
[gaim-migrate @ 10060]
Christian Hammond <chipx86@chipx86.com>
parents:
9153
diff
changeset
|
627 gaim_buddy_icon_unref(buddy->icon); |
77fdeb4c459f
[gaim-migrate @ 10060]
Christian Hammond <chipx86@chipx86.com>
parents:
9153
diff
changeset
|
628 |
77fdeb4c459f
[gaim-migrate @ 10060]
Christian Hammond <chipx86@chipx86.com>
parents:
9153
diff
changeset
|
629 buddy->icon = (icon == NULL ? NULL : gaim_buddy_icon_ref(icon)); |
77fdeb4c459f
[gaim-migrate @ 10060]
Christian Hammond <chipx86@chipx86.com>
parents:
9153
diff
changeset
|
630 } |
6846
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
631 |
9324 | 632 if (buddy->icon) |
633 gaim_buddy_icon_cache(icon, buddy); | |
634 else | |
635 gaim_blist_node_remove_setting((GaimBlistNode *)buddy, "buddy_icon"); | |
9299 | 636 |
637 schedule_blist_save(); | |
9926 | 638 |
6846
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
639 gaim_blist_update_buddy_icon(buddy); |
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
640 } |
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
641 |
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
642 GaimBuddyIcon * |
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
643 gaim_buddy_get_icon(const GaimBuddy *buddy) |
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
644 { |
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
645 g_return_val_if_fail(buddy != NULL, NULL); |
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
646 |
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
647 return buddy->icon; |
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
648 } |
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
649 |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
650 void gaim_blist_add_chat(GaimChat *chat, GaimGroup *group, GaimBlistNode *node) |
5234 | 651 { |
9285 | 652 GaimBlistNode *cnode = (GaimBlistNode*)chat; |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
653 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
6774 | 654 |
655 g_return_if_fail(chat != NULL); | |
9285 | 656 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT((GaimBlistNode *)chat)); |
657 | |
658 if (node == NULL) { | |
659 if (group == NULL) { | |
660 group = gaim_group_new(_("Chats")); | |
661 gaim_blist_add_group(group, | |
5634 | 662 gaim_blist_get_last_sibling(gaimbuddylist->root)); |
5234 | 663 } |
664 } else { | |
9285 | 665 group = (GaimGroup*)node->parent; |
5234 | 666 } |
667 | |
668 /* if we're moving to overtop of ourselves, do nothing */ | |
9285 | 669 if (cnode == node) |
5234 | 670 return; |
671 | |
672 if (cnode->parent) { | |
673 /* This chat was already in the list and is | |
674 * being moved. | |
675 */ | |
6695 | 676 ((GaimGroup *)cnode->parent)->totalsize--; |
5855 | 677 if (gaim_account_is_connected(chat->account)) { |
6695 | 678 ((GaimGroup *)cnode->parent)->online--; |
679 ((GaimGroup *)cnode->parent)->currentsize--; | |
5287 | 680 } |
9285 | 681 if (cnode->next) |
5234 | 682 cnode->next->prev = cnode->prev; |
9285 | 683 if (cnode->prev) |
5234 | 684 cnode->prev->next = cnode->next; |
9285 | 685 if (cnode->parent->child == cnode) |
5234 | 686 cnode->parent->child = cnode->next; |
687 | |
688 ops->remove(gaimbuddylist, cnode); | |
689 | |
9285 | 690 schedule_blist_save(); |
5234 | 691 } |
692 | |
9285 | 693 if (node != NULL) { |
694 if (node->next) | |
695 node->next->prev = cnode; | |
696 cnode->next = node->next; | |
697 cnode->prev = node; | |
698 cnode->parent = node->parent; | |
699 node->next = cnode; | |
700 ((GaimGroup *)node->parent)->totalsize++; | |
5855 | 701 if (gaim_account_is_connected(chat->account)) { |
9285 | 702 ((GaimGroup *)node->parent)->online++; |
703 ((GaimGroup *)node->parent)->currentsize++; | |
5287 | 704 } |
5234 | 705 } else { |
9285 | 706 if (((GaimBlistNode *)group)->child) |
707 ((GaimBlistNode *)group)->child->prev = cnode; | |
708 cnode->next = ((GaimBlistNode *)group)->child; | |
5634 | 709 cnode->prev = NULL; |
9285 | 710 ((GaimBlistNode *)group)->child = cnode; |
711 cnode->parent = (GaimBlistNode *)group; | |
712 group->totalsize++; | |
5855 | 713 if (gaim_account_is_connected(chat->account)) { |
9285 | 714 group->online++; |
715 group->currentsize++; | |
5287 | 716 } |
5234 | 717 } |
718 | |
9285 | 719 schedule_blist_save(); |
720 | |
721 if (ops && ops->update) | |
722 ops->update(gaimbuddylist, (GaimBlistNode *)cnode); | |
5234 | 723 } |
724 | |
7879 | 725 void gaim_blist_add_buddy(GaimBuddy *buddy, GaimContact *contact, GaimGroup *group, GaimBlistNode *node) |
5228 | 726 { |
6695 | 727 GaimBlistNode *cnode, *bnode; |
728 GaimGroup *g; | |
729 GaimContact *c; | |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
730 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
5247 | 731 struct _gaim_hbuddy *hb; |
6695 | 732 |
733 g_return_if_fail(buddy != NULL); | |
6774 | 734 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY((GaimBlistNode*)buddy)); |
6695 | 735 |
736 bnode = (GaimBlistNode *)buddy; | |
5228 | 737 |
6695 | 738 /* if we're moving to overtop of ourselves, do nothing */ |
9285 | 739 if (bnode == node || (!node && bnode->parent && |
6695 | 740 contact && bnode->parent == (GaimBlistNode*)contact |
741 && bnode == bnode->parent->child)) | |
742 return; | |
743 | |
9285 | 744 if (node && GAIM_BLIST_NODE_IS_BUDDY(node)) { |
6695 | 745 c = (GaimContact*)node->parent; |
746 g = (GaimGroup*)node->parent->parent; | |
9285 | 747 } else if (contact) { |
6695 | 748 c = contact; |
9285 | 749 g = (GaimGroup *)((GaimBlistNode *)c)->parent; |
750 } else { | |
751 if (group) { | |
6695 | 752 g = group; |
753 } else { | |
5228 | 754 g = gaim_group_new(_("Buddies")); |
5634 | 755 gaim_blist_add_group(g, |
756 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
5228 | 757 } |
6695 | 758 c = gaim_contact_new(); |
759 gaim_blist_add_contact(c, g, | |
760 gaim_blist_get_last_child((GaimBlistNode*)g)); | |
5228 | 761 } |
762 | |
6695 | 763 cnode = (GaimBlistNode *)c; |
5228 | 764 |
9285 | 765 if (bnode->parent) { |
766 if (GAIM_BUDDY_IS_ONLINE(buddy)) { | |
6695 | 767 ((GaimContact*)bnode->parent)->online--; |
9285 | 768 if (((GaimContact*)bnode->parent)->online == 0) |
6695 | 769 ((GaimGroup*)bnode->parent->parent)->online--; |
770 } | |
9285 | 771 if (gaim_account_is_connected(buddy->account)) { |
6695 | 772 ((GaimContact*)bnode->parent)->currentsize--; |
9285 | 773 if (((GaimContact*)bnode->parent)->currentsize == 0) |
6695 | 774 ((GaimGroup*)bnode->parent->parent)->currentsize--; |
775 } | |
776 ((GaimContact*)bnode->parent)->totalsize--; | |
777 /* the group totalsize will be taken care of by remove_contact below */ | |
778 | |
9285 | 779 if (bnode->parent->parent != (GaimBlistNode*)g) |
6695 | 780 serv_move_buddy(buddy, (GaimGroup *)bnode->parent->parent, g); |
5277 | 781 |
9285 | 782 if (bnode->next) |
5228 | 783 bnode->next->prev = bnode->prev; |
9285 | 784 if (bnode->prev) |
5228 | 785 bnode->prev->next = bnode->next; |
9285 | 786 if (bnode->parent->child == bnode) |
5228 | 787 bnode->parent->child = bnode->next; |
788 | |
789 ops->remove(gaimbuddylist, bnode); | |
790 | |
9285 | 791 schedule_blist_save(); |
792 | |
793 if (bnode->parent->parent != (GaimBlistNode*)g) { | |
6742 | 794 hb = g_new(struct _gaim_hbuddy, 1); |
7261 | 795 hb->name = g_strdup(gaim_normalize(buddy->account, buddy->name)); |
6742 | 796 hb->account = buddy->account; |
797 hb->group = bnode->parent->parent; | |
6775 | 798 g_hash_table_remove(gaimbuddylist->buddies, hb); |
7162 | 799 g_free(hb->name); |
6742 | 800 g_free(hb); |
801 } | |
6794 | 802 |
9285 | 803 if (!bnode->parent->child) { |
6794 | 804 gaim_blist_remove_contact((GaimContact*)bnode->parent); |
7003 | 805 } else { |
806 gaim_contact_compute_priority_buddy((GaimContact*)bnode->parent); | |
807 ops->update(gaimbuddylist, bnode->parent); | |
808 } | |
5228 | 809 } |
810 | |
9285 | 811 if (node && GAIM_BLIST_NODE_IS_BUDDY(node)) { |
812 if (node->next) | |
6695 | 813 node->next->prev = bnode; |
814 bnode->next = node->next; | |
815 bnode->prev = node; | |
816 bnode->parent = node->parent; | |
817 node->next = bnode; | |
5228 | 818 } else { |
9285 | 819 if (cnode->child) |
6695 | 820 cnode->child->prev = bnode; |
821 bnode->prev = NULL; | |
822 bnode->next = cnode->child; | |
823 cnode->child = bnode; | |
824 bnode->parent = cnode; | |
5228 | 825 } |
826 | |
9285 | 827 if (GAIM_BUDDY_IS_ONLINE(buddy)) { |
6695 | 828 ((GaimContact*)bnode->parent)->online++; |
9285 | 829 if (((GaimContact*)bnode->parent)->online == 1) |
6695 | 830 ((GaimGroup*)bnode->parent->parent)->online++; |
831 } | |
9285 | 832 if (gaim_account_is_connected(buddy->account)) { |
6695 | 833 ((GaimContact*)bnode->parent)->currentsize++; |
9285 | 834 if (((GaimContact*)bnode->parent)->currentsize == 1) |
6695 | 835 ((GaimGroup*)bnode->parent->parent)->currentsize++; |
836 } | |
837 ((GaimContact*)bnode->parent)->totalsize++; | |
838 | |
6742 | 839 hb = g_new(struct _gaim_hbuddy, 1); |
7261 | 840 hb->name = g_strdup(gaim_normalize(buddy->account, buddy->name)); |
5247 | 841 hb->account = buddy->account; |
6695 | 842 hb->group = ((GaimBlistNode*)buddy)->parent->parent; |
5247 | 843 |
6742 | 844 g_hash_table_replace(gaimbuddylist->buddies, hb, buddy); |
5247 | 845 |
6843 | 846 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); |
9285 | 847 |
848 schedule_blist_save(); | |
849 | |
850 if (ops && ops->update) | |
5228 | 851 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); |
852 } | |
853 | |
6695 | 854 GaimContact *gaim_contact_new() |
5228 | 855 { |
9285 | 856 GaimBlistUiOps *ops = gaim_blist_get_ui_ops(); |
857 | |
858 GaimContact *contact = g_new0(GaimContact, 1); | |
859 contact->totalsize = 0; | |
860 contact->currentsize = 0; | |
861 contact->online = 0; | |
862 gaim_blist_node_initialize_settings((GaimBlistNode *)contact); | |
863 ((GaimBlistNode *)contact)->type = GAIM_BLIST_CONTACT_NODE; | |
864 | |
865 if (ops && ops->new_node) | |
866 ops->new_node((GaimBlistNode *)contact); | |
867 | |
868 return contact; | |
6695 | 869 } |
870 | |
9285 | 871 void gaim_contact_set_alias(GaimContact *contact, const char *alias) |
6755 | 872 { |
7245 | 873 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
874 | |
6755 | 875 g_return_if_fail(contact != NULL); |
876 | |
9285 | 877 if (contact->alias != NULL) |
6755 | 878 g_free(contact->alias); |
879 | |
9285 | 880 if ((alias != NULL) && (*alias != '\0')) |
7245 | 881 contact->alias = g_strdup(alias); |
882 else | |
883 contact->alias = NULL; | |
884 | |
9285 | 885 schedule_blist_save(); |
886 | |
887 if (ops && ops->update) | |
7245 | 888 ops->update(gaimbuddylist, (GaimBlistNode*)contact); |
6755 | 889 } |
890 | |
891 const char *gaim_contact_get_alias(GaimContact* contact) | |
892 { | |
9285 | 893 g_return_val_if_fail(contact != NULL, NULL); |
894 | |
895 if (contact->alias) | |
7312 | 896 return contact->alias; |
897 | |
9620 | 898 return gaim_buddy_get_alias(contact->priority); |
6755 | 899 } |
900 | |
9787 | 901 gboolean gaim_contact_on_account(GaimContact *c, GaimAccount *account) |
902 { | |
903 GaimBlistNode *bnode, *cnode = (GaimBlistNode *) c; | |
904 | |
905 g_return_val_if_fail(c != NULL, FALSE); | |
906 g_return_val_if_fail(account != NULL, FALSE); | |
907 | |
908 for (bnode = cnode->child; bnode; bnode = bnode->next) { | |
909 GaimBuddy *buddy; | |
910 | |
911 if (! GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
912 continue; | |
913 | |
914 buddy = (GaimBuddy *)bnode; | |
915 if (buddy->account == account) | |
916 return TRUE; | |
917 } | |
918 return FALSE; | |
919 } | |
920 | |
6695 | 921 GaimGroup *gaim_group_new(const char *name) |
922 { | |
9285 | 923 GaimBlistUiOps *ops = gaim_blist_get_ui_ops(); |
924 GaimGroup *group = gaim_find_group(name); | |
925 | |
926 if (group != NULL) | |
927 return group; | |
928 | |
929 group = g_new0(GaimGroup, 1); | |
930 group->name = g_strdup(name); | |
931 group->totalsize = 0; | |
932 group->currentsize = 0; | |
933 group->online = 0; | |
934 gaim_blist_node_initialize_settings((GaimBlistNode *)group); | |
935 ((GaimBlistNode *)group)->type = GAIM_BLIST_GROUP_NODE; | |
936 | |
937 if (ops && ops->new_node) | |
938 ops->new_node((GaimBlistNode *)group); | |
939 | |
940 return group; | |
5228 | 941 } |
942 | |
6695 | 943 void gaim_blist_add_contact(GaimContact *contact, GaimGroup *group, GaimBlistNode *node) |
944 { | |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
945 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
6695 | 946 GaimGroup *g; |
6742 | 947 GaimBlistNode *gnode, *cnode, *bnode; |
6695 | 948 |
6774 | 949 g_return_if_fail(contact != NULL); |
950 g_return_if_fail(GAIM_BLIST_NODE_IS_CONTACT((GaimBlistNode*)contact)); | |
6695 | 951 |
9285 | 952 if ((GaimBlistNode*)contact == node) |
6975 | 953 return; |
954 | |
9285 | 955 if (node && (GAIM_BLIST_NODE_IS_CONTACT(node) || |
6695 | 956 GAIM_BLIST_NODE_IS_CHAT(node))) |
957 g = (GaimGroup*)node->parent; | |
9285 | 958 else if (group) |
6695 | 959 g = group; |
960 else { | |
961 g = gaim_group_new(_("Buddies")); | |
962 gaim_blist_add_group(g, | |
963 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
964 } | |
965 | |
966 gnode = (GaimBlistNode*)g; | |
967 cnode = (GaimBlistNode*)contact; | |
968 | |
9285 | 969 if (cnode->parent) { |
970 if (cnode->parent->child == cnode) | |
6731 | 971 cnode->parent->child = cnode->next; |
9285 | 972 if (cnode->prev) |
6695 | 973 cnode->prev->next = cnode->next; |
9285 | 974 if (cnode->next) |
6695 | 975 cnode->next->prev = cnode->prev; |
976 | |
9285 | 977 if (cnode->parent != gnode) { |
9928 | 978 bnode = cnode->child; |
979 while (bnode) { | |
980 GaimBlistNode *next_bnode = bnode->next; | |
6742 | 981 GaimBuddy *b = (GaimBuddy*)bnode; |
982 | |
983 struct _gaim_hbuddy *hb = g_new(struct _gaim_hbuddy, 1); | |
7261 | 984 hb->name = g_strdup(gaim_normalize(b->account, b->name)); |
6742 | 985 hb->account = b->account; |
986 hb->group = cnode->parent; | |
987 | |
6776 | 988 g_hash_table_remove(gaimbuddylist->buddies, hb); |
6742 | 989 |
9285 | 990 if (!gaim_find_buddy_in_group(b->account, b->name, g)) { |
8328 | 991 hb->group = gnode; |
992 g_hash_table_replace(gaimbuddylist->buddies, hb, b); | |
993 | |
9285 | 994 if (b->account->gc) |
995 serv_move_buddy(b, (GaimGroup *)cnode->parent, g); | |
8328 | 996 } else { |
9928 | 997 gboolean empty_contact = FALSE; |
998 | |
8328 | 999 /* this buddy already exists in the group, so we're |
1000 * gonna delete it instead */ | |
1001 g_free(hb->name); | |
1002 g_free(hb); | |
9285 | 1003 if (b->account->gc) |
1004 serv_remove_buddy(b->account->gc, b, (GaimGroup *)cnode->parent); | |
1005 | |
1006 if (!cnode->child->next) | |
8328 | 1007 empty_contact = TRUE; |
1008 gaim_blist_remove_buddy(b); | |
9928 | 1009 |
1010 /** in gaim_blist_remove_buddy(), if the last buddy in a | |
1011 * contact is removed, the contact is cleaned up and | |
1012 * g_free'd, so we mustn't try to reference bnode->next */ | |
1013 if (empty_contact) | |
1014 return; | |
8328 | 1015 } |
9928 | 1016 bnode = next_bnode; |
6742 | 1017 } |
1018 } | |
9928 | 1019 |
1020 if (contact->online > 0) | |
1021 ((GaimGroup*)cnode->parent)->online--; | |
1022 if (contact->currentsize > 0) | |
1023 ((GaimGroup*)cnode->parent)->currentsize--; | |
1024 ((GaimGroup*)cnode->parent)->totalsize--; | |
1025 | |
1026 ops->remove(gaimbuddylist, cnode); | |
1027 | |
1028 schedule_blist_save(); | |
6695 | 1029 } |
1030 | |
9285 | 1031 if (node && (GAIM_BLIST_NODE_IS_CONTACT(node) || |
6695 | 1032 GAIM_BLIST_NODE_IS_CHAT(node))) { |
9285 | 1033 if (node->next) |
6695 | 1034 node->next->prev = cnode; |
1035 cnode->next = node->next; | |
1036 cnode->prev = node; | |
1037 cnode->parent = node->parent; | |
1038 node->next = cnode; | |
1039 } else { | |
9285 | 1040 if (gnode->child) |
6695 | 1041 gnode->child->prev = cnode; |
1042 cnode->prev = NULL; | |
1043 cnode->next = gnode->child; | |
1044 gnode->child = cnode; | |
1045 cnode->parent = gnode; | |
1046 } | |
1047 | |
9285 | 1048 if (contact->online > 0) |
6695 | 1049 g->online++; |
9285 | 1050 if (contact->currentsize > 0) |
6695 | 1051 g->currentsize++; |
1052 g->totalsize++; | |
1053 | |
9285 | 1054 schedule_blist_save(); |
1055 | |
1056 if (ops && cnode->child) | |
6695 | 1057 ops->update(gaimbuddylist, cnode); |
6775 | 1058 |
9285 | 1059 for (bnode = cnode->child; bnode; bnode = bnode->next) |
6775 | 1060 ops->update(gaimbuddylist, bnode); |
6695 | 1061 } |
1062 | |
7246 | 1063 void gaim_blist_merge_contact(GaimContact *source, GaimBlistNode *node) |
6965 | 1064 { |
1065 GaimBlistNode *sourcenode = (GaimBlistNode*)source; | |
7246 | 1066 GaimBlistNode *targetnode; |
1067 GaimBlistNode *prev, *cur, *next; | |
1068 GaimContact *target; | |
1069 | |
9285 | 1070 g_return_if_fail(source != NULL); |
1071 g_return_if_fail(node != NULL); | |
1072 | |
1073 if (GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
1074 target = (GaimContact *)node; | |
7246 | 1075 prev = gaim_blist_get_last_child(node); |
9285 | 1076 } else if (GAIM_BLIST_NODE_IS_BUDDY(node)) { |
1077 target = (GaimContact *)node->parent; | |
7246 | 1078 prev = node; |
1079 } else { | |
6965 | 1080 return; |
7246 | 1081 } |
1082 | |
9285 | 1083 if (source == target || !target) |
7246 | 1084 return; |
1085 | |
9285 | 1086 targetnode = (GaimBlistNode *)target; |
7246 | 1087 next = sourcenode->child; |
1088 | |
9285 | 1089 while (next) { |
7246 | 1090 cur = next; |
1091 next = cur->next; | |
9285 | 1092 if (GAIM_BLIST_NODE_IS_BUDDY(cur)) { |
1093 gaim_blist_add_buddy((GaimBuddy *)cur, target, NULL, prev); | |
7246 | 1094 prev = cur; |
1095 } | |
6965 | 1096 } |
1097 } | |
1098 | |
9285 | 1099 void gaim_blist_add_group(GaimGroup *group, GaimBlistNode *node) |
5228 | 1100 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
1101 GaimBlistUiOps *ops; |
5228 | 1102 GaimBlistNode *gnode = (GaimBlistNode*)group; |
1103 | |
6774 | 1104 g_return_if_fail(group != NULL); |
9285 | 1105 g_return_if_fail(GAIM_BLIST_NODE_IS_GROUP((GaimBlistNode *)group)); |
1106 | |
5228 | 1107 ops = gaimbuddylist->ui_ops; |
1108 | |
1109 if (!gaimbuddylist->root) { | |
1110 gaimbuddylist->root = gnode; | |
1111 return; | |
1112 } | |
1113 | |
1114 /* if we're moving to overtop of ourselves, do nothing */ | |
9285 | 1115 if (gnode == node) |
5228 | 1116 return; |
1117 | |
1118 if (gaim_find_group(group->name)) { | |
1119 /* This is just being moved */ | |
1120 | |
9285 | 1121 ops->remove(gaimbuddylist, (GaimBlistNode *)group); |
1122 | |
1123 if (gnode == gaimbuddylist->root) | |
5228 | 1124 gaimbuddylist->root = gnode->next; |
9285 | 1125 if (gnode->prev) |
5228 | 1126 gnode->prev->next = gnode->next; |
9285 | 1127 if (gnode->next) |
5228 | 1128 gnode->next->prev = gnode->prev; |
1129 } | |
1130 | |
6695 | 1131 if (node && GAIM_BLIST_NODE_IS_GROUP(node)) { |
5634 | 1132 gnode->next = node->next; |
1133 gnode->prev = node; | |
9285 | 1134 if (node->next) |
5634 | 1135 node->next->prev = gnode; |
1136 node->next = gnode; | |
1137 } else { | |
9285 | 1138 if (gaimbuddylist->root) |
6807 | 1139 gaimbuddylist->root->prev = gnode; |
5634 | 1140 gnode->next = gaimbuddylist->root; |
1141 gnode->prev = NULL; | |
1142 gaimbuddylist->root = gnode; | |
1143 } | |
1144 | |
9285 | 1145 schedule_blist_save(); |
1146 | |
1147 if (ops && ops->update) { | |
5228 | 1148 ops->update(gaimbuddylist, gnode); |
9285 | 1149 for (node = gnode->child; node; node = node->next) |
5228 | 1150 ops->update(gaimbuddylist, node); |
1151 } | |
1152 } | |
1153 | |
9285 | 1154 void gaim_blist_remove_contact(GaimContact *contact) |
5228 | 1155 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
1156 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
9285 | 1157 GaimBlistNode *node, *gnode; |
1158 | |
1159 g_return_if_fail(contact != NULL); | |
1160 | |
1161 node = (GaimBlistNode *)contact; | |
1162 gnode = node->parent; | |
1163 | |
1164 if (node->child) { | |
1165 /* | |
1166 * If this contact has children then remove them. When the last | |
1167 * buddy is removed from the contact, the contact is deleted. | |
1168 */ | |
1169 while (node->child) { | |
1170 gaim_blist_remove_buddy((GaimBuddy*)node->child); | |
6695 | 1171 } |
1172 } else { | |
9285 | 1173 /* Remove the node from its parent */ |
1174 if (gnode->child == node) | |
1175 gnode->child = node->next; | |
1176 if (node->prev) | |
1177 node->prev->next = node->next; | |
1178 if (node->next) | |
1179 node->next->prev = node->prev; | |
1180 | |
1181 schedule_blist_save(); | |
1182 | |
1183 /* Update the UI */ | |
1184 if (ops && ops->remove) | |
1185 ops->remove(gaimbuddylist, node); | |
1186 | |
1187 /* Delete the node */ | |
6695 | 1188 g_free(contact); |
1189 } | |
1190 } | |
1191 | |
9285 | 1192 void gaim_blist_remove_buddy(GaimBuddy *buddy) |
6695 | 1193 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
1194 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
9285 | 1195 GaimBlistNode *node, *cnode, *gnode; |
1196 GaimContact *contact; | |
6695 | 1197 GaimGroup *group; |
6742 | 1198 struct _gaim_hbuddy hb; |
5228 | 1199 |
9285 | 1200 g_return_if_fail(buddy != NULL); |
1201 | |
1202 node = (GaimBlistNode *)buddy; | |
6695 | 1203 cnode = node->parent; |
9285 | 1204 gnode = cnode->parent; |
1205 contact = (GaimContact *)cnode; | |
1206 group = (GaimGroup *)gnode; | |
1207 | |
1208 /* Remove the node from its parent */ | |
5228 | 1209 if (node->prev) |
1210 node->prev->next = node->next; | |
1211 if (node->next) | |
1212 node->next->prev = node->prev; | |
9285 | 1213 if (cnode->child == node) |
6695 | 1214 cnode->child = node->next; |
9285 | 1215 |
1216 /* Adjust size counts */ | |
1217 if (GAIM_BUDDY_IS_ONLINE(buddy)) { | |
1218 contact->online--; | |
1219 if (contact->online == 0) | |
1220 group->online--; | |
6695 | 1221 } |
9285 | 1222 if (gaim_account_is_connected(buddy->account)) { |
1223 contact->currentsize--; | |
1224 if (contact->currentsize == 0) | |
1225 group->currentsize--; | |
8194 | 1226 } |
9285 | 1227 contact->totalsize--; |
1228 | |
1229 schedule_blist_save(); | |
1230 | |
1231 /* Re-sort the contact */ | |
1232 if (contact->priority == buddy) { | |
1233 gaim_contact_compute_priority_buddy(contact); | |
1234 if (ops && ops->update) | |
1235 ops->update(gaimbuddylist, cnode); | |
1236 } | |
1237 | |
1238 /* Remove this buddy from the buddies hash table */ | |
7261 | 1239 hb.name = g_strdup(gaim_normalize(buddy->account, buddy->name)); |
5247 | 1240 hb.account = buddy->account; |
6695 | 1241 hb.group = ((GaimBlistNode*)buddy)->parent->parent; |
6742 | 1242 g_hash_table_remove(gaimbuddylist->buddies, &hb); |
7162 | 1243 g_free(hb.name); |
5247 | 1244 |
9285 | 1245 /* Update the UI */ |
1246 if (ops && ops->remove) | |
1247 ops->remove(gaimbuddylist, node); | |
1248 | |
1249 /* Delete the node */ | |
1250 if (buddy->timer > 0) | |
8287
ef881489396e
[gaim-migrate @ 9011]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
1251 gaim_timeout_remove(buddy->timer); |
6846
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
1252 if (buddy->icon != NULL) |
8ab95f4c9800
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
1253 gaim_buddy_icon_unref(buddy->icon); |
7693 | 1254 g_hash_table_destroy(buddy->node.settings); |
9944 | 1255 gaim_presence_remove_buddy(buddy->presence, buddy); |
1256 gaim_presence_destroy(buddy->presence); | |
5228 | 1257 g_free(buddy->name); |
1258 g_free(buddy->alias); | |
1259 g_free(buddy); | |
6755 | 1260 |
9285 | 1261 /* If the contact is empty then remove it */ |
1262 if (!cnode->child) | |
1263 gaim_blist_remove_contact(contact); | |
5228 | 1264 } |
1265 | |
9285 | 1266 void gaim_blist_remove_chat(GaimChat *chat) |
5234 | 1267 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
1268 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
9285 | 1269 GaimBlistNode *node, *gnode; |
6695 | 1270 GaimGroup *group; |
5234 | 1271 |
9285 | 1272 g_return_if_fail(chat != NULL); |
1273 | |
1274 node = (GaimBlistNode *)chat; | |
5234 | 1275 gnode = node->parent; |
6695 | 1276 group = (GaimGroup *)gnode; |
5234 | 1277 |
9285 | 1278 /* Remove the node from its parent */ |
1279 if (gnode->child == node) | |
5234 | 1280 gnode->child = node->next; |
1281 if (node->prev) | |
1282 node->prev->next = node->next; | |
1283 if (node->next) | |
1284 node->next->prev = node->prev; | |
9285 | 1285 |
1286 /* Adjust size counts */ | |
5855 | 1287 if (gaim_account_is_connected(chat->account)) { |
5394 | 1288 group->online--; |
9285 | 1289 group->currentsize--; |
5394 | 1290 } |
9285 | 1291 group->totalsize--; |
1292 | |
1293 schedule_blist_save(); | |
1294 | |
1295 /* Update the UI */ | |
1296 if (ops && ops->remove) | |
1297 ops->remove(gaimbuddylist, node); | |
1298 | |
1299 /* Delete the node */ | |
5234 | 1300 g_hash_table_destroy(chat->components); |
1301 g_free(chat->alias); | |
1302 g_free(chat); | |
1303 } | |
1304 | |
9285 | 1305 void gaim_blist_remove_group(GaimGroup *group) |
5228 | 1306 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
1307 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
9285 | 1308 GaimBlistNode *node; |
6885
66dd420d3d23
[gaim-migrate @ 7431]
Christian Hammond <chipx86@chipx86.com>
parents:
6872
diff
changeset
|
1309 GList *l; |
5228 | 1310 |
9285 | 1311 g_return_if_fail(group != NULL); |
1312 | |
1313 node = (GaimBlistNode *)group; | |
1314 | |
1315 /* Make sure the group is empty */ | |
1316 if (node->child) { | |
5228 | 1317 char *buf; |
1318 int count = 0; | |
9285 | 1319 GaimBlistNode *child; |
1320 | |
1321 for (child = node->child; child != NULL; child = child->next) | |
5228 | 1322 count++; |
1323 | |
6308 | 1324 buf = g_strdup_printf(ngettext("%d buddy from group %s was not removed " |
1325 "because its account was not logged in." | |
1326 " This buddy and the group were not " | |
1327 "removed.\n", | |
1328 "%d buddies from group %s were not " | |
1329 "removed because their accounts were " | |
6336 | 1330 "not logged in. These buddies and " |
1331 "the group were not removed.\n", count), | |
6308 | 1332 count, group->name); |
5541
aee0ee458974
[gaim-migrate @ 5941]
Christian Hammond <chipx86@chipx86.com>
parents:
5436
diff
changeset
|
1333 gaim_notify_error(NULL, NULL, _("Group not removed"), buf); |
5228 | 1334 g_free(buf); |
1335 return; | |
1336 } | |
1337 | |
9285 | 1338 /* Remove the node from its parent */ |
1339 if (gaimbuddylist->root == node) | |
5228 | 1340 gaimbuddylist->root = node->next; |
1341 if (node->prev) | |
1342 node->prev->next = node->next; | |
1343 if (node->next) | |
1344 node->next->prev = node->prev; | |
1345 | |
9285 | 1346 schedule_blist_save(); |
1347 | |
1348 /* Update the UI */ | |
1349 if (ops && ops->remove) | |
1350 ops->remove(gaimbuddylist, node); | |
1351 | |
1352 /* Remove the group from all accounts that are online */ | |
6885
66dd420d3d23
[gaim-migrate @ 7431]
Christian Hammond <chipx86@chipx86.com>
parents:
6872
diff
changeset
|
1353 for (l = gaim_connections_get_all(); l != NULL; l = l->next) |
66dd420d3d23
[gaim-migrate @ 7431]
Christian Hammond <chipx86@chipx86.com>
parents:
6872
diff
changeset
|
1354 { |
66dd420d3d23
[gaim-migrate @ 7431]
Christian Hammond <chipx86@chipx86.com>
parents:
6872
diff
changeset
|
1355 GaimConnection *gc = (GaimConnection *)l->data; |
66dd420d3d23
[gaim-migrate @ 7431]
Christian Hammond <chipx86@chipx86.com>
parents:
6872
diff
changeset
|
1356 |
66dd420d3d23
[gaim-migrate @ 7431]
Christian Hammond <chipx86@chipx86.com>
parents:
6872
diff
changeset
|
1357 if (gaim_connection_get_state(gc) == GAIM_CONNECTED) |
9285 | 1358 serv_remove_group(gc, group); |
6885
66dd420d3d23
[gaim-migrate @ 7431]
Christian Hammond <chipx86@chipx86.com>
parents:
6872
diff
changeset
|
1359 } |
66dd420d3d23
[gaim-migrate @ 7431]
Christian Hammond <chipx86@chipx86.com>
parents:
6872
diff
changeset
|
1360 |
9285 | 1361 /* Delete the node */ |
5228 | 1362 g_free(group->name); |
1363 g_free(group); | |
1364 } | |
1365 | |
9285 | 1366 GaimBuddy *gaim_contact_get_priority_buddy(GaimContact *contact) |
1367 { | |
1368 g_return_val_if_fail(contact != NULL, NULL); | |
1369 | |
6843 | 1370 return contact->priority; |
6695 | 1371 } |
1372 | |
9620 | 1373 const char *gaim_buddy_get_alias_only(GaimBuddy *buddy) |
9285 | 1374 { |
1375 g_return_val_if_fail(buddy != NULL, NULL); | |
1376 | |
1377 if ((buddy->alias != NULL) && (*buddy->alias != '\0')) { | |
1378 return buddy->alias; | |
1379 } else if ((buddy->server_alias != NULL) && | |
1380 (*buddy->server_alias != '\0') && | |
1381 (gaim_prefs_get_bool("/core/buddies/use_server_alias"))) { | |
1382 | |
1383 return buddy->server_alias; | |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1384 } |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1385 |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1386 return NULL; |
5228 | 1387 } |
1388 | |
9620 | 1389 |
1390 const char *gaim_buddy_get_contact_alias(GaimBuddy *buddy) | |
5228 | 1391 { |
9620 | 1392 GaimContact *c; |
1393 | |
1394 g_return_val_if_fail(buddy != NULL, NULL); | |
1395 | |
1396 /* Search for an alias for the buddy. In order of precedence: */ | |
1397 /* The buddy alias */ | |
1398 if (buddy->alias != NULL) | |
1399 return buddy->alias; | |
1400 | |
1401 /* The contact alias */ | |
1402 c = gaim_buddy_get_contact(buddy); | |
1403 if ((c != NULL) && (c->alias != NULL)) | |
1404 return c->alias; | |
1405 | |
1406 /* The server alias, if preferences say so */ | |
1407 if ((buddy->server_alias) && (*buddy->server_alias) && | |
1408 (gaim_prefs_get_bool("/core/buddies/use_server_alias"))) | |
1409 return buddy->server_alias; | |
1410 | |
1411 /* The buddy's user name (i.e. no alias) */ | |
1412 return buddy->name; | |
5228 | 1413 } |
1414 | |
9620 | 1415 |
1416 const char *gaim_buddy_get_alias(GaimBuddy *buddy) | |
1417 { | |
1418 g_return_val_if_fail(buddy != NULL, NULL); | |
1419 | |
1420 /* Search for an alias for the buddy. In order of precedence: */ | |
1421 /* The buddy alias */ | |
1422 if (buddy->alias != NULL) | |
1423 return buddy->alias; | |
1424 | |
1425 /* The server alias, if preferences say so */ | |
1426 if ((buddy->server_alias) && (*buddy->server_alias) && | |
1427 (gaim_prefs_get_bool("/core/buddies/use_server_alias"))) | |
1428 return buddy->server_alias; | |
1429 | |
1430 /* The buddy's user name (i.e. no alias) */ | |
1431 return buddy->name; | |
1432 } | |
1433 | |
1434 | |
7125 | 1435 const char *gaim_chat_get_name(GaimChat *chat) |
6744 | 1436 { |
9285 | 1437 struct proto_chat_entry *pce; |
1438 GList *parts, *tmp; | |
1439 char *ret; | |
1440 | |
1441 g_return_val_if_fail(chat != NULL, NULL); | |
1442 | |
1443 if ((chat->alias != NULL) && (*chat->alias != '\0')) | |
6744 | 1444 return chat->alias; |
9285 | 1445 |
1446 parts = GAIM_PLUGIN_PROTOCOL_INFO(chat->account->gc->prpl)->chat_info(chat->account->gc); | |
1447 pce = parts->data; | |
1448 ret = g_hash_table_lookup(chat->components, pce->identifier); | |
1449 for (tmp = parts; tmp; tmp = tmp->next) | |
1450 g_free(tmp->data); | |
1451 g_list_free(parts); | |
1452 | |
1453 return ret; | |
6744 | 1454 } |
1455 | |
6695 | 1456 GaimBuddy *gaim_find_buddy(GaimAccount *account, const char *name) |
5228 | 1457 { |
6695 | 1458 GaimBuddy *buddy; |
5247 | 1459 struct _gaim_hbuddy hb; |
5758 | 1460 GaimBlistNode *group; |
5228 | 1461 |
9285 | 1462 g_return_val_if_fail(gaimbuddylist != NULL, NULL); |
1463 g_return_val_if_fail(account != NULL, NULL); | |
1464 g_return_val_if_fail((name != NULL) && (*name != '\0'), NULL); | |
5228 | 1465 |
7429 | 1466 hb.account = account; |
7261 | 1467 hb.name = g_strdup(gaim_normalize(account, name)); |
7429 | 1468 |
9285 | 1469 for (group = gaimbuddylist->root; group; group = group->next) { |
5758 | 1470 hb.group = group; |
7162 | 1471 if ((buddy = g_hash_table_lookup(gaimbuddylist->buddies, &hb))) { |
1472 g_free(hb.name); | |
5758 | 1473 return buddy; |
7162 | 1474 } |
5758 | 1475 } |
7162 | 1476 g_free(hb.name); |
9285 | 1477 |
5758 | 1478 return NULL; |
5228 | 1479 } |
1480 | |
6872 | 1481 GaimBuddy *gaim_find_buddy_in_group(GaimAccount *account, const char *name, |
1482 GaimGroup *group) | |
1483 { | |
1484 struct _gaim_hbuddy hb; | |
7162 | 1485 GaimBuddy *ret; |
6872 | 1486 |
9285 | 1487 g_return_val_if_fail(gaimbuddylist != NULL, NULL); |
1488 g_return_val_if_fail(account != NULL, NULL); | |
1489 g_return_val_if_fail((name != NULL) && (*name != '\0'), NULL); | |
6872 | 1490 |
7261 | 1491 hb.name = g_strdup(gaim_normalize(account, name)); |
6872 | 1492 hb.account = account; |
1493 hb.group = (GaimBlistNode*)group; | |
1494 | |
7162 | 1495 ret = g_hash_table_lookup(gaimbuddylist->buddies, &hb); |
1496 g_free(hb.name); | |
9285 | 1497 |
7162 | 1498 return ret; |
6872 | 1499 } |
1500 | |
6245 | 1501 GSList *gaim_find_buddies(GaimAccount *account, const char *name) |
1502 { | |
1503 struct buddy *buddy; | |
1504 struct _gaim_hbuddy hb; | |
9285 | 1505 GaimBlistNode *node; |
6245 | 1506 GSList *ret = NULL; |
1507 | |
9285 | 1508 g_return_val_if_fail(gaimbuddylist != NULL, NULL); |
1509 g_return_val_if_fail(account != NULL, NULL); | |
1510 g_return_val_if_fail((name != NULL) && (*name != '\0'), NULL); | |
6245 | 1511 |
7261 | 1512 hb.name = g_strdup(gaim_normalize(account, name)); |
6245 | 1513 hb.account = account; |
1514 | |
9285 | 1515 for (node = gaimbuddylist->root; node != NULL; node = node->next) { |
1516 hb.group = node; | |
6245 | 1517 if ((buddy = g_hash_table_lookup(gaimbuddylist->buddies, &hb)) != NULL) |
1518 ret = g_slist_append(ret, buddy); | |
1519 } | |
7162 | 1520 g_free(hb.name); |
9285 | 1521 |
6245 | 1522 return ret; |
1523 } | |
1524 | |
6695 | 1525 GaimGroup *gaim_find_group(const char *name) |
5228 | 1526 { |
1527 GaimBlistNode *node; | |
9285 | 1528 |
1529 g_return_val_if_fail(gaimbuddylist != NULL, NULL); | |
1530 g_return_val_if_fail((name != NULL) && (*name != '\0'), NULL); | |
1531 | |
1532 for (node = gaimbuddylist->root; node != NULL; node = node->next) { | |
6695 | 1533 if (!strcmp(((GaimGroup *)node)->name, name)) |
1534 return (GaimGroup *)node; | |
5228 | 1535 } |
9285 | 1536 |
5228 | 1537 return NULL; |
1538 } | |
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1539 |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1540 GaimChat * |
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1541 gaim_blist_find_chat(GaimAccount *account, const char *name) |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1542 { |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1543 char *chat_name; |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1544 GaimChat *chat; |
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1545 GaimPlugin *prpl; |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1546 GaimPluginProtocolInfo *prpl_info = NULL; |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1547 struct proto_chat_entry *pce; |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1548 GaimBlistNode *node, *group; |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1549 GList *parts; |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1550 |
9285 | 1551 g_return_val_if_fail(gaimbuddylist != NULL, NULL); |
1552 g_return_val_if_fail((name != NULL) && (*name != '\0'), NULL); | |
1553 | |
1554 if (!gaim_account_is_connected(account)) | |
7970 | 1555 return NULL; |
1556 | |
7999 | 1557 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); |
1558 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
1559 | |
9285 | 1560 if (prpl_info->find_blist_chat != NULL) |
7999 | 1561 return prpl_info->find_blist_chat(account, name); |
1562 | |
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1563 for (group = gaimbuddylist->root; group != NULL; group = group->next) { |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1564 for (node = group->child; node != NULL; node = node->next) { |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1565 if (GAIM_BLIST_NODE_IS_CHAT(node)) { |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1566 |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1567 chat = (GaimChat*)node; |
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1568 |
9285 | 1569 if (account != chat->account) |
7970 | 1570 continue; |
1571 | |
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1572 parts = prpl_info->chat_info( |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1573 gaim_account_get_connection(chat->account)); |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1574 |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1575 pce = parts->data; |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1576 chat_name = g_hash_table_lookup(chat->components, |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1577 pce->identifier); |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1578 |
9153 | 1579 if (chat->account == account && chat_name != NULL && |
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1580 name != NULL && !strcmp(chat_name, name)) { |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1581 |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1582 return chat; |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1583 } |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1584 } |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1585 } |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1586 } |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1587 |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1588 return NULL; |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1589 } |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1590 |
6695 | 1591 GaimGroup * |
7125 | 1592 gaim_chat_get_group(GaimChat *chat) |
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1593 { |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1594 g_return_val_if_fail(chat != NULL, NULL); |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1595 |
6695 | 1596 return (GaimGroup *)(((GaimBlistNode *)chat)->parent); |
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1597 } |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1598 |
9285 | 1599 GaimContact *gaim_buddy_get_contact(GaimBuddy *buddy) |
1600 { | |
1601 g_return_val_if_fail(buddy != NULL, NULL); | |
1602 | |
1603 return (GaimContact*)((GaimBlistNode*)buddy)->parent; | |
1604 } | |
1605 | |
9949 | 1606 GaimPresence *gaim_buddy_get_presence(const GaimBuddy *buddy) |
1607 { | |
1608 g_return_val_if_fail(buddy != NULL, NULL); | |
1609 return buddy->presence; | |
1610 } | |
1611 | |
1612 | |
6695 | 1613 GaimGroup *gaim_find_buddys_group(GaimBuddy *buddy) |
5228 | 1614 { |
9285 | 1615 g_return_val_if_fail(buddy != NULL, NULL); |
6706
854a435d2cc3
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1616 |
854a435d2cc3
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1617 if (((GaimBlistNode *)buddy)->parent == NULL) |
854a435d2cc3
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1618 return NULL; |
854a435d2cc3
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1619 |
6695 | 1620 return (GaimGroup *)(((GaimBlistNode*)buddy)->parent->parent); |
5228 | 1621 } |
1622 | |
9285 | 1623 GSList *gaim_group_get_accounts(GaimGroup *group) |
5228 | 1624 { |
1625 GSList *l = NULL; | |
6695 | 1626 GaimBlistNode *gnode, *cnode, *bnode; |
1627 | |
9285 | 1628 gnode = (GaimBlistNode *)group; |
1629 | |
1630 for (cnode = gnode->child; cnode; cnode = cnode->next) { | |
6695 | 1631 if (GAIM_BLIST_NODE_IS_CHAT(cnode)) { |
9285 | 1632 if (!g_slist_find(l, ((GaimChat *)cnode)->account)) |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1633 l = g_slist_append(l, ((GaimChat *)cnode)->account); |
9285 | 1634 } else if (GAIM_BLIST_NODE_IS_CONTACT(cnode)) { |
1635 for (bnode = cnode->child; bnode; bnode = bnode->next) { | |
1636 if (GAIM_BLIST_NODE_IS_BUDDY(bnode)) { | |
1637 if (!g_slist_find(l, ((GaimBuddy *)bnode)->account)) | |
6695 | 1638 l = g_slist_append(l, ((GaimBuddy *)bnode)->account); |
1639 } | |
1640 } | |
1641 } | |
5228 | 1642 } |
6695 | 1643 |
5228 | 1644 return l; |
1645 } | |
1646 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1647 void gaim_blist_add_account(GaimAccount *account) |
5234 | 1648 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
1649 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
6695 | 1650 GaimBlistNode *gnode, *cnode, *bnode; |
5234 | 1651 |
9285 | 1652 g_return_if_fail(gaimbuddylist != NULL); |
1653 | |
1654 if (!ops || !ops->update) | |
6695 | 1655 return; |
1656 | |
9285 | 1657 for (gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { |
1658 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
5234 | 1659 continue; |
9285 | 1660 for (cnode = gnode->child; cnode; cnode = cnode->next) { |
1661 if (GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
6956 | 1662 gboolean recompute = FALSE; |
9285 | 1663 for (bnode = cnode->child; bnode; bnode = bnode->next) { |
1664 if (GAIM_BLIST_NODE_IS_BUDDY(bnode) && | |
6695 | 1665 ((GaimBuddy*)bnode)->account == account) { |
6956 | 1666 recompute = TRUE; |
6695 | 1667 ((GaimContact*)cnode)->currentsize++; |
9285 | 1668 if (((GaimContact*)cnode)->currentsize == 1) |
6695 | 1669 ((GaimGroup*)gnode)->currentsize++; |
1670 ops->update(gaimbuddylist, bnode); | |
1671 } | |
1672 } | |
9285 | 1673 if (recompute || |
8960 | 1674 gaim_blist_node_get_bool(cnode, "show_offline")) { |
6956 | 1675 gaim_contact_compute_priority_buddy((GaimContact*)cnode); |
1676 ops->update(gaimbuddylist, cnode); | |
1677 } | |
9285 | 1678 } else if (GAIM_BLIST_NODE_IS_CHAT(cnode) && |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1679 ((GaimChat*)cnode)->account == account) { |
6901 | 1680 ((GaimGroup *)gnode)->online++; |
1681 ((GaimGroup *)gnode)->currentsize++; | |
1682 ops->update(gaimbuddylist, cnode); | |
5234 | 1683 } |
1684 } | |
6695 | 1685 ops->update(gaimbuddylist, gnode); |
5234 | 1686 } |
1687 } | |
1688 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1689 void gaim_blist_remove_account(GaimAccount *account) |
5228 | 1690 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
1691 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
6695 | 1692 GaimBlistNode *gnode, *cnode, *bnode; |
5234 | 1693 |
9285 | 1694 g_return_if_fail(gaimbuddylist != NULL); |
1695 | |
1696 for (gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { | |
1697 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
5234 | 1698 continue; |
9285 | 1699 for (cnode = gnode->child; cnode; cnode = cnode->next) { |
1700 if (GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
6957 | 1701 gboolean recompute = FALSE; |
9285 | 1702 for (bnode = cnode->child; bnode; bnode = bnode->next) { |
1703 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
6695 | 1704 continue; |
9285 | 1705 if (account == ((GaimBuddy *)bnode)->account) { |
6957 | 1706 recompute = TRUE; |
9285 | 1707 if (((GaimBuddy*)bnode)->present == GAIM_BUDDY_ONLINE || |
6695 | 1708 ((GaimBuddy*)bnode)->present == GAIM_BUDDY_SIGNING_ON) { |
1709 ((GaimContact*)cnode)->online--; | |
9285 | 1710 if (((GaimContact*)cnode)->online == 0) |
6695 | 1711 ((GaimGroup*)gnode)->online--; |
1712 } | |
1713 ((GaimContact*)cnode)->currentsize--; | |
9285 | 1714 if (((GaimContact*)cnode)->currentsize == 0) |
6695 | 1715 ((GaimGroup*)gnode)->currentsize--; |
1716 | |
1717 ((GaimBuddy*)bnode)->present = GAIM_BUDDY_OFFLINE; | |
1718 | |
6803 | 1719 ((GaimBuddy*)bnode)->uc = 0; |
9944 | 1720 /* XXX ((GaimBuddy*)bnode)->idle = 0; */ |
6803 | 1721 |
6945 | 1722 |
9285 | 1723 if (ops && ops->remove) |
6695 | 1724 ops->remove(gaimbuddylist, bnode); |
1725 } | |
5234 | 1726 } |
9285 | 1727 if (recompute) { |
6959 | 1728 gaim_contact_compute_priority_buddy((GaimContact*)cnode); |
9285 | 1729 if (ops && ops->update) |
6983 | 1730 ops->update(gaimbuddylist, cnode); |
1731 } | |
9285 | 1732 } else if (GAIM_BLIST_NODE_IS_CHAT(cnode) && |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1733 ((GaimChat*)cnode)->account == account) { |
6695 | 1734 ((GaimGroup*)gnode)->currentsize--; |
1735 ((GaimGroup*)gnode)->online--; | |
9285 | 1736 if (ops && ops->remove) |
6695 | 1737 ops->remove(gaimbuddylist, cnode); |
5228 | 1738 } |
1739 } | |
1740 } | |
1741 } | |
1742 | |
9285 | 1743 gboolean gaim_group_on_account(GaimGroup *g, GaimAccount *account) |
1744 { | |
9787 | 1745 GaimBlistNode *cnode; |
9285 | 1746 for (cnode = ((GaimBlistNode *)g)->child; cnode; cnode = cnode->next) { |
1747 if (GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
9787 | 1748 if(gaim_contact_on_account((GaimContact *) cnode, account)) |
1749 return TRUE; | |
9285 | 1750 } else if (GAIM_BLIST_NODE_IS_CHAT(cnode)) { |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1751 GaimChat *chat = (GaimChat *)cnode; |
9285 | 1752 if ((!account && gaim_account_is_connected(chat->account)) |
6695 | 1753 || chat->account == account) |
1754 return TRUE; | |
1755 } | |
5228 | 1756 } |
1757 return FALSE; | |
1758 } | |
1759 | |
1760 static gboolean blist_safe_to_write = FALSE; | |
1761 | |
7132 | 1762 static void parse_setting(GaimBlistNode *node, xmlnode *setting) |
1763 { | |
1764 const char *name = xmlnode_get_attrib(setting, "name"); | |
7693 | 1765 const char *type = xmlnode_get_attrib(setting, "type"); |
7132 | 1766 char *value = xmlnode_get_data(setting); |
1767 | |
9285 | 1768 if (!value) |
7693 | 1769 return; |
1770 | |
9285 | 1771 if (!type || !strcmp(type, "string")) |
7693 | 1772 gaim_blist_node_set_string(node, name, value); |
9285 | 1773 else if (!strcmp(type, "bool")) |
7693 | 1774 gaim_blist_node_set_bool(node, name, atoi(value)); |
9285 | 1775 else if (!strcmp(type, "int")) |
7693 | 1776 gaim_blist_node_set_int(node, name, atoi(value)); |
7132 | 1777 |
1778 g_free(value); | |
1779 } | |
1780 | |
1781 static void parse_buddy(GaimGroup *group, GaimContact *contact, xmlnode *bnode) | |
1782 { | |
1783 GaimAccount *account; | |
1784 GaimBuddy *buddy; | |
7727 | 1785 char *name = NULL, *alias = NULL; |
7153 | 1786 const char *acct_name, *proto, *protocol; |
7132 | 1787 xmlnode *x; |
1788 | |
1789 acct_name = xmlnode_get_attrib(bnode, "account"); | |
7153 | 1790 protocol = xmlnode_get_attrib(bnode, "protocol"); |
1791 proto = xmlnode_get_attrib(bnode, "proto"); | |
1792 | |
9285 | 1793 if (!acct_name || (!proto && !protocol)) |
7132 | 1794 return; |
1795 | |
7153 | 1796 account = gaim_accounts_find(acct_name, proto ? proto : protocol); |
7132 | 1797 |
9285 | 1798 if (!account) |
7132 | 1799 return; |
1800 | |
9285 | 1801 if ((x = xmlnode_get_child(bnode, "name"))) |
7132 | 1802 name = xmlnode_get_data(x); |
1803 | |
9285 | 1804 if (!name) |
7132 | 1805 return; |
1806 | |
9285 | 1807 if ((x = xmlnode_get_child(bnode, "alias"))) |
7132 | 1808 alias = xmlnode_get_data(x); |
1809 | |
1810 buddy = gaim_buddy_new(account, name, alias); | |
1811 gaim_blist_add_buddy(buddy, contact, group, | |
1812 gaim_blist_get_last_child((GaimBlistNode*)contact)); | |
1813 | |
9285 | 1814 for (x = xmlnode_get_child(bnode, "setting"); x; x = xmlnode_get_next_twin(x)) { |
7132 | 1815 parse_setting((GaimBlistNode*)buddy, x); |
1816 } | |
1817 | |
1818 g_free(name); | |
9285 | 1819 if (alias) |
7132 | 1820 g_free(alias); |
1821 } | |
1822 | |
1823 static void parse_contact(GaimGroup *group, xmlnode *cnode) | |
1824 { | |
1825 GaimContact *contact = gaim_contact_new(); | |
1826 xmlnode *x; | |
7245 | 1827 const char *alias; |
7132 | 1828 |
1829 gaim_blist_add_contact(contact, group, | |
1830 gaim_blist_get_last_child((GaimBlistNode*)group)); | |
1831 | |
9285 | 1832 if ((alias = xmlnode_get_attrib(cnode, "alias"))) { |
7132 | 1833 gaim_contact_set_alias(contact, alias); |
1834 } | |
1835 | |
9285 | 1836 for (x = cnode->child; x; x = x->next) { |
1837 if (x->type != XMLNODE_TYPE_TAG) | |
7132 | 1838 continue; |
9285 | 1839 if (!strcmp(x->name, "buddy")) |
7132 | 1840 parse_buddy(group, contact, x); |
9285 | 1841 else if (!strcmp(x->name, "setting")) |
7132 | 1842 parse_setting((GaimBlistNode*)contact, x); |
5228 | 1843 } |
7825 | 1844 |
1845 /* if the contact is empty, don't keep it around. it causes problems */ | |
9285 | 1846 if (!((GaimBlistNode*)contact)->child) |
7825 | 1847 gaim_blist_remove_contact(contact); |
5228 | 1848 } |
1849 | |
7132 | 1850 static void parse_chat(GaimGroup *group, xmlnode *cnode) |
1851 { | |
1852 GaimChat *chat; | |
1853 GaimAccount *account; | |
7153 | 1854 const char *acct_name, *proto, *protocol; |
7132 | 1855 xmlnode *x; |
1856 char *alias = NULL; | |
1857 GHashTable *components; | |
1858 | |
1859 acct_name = xmlnode_get_attrib(cnode, "account"); | |
7153 | 1860 protocol = xmlnode_get_attrib(cnode, "protocol"); |
1861 proto = xmlnode_get_attrib(cnode, "proto"); | |
1862 | |
9285 | 1863 if (!acct_name || (!proto && !protocol)) |
7132 | 1864 return; |
1865 | |
7153 | 1866 account = gaim_accounts_find(acct_name, proto ? proto : protocol); |
7132 | 1867 |
9285 | 1868 if (!account) |
7132 | 1869 return; |
1870 | |
9285 | 1871 if ((x = xmlnode_get_child(cnode, "alias"))) |
7132 | 1872 alias = xmlnode_get_data(x); |
1873 | |
1874 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
1875 | |
9285 | 1876 for (x = xmlnode_get_child(cnode, "component"); x; x = xmlnode_get_next_twin(x)) { |
7132 | 1877 const char *name; |
1878 char *value; | |
1879 | |
1880 name = xmlnode_get_attrib(x, "name"); | |
1881 value = xmlnode_get_data(x); | |
1882 g_hash_table_replace(components, g_strdup(name), value); | |
1883 } | |
1884 | |
1885 chat = gaim_chat_new(account, alias, components); | |
7151 | 1886 gaim_blist_add_chat(chat, group, |
1887 gaim_blist_get_last_child((GaimBlistNode*)group)); | |
7132 | 1888 |
9285 | 1889 for (x = xmlnode_get_child(cnode, "setting"); x; x = xmlnode_get_next_twin(x)) { |
7132 | 1890 parse_setting((GaimBlistNode*)chat, x); |
1891 } | |
1892 | |
9285 | 1893 if (alias) |
7132 | 1894 g_free(alias); |
1895 } | |
1896 | |
1897 | |
1898 static void parse_group(xmlnode *groupnode) | |
1899 { | |
1900 const char *name = xmlnode_get_attrib(groupnode, "name"); | |
1901 GaimGroup *group; | |
1902 xmlnode *cnode; | |
1903 | |
9285 | 1904 if (!name) |
7132 | 1905 name = _("Buddies"); |
1906 | |
1907 group = gaim_group_new(name); | |
1908 gaim_blist_add_group(group, | |
1909 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
1910 | |
9285 | 1911 for (cnode = groupnode->child; cnode; cnode = cnode->next) { |
1912 if (cnode->type != XMLNODE_TYPE_TAG) | |
7132 | 1913 continue; |
9285 | 1914 if (!strcmp(cnode->name, "setting")) |
7132 | 1915 parse_setting((GaimBlistNode*)group, cnode); |
9285 | 1916 else if (!strcmp(cnode->name, "contact") || |
7132 | 1917 !strcmp(cnode->name, "person")) |
1918 parse_contact(group, cnode); | |
9285 | 1919 else if (!strcmp(cnode->name, "chat")) |
7132 | 1920 parse_chat(group, cnode); |
5228 | 1921 } |
1922 } | |
1923 | |
9285 | 1924 static gboolean gaim_blist_read(const char *filename) |
1925 { | |
7132 | 1926 GError *error; |
5228 | 1927 gchar *contents = NULL; |
1928 gsize length; | |
7132 | 1929 xmlnode *gaim, *blist, *privacy; |
5228 | 1930 |
1931 gaim_debug(GAIM_DEBUG_INFO, "blist import", | |
1932 "Reading %s\n", filename); | |
9285 | 1933 if (!g_file_get_contents(filename, &contents, &length, &error)) { |
5228 | 1934 gaim_debug(GAIM_DEBUG_ERROR, "blist import", |
1935 "Error reading blist: %s\n", error->message); | |
1936 g_error_free(error); | |
1937 return FALSE; | |
1938 } | |
1939 | |
7132 | 1940 gaim = xmlnode_from_str(contents, length); |
8826 | 1941 |
9285 | 1942 if (!gaim) { |
8826 | 1943 FILE *backup; |
1944 char *name; | |
7132 | 1945 gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Error parsing %s\n", |
1946 filename); | |
8826 | 1947 name = g_build_filename(gaim_user_dir(), "blist.xml~", NULL); |
1948 | |
9285 | 1949 if ((backup = fopen(name, "w"))) { |
8826 | 1950 fwrite(contents, length, 1, backup); |
1951 fclose(backup); | |
1952 chmod(name, S_IRUSR | S_IWUSR); | |
1953 } else { | |
1954 gaim_debug(GAIM_DEBUG_ERROR, "blist load", "Unable to write backup %s\n", | |
1955 name); | |
1956 } | |
1957 g_free(name); | |
1958 g_free(contents); | |
5228 | 1959 return FALSE; |
1960 } | |
8826 | 1961 |
1962 g_free(contents); | |
1963 | |
7132 | 1964 blist = xmlnode_get_child(gaim, "blist"); |
9285 | 1965 if (blist) { |
7132 | 1966 xmlnode *groupnode; |
9285 | 1967 for (groupnode = xmlnode_get_child(blist, "group"); groupnode; |
8135 | 1968 groupnode = xmlnode_get_next_twin(groupnode)) { |
7132 | 1969 parse_group(groupnode); |
1970 } | |
5228 | 1971 } |
1972 | |
7132 | 1973 privacy = xmlnode_get_child(gaim, "privacy"); |
9285 | 1974 if (privacy) { |
7132 | 1975 xmlnode *anode; |
9285 | 1976 for (anode = privacy->child; anode; anode = anode->next) { |
7132 | 1977 xmlnode *x; |
1978 GaimAccount *account; | |
7153 | 1979 const char *acct_name, *proto, *mode, *protocol; |
7132 | 1980 |
1981 acct_name = xmlnode_get_attrib(anode, "name"); | |
7153 | 1982 protocol = xmlnode_get_attrib(anode, "protocol"); |
1983 proto = xmlnode_get_attrib(anode, "proto"); | |
7132 | 1984 mode = xmlnode_get_attrib(anode, "mode"); |
1985 | |
9285 | 1986 if (!acct_name || (!proto && !protocol) || !mode) |
7132 | 1987 continue; |
1988 | |
7153 | 1989 account = gaim_accounts_find(acct_name, proto ? proto : protocol); |
7132 | 1990 |
9285 | 1991 if (!account) |
7132 | 1992 continue; |
1993 | |
1994 account->perm_deny = atoi(mode); | |
1995 | |
9285 | 1996 for (x = anode->child; x; x = x->next) { |
7132 | 1997 char *name; |
9285 | 1998 if (x->type != XMLNODE_TYPE_TAG) |
7132 | 1999 continue; |
2000 | |
9285 | 2001 if (!strcmp(x->name, "permit")) { |
7132 | 2002 name = xmlnode_get_data(x); |
2003 gaim_privacy_permit_add(account, name, TRUE); | |
2004 g_free(name); | |
9285 | 2005 } else if (!strcmp(x->name, "block")) { |
7132 | 2006 name = xmlnode_get_data(x); |
2007 gaim_privacy_deny_add(account, name, TRUE); | |
2008 g_free(name); | |
2009 } | |
2010 } | |
2011 } | |
2012 } | |
5228 | 2013 |
2014 gaim_debug(GAIM_DEBUG_INFO, "blist import", "Finished reading %s\n", | |
2015 filename); | |
2016 | |
8200 | 2017 xmlnode_free(gaim); |
5228 | 2018 return TRUE; |
2019 } | |
2020 | |
9285 | 2021 void gaim_blist_load() |
2022 { | |
5228 | 2023 char *user_dir = gaim_user_dir(); |
2024 char *filename; | |
2025 char *msg; | |
2026 | |
2027 blist_safe_to_write = TRUE; | |
2028 | |
9285 | 2029 if (!user_dir) |
5228 | 2030 return; |
2031 | |
2032 filename = g_build_filename(user_dir, "blist.xml", NULL); | |
2033 | |
9285 | 2034 if (g_file_test(filename, G_FILE_TEST_EXISTS)) { |
2035 if (!gaim_blist_read(filename)) { | |
5228 | 2036 msg = g_strdup_printf(_("An error was encountered parsing your " |
8826 | 2037 "buddy list. It has not been loaded, " |
2038 "and the old file has moved to blist.xml~.")); | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
2039 gaim_notify_error(NULL, NULL, _("Buddy List Error"), msg); |
5228 | 2040 g_free(msg); |
2041 } | |
2042 } | |
2043 | |
2044 g_free(filename); | |
2045 } | |
2046 | |
7060
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2047 void |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2048 gaim_blist_request_add_buddy(GaimAccount *account, const char *username, |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2049 const char *group, const char *alias) |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2050 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2051 GaimBlistUiOps *ui_ops; |
7060
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2052 |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2053 ui_ops = gaim_blist_get_ui_ops(); |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2054 |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2055 if (ui_ops != NULL && ui_ops->request_add_buddy != NULL) |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2056 ui_ops->request_add_buddy(account, username, group, alias); |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2057 } |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2058 |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2059 void |
9754 | 2060 gaim_blist_request_add_chat(GaimAccount *account, GaimGroup *group, |
2061 const char *alias, const char *name) | |
7060
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2062 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2063 GaimBlistUiOps *ui_ops; |
7060
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2064 |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2065 ui_ops = gaim_blist_get_ui_ops(); |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2066 |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2067 if (ui_ops != NULL && ui_ops->request_add_chat != NULL) |
9754 | 2068 ui_ops->request_add_chat(account, group, alias, name); |
7060
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2069 } |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2070 |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2071 void |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2072 gaim_blist_request_add_group(void) |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2073 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2074 GaimBlistUiOps *ui_ops; |
7060
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2075 |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2076 ui_ops = gaim_blist_get_ui_ops(); |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2077 |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2078 if (ui_ops != NULL && ui_ops->request_add_group != NULL) |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2079 ui_ops->request_add_group(); |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2080 } |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2081 |
7693 | 2082 static void blist_print_setting(const char *key, |
2083 struct gaim_blist_node_setting *setting, FILE *file, int indent) | |
2084 { | |
2085 char *key_val, *data_val = NULL; | |
2086 const char *type = NULL; | |
2087 int i; | |
2088 | |
9285 | 2089 if (!key) |
7693 | 2090 return; |
2091 | |
2092 switch(setting->type) { | |
2093 case GAIM_BLIST_NODE_SETTING_BOOL: | |
2094 type = "bool"; | |
2095 data_val = g_strdup_printf("%d", setting->value.boolean); | |
2096 break; | |
2097 case GAIM_BLIST_NODE_SETTING_INT: | |
2098 type = "int"; | |
2099 data_val = g_strdup_printf("%d", setting->value.integer); | |
2100 break; | |
2101 case GAIM_BLIST_NODE_SETTING_STRING: | |
9285 | 2102 if (!setting->value.string) |
7693 | 2103 return; |
2104 | |
2105 type = "string"; | |
2106 data_val = g_markup_escape_text(setting->value.string, -1); | |
2107 break; | |
2108 } | |
2109 | |
2110 /* this can't happen */ | |
9285 | 2111 if (!type || !data_val) |
7693 | 2112 return; |
2113 | |
9285 | 2114 for (i=0; i<indent; i++) fprintf(file, "\t"); |
7693 | 2115 |
2116 key_val = g_markup_escape_text(key, -1); | |
2117 fprintf(file, "<setting name=\"%s\" type=\"%s\">%s</setting>\n", key_val, type, | |
2118 data_val); | |
2119 | |
2120 g_free(key_val); | |
2121 g_free(data_val); | |
2122 } | |
2123 | |
5228 | 2124 static void blist_print_group_settings(gpointer key, gpointer data, |
9285 | 2125 gpointer user_data) |
2126 { | |
7693 | 2127 blist_print_setting(key, data, user_data, 3); |
5228 | 2128 } |
2129 | |
2130 static void blist_print_buddy_settings(gpointer key, gpointer data, | |
9285 | 2131 gpointer user_data) |
2132 { | |
7693 | 2133 blist_print_setting(key, data, user_data, 5); |
5228 | 2134 } |
2135 | |
6695 | 2136 static void blist_print_cnode_settings(gpointer key, gpointer data, |
9285 | 2137 gpointer user_data) |
2138 { | |
7693 | 2139 blist_print_setting(key, data, user_data, 4); |
6695 | 2140 } |
2141 | |
5234 | 2142 static void blist_print_chat_components(gpointer key, gpointer data, |
2143 gpointer user_data) { | |
2144 char *key_val; | |
2145 char *data_val; | |
2146 FILE *file = user_data; | |
2147 | |
9285 | 2148 if (!key || !data) |
5234 | 2149 return; |
2150 | |
2151 key_val = g_markup_escape_text(key, -1); | |
2152 data_val = g_markup_escape_text(data, -1); | |
2153 | |
2154 fprintf(file, "\t\t\t\t<component name=\"%s\">%s</component>\n", key_val, | |
2155 data_val); | |
2156 g_free(key_val); | |
2157 g_free(data_val); | |
2158 } | |
2159 | |
9285 | 2160 static void print_buddy(FILE *file, GaimBuddy *buddy) |
2161 { | |
6695 | 2162 char *bud_name = g_markup_escape_text(buddy->name, -1); |
2163 char *bud_alias = NULL; | |
2164 char *acct_name = g_markup_escape_text(buddy->account->username, -1); | |
9285 | 2165 if (buddy->alias) |
6695 | 2166 bud_alias= g_markup_escape_text(buddy->alias, -1); |
9460 | 2167 fprintf(file, "\t\t\t\t<buddy account=\"%s\" proto=\"%s\">\n", acct_name, |
7153 | 2168 gaim_account_get_protocol_id(buddy->account)); |
2169 | |
6695 | 2170 fprintf(file, "\t\t\t\t\t<name>%s</name>\n", bud_name); |
9285 | 2171 if (bud_alias) { |
6695 | 2172 fprintf(file, "\t\t\t\t\t<alias>%s</alias>\n", bud_alias); |
2173 } | |
7726 | 2174 g_hash_table_foreach(buddy->node.settings, blist_print_buddy_settings, file); |
6695 | 2175 fprintf(file, "\t\t\t\t</buddy>\n"); |
2176 g_free(bud_name); | |
2177 g_free(bud_alias); | |
2178 g_free(acct_name); | |
2179 } | |
2180 | |
9787 | 2181 |
2182 /* check for flagging and account exclusion on buddy */ | |
2183 static gboolean blist_buddy_should_save(GaimAccount *exp_acct, GaimBuddy *buddy) | |
2184 { | |
2185 if (! GAIM_BLIST_NODE_SHOULD_SAVE((GaimBlistNode *) buddy)) | |
2186 return FALSE; | |
2187 | |
2188 if (exp_acct && buddy->account != exp_acct) | |
2189 return FALSE; | |
2190 | |
2191 return TRUE; | |
2192 } | |
2193 | |
2194 | |
2195 static void blist_write_buddy(FILE *file, GaimAccount *exp_acct, GaimBuddy *buddy) | |
2196 { | |
2197 if (blist_buddy_should_save(exp_acct, buddy)) | |
2198 print_buddy(file, buddy); | |
2199 } | |
2200 | |
2201 | |
2202 /* check for flagging and account exclusion on contact and all members */ | |
2203 static gboolean blist_contact_should_save(GaimAccount *exp_acct, GaimContact *contact) | |
2204 { | |
2205 GaimBlistNode *bnode, *cnode = (GaimBlistNode *) contact; | |
2206 | |
2207 if (! GAIM_BLIST_NODE_SHOULD_SAVE(cnode)) | |
2208 return FALSE; | |
2209 | |
2210 for (bnode = cnode->child; bnode; bnode = bnode->next) { | |
2211 if (! GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
2212 continue; | |
2213 | |
2214 if (blist_buddy_should_save(exp_acct, (GaimBuddy *) bnode)) | |
2215 return TRUE; | |
2216 } | |
2217 | |
2218 return FALSE; | |
2219 } | |
2220 | |
2221 | |
2222 static void blist_write_contact(FILE *file, GaimAccount *exp_acct, GaimContact *contact) | |
2223 { | |
2224 GaimBlistNode *bnode, *cnode = (GaimBlistNode *) contact; | |
2225 | |
2226 if (! blist_contact_should_save(exp_acct, contact)) | |
2227 return; | |
2228 | |
2229 fprintf(file, "\t\t\t<contact"); | |
2230 if (contact->alias) { | |
2231 char *alias = g_markup_escape_text(contact->alias, -1); | |
2232 fprintf(file, " alias=\"%s\"", alias); | |
2233 g_free(alias); | |
2234 } | |
2235 fprintf(file, ">\n"); | |
2236 | |
2237 for (bnode = cnode->child; bnode; bnode = bnode->next) { | |
2238 if (GAIM_BLIST_NODE_IS_BUDDY(bnode)) { | |
2239 blist_write_buddy(file, exp_acct, (GaimBuddy *) bnode); | |
2240 } | |
2241 } | |
2242 | |
2243 g_hash_table_foreach(cnode->settings, blist_print_cnode_settings, file); | |
2244 fprintf(file, "\t\t\t</contact>\n"); | |
2245 } | |
2246 | |
2247 | |
2248 static void blist_write_chat(FILE *file, GaimAccount *exp_acct, GaimChat *chat) | |
2249 { | |
2250 char *acct_name; | |
2251 | |
2252 if (! GAIM_BLIST_NODE_SHOULD_SAVE((GaimBlistNode *) chat)) | |
2253 return; | |
2254 | |
2255 if (exp_acct && chat->account != exp_acct) | |
2256 return; | |
2257 | |
2258 acct_name = g_markup_escape_text(chat->account->username, -1); | |
2259 fprintf(file, "\t\t\t<chat proto=\"%s\" account=\"%s\">\n", | |
2260 gaim_account_get_protocol_id(chat->account), acct_name); | |
2261 g_free(acct_name); | |
2262 | |
2263 if (chat->alias) { | |
2264 char *chat_alias = g_markup_escape_text(chat->alias, -1); | |
2265 fprintf(file, "\t\t\t\t<alias>%s</alias>\n", chat_alias); | |
2266 g_free(chat_alias); | |
2267 } | |
2268 | |
2269 g_hash_table_foreach(chat->components, blist_print_chat_components, file); | |
2270 g_hash_table_foreach(chat->node.settings, blist_print_cnode_settings, file); | |
2271 | |
2272 fprintf(file, "\t\t\t</chat>\n"); | |
2273 } | |
2274 | |
2275 | |
2276 static void blist_write_group(FILE *file, GaimAccount *exp_acct, GaimGroup *group) | |
2277 { | |
2278 GaimBlistNode *cnode, *gnode = (GaimBlistNode *) group; | |
2279 char *group_name; | |
2280 | |
2281 if (! GAIM_BLIST_NODE_SHOULD_SAVE(gnode)) | |
2282 return; | |
2283 | |
2284 if (exp_acct && ! gaim_group_on_account(group, exp_acct)) | |
2285 return; | |
2286 | |
2287 group_name = g_markup_escape_text(group->name, -1); | |
2288 fprintf(file, "\t\t<group name=\"%s\">\n", group_name); | |
2289 g_free(group_name); | |
2290 | |
2291 g_hash_table_foreach(group->node.settings, | |
2292 blist_print_group_settings, file); | |
2293 | |
2294 for (cnode = gnode->child; cnode; cnode = cnode->next) { | |
2295 if (GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
2296 blist_write_contact(file, exp_acct, (GaimContact *) cnode); | |
2297 } else if (GAIM_BLIST_NODE_IS_CHAT(cnode)) { | |
2298 blist_write_chat(file, exp_acct, (GaimChat *) cnode); | |
2299 } | |
2300 } | |
2301 | |
2302 fprintf(file, "\t\t</group>\n"); | |
2303 } | |
2304 | |
2305 | |
2306 static void blist_write_privacy_account(FILE *file, GaimAccount *exp_acct, GaimAccount *account) | |
2307 { | |
2308 char *acct_name; | |
2309 GSList *buds; | |
2310 | |
2311 if(exp_acct && exp_acct != account) | |
2312 return; | |
2313 | |
2314 acct_name = g_markup_escape_text(account->username, -1); | |
2315 fprintf(file, "\t\t<account proto=\"%s\" name=\"%s\" mode=\"%d\">\n", | |
2316 gaim_account_get_protocol_id(account), | |
2317 acct_name, account->perm_deny); | |
2318 g_free(acct_name); | |
2319 | |
2320 for (buds = account->permit; buds; buds = buds->next) { | |
2321 char *bud_name = g_markup_escape_text(buds->data, -1); | |
2322 fprintf(file, "\t\t\t<permit>%s</permit>\n", bud_name); | |
2323 g_free(bud_name); | |
2324 } | |
2325 | |
2326 for (buds = account->deny; buds; buds = buds->next) { | |
2327 char *bud_name = g_markup_escape_text(buds->data, -1); | |
2328 fprintf(file, "\t\t\t<block>%s</block>\n", bud_name); | |
2329 g_free(bud_name); | |
2330 } | |
2331 | |
2332 fprintf(file, "\t\t</account>\n"); | |
2333 } | |
2334 | |
2335 | |
9285 | 2336 static void gaim_blist_write(FILE *file, GaimAccount *exp_acct) |
2337 { | |
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2338 GList *accounts; |
9787 | 2339 GaimBlistNode *gnode; |
2340 | |
5228 | 2341 fprintf(file, "<?xml version='1.0' encoding='UTF-8' ?>\n"); |
2342 fprintf(file, "<gaim version=\"1\">\n"); | |
2343 fprintf(file, "\t<blist>\n"); | |
2344 | |
9285 | 2345 for (gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { |
9787 | 2346 if (GAIM_BLIST_NODE_IS_GROUP(gnode)) |
2347 blist_write_group(file, exp_acct, (GaimGroup *) gnode); | |
5228 | 2348 } |
2349 | |
2350 fprintf(file, "\t</blist>\n"); | |
2351 fprintf(file, "\t<privacy>\n"); | |
2352 | |
9787 | 2353 for (accounts = gaim_accounts_get_all(); accounts; accounts = accounts->next) { |
2354 blist_write_privacy_account(file, exp_acct, (GaimAccount *) accounts->data); | |
5228 | 2355 } |
2356 | |
2357 fprintf(file, "\t</privacy>\n"); | |
2358 fprintf(file, "</gaim>\n"); | |
2359 } | |
2360 | |
9787 | 2361 |
9285 | 2362 void gaim_blist_sync() |
2363 { | |
5228 | 2364 FILE *file; |
2365 char *user_dir = gaim_user_dir(); | |
2366 char *filename; | |
2367 char *filename_real; | |
2368 | |
9285 | 2369 if (!user_dir) |
5228 | 2370 return; |
9285 | 2371 |
2372 if (!blist_safe_to_write) { | |
5228 | 2373 gaim_debug(GAIM_DEBUG_WARNING, "blist save", |
2374 "AHH!! Tried to write the blist before we read it!\n"); | |
2375 return; | |
2376 } | |
2377 | |
2378 file = fopen(user_dir, "r"); | |
9285 | 2379 if (!file) |
5228 | 2380 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); |
2381 else | |
2382 fclose(file); | |
2383 | |
2384 filename = g_build_filename(user_dir, "blist.xml.save", NULL); | |
2385 | |
9285 | 2386 if ((file = fopen(filename, "w"))) { |
5228 | 2387 gaim_blist_write(file, NULL); |
2388 fclose(file); | |
2389 chmod(filename, S_IRUSR | S_IWUSR); | |
2390 } else { | |
2391 gaim_debug(GAIM_DEBUG_ERROR, "blist save", "Unable to write %s\n", | |
2392 filename); | |
8549 | 2393 g_free(filename); |
2394 return; | |
5228 | 2395 } |
2396 | |
2397 filename_real = g_build_filename(user_dir, "blist.xml", NULL); | |
2398 | |
9285 | 2399 if (rename(filename, filename_real) < 0) |
5228 | 2400 gaim_debug(GAIM_DEBUG_ERROR, "blist save", |
2401 "Error renaming %s to %s\n", filename, filename_real); | |
2402 | |
2403 | |
2404 g_free(filename); | |
2405 g_free(filename_real); | |
2406 } | |
2407 | |
7693 | 2408 |
2409 static void gaim_blist_node_setting_free(struct gaim_blist_node_setting *setting) | |
2410 { | |
2411 switch(setting->type) { | |
2412 case GAIM_BLIST_NODE_SETTING_BOOL: | |
2413 case GAIM_BLIST_NODE_SETTING_INT: | |
2414 break; | |
2415 case GAIM_BLIST_NODE_SETTING_STRING: | |
2416 g_free(setting->value.string); | |
2417 break; | |
2418 } | |
8020 | 2419 g_free(setting); |
7693 | 2420 } |
2421 | |
9285 | 2422 static void gaim_blist_node_initialize_settings(GaimBlistNode *node) |
7693 | 2423 { |
9285 | 2424 if (node->settings) |
5228 | 2425 return; |
7693 | 2426 |
2427 node->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, | |
2428 (GDestroyNotify)gaim_blist_node_setting_free); | |
2429 } | |
2430 | |
2431 void gaim_blist_node_remove_setting(GaimBlistNode *node, const char *key) | |
2432 { | |
2433 g_return_if_fail(node != NULL); | |
2434 g_return_if_fail(node->settings != NULL); | |
2435 g_return_if_fail(key != NULL); | |
2436 | |
2437 g_hash_table_remove(node->settings, key); | |
9285 | 2438 |
2439 schedule_blist_save(); | |
5228 | 2440 } |
2441 | |
7693 | 2442 |
2443 void gaim_blist_node_set_bool(GaimBlistNode* node, const char *key, gboolean value) | |
2444 { | |
2445 struct gaim_blist_node_setting *setting; | |
2446 | |
2447 g_return_if_fail(node != NULL); | |
2448 g_return_if_fail(node->settings != NULL); | |
2449 g_return_if_fail(key != NULL); | |
2450 | |
2451 setting = g_new0(struct gaim_blist_node_setting, 1); | |
2452 setting->type = GAIM_BLIST_NODE_SETTING_BOOL; | |
2453 setting->value.boolean = value; | |
2454 | |
2455 g_hash_table_replace(node->settings, g_strdup(key), setting); | |
9285 | 2456 |
2457 schedule_blist_save(); | |
7693 | 2458 } |
2459 | |
2460 gboolean gaim_blist_node_get_bool(GaimBlistNode* node, const char *key) | |
2461 { | |
2462 struct gaim_blist_node_setting *setting; | |
2463 | |
2464 g_return_val_if_fail(node != NULL, FALSE); | |
2465 g_return_val_if_fail(node->settings != NULL, FALSE); | |
2466 g_return_val_if_fail(key != NULL, FALSE); | |
2467 | |
2468 setting = g_hash_table_lookup(node->settings, key); | |
2469 | |
9285 | 2470 if (!setting) |
7849 | 2471 return FALSE; |
2472 | |
7848 | 2473 g_return_val_if_fail(setting->type == GAIM_BLIST_NODE_SETTING_BOOL, FALSE); |
2474 | |
2475 return setting->value.boolean; | |
5228 | 2476 } |
2477 | |
7693 | 2478 void gaim_blist_node_set_int(GaimBlistNode* node, const char *key, int value) |
2479 { | |
2480 struct gaim_blist_node_setting *setting; | |
2481 | |
2482 g_return_if_fail(node != NULL); | |
2483 g_return_if_fail(node->settings != NULL); | |
2484 g_return_if_fail(key != NULL); | |
2485 | |
2486 setting = g_new0(struct gaim_blist_node_setting, 1); | |
8071 | 2487 setting->type = GAIM_BLIST_NODE_SETTING_INT; |
7693 | 2488 setting->value.integer = value; |
2489 | |
2490 g_hash_table_replace(node->settings, g_strdup(key), setting); | |
9285 | 2491 |
2492 schedule_blist_save(); | |
7693 | 2493 } |
2494 | |
2495 int gaim_blist_node_get_int(GaimBlistNode* node, const char *key) | |
2496 { | |
2497 struct gaim_blist_node_setting *setting; | |
2498 | |
2499 g_return_val_if_fail(node != NULL, 0); | |
2500 g_return_val_if_fail(node->settings != NULL, 0); | |
2501 g_return_val_if_fail(key != NULL, 0); | |
2502 | |
2503 setting = g_hash_table_lookup(node->settings, key); | |
2504 | |
9285 | 2505 if (!setting) |
7849 | 2506 return 0; |
2507 | |
7848 | 2508 g_return_val_if_fail(setting->type == GAIM_BLIST_NODE_SETTING_INT, 0); |
2509 | |
2510 return setting->value.integer; | |
7693 | 2511 } |
2512 | |
2513 void gaim_blist_node_set_string(GaimBlistNode* node, const char *key, | |
5906 | 2514 const char *value) |
2515 { | |
7693 | 2516 struct gaim_blist_node_setting *setting; |
2517 | |
2518 g_return_if_fail(node != NULL); | |
2519 g_return_if_fail(node->settings != NULL); | |
2520 g_return_if_fail(key != NULL); | |
2521 | |
2522 setting = g_new0(struct gaim_blist_node_setting, 1); | |
2523 setting->type = GAIM_BLIST_NODE_SETTING_STRING; | |
2524 setting->value.string = g_strdup(value); | |
2525 | |
2526 g_hash_table_replace(node->settings, g_strdup(key), setting); | |
9285 | 2527 |
2528 schedule_blist_save(); | |
7693 | 2529 } |
2530 | |
2531 const char *gaim_blist_node_get_string(GaimBlistNode* node, const char *key) | |
2532 { | |
2533 struct gaim_blist_node_setting *setting; | |
2534 | |
2535 g_return_val_if_fail(node != NULL, NULL); | |
2536 g_return_val_if_fail(node->settings != NULL, NULL); | |
2537 g_return_val_if_fail(key != NULL, NULL); | |
2538 | |
2539 setting = g_hash_table_lookup(node->settings, key); | |
2540 | |
9285 | 2541 if (!setting) |
7849 | 2542 return NULL; |
2543 | |
7848 | 2544 g_return_val_if_fail(setting->type == GAIM_BLIST_NODE_SETTING_STRING, NULL); |
2545 | |
2546 return setting->value.string; | |
7693 | 2547 } |
2548 | |
9285 | 2549 GList *gaim_blist_node_get_extended_menu(GaimBlistNode *n) |
7693 | 2550 { |
8710
36b043fe2740
[gaim-migrate @ 9464]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
2551 GList *menu = NULL; |
9030 | 2552 |
2553 g_return_val_if_fail(n, NULL); | |
2554 | |
2555 gaim_signal_emit(gaim_blist_get_handle(), | |
2556 "blist-node-extended-menu", | |
2557 n, &menu); | |
8710
36b043fe2740
[gaim-migrate @ 9464]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
2558 return menu; |
36b043fe2740
[gaim-migrate @ 9464]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
2559 } |
36b043fe2740
[gaim-migrate @ 9464]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
2560 |
9030 | 2561 |
2562 GaimBlistNodeAction * | |
2563 gaim_blist_node_action_new(char *label, | |
2564 void (*callback)(GaimBlistNode *, gpointer), | |
2565 gpointer data) | |
2566 { | |
2567 GaimBlistNodeAction *act = g_new0(GaimBlistNodeAction, 1); | |
2568 act->label = label; | |
2569 act->callback = callback; | |
2570 act->data = data; | |
2571 return act; | |
8952 | 2572 } |
2573 | |
8710
36b043fe2740
[gaim-migrate @ 9464]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
2574 |
9285 | 2575 int gaim_blist_get_group_size(GaimGroup *group, gboolean offline) |
2576 { | |
2577 if (!group) | |
5228 | 2578 return 0; |
2579 | |
5277 | 2580 return offline ? group->totalsize : group->currentsize; |
5228 | 2581 } |
2582 | |
9285 | 2583 int gaim_blist_get_group_online_count(GaimGroup *group) |
2584 { | |
2585 if (!group) | |
5228 | 2586 return 0; |
2587 | |
5277 | 2588 return group->online; |
5228 | 2589 } |
2590 | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2591 void |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2592 gaim_blist_set_ui_ops(GaimBlistUiOps *ops) |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2593 { |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2594 blist_ui_ops = ops; |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2595 } |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2596 |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2597 GaimBlistUiOps * |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2598 gaim_blist_get_ui_ops(void) |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2599 { |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2600 return blist_ui_ops; |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2601 } |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2602 |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2603 |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2604 void * |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2605 gaim_blist_get_handle(void) |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2606 { |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2607 static int handle; |
5228 | 2608 |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2609 return &handle; |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2610 } |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2611 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2612 void |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2613 gaim_blist_init(void) |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2614 { |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2615 void *handle = gaim_blist_get_handle(); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2616 |
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2617 gaim_signal_register(handle, "buddy-away", |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2618 gaim_marshal_VOID__POINTER, NULL, 1, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2619 gaim_value_new(GAIM_TYPE_SUBTYPE, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2620 GAIM_SUBTYPE_BLIST_BUDDY)); |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2621 |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2622 gaim_signal_register(handle, "buddy-back", |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2623 gaim_marshal_VOID__POINTER, NULL, 1, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2624 gaim_value_new(GAIM_TYPE_SUBTYPE, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2625 GAIM_SUBTYPE_BLIST_BUDDY)); |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2626 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2627 gaim_signal_register(handle, "buddy-idle", |
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2628 gaim_marshal_VOID__POINTER, NULL, 1, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2629 gaim_value_new(GAIM_TYPE_SUBTYPE, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2630 GAIM_SUBTYPE_BLIST_BUDDY)); |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2631 gaim_signal_register(handle, "buddy-unidle", |
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2632 gaim_marshal_VOID__POINTER, NULL, 1, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2633 gaim_value_new(GAIM_TYPE_SUBTYPE, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2634 GAIM_SUBTYPE_BLIST_BUDDY)); |
9109
9f21659ecf11
[gaim-migrate @ 9886]
Christian Hammond <chipx86@chipx86.com>
parents:
9030
diff
changeset
|
2635 gaim_signal_register(handle, "buddy-idle-updated", |
9f21659ecf11
[gaim-migrate @ 9886]
Christian Hammond <chipx86@chipx86.com>
parents:
9030
diff
changeset
|
2636 gaim_marshal_VOID__POINTER, NULL, 1, |
9f21659ecf11
[gaim-migrate @ 9886]
Christian Hammond <chipx86@chipx86.com>
parents:
9030
diff
changeset
|
2637 gaim_value_new(GAIM_TYPE_SUBTYPE, |
9f21659ecf11
[gaim-migrate @ 9886]
Christian Hammond <chipx86@chipx86.com>
parents:
9030
diff
changeset
|
2638 GAIM_SUBTYPE_BLIST_BUDDY)); |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2639 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2640 gaim_signal_register(handle, "buddy-signed-on", |
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2641 gaim_marshal_VOID__POINTER, NULL, 1, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2642 gaim_value_new(GAIM_TYPE_SUBTYPE, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2643 GAIM_SUBTYPE_BLIST_BUDDY)); |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2644 |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2645 gaim_signal_register(handle, "buddy-signed-off", |
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2646 gaim_marshal_VOID__POINTER, NULL, 1, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2647 gaim_value_new(GAIM_TYPE_SUBTYPE, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2648 GAIM_SUBTYPE_BLIST_BUDDY)); |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2649 |
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2650 gaim_signal_register(handle, "update-idle", gaim_marshal_VOID, NULL, 0); |
9030 | 2651 |
2652 gaim_signal_register(handle, "blist-node-extended-menu", | |
8710
36b043fe2740
[gaim-migrate @ 9464]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
2653 gaim_marshal_VOID__POINTER_POINTER, NULL, 2, |
36b043fe2740
[gaim-migrate @ 9464]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
2654 gaim_value_new(GAIM_TYPE_SUBTYPE, |
9030 | 2655 GAIM_SUBTYPE_BLIST_NODE), |
8952 | 2656 gaim_value_new(GAIM_TYPE_BOXED, "GList **")); |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2657 } |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2658 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2659 void |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2660 gaim_blist_uninit(void) |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2661 { |
9285 | 2662 if (blist_save_timer != 0) { |
2663 gaim_timeout_remove(blist_save_timer); | |
2664 blist_save_timer = 0; | |
2665 gaim_blist_sync(); | |
2666 } | |
2667 | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2668 gaim_signals_unregister_by_instance(gaim_blist_get_handle()); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2669 } |