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