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