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