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