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