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