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