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