Mercurial > pidgin
annotate src/blist.c @ 5947:ac4dd1d0ee39
[gaim-migrate @ 6388]
Moved the gtk main loop stuff over to glib's.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Mon, 23 Jun 2003 07:09:30 +0000 |
parents | a4f2aba0848d |
children | 60d9cbfb6bf8 |
rev | line source |
---|---|
5228 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 2003, Sean Egan <sean.egan@binghamton.edu> | |
5 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 * | |
21 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
22 #include "internal.h" |
5228 | 23 #include "blist.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
24 #include "conversation.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
25 #include "debug.h" |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
26 #include "notify.h" |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
27 #include "prefs.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
28 #include "privacy.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
29 #include "prpl.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
30 #include "server.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
31 #include "util.h" |
5228 | 32 |
33 #define PATHSIZE 1024 | |
34 | |
35 struct gaim_buddy_list *gaimbuddylist = NULL; | |
36 static struct gaim_blist_ui_ops *blist_ui_ops = NULL; | |
37 | |
38 /***************************************************************************** | |
39 * Private Utility functions * | |
40 *****************************************************************************/ | |
41 static GaimBlistNode *gaim_blist_get_last_sibling(GaimBlistNode *node) | |
42 { | |
43 GaimBlistNode *n = node; | |
44 if (!n) | |
45 return NULL; | |
46 while (n->next) | |
47 n = n->next; | |
48 return n; | |
49 } | |
50 static GaimBlistNode *gaim_blist_get_last_child(GaimBlistNode *node) | |
51 { | |
52 if (!node) | |
53 return NULL; | |
54 return gaim_blist_get_last_sibling(node->child); | |
55 } | |
56 | |
5247 | 57 struct _gaim_hbuddy { |
58 char *name; | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
59 GaimAccount *account; |
5758 | 60 GaimBlistNode *group; |
5247 | 61 }; |
62 | |
63 static guint _gaim_blist_hbuddy_hash (struct _gaim_hbuddy *hb) | |
64 { | |
65 return g_str_hash(hb->name); | |
66 } | |
67 | |
68 static guint _gaim_blist_hbuddy_equal (struct _gaim_hbuddy *hb1, struct _gaim_hbuddy *hb2) | |
69 { | |
5758 | 70 return ((!strcmp(hb1->name, hb2->name)) && hb1->account == hb2->account && hb1->group == hb2->group); |
5247 | 71 } |
72 | |
5228 | 73 /***************************************************************************** |
74 * Public API functions * | |
75 *****************************************************************************/ | |
76 | |
77 struct gaim_buddy_list *gaim_blist_new() | |
78 { | |
79 struct gaim_buddy_list *gbl = g_new0(struct gaim_buddy_list, 1); | |
80 | |
81 gbl->ui_ops = gaim_get_blist_ui_ops(); | |
82 | |
5247 | 83 gbl->buddies = g_hash_table_new ((GHashFunc)_gaim_blist_hbuddy_hash, |
84 (GEqualFunc)_gaim_blist_hbuddy_equal); | |
85 | |
5228 | 86 if (gbl->ui_ops != NULL && gbl->ui_ops->new_list != NULL) |
87 gbl->ui_ops->new_list(gbl); | |
88 | |
89 return gbl; | |
90 } | |
91 | |
92 void | |
93 gaim_set_blist(struct gaim_buddy_list *list) | |
94 { | |
95 gaimbuddylist = list; | |
96 } | |
97 | |
98 struct gaim_buddy_list * | |
99 gaim_get_blist(void) | |
100 { | |
101 return gaimbuddylist; | |
102 } | |
103 | |
104 void gaim_blist_show () | |
105 { | |
106 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
107 if (ops) | |
108 ops->show(gaimbuddylist); | |
109 } | |
110 | |
111 void gaim_blist_destroy() | |
112 { | |
113 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
114 if (ops) | |
115 ops->destroy(gaimbuddylist); | |
116 } | |
117 | |
118 void gaim_blist_set_visible (gboolean show) | |
119 { | |
120 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
121 if (ops) | |
122 ops->set_visible(gaimbuddylist, show); | |
123 } | |
124 | |
125 void gaim_blist_update_buddy_status (struct buddy *buddy, int status) | |
126 { | |
5266
b3a03b86b09b
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
127 struct gaim_blist_ui_ops *ops; |
b3a03b86b09b
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
128 |
b3a03b86b09b
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
129 if (buddy->uc == status) |
b3a03b86b09b
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
130 return; |
b3a03b86b09b
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
131 |
b3a03b86b09b
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
132 ops = gaimbuddylist->ui_ops; |
5228 | 133 |
5305 | 134 if((status & UC_UNAVAILABLE) != (buddy->uc & UC_UNAVAILABLE)) { |
135 if(status & UC_UNAVAILABLE) | |
136 gaim_event_broadcast(event_buddy_away, buddy->account->gc, buddy->name); | |
137 else | |
138 gaim_event_broadcast(event_buddy_back, buddy->account->gc, buddy->name); | |
139 } | |
5228 | 140 |
5305 | 141 buddy->uc = status; |
5228 | 142 if (ops) |
143 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
144 } | |
145 | |
146 static gboolean presence_update_timeout_cb(struct buddy *buddy) { | |
147 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
148 | |
149 if(buddy->present == GAIM_BUDDY_SIGNING_ON) { | |
150 buddy->present = GAIM_BUDDY_ONLINE; | |
151 gaim_event_broadcast(event_buddy_signon, buddy->account->gc, buddy->name); | |
152 } else if(buddy->present == GAIM_BUDDY_SIGNING_OFF) { | |
153 buddy->present = GAIM_BUDDY_OFFLINE; | |
154 } | |
155 | |
156 buddy->timer = 0; | |
157 | |
158 if (ops) | |
159 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
160 | |
161 return FALSE; | |
162 } | |
163 | |
164 void gaim_blist_update_buddy_presence(struct buddy *buddy, int presence) { | |
165 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
166 gboolean do_timer = FALSE; | |
167 | |
168 if (!GAIM_BUDDY_IS_ONLINE(buddy) && presence) { | |
169 buddy->present = GAIM_BUDDY_SIGNING_ON; | |
170 gaim_event_broadcast(event_buddy_signon, buddy->account->gc, buddy->name); | |
171 do_timer = TRUE; | |
5277 | 172 ((struct group *)((GaimBlistNode *)buddy)->parent)->online++; |
5228 | 173 } else if(GAIM_BUDDY_IS_ONLINE(buddy) && !presence) { |
174 buddy->present = GAIM_BUDDY_SIGNING_OFF; | |
175 gaim_event_broadcast(event_buddy_signoff, buddy->account->gc, buddy->name); | |
176 do_timer = TRUE; | |
5394 | 177 ((struct group *)((GaimBlistNode *)buddy)->parent)->online--; |
5228 | 178 } |
179 | |
180 if(do_timer) { | |
181 if(buddy->timer > 0) | |
182 g_source_remove(buddy->timer); | |
183 buddy->timer = g_timeout_add(10000, (GSourceFunc)presence_update_timeout_cb, buddy); | |
184 } | |
185 | |
186 if (ops) | |
187 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
188 } | |
189 | |
190 | |
191 void gaim_blist_update_buddy_idle (struct buddy *buddy, int idle) | |
192 { | |
193 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
194 buddy->idle = idle; | |
195 if (ops) | |
196 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
197 } | |
198 void gaim_blist_update_buddy_evil (struct buddy *buddy, int warning) | |
199 { | |
200 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
201 buddy->evil = warning; | |
202 if (ops) | |
203 ops->update(gaimbuddylist,(GaimBlistNode*)buddy); | |
204 } | |
205 void gaim_blist_update_buddy_icon(struct buddy *buddy) { | |
206 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
207 if(ops) | |
208 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
209 } | |
210 void gaim_blist_rename_buddy (struct buddy *buddy, const char *name) | |
211 { | |
212 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
5634 | 213 g_free(buddy->name); |
5228 | 214 buddy->name = g_strdup(name); |
215 if (ops) | |
216 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
217 } | |
5234 | 218 |
219 void gaim_blist_alias_chat(struct chat *chat, const char *alias) | |
220 { | |
221 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
222 | |
5237 | 223 g_free(chat->alias); |
5234 | 224 |
5237 | 225 if(alias && strlen(alias)) |
226 chat->alias = g_strdup(alias); | |
227 else | |
228 chat->alias = NULL; | |
229 | |
5234 | 230 if(ops) |
231 ops->update(gaimbuddylist, (GaimBlistNode*)chat); | |
232 } | |
233 | |
5228 | 234 void gaim_blist_alias_buddy (struct buddy *buddy, const char *alias) |
235 { | |
236 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5634
diff
changeset
|
237 GaimConversation *conv; |
5228 | 238 |
239 g_free(buddy->alias); | |
240 | |
241 if(alias && strlen(alias)) | |
242 buddy->alias = g_strdup(alias); | |
243 else | |
244 buddy->alias = NULL; | |
245 | |
246 if (ops) | |
247 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
248 | |
249 conv = gaim_find_conversation_with_account(buddy->name, buddy->account); | |
250 | |
251 if (conv) | |
252 gaim_conversation_autoset_title(conv); | |
253 } | |
254 | |
255 void gaim_blist_rename_group(struct group *group, const char *name) | |
256 { | |
257 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
5346 | 258 struct group *dest_group; |
259 GaimBlistNode *prev, *child, *next; | |
260 GSList *accts; | |
261 | |
262 if(!name || !strlen(name) || !strcmp(name, group->name)) { | |
263 /* nothing to do here */ | |
264 return; | |
265 } else if((dest_group = gaim_find_group(name))) { | |
266 /* here we're merging two groups */ | |
267 prev = gaim_blist_get_last_child((GaimBlistNode*)dest_group); | |
268 child = ((GaimBlistNode*)group)->child; | |
269 | |
270 while(child) | |
271 { | |
272 next = child->next; | |
273 if(GAIM_BLIST_NODE_IS_BUDDY(child)) { | |
274 gaim_blist_add_buddy((struct buddy *)child, dest_group, prev); | |
275 prev = child; | |
276 } else if(GAIM_BLIST_NODE_IS_CHAT(child)) { | |
277 gaim_blist_add_chat((struct chat *)child, dest_group, prev); | |
278 prev = child; | |
279 } else { | |
280 gaim_debug(GAIM_DEBUG_ERROR, "blist", | |
281 "Unknown child type in group %s\n", group->name); | |
282 } | |
283 child = next; | |
284 } | |
285 for (accts = gaim_group_get_accounts(group); accts; accts = g_slist_remove(accts, accts->data)) { | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
286 GaimAccount *account = accts->data; |
5346 | 287 serv_rename_group(account->gc, group, name); |
288 } | |
289 gaim_blist_remove_group(group); | |
290 } else { | |
291 /* a simple rename */ | |
292 for (accts = gaim_group_get_accounts(group); accts; accts = g_slist_remove(accts, accts->data)) { | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
293 GaimAccount *account = accts->data; |
5346 | 294 serv_rename_group(account->gc, group, name); |
295 } | |
296 g_free(group->name); | |
297 group->name = g_strdup(name); | |
298 if (ops) | |
299 ops->update(gaimbuddylist, (GaimBlistNode*)group); | |
300 } | |
5228 | 301 } |
5234 | 302 |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
303 struct chat *gaim_chat_new(GaimAccount *account, const char *alias, GHashTable *components) |
5234 | 304 { |
305 struct chat *chat; | |
306 struct gaim_blist_ui_ops *ops; | |
307 | |
5237 | 308 if(!components) |
5234 | 309 return NULL; |
310 | |
311 chat = g_new0(struct chat, 1); | |
312 chat->account = account; | |
5237 | 313 if(alias && strlen(alias)) |
314 chat->alias = g_strdup(alias); | |
5234 | 315 chat->components = components; |
5906 | 316 chat->settings = g_hash_table_new_full(g_str_hash, g_str_equal, |
317 g_free, g_free); | |
5234 | 318 |
319 ((GaimBlistNode*)chat)->type = GAIM_BLIST_CHAT_NODE; | |
320 | |
321 ops = gaim_get_blist_ui_ops(); | |
322 | |
323 if (ops != NULL && ops->new_node != NULL) | |
324 ops->new_node((GaimBlistNode *)chat); | |
325 | |
326 return chat; | |
327 } | |
328 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
329 struct buddy *gaim_buddy_new(GaimAccount *account, const char *screenname, const char *alias) |
5228 | 330 { |
331 struct buddy *b; | |
332 struct gaim_blist_ui_ops *ops; | |
333 | |
334 b = g_new0(struct buddy, 1); | |
335 b->account = account; | |
336 b->name = g_strdup(screenname); | |
337 b->alias = g_strdup(alias); | |
338 b->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
339 ((GaimBlistNode*)b)->type = GAIM_BLIST_BUDDY_NODE; | |
340 | |
341 ops = gaim_get_blist_ui_ops(); | |
342 | |
343 if (ops != NULL && ops->new_node != NULL) | |
344 ops->new_node((GaimBlistNode *)b); | |
345 | |
346 return b; | |
347 } | |
5634 | 348 |
5234 | 349 void gaim_blist_add_chat(struct chat *chat, struct group *group, GaimBlistNode *node) |
350 { | |
351 GaimBlistNode *n = node, *cnode = (GaimBlistNode*)chat; | |
352 struct group *g = group; | |
353 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
354 gboolean save = FALSE; | |
355 | |
356 if (!n) { | |
357 if (!g) { | |
358 g = gaim_group_new(_("Chats")); | |
5634 | 359 gaim_blist_add_group(g, |
360 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
5234 | 361 } |
362 } else { | |
363 g = (struct group*)n->parent; | |
364 } | |
365 | |
366 /* if we're moving to overtop of ourselves, do nothing */ | |
367 if(cnode == n) | |
368 return; | |
369 | |
370 if (cnode->parent) { | |
371 /* This chat was already in the list and is | |
372 * being moved. | |
373 */ | |
5277 | 374 ((struct group *)cnode->parent)->totalsize--; |
5855 | 375 if (gaim_account_is_connected(chat->account)) { |
5287 | 376 ((struct group *)cnode->parent)->online--; |
5277 | 377 ((struct group *)cnode->parent)->currentsize--; |
5287 | 378 } |
5234 | 379 if(cnode->next) |
380 cnode->next->prev = cnode->prev; | |
381 if(cnode->prev) | |
382 cnode->prev->next = cnode->next; | |
383 if(cnode->parent->child == cnode) | |
384 cnode->parent->child = cnode->next; | |
385 | |
386 ops->remove(gaimbuddylist, cnode); | |
387 | |
388 save = TRUE; | |
389 } | |
390 | |
391 if (n) { | |
392 if(n->next) | |
393 n->next->prev = cnode; | |
394 cnode->next = n->next; | |
395 cnode->prev = n; | |
396 cnode->parent = n->parent; | |
397 n->next = cnode; | |
5277 | 398 ((struct group *)n->parent)->totalsize++; |
5855 | 399 if (gaim_account_is_connected(chat->account)) { |
5287 | 400 ((struct group *)n->parent)->online++; |
5277 | 401 ((struct group *)n->parent)->currentsize++; |
5287 | 402 } |
5234 | 403 } else { |
5634 | 404 if(((GaimBlistNode*)g)->child) |
405 ((GaimBlistNode*)g)->child->prev = cnode; | |
406 cnode->next = ((GaimBlistNode*)g)->child; | |
407 cnode->prev = NULL; | |
5234 | 408 ((GaimBlistNode*)g)->child = cnode; |
409 cnode->parent = (GaimBlistNode*)g; | |
5277 | 410 g->totalsize++; |
5855 | 411 if (gaim_account_is_connected(chat->account)) { |
5287 | 412 g->online++; |
5277 | 413 g->currentsize++; |
5287 | 414 } |
5234 | 415 } |
416 | |
417 if (ops) | |
418 ops->update(gaimbuddylist, (GaimBlistNode*)cnode); | |
419 if (save) | |
420 gaim_blist_save(); | |
421 } | |
422 | |
5228 | 423 void gaim_blist_add_buddy (struct buddy *buddy, struct group *group, GaimBlistNode *node) |
424 { | |
425 GaimBlistNode *n = node, *bnode = (GaimBlistNode*)buddy; | |
426 struct group *g = group; | |
427 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
5247 | 428 struct _gaim_hbuddy *hb; |
5228 | 429 gboolean save = FALSE; |
430 | |
431 if (!n) { | |
432 if (!g) { | |
433 g = gaim_group_new(_("Buddies")); | |
5634 | 434 gaim_blist_add_group(g, |
435 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
5228 | 436 } |
437 } else { | |
438 g = (struct group*)n->parent; | |
439 } | |
440 | |
441 /* if we're moving to overtop of ourselves, do nothing */ | |
442 if(bnode == n) | |
443 return; | |
444 | |
445 if (bnode->parent) { | |
446 /* This buddy was already in the list and is | |
447 * being moved. | |
448 */ | |
5394 | 449 ((struct group *)bnode->parent)->totalsize--; |
5855 | 450 if (gaim_account_is_connected(buddy->account)) |
5277 | 451 ((struct group *)bnode->parent)->currentsize--; |
5394 | 452 if (GAIM_BUDDY_IS_ONLINE(buddy)) |
5313 | 453 ((struct group *)bnode->parent)->online--; |
5277 | 454 |
5228 | 455 if(bnode->next) |
456 bnode->next->prev = bnode->prev; | |
457 if(bnode->prev) | |
458 bnode->prev->next = bnode->next; | |
459 if(bnode->parent->child == bnode) | |
460 bnode->parent->child = bnode->next; | |
461 | |
462 ops->remove(gaimbuddylist, bnode); | |
463 | |
5277 | 464 if (bnode->parent != ((GaimBlistNode*)g)) { |
5228 | 465 serv_move_buddy(buddy, (struct group*)bnode->parent, g); |
5277 | 466 } |
5228 | 467 save = TRUE; |
468 } | |
469 | |
470 if (n) { | |
471 if(n->next) | |
472 n->next->prev = (GaimBlistNode*)buddy; | |
473 ((GaimBlistNode*)buddy)->next = n->next; | |
474 ((GaimBlistNode*)buddy)->prev = n; | |
475 ((GaimBlistNode*)buddy)->parent = n->parent; | |
476 n->next = (GaimBlistNode*)buddy; | |
5277 | 477 ((struct group *)n->parent)->totalsize++; |
5855 | 478 if (gaim_account_is_connected(buddy->account)) |
5277 | 479 ((struct group *)n->parent)->currentsize++; |
5394 | 480 if (GAIM_BUDDY_IS_ONLINE(buddy)) |
5313 | 481 ((struct group *)n->parent)->online++; |
5228 | 482 } else { |
5634 | 483 if(((GaimBlistNode*)g)->child) |
484 ((GaimBlistNode*)g)->child->prev = (GaimBlistNode*)buddy; | |
485 ((GaimBlistNode*)buddy)->prev = NULL; | |
486 ((GaimBlistNode*)buddy)->next = ((GaimBlistNode*)g)->child; | |
5228 | 487 ((GaimBlistNode*)g)->child = (GaimBlistNode*)buddy; |
488 ((GaimBlistNode*)buddy)->parent = (GaimBlistNode*)g; | |
5277 | 489 g->totalsize++; |
5855 | 490 if (gaim_account_is_connected(buddy->account)) |
5277 | 491 g->currentsize++; |
5394 | 492 if (GAIM_BUDDY_IS_ONLINE(buddy)) |
5313 | 493 g->online++; |
5228 | 494 } |
495 | |
5247 | 496 hb = g_malloc(sizeof(struct _gaim_hbuddy)); |
497 hb->name = g_strdup(normalize(buddy->name)); | |
498 hb->account = buddy->account; | |
5758 | 499 hb->group = ((GaimBlistNode*)buddy)->parent; |
5247 | 500 |
501 if (g_hash_table_lookup(gaimbuddylist->buddies, (gpointer)hb)) { | |
502 /* This guy already exists */ | |
503 g_free(hb->name); | |
504 g_free(hb); | |
505 } else { | |
506 g_hash_table_insert(gaimbuddylist->buddies, (gpointer)hb, (gpointer)buddy); | |
507 } | |
508 | |
5228 | 509 if (ops) |
510 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
511 if (save) | |
512 gaim_blist_save(); | |
513 } | |
514 | |
515 struct group *gaim_group_new(const char *name) | |
516 { | |
517 struct group *g = gaim_find_group(name); | |
518 | |
519 if (!g) { | |
520 struct gaim_blist_ui_ops *ops; | |
521 g= g_new0(struct group, 1); | |
522 g->name = g_strdup(name); | |
5277 | 523 g->totalsize = 0; |
524 g->currentsize = 0; | |
525 g->online = 0; | |
5228 | 526 g->settings = g_hash_table_new_full(g_str_hash, g_str_equal, |
527 g_free, g_free); | |
528 ((GaimBlistNode*)g)->type = GAIM_BLIST_GROUP_NODE; | |
529 | |
530 ops = gaim_get_blist_ui_ops(); | |
531 | |
532 if (ops != NULL && ops->new_node != NULL) | |
533 ops->new_node((GaimBlistNode *)g); | |
534 | |
535 } | |
536 return g; | |
537 } | |
538 | |
539 void gaim_blist_add_group (struct group *group, GaimBlistNode *node) | |
540 { | |
541 struct gaim_blist_ui_ops *ops; | |
542 GaimBlistNode *gnode = (GaimBlistNode*)group; | |
543 gboolean save = FALSE; | |
544 | |
545 if (!gaimbuddylist) | |
546 gaimbuddylist = gaim_blist_new(); | |
547 ops = gaimbuddylist->ui_ops; | |
548 | |
549 if (!gaimbuddylist->root) { | |
550 gaimbuddylist->root = gnode; | |
551 return; | |
552 } | |
553 | |
554 /* if we're moving to overtop of ourselves, do nothing */ | |
555 if(gnode == node) | |
556 return; | |
557 | |
558 if (gaim_find_group(group->name)) { | |
559 /* This is just being moved */ | |
560 | |
561 ops->remove(gaimbuddylist, (GaimBlistNode*)group); | |
562 | |
563 if(gnode == gaimbuddylist->root) | |
564 gaimbuddylist->root = gnode->next; | |
565 if(gnode->prev) | |
566 gnode->prev->next = gnode->next; | |
567 if(gnode->next) | |
568 gnode->next->prev = gnode->prev; | |
569 | |
570 save = TRUE; | |
571 } | |
572 | |
5634 | 573 if (node) { |
574 gnode->next = node->next; | |
575 gnode->prev = node; | |
576 if(node->next) | |
577 node->next->prev = gnode; | |
578 node->next = gnode; | |
579 } else { | |
580 gaimbuddylist->root->prev = gnode; | |
581 gnode->next = gaimbuddylist->root; | |
582 gnode->prev = NULL; | |
583 gaimbuddylist->root = gnode; | |
584 } | |
585 | |
5228 | 586 |
587 if (ops) { | |
588 ops->update(gaimbuddylist, gnode); | |
589 for(node = gnode->child; node; node = node->next) | |
590 ops->update(gaimbuddylist, node); | |
591 } | |
592 if (save) | |
593 gaim_blist_save(); | |
594 } | |
595 | |
596 void gaim_blist_remove_buddy (struct buddy *buddy) | |
597 { | |
598 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
599 | |
600 GaimBlistNode *gnode, *node = (GaimBlistNode*)buddy; | |
601 struct group *group; | |
5247 | 602 struct _gaim_hbuddy hb, *key; |
603 struct buddy *val; | |
5228 | 604 |
605 gnode = node->parent; | |
606 group = (struct group *)gnode; | |
607 | |
608 if(gnode->child == node) | |
609 gnode->child = node->next; | |
610 if (node->prev) | |
611 node->prev->next = node->next; | |
612 if (node->next) | |
613 node->next->prev = node->prev; | |
5394 | 614 group->totalsize--; |
5855 | 615 if (gaim_account_is_connected(buddy->account)) |
5277 | 616 group->currentsize--; |
5394 | 617 if (GAIM_BUDDY_IS_ONLINE(buddy)) |
618 group->online--; | |
5228 | 619 |
5247 | 620 hb.name = normalize(buddy->name); |
621 hb.account = buddy->account; | |
5758 | 622 hb.group = ((GaimBlistNode*)buddy)->parent; |
5247 | 623 if (g_hash_table_lookup_extended(gaimbuddylist->buddies, &hb, (gpointer *)&key, (gpointer *)&val)) { |
624 g_hash_table_remove(gaimbuddylist->buddies, &hb); | |
625 g_free(key->name); | |
626 g_free(key); | |
627 } | |
628 | |
5292 | 629 if(buddy->timer > 0) |
630 g_source_remove(buddy->timer); | |
631 | |
5228 | 632 ops->remove(gaimbuddylist, node); |
633 g_hash_table_destroy(buddy->settings); | |
634 g_free(buddy->name); | |
635 g_free(buddy->alias); | |
636 g_free(buddy); | |
637 } | |
638 | |
5234 | 639 void gaim_blist_remove_chat (struct chat *chat) |
640 { | |
641 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
642 | |
643 GaimBlistNode *gnode, *node = (GaimBlistNode*)chat; | |
644 struct group *group; | |
645 | |
646 gnode = node->parent; | |
647 group = (struct group *)gnode; | |
648 | |
649 if(gnode->child == node) | |
650 gnode->child = node->next; | |
651 if (node->prev) | |
652 node->prev->next = node->next; | |
653 if (node->next) | |
654 node->next->prev = node->prev; | |
5277 | 655 group->totalsize--; |
5855 | 656 if (gaim_account_is_connected(chat->account)) { |
5277 | 657 group->currentsize--; |
5394 | 658 group->online--; |
659 } | |
5234 | 660 |
661 ops->remove(gaimbuddylist, node); | |
662 g_hash_table_destroy(chat->components); | |
663 g_free(chat->alias); | |
664 g_free(chat); | |
665 } | |
666 | |
5228 | 667 void gaim_blist_remove_group (struct group *group) |
668 { | |
669 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
670 GaimBlistNode *node = (GaimBlistNode*)group; | |
671 | |
672 if(node->child) { | |
673 char *buf; | |
674 int count = 0; | |
675 GaimBlistNode *child = node->child; | |
676 | |
677 while(child) { | |
678 count++; | |
679 child = child->next; | |
680 } | |
681 | |
682 buf = g_strdup_printf(_("%d buddies from group %s were not " | |
683 "removed because their accounts were not logged in. These " | |
5541
aee0ee458974
[gaim-migrate @ 5941]
Christian Hammond <chipx86@chipx86.com>
parents:
5436
diff
changeset
|
684 "buddies and the group were not removed.\n"), |
5228 | 685 count, group->name); |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
686 |
5541
aee0ee458974
[gaim-migrate @ 5941]
Christian Hammond <chipx86@chipx86.com>
parents:
5436
diff
changeset
|
687 gaim_notify_error(NULL, NULL, _("Group not removed"), buf); |
5228 | 688 g_free(buf); |
689 return; | |
690 } | |
691 | |
692 if(gaimbuddylist->root == node) | |
693 gaimbuddylist->root = node->next; | |
694 if (node->prev) | |
695 node->prev->next = node->next; | |
696 if (node->next) | |
697 node->next->prev = node->prev; | |
698 | |
699 ops->remove(gaimbuddylist, node); | |
700 g_free(group->name); | |
701 g_free(group); | |
702 } | |
703 | |
704 char *gaim_get_buddy_alias_only(struct buddy *b) { | |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
705 if(!b) |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
706 return NULL; |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
707 |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
708 if(b->alias && b->alias[0]) { |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
709 return b->alias; |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
710 } |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
711 else if (b->server_alias != NULL && |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
712 gaim_prefs_get_bool("/core/buddies/use_server_alias")) { |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
713 |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
714 return b->server_alias; |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
715 } |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
716 |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
717 return NULL; |
5228 | 718 } |
719 | |
720 char * gaim_get_buddy_alias (struct buddy *buddy) | |
721 { | |
722 char *ret = gaim_get_buddy_alias_only(buddy); | |
723 if(!ret) | |
724 return buddy ? buddy->name : _("Unknown"); | |
725 return ret; | |
726 | |
727 } | |
728 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
729 struct buddy *gaim_find_buddy(GaimAccount *account, const char *name) |
5228 | 730 { |
5758 | 731 static struct buddy *buddy = NULL; |
5247 | 732 struct _gaim_hbuddy hb; |
5758 | 733 GaimBlistNode *group; |
734 const char *n = NULL; | |
5228 | 735 |
736 if (!gaimbuddylist) | |
737 return NULL; | |
5758 | 738 |
739 if (!name && !buddy); | |
5228 | 740 |
5758 | 741 if (name) { |
742 group = gaimbuddylist->root; | |
743 n = name; | |
744 } else { | |
745 group = ((GaimBlistNode*)buddy)->parent->next; | |
746 n = buddy->name; | |
747 } | |
5247 | 748 |
5758 | 749 while (group) { |
750 hb.name = normalize(n); | |
751 hb.account = account; | |
752 hb.group = group; | |
5776 | 753 if ((buddy = g_hash_table_lookup(gaimbuddylist->buddies, &hb)) != NULL) |
5758 | 754 return buddy; |
755 group = ((GaimBlistNode*)group)->next; | |
756 } | |
757 return NULL; | |
5228 | 758 } |
759 | |
760 struct group *gaim_find_group(const char *name) | |
761 { | |
762 GaimBlistNode *node; | |
763 if (!gaimbuddylist) | |
764 return NULL; | |
765 node = gaimbuddylist->root; | |
766 while(node) { | |
767 if (!strcmp(((struct group*)node)->name, name)) | |
768 return (struct group*)node; | |
769 node = node->next; | |
770 } | |
771 return NULL; | |
772 } | |
773 struct group *gaim_find_buddys_group(struct buddy *buddy) | |
774 { | |
775 if (!buddy) | |
776 return NULL; | |
777 return (struct group*)(((GaimBlistNode*)buddy)->parent); | |
778 } | |
779 | |
780 GSList *gaim_group_get_accounts(struct group *g) | |
781 { | |
782 GSList *l = NULL; | |
783 GaimBlistNode *child = ((GaimBlistNode *)g)->child; | |
784 | |
785 while (child) { | |
786 if (!g_slist_find(l, ((struct buddy*)child)->account)) | |
787 l = g_slist_append(l, ((struct buddy*)child)->account); | |
788 child = child->next; | |
789 } | |
790 return l; | |
791 } | |
792 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
793 void gaim_blist_add_account(GaimAccount *account) |
5234 | 794 { |
795 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
796 GaimBlistNode *group, *buddy; | |
797 | |
798 if(!gaimbuddylist) | |
799 return; | |
800 | |
801 for(group = gaimbuddylist->root; group; group = group->next) { | |
802 if(!GAIM_BLIST_NODE_IS_GROUP(group)) | |
803 continue; | |
804 for(buddy = group->child; buddy; buddy = buddy->next) { | |
805 if(GAIM_BLIST_NODE_IS_BUDDY(buddy)) { | |
806 if (account == ((struct buddy*)buddy)->account) { | |
5277 | 807 ((struct group *)group)->currentsize++; |
5234 | 808 if(ops) |
809 ops->update(gaimbuddylist, buddy); | |
810 } | |
811 } else if(GAIM_BLIST_NODE_IS_CHAT(buddy)) { | |
812 if (account == ((struct chat*)buddy)->account) { | |
5287 | 813 ((struct group *)group)->online++; |
5277 | 814 ((struct group *)group)->currentsize++; |
5234 | 815 if(ops) |
816 ops->update(gaimbuddylist, buddy); | |
817 } | |
818 } | |
819 } | |
820 } | |
821 } | |
822 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
823 void gaim_blist_remove_account(GaimAccount *account) |
5228 | 824 { |
825 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
5234 | 826 GaimBlistNode *group, *buddy; |
827 | |
5228 | 828 if (!gaimbuddylist) |
829 return; | |
5234 | 830 |
831 for(group = gaimbuddylist->root; group; group = group->next) { | |
832 if(!GAIM_BLIST_NODE_IS_GROUP(group)) | |
833 continue; | |
834 for(buddy = group->child; buddy; buddy = buddy->next) { | |
835 if(GAIM_BLIST_NODE_IS_BUDDY(buddy)) { | |
836 if (account == ((struct buddy*)buddy)->account) { | |
5394 | 837 if (GAIM_BUDDY_IS_ONLINE((struct buddy*)buddy)) |
5277 | 838 ((struct group *)group)->online--; |
5234 | 839 ((struct buddy*)buddy)->present = GAIM_BUDDY_OFFLINE; |
5394 | 840 ((struct group *)group)->currentsize--; |
5234 | 841 if(ops) |
842 ops->remove(gaimbuddylist, buddy); | |
843 } | |
844 } else if(GAIM_BLIST_NODE_IS_CHAT(buddy)) { | |
845 if (account == ((struct chat*)buddy)->account) { | |
5277 | 846 ((struct group *)group)->online--; |
847 ((struct group *)group)->currentsize--; | |
5234 | 848 if(ops) |
849 ops->remove(gaimbuddylist, buddy); | |
850 } | |
5228 | 851 } |
852 } | |
853 } | |
854 } | |
855 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
856 void parse_toc_buddy_list(GaimAccount *account, char *config) |
5228 | 857 { |
858 char *c; | |
859 char current[256]; | |
860 GList *bud = NULL; | |
861 | |
862 | |
863 if (config != NULL) { | |
864 | |
865 /* skip "CONFIG:" (if it exists) */ | |
866 c = strncmp(config + 6 /* sizeof(struct sflap_hdr) */ , "CONFIG:", strlen("CONFIG:")) ? | |
867 strtok(config, "\n") : | |
868 strtok(config + 6 /* sizeof(struct sflap_hdr) */ + strlen("CONFIG:"), "\n"); | |
869 do { | |
870 if (c == NULL) | |
871 break; | |
872 if (*c == 'g') { | |
873 char *utf8 = NULL; | |
874 utf8 = gaim_try_conv_to_utf8(c + 2); | |
875 if (utf8 == NULL) { | |
876 g_strlcpy(current, _("Invalid Groupname"), sizeof(current)); | |
877 } else { | |
878 g_strlcpy(current, utf8, sizeof(current)); | |
879 g_free(utf8); | |
880 } | |
881 if (!gaim_find_group(current)) { | |
882 struct group *g = gaim_group_new(current); | |
5634 | 883 gaim_blist_add_group(g, |
884 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
5228 | 885 } |
886 } else if (*c == 'b') { /*&& !gaim_find_buddy(user, c + 2)) {*/ | |
887 char nm[80], sw[388], *a, *utf8 = NULL; | |
888 | |
889 if ((a = strchr(c + 2, ':')) != NULL) { | |
890 *a++ = '\0'; /* nul the : */ | |
891 } | |
892 | |
893 g_strlcpy(nm, c + 2, sizeof(nm)); | |
894 if (a) { | |
895 utf8 = gaim_try_conv_to_utf8(a); | |
896 if (utf8 == NULL) { | |
897 gaim_debug(GAIM_DEBUG_ERROR, "toc blist", | |
898 "Failed to convert alias for " | |
899 "'%s' to UTF-8\n", nm); | |
900 } | |
901 } | |
902 if (utf8 == NULL) { | |
903 sw[0] = '\0'; | |
904 } else { | |
905 /* This can leave a partial sequence at the end, | |
906 * but who cares? */ | |
907 g_strlcpy(sw, utf8, sizeof(sw)); | |
908 g_free(utf8); | |
909 } | |
910 | |
911 if (!gaim_find_buddy(account, nm)) { | |
912 struct buddy *b = gaim_buddy_new(account, nm, sw); | |
913 struct group *g = gaim_find_group(current); | |
5634 | 914 gaim_blist_add_buddy(b, g, |
915 gaim_blist_get_last_child((GaimBlistNode*)g)); | |
5228 | 916 bud = g_list_append(bud, g_strdup(nm)); |
917 } | |
918 } else if (*c == 'p') { | |
919 gaim_privacy_permit_add(account, c + 2); | |
920 } else if (*c == 'd') { | |
921 gaim_privacy_deny_add(account, c + 2); | |
922 } else if (!strncmp("toc", c, 3)) { | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
923 sscanf(c + strlen(c) - 1, "%d", &account->perm_deny); |
5228 | 924 gaim_debug(GAIM_DEBUG_MISC, "toc blist", |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
925 "permdeny: %d\n", account->perm_deny); |
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
926 if (account->perm_deny == 0) |
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
927 account->perm_deny = 1; |
5228 | 928 } else if (*c == 'm') { |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
929 sscanf(c + 2, "%d", &account->perm_deny); |
5228 | 930 gaim_debug(GAIM_DEBUG_MISC, "toc blist", |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
931 "permdeny: %d\n", account->perm_deny); |
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
932 if (account->perm_deny == 0) |
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
933 account->perm_deny = 1; |
5228 | 934 } |
935 } while ((c = strtok(NULL, "\n"))); | |
936 | |
937 if(account->gc) { | |
938 if(bud) { | |
939 GList *node = bud; | |
940 serv_add_buddies(account->gc, bud); | |
941 while(node) { | |
942 g_free(node->data); | |
943 node = node->next; | |
944 } | |
945 } | |
946 serv_set_permit_deny(account->gc); | |
947 } | |
948 g_list_free(bud); | |
949 } | |
950 } | |
951 | |
952 #if 0 | |
953 /* translate an AIM 3 buddylist (*.lst) to a Gaim buddylist */ | |
954 static GString *translate_lst(FILE *src_fp) | |
955 { | |
956 char line[BUF_LEN], *line2; | |
957 char *name; | |
958 int i; | |
959 | |
960 GString *dest = g_string_new("m 1\n"); | |
961 | |
962 while (fgets(line, BUF_LEN, src_fp)) { | |
963 line2 = g_strchug(line); | |
964 if (strstr(line2, "group") == line2) { | |
965 name = strpbrk(line2, " \t\n\r\f") + 1; | |
966 dest = g_string_append(dest, "g "); | |
967 for (i = 0; i < strcspn(name, "\n\r"); i++) | |
968 if (name[i] != '\"') | |
969 dest = g_string_append_c(dest, name[i]); | |
970 dest = g_string_append_c(dest, '\n'); | |
971 } | |
972 if (strstr(line2, "buddy") == line2) { | |
973 name = strpbrk(line2, " \t\n\r\f") + 1; | |
974 dest = g_string_append(dest, "b "); | |
975 for (i = 0; i < strcspn(name, "\n\r"); i++) | |
976 if (name[i] != '\"') | |
977 dest = g_string_append_c(dest, name[i]); | |
978 dest = g_string_append_c(dest, '\n'); | |
979 } | |
980 } | |
981 | |
982 return dest; | |
983 } | |
984 | |
985 | |
986 /* translate an AIM 4 buddylist (*.blt) to Gaim format */ | |
987 static GString *translate_blt(FILE *src_fp) | |
988 { | |
989 int i; | |
990 char line[BUF_LEN]; | |
991 char *buddy; | |
992 | |
993 GString *dest = g_string_new("m 1\n"); | |
994 | |
995 while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL); | |
996 while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL); | |
997 | |
998 while (1) { | |
999 fgets(line, BUF_LEN, src_fp); g_strchomp(line); | |
1000 if (strchr(line, '}') != NULL) | |
1001 break; | |
1002 | |
1003 if (strchr(line, '{') != NULL) { | |
1004 /* Syntax starting with "<group> {" */ | |
1005 | |
1006 dest = g_string_append(dest, "g "); | |
1007 buddy = g_strchug(strtok(line, "{")); | |
1008 for (i = 0; i < strlen(buddy); i++) | |
1009 if (buddy[i] != '\"') | |
1010 dest = g_string_append_c(dest, buddy[i]); | |
1011 dest = g_string_append_c(dest, '\n'); | |
1012 while (strchr(fgets(line, BUF_LEN, src_fp), '}') == NULL) { | |
1013 gboolean pounce = FALSE; | |
1014 char *e; | |
1015 g_strchomp(line); | |
1016 buddy = g_strchug(line); | |
1017 gaim_debug(GAIM_DEBUG_MISC, "AIM 4 blt import", | |
1018 "buddy: \"%s\"\n", buddy); | |
1019 dest = g_string_append(dest, "b "); | |
1020 if (strchr(buddy, '{') != NULL) { | |
1021 /* buddy pounce, etc */ | |
1022 char *pos = strchr(buddy, '{') - 1; | |
1023 *pos = 0; | |
1024 pounce = TRUE; | |
1025 } | |
1026 if ((e = strchr(buddy, '\"')) != NULL) { | |
1027 *e = '\0'; | |
1028 buddy++; | |
1029 } | |
1030 dest = g_string_append(dest, buddy); | |
1031 dest = g_string_append_c(dest, '\n'); | |
1032 if (pounce) | |
1033 do | |
1034 fgets(line, BUF_LEN, src_fp); | |
1035 while (!strchr(line, '}')); | |
1036 } | |
1037 } else { | |
1038 | |
1039 /* Syntax "group buddy buddy ..." */ | |
1040 buddy = g_strchug(strtok(line, " \n")); | |
1041 dest = g_string_append(dest, "g "); | |
1042 if (strchr(buddy, '\"') != NULL) { | |
1043 dest = g_string_append(dest, &buddy[1]); | |
1044 dest = g_string_append_c(dest, ' '); | |
1045 buddy = g_strchug(strtok(NULL, " \n")); | |
1046 while (strchr(buddy, '\"') == NULL) { | |
1047 dest = g_string_append(dest, buddy); | |
1048 dest = g_string_append_c(dest, ' '); | |
1049 buddy = g_strchug(strtok(NULL, " \n")); | |
1050 } | |
1051 buddy[strlen(buddy) - 1] = '\0'; | |
1052 dest = g_string_append(dest, buddy); | |
1053 } else { | |
1054 dest = g_string_append(dest, buddy); | |
1055 } | |
1056 dest = g_string_append_c(dest, '\n'); | |
1057 while ((buddy = g_strchug(strtok(NULL, " \n"))) != NULL) { | |
1058 dest = g_string_append(dest, "b "); | |
1059 if (strchr(buddy, '\"') != NULL) { | |
1060 dest = g_string_append(dest, &buddy[1]); | |
1061 dest = g_string_append_c(dest, ' '); | |
1062 buddy = g_strchug(strtok(NULL, " \n")); | |
1063 while (strchr(buddy, '\"') == NULL) { | |
1064 dest = g_string_append(dest, buddy); | |
1065 dest = g_string_append_c(dest, ' '); | |
1066 buddy = g_strchug(strtok(NULL, " \n")); | |
1067 } | |
1068 buddy[strlen(buddy) - 1] = '\0'; | |
1069 dest = g_string_append(dest, buddy); | |
1070 } else { | |
1071 dest = g_string_append(dest, buddy); | |
1072 } | |
1073 dest = g_string_append_c(dest, '\n'); | |
1074 } | |
1075 } | |
1076 } | |
1077 | |
1078 return dest; | |
1079 } | |
1080 | |
1081 static GString *translate_gnomeicu(FILE *src_fp) | |
1082 { | |
1083 char line[BUF_LEN]; | |
1084 GString *dest = g_string_new("m 1\ng Buddies\n"); | |
1085 | |
1086 while (strstr(fgets(line, BUF_LEN, src_fp), "NewContacts") == NULL); | |
1087 | |
1088 while (fgets(line, BUF_LEN, src_fp)) { | |
1089 char *eq; | |
1090 g_strchomp(line); | |
1091 if (line[0] == '\n' || line[0] == '[') | |
1092 break; | |
1093 eq = strchr(line, '='); | |
1094 if (!eq) | |
1095 break; | |
1096 *eq = ':'; | |
1097 eq = strchr(eq, ','); | |
1098 if (eq) | |
1099 *eq = '\0'; | |
1100 dest = g_string_append(dest, "b "); | |
1101 dest = g_string_append(dest, line); | |
1102 dest = g_string_append_c(dest, '\n'); | |
1103 } | |
1104 | |
1105 return dest; | |
1106 } | |
1107 #endif | |
1108 | |
1109 static gchar *get_screenname_filename(const char *name) | |
1110 { | |
1111 gchar **split; | |
1112 gchar *good; | |
1113 gchar *ret; | |
1114 | |
1115 split = g_strsplit(name, G_DIR_SEPARATOR_S, -1); | |
1116 good = g_strjoinv(NULL, split); | |
1117 g_strfreev(split); | |
1118 | |
1119 ret = g_utf8_strup(good, -1); | |
1120 | |
1121 g_free(good); | |
1122 | |
1123 return ret; | |
1124 } | |
1125 | |
1126 static gboolean gaim_blist_read(const char *filename); | |
1127 | |
1128 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1129 static void do_import(GaimAccount *account, const char *filename) |
5228 | 1130 { |
1131 GString *buf = NULL; | |
1132 char first[64]; | |
1133 char path[PATHSIZE]; | |
1134 int len; | |
1135 FILE *f; | |
1136 struct stat st; | |
1137 | |
1138 if (filename) { | |
1139 g_snprintf(path, sizeof(path), "%s", filename); | |
1140 } else { | |
1141 char *g_screenname = get_screenname_filename(account->username); | |
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1142 const char *username; |
5228 | 1143 char *file = gaim_user_dir(); |
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1144 GaimProtocol prpl_num; |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1145 int protocol; |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1146 |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1147 prpl_num = gaim_account_get_protocol(account); |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1148 |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1149 protocol = prpl_num; |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1150 |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1151 if (prpl_num == GAIM_PROTO_OSCAR) { |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1152 if ((username = gaim_account_get_username(account)) != NULL) { |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1153 protocol = (isalpha(*username) |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1154 ? GAIM_PROTO_TOC : GAIM_PROTO_ICQ); |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1155 } |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1156 } |
5228 | 1157 |
1158 if (file != (char *)NULL) { | |
5435 | 1159 snprintf(path, PATHSIZE, "%s" G_DIR_SEPARATOR_S "%s.%d.blist", file, g_screenname, protocol); |
5228 | 1160 g_free(g_screenname); |
1161 } else { | |
1162 g_free(g_screenname); | |
1163 return; | |
1164 } | |
1165 } | |
1166 | |
1167 if (stat(path, &st)) { | |
1168 gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Unable to stat %s.\n", | |
1169 path); | |
1170 return; | |
1171 } | |
1172 | |
1173 if (!(f = fopen(path, "r"))) { | |
1174 gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Unable to open %s.\n", | |
1175 path); | |
1176 return; | |
1177 } | |
1178 | |
1179 fgets(first, 64, f); | |
1180 | |
1181 if ((first[0] == '\n') || (first[0] == '\r' && first[1] == '\n')) | |
1182 fgets(first, 64, f); | |
1183 | |
1184 #if 0 | |
1185 if (!g_strncasecmp(first, "<xml", strlen("<xml"))) { | |
1186 /* new gaim XML buddy list */ | |
1187 gaim_blist_read(path); | |
1188 | |
1189 /* We really don't need to bother doing stuf like translating AIM 3 buddy lists anymore */ | |
1190 | |
1191 } else if (!g_strncasecmp(first, "Config {", strlen("Config {"))) { | |
1192 /* AIM 4 buddy list */ | |
1193 gaim_debug(GAIM_DEBUG_MISC, "blist import", "aim 4\n"); | |
1194 rewind(f); | |
1195 buf = translate_blt(f); | |
1196 } else if (strstr(first, "group") != NULL) { | |
1197 /* AIM 3 buddy list */ | |
1198 gaim_debug(GAIM_DEBUG_MISC, "blist import", "aim 3\n"); | |
1199 rewind(f); | |
1200 buf = translate_lst(f); | |
1201 } else if (!g_strncasecmp(first, "[User]", strlen("[User]"))) { | |
1202 /* GnomeICU (hopefully) */ | |
1203 gaim_debug(GAIM_DEBUG_MISC, "blist import", "gnomeicu\n"); | |
1204 rewind(f); | |
1205 buf = translate_gnomeicu(f); | |
1206 | |
1207 } else | |
1208 #endif | |
1209 if (first[0] == 'm') { | |
1210 /* Gaim buddy list - no translation */ | |
1211 char buf2[BUF_LONG * 2]; | |
1212 buf = g_string_new(""); | |
1213 rewind(f); | |
1214 while (1) { | |
1215 len = fread(buf2, 1, BUF_LONG * 2 - 1, f); | |
1216 if (len <= 0) | |
1217 break; | |
1218 buf2[len] = '\0'; | |
1219 buf = g_string_append(buf, buf2); | |
1220 if (len != BUF_LONG * 2 - 1) | |
1221 break; | |
1222 } | |
1223 } | |
1224 | |
1225 fclose(f); | |
1226 | |
1227 if (buf) { | |
1228 buf = g_string_prepend(buf, "toc_set_config {"); | |
1229 buf = g_string_append(buf, "}\n"); | |
1230 parse_toc_buddy_list(account, buf->str); | |
1231 g_string_free(buf, TRUE); | |
1232 } | |
1233 } | |
1234 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1235 gboolean gaim_group_on_account(struct group *g, GaimAccount *account) { |
5228 | 1236 GaimBlistNode *bnode; |
1237 for(bnode = g->node.child; bnode; bnode = bnode->next) { | |
1238 struct buddy *b = (struct buddy *)bnode; | |
1239 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
1240 continue; | |
5855 | 1241 if((!account && gaim_account_is_connected(b->account)) |
1242 || b->account == account) | |
5228 | 1243 return TRUE; |
1244 } | |
1245 return FALSE; | |
1246 } | |
1247 | |
1248 static gboolean blist_safe_to_write = FALSE; | |
1249 | |
1250 static char *blist_parser_group_name = NULL; | |
1251 static char *blist_parser_person_name = NULL; | |
1252 static char *blist_parser_account_name = NULL; | |
1253 static int blist_parser_account_protocol = 0; | |
5234 | 1254 static char *blist_parser_chat_alias = NULL; |
1255 static char *blist_parser_component_name = NULL; | |
1256 static char *blist_parser_component_value = NULL; | |
5228 | 1257 static char *blist_parser_buddy_name = NULL; |
1258 static char *blist_parser_buddy_alias = NULL; | |
1259 static char *blist_parser_setting_name = NULL; | |
1260 static char *blist_parser_setting_value = NULL; | |
1261 static GHashTable *blist_parser_buddy_settings = NULL; | |
5906 | 1262 static GHashTable *blist_parser_chat_settings = NULL; |
5228 | 1263 static GHashTable *blist_parser_group_settings = NULL; |
5234 | 1264 static GHashTable *blist_parser_chat_components = NULL; |
5228 | 1265 static int blist_parser_privacy_mode = 0; |
1266 static GList *tag_stack = NULL; | |
1267 enum { | |
1268 BLIST_TAG_GAIM, | |
1269 BLIST_TAG_BLIST, | |
1270 BLIST_TAG_GROUP, | |
5234 | 1271 BLIST_TAG_CHAT, |
1272 BLIST_TAG_COMPONENT, | |
5228 | 1273 BLIST_TAG_PERSON, |
1274 BLIST_TAG_BUDDY, | |
1275 BLIST_TAG_NAME, | |
1276 BLIST_TAG_ALIAS, | |
1277 BLIST_TAG_SETTING, | |
1278 BLIST_TAG_PRIVACY, | |
1279 BLIST_TAG_ACCOUNT, | |
1280 BLIST_TAG_PERMIT, | |
1281 BLIST_TAG_BLOCK, | |
1282 BLIST_TAG_IGNORE | |
1283 }; | |
1284 static gboolean blist_parser_error_occurred = FALSE; | |
1285 | |
1286 static void blist_start_element_handler (GMarkupParseContext *context, | |
1287 const gchar *element_name, | |
1288 const gchar **attribute_names, | |
1289 const gchar **attribute_values, | |
1290 gpointer user_data, | |
1291 GError **error) { | |
1292 int i; | |
1293 | |
1294 if(!strcmp(element_name, "gaim")) { | |
1295 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_GAIM)); | |
1296 } else if(!strcmp(element_name, "blist")) { | |
1297 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BLIST)); | |
1298 } else if(!strcmp(element_name, "group")) { | |
1299 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_GROUP)); | |
1300 for(i=0; attribute_names[i]; i++) { | |
1301 if(!strcmp(attribute_names[i], "name")) { | |
1302 g_free(blist_parser_group_name); | |
1303 blist_parser_group_name = g_strdup(attribute_values[i]); | |
1304 } | |
1305 } | |
1306 if(blist_parser_group_name) { | |
1307 struct group *g = gaim_group_new(blist_parser_group_name); | |
5634 | 1308 gaim_blist_add_group(g, |
1309 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
5228 | 1310 } |
5234 | 1311 } else if(!strcmp(element_name, "chat")) { |
1312 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_CHAT)); | |
1313 for(i=0; attribute_names[i]; i++) { | |
1314 if(!strcmp(attribute_names[i], "account")) { | |
1315 g_free(blist_parser_account_name); | |
1316 blist_parser_account_name = g_strdup(attribute_values[i]); | |
1317 } else if(!strcmp(attribute_names[i], "protocol")) { | |
1318 blist_parser_account_protocol = atoi(attribute_values[i]); | |
1319 } | |
1320 } | |
5228 | 1321 } else if(!strcmp(element_name, "person")) { |
1322 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PERSON)); | |
1323 for(i=0; attribute_names[i]; i++) { | |
1324 if(!strcmp(attribute_names[i], "name")) { | |
1325 g_free(blist_parser_person_name); | |
1326 blist_parser_person_name = g_strdup(attribute_values[i]); | |
1327 } | |
1328 } | |
1329 } else if(!strcmp(element_name, "buddy")) { | |
1330 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BUDDY)); | |
1331 for(i=0; attribute_names[i]; i++) { | |
1332 if(!strcmp(attribute_names[i], "account")) { | |
1333 g_free(blist_parser_account_name); | |
1334 blist_parser_account_name = g_strdup(attribute_values[i]); | |
1335 } else if(!strcmp(attribute_names[i], "protocol")) { | |
1336 blist_parser_account_protocol = atoi(attribute_values[i]); | |
1337 } | |
1338 } | |
1339 } else if(!strcmp(element_name, "name")) { | |
1340 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_NAME)); | |
1341 } else if(!strcmp(element_name, "alias")) { | |
1342 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_ALIAS)); | |
1343 } else if(!strcmp(element_name, "setting")) { | |
1344 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_SETTING)); | |
1345 for(i=0; attribute_names[i]; i++) { | |
1346 if(!strcmp(attribute_names[i], "name")) { | |
1347 g_free(blist_parser_setting_name); | |
1348 blist_parser_setting_name = g_strdup(attribute_values[i]); | |
1349 } | |
1350 } | |
5234 | 1351 } else if(!strcmp(element_name, "component")) { |
1352 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_COMPONENT)); | |
1353 for(i=0; attribute_names[i]; i++) { | |
1354 if(!strcmp(attribute_names[i], "name")) { | |
1355 g_free(blist_parser_component_name); | |
1356 blist_parser_component_name = g_strdup(attribute_values[i]); | |
1357 } | |
1358 } | |
1359 | |
5228 | 1360 } else if(!strcmp(element_name, "privacy")) { |
1361 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PRIVACY)); | |
1362 } else if(!strcmp(element_name, "account")) { | |
1363 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_ACCOUNT)); | |
1364 for(i=0; attribute_names[i]; i++) { | |
1365 if(!strcmp(attribute_names[i], "protocol")) | |
1366 blist_parser_account_protocol = atoi(attribute_values[i]); | |
1367 else if(!strcmp(attribute_names[i], "mode")) | |
1368 blist_parser_privacy_mode = atoi(attribute_values[i]); | |
1369 else if(!strcmp(attribute_names[i], "name")) { | |
1370 g_free(blist_parser_account_name); | |
1371 blist_parser_account_name = g_strdup(attribute_values[i]); | |
1372 } | |
1373 } | |
1374 } else if(!strcmp(element_name, "permit")) { | |
1375 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PERMIT)); | |
1376 } else if(!strcmp(element_name, "block")) { | |
1377 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BLOCK)); | |
1378 } else if(!strcmp(element_name, "ignore")) { | |
1379 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_IGNORE)); | |
1380 } | |
1381 } | |
1382 | |
1383 static void blist_end_element_handler(GMarkupParseContext *context, | |
1384 const gchar *element_name, gpointer user_data, GError **error) { | |
1385 if(!strcmp(element_name, "gaim")) { | |
1386 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1387 } else if(!strcmp(element_name, "blist")) { | |
1388 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1389 } else if(!strcmp(element_name, "group")) { | |
1390 if(blist_parser_group_settings) { | |
1391 struct group *g = gaim_find_group(blist_parser_group_name); | |
1392 g_hash_table_destroy(g->settings); | |
1393 g->settings = blist_parser_group_settings; | |
1394 } | |
1395 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1396 blist_parser_group_settings = NULL; | |
5234 | 1397 } else if(!strcmp(element_name, "chat")) { |
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1398 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
5234 | 1399 blist_parser_account_protocol); |
5237 | 1400 if(account) { |
5234 | 1401 struct chat *chat = gaim_chat_new(account, blist_parser_chat_alias, blist_parser_chat_components); |
1402 struct group *g = gaim_find_group(blist_parser_group_name); | |
5634 | 1403 gaim_blist_add_chat(chat,g, |
1404 gaim_blist_get_last_child((GaimBlistNode*)g)); | |
5906 | 1405 if(blist_parser_chat_settings) { |
1406 g_hash_table_destroy(chat->settings); | |
1407 chat->settings = blist_parser_chat_settings; | |
1408 } | |
5234 | 1409 } |
1410 g_free(blist_parser_chat_alias); | |
1411 blist_parser_chat_alias = NULL; | |
1412 g_free(blist_parser_account_name); | |
1413 blist_parser_account_name = NULL; | |
1414 blist_parser_chat_components = NULL; | |
5906 | 1415 blist_parser_chat_settings = NULL; |
5234 | 1416 tag_stack = g_list_delete_link(tag_stack, tag_stack); |
5228 | 1417 } else if(!strcmp(element_name, "person")) { |
1418 g_free(blist_parser_person_name); | |
1419 blist_parser_person_name = NULL; | |
1420 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1421 } else if(!strcmp(element_name, "buddy")) { | |
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1422 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
5228 | 1423 blist_parser_account_protocol); |
1424 if(account) { | |
1425 struct buddy *b = gaim_buddy_new(account, blist_parser_buddy_name, blist_parser_buddy_alias); | |
1426 struct group *g = gaim_find_group(blist_parser_group_name); | |
5634 | 1427 gaim_blist_add_buddy(b,g, |
1428 gaim_blist_get_last_child((GaimBlistNode*)g)); | |
5228 | 1429 if(blist_parser_buddy_settings) { |
1430 g_hash_table_destroy(b->settings); | |
1431 b->settings = blist_parser_buddy_settings; | |
1432 } | |
1433 } | |
1434 g_free(blist_parser_buddy_name); | |
1435 blist_parser_buddy_name = NULL; | |
1436 g_free(blist_parser_buddy_alias); | |
1437 blist_parser_buddy_alias = NULL; | |
1438 g_free(blist_parser_account_name); | |
1439 blist_parser_account_name = NULL; | |
1440 blist_parser_buddy_settings = NULL; | |
1441 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1442 } else if(!strcmp(element_name, "name")) { | |
1443 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1444 } else if(!strcmp(element_name, "alias")) { | |
1445 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
5234 | 1446 } else if(!strcmp(element_name, "component")) { |
1447 if(!blist_parser_chat_components) | |
1448 blist_parser_chat_components = g_hash_table_new_full(g_str_hash, | |
1449 g_str_equal, g_free, g_free); | |
1450 if(blist_parser_component_name && blist_parser_component_value) { | |
1451 g_hash_table_replace(blist_parser_chat_components, | |
1452 g_strdup(blist_parser_component_name), | |
1453 g_strdup(blist_parser_component_value)); | |
1454 } | |
1455 g_free(blist_parser_component_name); | |
1456 g_free(blist_parser_component_value); | |
1457 blist_parser_component_name = NULL; | |
1458 blist_parser_component_value = NULL; | |
1459 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
5228 | 1460 } else if(!strcmp(element_name, "setting")) { |
1461 if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_BUDDY) { | |
1462 if(!blist_parser_buddy_settings) | |
1463 blist_parser_buddy_settings = g_hash_table_new_full(g_str_hash, | |
1464 g_str_equal, g_free, g_free); | |
1465 if(blist_parser_setting_name && blist_parser_setting_value) { | |
1466 g_hash_table_replace(blist_parser_buddy_settings, | |
1467 g_strdup(blist_parser_setting_name), | |
1468 g_strdup(blist_parser_setting_value)); | |
1469 } | |
5906 | 1470 } else if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_CHAT) { |
1471 if(!blist_parser_chat_settings) | |
1472 blist_parser_chat_settings = g_hash_table_new_full(g_str_hash, | |
1473 g_str_equal, g_free, g_free); | |
1474 if(blist_parser_setting_name && blist_parser_setting_value) { | |
1475 g_hash_table_replace(blist_parser_buddy_settings, | |
1476 g_strdup(blist_parser_setting_name), | |
1477 g_strdup(blist_parser_setting_value)); | |
1478 } | |
5228 | 1479 } else if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_GROUP) { |
1480 if(!blist_parser_group_settings) | |
1481 blist_parser_group_settings = g_hash_table_new_full(g_str_hash, | |
1482 g_str_equal, g_free, g_free); | |
1483 if(blist_parser_setting_name && blist_parser_setting_value) { | |
1484 g_hash_table_replace(blist_parser_group_settings, | |
1485 g_strdup(blist_parser_setting_name), | |
1486 g_strdup(blist_parser_setting_value)); | |
1487 } | |
1488 } | |
1489 g_free(blist_parser_setting_name); | |
1490 g_free(blist_parser_setting_value); | |
1491 blist_parser_setting_name = NULL; | |
1492 blist_parser_setting_value = NULL; | |
1493 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1494 } else if(!strcmp(element_name, "privacy")) { | |
1495 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1496 } else if(!strcmp(element_name, "account")) { | |
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1497 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
5228 | 1498 blist_parser_account_protocol); |
1499 if(account) { | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1500 account->perm_deny = blist_parser_privacy_mode; |
5228 | 1501 } |
1502 g_free(blist_parser_account_name); | |
1503 blist_parser_account_name = NULL; | |
1504 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1505 } else if(!strcmp(element_name, "permit")) { | |
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1506 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
5228 | 1507 blist_parser_account_protocol); |
1508 if(account) { | |
1509 gaim_privacy_permit_add(account, blist_parser_buddy_name); | |
1510 } | |
1511 g_free(blist_parser_buddy_name); | |
1512 blist_parser_buddy_name = NULL; | |
1513 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1514 } else if(!strcmp(element_name, "block")) { | |
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1515 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
5228 | 1516 blist_parser_account_protocol); |
1517 if(account) { | |
1518 gaim_privacy_deny_add(account, blist_parser_buddy_name); | |
1519 } | |
1520 g_free(blist_parser_buddy_name); | |
1521 blist_parser_buddy_name = NULL; | |
1522 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1523 } else if(!strcmp(element_name, "ignore")) { | |
1524 /* we'll apparently do something with this later */ | |
1525 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1526 } | |
1527 } | |
1528 | |
1529 static void blist_text_handler(GMarkupParseContext *context, const gchar *text, | |
1530 gsize text_len, gpointer user_data, GError **error) { | |
1531 switch(GPOINTER_TO_INT(tag_stack->data)) { | |
1532 case BLIST_TAG_NAME: | |
1533 blist_parser_buddy_name = g_strndup(text, text_len); | |
1534 break; | |
1535 case BLIST_TAG_ALIAS: | |
5234 | 1536 if(tag_stack->next && |
1537 GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_BUDDY) | |
1538 blist_parser_buddy_alias = g_strndup(text, text_len); | |
1539 else if(tag_stack->next && | |
1540 GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_CHAT) | |
1541 blist_parser_chat_alias = g_strndup(text, text_len); | |
5228 | 1542 break; |
1543 case BLIST_TAG_PERMIT: | |
1544 case BLIST_TAG_BLOCK: | |
1545 case BLIST_TAG_IGNORE: | |
1546 blist_parser_buddy_name = g_strndup(text, text_len); | |
1547 break; | |
5234 | 1548 case BLIST_TAG_COMPONENT: |
1549 blist_parser_component_value = g_strndup(text, text_len); | |
1550 break; | |
5228 | 1551 case BLIST_TAG_SETTING: |
1552 blist_parser_setting_value = g_strndup(text, text_len); | |
1553 break; | |
1554 default: | |
1555 break; | |
1556 } | |
1557 } | |
1558 | |
1559 static void blist_error_handler(GMarkupParseContext *context, GError *error, | |
1560 gpointer user_data) { | |
1561 blist_parser_error_occurred = TRUE; | |
1562 gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
1563 "Error parsing blist.xml: %s\n", error->message); | |
1564 } | |
1565 | |
1566 static GMarkupParser blist_parser = { | |
1567 blist_start_element_handler, | |
1568 blist_end_element_handler, | |
1569 blist_text_handler, | |
1570 NULL, | |
1571 blist_error_handler | |
1572 }; | |
1573 | |
1574 static gboolean gaim_blist_read(const char *filename) { | |
1575 gchar *contents = NULL; | |
1576 gsize length; | |
1577 GMarkupParseContext *context; | |
1578 GError *error = NULL; | |
1579 | |
1580 gaim_debug(GAIM_DEBUG_INFO, "blist import", | |
1581 "Reading %s\n", filename); | |
1582 if(!g_file_get_contents(filename, &contents, &length, &error)) { | |
1583 gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
1584 "Error reading blist: %s\n", error->message); | |
1585 g_error_free(error); | |
1586 return FALSE; | |
1587 } | |
1588 | |
1589 context = g_markup_parse_context_new(&blist_parser, 0, NULL, NULL); | |
1590 | |
1591 if(!g_markup_parse_context_parse(context, contents, length, NULL)) { | |
1592 g_markup_parse_context_free(context); | |
1593 g_free(contents); | |
1594 return FALSE; | |
1595 } | |
1596 | |
1597 if(!g_markup_parse_context_end_parse(context, NULL)) { | |
1598 gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
1599 "Error parsing %s\n", filename); | |
1600 g_markup_parse_context_free(context); | |
1601 g_free(contents); | |
1602 return FALSE; | |
1603 } | |
1604 | |
1605 g_markup_parse_context_free(context); | |
1606 g_free(contents); | |
1607 | |
1608 if(blist_parser_error_occurred) | |
1609 return FALSE; | |
1610 | |
1611 gaim_debug(GAIM_DEBUG_INFO, "blist import", "Finished reading %s\n", | |
1612 filename); | |
1613 | |
1614 return TRUE; | |
1615 } | |
1616 | |
1617 void gaim_blist_load() { | |
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1618 GList *accts; |
5228 | 1619 char *user_dir = gaim_user_dir(); |
1620 char *filename; | |
1621 char *msg; | |
1622 | |
1623 blist_safe_to_write = TRUE; | |
1624 | |
1625 if(!user_dir) | |
1626 return; | |
1627 | |
1628 filename = g_build_filename(user_dir, "blist.xml", NULL); | |
1629 | |
1630 if(g_file_test(filename, G_FILE_TEST_EXISTS)) { | |
1631 if(!gaim_blist_read(filename)) { | |
1632 msg = g_strdup_printf(_("An error was encountered parsing your " | |
1633 "buddy list. It has not been loaded.")); | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
1634 gaim_notify_error(NULL, NULL, _("Buddy List Error"), msg); |
5228 | 1635 g_free(msg); |
1636 } | |
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1637 } else if(g_list_length(gaim_accounts_get_all())) { |
5947
ac4dd1d0ee39
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1638 GMainContext *ctx; |
ac4dd1d0ee39
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1639 |
5228 | 1640 /* rob wants to inform the user that their buddy lists are |
1641 * being converted */ | |
1642 msg = g_strdup_printf(_("Gaim is converting your old buddy lists " | |
1643 "to a new format, which will now be located at %s"), | |
1644 filename); | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
1645 gaim_notify_info(NULL, NULL, _("Converting Buddy List"), msg); |
5228 | 1646 g_free(msg); |
1647 | |
1648 /* now, let gtk actually display the dialog before we start anything */ | |
5947
ac4dd1d0ee39
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1649 ctx = g_main_context_default(); |
ac4dd1d0ee39
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1650 |
ac4dd1d0ee39
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1651 while(g_main_context_pending(ctx)) |
ac4dd1d0ee39
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1652 g_main_context_iteration(ctx, FALSE); |
5228 | 1653 |
1654 /* read in the old lists, then save to the new format */ | |
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1655 for(accts = gaim_accounts_get_all(); accts; accts = accts->next) { |
5228 | 1656 do_import(accts->data, NULL); |
1657 } | |
1658 gaim_blist_save(); | |
1659 } | |
1660 | |
1661 g_free(filename); | |
1662 } | |
1663 | |
1664 static void blist_print_group_settings(gpointer key, gpointer data, | |
1665 gpointer user_data) { | |
1666 char *key_val; | |
1667 char *data_val; | |
1668 FILE *file = user_data; | |
1669 | |
1670 if(!key || !data) | |
1671 return; | |
1672 | |
1673 key_val = g_markup_escape_text(key, -1); | |
1674 data_val = g_markup_escape_text(data, -1); | |
1675 | |
1676 fprintf(file, "\t\t\t<setting name=\"%s\">%s</setting>\n", key_val, | |
1677 data_val); | |
1678 g_free(key_val); | |
1679 g_free(data_val); | |
1680 } | |
1681 | |
1682 static void blist_print_buddy_settings(gpointer key, gpointer data, | |
1683 gpointer user_data) { | |
1684 char *key_val; | |
1685 char *data_val; | |
1686 FILE *file = user_data; | |
1687 | |
1688 if(!key || !data) | |
1689 return; | |
1690 | |
1691 key_val = g_markup_escape_text(key, -1); | |
1692 data_val = g_markup_escape_text(data, -1); | |
1693 | |
1694 fprintf(file, "\t\t\t\t\t<setting name=\"%s\">%s</setting>\n", key_val, | |
1695 data_val); | |
1696 g_free(key_val); | |
1697 g_free(data_val); | |
1698 } | |
1699 | |
5234 | 1700 static void blist_print_chat_components(gpointer key, gpointer data, |
1701 gpointer user_data) { | |
1702 char *key_val; | |
1703 char *data_val; | |
1704 FILE *file = user_data; | |
1705 | |
1706 if(!key || !data) | |
1707 return; | |
1708 | |
1709 key_val = g_markup_escape_text(key, -1); | |
1710 data_val = g_markup_escape_text(data, -1); | |
1711 | |
1712 fprintf(file, "\t\t\t\t<component name=\"%s\">%s</component>\n", key_val, | |
1713 data_val); | |
1714 g_free(key_val); | |
1715 g_free(data_val); | |
1716 } | |
1717 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1718 static void gaim_blist_write(FILE *file, GaimAccount *exp_acct) { |
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1719 GList *accounts; |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1720 GSList *buds; |
5228 | 1721 GaimBlistNode *gnode,*bnode; |
1722 struct group *group; | |
1723 struct buddy *bud; | |
1724 fprintf(file, "<?xml version='1.0' encoding='UTF-8' ?>\n"); | |
1725 fprintf(file, "<gaim version=\"1\">\n"); | |
1726 fprintf(file, "\t<blist>\n"); | |
1727 | |
1728 for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { | |
1729 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
1730 continue; | |
1731 group = (struct group *)gnode; | |
1732 if(!exp_acct || gaim_group_on_account(group, exp_acct)) { | |
1733 char *group_name = g_markup_escape_text(group->name, -1); | |
1734 fprintf(file, "\t\t<group name=\"%s\">\n", group_name); | |
1735 g_hash_table_foreach(group->settings, blist_print_group_settings, file); | |
1736 for(bnode = gnode->child; bnode; bnode = bnode->next) { | |
5234 | 1737 if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { |
1738 bud = (struct buddy *)bnode; | |
1739 if(!exp_acct || bud->account == exp_acct) { | |
1740 char *bud_name = g_markup_escape_text(bud->name, -1); | |
1741 char *bud_alias = NULL; | |
1742 char *acct_name = g_markup_escape_text(bud->account->username, -1); | |
1743 if(bud->alias) | |
1744 bud_alias= g_markup_escape_text(bud->alias, -1); | |
1745 fprintf(file, "\t\t\t<person name=\"%s\">\n", | |
1746 bud_alias ? bud_alias : bud_name); | |
1747 fprintf(file, "\t\t\t\t<buddy protocol=\"%d\" " | |
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1748 "account=\"%s\">\n", |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1749 gaim_account_get_protocol(bud->account), |
5234 | 1750 acct_name); |
1751 fprintf(file, "\t\t\t\t\t<name>%s</name>\n", bud_name); | |
1752 if(bud_alias) { | |
1753 fprintf(file, "\t\t\t\t\t<alias>%s</alias>\n", | |
1754 bud_alias); | |
1755 } | |
1756 g_hash_table_foreach(bud->settings, | |
1757 blist_print_buddy_settings, file); | |
1758 fprintf(file, "\t\t\t\t</buddy>\n"); | |
1759 fprintf(file, "\t\t\t</person>\n"); | |
1760 g_free(bud_name); | |
1761 g_free(bud_alias); | |
1762 g_free(acct_name); | |
5228 | 1763 } |
5234 | 1764 } else if(GAIM_BLIST_NODE_IS_CHAT(bnode)) { |
1765 struct chat *chat = (struct chat *)bnode; | |
1766 if(!exp_acct || chat->account == exp_acct) { | |
1767 char *acct_name = g_markup_escape_text(chat->account->username, -1); | |
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1768 fprintf(file, "\t\t\t<chat protocol=\"%d\" account=\"%s\">\n", |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1769 gaim_account_get_protocol(chat->account), |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1770 acct_name); |
5237 | 1771 if(chat->alias) { |
1772 char *chat_alias = g_markup_escape_text(chat->alias, -1); | |
1773 fprintf(file, "\t\t\t\t<alias>%s</alias>\n", chat_alias); | |
1774 g_free(chat_alias); | |
1775 } | |
5234 | 1776 g_hash_table_foreach(chat->components, |
1777 blist_print_chat_components, file); | |
5906 | 1778 /* works for chats too, I don't feel like renaming */ |
1779 g_hash_table_foreach(chat->settings, | |
1780 blist_print_buddy_settings, file); | |
5234 | 1781 fprintf(file, "\t\t\t</chat>\n"); |
5237 | 1782 g_free(acct_name); |
5234 | 1783 } |
5228 | 1784 } |
1785 } | |
1786 fprintf(file, "\t\t</group>\n"); | |
1787 g_free(group_name); | |
1788 } | |
1789 } | |
1790 | |
1791 fprintf(file, "\t</blist>\n"); | |
1792 fprintf(file, "\t<privacy>\n"); | |
1793 | |
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1794 for(accounts = gaim_accounts_get_all(); |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1795 accounts != NULL; |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1796 accounts = accounts->next) { |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1797 |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1798 GaimAccount *account = accounts->data; |
5228 | 1799 char *acct_name = g_markup_escape_text(account->username, -1); |
1800 if(!exp_acct || account == exp_acct) { | |
1801 fprintf(file, "\t\t<account protocol=\"%d\" name=\"%s\" " | |
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1802 "mode=\"%d\">\n", gaim_account_get_protocol(account), |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1803 acct_name, account->perm_deny); |
5228 | 1804 for(buds = account->permit; buds; buds = buds->next) { |
1805 char *bud_name = g_markup_escape_text(buds->data, -1); | |
1806 fprintf(file, "\t\t\t<permit>%s</permit>\n", bud_name); | |
1807 g_free(bud_name); | |
1808 } | |
1809 for(buds = account->deny; buds; buds = buds->next) { | |
1810 char *bud_name = g_markup_escape_text(buds->data, -1); | |
1811 fprintf(file, "\t\t\t<block>%s</block>\n", bud_name); | |
1812 g_free(bud_name); | |
1813 } | |
1814 fprintf(file, "\t\t</account>\n"); | |
1815 } | |
1816 g_free(acct_name); | |
1817 } | |
1818 | |
1819 fprintf(file, "\t</privacy>\n"); | |
1820 fprintf(file, "</gaim>\n"); | |
1821 } | |
1822 | |
1823 void gaim_blist_save() { | |
1824 FILE *file; | |
1825 char *user_dir = gaim_user_dir(); | |
1826 char *filename; | |
1827 char *filename_real; | |
1828 | |
1829 if(!user_dir) | |
1830 return; | |
1831 if(!blist_safe_to_write) { | |
1832 gaim_debug(GAIM_DEBUG_WARNING, "blist save", | |
1833 "AHH!! Tried to write the blist before we read it!\n"); | |
1834 return; | |
1835 } | |
1836 | |
1837 file = fopen(user_dir, "r"); | |
1838 if(!file) | |
1839 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
1840 else | |
1841 fclose(file); | |
1842 | |
1843 filename = g_build_filename(user_dir, "blist.xml.save", NULL); | |
1844 | |
1845 if((file = fopen(filename, "w"))) { | |
1846 gaim_blist_write(file, NULL); | |
1847 fclose(file); | |
1848 chmod(filename, S_IRUSR | S_IWUSR); | |
1849 } else { | |
1850 gaim_debug(GAIM_DEBUG_ERROR, "blist save", "Unable to write %s\n", | |
1851 filename); | |
1852 } | |
1853 | |
1854 filename_real = g_build_filename(user_dir, "blist.xml", NULL); | |
1855 | |
1856 if(rename(filename, filename_real) < 0) | |
1857 gaim_debug(GAIM_DEBUG_ERROR, "blist save", | |
1858 "Error renaming %s to %s\n", filename, filename_real); | |
1859 | |
1860 | |
1861 g_free(filename); | |
1862 g_free(filename_real); | |
1863 } | |
1864 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1865 gboolean gaim_privacy_permit_add(GaimAccount *account, const char *who) { |
5228 | 1866 GSList *d = account->permit; |
1867 char *n = g_strdup(normalize(who)); | |
1868 while(d) { | |
1869 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) | |
1870 break; | |
1871 d = d->next; | |
1872 } | |
1873 g_free(n); | |
1874 if(!d) { | |
1875 account->permit = g_slist_append(account->permit, g_strdup(who)); | |
1876 return TRUE; | |
1877 } | |
1878 | |
1879 return FALSE; | |
1880 } | |
1881 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1882 gboolean gaim_privacy_permit_remove(GaimAccount *account, const char *who) { |
5228 | 1883 GSList *d = account->permit; |
1884 char *n = g_strdup(normalize(who)); | |
1885 while(d) { | |
1886 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) | |
1887 break; | |
1888 d = d->next; | |
1889 } | |
1890 g_free(n); | |
1891 if(d) { | |
1892 account->permit = g_slist_remove(account->permit, d->data); | |
1893 g_free(d->data); | |
1894 return TRUE; | |
1895 } | |
1896 return FALSE; | |
1897 } | |
1898 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1899 gboolean gaim_privacy_deny_add(GaimAccount *account, const char *who) { |
5228 | 1900 GSList *d = account->deny; |
1901 char *n = g_strdup(normalize(who)); | |
1902 while(d) { | |
1903 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) | |
1904 break; | |
1905 d = d->next; | |
1906 } | |
1907 g_free(n); | |
1908 if(!d) { | |
1909 account->deny = g_slist_append(account->deny, g_strdup(who)); | |
1910 return TRUE; | |
1911 } | |
1912 | |
1913 return FALSE; | |
1914 } | |
1915 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1916 gboolean gaim_privacy_deny_remove(GaimAccount *account, const char *who) { |
5228 | 1917 GSList *d = account->deny; |
1918 char *n = g_strdup(normalize(who)); | |
1919 while(d) { | |
1920 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) | |
1921 break; | |
1922 d = d->next; | |
1923 } | |
1924 g_free(n); | |
1925 if(d) { | |
1926 account->deny = g_slist_remove(account->deny, d->data); | |
1927 g_free(d->data); | |
1928 return TRUE; | |
1929 } | |
1930 return FALSE; | |
1931 } | |
1932 | |
1933 void gaim_group_set_setting(struct group *g, const char *key, | |
1934 const char *value) { | |
1935 if(!g) | |
1936 return; | |
1937 g_hash_table_replace(g->settings, g_strdup(key), g_strdup(value)); | |
1938 } | |
1939 | |
1940 char *gaim_group_get_setting(struct group *g, const char *key) { | |
1941 if(!g) | |
1942 return NULL; | |
1943 return g_strdup(g_hash_table_lookup(g->settings, key)); | |
1944 } | |
1945 | |
5906 | 1946 void gaim_chat_set_setting(struct chat *c, const char *key, |
1947 const char *value) | |
1948 { | |
1949 if(!c) | |
1950 return; | |
1951 g_hash_table_replace(c->settings, g_strdup(key), g_strdup(value)); | |
1952 } | |
1953 | |
1954 char *gaim_chat_get_setting(struct chat *c, const char *key) | |
1955 { | |
1956 if(!c) | |
1957 return NULL; | |
1958 return g_strdup(g_hash_table_lookup(c->settings, key)); | |
1959 } | |
1960 | |
5228 | 1961 void gaim_buddy_set_setting(struct buddy *b, const char *key, |
1962 const char *value) { | |
1963 if(!b) | |
1964 return; | |
1965 g_hash_table_replace(b->settings, g_strdup(key), g_strdup(value)); | |
1966 } | |
1967 | |
1968 char *gaim_buddy_get_setting(struct buddy *b, const char *key) { | |
1969 if(!b) | |
1970 return NULL; | |
1971 return g_strdup(g_hash_table_lookup(b->settings, key)); | |
1972 } | |
1973 | |
1974 void gaim_set_blist_ui_ops(struct gaim_blist_ui_ops *ops) | |
1975 { | |
1976 blist_ui_ops = ops; | |
1977 } | |
1978 | |
1979 struct gaim_blist_ui_ops * | |
1980 gaim_get_blist_ui_ops(void) | |
1981 { | |
1982 return blist_ui_ops; | |
1983 } | |
1984 | |
1985 int gaim_blist_get_group_size(struct group *group, gboolean offline) { | |
1986 if(!group) | |
1987 return 0; | |
1988 | |
5277 | 1989 return offline ? group->totalsize : group->currentsize; |
5228 | 1990 } |
1991 | |
1992 int gaim_blist_get_group_online_count(struct group *group) { | |
1993 if(!group) | |
1994 return 0; | |
1995 | |
5277 | 1996 return group->online; |
5228 | 1997 } |
1998 | |
1999 |