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