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