Mercurial > pidgin.yaz
annotate src/list.c @ 4936:cfeab08d4be9
[gaim-migrate @ 5270]
This should fix up the group deletion segfaults, makes the offline groups not
start out collapsed, and probably something else i've forgotten. Oh, yeah,
makes the show offline buddies preference actually work right. Also kills
some code duplication.
I should make buddy icons 100x100, so they can use some of that new blank
space in the buddy list. That'd be cool.
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Tue, 01 Apr 2003 03:19:51 +0000 |
parents | a1551892049c |
children | 4228bddbf2cd |
rev | line source |
---|---|
2382 | 1 /* |
2 * gaim | |
3 * | |
4687 | 4 * Copyright (C) 2003, Sean Egan <sean.egan@binghamton.edu> |
2382 | 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 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 #include <string.h> | |
4349 | 27 #include <stdlib.h> |
2382 | 28 #include <sys/types.h> |
29 #include <sys/stat.h> | |
3630 | 30 #ifndef _WIN32 |
2382 | 31 #include <unistd.h> |
3630 | 32 #else |
33 #include <direct.h> | |
34 #endif | |
4349 | 35 #include <ctype.h> |
2382 | 36 #include "gaim.h" |
37 #include "prpl.h" | |
4687 | 38 #include "list.h" |
2382 | 39 |
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
40 #ifdef _WIN32 |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
41 #include "win32dep.h" |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
42 #endif |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
43 |
2382 | 44 #define PATHSIZE 1024 |
45 | |
4687 | 46 struct gaim_buddy_list *gaimbuddylist = NULL; |
47 static struct gaim_blist_ui_ops *blist_ui_ops = NULL; | |
2382 | 48 |
4687 | 49 /***************************************************************************** |
50 * Private Utility functions * | |
51 *****************************************************************************/ | |
52 static GaimBlistNode *gaim_blist_get_last_sibling(GaimBlistNode *node) | |
53 { | |
54 GaimBlistNode *n = node; | |
55 if (!n) | |
56 return NULL; | |
57 while (n->next) | |
58 n = n->next; | |
59 return n; | |
60 } | |
61 static GaimBlistNode *gaim_blist_get_last_child(GaimBlistNode *node) | |
62 { | |
63 if (!node) | |
64 return NULL; | |
65 return gaim_blist_get_last_sibling(node->child); | |
66 } | |
2382 | 67 |
4770 | 68 /***************************************************************************** |
4687 | 69 * Public API functions * |
70 *****************************************************************************/ | |
4349 | 71 |
4687 | 72 struct gaim_buddy_list *gaim_blist_new() |
73 { | |
74 struct gaim_buddy_list *gbl = g_new0(struct gaim_buddy_list, 1); | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
75 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
76 gbl->ui_ops = gaim_get_blist_ui_ops(); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
77 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
78 if (gbl->ui_ops != NULL && gbl->ui_ops->new_list != NULL) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
79 gbl->ui_ops->new_list(gbl); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
80 |
4687 | 81 return gbl; |
82 } | |
2382 | 83 |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
84 void |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
85 gaim_set_blist(struct gaim_buddy_list *list) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
86 { |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
87 gaimbuddylist = list; |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
88 } |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
89 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
90 struct gaim_buddy_list * |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
91 gaim_get_blist(void) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
92 { |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
93 return gaimbuddylist; |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
94 } |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
95 |
4687 | 96 void gaim_blist_show () |
97 { | |
98 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
99 if (ops) | |
100 ops->show(gaimbuddylist); | |
101 } | |
2382 | 102 |
4687 | 103 void gaim_blist_destroy() |
104 { | |
105 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
106 if (ops) | |
107 ops->destroy(gaimbuddylist); | |
108 } | |
2382 | 109 |
4687 | 110 void gaim_blist_set_visible (gboolean show) |
111 { | |
112 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
113 if (ops) | |
114 ops->set_visible(gaimbuddylist, show); | |
115 } | |
2382 | 116 |
4687 | 117 void gaim_blist_update_buddy_status (struct buddy *buddy, int status) |
118 { | |
119 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
120 buddy->uc = status; | |
121 if (ops) | |
122 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
2382 | 123 } |
124 | |
4687 | 125 void gaim_blist_update_buddy_presence(struct buddy *buddy, int presence) { |
126 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
127 if (!buddy->present && presence) | |
128 buddy->present = 2; | |
129 else if (buddy->present != 2) | |
130 buddy->present = presence; | |
131 if (ops) | |
132 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
133 } | |
2382 | 134 |
135 | |
4687 | 136 void gaim_blist_update_buddy_idle (struct buddy *buddy, int idle) |
137 { | |
138 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
139 buddy->idle = idle; | |
140 if (ops) | |
141 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
142 } | |
143 void gaim_blist_update_buddy_evil (struct buddy *buddy, int warning) | |
144 { | |
145 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
146 buddy->evil = warning; | |
147 if (ops) | |
148 ops->update(gaimbuddylist,(GaimBlistNode*)buddy); | |
149 } | |
4757 | 150 void gaim_blist_update_buddy_icon(struct buddy *buddy) { |
151 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
152 if(ops) | |
153 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
154 } | |
4687 | 155 void gaim_blist_rename_buddy (struct buddy *buddy, const char *name) |
156 { | |
157 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
158 g_free(buddy->name); | |
159 buddy->name = g_strdup(name); | |
160 if (ops) | |
161 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
162 } | |
163 void gaim_blist_alias_buddy (struct buddy *buddy, const char *alias) | |
164 { | |
165 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
166 g_free(buddy->alias); | |
167 buddy->alias = g_strdup(alias); | |
168 if (ops) | |
169 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
170 } | |
171 void gaim_blist_rename_group(struct group *group, const char *name) | |
172 { | |
173 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
174 g_free(group->name); | |
175 group->name = g_strdup(name); | |
176 if (ops) | |
177 ops->update(gaimbuddylist, (GaimBlistNode*)group); | |
178 } | |
179 struct buddy *gaim_buddy_new(struct gaim_account *account, const char *screenname, const char *alias) | |
180 { | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
181 struct buddy *b; |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
182 struct gaim_blist_ui_ops *ops; |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
183 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
184 b = g_new0(struct buddy, 1); |
4491 | 185 b->account = account; |
4687 | 186 b->name = g_strdup(screenname); |
187 b->alias = g_strdup(alias); | |
4349 | 188 b->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
4687 | 189 ((GaimBlistNode*)b)->type = GAIM_BLIST_BUDDY_NODE; |
2382 | 190 |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
191 ops = gaim_get_blist_ui_ops(); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
192 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
193 if (ops != NULL && ops->new_node != NULL) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
194 ops->new_node((GaimBlistNode *)b); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
195 |
2382 | 196 return b; |
197 } | |
4687 | 198 void gaim_blist_add_buddy (struct buddy *buddy, struct group *group, GaimBlistNode *node) |
2382 | 199 { |
4687 | 200 GaimBlistNode *n = node, *node2, *node3; |
201 struct group *g = group; | |
202 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
4770 | 203 gboolean save = FALSE; |
4865 | 204 |
205 /* if we're moving to overtop of ourselves, do nothing */ | |
206 if((GaimBlistNode*)buddy == node) | |
207 return; | |
208 | |
4687 | 209 if (!n) { |
210 if (!g) { | |
211 g = gaim_group_new(_("Buddies")); | |
212 gaim_blist_add_group(g, NULL); | |
213 } | |
214 n = gaim_blist_get_last_child((GaimBlistNode*)g); | |
215 } | |
216 | |
4770 | 217 if (((GaimBlistNode*)buddy)->parent) { |
218 /* This buddy was already in the list and is | |
219 * being moved. | |
220 */ | |
221 ops->remove(gaimbuddylist, (GaimBlistNode*)buddy); | |
222 node2 = ((GaimBlistNode*)buddy)->next; | |
223 node3 = ((GaimBlistNode*)buddy)->prev; | |
4865 | 224 |
4770 | 225 if (node2) |
226 node2->prev = node3; | |
227 if (node3) | |
228 node3->next = node2; | |
229 | |
230 if (((GaimBlistNode*)buddy)->parent != n->parent) | |
4865 | 231 serv_move_buddy(buddy, (struct group*)((GaimBlistNode*)buddy)->parent, |
4770 | 232 (struct group*)n->parent); |
233 save = TRUE; | |
234 } | |
2382 | 235 |
4687 | 236 if (n) { |
237 ((GaimBlistNode*)buddy)->next = n->next; | |
238 ((GaimBlistNode*)buddy)->prev = n; | |
239 ((GaimBlistNode*)buddy)->parent = n->parent; | |
240 n->next = (GaimBlistNode*)buddy; | |
241 } else { | |
242 ((GaimBlistNode*)g)->child = (GaimBlistNode*)buddy; | |
243 ((GaimBlistNode*)buddy)->next = NULL; | |
244 ((GaimBlistNode*)buddy)->prev = NULL; | |
245 ((GaimBlistNode*)buddy)->parent = (GaimBlistNode*)g; | |
246 } | |
2382 | 247 |
4687 | 248 if (ops) |
249 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
4865 | 250 if (save) |
4770 | 251 gaim_blist_save(); |
4687 | 252 } |
2382 | 253 |
4687 | 254 struct group *gaim_group_new(const char *name) |
255 { | |
256 struct group *g = gaim_find_group(name); | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
257 |
4687 | 258 if (!g) { |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
259 struct gaim_blist_ui_ops *ops; |
4687 | 260 g= g_new0(struct group, 1); |
261 g->name = g_strdup(name); | |
262 ((GaimBlistNode*)g)->type = GAIM_BLIST_GROUP_NODE; | |
2382 | 263 |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
264 ops = gaim_get_blist_ui_ops(); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
265 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
266 if (ops != NULL && ops->new_node != NULL) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
267 ops->new_node((GaimBlistNode *)g); |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
268 |
4687 | 269 } |
2382 | 270 return g; |
271 } | |
272 | |
4687 | 273 void gaim_blist_add_group (struct group *group, GaimBlistNode *node) |
2382 | 274 { |
4687 | 275 struct gaim_blist_ui_ops *ops; |
4785 | 276 gboolean save = FALSE; |
277 | |
4687 | 278 if (!gaimbuddylist) |
279 gaimbuddylist = gaim_blist_new(); | |
280 ops = gaimbuddylist->ui_ops; | |
4785 | 281 |
4687 | 282 if (!gaimbuddylist->root) { |
283 gaimbuddylist->root = (GaimBlistNode*)group; | |
284 return; | |
285 } | |
4785 | 286 |
287 | |
288 if (!node) | |
4687 | 289 node = gaim_blist_get_last_sibling(gaimbuddylist->root); |
4785 | 290 |
4781 | 291 if (gaim_find_group(group->name)) { |
292 /* This is just being moved */ | |
293 GaimBlistNode *node2 = ((GaimBlistNode*)group)->next; | |
294 GaimBlistNode *node3 = ((GaimBlistNode*)group)->prev; | |
2382 | 295 |
4781 | 296 ops->remove(gaimbuddylist, (GaimBlistNode*)group); |
297 | |
298 if (node2) | |
299 node2->prev = node3; | |
300 if (node3) | |
301 node3->next = node2; | |
302 save = TRUE; | |
303 } | |
4785 | 304 |
4687 | 305 ((GaimBlistNode*)group)->next = node ? node->next : NULL; |
306 ((GaimBlistNode*)group)->prev = node; | |
307 node->next = (GaimBlistNode*)group; | |
308 | |
309 if (ops) | |
310 ops->update(gaimbuddylist, (GaimBlistNode*)group); | |
4785 | 311 if (save) |
4781 | 312 gaim_blist_save(); |
4687 | 313 } |
314 | |
315 void gaim_blist_remove_buddy (struct buddy *buddy) | |
316 { | |
317 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
318 | |
4721 | 319 GaimBlistNode *gnode, *node = (GaimBlistNode*)buddy; |
320 struct group *group; | |
321 | |
322 gnode = node->parent; | |
323 group = (struct group *)gnode; | |
324 | |
325 if(gnode->child == node) | |
326 gnode->child = node->next; | |
4687 | 327 if (node->prev) |
328 node->prev->next = node->next; | |
329 if (node->next) | |
330 node->next->prev = node->prev; | |
4721 | 331 |
4687 | 332 ops->remove(gaimbuddylist, node); |
333 g_free(buddy->name); | |
334 g_free(buddy->alias); | |
335 g_free(buddy); | |
2382 | 336 } |
337 | |
4687 | 338 void gaim_blist_remove_group (struct group *group) |
4349 | 339 { |
4687 | 340 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; |
341 GaimBlistNode *node = (GaimBlistNode*)group; | |
342 GaimBlistNode *child = node->child; | |
343 while (child) { | |
344 GaimBlistNode *n = child; | |
345 child = child->next; | |
346 gaim_blist_remove_buddy((struct buddy*)n); | |
347 } | |
4936 | 348 |
349 if(node->parent->child == node) | |
350 node->parent->child = node->next; | |
351 if (node->prev) | |
352 node->prev->next = node->next; | |
353 if (node->next) | |
354 node->next->prev = node->prev; | |
355 | |
4687 | 356 ops->remove(gaimbuddylist, node); |
357 g_free(group->name); | |
358 g_free(group); | |
359 } | |
4349 | 360 |
4687 | 361 char *gaim_get_buddy_alias_only(struct buddy *b) { |
362 if(!b) | |
363 return NULL; | |
364 if(b->alias && b->alias[0]) | |
365 return b->alias; | |
366 else if((misc_options & OPT_MISC_USE_SERVER_ALIAS) && b->server_alias) | |
367 return b->server_alias; | |
368 return NULL; | |
369 } | |
370 | |
371 char * gaim_get_buddy_alias (struct buddy *buddy) | |
372 { | |
373 char *ret = gaim_get_buddy_alias_only(buddy); | |
374 if(!ret) | |
375 return buddy ? buddy->name : _("Unknown"); | |
376 return ret; | |
377 | |
378 } | |
379 | |
380 struct buddy *gaim_find_buddy(struct gaim_account *account, const char *name) | |
381 { | |
4757 | 382 GaimBlistNode *group; |
4687 | 383 GaimBlistNode *buddy; |
4757 | 384 char *norm_name = g_strdup(normalize(name)); |
385 | |
4687 | 386 if (!gaimbuddylist) |
387 return NULL; | |
4757 | 388 |
389 group = gaimbuddylist->root; | |
4687 | 390 while (group) { |
391 buddy = group->child; | |
392 while (buddy) { | |
4793 | 393 if (!gaim_utf8_strcasecmp(normalize(((struct buddy*)buddy)->name), norm_name) && account == ((struct buddy*)buddy)->account) { |
4757 | 394 g_free(norm_name); |
4687 | 395 return (struct buddy*)buddy; |
4757 | 396 } |
4687 | 397 buddy = buddy->next; |
398 } | |
399 group = group->next; | |
4349 | 400 } |
4757 | 401 g_free(norm_name); |
4349 | 402 return NULL; |
403 } | |
404 | |
4687 | 405 struct group *gaim_find_group(const char *name) |
2382 | 406 { |
4687 | 407 GaimBlistNode *node; |
408 if (!gaimbuddylist) | |
409 return NULL; | |
410 node = gaimbuddylist->root; | |
411 while(node) { | |
412 if (!strcmp(((struct group*)node)->name, name)) | |
413 return (struct group*)node; | |
414 node = node->next; | |
2382 | 415 } |
4349 | 416 return NULL; |
2382 | 417 } |
4687 | 418 struct group *gaim_find_buddys_group(struct buddy *buddy) |
419 { | |
4830 | 420 if (!buddy) |
421 return NULL; | |
4687 | 422 return (struct group*)(((GaimBlistNode*)buddy)->parent); |
423 } | |
424 | |
425 GSList *gaim_group_get_accounts(struct group *g) | |
426 { | |
427 GSList *l = NULL; | |
428 GaimBlistNode *child = ((GaimBlistNode *)g)->child; | |
429 | |
430 while (child) { | |
431 if (!g_slist_find(l, ((struct buddy*)child)->account)) | |
432 l = g_slist_append(l, ((struct buddy*)child)->account); | |
433 child = child->next; | |
434 } | |
435 return l; | |
436 } | |
437 | |
438 void gaim_blist_remove_account(struct gaim_account *account) | |
439 { | |
440 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
441 GaimBlistNode *group = gaimbuddylist->root; | |
442 GaimBlistNode *buddy; | |
443 if (!gaimbuddylist) | |
444 return; | |
445 while (group) { | |
446 buddy = group->child; | |
447 while (buddy) { | |
448 if (account == ((struct buddy*)buddy)->account) { | |
449 ((struct buddy*)buddy)->present = 0; | |
4919 | 450 if(ops) |
451 ops->remove(gaimbuddylist, buddy); | |
4687 | 452 } |
453 buddy = buddy->next; | |
454 } | |
455 group = group->next; | |
456 } | |
457 } | |
2382 | 458 |
4491 | 459 void parse_toc_buddy_list(struct gaim_account *account, char *config) |
2382 | 460 { |
461 char *c; | |
462 char current[256]; | |
4351 | 463 GList *bud = NULL; |
4349 | 464 |
2382 | 465 |
466 if (config != NULL) { | |
4349 | 467 |
2382 | 468 /* skip "CONFIG:" (if it exists) */ |
469 c = strncmp(config + 6 /* sizeof(struct sflap_hdr) */ , "CONFIG:", strlen("CONFIG:")) ? | |
2998 | 470 strtok(config, "\n") : |
471 strtok(config + 6 /* sizeof(struct sflap_hdr) */ + strlen("CONFIG:"), "\n"); | |
2382 | 472 do { |
473 if (c == NULL) | |
474 break; | |
475 if (*c == 'g') { | |
4404 | 476 char *utf8 = NULL; |
4458 | 477 utf8 = gaim_try_conv_to_utf8(c + 2); |
4404 | 478 if (utf8 == NULL) { |
479 g_strlcpy(current, _("Invalid Groupname"), sizeof(current)); | |
480 } else { | |
481 g_strlcpy(current, utf8, sizeof(current)); | |
482 g_free(utf8); | |
483 } | |
4687 | 484 if (!gaim_find_group(current)) { |
485 struct group *g = gaim_group_new(current); | |
486 gaim_blist_add_group(g, NULL); | |
2526
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
487 } |
4687 | 488 } else if (*c == 'b') { /*&& !gaim_find_buddy(user, c + 2)) {*/ |
489 char nm[80], sw[388], *a, *utf8 = NULL; | |
4408 | 490 |
4404 | 491 if ((a = strchr(c + 2, ':')) != NULL) { |
492 *a++ = '\0'; /* nul the : */ | |
493 } | |
4349 | 494 |
4404 | 495 g_strlcpy(nm, c + 2, sizeof(nm)); |
496 if (a) { | |
4458 | 497 utf8 = gaim_try_conv_to_utf8(a); |
4404 | 498 if (utf8 == NULL) { |
499 debug_printf ("Failed to convert alias for '%s' to UTF-8\n", nm); | |
500 } | |
501 } | |
502 if (utf8 == NULL) { | |
503 sw[0] = '\0'; | |
504 } else { | |
4491 | 505 /* This can leave a partial sequence at the end, |
4404 | 506 * but who cares? */ |
507 g_strlcpy(sw, utf8, sizeof(sw)); | |
508 g_free(utf8); | |
509 } | |
4491 | 510 |
4687 | 511 if (!gaim_find_buddy(account, nm)) { |
512 struct buddy *b = gaim_buddy_new(account, nm, sw); | |
513 struct group *g = gaim_find_group(current); | |
514 gaim_blist_add_buddy(b, g, NULL); | |
4404 | 515 bud = g_list_append(bud, nm); |
2526
413a81136e3a
[gaim-migrate @ 2539]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
516 } |
2382 | 517 } else if (*c == 'p') { |
4491 | 518 gaim_privacy_permit_add(account, c + 2); |
2382 | 519 } else if (*c == 'd') { |
4491 | 520 gaim_privacy_deny_add(account, c + 2); |
2382 | 521 } else if (!strncmp("toc", c, 3)) { |
4491 | 522 sscanf(c + strlen(c) - 1, "%d", &account->permdeny); |
523 debug_printf("permdeny: %d\n", account->permdeny); | |
524 if (account->permdeny == 0) | |
525 account->permdeny = 1; | |
2382 | 526 } else if (*c == 'm') { |
4491 | 527 sscanf(c + 2, "%d", &account->permdeny); |
528 debug_printf("permdeny: %d\n", account->permdeny); | |
529 if (account->permdeny == 0) | |
530 account->permdeny = 1; | |
2382 | 531 } |
532 } while ((c = strtok(NULL, "\n"))); | |
4351 | 533 |
4491 | 534 if(account->gc) { |
4351 | 535 if(bud) |
4491 | 536 serv_add_buddies(account->gc, bud); |
537 serv_set_permit_deny(account->gc); | |
4351 | 538 } |
539 g_list_free(bud); | |
2382 | 540 } |
541 } | |
542 | |
4687 | 543 #if 0 |
2536
0e0a54e5819a
[gaim-migrate @ 2549]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2526
diff
changeset
|
544 /* translate an AIM 3 buddylist (*.lst) to a Gaim buddylist */ |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
545 static GString *translate_lst(FILE *src_fp) |
2382 | 546 { |
547 char line[BUF_LEN], *line2; | |
548 char *name; | |
549 int i; | |
550 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
551 GString *dest = g_string_new("m 1\n"); |
2382 | 552 |
553 while (fgets(line, BUF_LEN, src_fp)) { | |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
554 line2 = g_strchug(line); |
2382 | 555 if (strstr(line2, "group") == line2) { |
556 name = strpbrk(line2, " \t\n\r\f") + 1; | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
557 dest = g_string_append(dest, "g "); |
2382 | 558 for (i = 0; i < strcspn(name, "\n\r"); i++) |
559 if (name[i] != '\"') | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
560 dest = g_string_append_c(dest, name[i]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
561 dest = g_string_append_c(dest, '\n'); |
2382 | 562 } |
563 if (strstr(line2, "buddy") == line2) { | |
564 name = strpbrk(line2, " \t\n\r\f") + 1; | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
565 dest = g_string_append(dest, "b "); |
2382 | 566 for (i = 0; i < strcspn(name, "\n\r"); i++) |
567 if (name[i] != '\"') | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
568 dest = g_string_append_c(dest, name[i]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
569 dest = g_string_append_c(dest, '\n'); |
2382 | 570 } |
571 } | |
572 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
573 return dest; |
2382 | 574 } |
575 | |
576 | |
2536
0e0a54e5819a
[gaim-migrate @ 2549]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2526
diff
changeset
|
577 /* translate an AIM 4 buddylist (*.blt) to Gaim format */ |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
578 static GString *translate_blt(FILE *src_fp) |
2382 | 579 { |
580 int i; | |
581 char line[BUF_LEN]; | |
582 char *buddy; | |
583 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
584 GString *dest = g_string_new("m 1\n"); |
2382 | 585 |
586 while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL); | |
587 while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL); | |
588 | |
589 while (1) { | |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
590 fgets(line, BUF_LEN, src_fp); g_strchomp(line); |
2382 | 591 if (strchr(line, '}') != NULL) |
592 break; | |
593 | |
594 if (strchr(line, '{') != NULL) { | |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
595 /* Syntax starting with "<group> {" */ |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
596 |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
597 dest = g_string_append(dest, "g "); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
598 buddy = g_strchug(strtok(line, "{")); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
599 for (i = 0; i < strlen(buddy); i++) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
600 if (buddy[i] != '\"') |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
601 dest = g_string_append_c(dest, buddy[i]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
602 dest = g_string_append_c(dest, '\n'); |
2382 | 603 while (strchr(fgets(line, BUF_LEN, src_fp), '}') == NULL) { |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
604 gboolean pounce = FALSE; |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
605 char *e; |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
606 g_strchomp(line); |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
607 buddy = g_strchug(line); |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
608 debug_printf("\nbuddy: \"%s\"\n\n", buddy); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
609 dest = g_string_append(dest, "b "); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
610 if (strchr(buddy, '{') != NULL) { |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
611 /* buddy pounce, etc */ |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
612 char *pos = strchr(buddy, '{') - 1; |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
613 *pos = 0; |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
614 pounce = TRUE; |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
615 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
616 if ((e = strchr(buddy, '\"')) != NULL) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
617 *e = '\0'; |
2382 | 618 buddy++; |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
619 } |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
620 dest = g_string_append(dest, buddy); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
621 dest = g_string_append_c(dest, '\n'); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
622 if (pounce) |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
623 do |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
624 fgets(line, BUF_LEN, src_fp); |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
625 while (!strchr(line, '}')); |
2382 | 626 } |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
627 } else { |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
628 |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
629 /* Syntax "group buddy buddy ..." */ |
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
630 buddy = g_strchug(strtok(line, " \n")); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
631 dest = g_string_append(dest, "g "); |
2382 | 632 if (strchr(buddy, '\"') != NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
633 dest = g_string_append(dest, &buddy[1]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
634 dest = g_string_append_c(dest, ' '); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
635 buddy = g_strchug(strtok(NULL, " \n")); |
2382 | 636 while (strchr(buddy, '\"') == NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
637 dest = g_string_append(dest, buddy); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
638 dest = g_string_append_c(dest, ' '); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
639 buddy = g_strchug(strtok(NULL, " \n")); |
2382 | 640 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
641 buddy[strlen(buddy) - 1] = '\0'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
642 dest = g_string_append(dest, buddy); |
2382 | 643 } else { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
644 dest = g_string_append(dest, buddy); |
2382 | 645 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
646 dest = g_string_append_c(dest, '\n'); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
647 while ((buddy = g_strchug(strtok(NULL, " \n"))) != NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
648 dest = g_string_append(dest, "b "); |
2382 | 649 if (strchr(buddy, '\"') != NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
650 dest = g_string_append(dest, &buddy[1]); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
651 dest = g_string_append_c(dest, ' '); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
652 buddy = g_strchug(strtok(NULL, " \n")); |
2382 | 653 while (strchr(buddy, '\"') == NULL) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
654 dest = g_string_append(dest, buddy); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
655 dest = g_string_append_c(dest, ' '); |
2548
20418e5702eb
[gaim-migrate @ 2561]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
656 buddy = g_strchug(strtok(NULL, " \n")); |
2382 | 657 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
658 buddy[strlen(buddy) - 1] = '\0'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
659 dest = g_string_append(dest, buddy); |
2382 | 660 } else { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
661 dest = g_string_append(dest, buddy); |
2382 | 662 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
663 dest = g_string_append_c(dest, '\n'); |
2382 | 664 } |
665 } | |
666 } | |
667 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
668 return dest; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
669 } |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
670 |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
671 static GString *translate_gnomeicu(FILE *src_fp) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
672 { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
673 char line[BUF_LEN]; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
674 GString *dest = g_string_new("m 1\ng Buddies\n"); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
675 |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
676 while (strstr(fgets(line, BUF_LEN, src_fp), "NewContacts") == NULL); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
677 |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
678 while (fgets(line, BUF_LEN, src_fp)) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
679 char *eq; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
680 g_strchomp(line); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
681 if (line[0] == '\n' || line[0] == '[') |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
682 break; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
683 eq = strchr(line, '='); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
684 if (!eq) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
685 break; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
686 *eq = ':'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
687 eq = strchr(eq, ','); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
688 if (eq) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
689 *eq = '\0'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
690 dest = g_string_append(dest, "b "); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
691 dest = g_string_append(dest, line); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
692 dest = g_string_append_c(dest, '\n'); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
693 } |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
694 |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
695 return dest; |
2382 | 696 } |
4687 | 697 #endif |
2382 | 698 |
699 static gchar *get_screenname_filename(const char *name) | |
700 { | |
701 gchar **split; | |
702 gchar *good; | |
4793 | 703 gchar *ret; |
2382 | 704 |
705 split = g_strsplit(name, G_DIR_SEPARATOR_S, -1); | |
706 good = g_strjoinv(NULL, split); | |
707 g_strfreev(split); | |
708 | |
4793 | 709 ret = g_utf8_strup(good, -1); |
2382 | 710 |
4793 | 711 g_free(good); |
712 | |
713 return ret; | |
2382 | 714 } |
715 | |
4349 | 716 static gboolean gaim_blist_read(const char *filename); |
2382 | 717 |
4687 | 718 |
719 static void do_import(struct gaim_account *account, const char *filename) | |
2382 | 720 { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
721 GString *buf = NULL; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
722 char first[64]; |
2382 | 723 char path[PATHSIZE]; |
724 int len; | |
725 FILE *f; | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
726 struct stat st; |
2382 | 727 |
728 if (filename) { | |
729 g_snprintf(path, sizeof(path), "%s", filename); | |
730 } else { | |
4491 | 731 char *g_screenname = get_screenname_filename(account->username); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
732 char *file = gaim_user_dir(); |
4491 | 733 int protocol = (account->protocol == PROTO_OSCAR) ? (isalpha(account->username[0]) ? PROTO_TOC : PROTO_ICQ): account->protocol; |
2382 | 734 |
735 if (file != (char *)NULL) { | |
4349 | 736 sprintf(path, "%s" G_DIR_SEPARATOR_S "%s.%d.blist", file, g_screenname, protocol); |
2382 | 737 g_free(g_screenname); |
738 } else { | |
739 g_free(g_screenname); | |
740 return; | |
741 } | |
742 } | |
743 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
744 if (stat(path, &st)) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
745 debug_printf("Unable to stat %s.\n", path); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
746 return; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
747 } |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
748 |
2382 | 749 if (!(f = fopen(path, "r"))) { |
750 debug_printf("Unable to open %s.\n", path); | |
751 return; | |
752 } | |
753 | |
754 fgets(first, 64, f); | |
755 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
756 if ((first[0] == '\n') || (first[0] == '\r' && first[1] == '\n')) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
757 fgets(first, 64, f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
758 |
4687 | 759 #if 0 |
4349 | 760 if (!g_strncasecmp(first, "<xml", strlen("<xml"))) { |
761 /* new gaim XML buddy list */ | |
762 gaim_blist_read(path); | |
4687 | 763 |
764 /* We really don't need to bother doing stuf like translating AIM 3 buddy lists anymore */ | |
765 | |
4349 | 766 } else if (!g_strncasecmp(first, "Config {", strlen("Config {"))) { |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
767 /* AIM 4 buddy list */ |
2382 | 768 debug_printf("aim 4\n"); |
769 rewind(f); | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
770 buf = translate_blt(f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
771 } else if (strstr(first, "group") != NULL) { |
2382 | 772 /* AIM 3 buddy list */ |
773 debug_printf("aim 3\n"); | |
774 rewind(f); | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
775 buf = translate_lst(f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
776 } else if (!g_strncasecmp(first, "[User]", strlen("[User]"))) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
777 /* GnomeICU (hopefully) */ |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
778 debug_printf("gnomeicu\n"); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
779 rewind(f); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
780 buf = translate_gnomeicu(f); |
4687 | 781 |
782 } else | |
783 #endif | |
784 if (first[0] == 'm') { | |
785 /* Gaim buddy list - no translation */ | |
786 char buf2[BUF_LONG * 2]; | |
787 buf = g_string_new(""); | |
788 rewind(f); | |
789 while (1) { | |
790 len = fread(buf2, 1, BUF_LONG * 2 - 1, f); | |
791 if (len <= 0) | |
792 break; | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
793 buf2[len] = '\0'; |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
794 buf = g_string_append(buf, buf2); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
795 if (len != BUF_LONG * 2 - 1) |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
796 break; |
4687 | 797 } |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
798 } |
4687 | 799 |
2382 | 800 fclose(f); |
801 | |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
802 if (buf) { |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
803 buf = g_string_prepend(buf, "toc_set_config {"); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
804 buf = g_string_append(buf, "}\n"); |
4491 | 805 parse_toc_buddy_list(account, buf->str); |
2825
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
806 g_string_free(buf, TRUE); |
8cd878c14090
[gaim-migrate @ 2838]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
807 } |
2382 | 808 } |
809 | |
4491 | 810 gboolean gaim_group_on_account(struct group *g, struct gaim_account *account) { |
4785 | 811 GaimBlistNode *bnode; |
812 for(bnode = g->node.child; bnode; bnode = bnode->next) { | |
813 struct buddy *b = (struct buddy *)bnode; | |
814 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
815 continue; | |
4491 | 816 if((!account && b->account->gc) || b->account == account) |
4349 | 817 return TRUE; |
818 } | |
819 return FALSE; | |
820 } | |
821 | |
4497 | 822 static gboolean blist_safe_to_write = FALSE; |
4349 | 823 |
824 static char *blist_parser_group_name = NULL; | |
825 static char *blist_parser_person_name = NULL; | |
826 static char *blist_parser_account_name = NULL; | |
827 static int blist_parser_account_protocol = 0; | |
828 static char *blist_parser_buddy_name = NULL; | |
829 static char *blist_parser_buddy_alias = NULL; | |
830 static char *blist_parser_setting_name = NULL; | |
831 static char *blist_parser_setting_value = NULL; | |
832 static GHashTable *blist_parser_buddy_settings = NULL; | |
833 static int blist_parser_privacy_mode = 0; | |
834 static enum { | |
835 BLIST_TAG_GAIM, | |
836 BLIST_TAG_BLIST, | |
837 BLIST_TAG_GROUP, | |
838 BLIST_TAG_PERSON, | |
839 BLIST_TAG_BUDDY, | |
840 BLIST_TAG_NAME, | |
841 BLIST_TAG_ALIAS, | |
842 BLIST_TAG_SETTING, | |
843 BLIST_TAG_PRIVACY, | |
844 BLIST_TAG_ACCOUNT, | |
845 BLIST_TAG_PERMIT, | |
846 BLIST_TAG_BLOCK, | |
847 BLIST_TAG_IGNORE | |
848 } blist_parser_current_tag; | |
4439 | 849 static gboolean blist_parser_error_occurred = FALSE; |
4349 | 850 |
851 static void blist_start_element_handler (GMarkupParseContext *context, | |
852 const gchar *element_name, | |
853 const gchar **attribute_names, | |
854 const gchar **attribute_values, | |
855 gpointer user_data, | |
856 GError **error) { | |
857 int i; | |
858 | |
859 if(!strcmp(element_name, "gaim")) { | |
860 blist_parser_current_tag = BLIST_TAG_GAIM; | |
861 } else if(!strcmp(element_name, "blist")) { | |
862 blist_parser_current_tag = BLIST_TAG_BLIST; | |
863 } else if(!strcmp(element_name, "group")) { | |
864 blist_parser_current_tag = BLIST_TAG_GROUP; | |
865 for(i=0; attribute_names[i]; i++) { | |
4444 | 866 if(!strcmp(attribute_names[i], "name")) { |
867 g_free(blist_parser_group_name); | |
4349 | 868 blist_parser_group_name = g_strdup(attribute_values[i]); |
4444 | 869 } |
4349 | 870 } |
871 if(blist_parser_group_name) { | |
4687 | 872 struct group *g = gaim_group_new(blist_parser_group_name); |
873 gaim_blist_add_group(g,NULL); | |
4349 | 874 } |
875 } else if(!strcmp(element_name, "person")) { | |
876 blist_parser_current_tag = BLIST_TAG_PERSON; | |
877 for(i=0; attribute_names[i]; i++) { | |
4444 | 878 if(!strcmp(attribute_names[i], "name")) { |
879 g_free(blist_parser_person_name); | |
4349 | 880 blist_parser_person_name = g_strdup(attribute_values[i]); |
4444 | 881 } |
4349 | 882 } |
883 } else if(!strcmp(element_name, "buddy")) { | |
884 blist_parser_current_tag = BLIST_TAG_BUDDY; | |
885 for(i=0; attribute_names[i]; i++) { | |
4444 | 886 if(!strcmp(attribute_names[i], "account")) { |
887 g_free(blist_parser_account_name); | |
4349 | 888 blist_parser_account_name = g_strdup(attribute_values[i]); |
4444 | 889 } else if(!strcmp(attribute_names[i], "protocol")) { |
4349 | 890 blist_parser_account_protocol = atoi(attribute_values[i]); |
4444 | 891 } |
4349 | 892 } |
893 } else if(!strcmp(element_name, "name")) { | |
894 blist_parser_current_tag = BLIST_TAG_NAME; | |
895 } else if(!strcmp(element_name, "alias")) { | |
896 blist_parser_current_tag = BLIST_TAG_ALIAS; | |
897 } else if(!strcmp(element_name, "setting")) { | |
898 blist_parser_current_tag = BLIST_TAG_SETTING; | |
899 for(i=0; attribute_names[i]; i++) { | |
4444 | 900 if(!strcmp(attribute_names[i], "name")) { |
901 g_free(blist_parser_setting_name); | |
4349 | 902 blist_parser_setting_name = g_strdup(attribute_values[i]); |
4444 | 903 } |
4349 | 904 } |
905 } else if(!strcmp(element_name, "privacy")) { | |
906 blist_parser_current_tag = BLIST_TAG_PRIVACY; | |
907 } else if(!strcmp(element_name, "account")) { | |
908 blist_parser_current_tag = BLIST_TAG_ACCOUNT; | |
909 for(i=0; attribute_names[i]; i++) { | |
910 if(!strcmp(attribute_names[i], "protocol")) | |
911 blist_parser_account_protocol = atoi(attribute_values[i]); | |
912 else if(!strcmp(attribute_names[i], "mode")) | |
913 blist_parser_privacy_mode = atoi(attribute_values[i]); | |
4444 | 914 else if(!strcmp(attribute_names[i], "name")) { |
915 g_free(blist_parser_account_name); | |
4349 | 916 blist_parser_account_name = g_strdup(attribute_values[i]); |
4444 | 917 } |
4349 | 918 } |
919 } else if(!strcmp(element_name, "permit")) { | |
920 blist_parser_current_tag = BLIST_TAG_PERMIT; | |
921 } else if(!strcmp(element_name, "block")) { | |
922 blist_parser_current_tag = BLIST_TAG_BLOCK; | |
923 } else if(!strcmp(element_name, "ignore")) { | |
924 blist_parser_current_tag = BLIST_TAG_IGNORE; | |
925 } | |
926 } | |
927 | |
928 static void blist_end_element_handler(GMarkupParseContext *context, | |
929 const gchar *element_name, gpointer user_data, GError **error) { | |
930 if(!strcmp(element_name, "gaim")) { | |
931 } else if(!strcmp(element_name, "blist")) { | |
932 blist_parser_current_tag = BLIST_TAG_GAIM; | |
933 } else if(!strcmp(element_name, "group")) { | |
934 blist_parser_current_tag = BLIST_TAG_BLIST; | |
935 } else if(!strcmp(element_name, "person")) { | |
936 blist_parser_current_tag = BLIST_TAG_GROUP; | |
937 g_free(blist_parser_person_name); | |
938 blist_parser_person_name = NULL; | |
939 } else if(!strcmp(element_name, "buddy")) { | |
4491 | 940 struct gaim_account *account = gaim_account_find(blist_parser_account_name, |
4349 | 941 blist_parser_account_protocol); |
4491 | 942 if(account) { |
4687 | 943 struct buddy *b = gaim_buddy_new(account, blist_parser_buddy_name, blist_parser_buddy_alias); |
944 struct group *g = gaim_find_group(blist_parser_group_name); | |
945 gaim_blist_add_buddy(b,g,NULL); | |
4349 | 946 if(blist_parser_buddy_settings) { |
947 g_hash_table_destroy(b->settings); | |
948 b->settings = blist_parser_buddy_settings; | |
949 } | |
950 } | |
951 blist_parser_current_tag = BLIST_TAG_PERSON; | |
952 g_free(blist_parser_buddy_name); | |
953 blist_parser_buddy_name = NULL; | |
954 g_free(blist_parser_buddy_alias); | |
955 blist_parser_buddy_alias = NULL; | |
956 g_free(blist_parser_account_name); | |
957 blist_parser_account_name = NULL; | |
958 blist_parser_buddy_settings = NULL; | |
959 } else if(!strcmp(element_name, "name")) { | |
960 blist_parser_current_tag = BLIST_TAG_BUDDY; | |
961 } else if(!strcmp(element_name, "alias")) { | |
962 blist_parser_current_tag = BLIST_TAG_BUDDY; | |
963 } else if(!strcmp(element_name, "setting")) { | |
964 if(!blist_parser_buddy_settings) | |
965 blist_parser_buddy_settings = g_hash_table_new_full(g_str_hash, | |
966 g_str_equal, g_free, g_free); | |
967 if(blist_parser_setting_name && blist_parser_setting_value) { | |
968 g_hash_table_replace(blist_parser_buddy_settings, | |
969 g_strdup(blist_parser_setting_name), | |
970 g_strdup(blist_parser_setting_value)); | |
971 } | |
972 g_free(blist_parser_setting_name); | |
973 g_free(blist_parser_setting_value); | |
4720 | 974 blist_parser_setting_name = NULL; |
975 blist_parser_setting_value = NULL; | |
4349 | 976 blist_parser_current_tag = BLIST_TAG_BUDDY; |
977 } else if(!strcmp(element_name, "privacy")) { | |
978 blist_parser_current_tag = BLIST_TAG_GAIM; | |
979 } else if(!strcmp(element_name, "account")) { | |
4491 | 980 struct gaim_account *account = gaim_account_find(blist_parser_account_name, |
4349 | 981 blist_parser_account_protocol); |
4491 | 982 if(account) { |
983 account->permdeny = blist_parser_privacy_mode; | |
4349 | 984 } |
985 blist_parser_current_tag = BLIST_TAG_PRIVACY; | |
986 g_free(blist_parser_account_name); | |
987 blist_parser_account_name = NULL; | |
988 } else if(!strcmp(element_name, "permit")) { | |
4491 | 989 struct gaim_account *account = gaim_account_find(blist_parser_account_name, |
4349 | 990 blist_parser_account_protocol); |
4491 | 991 if(account) { |
992 gaim_privacy_permit_add(account, blist_parser_buddy_name); | |
4349 | 993 } |
4444 | 994 blist_parser_current_tag = BLIST_TAG_ACCOUNT; |
4442 | 995 g_free(blist_parser_buddy_name); |
4444 | 996 blist_parser_buddy_name = NULL; |
4349 | 997 } else if(!strcmp(element_name, "block")) { |
4491 | 998 struct gaim_account *account = gaim_account_find(blist_parser_account_name, |
4349 | 999 blist_parser_account_protocol); |
4491 | 1000 if(account) { |
1001 gaim_privacy_deny_add(account, blist_parser_buddy_name); | |
4349 | 1002 } |
4444 | 1003 blist_parser_current_tag = BLIST_TAG_ACCOUNT; |
4442 | 1004 g_free(blist_parser_buddy_name); |
4444 | 1005 blist_parser_buddy_name = NULL; |
4349 | 1006 } else if(!strcmp(element_name, "ignore")) { |
1007 /* we'll apparently do something with this later */ | |
1008 blist_parser_current_tag = BLIST_TAG_ACCOUNT; | |
1009 } | |
1010 } | |
1011 | |
1012 static void blist_text_handler(GMarkupParseContext *context, const gchar *text, | |
1013 gsize text_len, gpointer user_data, GError **error) { | |
1014 switch(blist_parser_current_tag) { | |
1015 case BLIST_TAG_NAME: | |
1016 blist_parser_buddy_name = g_strndup(text, text_len); | |
1017 break; | |
1018 case BLIST_TAG_ALIAS: | |
1019 blist_parser_buddy_alias = g_strndup(text, text_len); | |
1020 break; | |
1021 case BLIST_TAG_PERMIT: | |
1022 case BLIST_TAG_BLOCK: | |
1023 case BLIST_TAG_IGNORE: | |
1024 blist_parser_buddy_name = g_strndup(text, text_len); | |
1025 break; | |
1026 case BLIST_TAG_SETTING: | |
1027 blist_parser_setting_value = g_strndup(text, text_len); | |
1028 break; | |
1029 default: | |
1030 break; | |
1031 } | |
1032 } | |
1033 | |
4439 | 1034 static void blist_error_handler(GMarkupParseContext *context, GError *error, |
1035 gpointer user_data) { | |
1036 blist_parser_error_occurred = TRUE; | |
1037 debug_printf("error parsing blist.xml: %s\n", error->message); | |
1038 } | |
1039 | |
4349 | 1040 static GMarkupParser blist_parser = { |
1041 blist_start_element_handler, | |
1042 blist_end_element_handler, | |
1043 blist_text_handler, | |
1044 NULL, | |
4439 | 1045 blist_error_handler |
4349 | 1046 }; |
1047 | |
1048 static gboolean gaim_blist_read(const char *filename) { | |
4441 | 1049 gchar *contents = NULL; |
4349 | 1050 gsize length; |
1051 GMarkupParseContext *context; | |
1052 GError *error = NULL; | |
4496 | 1053 |
1054 debug_printf("gaim_blist_read: reading %s\n", filename); | |
4349 | 1055 if(!g_file_get_contents(filename, &contents, &length, &error)) { |
1056 debug_printf("error reading blist: %s\n", error->message); | |
1057 g_error_free(error); | |
1058 return FALSE; | |
1059 } | |
1060 | |
1061 context = g_markup_parse_context_new(&blist_parser, 0, NULL, NULL); | |
1062 | |
1063 if(!g_markup_parse_context_parse(context, contents, length, NULL)) { | |
1064 g_markup_parse_context_free(context); | |
4441 | 1065 g_free(contents); |
4349 | 1066 return FALSE; |
1067 } | |
1068 | |
1069 if(!g_markup_parse_context_end_parse(context, NULL)) { | |
1070 debug_printf("error parsing blist\n"); | |
1071 g_markup_parse_context_free(context); | |
4441 | 1072 g_free(contents); |
4349 | 1073 return FALSE; |
1074 } | |
1075 | |
1076 g_markup_parse_context_free(context); | |
4441 | 1077 g_free(contents); |
1078 | |
4439 | 1079 if(blist_parser_error_occurred) |
1080 return FALSE; | |
1081 | |
4496 | 1082 debug_printf("gaim_blist_read: finished reading %s\n", filename); |
1083 | |
4349 | 1084 return TRUE; |
1085 } | |
1086 | |
1087 void gaim_blist_load() { | |
1088 GSList *accts; | |
1089 char *user_dir = gaim_user_dir(); | |
1090 char *filename; | |
1091 char *msg; | |
1092 | |
4497 | 1093 blist_safe_to_write = TRUE; |
1094 | |
1095 if(!user_dir) | |
4349 | 1096 return; |
1097 | |
1098 filename = g_build_filename(user_dir, "blist.xml", NULL); | |
1099 | |
1100 if(g_file_test(filename, G_FILE_TEST_EXISTS)) { | |
1101 if(!gaim_blist_read(filename)) { | |
1102 msg = g_strdup_printf(_("An error was encountered parsing your " | |
1103 "buddy list. It has not been loaded.")); | |
1104 do_error_dialog(_("Buddy List Error"), msg, GAIM_ERROR); | |
1105 g_free(msg); | |
1106 } | |
4491 | 1107 } else if(g_slist_length(gaim_accounts)) { |
4349 | 1108 /* rob wants to inform the user that their buddy lists are |
1109 * being converted */ | |
1110 msg = g_strdup_printf(_("Gaim is converting your old buddy lists " | |
1111 "to a new format, which will now be located at %s"), | |
1112 filename); | |
1113 do_error_dialog(_("Converting Buddy List"), msg, GAIM_INFO); | |
1114 g_free(msg); | |
1115 | |
1116 /* now, let gtk actually display the dialog before we start anything */ | |
1117 while(gtk_events_pending()) | |
1118 gtk_main_iteration(); | |
1119 | |
1120 /* read in the old lists, then save to the new format */ | |
4491 | 1121 for(accts = gaim_accounts; accts; accts = accts->next) { |
4349 | 1122 do_import(accts->data, NULL); |
1123 } | |
1124 gaim_blist_save(); | |
1125 } | |
1126 | |
1127 g_free(filename); | |
1128 } | |
1129 | |
1130 static void blist_print_buddy_settings(gpointer key, gpointer data, | |
1131 gpointer user_data) { | |
1132 char *key_val = g_markup_escape_text(key, -1); | |
1133 char *data_val = g_markup_escape_text(data, -1); | |
1134 FILE *file = user_data; | |
1135 fprintf(file, "\t\t\t\t\t<setting name=\"%s\">%s</setting>\n", key_val, | |
1136 data_val); | |
1137 g_free(key_val); | |
1138 g_free(data_val); | |
1139 } | |
1140 | |
4491 | 1141 static void gaim_blist_write(FILE *file, struct gaim_account *exp_acct) { |
4687 | 1142 GSList *accounts, *buds; |
4785 | 1143 GaimBlistNode *gnode,*bnode; |
4687 | 1144 struct group *group; |
1145 struct buddy *bud; | |
4349 | 1146 fprintf(file, "<?xml version='1.0' encoding='UTF-8' ?>\n"); |
1147 fprintf(file, "<gaim version=\"1\">\n"); | |
1148 fprintf(file, "\t<blist>\n"); | |
1149 | |
4785 | 1150 for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { |
1151 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
1152 continue; | |
1153 group = (struct group *)gnode; | |
4687 | 1154 if(!exp_acct || gaim_group_on_account(group, exp_acct)) { |
1155 char *group_name = g_markup_escape_text(group->name, -1); | |
4349 | 1156 fprintf(file, "\t\t<group name=\"%s\">\n", group_name); |
4785 | 1157 for(bnode = gnode->child; bnode; bnode = bnode->next) { |
1158 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
1159 continue; | |
1160 bud = (struct buddy *)bnode; | |
4687 | 1161 if(!exp_acct || bud->account == exp_acct) { |
1162 char *bud_name = g_markup_escape_text(bud->name, -1); | |
4349 | 1163 char *bud_alias = NULL; |
4687 | 1164 char *acct_name = g_markup_escape_text(bud->account->username, -1); |
1165 if(bud->alias) | |
1166 bud_alias= g_markup_escape_text(bud->alias, -1); | |
4349 | 1167 fprintf(file, "\t\t\t<person name=\"%s\">\n", |
1168 bud_alias ? bud_alias : bud_name); | |
1169 fprintf(file, "\t\t\t\t<buddy protocol=\"%d\" " | |
4687 | 1170 "account=\"%s\">\n", bud->account->protocol, |
4349 | 1171 acct_name); |
1172 fprintf(file, "\t\t\t\t\t<name>%s</name>\n", bud_name); | |
1173 if(bud_alias) { | |
1174 fprintf(file, "\t\t\t\t\t<alias>%s</alias>\n", | |
1175 bud_alias); | |
1176 } | |
4687 | 1177 g_hash_table_foreach(bud->settings, |
4349 | 1178 blist_print_buddy_settings, file); |
1179 fprintf(file, "\t\t\t\t</buddy>\n"); | |
1180 fprintf(file, "\t\t\t</person>\n"); | |
1181 g_free(bud_name); | |
1182 g_free(bud_alias); | |
1183 g_free(acct_name); | |
1184 } | |
1185 } | |
1186 fprintf(file, "\t\t</group>\n"); | |
1187 g_free(group_name); | |
1188 } | |
1189 } | |
1190 | |
1191 fprintf(file, "\t</blist>\n"); | |
1192 fprintf(file, "\t<privacy>\n"); | |
1193 | |
4491 | 1194 for(accounts = gaim_accounts; accounts; accounts = accounts->next) { |
1195 struct gaim_account *account = accounts->data; | |
1196 char *acct_name = g_markup_escape_text(account->username, -1); | |
1197 if(!exp_acct || account == exp_acct) { | |
4349 | 1198 fprintf(file, "\t\t<account protocol=\"%d\" name=\"%s\" " |
4491 | 1199 "mode=\"%d\">\n", account->protocol, acct_name, account->permdeny); |
1200 for(buds = account->permit; buds; buds = buds->next) { | |
4349 | 1201 char *bud_name = g_markup_escape_text(buds->data, -1); |
1202 fprintf(file, "\t\t\t<permit>%s</permit>\n", bud_name); | |
1203 g_free(bud_name); | |
1204 } | |
4491 | 1205 for(buds = account->deny; buds; buds = buds->next) { |
4349 | 1206 char *bud_name = g_markup_escape_text(buds->data, -1); |
1207 fprintf(file, "\t\t\t<block>%s</block>\n", bud_name); | |
1208 g_free(bud_name); | |
1209 } | |
1210 fprintf(file, "\t\t</account>\n"); | |
1211 } | |
4491 | 1212 g_free(acct_name); |
4349 | 1213 } |
1214 | |
1215 fprintf(file, "\t</privacy>\n"); | |
1216 fprintf(file, "</gaim>\n"); | |
1217 } | |
1218 | |
1219 void gaim_blist_save() { | |
1220 FILE *file; | |
1221 char *user_dir = gaim_user_dir(); | |
1222 char *filename; | |
4891 | 1223 char *filename_real; |
4349 | 1224 |
1225 if(!user_dir) | |
1226 return; | |
4497 | 1227 if(!blist_safe_to_write) { |
1228 debug_printf("AHH!! tried to write the blist before we read it!\n"); | |
1229 return; | |
1230 } | |
1231 | |
4349 | 1232 file = fopen(user_dir, "r"); |
1233 if(!file) | |
1234 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
1235 else | |
1236 fclose(file); | |
1237 | |
4891 | 1238 filename = g_build_filename(user_dir, "blist.xml.save", NULL); |
4349 | 1239 |
1240 if((file = fopen(filename, "w"))) { | |
1241 gaim_blist_write(file, NULL); | |
1242 fclose(file); | |
1243 chmod(filename, S_IRUSR | S_IWUSR); | |
1244 } else { | |
1245 debug_printf("unable to write %s\n", filename); | |
1246 } | |
1247 | |
4891 | 1248 filename_real = g_build_filename(user_dir, "blist.xml", NULL); |
1249 | |
1250 if(rename(filename, filename_real) < 0) | |
1251 debug_printf("error renaming %s to %s\n", filename, filename_real); | |
1252 | |
1253 | |
4349 | 1254 g_free(filename); |
4891 | 1255 g_free(filename_real); |
4349 | 1256 } |
1257 | |
4491 | 1258 gboolean gaim_privacy_permit_add(struct gaim_account *account, const char *who) { |
1259 GSList *d = account->permit; | |
4349 | 1260 char *n = g_strdup(normalize(who)); |
1261 while(d) { | |
4793 | 1262 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) |
4349 | 1263 break; |
1264 d = d->next; | |
1265 } | |
1266 g_free(n); | |
1267 if(!d) { | |
4491 | 1268 account->permit = g_slist_append(account->permit, g_strdup(who)); |
4349 | 1269 return TRUE; |
1270 } | |
1271 | |
1272 return FALSE; | |
1273 } | |
1274 | |
4491 | 1275 gboolean gaim_privacy_permit_remove(struct gaim_account *account, const char *who) { |
1276 GSList *d = account->permit; | |
4349 | 1277 char *n = g_strdup(normalize(who)); |
1278 while(d) { | |
4793 | 1279 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) |
4349 | 1280 break; |
1281 d = d->next; | |
1282 } | |
1283 g_free(n); | |
1284 if(d) { | |
4491 | 1285 account->permit = g_slist_remove(account->permit, d->data); |
4349 | 1286 g_free(d->data); |
1287 return TRUE; | |
1288 } | |
1289 return FALSE; | |
1290 } | |
1291 | |
4491 | 1292 gboolean gaim_privacy_deny_add(struct gaim_account *account, const char *who) { |
1293 GSList *d = account->deny; | |
4349 | 1294 char *n = g_strdup(normalize(who)); |
1295 while(d) { | |
4793 | 1296 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) |
4349 | 1297 break; |
1298 d = d->next; | |
1299 } | |
1300 g_free(n); | |
1301 if(!d) { | |
4491 | 1302 account->deny = g_slist_append(account->deny, g_strdup(who)); |
4349 | 1303 return TRUE; |
1304 } | |
1305 | |
1306 return FALSE; | |
1307 } | |
1308 | |
4491 | 1309 gboolean gaim_privacy_deny_remove(struct gaim_account *account, const char *who) { |
1310 GSList *d = account->deny; | |
4349 | 1311 char *n = g_strdup(normalize(who)); |
1312 while(d) { | |
4793 | 1313 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) |
4349 | 1314 break; |
1315 d = d->next; | |
1316 } | |
1317 g_free(n); | |
1318 if(d) { | |
4491 | 1319 account->deny = g_slist_remove(account->deny, d->data); |
4349 | 1320 g_free(d->data); |
1321 return TRUE; | |
1322 } | |
1323 return FALSE; | |
1324 } | |
1325 | |
1326 void gaim_buddy_set_setting(struct buddy *b, const char *key, | |
1327 const char *value) { | |
1328 if(!b) | |
1329 return; | |
1330 g_hash_table_replace(b->settings, g_strdup(key), g_strdup(value)); | |
1331 } | |
1332 | |
1333 char *gaim_buddy_get_setting(struct buddy *b, const char *key) { | |
1334 if(!b) | |
1335 return NULL; | |
1336 return g_strdup(g_hash_table_lookup(b->settings, key)); | |
1337 } | |
4687 | 1338 |
1339 void gaim_set_blist_ui_ops(struct gaim_blist_ui_ops *ops) | |
1340 { | |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1341 blist_ui_ops = ops; |
4687 | 1342 } |
4695
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1343 |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1344 struct gaim_blist_ui_ops * |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1345 gaim_get_blist_ui_ops(void) |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1346 { |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1347 return blist_ui_ops; |
4bdd9a5fd026
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1348 } |
4701 | 1349 |
1350 int gaim_blist_get_group_size(struct group *group, gboolean offline) { | |
1351 GaimBlistNode *node; | |
1352 int count = 0; | |
1353 | |
1354 if(!group) | |
1355 return 0; | |
1356 | |
1357 for(node = group->node.child; node; node = node->next) { | |
1358 if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
1359 struct buddy *b = (struct buddy *)node; | |
1360 if(b->account->gc || offline) | |
1361 count++; | |
1362 } | |
1363 } | |
1364 | |
1365 return count; | |
1366 } | |
1367 | |
1368 int gaim_blist_get_group_online_count(struct group *group) { | |
1369 GaimBlistNode *node; | |
1370 int count = 0; | |
1371 | |
1372 if(!group) | |
1373 return 0; | |
1374 | |
1375 for(node = group->node.child; node; node = node->next) { | |
1376 if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
1377 struct buddy *b = (struct buddy *)node; | |
1378 if(b->present) | |
1379 count++; | |
1380 } | |
1381 } | |
1382 | |
1383 return count; | |
1384 } | |
1385 | |
1386 |