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