Fri, 06 Jun 2003 16:53:22 +0000
[gaim-migrate @ 6201]
compile fixes and cleanups
| 5228 | 1 | /* |
| 2 | * gaim | |
| 3 | * | |
| 4 | * Copyright (C) 2003, Sean Egan <sean.egan@binghamton.edu> | |
| 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> | |
| 27 | #include <stdlib.h> | |
| 28 | #include <sys/types.h> | |
| 29 | #include <sys/stat.h> | |
| 30 | #ifndef _WIN32 | |
| 31 | #include <unistd.h> | |
| 32 | #else | |
| 33 | #include <direct.h> | |
| 34 | #endif | |
| 35 | #include <ctype.h> | |
| 36 | #include "gaim.h" | |
| 37 | #include "prpl.h" | |
| 38 | #include "blist.h" | |
|
5436
a0e0bacaa196
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
39 | #include "notify.h" |
|
5545
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
40 | #include "prefs.h" |
| 5228 | 41 | |
| 42 | #ifdef _WIN32 | |
| 43 | #include "win32dep.h" | |
| 44 | #endif | |
| 45 | ||
| 46 | #define PATHSIZE 1024 | |
| 47 | ||
| 48 | struct gaim_buddy_list *gaimbuddylist = NULL; | |
| 49 | static struct gaim_blist_ui_ops *blist_ui_ops = NULL; | |
| 50 | ||
| 51 | /***************************************************************************** | |
| 52 | * Private Utility functions * | |
| 53 | *****************************************************************************/ | |
| 54 | static GaimBlistNode *gaim_blist_get_last_sibling(GaimBlistNode *node) | |
| 55 | { | |
| 56 | GaimBlistNode *n = node; | |
| 57 | if (!n) | |
| 58 | return NULL; | |
| 59 | while (n->next) | |
| 60 | n = n->next; | |
| 61 | return n; | |
| 62 | } | |
| 63 | static GaimBlistNode *gaim_blist_get_last_child(GaimBlistNode *node) | |
| 64 | { | |
| 65 | if (!node) | |
| 66 | return NULL; | |
| 67 | return gaim_blist_get_last_sibling(node->child); | |
| 68 | } | |
| 69 | ||
| 5247 | 70 | struct _gaim_hbuddy { |
| 71 | char *name; | |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
72 | GaimAccount *account; |
| 5758 | 73 | GaimBlistNode *group; |
| 5247 | 74 | }; |
| 75 | ||
| 76 | static guint _gaim_blist_hbuddy_hash (struct _gaim_hbuddy *hb) | |
| 77 | { | |
| 78 | return g_str_hash(hb->name); | |
| 79 | } | |
| 80 | ||
| 81 | static guint _gaim_blist_hbuddy_equal (struct _gaim_hbuddy *hb1, struct _gaim_hbuddy *hb2) | |
| 82 | { | |
| 5758 | 83 | return ((!strcmp(hb1->name, hb2->name)) && hb1->account == hb2->account && hb1->group == hb2->group); |
| 5247 | 84 | } |
| 85 | ||
| 5228 | 86 | /***************************************************************************** |
| 87 | * Public API functions * | |
| 88 | *****************************************************************************/ | |
| 89 | ||
| 90 | struct gaim_buddy_list *gaim_blist_new() | |
| 91 | { | |
| 92 | struct gaim_buddy_list *gbl = g_new0(struct gaim_buddy_list, 1); | |
| 93 | ||
| 94 | gbl->ui_ops = gaim_get_blist_ui_ops(); | |
| 95 | ||
| 5247 | 96 | gbl->buddies = g_hash_table_new ((GHashFunc)_gaim_blist_hbuddy_hash, |
| 97 | (GEqualFunc)_gaim_blist_hbuddy_equal); | |
| 98 | ||
| 5228 | 99 | if (gbl->ui_ops != NULL && gbl->ui_ops->new_list != NULL) |
| 100 | gbl->ui_ops->new_list(gbl); | |
| 101 | ||
| 102 | return gbl; | |
| 103 | } | |
| 104 | ||
| 105 | void | |
| 106 | gaim_set_blist(struct gaim_buddy_list *list) | |
| 107 | { | |
| 108 | gaimbuddylist = list; | |
| 109 | } | |
| 110 | ||
| 111 | struct gaim_buddy_list * | |
| 112 | gaim_get_blist(void) | |
| 113 | { | |
| 114 | return gaimbuddylist; | |
| 115 | } | |
| 116 | ||
| 117 | void gaim_blist_show () | |
| 118 | { | |
| 119 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 120 | if (ops) | |
| 121 | ops->show(gaimbuddylist); | |
| 122 | } | |
| 123 | ||
| 124 | void gaim_blist_destroy() | |
| 125 | { | |
| 126 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 127 | if (ops) | |
| 128 | ops->destroy(gaimbuddylist); | |
| 129 | } | |
| 130 | ||
| 131 | void gaim_blist_set_visible (gboolean show) | |
| 132 | { | |
| 133 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 134 | if (ops) | |
| 135 | ops->set_visible(gaimbuddylist, show); | |
| 136 | } | |
| 137 | ||
| 138 | void gaim_blist_update_buddy_status (struct buddy *buddy, int status) | |
| 139 | { | |
|
5266
cb6fe050ff33
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
140 | struct gaim_blist_ui_ops *ops; |
|
cb6fe050ff33
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
141 | |
|
cb6fe050ff33
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
142 | if (buddy->uc == status) |
|
cb6fe050ff33
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
143 | return; |
|
cb6fe050ff33
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
144 | |
|
cb6fe050ff33
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
145 | ops = gaimbuddylist->ui_ops; |
| 5228 | 146 | |
|
5305
5a6fc3d321d9
[gaim-migrate @ 5677]
David J. Brigada <brigada@prism.net>
parents:
5292
diff
changeset
|
147 | if((status & UC_UNAVAILABLE) != (buddy->uc & UC_UNAVAILABLE)) { |
|
5a6fc3d321d9
[gaim-migrate @ 5677]
David J. Brigada <brigada@prism.net>
parents:
5292
diff
changeset
|
148 | if(status & UC_UNAVAILABLE) |
|
5a6fc3d321d9
[gaim-migrate @ 5677]
David J. Brigada <brigada@prism.net>
parents:
5292
diff
changeset
|
149 | gaim_event_broadcast(event_buddy_away, buddy->account->gc, buddy->name); |
|
5a6fc3d321d9
[gaim-migrate @ 5677]
David J. Brigada <brigada@prism.net>
parents:
5292
diff
changeset
|
150 | else |
|
5a6fc3d321d9
[gaim-migrate @ 5677]
David J. Brigada <brigada@prism.net>
parents:
5292
diff
changeset
|
151 | gaim_event_broadcast(event_buddy_back, buddy->account->gc, buddy->name); |
|
5a6fc3d321d9
[gaim-migrate @ 5677]
David J. Brigada <brigada@prism.net>
parents:
5292
diff
changeset
|
152 | } |
| 5228 | 153 | |
|
5305
5a6fc3d321d9
[gaim-migrate @ 5677]
David J. Brigada <brigada@prism.net>
parents:
5292
diff
changeset
|
154 | buddy->uc = status; |
| 5228 | 155 | if (ops) |
| 156 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 157 | } | |
| 158 | ||
| 159 | static gboolean presence_update_timeout_cb(struct buddy *buddy) { | |
| 160 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 161 | ||
| 162 | if(buddy->present == GAIM_BUDDY_SIGNING_ON) { | |
| 163 | buddy->present = GAIM_BUDDY_ONLINE; | |
| 164 | gaim_event_broadcast(event_buddy_signon, buddy->account->gc, buddy->name); | |
| 165 | } else if(buddy->present == GAIM_BUDDY_SIGNING_OFF) { | |
| 166 | buddy->present = GAIM_BUDDY_OFFLINE; | |
| 167 | } | |
| 168 | ||
| 169 | buddy->timer = 0; | |
| 170 | ||
| 171 | if (ops) | |
| 172 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 173 | ||
| 174 | return FALSE; | |
| 175 | } | |
| 176 | ||
| 177 | void gaim_blist_update_buddy_presence(struct buddy *buddy, int presence) { | |
| 178 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 179 | gboolean do_timer = FALSE; | |
| 180 | ||
| 181 | if (!GAIM_BUDDY_IS_ONLINE(buddy) && presence) { | |
| 182 | buddy->present = GAIM_BUDDY_SIGNING_ON; | |
| 183 | gaim_event_broadcast(event_buddy_signon, buddy->account->gc, buddy->name); | |
| 184 | do_timer = TRUE; | |
| 5277 | 185 | ((struct group *)((GaimBlistNode *)buddy)->parent)->online++; |
| 5228 | 186 | } else if(GAIM_BUDDY_IS_ONLINE(buddy) && !presence) { |
| 187 | buddy->present = GAIM_BUDDY_SIGNING_OFF; | |
| 188 | gaim_event_broadcast(event_buddy_signoff, buddy->account->gc, buddy->name); | |
| 189 | do_timer = TRUE; | |
| 5394 | 190 | ((struct group *)((GaimBlistNode *)buddy)->parent)->online--; |
| 5228 | 191 | } |
| 192 | ||
| 193 | if(do_timer) { | |
| 194 | if(buddy->timer > 0) | |
| 195 | g_source_remove(buddy->timer); | |
| 196 | buddy->timer = g_timeout_add(10000, (GSourceFunc)presence_update_timeout_cb, buddy); | |
| 197 | } | |
| 198 | ||
| 199 | if (ops) | |
| 200 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 201 | } | |
| 202 | ||
| 203 | ||
| 204 | void gaim_blist_update_buddy_idle (struct buddy *buddy, int idle) | |
| 205 | { | |
| 206 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 207 | buddy->idle = idle; | |
| 208 | if (ops) | |
| 209 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 210 | } | |
| 211 | void gaim_blist_update_buddy_evil (struct buddy *buddy, int warning) | |
| 212 | { | |
| 213 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 214 | buddy->evil = warning; | |
| 215 | if (ops) | |
| 216 | ops->update(gaimbuddylist,(GaimBlistNode*)buddy); | |
| 217 | } | |
| 218 | void gaim_blist_update_buddy_icon(struct buddy *buddy) { | |
| 219 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 220 | if(ops) | |
| 221 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 222 | } | |
| 223 | void gaim_blist_rename_buddy (struct buddy *buddy, const char *name) | |
| 224 | { | |
| 225 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 5634 | 226 | g_free(buddy->name); |
| 5228 | 227 | buddy->name = g_strdup(name); |
| 228 | if (ops) | |
| 229 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 230 | } | |
| 5234 | 231 | |
| 232 | void gaim_blist_alias_chat(struct chat *chat, const char *alias) | |
| 233 | { | |
| 234 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 235 | ||
| 5237 | 236 | g_free(chat->alias); |
| 5234 | 237 | |
| 5237 | 238 | if(alias && strlen(alias)) |
| 239 | chat->alias = g_strdup(alias); | |
| 240 | else | |
| 241 | chat->alias = NULL; | |
| 242 | ||
| 5234 | 243 | if(ops) |
| 244 | ops->update(gaimbuddylist, (GaimBlistNode*)chat); | |
| 245 | } | |
| 246 | ||
| 5228 | 247 | void gaim_blist_alias_buddy (struct buddy *buddy, const char *alias) |
| 248 | { | |
| 249 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
|
5676
d3c2fdaf4821
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5634
diff
changeset
|
250 | GaimConversation *conv; |
| 5228 | 251 | |
| 252 | g_free(buddy->alias); | |
| 253 | ||
| 254 | if(alias && strlen(alias)) | |
| 255 | buddy->alias = g_strdup(alias); | |
| 256 | else | |
| 257 | buddy->alias = NULL; | |
| 258 | ||
| 259 | if (ops) | |
| 260 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 261 | ||
| 262 | conv = gaim_find_conversation_with_account(buddy->name, buddy->account); | |
| 263 | ||
| 264 | if (conv) | |
| 265 | gaim_conversation_autoset_title(conv); | |
| 266 | } | |
| 267 | ||
| 268 | void gaim_blist_rename_group(struct group *group, const char *name) | |
| 269 | { | |
| 270 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 5346 | 271 | struct group *dest_group; |
| 272 | GaimBlistNode *prev, *child, *next; | |
| 273 | GSList *accts; | |
| 274 | ||
| 275 | if(!name || !strlen(name) || !strcmp(name, group->name)) { | |
| 276 | /* nothing to do here */ | |
| 277 | return; | |
| 278 | } else if((dest_group = gaim_find_group(name))) { | |
| 279 | /* here we're merging two groups */ | |
| 280 | prev = gaim_blist_get_last_child((GaimBlistNode*)dest_group); | |
| 281 | child = ((GaimBlistNode*)group)->child; | |
| 282 | ||
| 283 | while(child) | |
| 284 | { | |
| 285 | next = child->next; | |
| 286 | if(GAIM_BLIST_NODE_IS_BUDDY(child)) { | |
| 287 | gaim_blist_add_buddy((struct buddy *)child, dest_group, prev); | |
| 288 | prev = child; | |
| 289 | } else if(GAIM_BLIST_NODE_IS_CHAT(child)) { | |
| 290 | gaim_blist_add_chat((struct chat *)child, dest_group, prev); | |
| 291 | prev = child; | |
| 292 | } else { | |
| 293 | gaim_debug(GAIM_DEBUG_ERROR, "blist", | |
| 294 | "Unknown child type in group %s\n", group->name); | |
| 295 | } | |
| 296 | child = next; | |
| 297 | } | |
| 298 | for (accts = gaim_group_get_accounts(group); accts; accts = g_slist_remove(accts, accts->data)) { | |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
299 | GaimAccount *account = accts->data; |
| 5346 | 300 | serv_rename_group(account->gc, group, name); |
| 301 | } | |
| 302 | gaim_blist_remove_group(group); | |
| 303 | } else { | |
| 304 | /* a simple rename */ | |
| 305 | for (accts = gaim_group_get_accounts(group); accts; accts = g_slist_remove(accts, accts->data)) { | |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
306 | GaimAccount *account = accts->data; |
| 5346 | 307 | serv_rename_group(account->gc, group, name); |
| 308 | } | |
| 309 | g_free(group->name); | |
| 310 | group->name = g_strdup(name); | |
| 311 | if (ops) | |
| 312 | ops->update(gaimbuddylist, (GaimBlistNode*)group); | |
| 313 | } | |
| 5228 | 314 | } |
| 5234 | 315 | |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
316 | struct chat *gaim_chat_new(GaimAccount *account, const char *alias, GHashTable *components) |
| 5234 | 317 | { |
| 318 | struct chat *chat; | |
| 319 | struct gaim_blist_ui_ops *ops; | |
| 320 | ||
| 5237 | 321 | if(!components) |
| 5234 | 322 | return NULL; |
| 323 | ||
| 324 | chat = g_new0(struct chat, 1); | |
| 325 | chat->account = account; | |
| 5237 | 326 | if(alias && strlen(alias)) |
| 327 | chat->alias = g_strdup(alias); | |
| 5234 | 328 | chat->components = components; |
| 329 | ||
| 330 | ((GaimBlistNode*)chat)->type = GAIM_BLIST_CHAT_NODE; | |
| 331 | ||
| 332 | ops = gaim_get_blist_ui_ops(); | |
| 333 | ||
| 334 | if (ops != NULL && ops->new_node != NULL) | |
| 335 | ops->new_node((GaimBlistNode *)chat); | |
| 336 | ||
| 337 | return chat; | |
| 338 | } | |
| 339 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
340 | struct buddy *gaim_buddy_new(GaimAccount *account, const char *screenname, const char *alias) |
| 5228 | 341 | { |
| 342 | struct buddy *b; | |
| 343 | struct gaim_blist_ui_ops *ops; | |
| 344 | ||
| 345 | b = g_new0(struct buddy, 1); | |
| 346 | b->account = account; | |
| 347 | b->name = g_strdup(screenname); | |
| 348 | b->alias = g_strdup(alias); | |
| 349 | b->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
| 350 | ((GaimBlistNode*)b)->type = GAIM_BLIST_BUDDY_NODE; | |
| 351 | ||
| 352 | ops = gaim_get_blist_ui_ops(); | |
| 353 | ||
| 354 | if (ops != NULL && ops->new_node != NULL) | |
| 355 | ops->new_node((GaimBlistNode *)b); | |
| 356 | ||
| 357 | return b; | |
| 358 | } | |
| 5634 | 359 | |
| 5234 | 360 | void gaim_blist_add_chat(struct chat *chat, struct group *group, GaimBlistNode *node) |
| 361 | { | |
| 362 | GaimBlistNode *n = node, *cnode = (GaimBlistNode*)chat; | |
| 363 | struct group *g = group; | |
| 364 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 365 | gboolean save = FALSE; | |
| 366 | ||
| 367 | if (!n) { | |
| 368 | if (!g) { | |
| 369 | g = gaim_group_new(_("Chats")); | |
| 5634 | 370 | gaim_blist_add_group(g, |
| 371 | gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
| 5234 | 372 | } |
| 373 | } else { | |
| 374 | g = (struct group*)n->parent; | |
| 375 | } | |
| 376 | ||
| 377 | /* if we're moving to overtop of ourselves, do nothing */ | |
| 378 | if(cnode == n) | |
| 379 | return; | |
| 380 | ||
| 381 | if (cnode->parent) { | |
| 382 | /* This chat was already in the list and is | |
| 383 | * being moved. | |
| 384 | */ | |
| 5277 | 385 | ((struct group *)cnode->parent)->totalsize--; |
| 5287 | 386 | if (chat->account->gc) { |
| 387 | ((struct group *)cnode->parent)->online--; | |
| 5277 | 388 | ((struct group *)cnode->parent)->currentsize--; |
| 5287 | 389 | } |
| 5234 | 390 | if(cnode->next) |
| 391 | cnode->next->prev = cnode->prev; | |
| 392 | if(cnode->prev) | |
| 393 | cnode->prev->next = cnode->next; | |
| 394 | if(cnode->parent->child == cnode) | |
| 395 | cnode->parent->child = cnode->next; | |
| 396 | ||
| 397 | ops->remove(gaimbuddylist, cnode); | |
| 398 | ||
| 399 | save = TRUE; | |
| 400 | } | |
| 401 | ||
| 402 | if (n) { | |
| 403 | if(n->next) | |
| 404 | n->next->prev = cnode; | |
| 405 | cnode->next = n->next; | |
| 406 | cnode->prev = n; | |
| 407 | cnode->parent = n->parent; | |
| 408 | n->next = cnode; | |
| 5277 | 409 | ((struct group *)n->parent)->totalsize++; |
| 5287 | 410 | if (chat->account->gc) { |
| 411 | ((struct group *)n->parent)->online++; | |
| 5277 | 412 | ((struct group *)n->parent)->currentsize++; |
| 5287 | 413 | } |
| 5234 | 414 | } else { |
| 5634 | 415 | if(((GaimBlistNode*)g)->child) |
| 416 | ((GaimBlistNode*)g)->child->prev = cnode; | |
| 417 | cnode->next = ((GaimBlistNode*)g)->child; | |
| 418 | cnode->prev = NULL; | |
| 5234 | 419 | ((GaimBlistNode*)g)->child = cnode; |
| 420 | cnode->parent = (GaimBlistNode*)g; | |
| 5277 | 421 | g->totalsize++; |
| 5287 | 422 | if (chat->account->gc) { |
| 423 | g->online++; | |
| 5277 | 424 | g->currentsize++; |
| 5287 | 425 | } |
| 5234 | 426 | } |
| 427 | ||
| 428 | if (ops) | |
| 429 | ops->update(gaimbuddylist, (GaimBlistNode*)cnode); | |
| 430 | if (save) | |
| 431 | gaim_blist_save(); | |
| 432 | } | |
| 433 | ||
| 5228 | 434 | void gaim_blist_add_buddy (struct buddy *buddy, struct group *group, GaimBlistNode *node) |
| 435 | { | |
| 436 | GaimBlistNode *n = node, *bnode = (GaimBlistNode*)buddy; | |
| 437 | struct group *g = group; | |
| 438 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 5247 | 439 | struct _gaim_hbuddy *hb; |
| 5228 | 440 | gboolean save = FALSE; |
| 441 | ||
| 442 | if (!n) { | |
| 443 | if (!g) { | |
| 444 | g = gaim_group_new(_("Buddies")); | |
| 5634 | 445 | gaim_blist_add_group(g, |
| 446 | gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
| 5228 | 447 | } |
| 448 | } else { | |
| 449 | g = (struct group*)n->parent; | |
| 450 | } | |
| 451 | ||
| 452 | /* if we're moving to overtop of ourselves, do nothing */ | |
| 453 | if(bnode == n) | |
| 454 | return; | |
| 455 | ||
| 456 | if (bnode->parent) { | |
| 457 | /* This buddy was already in the list and is | |
| 458 | * being moved. | |
| 459 | */ | |
| 5394 | 460 | ((struct group *)bnode->parent)->totalsize--; |
| 461 | if (buddy->account->gc) | |
| 5277 | 462 | ((struct group *)bnode->parent)->currentsize--; |
| 5394 | 463 | if (GAIM_BUDDY_IS_ONLINE(buddy)) |
| 5313 | 464 | ((struct group *)bnode->parent)->online--; |
| 5277 | 465 | |
| 5228 | 466 | if(bnode->next) |
| 467 | bnode->next->prev = bnode->prev; | |
| 468 | if(bnode->prev) | |
| 469 | bnode->prev->next = bnode->next; | |
| 470 | if(bnode->parent->child == bnode) | |
| 471 | bnode->parent->child = bnode->next; | |
| 472 | ||
| 473 | ops->remove(gaimbuddylist, bnode); | |
| 474 | ||
| 5277 | 475 | if (bnode->parent != ((GaimBlistNode*)g)) { |
| 5228 | 476 | serv_move_buddy(buddy, (struct group*)bnode->parent, g); |
| 5277 | 477 | } |
| 5228 | 478 | save = TRUE; |
| 479 | } | |
| 480 | ||
| 481 | if (n) { | |
| 482 | if(n->next) | |
| 483 | n->next->prev = (GaimBlistNode*)buddy; | |
| 484 | ((GaimBlistNode*)buddy)->next = n->next; | |
| 485 | ((GaimBlistNode*)buddy)->prev = n; | |
| 486 | ((GaimBlistNode*)buddy)->parent = n->parent; | |
| 487 | n->next = (GaimBlistNode*)buddy; | |
| 5277 | 488 | ((struct group *)n->parent)->totalsize++; |
| 489 | if (buddy->account->gc) | |
| 490 | ((struct group *)n->parent)->currentsize++; | |
| 5394 | 491 | if (GAIM_BUDDY_IS_ONLINE(buddy)) |
| 5313 | 492 | ((struct group *)n->parent)->online++; |
| 5228 | 493 | } else { |
| 5634 | 494 | if(((GaimBlistNode*)g)->child) |
| 495 | ((GaimBlistNode*)g)->child->prev = (GaimBlistNode*)buddy; | |
| 496 | ((GaimBlistNode*)buddy)->prev = NULL; | |
| 497 | ((GaimBlistNode*)buddy)->next = ((GaimBlistNode*)g)->child; | |
| 5228 | 498 | ((GaimBlistNode*)g)->child = (GaimBlistNode*)buddy; |
| 499 | ((GaimBlistNode*)buddy)->parent = (GaimBlistNode*)g; | |
| 5277 | 500 | g->totalsize++; |
| 501 | if (buddy->account->gc) | |
| 502 | g->currentsize++; | |
| 5394 | 503 | if (GAIM_BUDDY_IS_ONLINE(buddy)) |
| 5313 | 504 | g->online++; |
| 5228 | 505 | } |
| 506 | ||
| 5247 | 507 | hb = g_malloc(sizeof(struct _gaim_hbuddy)); |
| 508 | hb->name = g_strdup(normalize(buddy->name)); | |
| 509 | hb->account = buddy->account; | |
| 5758 | 510 | hb->group = ((GaimBlistNode*)buddy)->parent; |
| 5247 | 511 | |
| 512 | if (g_hash_table_lookup(gaimbuddylist->buddies, (gpointer)hb)) { | |
| 513 | /* This guy already exists */ | |
| 514 | g_free(hb->name); | |
| 515 | g_free(hb); | |
| 516 | } else { | |
| 517 | g_hash_table_insert(gaimbuddylist->buddies, (gpointer)hb, (gpointer)buddy); | |
| 518 | } | |
| 519 | ||
| 5228 | 520 | if (ops) |
| 521 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 522 | if (save) | |
| 523 | gaim_blist_save(); | |
| 524 | } | |
| 525 | ||
| 526 | struct group *gaim_group_new(const char *name) | |
| 527 | { | |
| 528 | struct group *g = gaim_find_group(name); | |
| 529 | ||
| 530 | if (!g) { | |
| 531 | struct gaim_blist_ui_ops *ops; | |
| 532 | g= g_new0(struct group, 1); | |
| 533 | g->name = g_strdup(name); | |
| 5277 | 534 | g->totalsize = 0; |
| 535 | g->currentsize = 0; | |
| 536 | g->online = 0; | |
| 5228 | 537 | g->settings = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 538 | g_free, g_free); | |
| 539 | ((GaimBlistNode*)g)->type = GAIM_BLIST_GROUP_NODE; | |
| 540 | ||
| 541 | ops = gaim_get_blist_ui_ops(); | |
| 542 | ||
| 543 | if (ops != NULL && ops->new_node != NULL) | |
| 544 | ops->new_node((GaimBlistNode *)g); | |
| 545 | ||
| 546 | } | |
| 547 | return g; | |
| 548 | } | |
| 549 | ||
| 550 | void gaim_blist_add_group (struct group *group, GaimBlistNode *node) | |
| 551 | { | |
| 552 | struct gaim_blist_ui_ops *ops; | |
| 553 | GaimBlistNode *gnode = (GaimBlistNode*)group; | |
| 554 | gboolean save = FALSE; | |
| 555 | ||
| 556 | if (!gaimbuddylist) | |
| 557 | gaimbuddylist = gaim_blist_new(); | |
| 558 | ops = gaimbuddylist->ui_ops; | |
| 559 | ||
| 560 | if (!gaimbuddylist->root) { | |
| 561 | gaimbuddylist->root = gnode; | |
| 562 | return; | |
| 563 | } | |
| 564 | ||
| 565 | /* if we're moving to overtop of ourselves, do nothing */ | |
| 566 | if(gnode == node) | |
| 567 | return; | |
| 568 | ||
| 569 | if (gaim_find_group(group->name)) { | |
| 570 | /* This is just being moved */ | |
| 571 | ||
| 572 | ops->remove(gaimbuddylist, (GaimBlistNode*)group); | |
| 573 | ||
| 574 | if(gnode == gaimbuddylist->root) | |
| 575 | gaimbuddylist->root = gnode->next; | |
| 576 | if(gnode->prev) | |
| 577 | gnode->prev->next = gnode->next; | |
| 578 | if(gnode->next) | |
| 579 | gnode->next->prev = gnode->prev; | |
| 580 | ||
| 581 | save = TRUE; | |
| 582 | } | |
| 583 | ||
| 5634 | 584 | if (node) { |
| 585 | gnode->next = node->next; | |
| 586 | gnode->prev = node; | |
| 587 | if(node->next) | |
| 588 | node->next->prev = gnode; | |
| 589 | node->next = gnode; | |
| 590 | } else { | |
| 591 | gaimbuddylist->root->prev = gnode; | |
| 592 | gnode->next = gaimbuddylist->root; | |
| 593 | gnode->prev = NULL; | |
| 594 | gaimbuddylist->root = gnode; | |
| 595 | } | |
| 596 | ||
| 5228 | 597 | |
| 598 | if (ops) { | |
| 599 | ops->update(gaimbuddylist, gnode); | |
| 600 | for(node = gnode->child; node; node = node->next) | |
| 601 | ops->update(gaimbuddylist, node); | |
| 602 | } | |
| 603 | if (save) | |
| 604 | gaim_blist_save(); | |
| 605 | } | |
| 606 | ||
| 607 | void gaim_blist_remove_buddy (struct buddy *buddy) | |
| 608 | { | |
| 609 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 610 | ||
| 611 | GaimBlistNode *gnode, *node = (GaimBlistNode*)buddy; | |
| 612 | struct group *group; | |
| 5247 | 613 | struct _gaim_hbuddy hb, *key; |
| 614 | struct buddy *val; | |
| 5228 | 615 | |
| 616 | gnode = node->parent; | |
| 617 | group = (struct group *)gnode; | |
| 618 | ||
| 619 | if(gnode->child == node) | |
| 620 | gnode->child = node->next; | |
| 621 | if (node->prev) | |
| 622 | node->prev->next = node->next; | |
| 623 | if (node->next) | |
| 624 | node->next->prev = node->prev; | |
| 5394 | 625 | group->totalsize--; |
| 626 | if (buddy->account->gc) | |
| 5277 | 627 | group->currentsize--; |
| 5394 | 628 | if (GAIM_BUDDY_IS_ONLINE(buddy)) |
| 629 | group->online--; | |
| 5228 | 630 | |
| 5247 | 631 | hb.name = normalize(buddy->name); |
| 632 | hb.account = buddy->account; | |
| 5758 | 633 | hb.group = ((GaimBlistNode*)buddy)->parent; |
| 5247 | 634 | if (g_hash_table_lookup_extended(gaimbuddylist->buddies, &hb, (gpointer *)&key, (gpointer *)&val)) { |
| 635 | g_hash_table_remove(gaimbuddylist->buddies, &hb); | |
| 636 | g_free(key->name); | |
| 637 | g_free(key); | |
| 638 | } | |
| 639 | ||
| 5292 | 640 | if(buddy->timer > 0) |
| 641 | g_source_remove(buddy->timer); | |
| 642 | ||
| 5228 | 643 | ops->remove(gaimbuddylist, node); |
| 644 | g_hash_table_destroy(buddy->settings); | |
| 645 | g_free(buddy->name); | |
| 646 | g_free(buddy->alias); | |
| 647 | g_free(buddy); | |
| 648 | } | |
| 649 | ||
| 5234 | 650 | void gaim_blist_remove_chat (struct chat *chat) |
| 651 | { | |
| 652 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 653 | ||
| 654 | GaimBlistNode *gnode, *node = (GaimBlistNode*)chat; | |
| 655 | struct group *group; | |
| 656 | ||
| 657 | gnode = node->parent; | |
| 658 | group = (struct group *)gnode; | |
| 659 | ||
| 660 | if(gnode->child == node) | |
| 661 | gnode->child = node->next; | |
| 662 | if (node->prev) | |
| 663 | node->prev->next = node->next; | |
| 664 | if (node->next) | |
| 665 | node->next->prev = node->prev; | |
| 5277 | 666 | group->totalsize--; |
| 5394 | 667 | if (chat->account->gc) { |
| 5277 | 668 | group->currentsize--; |
| 5394 | 669 | group->online--; |
| 670 | } | |
| 5234 | 671 | |
| 672 | ops->remove(gaimbuddylist, node); | |
| 673 | g_hash_table_destroy(chat->components); | |
| 674 | g_free(chat->alias); | |
| 675 | g_free(chat); | |
| 676 | } | |
| 677 | ||
| 5228 | 678 | void gaim_blist_remove_group (struct group *group) |
| 679 | { | |
| 680 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 681 | GaimBlistNode *node = (GaimBlistNode*)group; | |
| 682 | ||
| 683 | if(node->child) { | |
| 684 | char *buf; | |
| 685 | int count = 0; | |
| 686 | GaimBlistNode *child = node->child; | |
| 687 | ||
| 688 | while(child) { | |
| 689 | count++; | |
| 690 | child = child->next; | |
| 691 | } | |
| 692 | ||
| 693 | buf = g_strdup_printf(_("%d buddies from group %s were not " | |
| 694 | "removed because their accounts were not logged in. These " | |
|
5541
d4840f195f45
[gaim-migrate @ 5941]
Christian Hammond <chipx86@chipx86.com>
parents:
5436
diff
changeset
|
695 | "buddies and the group were not removed.\n"), |
| 5228 | 696 | count, group->name); |
|
5436
a0e0bacaa196
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
697 | |
|
5541
d4840f195f45
[gaim-migrate @ 5941]
Christian Hammond <chipx86@chipx86.com>
parents:
5436
diff
changeset
|
698 | gaim_notify_error(NULL, NULL, _("Group not removed"), buf); |
| 5228 | 699 | g_free(buf); |
| 700 | return; | |
| 701 | } | |
| 702 | ||
| 703 | if(gaimbuddylist->root == node) | |
| 704 | gaimbuddylist->root = node->next; | |
| 705 | if (node->prev) | |
| 706 | node->prev->next = node->next; | |
| 707 | if (node->next) | |
| 708 | node->next->prev = node->prev; | |
| 709 | ||
| 710 | ops->remove(gaimbuddylist, node); | |
| 711 | g_free(group->name); | |
| 712 | g_free(group); | |
| 713 | } | |
| 714 | ||
| 715 | char *gaim_get_buddy_alias_only(struct buddy *b) { | |
|
5545
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
716 | if(!b) |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
717 | return NULL; |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
718 | |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
719 | if(b->alias && b->alias[0]) { |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
720 | return b->alias; |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
721 | } |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
722 | else if (b->server_alias != NULL && |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
723 | gaim_prefs_get_bool("/core/buddies/use_server_alias")) { |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
724 | |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
725 | return b->server_alias; |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
726 | } |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
727 | |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
728 | return NULL; |
| 5228 | 729 | } |
| 730 | ||
| 731 | char * gaim_get_buddy_alias (struct buddy *buddy) | |
| 732 | { | |
| 733 | char *ret = gaim_get_buddy_alias_only(buddy); | |
| 734 | if(!ret) | |
| 735 | return buddy ? buddy->name : _("Unknown"); | |
| 736 | return ret; | |
| 737 | ||
| 738 | } | |
| 739 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
740 | struct buddy *gaim_find_buddy(GaimAccount *account, const char *name) |
| 5228 | 741 | { |
| 5758 | 742 | static struct buddy *buddy = NULL; |
| 5247 | 743 | struct _gaim_hbuddy hb; |
| 5758 | 744 | GaimBlistNode *group; |
| 745 | const char *n = NULL; | |
| 5228 | 746 | |
| 747 | if (!gaimbuddylist) | |
| 748 | return NULL; | |
| 5758 | 749 | |
| 750 | if (!name && !buddy); | |
| 5228 | 751 | |
| 5758 | 752 | if (name) { |
| 753 | group = gaimbuddylist->root; | |
| 754 | n = name; | |
| 755 | } else { | |
| 756 | group = ((GaimBlistNode*)buddy)->parent->next; | |
| 757 | n = buddy->name; | |
| 758 | } | |
| 5247 | 759 | |
| 5758 | 760 | while (group) { |
| 761 | hb.name = normalize(n); | |
| 762 | hb.account = account; | |
| 763 | hb.group = group; | |
| 5776 | 764 | if ((buddy = g_hash_table_lookup(gaimbuddylist->buddies, &hb)) != NULL) |
| 5758 | 765 | return buddy; |
| 766 | group = ((GaimBlistNode*)group)->next; | |
| 767 | } | |
| 768 | return NULL; | |
| 5228 | 769 | } |
| 770 | ||
| 771 | struct group *gaim_find_group(const char *name) | |
| 772 | { | |
| 773 | GaimBlistNode *node; | |
| 774 | if (!gaimbuddylist) | |
| 775 | return NULL; | |
| 776 | node = gaimbuddylist->root; | |
| 777 | while(node) { | |
| 778 | if (!strcmp(((struct group*)node)->name, name)) | |
| 779 | return (struct group*)node; | |
| 780 | node = node->next; | |
| 781 | } | |
| 782 | return NULL; | |
| 783 | } | |
| 784 | struct group *gaim_find_buddys_group(struct buddy *buddy) | |
| 785 | { | |
| 786 | if (!buddy) | |
| 787 | return NULL; | |
| 788 | return (struct group*)(((GaimBlistNode*)buddy)->parent); | |
| 789 | } | |
| 790 | ||
| 791 | GSList *gaim_group_get_accounts(struct group *g) | |
| 792 | { | |
| 793 | GSList *l = NULL; | |
| 794 | GaimBlistNode *child = ((GaimBlistNode *)g)->child; | |
| 795 | ||
| 796 | while (child) { | |
| 797 | if (!g_slist_find(l, ((struct buddy*)child)->account)) | |
| 798 | l = g_slist_append(l, ((struct buddy*)child)->account); | |
| 799 | child = child->next; | |
| 800 | } | |
| 801 | return l; | |
| 802 | } | |
| 803 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
804 | void gaim_blist_add_account(GaimAccount *account) |
| 5234 | 805 | { |
| 806 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 807 | GaimBlistNode *group, *buddy; | |
| 808 | ||
| 809 | if(!gaimbuddylist) | |
| 810 | return; | |
| 811 | ||
| 812 | for(group = gaimbuddylist->root; group; group = group->next) { | |
| 813 | if(!GAIM_BLIST_NODE_IS_GROUP(group)) | |
| 814 | continue; | |
| 815 | for(buddy = group->child; buddy; buddy = buddy->next) { | |
| 816 | if(GAIM_BLIST_NODE_IS_BUDDY(buddy)) { | |
| 817 | if (account == ((struct buddy*)buddy)->account) { | |
| 5277 | 818 | ((struct group *)group)->currentsize++; |
| 5234 | 819 | if(ops) |
| 820 | ops->update(gaimbuddylist, buddy); | |
| 821 | } | |
| 822 | } else if(GAIM_BLIST_NODE_IS_CHAT(buddy)) { | |
| 823 | if (account == ((struct chat*)buddy)->account) { | |
| 5287 | 824 | ((struct group *)group)->online++; |
| 5277 | 825 | ((struct group *)group)->currentsize++; |
| 5234 | 826 | if(ops) |
| 827 | ops->update(gaimbuddylist, buddy); | |
| 828 | } | |
| 829 | } | |
| 830 | } | |
| 831 | } | |
| 832 | } | |
| 833 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
834 | void gaim_blist_remove_account(GaimAccount *account) |
| 5228 | 835 | { |
| 836 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 5234 | 837 | GaimBlistNode *group, *buddy; |
| 838 | ||
| 5228 | 839 | if (!gaimbuddylist) |
| 840 | return; | |
| 5234 | 841 | |
| 842 | for(group = gaimbuddylist->root; group; group = group->next) { | |
| 843 | if(!GAIM_BLIST_NODE_IS_GROUP(group)) | |
| 844 | continue; | |
| 845 | for(buddy = group->child; buddy; buddy = buddy->next) { | |
| 846 | if(GAIM_BLIST_NODE_IS_BUDDY(buddy)) { | |
| 847 | if (account == ((struct buddy*)buddy)->account) { | |
| 5394 | 848 | if (GAIM_BUDDY_IS_ONLINE((struct buddy*)buddy)) |
| 5277 | 849 | ((struct group *)group)->online--; |
| 5234 | 850 | ((struct buddy*)buddy)->present = GAIM_BUDDY_OFFLINE; |
| 5394 | 851 | ((struct group *)group)->currentsize--; |
| 5234 | 852 | if(ops) |
| 853 | ops->remove(gaimbuddylist, buddy); | |
| 854 | } | |
| 855 | } else if(GAIM_BLIST_NODE_IS_CHAT(buddy)) { | |
| 856 | if (account == ((struct chat*)buddy)->account) { | |
| 5277 | 857 | ((struct group *)group)->online--; |
| 858 | ((struct group *)group)->currentsize--; | |
| 5234 | 859 | if(ops) |
| 860 | ops->remove(gaimbuddylist, buddy); | |
| 861 | } | |
| 5228 | 862 | } |
| 863 | } | |
| 864 | } | |
| 865 | } | |
| 866 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
867 | void parse_toc_buddy_list(GaimAccount *account, char *config) |
| 5228 | 868 | { |
| 869 | char *c; | |
| 870 | char current[256]; | |
| 871 | GList *bud = NULL; | |
| 872 | ||
| 873 | ||
| 874 | if (config != NULL) { | |
| 875 | ||
| 876 | /* skip "CONFIG:" (if it exists) */ | |
| 877 | c = strncmp(config + 6 /* sizeof(struct sflap_hdr) */ , "CONFIG:", strlen("CONFIG:")) ? | |
| 878 | strtok(config, "\n") : | |
| 879 | strtok(config + 6 /* sizeof(struct sflap_hdr) */ + strlen("CONFIG:"), "\n"); | |
| 880 | do { | |
| 881 | if (c == NULL) | |
| 882 | break; | |
| 883 | if (*c == 'g') { | |
| 884 | char *utf8 = NULL; | |
| 885 | utf8 = gaim_try_conv_to_utf8(c + 2); | |
| 886 | if (utf8 == NULL) { | |
| 887 | g_strlcpy(current, _("Invalid Groupname"), sizeof(current)); | |
| 888 | } else { | |
| 889 | g_strlcpy(current, utf8, sizeof(current)); | |
| 890 | g_free(utf8); | |
| 891 | } | |
| 892 | if (!gaim_find_group(current)) { | |
| 893 | struct group *g = gaim_group_new(current); | |
| 5634 | 894 | gaim_blist_add_group(g, |
| 895 | gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
| 5228 | 896 | } |
| 897 | } else if (*c == 'b') { /*&& !gaim_find_buddy(user, c + 2)) {*/ | |
| 898 | char nm[80], sw[388], *a, *utf8 = NULL; | |
| 899 | ||
| 900 | if ((a = strchr(c + 2, ':')) != NULL) { | |
| 901 | *a++ = '\0'; /* nul the : */ | |
| 902 | } | |
| 903 | ||
| 904 | g_strlcpy(nm, c + 2, sizeof(nm)); | |
| 905 | if (a) { | |
| 906 | utf8 = gaim_try_conv_to_utf8(a); | |
| 907 | if (utf8 == NULL) { | |
| 908 | gaim_debug(GAIM_DEBUG_ERROR, "toc blist", | |
| 909 | "Failed to convert alias for " | |
| 910 | "'%s' to UTF-8\n", nm); | |
| 911 | } | |
| 912 | } | |
| 913 | if (utf8 == NULL) { | |
| 914 | sw[0] = '\0'; | |
| 915 | } else { | |
| 916 | /* This can leave a partial sequence at the end, | |
| 917 | * but who cares? */ | |
| 918 | g_strlcpy(sw, utf8, sizeof(sw)); | |
| 919 | g_free(utf8); | |
| 920 | } | |
| 921 | ||
| 922 | if (!gaim_find_buddy(account, nm)) { | |
| 923 | struct buddy *b = gaim_buddy_new(account, nm, sw); | |
| 924 | struct group *g = gaim_find_group(current); | |
| 5634 | 925 | gaim_blist_add_buddy(b, g, |
| 926 | gaim_blist_get_last_child((GaimBlistNode*)g)); | |
| 5228 | 927 | bud = g_list_append(bud, g_strdup(nm)); |
| 928 | } | |
| 929 | } else if (*c == 'p') { | |
| 930 | gaim_privacy_permit_add(account, c + 2); | |
| 931 | } else if (*c == 'd') { | |
| 932 | gaim_privacy_deny_add(account, c + 2); | |
| 933 | } else if (!strncmp("toc", c, 3)) { | |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
934 | sscanf(c + strlen(c) - 1, "%d", &account->perm_deny); |
| 5228 | 935 | gaim_debug(GAIM_DEBUG_MISC, "toc blist", |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
936 | "permdeny: %d\n", account->perm_deny); |
|
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
937 | if (account->perm_deny == 0) |
|
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
938 | account->perm_deny = 1; |
| 5228 | 939 | } else if (*c == 'm') { |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
940 | sscanf(c + 2, "%d", &account->perm_deny); |
| 5228 | 941 | gaim_debug(GAIM_DEBUG_MISC, "toc blist", |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
942 | "permdeny: %d\n", account->perm_deny); |
|
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
943 | if (account->perm_deny == 0) |
|
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
944 | account->perm_deny = 1; |
| 5228 | 945 | } |
| 946 | } while ((c = strtok(NULL, "\n"))); | |
| 947 | ||
| 948 | if(account->gc) { | |
| 949 | if(bud) { | |
| 950 | GList *node = bud; | |
| 951 | serv_add_buddies(account->gc, bud); | |
| 952 | while(node) { | |
| 953 | g_free(node->data); | |
| 954 | node = node->next; | |
| 955 | } | |
| 956 | } | |
| 957 | serv_set_permit_deny(account->gc); | |
| 958 | } | |
| 959 | g_list_free(bud); | |
| 960 | } | |
| 961 | } | |
| 962 | ||
| 963 | #if 0 | |
| 964 | /* translate an AIM 3 buddylist (*.lst) to a Gaim buddylist */ | |
| 965 | static GString *translate_lst(FILE *src_fp) | |
| 966 | { | |
| 967 | char line[BUF_LEN], *line2; | |
| 968 | char *name; | |
| 969 | int i; | |
| 970 | ||
| 971 | GString *dest = g_string_new("m 1\n"); | |
| 972 | ||
| 973 | while (fgets(line, BUF_LEN, src_fp)) { | |
| 974 | line2 = g_strchug(line); | |
| 975 | if (strstr(line2, "group") == line2) { | |
| 976 | name = strpbrk(line2, " \t\n\r\f") + 1; | |
| 977 | dest = g_string_append(dest, "g "); | |
| 978 | for (i = 0; i < strcspn(name, "\n\r"); i++) | |
| 979 | if (name[i] != '\"') | |
| 980 | dest = g_string_append_c(dest, name[i]); | |
| 981 | dest = g_string_append_c(dest, '\n'); | |
| 982 | } | |
| 983 | if (strstr(line2, "buddy") == line2) { | |
| 984 | name = strpbrk(line2, " \t\n\r\f") + 1; | |
| 985 | dest = g_string_append(dest, "b "); | |
| 986 | for (i = 0; i < strcspn(name, "\n\r"); i++) | |
| 987 | if (name[i] != '\"') | |
| 988 | dest = g_string_append_c(dest, name[i]); | |
| 989 | dest = g_string_append_c(dest, '\n'); | |
| 990 | } | |
| 991 | } | |
| 992 | ||
| 993 | return dest; | |
| 994 | } | |
| 995 | ||
| 996 | ||
| 997 | /* translate an AIM 4 buddylist (*.blt) to Gaim format */ | |
| 998 | static GString *translate_blt(FILE *src_fp) | |
| 999 | { | |
| 1000 | int i; | |
| 1001 | char line[BUF_LEN]; | |
| 1002 | char *buddy; | |
| 1003 | ||
| 1004 | GString *dest = g_string_new("m 1\n"); | |
| 1005 | ||
| 1006 | while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL); | |
| 1007 | while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL); | |
| 1008 | ||
| 1009 | while (1) { | |
| 1010 | fgets(line, BUF_LEN, src_fp); g_strchomp(line); | |
| 1011 | if (strchr(line, '}') != NULL) | |
| 1012 | break; | |
| 1013 | ||
| 1014 | if (strchr(line, '{') != NULL) { | |
| 1015 | /* Syntax starting with "<group> {" */ | |
| 1016 | ||
| 1017 | dest = g_string_append(dest, "g "); | |
| 1018 | buddy = g_strchug(strtok(line, "{")); | |
| 1019 | for (i = 0; i < strlen(buddy); i++) | |
| 1020 | if (buddy[i] != '\"') | |
| 1021 | dest = g_string_append_c(dest, buddy[i]); | |
| 1022 | dest = g_string_append_c(dest, '\n'); | |
| 1023 | while (strchr(fgets(line, BUF_LEN, src_fp), '}') == NULL) { | |
| 1024 | gboolean pounce = FALSE; | |
| 1025 | char *e; | |
| 1026 | g_strchomp(line); | |
| 1027 | buddy = g_strchug(line); | |
| 1028 | gaim_debug(GAIM_DEBUG_MISC, "AIM 4 blt import", | |
| 1029 | "buddy: \"%s\"\n", buddy); | |
| 1030 | dest = g_string_append(dest, "b "); | |
| 1031 | if (strchr(buddy, '{') != NULL) { | |
| 1032 | /* buddy pounce, etc */ | |
| 1033 | char *pos = strchr(buddy, '{') - 1; | |
| 1034 | *pos = 0; | |
| 1035 | pounce = TRUE; | |
| 1036 | } | |
| 1037 | if ((e = strchr(buddy, '\"')) != NULL) { | |
| 1038 | *e = '\0'; | |
| 1039 | buddy++; | |
| 1040 | } | |
| 1041 | dest = g_string_append(dest, buddy); | |
| 1042 | dest = g_string_append_c(dest, '\n'); | |
| 1043 | if (pounce) | |
| 1044 | do | |
| 1045 | fgets(line, BUF_LEN, src_fp); | |
| 1046 | while (!strchr(line, '}')); | |
| 1047 | } | |
| 1048 | } else { | |
| 1049 | ||
| 1050 | /* Syntax "group buddy buddy ..." */ | |
| 1051 | buddy = g_strchug(strtok(line, " \n")); | |
| 1052 | dest = g_string_append(dest, "g "); | |
| 1053 | if (strchr(buddy, '\"') != NULL) { | |
| 1054 | dest = g_string_append(dest, &buddy[1]); | |
| 1055 | dest = g_string_append_c(dest, ' '); | |
| 1056 | buddy = g_strchug(strtok(NULL, " \n")); | |
| 1057 | while (strchr(buddy, '\"') == NULL) { | |
| 1058 | dest = g_string_append(dest, buddy); | |
| 1059 | dest = g_string_append_c(dest, ' '); | |
| 1060 | buddy = g_strchug(strtok(NULL, " \n")); | |
| 1061 | } | |
| 1062 | buddy[strlen(buddy) - 1] = '\0'; | |
| 1063 | dest = g_string_append(dest, buddy); | |
| 1064 | } else { | |
| 1065 | dest = g_string_append(dest, buddy); | |
| 1066 | } | |
| 1067 | dest = g_string_append_c(dest, '\n'); | |
| 1068 | while ((buddy = g_strchug(strtok(NULL, " \n"))) != NULL) { | |
| 1069 | dest = g_string_append(dest, "b "); | |
| 1070 | if (strchr(buddy, '\"') != NULL) { | |
| 1071 | dest = g_string_append(dest, &buddy[1]); | |
| 1072 | dest = g_string_append_c(dest, ' '); | |
| 1073 | buddy = g_strchug(strtok(NULL, " \n")); | |
| 1074 | while (strchr(buddy, '\"') == NULL) { | |
| 1075 | dest = g_string_append(dest, buddy); | |
| 1076 | dest = g_string_append_c(dest, ' '); | |
| 1077 | buddy = g_strchug(strtok(NULL, " \n")); | |
| 1078 | } | |
| 1079 | buddy[strlen(buddy) - 1] = '\0'; | |
| 1080 | dest = g_string_append(dest, buddy); | |
| 1081 | } else { | |
| 1082 | dest = g_string_append(dest, buddy); | |
| 1083 | } | |
| 1084 | dest = g_string_append_c(dest, '\n'); | |
| 1085 | } | |
| 1086 | } | |
| 1087 | } | |
| 1088 | ||
| 1089 | return dest; | |
| 1090 | } | |
| 1091 | ||
| 1092 | static GString *translate_gnomeicu(FILE *src_fp) | |
| 1093 | { | |
| 1094 | char line[BUF_LEN]; | |
| 1095 | GString *dest = g_string_new("m 1\ng Buddies\n"); | |
| 1096 | ||
| 1097 | while (strstr(fgets(line, BUF_LEN, src_fp), "NewContacts") == NULL); | |
| 1098 | ||
| 1099 | while (fgets(line, BUF_LEN, src_fp)) { | |
| 1100 | char *eq; | |
| 1101 | g_strchomp(line); | |
| 1102 | if (line[0] == '\n' || line[0] == '[') | |
| 1103 | break; | |
| 1104 | eq = strchr(line, '='); | |
| 1105 | if (!eq) | |
| 1106 | break; | |
| 1107 | *eq = ':'; | |
| 1108 | eq = strchr(eq, ','); | |
| 1109 | if (eq) | |
| 1110 | *eq = '\0'; | |
| 1111 | dest = g_string_append(dest, "b "); | |
| 1112 | dest = g_string_append(dest, line); | |
| 1113 | dest = g_string_append_c(dest, '\n'); | |
| 1114 | } | |
| 1115 | ||
| 1116 | return dest; | |
| 1117 | } | |
| 1118 | #endif | |
| 1119 | ||
| 1120 | static gchar *get_screenname_filename(const char *name) | |
| 1121 | { | |
| 1122 | gchar **split; | |
| 1123 | gchar *good; | |
| 1124 | gchar *ret; | |
| 1125 | ||
| 1126 | split = g_strsplit(name, G_DIR_SEPARATOR_S, -1); | |
| 1127 | good = g_strjoinv(NULL, split); | |
| 1128 | g_strfreev(split); | |
| 1129 | ||
| 1130 | ret = g_utf8_strup(good, -1); | |
| 1131 | ||
| 1132 | g_free(good); | |
| 1133 | ||
| 1134 | return ret; | |
| 1135 | } | |
| 1136 | ||
| 1137 | static gboolean gaim_blist_read(const char *filename); | |
| 1138 | ||
| 1139 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1140 | static void do_import(GaimAccount *account, const char *filename) |
| 5228 | 1141 | { |
| 1142 | GString *buf = NULL; | |
| 1143 | char first[64]; | |
| 1144 | char path[PATHSIZE]; | |
| 1145 | int len; | |
| 1146 | FILE *f; | |
| 1147 | struct stat st; | |
| 1148 | ||
| 1149 | if (filename) { | |
| 1150 | g_snprintf(path, sizeof(path), "%s", filename); | |
| 1151 | } else { | |
| 1152 | char *g_screenname = get_screenname_filename(account->username); | |
| 1153 | char *file = gaim_user_dir(); | |
| 1154 | int protocol = (account->protocol == GAIM_PROTO_OSCAR) ? (isalpha(account->username[0]) ? GAIM_PROTO_TOC : GAIM_PROTO_ICQ): account->protocol; | |
| 1155 | ||
| 1156 | if (file != (char *)NULL) { | |
|
5435
990c340ecb6d
[gaim-migrate @ 5817]
Mark Doliner <markdoliner@pidgin.im>
parents:
5394
diff
changeset
|
1157 | snprintf(path, PATHSIZE, "%s" G_DIR_SEPARATOR_S "%s.%d.blist", file, g_screenname, protocol); |
| 5228 | 1158 | g_free(g_screenname); |
| 1159 | } else { | |
| 1160 | g_free(g_screenname); | |
| 1161 | return; | |
| 1162 | } | |
| 1163 | } | |
| 1164 | ||
| 1165 | if (stat(path, &st)) { | |
| 1166 | gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Unable to stat %s.\n", | |
| 1167 | path); | |
| 1168 | return; | |
| 1169 | } | |
| 1170 | ||
| 1171 | if (!(f = fopen(path, "r"))) { | |
| 1172 | gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Unable to open %s.\n", | |
| 1173 | path); | |
| 1174 | return; | |
| 1175 | } | |
| 1176 | ||
| 1177 | fgets(first, 64, f); | |
| 1178 | ||
| 1179 | if ((first[0] == '\n') || (first[0] == '\r' && first[1] == '\n')) | |
| 1180 | fgets(first, 64, f); | |
| 1181 | ||
| 1182 | #if 0 | |
| 1183 | if (!g_strncasecmp(first, "<xml", strlen("<xml"))) { | |
| 1184 | /* new gaim XML buddy list */ | |
| 1185 | gaim_blist_read(path); | |
| 1186 | ||
| 1187 | /* We really don't need to bother doing stuf like translating AIM 3 buddy lists anymore */ | |
| 1188 | ||
| 1189 | } else if (!g_strncasecmp(first, "Config {", strlen("Config {"))) { | |
| 1190 | /* AIM 4 buddy list */ | |
| 1191 | gaim_debug(GAIM_DEBUG_MISC, "blist import", "aim 4\n"); | |
| 1192 | rewind(f); | |
| 1193 | buf = translate_blt(f); | |
| 1194 | } else if (strstr(first, "group") != NULL) { | |
| 1195 | /* AIM 3 buddy list */ | |
| 1196 | gaim_debug(GAIM_DEBUG_MISC, "blist import", "aim 3\n"); | |
| 1197 | rewind(f); | |
| 1198 | buf = translate_lst(f); | |
| 1199 | } else if (!g_strncasecmp(first, "[User]", strlen("[User]"))) { | |
| 1200 | /* GnomeICU (hopefully) */ | |
| 1201 | gaim_debug(GAIM_DEBUG_MISC, "blist import", "gnomeicu\n"); | |
| 1202 | rewind(f); | |
| 1203 | buf = translate_gnomeicu(f); | |
| 1204 | ||
| 1205 | } else | |
| 1206 | #endif | |
| 1207 | if (first[0] == 'm') { | |
| 1208 | /* Gaim buddy list - no translation */ | |
| 1209 | char buf2[BUF_LONG * 2]; | |
| 1210 | buf = g_string_new(""); | |
| 1211 | rewind(f); | |
| 1212 | while (1) { | |
| 1213 | len = fread(buf2, 1, BUF_LONG * 2 - 1, f); | |
| 1214 | if (len <= 0) | |
| 1215 | break; | |
| 1216 | buf2[len] = '\0'; | |
| 1217 | buf = g_string_append(buf, buf2); | |
| 1218 | if (len != BUF_LONG * 2 - 1) | |
| 1219 | break; | |
| 1220 | } | |
| 1221 | } | |
| 1222 | ||
| 1223 | fclose(f); | |
| 1224 | ||
| 1225 | if (buf) { | |
| 1226 | buf = g_string_prepend(buf, "toc_set_config {"); | |
| 1227 | buf = g_string_append(buf, "}\n"); | |
| 1228 | parse_toc_buddy_list(account, buf->str); | |
| 1229 | g_string_free(buf, TRUE); | |
| 1230 | } | |
| 1231 | } | |
| 1232 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1233 | gboolean gaim_group_on_account(struct group *g, GaimAccount *account) { |
| 5228 | 1234 | GaimBlistNode *bnode; |
| 1235 | for(bnode = g->node.child; bnode; bnode = bnode->next) { | |
| 1236 | struct buddy *b = (struct buddy *)bnode; | |
| 1237 | if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
| 1238 | continue; | |
| 1239 | if((!account && b->account->gc) || b->account == account) | |
| 1240 | return TRUE; | |
| 1241 | } | |
| 1242 | return FALSE; | |
| 1243 | } | |
| 1244 | ||
| 1245 | static gboolean blist_safe_to_write = FALSE; | |
| 1246 | ||
| 1247 | static char *blist_parser_group_name = NULL; | |
| 1248 | static char *blist_parser_person_name = NULL; | |
| 1249 | static char *blist_parser_account_name = NULL; | |
| 1250 | static int blist_parser_account_protocol = 0; | |
| 5234 | 1251 | static char *blist_parser_chat_alias = NULL; |
| 1252 | static char *blist_parser_component_name = NULL; | |
| 1253 | static char *blist_parser_component_value = NULL; | |
| 5228 | 1254 | static char *blist_parser_buddy_name = NULL; |
| 1255 | static char *blist_parser_buddy_alias = NULL; | |
| 1256 | static char *blist_parser_setting_name = NULL; | |
| 1257 | static char *blist_parser_setting_value = NULL; | |
| 1258 | static GHashTable *blist_parser_buddy_settings = NULL; | |
| 1259 | static GHashTable *blist_parser_group_settings = NULL; | |
| 5234 | 1260 | static GHashTable *blist_parser_chat_components = NULL; |
| 5228 | 1261 | static int blist_parser_privacy_mode = 0; |
| 1262 | static GList *tag_stack = NULL; | |
| 1263 | enum { | |
| 1264 | BLIST_TAG_GAIM, | |
| 1265 | BLIST_TAG_BLIST, | |
| 1266 | BLIST_TAG_GROUP, | |
| 5234 | 1267 | BLIST_TAG_CHAT, |
| 1268 | BLIST_TAG_COMPONENT, | |
| 5228 | 1269 | BLIST_TAG_PERSON, |
| 1270 | BLIST_TAG_BUDDY, | |
| 1271 | BLIST_TAG_NAME, | |
| 1272 | BLIST_TAG_ALIAS, | |
| 1273 | BLIST_TAG_SETTING, | |
| 1274 | BLIST_TAG_PRIVACY, | |
| 1275 | BLIST_TAG_ACCOUNT, | |
| 1276 | BLIST_TAG_PERMIT, | |
| 1277 | BLIST_TAG_BLOCK, | |
| 1278 | BLIST_TAG_IGNORE | |
| 1279 | }; | |
| 1280 | static gboolean blist_parser_error_occurred = FALSE; | |
| 1281 | ||
| 1282 | static void blist_start_element_handler (GMarkupParseContext *context, | |
| 1283 | const gchar *element_name, | |
| 1284 | const gchar **attribute_names, | |
| 1285 | const gchar **attribute_values, | |
| 1286 | gpointer user_data, | |
| 1287 | GError **error) { | |
| 1288 | int i; | |
| 1289 | ||
| 1290 | if(!strcmp(element_name, "gaim")) { | |
| 1291 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_GAIM)); | |
| 1292 | } else if(!strcmp(element_name, "blist")) { | |
| 1293 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BLIST)); | |
| 1294 | } else if(!strcmp(element_name, "group")) { | |
| 1295 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_GROUP)); | |
| 1296 | for(i=0; attribute_names[i]; i++) { | |
| 1297 | if(!strcmp(attribute_names[i], "name")) { | |
| 1298 | g_free(blist_parser_group_name); | |
| 1299 | blist_parser_group_name = g_strdup(attribute_values[i]); | |
| 1300 | } | |
| 1301 | } | |
| 1302 | if(blist_parser_group_name) { | |
| 1303 | struct group *g = gaim_group_new(blist_parser_group_name); | |
| 5634 | 1304 | gaim_blist_add_group(g, |
| 1305 | gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
| 5228 | 1306 | } |
| 5234 | 1307 | } else if(!strcmp(element_name, "chat")) { |
| 1308 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_CHAT)); | |
| 1309 | for(i=0; attribute_names[i]; i++) { | |
| 1310 | if(!strcmp(attribute_names[i], "account")) { | |
| 1311 | g_free(blist_parser_account_name); | |
| 1312 | blist_parser_account_name = g_strdup(attribute_values[i]); | |
| 1313 | } else if(!strcmp(attribute_names[i], "protocol")) { | |
| 1314 | blist_parser_account_protocol = atoi(attribute_values[i]); | |
| 1315 | } | |
| 1316 | } | |
| 5228 | 1317 | } else if(!strcmp(element_name, "person")) { |
| 1318 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PERSON)); | |
| 1319 | for(i=0; attribute_names[i]; i++) { | |
| 1320 | if(!strcmp(attribute_names[i], "name")) { | |
| 1321 | g_free(blist_parser_person_name); | |
| 1322 | blist_parser_person_name = g_strdup(attribute_values[i]); | |
| 1323 | } | |
| 1324 | } | |
| 1325 | } else if(!strcmp(element_name, "buddy")) { | |
| 1326 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BUDDY)); | |
| 1327 | for(i=0; attribute_names[i]; i++) { | |
| 1328 | if(!strcmp(attribute_names[i], "account")) { | |
| 1329 | g_free(blist_parser_account_name); | |
| 1330 | blist_parser_account_name = g_strdup(attribute_values[i]); | |
| 1331 | } else if(!strcmp(attribute_names[i], "protocol")) { | |
| 1332 | blist_parser_account_protocol = atoi(attribute_values[i]); | |
| 1333 | } | |
| 1334 | } | |
| 1335 | } else if(!strcmp(element_name, "name")) { | |
| 1336 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_NAME)); | |
| 1337 | } else if(!strcmp(element_name, "alias")) { | |
| 1338 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_ALIAS)); | |
| 1339 | } else if(!strcmp(element_name, "setting")) { | |
| 1340 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_SETTING)); | |
| 1341 | for(i=0; attribute_names[i]; i++) { | |
| 1342 | if(!strcmp(attribute_names[i], "name")) { | |
| 1343 | g_free(blist_parser_setting_name); | |
| 1344 | blist_parser_setting_name = g_strdup(attribute_values[i]); | |
| 1345 | } | |
| 1346 | } | |
| 5234 | 1347 | } else if(!strcmp(element_name, "component")) { |
| 1348 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_COMPONENT)); | |
| 1349 | for(i=0; attribute_names[i]; i++) { | |
| 1350 | if(!strcmp(attribute_names[i], "name")) { | |
| 1351 | g_free(blist_parser_component_name); | |
| 1352 | blist_parser_component_name = g_strdup(attribute_values[i]); | |
| 1353 | } | |
| 1354 | } | |
| 1355 | ||
| 5228 | 1356 | } else if(!strcmp(element_name, "privacy")) { |
| 1357 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PRIVACY)); | |
| 1358 | } else if(!strcmp(element_name, "account")) { | |
| 1359 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_ACCOUNT)); | |
| 1360 | for(i=0; attribute_names[i]; i++) { | |
| 1361 | if(!strcmp(attribute_names[i], "protocol")) | |
| 1362 | blist_parser_account_protocol = atoi(attribute_values[i]); | |
| 1363 | else if(!strcmp(attribute_names[i], "mode")) | |
| 1364 | blist_parser_privacy_mode = atoi(attribute_values[i]); | |
| 1365 | else if(!strcmp(attribute_names[i], "name")) { | |
| 1366 | g_free(blist_parser_account_name); | |
| 1367 | blist_parser_account_name = g_strdup(attribute_values[i]); | |
| 1368 | } | |
| 1369 | } | |
| 1370 | } else if(!strcmp(element_name, "permit")) { | |
| 1371 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PERMIT)); | |
| 1372 | } else if(!strcmp(element_name, "block")) { | |
| 1373 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BLOCK)); | |
| 1374 | } else if(!strcmp(element_name, "ignore")) { | |
| 1375 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_IGNORE)); | |
| 1376 | } | |
| 1377 | } | |
| 1378 | ||
| 1379 | static void blist_end_element_handler(GMarkupParseContext *context, | |
| 1380 | const gchar *element_name, gpointer user_data, GError **error) { | |
| 1381 | if(!strcmp(element_name, "gaim")) { | |
| 1382 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1383 | } else if(!strcmp(element_name, "blist")) { | |
| 1384 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1385 | } else if(!strcmp(element_name, "group")) { | |
| 1386 | if(blist_parser_group_settings) { | |
| 1387 | struct group *g = gaim_find_group(blist_parser_group_name); | |
| 1388 | g_hash_table_destroy(g->settings); | |
| 1389 | g->settings = blist_parser_group_settings; | |
| 1390 | } | |
| 1391 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1392 | blist_parser_group_settings = NULL; | |
| 5234 | 1393 | } else if(!strcmp(element_name, "chat")) { |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1394 | GaimAccount *account = gaim_account_find(blist_parser_account_name, |
| 5234 | 1395 | blist_parser_account_protocol); |
| 5237 | 1396 | if(account) { |
| 5234 | 1397 | struct chat *chat = gaim_chat_new(account, blist_parser_chat_alias, blist_parser_chat_components); |
| 1398 | struct group *g = gaim_find_group(blist_parser_group_name); | |
| 5634 | 1399 | gaim_blist_add_chat(chat,g, |
| 1400 | gaim_blist_get_last_child((GaimBlistNode*)g)); | |
| 5234 | 1401 | } |
| 1402 | g_free(blist_parser_chat_alias); | |
| 1403 | blist_parser_chat_alias = NULL; | |
| 1404 | g_free(blist_parser_account_name); | |
| 1405 | blist_parser_account_name = NULL; | |
| 1406 | blist_parser_chat_components = NULL; | |
| 1407 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 5228 | 1408 | } else if(!strcmp(element_name, "person")) { |
| 1409 | g_free(blist_parser_person_name); | |
| 1410 | blist_parser_person_name = NULL; | |
| 1411 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1412 | } else if(!strcmp(element_name, "buddy")) { | |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1413 | GaimAccount *account = gaim_account_find(blist_parser_account_name, |
| 5228 | 1414 | blist_parser_account_protocol); |
| 1415 | if(account) { | |
| 1416 | struct buddy *b = gaim_buddy_new(account, blist_parser_buddy_name, blist_parser_buddy_alias); | |
| 1417 | struct group *g = gaim_find_group(blist_parser_group_name); | |
| 5634 | 1418 | gaim_blist_add_buddy(b,g, |
| 1419 | gaim_blist_get_last_child((GaimBlistNode*)g)); | |
| 5228 | 1420 | if(blist_parser_buddy_settings) { |
| 1421 | g_hash_table_destroy(b->settings); | |
| 1422 | b->settings = blist_parser_buddy_settings; | |
| 1423 | } | |
| 1424 | } | |
| 1425 | g_free(blist_parser_buddy_name); | |
| 1426 | blist_parser_buddy_name = NULL; | |
| 1427 | g_free(blist_parser_buddy_alias); | |
| 1428 | blist_parser_buddy_alias = NULL; | |
| 1429 | g_free(blist_parser_account_name); | |
| 1430 | blist_parser_account_name = NULL; | |
| 1431 | blist_parser_buddy_settings = NULL; | |
| 1432 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1433 | } else if(!strcmp(element_name, "name")) { | |
| 1434 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1435 | } else if(!strcmp(element_name, "alias")) { | |
| 1436 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 5234 | 1437 | } else if(!strcmp(element_name, "component")) { |
| 1438 | if(!blist_parser_chat_components) | |
| 1439 | blist_parser_chat_components = g_hash_table_new_full(g_str_hash, | |
| 1440 | g_str_equal, g_free, g_free); | |
| 1441 | if(blist_parser_component_name && blist_parser_component_value) { | |
| 1442 | g_hash_table_replace(blist_parser_chat_components, | |
| 1443 | g_strdup(blist_parser_component_name), | |
| 1444 | g_strdup(blist_parser_component_value)); | |
| 1445 | } | |
| 1446 | g_free(blist_parser_component_name); | |
| 1447 | g_free(blist_parser_component_value); | |
| 1448 | blist_parser_component_name = NULL; | |
| 1449 | blist_parser_component_value = NULL; | |
| 1450 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 5228 | 1451 | } else if(!strcmp(element_name, "setting")) { |
| 1452 | if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_BUDDY) { | |
| 1453 | if(!blist_parser_buddy_settings) | |
| 1454 | blist_parser_buddy_settings = g_hash_table_new_full(g_str_hash, | |
| 1455 | g_str_equal, g_free, g_free); | |
| 1456 | if(blist_parser_setting_name && blist_parser_setting_value) { | |
| 1457 | g_hash_table_replace(blist_parser_buddy_settings, | |
| 1458 | g_strdup(blist_parser_setting_name), | |
| 1459 | g_strdup(blist_parser_setting_value)); | |
| 1460 | } | |
| 1461 | } else if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_GROUP) { | |
| 1462 | if(!blist_parser_group_settings) | |
| 1463 | blist_parser_group_settings = g_hash_table_new_full(g_str_hash, | |
| 1464 | g_str_equal, g_free, g_free); | |
| 1465 | if(blist_parser_setting_name && blist_parser_setting_value) { | |
| 1466 | g_hash_table_replace(blist_parser_group_settings, | |
| 1467 | g_strdup(blist_parser_setting_name), | |
| 1468 | g_strdup(blist_parser_setting_value)); | |
| 1469 | } | |
| 1470 | } | |
| 1471 | g_free(blist_parser_setting_name); | |
| 1472 | g_free(blist_parser_setting_value); | |
| 1473 | blist_parser_setting_name = NULL; | |
| 1474 | blist_parser_setting_value = NULL; | |
| 1475 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1476 | } else if(!strcmp(element_name, "privacy")) { | |
| 1477 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1478 | } else if(!strcmp(element_name, "account")) { | |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1479 | GaimAccount *account = gaim_account_find(blist_parser_account_name, |
| 5228 | 1480 | blist_parser_account_protocol); |
| 1481 | if(account) { | |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1482 | account->perm_deny = blist_parser_privacy_mode; |
| 5228 | 1483 | } |
| 1484 | g_free(blist_parser_account_name); | |
| 1485 | blist_parser_account_name = NULL; | |
| 1486 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1487 | } else if(!strcmp(element_name, "permit")) { | |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1488 | GaimAccount *account = gaim_account_find(blist_parser_account_name, |
| 5228 | 1489 | blist_parser_account_protocol); |
| 1490 | if(account) { | |
| 1491 | gaim_privacy_permit_add(account, blist_parser_buddy_name); | |
| 1492 | } | |
| 1493 | g_free(blist_parser_buddy_name); | |
| 1494 | blist_parser_buddy_name = NULL; | |
| 1495 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1496 | } else if(!strcmp(element_name, "block")) { | |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1497 | GaimAccount *account = gaim_account_find(blist_parser_account_name, |
| 5228 | 1498 | blist_parser_account_protocol); |
| 1499 | if(account) { | |
| 1500 | gaim_privacy_deny_add(account, blist_parser_buddy_name); | |
| 1501 | } | |
| 1502 | g_free(blist_parser_buddy_name); | |
| 1503 | blist_parser_buddy_name = NULL; | |
| 1504 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1505 | } else if(!strcmp(element_name, "ignore")) { | |
| 1506 | /* we'll apparently do something with this later */ | |
| 1507 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1508 | } | |
| 1509 | } | |
| 1510 | ||
| 1511 | static void blist_text_handler(GMarkupParseContext *context, const gchar *text, | |
| 1512 | gsize text_len, gpointer user_data, GError **error) { | |
| 1513 | switch(GPOINTER_TO_INT(tag_stack->data)) { | |
| 1514 | case BLIST_TAG_NAME: | |
| 1515 | blist_parser_buddy_name = g_strndup(text, text_len); | |
| 1516 | break; | |
| 1517 | case BLIST_TAG_ALIAS: | |
| 5234 | 1518 | if(tag_stack->next && |
| 1519 | GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_BUDDY) | |
| 1520 | blist_parser_buddy_alias = g_strndup(text, text_len); | |
| 1521 | else if(tag_stack->next && | |
| 1522 | GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_CHAT) | |
| 1523 | blist_parser_chat_alias = g_strndup(text, text_len); | |
| 5228 | 1524 | break; |
| 1525 | case BLIST_TAG_PERMIT: | |
| 1526 | case BLIST_TAG_BLOCK: | |
| 1527 | case BLIST_TAG_IGNORE: | |
| 1528 | blist_parser_buddy_name = g_strndup(text, text_len); | |
| 1529 | break; | |
| 5234 | 1530 | case BLIST_TAG_COMPONENT: |
| 1531 | blist_parser_component_value = g_strndup(text, text_len); | |
| 1532 | break; | |
| 5228 | 1533 | case BLIST_TAG_SETTING: |
| 1534 | blist_parser_setting_value = g_strndup(text, text_len); | |
| 1535 | break; | |
| 1536 | default: | |
| 1537 | break; | |
| 1538 | } | |
| 1539 | } | |
| 1540 | ||
| 1541 | static void blist_error_handler(GMarkupParseContext *context, GError *error, | |
| 1542 | gpointer user_data) { | |
| 1543 | blist_parser_error_occurred = TRUE; | |
| 1544 | gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
| 1545 | "Error parsing blist.xml: %s\n", error->message); | |
| 1546 | } | |
| 1547 | ||
| 1548 | static GMarkupParser blist_parser = { | |
| 1549 | blist_start_element_handler, | |
| 1550 | blist_end_element_handler, | |
| 1551 | blist_text_handler, | |
| 1552 | NULL, | |
| 1553 | blist_error_handler | |
| 1554 | }; | |
| 1555 | ||
| 1556 | static gboolean gaim_blist_read(const char *filename) { | |
| 1557 | gchar *contents = NULL; | |
| 1558 | gsize length; | |
| 1559 | GMarkupParseContext *context; | |
| 1560 | GError *error = NULL; | |
| 1561 | ||
| 1562 | gaim_debug(GAIM_DEBUG_INFO, "blist import", | |
| 1563 | "Reading %s\n", filename); | |
| 1564 | if(!g_file_get_contents(filename, &contents, &length, &error)) { | |
| 1565 | gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
| 1566 | "Error reading blist: %s\n", error->message); | |
| 1567 | g_error_free(error); | |
| 1568 | return FALSE; | |
| 1569 | } | |
| 1570 | ||
| 1571 | context = g_markup_parse_context_new(&blist_parser, 0, NULL, NULL); | |
| 1572 | ||
| 1573 | if(!g_markup_parse_context_parse(context, contents, length, NULL)) { | |
| 1574 | g_markup_parse_context_free(context); | |
| 1575 | g_free(contents); | |
| 1576 | return FALSE; | |
| 1577 | } | |
| 1578 | ||
| 1579 | if(!g_markup_parse_context_end_parse(context, NULL)) { | |
| 1580 | gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
| 1581 | "Error parsing %s\n", filename); | |
| 1582 | g_markup_parse_context_free(context); | |
| 1583 | g_free(contents); | |
| 1584 | return FALSE; | |
| 1585 | } | |
| 1586 | ||
| 1587 | g_markup_parse_context_free(context); | |
| 1588 | g_free(contents); | |
| 1589 | ||
| 1590 | if(blist_parser_error_occurred) | |
| 1591 | return FALSE; | |
| 1592 | ||
| 1593 | gaim_debug(GAIM_DEBUG_INFO, "blist import", "Finished reading %s\n", | |
| 1594 | filename); | |
| 1595 | ||
| 1596 | return TRUE; | |
| 1597 | } | |
| 1598 | ||
| 1599 | void gaim_blist_load() { | |
|
5580
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1600 | GList *accts; |
| 5228 | 1601 | char *user_dir = gaim_user_dir(); |
| 1602 | char *filename; | |
| 1603 | char *msg; | |
| 1604 | ||
| 1605 | blist_safe_to_write = TRUE; | |
| 1606 | ||
| 1607 | if(!user_dir) | |
| 1608 | return; | |
| 1609 | ||
| 1610 | filename = g_build_filename(user_dir, "blist.xml", NULL); | |
| 1611 | ||
| 1612 | if(g_file_test(filename, G_FILE_TEST_EXISTS)) { | |
| 1613 | if(!gaim_blist_read(filename)) { | |
| 1614 | msg = g_strdup_printf(_("An error was encountered parsing your " | |
| 1615 | "buddy list. It has not been loaded.")); | |
|
5436
a0e0bacaa196
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
1616 | gaim_notify_error(NULL, NULL, _("Buddy List Error"), msg); |
| 5228 | 1617 | g_free(msg); |
| 1618 | } | |
|
5580
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1619 | } else if(g_list_length(gaim_accounts_get_all())) { |
| 5228 | 1620 | /* rob wants to inform the user that their buddy lists are |
| 1621 | * being converted */ | |
| 1622 | msg = g_strdup_printf(_("Gaim is converting your old buddy lists " | |
| 1623 | "to a new format, which will now be located at %s"), | |
| 1624 | filename); | |
|
5436
a0e0bacaa196
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
1625 | gaim_notify_info(NULL, NULL, _("Converting Buddy List"), msg); |
| 5228 | 1626 | g_free(msg); |
| 1627 | ||
| 1628 | /* now, let gtk actually display the dialog before we start anything */ | |
| 1629 | while(gtk_events_pending()) | |
| 1630 | gtk_main_iteration(); | |
| 1631 | ||
| 1632 | /* read in the old lists, then save to the new format */ | |
|
5580
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1633 | for(accts = gaim_accounts_get_all(); accts; accts = accts->next) { |
| 5228 | 1634 | do_import(accts->data, NULL); |
| 1635 | } | |
| 1636 | gaim_blist_save(); | |
| 1637 | } | |
| 1638 | ||
| 1639 | g_free(filename); | |
| 1640 | } | |
| 1641 | ||
| 1642 | static void blist_print_group_settings(gpointer key, gpointer data, | |
| 1643 | gpointer user_data) { | |
| 1644 | char *key_val; | |
| 1645 | char *data_val; | |
| 1646 | FILE *file = user_data; | |
| 1647 | ||
| 1648 | if(!key || !data) | |
| 1649 | return; | |
| 1650 | ||
| 1651 | key_val = g_markup_escape_text(key, -1); | |
| 1652 | data_val = g_markup_escape_text(data, -1); | |
| 1653 | ||
| 1654 | fprintf(file, "\t\t\t<setting name=\"%s\">%s</setting>\n", key_val, | |
| 1655 | data_val); | |
| 1656 | g_free(key_val); | |
| 1657 | g_free(data_val); | |
| 1658 | } | |
| 1659 | ||
| 1660 | static void blist_print_buddy_settings(gpointer key, gpointer data, | |
| 1661 | gpointer user_data) { | |
| 1662 | char *key_val; | |
| 1663 | char *data_val; | |
| 1664 | FILE *file = user_data; | |
| 1665 | ||
| 1666 | if(!key || !data) | |
| 1667 | return; | |
| 1668 | ||
| 1669 | key_val = g_markup_escape_text(key, -1); | |
| 1670 | data_val = g_markup_escape_text(data, -1); | |
| 1671 | ||
| 1672 | fprintf(file, "\t\t\t\t\t<setting name=\"%s\">%s</setting>\n", key_val, | |
| 1673 | data_val); | |
| 1674 | g_free(key_val); | |
| 1675 | g_free(data_val); | |
| 1676 | } | |
| 1677 | ||
| 5234 | 1678 | static void blist_print_chat_components(gpointer key, gpointer data, |
| 1679 | gpointer user_data) { | |
| 1680 | char *key_val; | |
| 1681 | char *data_val; | |
| 1682 | FILE *file = user_data; | |
| 1683 | ||
| 1684 | if(!key || !data) | |
| 1685 | return; | |
| 1686 | ||
| 1687 | key_val = g_markup_escape_text(key, -1); | |
| 1688 | data_val = g_markup_escape_text(data, -1); | |
| 1689 | ||
| 1690 | fprintf(file, "\t\t\t\t<component name=\"%s\">%s</component>\n", key_val, | |
| 1691 | data_val); | |
| 1692 | g_free(key_val); | |
| 1693 | g_free(data_val); | |
| 1694 | } | |
| 1695 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1696 | static void gaim_blist_write(FILE *file, GaimAccount *exp_acct) { |
|
5580
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1697 | GList *accounts; |
|
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1698 | GSList *buds; |
| 5228 | 1699 | GaimBlistNode *gnode,*bnode; |
| 1700 | struct group *group; | |
| 1701 | struct buddy *bud; | |
| 1702 | fprintf(file, "<?xml version='1.0' encoding='UTF-8' ?>\n"); | |
| 1703 | fprintf(file, "<gaim version=\"1\">\n"); | |
| 1704 | fprintf(file, "\t<blist>\n"); | |
| 1705 | ||
| 1706 | for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { | |
| 1707 | if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
| 1708 | continue; | |
| 1709 | group = (struct group *)gnode; | |
| 1710 | if(!exp_acct || gaim_group_on_account(group, exp_acct)) { | |
| 1711 | char *group_name = g_markup_escape_text(group->name, -1); | |
| 1712 | fprintf(file, "\t\t<group name=\"%s\">\n", group_name); | |
| 1713 | g_hash_table_foreach(group->settings, blist_print_group_settings, file); | |
| 1714 | for(bnode = gnode->child; bnode; bnode = bnode->next) { | |
| 5234 | 1715 | if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { |
| 1716 | bud = (struct buddy *)bnode; | |
| 1717 | if(!exp_acct || bud->account == exp_acct) { | |
| 1718 | char *bud_name = g_markup_escape_text(bud->name, -1); | |
| 1719 | char *bud_alias = NULL; | |
| 1720 | char *acct_name = g_markup_escape_text(bud->account->username, -1); | |
| 1721 | if(bud->alias) | |
| 1722 | bud_alias= g_markup_escape_text(bud->alias, -1); | |
| 1723 | fprintf(file, "\t\t\t<person name=\"%s\">\n", | |
| 1724 | bud_alias ? bud_alias : bud_name); | |
| 1725 | fprintf(file, "\t\t\t\t<buddy protocol=\"%d\" " | |
| 1726 | "account=\"%s\">\n", bud->account->protocol, | |
| 1727 | acct_name); | |
| 1728 | fprintf(file, "\t\t\t\t\t<name>%s</name>\n", bud_name); | |
| 1729 | if(bud_alias) { | |
| 1730 | fprintf(file, "\t\t\t\t\t<alias>%s</alias>\n", | |
| 1731 | bud_alias); | |
| 1732 | } | |
| 1733 | g_hash_table_foreach(bud->settings, | |
| 1734 | blist_print_buddy_settings, file); | |
| 1735 | fprintf(file, "\t\t\t\t</buddy>\n"); | |
| 1736 | fprintf(file, "\t\t\t</person>\n"); | |
| 1737 | g_free(bud_name); | |
| 1738 | g_free(bud_alias); | |
| 1739 | g_free(acct_name); | |
| 5228 | 1740 | } |
| 5234 | 1741 | } else if(GAIM_BLIST_NODE_IS_CHAT(bnode)) { |
| 1742 | struct chat *chat = (struct chat *)bnode; | |
| 1743 | if(!exp_acct || chat->account == exp_acct) { | |
| 1744 | char *acct_name = g_markup_escape_text(chat->account->username, -1); | |
| 1745 | fprintf(file, "\t\t\t<chat protocol=\"%d\" account=\"%s\">\n", chat->account->protocol, acct_name); | |
| 5237 | 1746 | if(chat->alias) { |
| 1747 | char *chat_alias = g_markup_escape_text(chat->alias, -1); | |
| 1748 | fprintf(file, "\t\t\t\t<alias>%s</alias>\n", chat_alias); | |
| 1749 | g_free(chat_alias); | |
| 1750 | } | |
| 5234 | 1751 | g_hash_table_foreach(chat->components, |
| 1752 | blist_print_chat_components, file); | |
| 1753 | fprintf(file, "\t\t\t</chat>\n"); | |
| 5237 | 1754 | g_free(acct_name); |
| 5234 | 1755 | } |
| 5228 | 1756 | } |
| 1757 | } | |
| 1758 | fprintf(file, "\t\t</group>\n"); | |
| 1759 | g_free(group_name); | |
| 1760 | } | |
| 1761 | } | |
| 1762 | ||
| 1763 | fprintf(file, "\t</blist>\n"); | |
| 1764 | fprintf(file, "\t<privacy>\n"); | |
| 1765 | ||
|
5580
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1766 | for(accounts = gaim_accounts_get_all(); |
|
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1767 | accounts != NULL; |
|
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1768 | accounts = accounts->next) { |
|
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1769 | |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1770 | GaimAccount *account = accounts->data; |
| 5228 | 1771 | char *acct_name = g_markup_escape_text(account->username, -1); |
| 1772 | if(!exp_acct || account == exp_acct) { | |
| 1773 | fprintf(file, "\t\t<account protocol=\"%d\" name=\"%s\" " | |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1774 | "mode=\"%d\">\n", account->protocol, acct_name, account->perm_deny); |
| 5228 | 1775 | for(buds = account->permit; buds; buds = buds->next) { |
| 1776 | char *bud_name = g_markup_escape_text(buds->data, -1); | |
| 1777 | fprintf(file, "\t\t\t<permit>%s</permit>\n", bud_name); | |
| 1778 | g_free(bud_name); | |
| 1779 | } | |
| 1780 | for(buds = account->deny; buds; buds = buds->next) { | |
| 1781 | char *bud_name = g_markup_escape_text(buds->data, -1); | |
| 1782 | fprintf(file, "\t\t\t<block>%s</block>\n", bud_name); | |
| 1783 | g_free(bud_name); | |
| 1784 | } | |
| 1785 | fprintf(file, "\t\t</account>\n"); | |
| 1786 | } | |
| 1787 | g_free(acct_name); | |
| 1788 | } | |
| 1789 | ||
| 1790 | fprintf(file, "\t</privacy>\n"); | |
| 1791 | fprintf(file, "</gaim>\n"); | |
| 1792 | } | |
| 1793 | ||
| 1794 | void gaim_blist_save() { | |
| 1795 | FILE *file; | |
| 1796 | char *user_dir = gaim_user_dir(); | |
| 1797 | char *filename; | |
| 1798 | char *filename_real; | |
| 1799 | ||
| 1800 | if(!user_dir) | |
| 1801 | return; | |
| 1802 | if(!blist_safe_to_write) { | |
| 1803 | gaim_debug(GAIM_DEBUG_WARNING, "blist save", | |
| 1804 | "AHH!! Tried to write the blist before we read it!\n"); | |
| 1805 | return; | |
| 1806 | } | |
| 1807 | ||
| 1808 | file = fopen(user_dir, "r"); | |
| 1809 | if(!file) | |
| 1810 | mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 1811 | else | |
| 1812 | fclose(file); | |
| 1813 | ||
| 1814 | filename = g_build_filename(user_dir, "blist.xml.save", NULL); | |
| 1815 | ||
| 1816 | if((file = fopen(filename, "w"))) { | |
| 1817 | gaim_blist_write(file, NULL); | |
| 1818 | fclose(file); | |
| 1819 | chmod(filename, S_IRUSR | S_IWUSR); | |
| 1820 | } else { | |
| 1821 | gaim_debug(GAIM_DEBUG_ERROR, "blist save", "Unable to write %s\n", | |
| 1822 | filename); | |
| 1823 | } | |
| 1824 | ||
| 1825 | filename_real = g_build_filename(user_dir, "blist.xml", NULL); | |
| 1826 | ||
| 1827 | if(rename(filename, filename_real) < 0) | |
| 1828 | gaim_debug(GAIM_DEBUG_ERROR, "blist save", | |
| 1829 | "Error renaming %s to %s\n", filename, filename_real); | |
| 1830 | ||
| 1831 | ||
| 1832 | g_free(filename); | |
| 1833 | g_free(filename_real); | |
| 1834 | } | |
| 1835 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1836 | gboolean gaim_privacy_permit_add(GaimAccount *account, const char *who) { |
| 5228 | 1837 | GSList *d = account->permit; |
| 1838 | char *n = g_strdup(normalize(who)); | |
| 1839 | while(d) { | |
| 1840 | if(!gaim_utf8_strcasecmp(n, normalize(d->data))) | |
| 1841 | break; | |
| 1842 | d = d->next; | |
| 1843 | } | |
| 1844 | g_free(n); | |
| 1845 | if(!d) { | |
| 1846 | account->permit = g_slist_append(account->permit, g_strdup(who)); | |
| 1847 | return TRUE; | |
| 1848 | } | |
| 1849 | ||
| 1850 | return FALSE; | |
| 1851 | } | |
| 1852 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1853 | gboolean gaim_privacy_permit_remove(GaimAccount *account, const char *who) { |
| 5228 | 1854 | GSList *d = account->permit; |
| 1855 | char *n = g_strdup(normalize(who)); | |
| 1856 | while(d) { | |
| 1857 | if(!gaim_utf8_strcasecmp(n, normalize(d->data))) | |
| 1858 | break; | |
| 1859 | d = d->next; | |
| 1860 | } | |
| 1861 | g_free(n); | |
| 1862 | if(d) { | |
| 1863 | account->permit = g_slist_remove(account->permit, d->data); | |
| 1864 | g_free(d->data); | |
| 1865 | return TRUE; | |
| 1866 | } | |
| 1867 | return FALSE; | |
| 1868 | } | |
| 1869 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1870 | gboolean gaim_privacy_deny_add(GaimAccount *account, const char *who) { |
| 5228 | 1871 | GSList *d = account->deny; |
| 1872 | char *n = g_strdup(normalize(who)); | |
| 1873 | while(d) { | |
| 1874 | if(!gaim_utf8_strcasecmp(n, normalize(d->data))) | |
| 1875 | break; | |
| 1876 | d = d->next; | |
| 1877 | } | |
| 1878 | g_free(n); | |
| 1879 | if(!d) { | |
| 1880 | account->deny = g_slist_append(account->deny, g_strdup(who)); | |
| 1881 | return TRUE; | |
| 1882 | } | |
| 1883 | ||
| 1884 | return FALSE; | |
| 1885 | } | |
| 1886 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1887 | gboolean gaim_privacy_deny_remove(GaimAccount *account, const char *who) { |
| 5228 | 1888 | GSList *d = account->deny; |
| 1889 | char *n = g_strdup(normalize(who)); | |
| 1890 | while(d) { | |
| 1891 | if(!gaim_utf8_strcasecmp(n, normalize(d->data))) | |
| 1892 | break; | |
| 1893 | d = d->next; | |
| 1894 | } | |
| 1895 | g_free(n); | |
| 1896 | if(d) { | |
| 1897 | account->deny = g_slist_remove(account->deny, d->data); | |
| 1898 | g_free(d->data); | |
| 1899 | return TRUE; | |
| 1900 | } | |
| 1901 | return FALSE; | |
| 1902 | } | |
| 1903 | ||
| 1904 | void gaim_group_set_setting(struct group *g, const char *key, | |
| 1905 | const char *value) { | |
| 1906 | if(!g) | |
| 1907 | return; | |
| 1908 | g_hash_table_replace(g->settings, g_strdup(key), g_strdup(value)); | |
| 1909 | } | |
| 1910 | ||
| 1911 | char *gaim_group_get_setting(struct group *g, const char *key) { | |
| 1912 | if(!g) | |
| 1913 | return NULL; | |
| 1914 | return g_strdup(g_hash_table_lookup(g->settings, key)); | |
| 1915 | } | |
| 1916 | ||
| 1917 | void gaim_buddy_set_setting(struct buddy *b, const char *key, | |
| 1918 | const char *value) { | |
| 1919 | if(!b) | |
| 1920 | return; | |
| 1921 | g_hash_table_replace(b->settings, g_strdup(key), g_strdup(value)); | |
| 1922 | } | |
| 1923 | ||
| 1924 | char *gaim_buddy_get_setting(struct buddy *b, const char *key) { | |
| 1925 | if(!b) | |
| 1926 | return NULL; | |
| 1927 | return g_strdup(g_hash_table_lookup(b->settings, key)); | |
| 1928 | } | |
| 1929 | ||
| 1930 | void gaim_set_blist_ui_ops(struct gaim_blist_ui_ops *ops) | |
| 1931 | { | |
| 1932 | blist_ui_ops = ops; | |
| 1933 | } | |
| 1934 | ||
| 1935 | struct gaim_blist_ui_ops * | |
| 1936 | gaim_get_blist_ui_ops(void) | |
| 1937 | { | |
| 1938 | return blist_ui_ops; | |
| 1939 | } | |
| 1940 | ||
| 1941 | int gaim_blist_get_group_size(struct group *group, gboolean offline) { | |
| 1942 | if(!group) | |
| 1943 | return 0; | |
| 1944 | ||
| 5277 | 1945 | return offline ? group->totalsize : group->currentsize; |
| 5228 | 1946 | } |
| 1947 | ||
| 1948 | int gaim_blist_get_group_online_count(struct group *group) { | |
| 1949 | if(!group) | |
| 1950 | return 0; | |
| 1951 | ||
| 5277 | 1952 | return group->online; |
| 5228 | 1953 | } |
| 1954 | ||
| 1955 |