Mercurial > pidgin
annotate src/blist.c @ 6322:dd2be7cd66df
[gaim-migrate @ 6821]
This is:
-Alphabetize the translation things in ChangeLog
-Spell Brian Tarricone's name correctly (I hope...)
-A fix for a crash when renaming a group containing a chat, thanks to
javabsp. Me gusta this change.
-Make the rename group dialog use gaim_request_input(). The old dialog
may be a bit prettier, but this one uses the request code, which means
less work for UIs, which rocks.
-Change the TRUE and FALSE defines in aim.h to be more compatible with c++.
Thanks to Zack Rusin for this change.
-Declare aim.h as a C file when it is used in a c++ program. This should
let libfaim be used in C++ programs such as kopete. Thanks again to
Zack Rusin.
-Rename aimutil_itemidx() to aimutil_itemindex(). "idx" is not a standard
abbreviation, and code is written once and read many times--it should be
easily readable.
-Not an automatic laundry folding machine. So I'm going to do that.
(Fold my laundry)
(Not automatically)
(yet)
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Tue, 29 Jul 2003 04:27:31 +0000 |
| parents | a21cf07cd8e1 |
| children | aeb8c2119a58 |
| 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) { | |
| 6322 | 878 GaimAccount *account = NULL; |
| 879 if (GAIM_BLIST_NODE_IS_BUDDY(child)) | |
| 880 account = ((struct buddy *)child)->account; | |
| 881 else if (GAIM_BLIST_NODE_IS_CHAT(child)) | |
| 882 account = ((struct chat *)child)->account; | |
| 883 if (!g_slist_find(l, account)) | |
| 884 l = g_slist_append(l, account); | |
| 5228 | 885 child = child->next; |
| 886 } | |
| 887 return l; | |
| 888 } | |
| 889 | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
890 void gaim_blist_add_account(GaimAccount *account) |
| 5234 | 891 { |
| 892 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 893 GaimBlistNode *group, *buddy; | |
| 894 | |
| 895 if(!gaimbuddylist) | |
| 896 return; | |
| 897 | |
| 898 for(group = gaimbuddylist->root; group; group = group->next) { | |
| 899 if(!GAIM_BLIST_NODE_IS_GROUP(group)) | |
| 900 continue; | |
| 901 for(buddy = group->child; buddy; buddy = buddy->next) { | |
| 902 if(GAIM_BLIST_NODE_IS_BUDDY(buddy)) { | |
| 903 if (account == ((struct buddy*)buddy)->account) { | |
| 5277 | 904 ((struct group *)group)->currentsize++; |
| 5234 | 905 if(ops) |
| 906 ops->update(gaimbuddylist, buddy); | |
| 907 } | |
| 908 } else if(GAIM_BLIST_NODE_IS_CHAT(buddy)) { | |
| 909 if (account == ((struct chat*)buddy)->account) { | |
| 5287 | 910 ((struct group *)group)->online++; |
| 5277 | 911 ((struct group *)group)->currentsize++; |
| 5234 | 912 if(ops) |
| 913 ops->update(gaimbuddylist, buddy); | |
| 914 } | |
| 915 } | |
| 916 } | |
| 917 } | |
| 918 } | |
| 919 | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
920 void gaim_blist_remove_account(GaimAccount *account) |
| 5228 | 921 { |
| 922 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 5234 | 923 GaimBlistNode *group, *buddy; |
| 924 | |
| 5228 | 925 if (!gaimbuddylist) |
| 926 return; | |
| 5234 | 927 |
| 928 for(group = gaimbuddylist->root; group; group = group->next) { | |
| 929 if(!GAIM_BLIST_NODE_IS_GROUP(group)) | |
| 930 continue; | |
| 931 for(buddy = group->child; buddy; buddy = buddy->next) { | |
| 932 if(GAIM_BLIST_NODE_IS_BUDDY(buddy)) { | |
| 933 if (account == ((struct buddy*)buddy)->account) { | |
| 5394 | 934 if (GAIM_BUDDY_IS_ONLINE((struct buddy*)buddy)) |
| 5277 | 935 ((struct group *)group)->online--; |
| 5234 | 936 ((struct buddy*)buddy)->present = GAIM_BUDDY_OFFLINE; |
| 5394 | 937 ((struct group *)group)->currentsize--; |
| 5234 | 938 if(ops) |
| 939 ops->remove(gaimbuddylist, buddy); | |
| 940 } | |
| 941 } else if(GAIM_BLIST_NODE_IS_CHAT(buddy)) { | |
| 942 if (account == ((struct chat*)buddy)->account) { | |
| 5277 | 943 ((struct group *)group)->online--; |
| 944 ((struct group *)group)->currentsize--; | |
| 5234 | 945 if(ops) |
| 946 ops->remove(gaimbuddylist, buddy); | |
| 947 } | |
| 5228 | 948 } |
| 949 } | |
| 950 } | |
| 951 } | |
| 952 | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
953 void parse_toc_buddy_list(GaimAccount *account, char *config) |
| 5228 | 954 { |
| 955 char *c; | |
| 956 char current[256]; | |
| 957 GList *bud = NULL; | |
| 958 | |
| 959 | |
| 960 if (config != NULL) { | |
| 961 | |
| 962 /* skip "CONFIG:" (if it exists) */ | |
| 963 c = strncmp(config + 6 /* sizeof(struct sflap_hdr) */ , "CONFIG:", strlen("CONFIG:")) ? | |
| 964 strtok(config, "\n") : | |
| 965 strtok(config + 6 /* sizeof(struct sflap_hdr) */ + strlen("CONFIG:"), "\n"); | |
| 966 do { | |
| 967 if (c == NULL) | |
| 968 break; | |
| 969 if (*c == 'g') { | |
| 970 char *utf8 = NULL; | |
| 971 utf8 = gaim_try_conv_to_utf8(c + 2); | |
| 972 if (utf8 == NULL) { | |
| 973 g_strlcpy(current, _("Invalid Groupname"), sizeof(current)); | |
| 974 } else { | |
| 975 g_strlcpy(current, utf8, sizeof(current)); | |
| 976 g_free(utf8); | |
| 977 } | |
| 978 if (!gaim_find_group(current)) { | |
| 979 struct group *g = gaim_group_new(current); | |
| 5634 | 980 gaim_blist_add_group(g, |
| 981 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
| 5228 | 982 } |
| 983 } else if (*c == 'b') { /*&& !gaim_find_buddy(user, c + 2)) {*/ | |
| 984 char nm[80], sw[388], *a, *utf8 = NULL; | |
| 985 | |
| 986 if ((a = strchr(c + 2, ':')) != NULL) { | |
| 987 *a++ = '\0'; /* nul the : */ | |
| 988 } | |
| 989 | |
| 990 g_strlcpy(nm, c + 2, sizeof(nm)); | |
| 991 if (a) { | |
| 992 utf8 = gaim_try_conv_to_utf8(a); | |
| 993 if (utf8 == NULL) { | |
| 994 gaim_debug(GAIM_DEBUG_ERROR, "toc blist", | |
| 995 "Failed to convert alias for " | |
| 996 "'%s' to UTF-8\n", nm); | |
| 997 } | |
| 998 } | |
| 999 if (utf8 == NULL) { | |
| 1000 sw[0] = '\0'; | |
| 1001 } else { | |
| 1002 /* This can leave a partial sequence at the end, | |
| 1003 * but who cares? */ | |
| 1004 g_strlcpy(sw, utf8, sizeof(sw)); | |
| 1005 g_free(utf8); | |
| 1006 } | |
| 1007 | |
| 1008 if (!gaim_find_buddy(account, nm)) { | |
| 1009 struct buddy *b = gaim_buddy_new(account, nm, sw); | |
| 1010 struct group *g = gaim_find_group(current); | |
| 5634 | 1011 gaim_blist_add_buddy(b, g, |
| 1012 gaim_blist_get_last_child((GaimBlistNode*)g)); | |
| 5228 | 1013 bud = g_list_append(bud, g_strdup(nm)); |
| 1014 } | |
| 1015 } else if (*c == 'p') { | |
| 1016 gaim_privacy_permit_add(account, c + 2); | |
| 1017 } else if (*c == 'd') { | |
| 1018 gaim_privacy_deny_add(account, c + 2); | |
| 1019 } else if (!strncmp("toc", c, 3)) { | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1020 sscanf(c + strlen(c) - 1, "%d", &account->perm_deny); |
| 5228 | 1021 gaim_debug(GAIM_DEBUG_MISC, "toc blist", |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1022 "permdeny: %d\n", account->perm_deny); |
|
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1023 if (account->perm_deny == 0) |
|
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1024 account->perm_deny = 1; |
| 5228 | 1025 } else if (*c == 'm') { |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1026 sscanf(c + 2, "%d", &account->perm_deny); |
| 5228 | 1027 gaim_debug(GAIM_DEBUG_MISC, "toc blist", |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1028 "permdeny: %d\n", account->perm_deny); |
|
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1029 if (account->perm_deny == 0) |
|
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1030 account->perm_deny = 1; |
| 5228 | 1031 } |
| 1032 } while ((c = strtok(NULL, "\n"))); | |
| 1033 | |
| 1034 if(account->gc) { | |
| 1035 if(bud) { | |
| 1036 GList *node = bud; | |
| 1037 serv_add_buddies(account->gc, bud); | |
| 1038 while(node) { | |
| 1039 g_free(node->data); | |
| 1040 node = node->next; | |
| 1041 } | |
| 1042 } | |
| 1043 serv_set_permit_deny(account->gc); | |
| 1044 } | |
| 1045 g_list_free(bud); | |
| 1046 } | |
| 1047 } | |
| 1048 | |
| 1049 #if 0 | |
| 1050 /* translate an AIM 3 buddylist (*.lst) to a Gaim buddylist */ | |
| 1051 static GString *translate_lst(FILE *src_fp) | |
| 1052 { | |
| 1053 char line[BUF_LEN], *line2; | |
| 1054 char *name; | |
| 1055 int i; | |
| 1056 | |
| 1057 GString *dest = g_string_new("m 1\n"); | |
| 1058 | |
| 1059 while (fgets(line, BUF_LEN, src_fp)) { | |
| 1060 line2 = g_strchug(line); | |
| 1061 if (strstr(line2, "group") == line2) { | |
| 1062 name = strpbrk(line2, " \t\n\r\f") + 1; | |
| 1063 dest = g_string_append(dest, "g "); | |
| 1064 for (i = 0; i < strcspn(name, "\n\r"); i++) | |
| 1065 if (name[i] != '\"') | |
| 1066 dest = g_string_append_c(dest, name[i]); | |
| 1067 dest = g_string_append_c(dest, '\n'); | |
| 1068 } | |
| 1069 if (strstr(line2, "buddy") == line2) { | |
| 1070 name = strpbrk(line2, " \t\n\r\f") + 1; | |
| 1071 dest = g_string_append(dest, "b "); | |
| 1072 for (i = 0; i < strcspn(name, "\n\r"); i++) | |
| 1073 if (name[i] != '\"') | |
| 1074 dest = g_string_append_c(dest, name[i]); | |
| 1075 dest = g_string_append_c(dest, '\n'); | |
| 1076 } | |
| 1077 } | |
| 1078 | |
| 1079 return dest; | |
| 1080 } | |
| 1081 | |
| 1082 | |
| 1083 /* translate an AIM 4 buddylist (*.blt) to Gaim format */ | |
| 1084 static GString *translate_blt(FILE *src_fp) | |
| 1085 { | |
| 1086 int i; | |
| 1087 char line[BUF_LEN]; | |
| 1088 char *buddy; | |
| 1089 | |
| 1090 GString *dest = g_string_new("m 1\n"); | |
| 1091 | |
| 1092 while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL); | |
| 1093 while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL); | |
| 1094 | |
| 1095 while (1) { | |
| 1096 fgets(line, BUF_LEN, src_fp); g_strchomp(line); | |
| 1097 if (strchr(line, '}') != NULL) | |
| 1098 break; | |
| 1099 | |
| 1100 if (strchr(line, '{') != NULL) { | |
| 1101 /* Syntax starting with "<group> {" */ | |
| 1102 | |
| 1103 dest = g_string_append(dest, "g "); | |
| 1104 buddy = g_strchug(strtok(line, "{")); | |
| 1105 for (i = 0; i < strlen(buddy); i++) | |
| 1106 if (buddy[i] != '\"') | |
| 1107 dest = g_string_append_c(dest, buddy[i]); | |
| 1108 dest = g_string_append_c(dest, '\n'); | |
| 1109 while (strchr(fgets(line, BUF_LEN, src_fp), '}') == NULL) { | |
| 1110 gboolean pounce = FALSE; | |
| 1111 char *e; | |
| 1112 g_strchomp(line); | |
| 1113 buddy = g_strchug(line); | |
| 1114 gaim_debug(GAIM_DEBUG_MISC, "AIM 4 blt import", | |
| 1115 "buddy: \"%s\"\n", buddy); | |
| 1116 dest = g_string_append(dest, "b "); | |
| 1117 if (strchr(buddy, '{') != NULL) { | |
| 1118 /* buddy pounce, etc */ | |
| 1119 char *pos = strchr(buddy, '{') - 1; | |
| 1120 *pos = 0; | |
| 1121 pounce = TRUE; | |
| 1122 } | |
| 1123 if ((e = strchr(buddy, '\"')) != NULL) { | |
| 1124 *e = '\0'; | |
| 1125 buddy++; | |
| 1126 } | |
| 1127 dest = g_string_append(dest, buddy); | |
| 1128 dest = g_string_append_c(dest, '\n'); | |
| 1129 if (pounce) | |
| 1130 do | |
| 1131 fgets(line, BUF_LEN, src_fp); | |
| 1132 while (!strchr(line, '}')); | |
| 1133 } | |
| 1134 } else { | |
| 1135 | |
| 1136 /* Syntax "group buddy buddy ..." */ | |
| 1137 buddy = g_strchug(strtok(line, " \n")); | |
| 1138 dest = g_string_append(dest, "g "); | |
| 1139 if (strchr(buddy, '\"') != NULL) { | |
| 1140 dest = g_string_append(dest, &buddy[1]); | |
| 1141 dest = g_string_append_c(dest, ' '); | |
| 1142 buddy = g_strchug(strtok(NULL, " \n")); | |
| 1143 while (strchr(buddy, '\"') == NULL) { | |
| 1144 dest = g_string_append(dest, buddy); | |
| 1145 dest = g_string_append_c(dest, ' '); | |
| 1146 buddy = g_strchug(strtok(NULL, " \n")); | |
| 1147 } | |
| 1148 buddy[strlen(buddy) - 1] = '\0'; | |
| 1149 dest = g_string_append(dest, buddy); | |
| 1150 } else { | |
| 1151 dest = g_string_append(dest, buddy); | |
| 1152 } | |
| 1153 dest = g_string_append_c(dest, '\n'); | |
| 1154 while ((buddy = g_strchug(strtok(NULL, " \n"))) != NULL) { | |
| 1155 dest = g_string_append(dest, "b "); | |
| 1156 if (strchr(buddy, '\"') != NULL) { | |
| 1157 dest = g_string_append(dest, &buddy[1]); | |
| 1158 dest = g_string_append_c(dest, ' '); | |
| 1159 buddy = g_strchug(strtok(NULL, " \n")); | |
| 1160 while (strchr(buddy, '\"') == NULL) { | |
| 1161 dest = g_string_append(dest, buddy); | |
| 1162 dest = g_string_append_c(dest, ' '); | |
| 1163 buddy = g_strchug(strtok(NULL, " \n")); | |
| 1164 } | |
| 1165 buddy[strlen(buddy) - 1] = '\0'; | |
| 1166 dest = g_string_append(dest, buddy); | |
| 1167 } else { | |
| 1168 dest = g_string_append(dest, buddy); | |
| 1169 } | |
| 1170 dest = g_string_append_c(dest, '\n'); | |
| 1171 } | |
| 1172 } | |
| 1173 } | |
| 1174 | |
| 1175 return dest; | |
| 1176 } | |
| 1177 | |
| 1178 static GString *translate_gnomeicu(FILE *src_fp) | |
| 1179 { | |
| 1180 char line[BUF_LEN]; | |
| 1181 GString *dest = g_string_new("m 1\ng Buddies\n"); | |
| 1182 | |
| 1183 while (strstr(fgets(line, BUF_LEN, src_fp), "NewContacts") == NULL); | |
| 1184 | |
| 1185 while (fgets(line, BUF_LEN, src_fp)) { | |
| 1186 char *eq; | |
| 1187 g_strchomp(line); | |
| 1188 if (line[0] == '\n' || line[0] == '[') | |
| 1189 break; | |
| 1190 eq = strchr(line, '='); | |
| 1191 if (!eq) | |
| 1192 break; | |
| 1193 *eq = ':'; | |
| 1194 eq = strchr(eq, ','); | |
| 1195 if (eq) | |
| 1196 *eq = '\0'; | |
| 1197 dest = g_string_append(dest, "b "); | |
| 1198 dest = g_string_append(dest, line); | |
| 1199 dest = g_string_append_c(dest, '\n'); | |
| 1200 } | |
| 1201 | |
| 1202 return dest; | |
| 1203 } | |
| 1204 #endif | |
| 1205 | |
| 1206 static gchar *get_screenname_filename(const char *name) | |
| 1207 { | |
| 1208 gchar **split; | |
| 1209 gchar *good; | |
| 1210 gchar *ret; | |
| 1211 | |
| 1212 split = g_strsplit(name, G_DIR_SEPARATOR_S, -1); | |
| 1213 good = g_strjoinv(NULL, split); | |
| 1214 g_strfreev(split); | |
| 1215 | |
| 1216 ret = g_utf8_strup(good, -1); | |
| 1217 | |
| 1218 g_free(good); | |
| 1219 | |
| 1220 return ret; | |
| 1221 } | |
| 1222 | |
| 1223 static gboolean gaim_blist_read(const char *filename); | |
| 1224 | |
| 1225 | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1226 static void do_import(GaimAccount *account, const char *filename) |
| 5228 | 1227 { |
| 1228 GString *buf = NULL; | |
| 1229 char first[64]; | |
| 1230 char path[PATHSIZE]; | |
| 1231 int len; | |
| 1232 FILE *f; | |
| 1233 struct stat st; | |
| 1234 | |
| 1235 if (filename) { | |
| 1236 g_snprintf(path, sizeof(path), "%s", filename); | |
| 1237 } else { | |
| 1238 char *g_screenname = get_screenname_filename(account->username); | |
|
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1239 const char *username; |
| 5228 | 1240 char *file = gaim_user_dir(); |
|
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1241 GaimProtocol prpl_num; |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1242 int protocol; |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1243 |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1244 prpl_num = gaim_account_get_protocol(account); |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1245 |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1246 protocol = prpl_num; |
|
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 if (prpl_num == GAIM_PROTO_OSCAR) { |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1249 if ((username = gaim_account_get_username(account)) != NULL) { |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1250 protocol = (isalpha(*username) |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1251 ? GAIM_PROTO_TOC : GAIM_PROTO_ICQ); |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1252 } |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1253 } |
| 5228 | 1254 |
| 1255 if (file != (char *)NULL) { | |
| 5435 | 1256 snprintf(path, PATHSIZE, "%s" G_DIR_SEPARATOR_S "%s.%d.blist", file, g_screenname, protocol); |
| 5228 | 1257 g_free(g_screenname); |
| 1258 } else { | |
| 1259 g_free(g_screenname); | |
| 1260 return; | |
| 1261 } | |
| 1262 } | |
| 1263 | |
| 1264 if (stat(path, &st)) { | |
| 1265 gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Unable to stat %s.\n", | |
| 1266 path); | |
| 1267 return; | |
| 1268 } | |
| 1269 | |
| 1270 if (!(f = fopen(path, "r"))) { | |
| 1271 gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Unable to open %s.\n", | |
| 1272 path); | |
| 1273 return; | |
| 1274 } | |
| 1275 | |
| 1276 fgets(first, 64, f); | |
| 1277 | |
| 1278 if ((first[0] == '\n') || (first[0] == '\r' && first[1] == '\n')) | |
| 1279 fgets(first, 64, f); | |
| 1280 | |
| 1281 #if 0 | |
| 1282 if (!g_strncasecmp(first, "<xml", strlen("<xml"))) { | |
| 1283 /* new gaim XML buddy list */ | |
| 1284 gaim_blist_read(path); | |
| 1285 | |
| 1286 /* We really don't need to bother doing stuf like translating AIM 3 buddy lists anymore */ | |
| 1287 | |
| 1288 } else if (!g_strncasecmp(first, "Config {", strlen("Config {"))) { | |
| 1289 /* AIM 4 buddy list */ | |
| 1290 gaim_debug(GAIM_DEBUG_MISC, "blist import", "aim 4\n"); | |
| 1291 rewind(f); | |
| 1292 buf = translate_blt(f); | |
| 1293 } else if (strstr(first, "group") != NULL) { | |
| 1294 /* AIM 3 buddy list */ | |
| 1295 gaim_debug(GAIM_DEBUG_MISC, "blist import", "aim 3\n"); | |
| 1296 rewind(f); | |
| 1297 buf = translate_lst(f); | |
| 1298 } else if (!g_strncasecmp(first, "[User]", strlen("[User]"))) { | |
| 1299 /* GnomeICU (hopefully) */ | |
| 1300 gaim_debug(GAIM_DEBUG_MISC, "blist import", "gnomeicu\n"); | |
| 1301 rewind(f); | |
| 1302 buf = translate_gnomeicu(f); | |
| 1303 | |
| 1304 } else | |
| 1305 #endif | |
| 1306 if (first[0] == 'm') { | |
| 1307 /* Gaim buddy list - no translation */ | |
| 1308 char buf2[BUF_LONG * 2]; | |
| 1309 buf = g_string_new(""); | |
| 1310 rewind(f); | |
| 1311 while (1) { | |
| 1312 len = fread(buf2, 1, BUF_LONG * 2 - 1, f); | |
| 1313 if (len <= 0) | |
| 1314 break; | |
| 1315 buf2[len] = '\0'; | |
| 1316 buf = g_string_append(buf, buf2); | |
| 1317 if (len != BUF_LONG * 2 - 1) | |
| 1318 break; | |
| 1319 } | |
| 1320 } | |
| 1321 | |
| 1322 fclose(f); | |
| 1323 | |
| 1324 if (buf) { | |
| 1325 buf = g_string_prepend(buf, "toc_set_config {"); | |
| 1326 buf = g_string_append(buf, "}\n"); | |
| 1327 parse_toc_buddy_list(account, buf->str); | |
| 1328 g_string_free(buf, TRUE); | |
| 1329 } | |
| 1330 } | |
| 1331 | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1332 gboolean gaim_group_on_account(struct group *g, GaimAccount *account) { |
| 5228 | 1333 GaimBlistNode *bnode; |
| 1334 for(bnode = g->node.child; bnode; bnode = bnode->next) { | |
| 1335 struct buddy *b = (struct buddy *)bnode; | |
| 1336 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
| 1337 continue; | |
| 5855 | 1338 if((!account && gaim_account_is_connected(b->account)) |
| 1339 || b->account == account) | |
| 5228 | 1340 return TRUE; |
| 1341 } | |
| 1342 return FALSE; | |
| 1343 } | |
| 1344 | |
| 1345 static gboolean blist_safe_to_write = FALSE; | |
| 1346 | |
| 1347 static char *blist_parser_group_name = NULL; | |
| 1348 static char *blist_parser_person_name = NULL; | |
| 1349 static char *blist_parser_account_name = NULL; | |
| 1350 static int blist_parser_account_protocol = 0; | |
| 5234 | 1351 static char *blist_parser_chat_alias = NULL; |
| 1352 static char *blist_parser_component_name = NULL; | |
| 1353 static char *blist_parser_component_value = NULL; | |
| 5228 | 1354 static char *blist_parser_buddy_name = NULL; |
| 1355 static char *blist_parser_buddy_alias = NULL; | |
| 1356 static char *blist_parser_setting_name = NULL; | |
| 1357 static char *blist_parser_setting_value = NULL; | |
| 1358 static GHashTable *blist_parser_buddy_settings = NULL; | |
| 5906 | 1359 static GHashTable *blist_parser_chat_settings = NULL; |
| 5228 | 1360 static GHashTable *blist_parser_group_settings = NULL; |
| 5234 | 1361 static GHashTable *blist_parser_chat_components = NULL; |
| 5228 | 1362 static int blist_parser_privacy_mode = 0; |
| 1363 static GList *tag_stack = NULL; | |
| 1364 enum { | |
| 1365 BLIST_TAG_GAIM, | |
| 1366 BLIST_TAG_BLIST, | |
| 1367 BLIST_TAG_GROUP, | |
| 5234 | 1368 BLIST_TAG_CHAT, |
| 1369 BLIST_TAG_COMPONENT, | |
| 5228 | 1370 BLIST_TAG_PERSON, |
| 1371 BLIST_TAG_BUDDY, | |
| 1372 BLIST_TAG_NAME, | |
| 1373 BLIST_TAG_ALIAS, | |
| 1374 BLIST_TAG_SETTING, | |
| 1375 BLIST_TAG_PRIVACY, | |
| 1376 BLIST_TAG_ACCOUNT, | |
| 1377 BLIST_TAG_PERMIT, | |
| 1378 BLIST_TAG_BLOCK, | |
| 1379 BLIST_TAG_IGNORE | |
| 1380 }; | |
| 1381 static gboolean blist_parser_error_occurred = FALSE; | |
| 1382 | |
| 1383 static void blist_start_element_handler (GMarkupParseContext *context, | |
| 1384 const gchar *element_name, | |
| 1385 const gchar **attribute_names, | |
| 1386 const gchar **attribute_values, | |
| 1387 gpointer user_data, | |
| 1388 GError **error) { | |
| 1389 int i; | |
| 1390 | |
| 1391 if(!strcmp(element_name, "gaim")) { | |
| 1392 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_GAIM)); | |
| 1393 } else if(!strcmp(element_name, "blist")) { | |
| 1394 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BLIST)); | |
| 1395 } else if(!strcmp(element_name, "group")) { | |
| 1396 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_GROUP)); | |
| 1397 for(i=0; attribute_names[i]; i++) { | |
| 1398 if(!strcmp(attribute_names[i], "name")) { | |
| 1399 g_free(blist_parser_group_name); | |
| 1400 blist_parser_group_name = g_strdup(attribute_values[i]); | |
| 1401 } | |
| 1402 } | |
| 1403 if(blist_parser_group_name) { | |
| 1404 struct group *g = gaim_group_new(blist_parser_group_name); | |
| 5634 | 1405 gaim_blist_add_group(g, |
| 1406 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
| 5228 | 1407 } |
| 5234 | 1408 } else if(!strcmp(element_name, "chat")) { |
| 1409 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_CHAT)); | |
| 1410 for(i=0; attribute_names[i]; i++) { | |
| 1411 if(!strcmp(attribute_names[i], "account")) { | |
| 1412 g_free(blist_parser_account_name); | |
| 1413 blist_parser_account_name = g_strdup(attribute_values[i]); | |
| 1414 } else if(!strcmp(attribute_names[i], "protocol")) { | |
| 1415 blist_parser_account_protocol = atoi(attribute_values[i]); | |
| 1416 } | |
| 1417 } | |
| 5228 | 1418 } else if(!strcmp(element_name, "person")) { |
| 1419 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PERSON)); | |
| 1420 for(i=0; attribute_names[i]; i++) { | |
| 1421 if(!strcmp(attribute_names[i], "name")) { | |
| 1422 g_free(blist_parser_person_name); | |
| 1423 blist_parser_person_name = g_strdup(attribute_values[i]); | |
| 1424 } | |
| 1425 } | |
| 1426 } else if(!strcmp(element_name, "buddy")) { | |
| 1427 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BUDDY)); | |
| 1428 for(i=0; attribute_names[i]; i++) { | |
| 1429 if(!strcmp(attribute_names[i], "account")) { | |
| 1430 g_free(blist_parser_account_name); | |
| 1431 blist_parser_account_name = g_strdup(attribute_values[i]); | |
| 1432 } else if(!strcmp(attribute_names[i], "protocol")) { | |
| 1433 blist_parser_account_protocol = atoi(attribute_values[i]); | |
| 1434 } | |
| 1435 } | |
| 1436 } else if(!strcmp(element_name, "name")) { | |
| 1437 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_NAME)); | |
| 1438 } else if(!strcmp(element_name, "alias")) { | |
| 1439 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_ALIAS)); | |
| 1440 } else if(!strcmp(element_name, "setting")) { | |
| 1441 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_SETTING)); | |
| 1442 for(i=0; attribute_names[i]; i++) { | |
| 1443 if(!strcmp(attribute_names[i], "name")) { | |
| 1444 g_free(blist_parser_setting_name); | |
| 1445 blist_parser_setting_name = g_strdup(attribute_values[i]); | |
| 1446 } | |
| 1447 } | |
| 5234 | 1448 } else if(!strcmp(element_name, "component")) { |
| 1449 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_COMPONENT)); | |
| 1450 for(i=0; attribute_names[i]; i++) { | |
| 1451 if(!strcmp(attribute_names[i], "name")) { | |
| 1452 g_free(blist_parser_component_name); | |
| 1453 blist_parser_component_name = g_strdup(attribute_values[i]); | |
| 1454 } | |
| 1455 } | |
| 1456 | |
| 5228 | 1457 } else if(!strcmp(element_name, "privacy")) { |
| 1458 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PRIVACY)); | |
| 1459 } else if(!strcmp(element_name, "account")) { | |
| 1460 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_ACCOUNT)); | |
| 1461 for(i=0; attribute_names[i]; i++) { | |
| 1462 if(!strcmp(attribute_names[i], "protocol")) | |
| 1463 blist_parser_account_protocol = atoi(attribute_values[i]); | |
| 1464 else if(!strcmp(attribute_names[i], "mode")) | |
| 1465 blist_parser_privacy_mode = atoi(attribute_values[i]); | |
| 1466 else if(!strcmp(attribute_names[i], "name")) { | |
| 1467 g_free(blist_parser_account_name); | |
| 1468 blist_parser_account_name = g_strdup(attribute_values[i]); | |
| 1469 } | |
| 1470 } | |
| 1471 } else if(!strcmp(element_name, "permit")) { | |
| 1472 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PERMIT)); | |
| 1473 } else if(!strcmp(element_name, "block")) { | |
| 1474 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BLOCK)); | |
| 1475 } else if(!strcmp(element_name, "ignore")) { | |
| 1476 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_IGNORE)); | |
| 1477 } | |
| 1478 } | |
| 1479 | |
| 1480 static void blist_end_element_handler(GMarkupParseContext *context, | |
| 1481 const gchar *element_name, gpointer user_data, GError **error) { | |
| 1482 if(!strcmp(element_name, "gaim")) { | |
| 1483 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1484 } else if(!strcmp(element_name, "blist")) { | |
| 1485 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1486 } else if(!strcmp(element_name, "group")) { | |
| 1487 if(blist_parser_group_settings) { | |
| 1488 struct group *g = gaim_find_group(blist_parser_group_name); | |
| 1489 g_hash_table_destroy(g->settings); | |
| 1490 g->settings = blist_parser_group_settings; | |
| 1491 } | |
| 1492 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1493 blist_parser_group_settings = NULL; | |
| 5234 | 1494 } else if(!strcmp(element_name, "chat")) { |
|
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1495 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
| 5234 | 1496 blist_parser_account_protocol); |
| 5237 | 1497 if(account) { |
| 5234 | 1498 struct chat *chat = gaim_chat_new(account, blist_parser_chat_alias, blist_parser_chat_components); |
| 1499 struct group *g = gaim_find_group(blist_parser_group_name); | |
| 5634 | 1500 gaim_blist_add_chat(chat,g, |
| 1501 gaim_blist_get_last_child((GaimBlistNode*)g)); | |
| 5906 | 1502 if(blist_parser_chat_settings) { |
| 1503 g_hash_table_destroy(chat->settings); | |
| 1504 chat->settings = blist_parser_chat_settings; | |
| 1505 } | |
| 5234 | 1506 } |
| 1507 g_free(blist_parser_chat_alias); | |
| 1508 blist_parser_chat_alias = NULL; | |
| 1509 g_free(blist_parser_account_name); | |
| 1510 blist_parser_account_name = NULL; | |
| 1511 blist_parser_chat_components = NULL; | |
| 5906 | 1512 blist_parser_chat_settings = NULL; |
| 5234 | 1513 tag_stack = g_list_delete_link(tag_stack, tag_stack); |
| 5228 | 1514 } else if(!strcmp(element_name, "person")) { |
| 1515 g_free(blist_parser_person_name); | |
| 1516 blist_parser_person_name = NULL; | |
| 1517 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1518 } else if(!strcmp(element_name, "buddy")) { | |
|
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1519 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
| 5228 | 1520 blist_parser_account_protocol); |
| 1521 if(account) { | |
| 1522 struct buddy *b = gaim_buddy_new(account, blist_parser_buddy_name, blist_parser_buddy_alias); | |
| 1523 struct group *g = gaim_find_group(blist_parser_group_name); | |
| 5634 | 1524 gaim_blist_add_buddy(b,g, |
| 1525 gaim_blist_get_last_child((GaimBlistNode*)g)); | |
| 5228 | 1526 if(blist_parser_buddy_settings) { |
| 1527 g_hash_table_destroy(b->settings); | |
| 1528 b->settings = blist_parser_buddy_settings; | |
| 1529 } | |
| 1530 } | |
| 1531 g_free(blist_parser_buddy_name); | |
| 1532 blist_parser_buddy_name = NULL; | |
| 1533 g_free(blist_parser_buddy_alias); | |
| 1534 blist_parser_buddy_alias = NULL; | |
| 1535 g_free(blist_parser_account_name); | |
| 1536 blist_parser_account_name = NULL; | |
| 1537 blist_parser_buddy_settings = NULL; | |
| 1538 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1539 } else if(!strcmp(element_name, "name")) { | |
| 1540 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1541 } else if(!strcmp(element_name, "alias")) { | |
| 1542 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 5234 | 1543 } else if(!strcmp(element_name, "component")) { |
| 1544 if(!blist_parser_chat_components) | |
| 1545 blist_parser_chat_components = g_hash_table_new_full(g_str_hash, | |
| 1546 g_str_equal, g_free, g_free); | |
| 1547 if(blist_parser_component_name && blist_parser_component_value) { | |
| 1548 g_hash_table_replace(blist_parser_chat_components, | |
| 1549 g_strdup(blist_parser_component_name), | |
| 1550 g_strdup(blist_parser_component_value)); | |
| 1551 } | |
| 1552 g_free(blist_parser_component_name); | |
| 1553 g_free(blist_parser_component_value); | |
| 1554 blist_parser_component_name = NULL; | |
| 1555 blist_parser_component_value = NULL; | |
| 1556 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 5228 | 1557 } else if(!strcmp(element_name, "setting")) { |
| 1558 if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_BUDDY) { | |
| 1559 if(!blist_parser_buddy_settings) | |
| 1560 blist_parser_buddy_settings = g_hash_table_new_full(g_str_hash, | |
| 1561 g_str_equal, g_free, g_free); | |
| 1562 if(blist_parser_setting_name && blist_parser_setting_value) { | |
| 1563 g_hash_table_replace(blist_parser_buddy_settings, | |
| 1564 g_strdup(blist_parser_setting_name), | |
| 1565 g_strdup(blist_parser_setting_value)); | |
| 1566 } | |
| 5906 | 1567 } else if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_CHAT) { |
| 1568 if(!blist_parser_chat_settings) | |
| 1569 blist_parser_chat_settings = g_hash_table_new_full(g_str_hash, | |
| 1570 g_str_equal, g_free, g_free); | |
| 1571 if(blist_parser_setting_name && blist_parser_setting_value) { | |
| 6307 | 1572 g_hash_table_replace(blist_parser_chat_settings, |
| 5906 | 1573 g_strdup(blist_parser_setting_name), |
| 1574 g_strdup(blist_parser_setting_value)); | |
| 1575 } | |
| 5228 | 1576 } else if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_GROUP) { |
| 1577 if(!blist_parser_group_settings) | |
| 1578 blist_parser_group_settings = g_hash_table_new_full(g_str_hash, | |
| 1579 g_str_equal, g_free, g_free); | |
| 1580 if(blist_parser_setting_name && blist_parser_setting_value) { | |
| 1581 g_hash_table_replace(blist_parser_group_settings, | |
| 1582 g_strdup(blist_parser_setting_name), | |
| 1583 g_strdup(blist_parser_setting_value)); | |
| 1584 } | |
| 1585 } | |
| 1586 g_free(blist_parser_setting_name); | |
| 1587 g_free(blist_parser_setting_value); | |
| 1588 blist_parser_setting_name = NULL; | |
| 1589 blist_parser_setting_value = NULL; | |
| 1590 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1591 } else if(!strcmp(element_name, "privacy")) { | |
| 1592 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1593 } else if(!strcmp(element_name, "account")) { | |
|
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1594 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
| 5228 | 1595 blist_parser_account_protocol); |
| 1596 if(account) { | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1597 account->perm_deny = blist_parser_privacy_mode; |
| 5228 | 1598 } |
| 1599 g_free(blist_parser_account_name); | |
| 1600 blist_parser_account_name = NULL; | |
| 1601 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1602 } else if(!strcmp(element_name, "permit")) { | |
|
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1603 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
| 5228 | 1604 blist_parser_account_protocol); |
| 1605 if(account) { | |
| 1606 gaim_privacy_permit_add(account, blist_parser_buddy_name); | |
| 1607 } | |
| 1608 g_free(blist_parser_buddy_name); | |
| 1609 blist_parser_buddy_name = NULL; | |
| 1610 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1611 } else if(!strcmp(element_name, "block")) { | |
|
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1612 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
| 5228 | 1613 blist_parser_account_protocol); |
| 1614 if(account) { | |
| 1615 gaim_privacy_deny_add(account, blist_parser_buddy_name); | |
| 1616 } | |
| 1617 g_free(blist_parser_buddy_name); | |
| 1618 blist_parser_buddy_name = NULL; | |
| 1619 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1620 } else if(!strcmp(element_name, "ignore")) { | |
| 1621 /* we'll apparently do something with this later */ | |
| 1622 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1623 } | |
| 1624 } | |
| 1625 | |
| 1626 static void blist_text_handler(GMarkupParseContext *context, const gchar *text, | |
| 1627 gsize text_len, gpointer user_data, GError **error) { | |
| 1628 switch(GPOINTER_TO_INT(tag_stack->data)) { | |
| 1629 case BLIST_TAG_NAME: | |
| 1630 blist_parser_buddy_name = g_strndup(text, text_len); | |
| 1631 break; | |
| 1632 case BLIST_TAG_ALIAS: | |
| 5234 | 1633 if(tag_stack->next && |
| 1634 GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_BUDDY) | |
| 1635 blist_parser_buddy_alias = g_strndup(text, text_len); | |
| 1636 else if(tag_stack->next && | |
| 1637 GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_CHAT) | |
| 1638 blist_parser_chat_alias = g_strndup(text, text_len); | |
| 5228 | 1639 break; |
| 1640 case BLIST_TAG_PERMIT: | |
| 1641 case BLIST_TAG_BLOCK: | |
| 1642 case BLIST_TAG_IGNORE: | |
| 1643 blist_parser_buddy_name = g_strndup(text, text_len); | |
| 1644 break; | |
| 5234 | 1645 case BLIST_TAG_COMPONENT: |
| 1646 blist_parser_component_value = g_strndup(text, text_len); | |
| 1647 break; | |
| 5228 | 1648 case BLIST_TAG_SETTING: |
| 1649 blist_parser_setting_value = g_strndup(text, text_len); | |
| 1650 break; | |
| 1651 default: | |
| 1652 break; | |
| 1653 } | |
| 1654 } | |
| 1655 | |
| 1656 static void blist_error_handler(GMarkupParseContext *context, GError *error, | |
| 1657 gpointer user_data) { | |
| 1658 blist_parser_error_occurred = TRUE; | |
| 1659 gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
| 1660 "Error parsing blist.xml: %s\n", error->message); | |
| 1661 } | |
| 1662 | |
| 1663 static GMarkupParser blist_parser = { | |
| 1664 blist_start_element_handler, | |
| 1665 blist_end_element_handler, | |
| 1666 blist_text_handler, | |
| 1667 NULL, | |
| 1668 blist_error_handler | |
| 1669 }; | |
| 1670 | |
| 1671 static gboolean gaim_blist_read(const char *filename) { | |
| 1672 gchar *contents = NULL; | |
| 1673 gsize length; | |
| 1674 GMarkupParseContext *context; | |
| 1675 GError *error = NULL; | |
| 1676 | |
| 1677 gaim_debug(GAIM_DEBUG_INFO, "blist import", | |
| 1678 "Reading %s\n", filename); | |
| 1679 if(!g_file_get_contents(filename, &contents, &length, &error)) { | |
| 1680 gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
| 1681 "Error reading blist: %s\n", error->message); | |
| 1682 g_error_free(error); | |
| 1683 return FALSE; | |
| 1684 } | |
| 1685 | |
| 1686 context = g_markup_parse_context_new(&blist_parser, 0, NULL, NULL); | |
| 1687 | |
| 1688 if(!g_markup_parse_context_parse(context, contents, length, NULL)) { | |
| 1689 g_markup_parse_context_free(context); | |
| 1690 g_free(contents); | |
| 1691 return FALSE; | |
| 1692 } | |
| 1693 | |
| 1694 if(!g_markup_parse_context_end_parse(context, NULL)) { | |
| 1695 gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
| 1696 "Error parsing %s\n", filename); | |
| 1697 g_markup_parse_context_free(context); | |
| 1698 g_free(contents); | |
| 1699 return FALSE; | |
| 1700 } | |
| 1701 | |
| 1702 g_markup_parse_context_free(context); | |
| 1703 g_free(contents); | |
| 1704 | |
| 1705 if(blist_parser_error_occurred) | |
| 1706 return FALSE; | |
| 1707 | |
| 1708 gaim_debug(GAIM_DEBUG_INFO, "blist import", "Finished reading %s\n", | |
| 1709 filename); | |
| 1710 | |
| 1711 return TRUE; | |
| 1712 } | |
| 1713 | |
| 1714 void gaim_blist_load() { | |
|
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1715 GList *accts; |
| 5228 | 1716 char *user_dir = gaim_user_dir(); |
| 1717 char *filename; | |
| 1718 char *msg; | |
| 1719 | |
| 1720 blist_safe_to_write = TRUE; | |
| 1721 | |
| 1722 if(!user_dir) | |
| 1723 return; | |
| 1724 | |
| 1725 filename = g_build_filename(user_dir, "blist.xml", NULL); | |
| 1726 | |
| 1727 if(g_file_test(filename, G_FILE_TEST_EXISTS)) { | |
| 1728 if(!gaim_blist_read(filename)) { | |
| 1729 msg = g_strdup_printf(_("An error was encountered parsing your " | |
| 1730 "buddy list. It has not been loaded.")); | |
|
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
1731 gaim_notify_error(NULL, NULL, _("Buddy List Error"), msg); |
| 5228 | 1732 g_free(msg); |
| 1733 } | |
|
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1734 } else if(g_list_length(gaim_accounts_get_all())) { |
|
5947
ac4dd1d0ee39
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1735 GMainContext *ctx; |
|
ac4dd1d0ee39
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1736 |
| 5228 | 1737 /* rob wants to inform the user that their buddy lists are |
| 1738 * being converted */ | |
| 1739 msg = g_strdup_printf(_("Gaim is converting your old buddy lists " | |
| 1740 "to a new format, which will now be located at %s"), | |
| 1741 filename); | |
|
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
1742 gaim_notify_info(NULL, NULL, _("Converting Buddy List"), msg); |
| 5228 | 1743 g_free(msg); |
| 1744 | |
| 1745 /* 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
|
1746 ctx = g_main_context_default(); |
|
ac4dd1d0ee39
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1747 |
|
ac4dd1d0ee39
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1748 while(g_main_context_pending(ctx)) |
|
ac4dd1d0ee39
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1749 g_main_context_iteration(ctx, FALSE); |
| 5228 | 1750 |
| 1751 /* 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
|
1752 for(accts = gaim_accounts_get_all(); accts; accts = accts->next) { |
| 5228 | 1753 do_import(accts->data, NULL); |
| 1754 } | |
| 1755 gaim_blist_save(); | |
| 1756 } | |
| 1757 | |
| 1758 g_free(filename); | |
| 1759 } | |
| 1760 | |
| 1761 static void blist_print_group_settings(gpointer key, gpointer data, | |
| 1762 gpointer user_data) { | |
| 1763 char *key_val; | |
| 1764 char *data_val; | |
| 1765 FILE *file = user_data; | |
| 1766 | |
| 1767 if(!key || !data) | |
| 1768 return; | |
| 1769 | |
| 1770 key_val = g_markup_escape_text(key, -1); | |
| 1771 data_val = g_markup_escape_text(data, -1); | |
| 1772 | |
| 1773 fprintf(file, "\t\t\t<setting name=\"%s\">%s</setting>\n", key_val, | |
| 1774 data_val); | |
| 1775 g_free(key_val); | |
| 1776 g_free(data_val); | |
| 1777 } | |
| 1778 | |
| 1779 static void blist_print_buddy_settings(gpointer key, gpointer data, | |
| 1780 gpointer user_data) { | |
| 1781 char *key_val; | |
| 1782 char *data_val; | |
| 1783 FILE *file = user_data; | |
| 1784 | |
| 1785 if(!key || !data) | |
| 1786 return; | |
| 1787 | |
| 1788 key_val = g_markup_escape_text(key, -1); | |
| 1789 data_val = g_markup_escape_text(data, -1); | |
| 1790 | |
| 1791 fprintf(file, "\t\t\t\t\t<setting name=\"%s\">%s</setting>\n", key_val, | |
| 1792 data_val); | |
| 1793 g_free(key_val); | |
| 1794 g_free(data_val); | |
| 1795 } | |
| 1796 | |
| 5234 | 1797 static void blist_print_chat_components(gpointer key, gpointer data, |
| 1798 gpointer user_data) { | |
| 1799 char *key_val; | |
| 1800 char *data_val; | |
| 1801 FILE *file = user_data; | |
| 1802 | |
| 1803 if(!key || !data) | |
| 1804 return; | |
| 1805 | |
| 1806 key_val = g_markup_escape_text(key, -1); | |
| 1807 data_val = g_markup_escape_text(data, -1); | |
| 1808 | |
| 1809 fprintf(file, "\t\t\t\t<component name=\"%s\">%s</component>\n", key_val, | |
| 1810 data_val); | |
| 1811 g_free(key_val); | |
| 1812 g_free(data_val); | |
| 1813 } | |
| 1814 | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1815 static void gaim_blist_write(FILE *file, GaimAccount *exp_acct) { |
|
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1816 GList *accounts; |
|
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1817 GSList *buds; |
| 5228 | 1818 GaimBlistNode *gnode,*bnode; |
| 1819 struct group *group; | |
| 1820 struct buddy *bud; | |
| 1821 fprintf(file, "<?xml version='1.0' encoding='UTF-8' ?>\n"); | |
| 1822 fprintf(file, "<gaim version=\"1\">\n"); | |
| 1823 fprintf(file, "\t<blist>\n"); | |
| 1824 | |
| 1825 for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { | |
| 1826 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
| 1827 continue; | |
| 1828 group = (struct group *)gnode; | |
| 1829 if(!exp_acct || gaim_group_on_account(group, exp_acct)) { | |
| 1830 char *group_name = g_markup_escape_text(group->name, -1); | |
| 1831 fprintf(file, "\t\t<group name=\"%s\">\n", group_name); | |
| 1832 g_hash_table_foreach(group->settings, blist_print_group_settings, file); | |
| 1833 for(bnode = gnode->child; bnode; bnode = bnode->next) { | |
| 5234 | 1834 if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { |
| 1835 bud = (struct buddy *)bnode; | |
| 1836 if(!exp_acct || bud->account == exp_acct) { | |
| 1837 char *bud_name = g_markup_escape_text(bud->name, -1); | |
| 1838 char *bud_alias = NULL; | |
| 1839 char *acct_name = g_markup_escape_text(bud->account->username, -1); | |
| 1840 if(bud->alias) | |
| 1841 bud_alias= g_markup_escape_text(bud->alias, -1); | |
| 1842 fprintf(file, "\t\t\t<person name=\"%s\">\n", | |
| 1843 bud_alias ? bud_alias : bud_name); | |
| 1844 fprintf(file, "\t\t\t\t<buddy protocol=\"%d\" " | |
|
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1845 "account=\"%s\">\n", |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1846 gaim_account_get_protocol(bud->account), |
| 5234 | 1847 acct_name); |
| 1848 fprintf(file, "\t\t\t\t\t<name>%s</name>\n", bud_name); | |
| 1849 if(bud_alias) { | |
| 1850 fprintf(file, "\t\t\t\t\t<alias>%s</alias>\n", | |
| 1851 bud_alias); | |
| 1852 } | |
| 1853 g_hash_table_foreach(bud->settings, | |
| 1854 blist_print_buddy_settings, file); | |
| 1855 fprintf(file, "\t\t\t\t</buddy>\n"); | |
| 1856 fprintf(file, "\t\t\t</person>\n"); | |
| 1857 g_free(bud_name); | |
| 1858 g_free(bud_alias); | |
| 1859 g_free(acct_name); | |
| 5228 | 1860 } |
| 5234 | 1861 } else if(GAIM_BLIST_NODE_IS_CHAT(bnode)) { |
| 1862 struct chat *chat = (struct chat *)bnode; | |
| 1863 if(!exp_acct || chat->account == exp_acct) { | |
| 1864 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
|
1865 fprintf(file, "\t\t\t<chat protocol=\"%d\" account=\"%s\">\n", |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1866 gaim_account_get_protocol(chat->account), |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1867 acct_name); |
| 5237 | 1868 if(chat->alias) { |
| 1869 char *chat_alias = g_markup_escape_text(chat->alias, -1); | |
| 1870 fprintf(file, "\t\t\t\t<alias>%s</alias>\n", chat_alias); | |
| 1871 g_free(chat_alias); | |
| 1872 } | |
| 5234 | 1873 g_hash_table_foreach(chat->components, |
| 1874 blist_print_chat_components, file); | |
| 5906 | 1875 /* works for chats too, I don't feel like renaming */ |
| 1876 g_hash_table_foreach(chat->settings, | |
| 1877 blist_print_buddy_settings, file); | |
| 5234 | 1878 fprintf(file, "\t\t\t</chat>\n"); |
| 5237 | 1879 g_free(acct_name); |
| 5234 | 1880 } |
| 5228 | 1881 } |
| 1882 } | |
| 1883 fprintf(file, "\t\t</group>\n"); | |
| 1884 g_free(group_name); | |
| 1885 } | |
| 1886 } | |
| 1887 | |
| 1888 fprintf(file, "\t</blist>\n"); | |
| 1889 fprintf(file, "\t<privacy>\n"); | |
| 1890 | |
|
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1891 for(accounts = gaim_accounts_get_all(); |
|
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1892 accounts != NULL; |
|
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1893 accounts = accounts->next) { |
|
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1894 |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1895 GaimAccount *account = accounts->data; |
| 5228 | 1896 char *acct_name = g_markup_escape_text(account->username, -1); |
| 1897 if(!exp_acct || account == exp_acct) { | |
| 1898 fprintf(file, "\t\t<account protocol=\"%d\" name=\"%s\" " | |
|
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1899 "mode=\"%d\">\n", gaim_account_get_protocol(account), |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1900 acct_name, account->perm_deny); |
| 5228 | 1901 for(buds = account->permit; buds; buds = buds->next) { |
| 1902 char *bud_name = g_markup_escape_text(buds->data, -1); | |
| 1903 fprintf(file, "\t\t\t<permit>%s</permit>\n", bud_name); | |
| 1904 g_free(bud_name); | |
| 1905 } | |
| 1906 for(buds = account->deny; buds; buds = buds->next) { | |
| 1907 char *bud_name = g_markup_escape_text(buds->data, -1); | |
| 1908 fprintf(file, "\t\t\t<block>%s</block>\n", bud_name); | |
| 1909 g_free(bud_name); | |
| 1910 } | |
| 1911 fprintf(file, "\t\t</account>\n"); | |
| 1912 } | |
| 1913 g_free(acct_name); | |
| 1914 } | |
| 1915 | |
| 1916 fprintf(file, "\t</privacy>\n"); | |
| 1917 fprintf(file, "</gaim>\n"); | |
| 1918 } | |
| 1919 | |
| 1920 void gaim_blist_save() { | |
| 1921 FILE *file; | |
| 1922 char *user_dir = gaim_user_dir(); | |
| 1923 char *filename; | |
| 1924 char *filename_real; | |
| 1925 | |
| 1926 if(!user_dir) | |
| 1927 return; | |
| 1928 if(!blist_safe_to_write) { | |
| 1929 gaim_debug(GAIM_DEBUG_WARNING, "blist save", | |
| 1930 "AHH!! Tried to write the blist before we read it!\n"); | |
| 1931 return; | |
| 1932 } | |
| 1933 | |
| 1934 file = fopen(user_dir, "r"); | |
| 1935 if(!file) | |
| 1936 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 1937 else | |
| 1938 fclose(file); | |
| 1939 | |
| 1940 filename = g_build_filename(user_dir, "blist.xml.save", NULL); | |
| 1941 | |
| 1942 if((file = fopen(filename, "w"))) { | |
| 1943 gaim_blist_write(file, NULL); | |
| 1944 fclose(file); | |
| 1945 chmod(filename, S_IRUSR | S_IWUSR); | |
| 1946 } else { | |
| 1947 gaim_debug(GAIM_DEBUG_ERROR, "blist save", "Unable to write %s\n", | |
| 1948 filename); | |
| 1949 } | |
| 1950 | |
| 1951 filename_real = g_build_filename(user_dir, "blist.xml", NULL); | |
| 1952 | |
| 1953 if(rename(filename, filename_real) < 0) | |
| 1954 gaim_debug(GAIM_DEBUG_ERROR, "blist save", | |
| 1955 "Error renaming %s to %s\n", filename, filename_real); | |
| 1956 | |
| 1957 | |
| 1958 g_free(filename); | |
| 1959 g_free(filename_real); | |
| 1960 } | |
| 1961 | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1962 gboolean gaim_privacy_permit_add(GaimAccount *account, const char *who) { |
| 5228 | 1963 GSList *d = account->permit; |
| 1964 char *n = g_strdup(normalize(who)); | |
| 1965 while(d) { | |
| 1966 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) | |
| 1967 break; | |
| 1968 d = d->next; | |
| 1969 } | |
| 1970 g_free(n); | |
| 1971 if(!d) { | |
| 1972 account->permit = g_slist_append(account->permit, g_strdup(who)); | |
| 1973 return TRUE; | |
| 1974 } | |
| 1975 | |
| 1976 return FALSE; | |
| 1977 } | |
| 1978 | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1979 gboolean gaim_privacy_permit_remove(GaimAccount *account, const char *who) { |
| 5228 | 1980 GSList *d = account->permit; |
| 1981 char *n = g_strdup(normalize(who)); | |
| 1982 while(d) { | |
| 1983 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) | |
| 1984 break; | |
| 1985 d = d->next; | |
| 1986 } | |
| 1987 g_free(n); | |
| 1988 if(d) { | |
| 1989 account->permit = g_slist_remove(account->permit, d->data); | |
| 1990 g_free(d->data); | |
| 1991 return TRUE; | |
| 1992 } | |
| 1993 return FALSE; | |
| 1994 } | |
| 1995 | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1996 gboolean gaim_privacy_deny_add(GaimAccount *account, const char *who) { |
| 5228 | 1997 GSList *d = account->deny; |
| 1998 char *n = g_strdup(normalize(who)); | |
| 1999 while(d) { | |
| 2000 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) | |
| 2001 break; | |
| 2002 d = d->next; | |
| 2003 } | |
| 2004 g_free(n); | |
| 2005 if(!d) { | |
| 2006 account->deny = g_slist_append(account->deny, g_strdup(who)); | |
| 2007 return TRUE; | |
| 2008 } | |
| 2009 | |
| 2010 return FALSE; | |
| 2011 } | |
| 2012 | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
2013 gboolean gaim_privacy_deny_remove(GaimAccount *account, const char *who) { |
| 5228 | 2014 GSList *d = account->deny; |
| 2015 char *n = g_strdup(normalize(who)); | |
| 2016 while(d) { | |
| 2017 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) | |
| 2018 break; | |
| 2019 d = d->next; | |
| 2020 } | |
| 2021 g_free(n); | |
| 2022 if(d) { | |
| 2023 account->deny = g_slist_remove(account->deny, d->data); | |
| 2024 g_free(d->data); | |
| 2025 return TRUE; | |
| 2026 } | |
| 2027 return FALSE; | |
| 2028 } | |
| 2029 | |
| 2030 void gaim_group_set_setting(struct group *g, const char *key, | |
| 2031 const char *value) { | |
| 2032 if(!g) | |
| 2033 return; | |
| 2034 g_hash_table_replace(g->settings, g_strdup(key), g_strdup(value)); | |
| 2035 } | |
| 2036 | |
| 2037 char *gaim_group_get_setting(struct group *g, const char *key) { | |
| 2038 if(!g) | |
| 2039 return NULL; | |
| 2040 return g_strdup(g_hash_table_lookup(g->settings, key)); | |
| 2041 } | |
| 2042 | |
| 5906 | 2043 void gaim_chat_set_setting(struct chat *c, const char *key, |
| 2044 const char *value) | |
| 2045 { | |
| 2046 if(!c) | |
| 2047 return; | |
| 2048 g_hash_table_replace(c->settings, g_strdup(key), g_strdup(value)); | |
| 2049 } | |
| 2050 | |
| 2051 char *gaim_chat_get_setting(struct chat *c, const char *key) | |
| 2052 { | |
| 2053 if(!c) | |
| 2054 return NULL; | |
| 2055 return g_strdup(g_hash_table_lookup(c->settings, key)); | |
| 2056 } | |
| 2057 | |
| 5228 | 2058 void gaim_buddy_set_setting(struct buddy *b, const char *key, |
| 2059 const char *value) { | |
| 2060 if(!b) | |
| 2061 return; | |
| 2062 g_hash_table_replace(b->settings, g_strdup(key), g_strdup(value)); | |
| 2063 } | |
| 2064 | |
| 2065 char *gaim_buddy_get_setting(struct buddy *b, const char *key) { | |
| 2066 if(!b) | |
| 2067 return NULL; | |
| 2068 return g_strdup(g_hash_table_lookup(b->settings, key)); | |
| 2069 } | |
| 2070 | |
| 2071 void gaim_set_blist_ui_ops(struct gaim_blist_ui_ops *ops) | |
| 2072 { | |
| 2073 blist_ui_ops = ops; | |
| 2074 } | |
| 2075 | |
| 2076 struct gaim_blist_ui_ops * | |
| 2077 gaim_get_blist_ui_ops(void) | |
| 2078 { | |
| 2079 return blist_ui_ops; | |
| 2080 } | |
| 2081 | |
| 2082 int gaim_blist_get_group_size(struct group *group, gboolean offline) { | |
| 2083 if(!group) | |
| 2084 return 0; | |
| 2085 | |
| 5277 | 2086 return offline ? group->totalsize : group->currentsize; |
| 5228 | 2087 } |
| 2088 | |
| 2089 int gaim_blist_get_group_online_count(struct group *group) { | |
| 2090 if(!group) | |
| 2091 return 0; | |
| 2092 | |
| 5277 | 2093 return group->online; |
| 5228 | 2094 } |
| 2095 | |
| 2096 |
