Fri, 18 Apr 2003 21:49:45 +0000
[gaim-migrate @ 5534]
This makes the buddy ticker plugin work again, and may cause some slight
breakage in some plugins, since it slightly changes the behavior of:
event_buddy_signon
event_buddy_signoff
event_buddy_away
event_buddy_back
Then again, it's nothing compared to the massive breakage being thought up
for the very near future ;-)
| 2382 | 1 | /* |
| 2 | * gaim | |
| 3 | * | |
| 4687 | 4 | * Copyright (C) 2003, Sean Egan <sean.egan@binghamton.edu> |
| 2382 | 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 | */ | |
| 22 | ||
| 23 | #ifdef HAVE_CONFIG_H | |
| 24 | #include <config.h> | |
| 25 | #endif | |
| 26 | #include <string.h> | |
| 4349 | 27 | #include <stdlib.h> |
| 2382 | 28 | #include <sys/types.h> |
| 29 | #include <sys/stat.h> | |
| 3630 | 30 | #ifndef _WIN32 |
| 2382 | 31 | #include <unistd.h> |
| 3630 | 32 | #else |
| 33 | #include <direct.h> | |
| 34 | #endif | |
| 4349 | 35 | #include <ctype.h> |
| 2382 | 36 | #include "gaim.h" |
| 37 | #include "prpl.h" | |
| 4687 | 38 | #include "list.h" |
| 2382 | 39 | |
|
3717
2fc0789e04e8
[gaim-migrate @ 3850]
Herman Bloggs <herman@bluedigits.com>
parents:
3630
diff
changeset
|
40 | #ifdef _WIN32 |
|
2fc0789e04e8
[gaim-migrate @ 3850]
Herman Bloggs <herman@bluedigits.com>
parents:
3630
diff
changeset
|
41 | #include "win32dep.h" |
|
2fc0789e04e8
[gaim-migrate @ 3850]
Herman Bloggs <herman@bluedigits.com>
parents:
3630
diff
changeset
|
42 | #endif |
|
2fc0789e04e8
[gaim-migrate @ 3850]
Herman Bloggs <herman@bluedigits.com>
parents:
3630
diff
changeset
|
43 | |
| 2382 | 44 | #define PATHSIZE 1024 |
| 45 | ||
| 4687 | 46 | struct gaim_buddy_list *gaimbuddylist = NULL; |
| 47 | static struct gaim_blist_ui_ops *blist_ui_ops = NULL; | |
| 2382 | 48 | |
| 4687 | 49 | /***************************************************************************** |
| 50 | * Private Utility functions * | |
| 51 | *****************************************************************************/ | |
| 52 | static GaimBlistNode *gaim_blist_get_last_sibling(GaimBlistNode *node) | |
| 53 | { | |
| 54 | GaimBlistNode *n = node; | |
| 55 | if (!n) | |
| 56 | return NULL; | |
| 57 | while (n->next) | |
| 58 | n = n->next; | |
| 59 | return n; | |
| 60 | } | |
| 61 | static GaimBlistNode *gaim_blist_get_last_child(GaimBlistNode *node) | |
| 62 | { | |
| 63 | if (!node) | |
| 64 | return NULL; | |
| 65 | return gaim_blist_get_last_sibling(node->child); | |
| 66 | } | |
| 2382 | 67 | |
| 4770 | 68 | /***************************************************************************** |
| 4687 | 69 | * Public API functions * |
| 70 | *****************************************************************************/ | |
| 4349 | 71 | |
| 4687 | 72 | struct gaim_buddy_list *gaim_blist_new() |
| 73 | { | |
| 74 | struct gaim_buddy_list *gbl = g_new0(struct gaim_buddy_list, 1); | |
|
4695
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
75 | |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
76 | gbl->ui_ops = gaim_get_blist_ui_ops(); |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
77 | |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
78 | if (gbl->ui_ops != NULL && gbl->ui_ops->new_list != NULL) |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
79 | gbl->ui_ops->new_list(gbl); |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
80 | |
| 4687 | 81 | return gbl; |
| 82 | } | |
| 2382 | 83 | |
|
4695
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
84 | void |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
85 | gaim_set_blist(struct gaim_buddy_list *list) |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
86 | { |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
87 | gaimbuddylist = list; |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
88 | } |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
89 | |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
90 | struct gaim_buddy_list * |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
91 | gaim_get_blist(void) |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
92 | { |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
93 | return gaimbuddylist; |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
94 | } |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
95 | |
| 4687 | 96 | void gaim_blist_show () |
| 97 | { | |
| 98 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 99 | if (ops) | |
| 100 | ops->show(gaimbuddylist); | |
| 101 | } | |
| 2382 | 102 | |
| 4687 | 103 | void gaim_blist_destroy() |
| 104 | { | |
| 105 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 106 | if (ops) | |
| 107 | ops->destroy(gaimbuddylist); | |
| 108 | } | |
| 2382 | 109 | |
| 4687 | 110 | void gaim_blist_set_visible (gboolean show) |
| 111 | { | |
| 112 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 113 | if (ops) | |
| 114 | ops->set_visible(gaimbuddylist, show); | |
| 115 | } | |
| 2382 | 116 | |
| 4687 | 117 | void gaim_blist_update_buddy_status (struct buddy *buddy, int status) |
| 118 | { | |
| 119 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 120 | buddy->uc = status; | |
| 5170 | 121 | |
| 122 | if(!(status & UC_UNAVAILABLE)) | |
| 123 | plugin_event(event_buddy_back, buddy->account->gc, buddy->name); | |
| 124 | else | |
| 125 | plugin_event(event_buddy_away, buddy->account->gc, buddy->name); | |
| 126 | ||
| 4687 | 127 | if (ops) |
| 128 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 2382 | 129 | } |
| 130 | ||
| 5068 | 131 | static gboolean presence_update_timeout_cb(struct buddy *buddy) { |
| 4687 | 132 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; |
| 4988 | 133 | |
| 5170 | 134 | if(buddy->present == GAIM_BUDDY_SIGNING_ON) { |
| 5068 | 135 | buddy->present = GAIM_BUDDY_ONLINE; |
| 5170 | 136 | plugin_event(event_buddy_signon, buddy->account->gc, buddy->name); |
| 137 | } else if(buddy->present == GAIM_BUDDY_SIGNING_OFF) { | |
| 5068 | 138 | buddy->present = GAIM_BUDDY_OFFLINE; |
| 5170 | 139 | } |
| 5068 | 140 | |
| 141 | buddy->timer = 0; | |
| 142 | ||
| 143 | if (ops) | |
| 144 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 145 | ||
| 146 | return FALSE; | |
| 147 | } | |
| 148 | ||
| 149 | void gaim_blist_update_buddy_presence(struct buddy *buddy, int presence) { | |
| 150 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 151 | gboolean do_timer = FALSE; | |
| 152 | ||
| 153 | if (!GAIM_BUDDY_IS_ONLINE(buddy) && presence) { | |
| 154 | buddy->present = GAIM_BUDDY_SIGNING_ON; | |
| 5170 | 155 | plugin_event(event_buddy_signon, buddy->account->gc, buddy->name); |
| 5068 | 156 | do_timer = TRUE; |
| 157 | } else if(GAIM_BUDDY_IS_ONLINE(buddy) && !presence) { | |
| 158 | buddy->present = GAIM_BUDDY_SIGNING_OFF; | |
| 5170 | 159 | plugin_event(event_buddy_signoff, buddy->account->gc, buddy->name); |
| 5068 | 160 | do_timer = TRUE; |
| 161 | } | |
| 162 | ||
| 163 | if(do_timer) { | |
| 164 | if(buddy->timer > 0) | |
| 165 | g_source_remove(buddy->timer); | |
| 166 | buddy->timer = g_timeout_add(10000, (GSourceFunc)presence_update_timeout_cb, buddy); | |
| 167 | } | |
| 168 | ||
| 4687 | 169 | if (ops) |
| 170 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 171 | } | |
| 2382 | 172 | |
| 173 | ||
| 4687 | 174 | void gaim_blist_update_buddy_idle (struct buddy *buddy, int idle) |
| 175 | { | |
| 176 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 177 | buddy->idle = idle; | |
| 178 | if (ops) | |
| 179 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 180 | } | |
| 181 | void gaim_blist_update_buddy_evil (struct buddy *buddy, int warning) | |
| 182 | { | |
| 183 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 184 | buddy->evil = warning; | |
| 185 | if (ops) | |
| 186 | ops->update(gaimbuddylist,(GaimBlistNode*)buddy); | |
| 187 | } | |
| 4757 | 188 | void gaim_blist_update_buddy_icon(struct buddy *buddy) { |
| 189 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 190 | if(ops) | |
| 191 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 192 | } | |
| 4687 | 193 | void gaim_blist_rename_buddy (struct buddy *buddy, const char *name) |
| 194 | { | |
| 195 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 196 | g_free(buddy->name); | |
| 197 | buddy->name = g_strdup(name); | |
| 198 | if (ops) | |
| 199 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 200 | } | |
| 201 | void gaim_blist_alias_buddy (struct buddy *buddy, const char *alias) | |
| 202 | { | |
| 203 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
|
4942
202cb90e14ba
[gaim-migrate @ 5276]
Christian Hammond <chipx86@chipx86.com>
parents:
4941
diff
changeset
|
204 | struct gaim_conversation *conv; |
|
202cb90e14ba
[gaim-migrate @ 5276]
Christian Hammond <chipx86@chipx86.com>
parents:
4941
diff
changeset
|
205 | |
| 4687 | 206 | g_free(buddy->alias); |
|
4942
202cb90e14ba
[gaim-migrate @ 5276]
Christian Hammond <chipx86@chipx86.com>
parents:
4941
diff
changeset
|
207 | |
| 4687 | 208 | buddy->alias = g_strdup(alias); |
|
4942
202cb90e14ba
[gaim-migrate @ 5276]
Christian Hammond <chipx86@chipx86.com>
parents:
4941
diff
changeset
|
209 | |
| 4687 | 210 | if (ops) |
| 211 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
|
4942
202cb90e14ba
[gaim-migrate @ 5276]
Christian Hammond <chipx86@chipx86.com>
parents:
4941
diff
changeset
|
212 | |
|
202cb90e14ba
[gaim-migrate @ 5276]
Christian Hammond <chipx86@chipx86.com>
parents:
4941
diff
changeset
|
213 | conv = gaim_find_conversation_with_account(buddy->name, buddy->account); |
|
202cb90e14ba
[gaim-migrate @ 5276]
Christian Hammond <chipx86@chipx86.com>
parents:
4941
diff
changeset
|
214 | |
|
202cb90e14ba
[gaim-migrate @ 5276]
Christian Hammond <chipx86@chipx86.com>
parents:
4941
diff
changeset
|
215 | if (conv) |
|
202cb90e14ba
[gaim-migrate @ 5276]
Christian Hammond <chipx86@chipx86.com>
parents:
4941
diff
changeset
|
216 | gaim_conversation_autoset_title(conv); |
| 4687 | 217 | } |
|
4942
202cb90e14ba
[gaim-migrate @ 5276]
Christian Hammond <chipx86@chipx86.com>
parents:
4941
diff
changeset
|
218 | |
| 4687 | 219 | void gaim_blist_rename_group(struct group *group, const char *name) |
| 220 | { | |
| 221 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 222 | g_free(group->name); | |
| 223 | group->name = g_strdup(name); | |
| 224 | if (ops) | |
| 225 | ops->update(gaimbuddylist, (GaimBlistNode*)group); | |
| 226 | } | |
| 227 | struct buddy *gaim_buddy_new(struct gaim_account *account, const char *screenname, const char *alias) | |
| 228 | { | |
|
4695
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
229 | struct buddy *b; |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
230 | struct gaim_blist_ui_ops *ops; |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
231 | |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
232 | b = g_new0(struct buddy, 1); |
| 4491 | 233 | b->account = account; |
| 4687 | 234 | b->name = g_strdup(screenname); |
| 235 | b->alias = g_strdup(alias); | |
| 4349 | 236 | b->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
| 4687 | 237 | ((GaimBlistNode*)b)->type = GAIM_BLIST_BUDDY_NODE; |
| 2382 | 238 | |
|
4695
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
239 | ops = gaim_get_blist_ui_ops(); |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
240 | |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
241 | if (ops != NULL && ops->new_node != NULL) |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
242 | ops->new_node((GaimBlistNode *)b); |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
243 | |
| 2382 | 244 | return b; |
| 245 | } | |
| 4687 | 246 | void gaim_blist_add_buddy (struct buddy *buddy, struct group *group, GaimBlistNode *node) |
| 2382 | 247 | { |
| 5041 | 248 | GaimBlistNode *n = node, *bnode = (GaimBlistNode*)buddy; |
| 4687 | 249 | struct group *g = group; |
| 250 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 4770 | 251 | gboolean save = FALSE; |
| 4865 | 252 | |
| 4687 | 253 | if (!n) { |
| 254 | if (!g) { | |
| 255 | g = gaim_group_new(_("Buddies")); | |
| 256 | gaim_blist_add_group(g, NULL); | |
| 257 | } | |
| 258 | n = gaim_blist_get_last_child((GaimBlistNode*)g); | |
| 4971 | 259 | } else { |
| 260 | g = (struct group*)n->parent; | |
| 4687 | 261 | } |
| 262 | ||
| 4941 | 263 | /* if we're moving to overtop of ourselves, do nothing */ |
| 5041 | 264 | if(bnode == n) |
| 4941 | 265 | return; |
| 266 | ||
| 5041 | 267 | if (bnode->parent) { |
| 4770 | 268 | /* This buddy was already in the list and is |
| 269 | * being moved. | |
| 270 | */ | |
| 5041 | 271 | if(bnode->next) |
| 272 | bnode->next->prev = bnode->prev; | |
| 273 | if(bnode->prev) | |
| 274 | bnode->prev->next = bnode->next; | |
| 275 | if(bnode->parent->child == bnode) | |
| 276 | bnode->parent->child = bnode->next; | |
| 4865 | 277 | |
| 5041 | 278 | ops->remove(gaimbuddylist, bnode); |
| 4770 | 279 | |
| 5041 | 280 | if (bnode->parent != ((GaimBlistNode*)g)) |
| 281 | serv_move_buddy(buddy, (struct group*)bnode->parent, g); | |
| 4770 | 282 | save = TRUE; |
| 283 | } | |
| 2382 | 284 | |
| 4687 | 285 | if (n) { |
| 5041 | 286 | if(n->next) |
| 287 | n->next->prev = (GaimBlistNode*)buddy; | |
| 4687 | 288 | ((GaimBlistNode*)buddy)->next = n->next; |
| 289 | ((GaimBlistNode*)buddy)->prev = n; | |
| 290 | ((GaimBlistNode*)buddy)->parent = n->parent; | |
| 291 | n->next = (GaimBlistNode*)buddy; | |
| 292 | } else { | |
| 293 | ((GaimBlistNode*)g)->child = (GaimBlistNode*)buddy; | |
| 294 | ((GaimBlistNode*)buddy)->next = NULL; | |
| 295 | ((GaimBlistNode*)buddy)->prev = NULL; | |
| 296 | ((GaimBlistNode*)buddy)->parent = (GaimBlistNode*)g; | |
| 297 | } | |
| 2382 | 298 | |
| 4687 | 299 | if (ops) |
| 300 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 4865 | 301 | if (save) |
| 4770 | 302 | gaim_blist_save(); |
| 4687 | 303 | } |
| 2382 | 304 | |
| 4687 | 305 | struct group *gaim_group_new(const char *name) |
| 306 | { | |
| 307 | struct group *g = gaim_find_group(name); | |
|
4695
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
308 | |
| 4687 | 309 | if (!g) { |
|
4695
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
310 | struct gaim_blist_ui_ops *ops; |
| 4687 | 311 | g= g_new0(struct group, 1); |
| 312 | g->name = g_strdup(name); | |
| 5142 | 313 | g->settings = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 314 | g_free, g_free); | |
| 4687 | 315 | ((GaimBlistNode*)g)->type = GAIM_BLIST_GROUP_NODE; |
| 2382 | 316 | |
|
4695
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
317 | ops = gaim_get_blist_ui_ops(); |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
318 | |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
319 | if (ops != NULL && ops->new_node != NULL) |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
320 | ops->new_node((GaimBlistNode *)g); |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
321 | |
| 4687 | 322 | } |
| 2382 | 323 | return g; |
| 324 | } | |
| 325 | ||
| 4687 | 326 | void gaim_blist_add_group (struct group *group, GaimBlistNode *node) |
| 2382 | 327 | { |
| 4687 | 328 | struct gaim_blist_ui_ops *ops; |
| 5055 | 329 | GaimBlistNode *gnode = (GaimBlistNode*)group; |
| 4785 | 330 | gboolean save = FALSE; |
| 331 | ||
| 4687 | 332 | if (!gaimbuddylist) |
| 333 | gaimbuddylist = gaim_blist_new(); | |
| 334 | ops = gaimbuddylist->ui_ops; | |
| 4785 | 335 | |
| 4687 | 336 | if (!gaimbuddylist->root) { |
| 5055 | 337 | gaimbuddylist->root = gnode; |
| 4687 | 338 | return; |
| 339 | } | |
| 4785 | 340 | |
| 4941 | 341 | if (!node) |
| 342 | node = gaim_blist_get_last_sibling(gaimbuddylist->root); | |
| 343 | ||
| 4937 | 344 | /* if we're moving to overtop of ourselves, do nothing */ |
| 5055 | 345 | if(gnode == node) |
| 4937 | 346 | return; |
| 4785 | 347 | |
| 4781 | 348 | if (gaim_find_group(group->name)) { |
| 349 | /* This is just being moved */ | |
| 2382 | 350 | |
| 4781 | 351 | ops->remove(gaimbuddylist, (GaimBlistNode*)group); |
| 352 | ||
| 5055 | 353 | if(gnode == gaimbuddylist->root) |
| 354 | gaimbuddylist->root = gnode->next; | |
| 355 | if(gnode->prev) | |
| 356 | gnode->prev->next = gnode->next; | |
| 357 | if(gnode->next) | |
| 358 | gnode->next->prev = gnode->prev; | |
| 359 | ||
| 4781 | 360 | save = TRUE; |
| 361 | } | |
| 4785 | 362 | |
| 5055 | 363 | gnode->next = node->next; |
| 364 | gnode->prev = node; | |
| 365 | if(node->next) | |
| 366 | node->next->prev = gnode; | |
| 367 | node->next = gnode; | |
| 4687 | 368 | |
| 5055 | 369 | if (ops) { |
| 370 | ops->update(gaimbuddylist, gnode); | |
| 371 | for(node = gnode->child; node; node = node->next) | |
| 372 | ops->update(gaimbuddylist, node); | |
| 373 | } | |
| 4785 | 374 | if (save) |
| 4781 | 375 | gaim_blist_save(); |
| 4687 | 376 | } |
| 377 | ||
| 378 | void gaim_blist_remove_buddy (struct buddy *buddy) | |
| 379 | { | |
| 380 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 381 | ||
| 4721 | 382 | GaimBlistNode *gnode, *node = (GaimBlistNode*)buddy; |
| 383 | struct group *group; | |
| 384 | ||
| 385 | gnode = node->parent; | |
| 386 | group = (struct group *)gnode; | |
| 387 | ||
| 388 | if(gnode->child == node) | |
| 389 | gnode->child = node->next; | |
| 4687 | 390 | if (node->prev) |
| 391 | node->prev->next = node->next; | |
| 392 | if (node->next) | |
| 393 | node->next->prev = node->prev; | |
| 4721 | 394 | |
| 4687 | 395 | ops->remove(gaimbuddylist, node); |
| 4954 | 396 | g_hash_table_destroy(buddy->settings); |
| 4687 | 397 | g_free(buddy->name); |
| 398 | g_free(buddy->alias); | |
| 399 | g_free(buddy); | |
| 2382 | 400 | } |
| 401 | ||
| 4687 | 402 | void gaim_blist_remove_group (struct group *group) |
| 4349 | 403 | { |
| 4687 | 404 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; |
| 405 | GaimBlistNode *node = (GaimBlistNode*)group; | |
| 4938 | 406 | |
| 407 | if(node->child) { | |
| 408 | char *buf; | |
| 409 | int count = 0; | |
| 410 | GaimBlistNode *child = node->child; | |
| 411 | ||
| 412 | while(child) { | |
| 413 | count++; | |
| 414 | child = child->next; | |
| 415 | } | |
| 416 | ||
| 417 | buf = g_strdup_printf(_("%d buddies from group %s were not " | |
| 418 | "removed because their accounts were not logged in. These " | |
| 419 | "buddies, and the group were not removed.\n"), | |
| 420 | count, group->name); | |
| 421 | do_error_dialog(_("Group Not Removed"), buf, GAIM_ERROR); | |
| 422 | g_free(buf); | |
| 423 | return; | |
| 4687 | 424 | } |
| 4936 | 425 | |
| 5056 | 426 | if(gaimbuddylist->root == node) |
| 427 | gaimbuddylist->root = node->next; | |
| 4936 | 428 | if (node->prev) |
| 429 | node->prev->next = node->next; | |
| 430 | if (node->next) | |
| 431 | node->next->prev = node->prev; | |
| 432 | ||
| 4687 | 433 | ops->remove(gaimbuddylist, node); |
| 434 | g_free(group->name); | |
| 435 | g_free(group); | |
| 436 | } | |
| 4349 | 437 | |
| 4687 | 438 | char *gaim_get_buddy_alias_only(struct buddy *b) { |
| 439 | if(!b) | |
| 440 | return NULL; | |
| 441 | if(b->alias && b->alias[0]) | |
| 442 | return b->alias; | |
| 443 | else if((misc_options & OPT_MISC_USE_SERVER_ALIAS) && b->server_alias) | |
| 444 | return b->server_alias; | |
| 445 | return NULL; | |
| 446 | } | |
| 447 | ||
| 448 | char * gaim_get_buddy_alias (struct buddy *buddy) | |
| 449 | { | |
| 450 | char *ret = gaim_get_buddy_alias_only(buddy); | |
| 451 | if(!ret) | |
| 452 | return buddy ? buddy->name : _("Unknown"); | |
| 453 | return ret; | |
| 454 | ||
| 455 | } | |
| 456 | ||
| 457 | struct buddy *gaim_find_buddy(struct gaim_account *account, const char *name) | |
| 458 | { | |
| 4757 | 459 | GaimBlistNode *group; |
| 4687 | 460 | GaimBlistNode *buddy; |
| 4757 | 461 | char *norm_name = g_strdup(normalize(name)); |
| 462 | ||
| 4687 | 463 | if (!gaimbuddylist) |
| 464 | return NULL; | |
| 4757 | 465 | |
| 466 | group = gaimbuddylist->root; | |
| 4687 | 467 | while (group) { |
| 468 | buddy = group->child; | |
| 469 | while (buddy) { | |
| 4793 | 470 | if (!gaim_utf8_strcasecmp(normalize(((struct buddy*)buddy)->name), norm_name) && account == ((struct buddy*)buddy)->account) { |
| 4757 | 471 | g_free(norm_name); |
| 4687 | 472 | return (struct buddy*)buddy; |
| 4757 | 473 | } |
| 4687 | 474 | buddy = buddy->next; |
| 475 | } | |
| 476 | group = group->next; | |
| 4349 | 477 | } |
| 4757 | 478 | g_free(norm_name); |
| 4349 | 479 | return NULL; |
| 480 | } | |
| 481 | ||
| 4687 | 482 | struct group *gaim_find_group(const char *name) |
| 2382 | 483 | { |
| 4687 | 484 | GaimBlistNode *node; |
| 485 | if (!gaimbuddylist) | |
| 486 | return NULL; | |
| 487 | node = gaimbuddylist->root; | |
| 488 | while(node) { | |
| 489 | if (!strcmp(((struct group*)node)->name, name)) | |
| 490 | return (struct group*)node; | |
| 491 | node = node->next; | |
| 2382 | 492 | } |
| 4349 | 493 | return NULL; |
| 2382 | 494 | } |
| 4687 | 495 | struct group *gaim_find_buddys_group(struct buddy *buddy) |
| 496 | { | |
|
4830
d0f1945b27b7
[gaim-migrate @ 5155]
Mark Doliner <markdoliner@pidgin.im>
parents:
4793
diff
changeset
|
497 | if (!buddy) |
|
d0f1945b27b7
[gaim-migrate @ 5155]
Mark Doliner <markdoliner@pidgin.im>
parents:
4793
diff
changeset
|
498 | return NULL; |
| 4687 | 499 | return (struct group*)(((GaimBlistNode*)buddy)->parent); |
| 500 | } | |
| 501 | ||
| 502 | GSList *gaim_group_get_accounts(struct group *g) | |
| 503 | { | |
| 504 | GSList *l = NULL; | |
| 505 | GaimBlistNode *child = ((GaimBlistNode *)g)->child; | |
| 506 | ||
| 507 | while (child) { | |
| 508 | if (!g_slist_find(l, ((struct buddy*)child)->account)) | |
| 509 | l = g_slist_append(l, ((struct buddy*)child)->account); | |
| 510 | child = child->next; | |
| 511 | } | |
| 512 | return l; | |
| 513 | } | |
| 514 | ||
| 515 | void gaim_blist_remove_account(struct gaim_account *account) | |
| 516 | { | |
| 517 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 518 | GaimBlistNode *group = gaimbuddylist->root; | |
| 519 | GaimBlistNode *buddy; | |
| 520 | if (!gaimbuddylist) | |
| 521 | return; | |
| 522 | while (group) { | |
| 523 | buddy = group->child; | |
| 524 | while (buddy) { | |
| 525 | if (account == ((struct buddy*)buddy)->account) { | |
| 5068 | 526 | ((struct buddy*)buddy)->present = GAIM_BUDDY_OFFLINE; |
| 4919 | 527 | if(ops) |
| 528 | ops->remove(gaimbuddylist, buddy); | |
| 4687 | 529 | } |
| 530 | buddy = buddy->next; | |
| 531 | } | |
| 532 | group = group->next; | |
| 533 | } | |
| 534 | } | |
| 2382 | 535 | |
| 4491 | 536 | void parse_toc_buddy_list(struct gaim_account *account, char *config) |
| 2382 | 537 | { |
| 538 | char *c; | |
| 539 | char current[256]; | |
| 4351 | 540 | GList *bud = NULL; |
| 4349 | 541 | |
| 2382 | 542 | |
| 543 | if (config != NULL) { | |
| 4349 | 544 | |
| 2382 | 545 | /* skip "CONFIG:" (if it exists) */ |
| 546 | c = strncmp(config + 6 /* sizeof(struct sflap_hdr) */ , "CONFIG:", strlen("CONFIG:")) ? | |
| 2998 | 547 | strtok(config, "\n") : |
| 548 | strtok(config + 6 /* sizeof(struct sflap_hdr) */ + strlen("CONFIG:"), "\n"); | |
| 2382 | 549 | do { |
| 550 | if (c == NULL) | |
| 551 | break; | |
| 552 | if (*c == 'g') { | |
| 4404 | 553 | char *utf8 = NULL; |
| 4458 | 554 | utf8 = gaim_try_conv_to_utf8(c + 2); |
| 4404 | 555 | if (utf8 == NULL) { |
| 556 | g_strlcpy(current, _("Invalid Groupname"), sizeof(current)); | |
| 557 | } else { | |
| 558 | g_strlcpy(current, utf8, sizeof(current)); | |
| 559 | g_free(utf8); | |
| 560 | } | |
| 4687 | 561 | if (!gaim_find_group(current)) { |
| 562 | struct group *g = gaim_group_new(current); | |
| 563 | gaim_blist_add_group(g, NULL); | |
|
2526
4efae93c7ed6
[gaim-migrate @ 2539]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2382
diff
changeset
|
564 | } |
| 4687 | 565 | } else if (*c == 'b') { /*&& !gaim_find_buddy(user, c + 2)) {*/ |
| 566 | char nm[80], sw[388], *a, *utf8 = NULL; | |
| 4408 | 567 | |
| 4404 | 568 | if ((a = strchr(c + 2, ':')) != NULL) { |
| 569 | *a++ = '\0'; /* nul the : */ | |
| 570 | } | |
| 4349 | 571 | |
| 4404 | 572 | g_strlcpy(nm, c + 2, sizeof(nm)); |
| 573 | if (a) { | |
| 4458 | 574 | utf8 = gaim_try_conv_to_utf8(a); |
| 4404 | 575 | if (utf8 == NULL) { |
| 576 | debug_printf ("Failed to convert alias for '%s' to UTF-8\n", nm); | |
| 577 | } | |
| 578 | } | |
| 579 | if (utf8 == NULL) { | |
| 580 | sw[0] = '\0'; | |
| 581 | } else { | |
| 4491 | 582 | /* This can leave a partial sequence at the end, |
| 4404 | 583 | * but who cares? */ |
| 584 | g_strlcpy(sw, utf8, sizeof(sw)); | |
| 585 | g_free(utf8); | |
| 586 | } | |
| 4491 | 587 | |
| 4687 | 588 | if (!gaim_find_buddy(account, nm)) { |
| 589 | struct buddy *b = gaim_buddy_new(account, nm, sw); | |
| 590 | struct group *g = gaim_find_group(current); | |
| 591 | gaim_blist_add_buddy(b, g, NULL); | |
|
4950
9f396a2285bf
[gaim-migrate @ 5284]
Herman Bloggs <herman@bluedigits.com>
parents:
4942
diff
changeset
|
592 | bud = g_list_append(bud, g_strdup(nm)); |
|
2526
4efae93c7ed6
[gaim-migrate @ 2539]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2382
diff
changeset
|
593 | } |
| 2382 | 594 | } else if (*c == 'p') { |
| 4491 | 595 | gaim_privacy_permit_add(account, c + 2); |
| 2382 | 596 | } else if (*c == 'd') { |
| 4491 | 597 | gaim_privacy_deny_add(account, c + 2); |
| 2382 | 598 | } else if (!strncmp("toc", c, 3)) { |
| 4491 | 599 | sscanf(c + strlen(c) - 1, "%d", &account->permdeny); |
| 600 | debug_printf("permdeny: %d\n", account->permdeny); | |
| 601 | if (account->permdeny == 0) | |
| 602 | account->permdeny = 1; | |
| 2382 | 603 | } else if (*c == 'm') { |
| 4491 | 604 | sscanf(c + 2, "%d", &account->permdeny); |
| 605 | debug_printf("permdeny: %d\n", account->permdeny); | |
| 606 | if (account->permdeny == 0) | |
| 607 | account->permdeny = 1; | |
| 2382 | 608 | } |
| 609 | } while ((c = strtok(NULL, "\n"))); | |
| 4351 | 610 | |
| 4491 | 611 | if(account->gc) { |
|
4950
9f396a2285bf
[gaim-migrate @ 5284]
Herman Bloggs <herman@bluedigits.com>
parents:
4942
diff
changeset
|
612 | if(bud) { |
|
9f396a2285bf
[gaim-migrate @ 5284]
Herman Bloggs <herman@bluedigits.com>
parents:
4942
diff
changeset
|
613 | GList *node = bud; |
| 4491 | 614 | serv_add_buddies(account->gc, bud); |
|
4950
9f396a2285bf
[gaim-migrate @ 5284]
Herman Bloggs <herman@bluedigits.com>
parents:
4942
diff
changeset
|
615 | while(node) { |
|
9f396a2285bf
[gaim-migrate @ 5284]
Herman Bloggs <herman@bluedigits.com>
parents:
4942
diff
changeset
|
616 | g_free(node->data); |
|
9f396a2285bf
[gaim-migrate @ 5284]
Herman Bloggs <herman@bluedigits.com>
parents:
4942
diff
changeset
|
617 | node = node->next; |
|
9f396a2285bf
[gaim-migrate @ 5284]
Herman Bloggs <herman@bluedigits.com>
parents:
4942
diff
changeset
|
618 | } |
|
9f396a2285bf
[gaim-migrate @ 5284]
Herman Bloggs <herman@bluedigits.com>
parents:
4942
diff
changeset
|
619 | } |
| 4491 | 620 | serv_set_permit_deny(account->gc); |
| 4351 | 621 | } |
| 622 | g_list_free(bud); | |
| 2382 | 623 | } |
| 624 | } | |
| 625 | ||
| 4687 | 626 | #if 0 |
|
2536
84dd244c1b98
[gaim-migrate @ 2549]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2526
diff
changeset
|
627 | /* translate an AIM 3 buddylist (*.lst) to a Gaim buddylist */ |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
628 | static GString *translate_lst(FILE *src_fp) |
| 2382 | 629 | { |
| 630 | char line[BUF_LEN], *line2; | |
| 631 | char *name; | |
| 632 | int i; | |
| 633 | ||
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
634 | GString *dest = g_string_new("m 1\n"); |
| 2382 | 635 | |
| 636 | while (fgets(line, BUF_LEN, src_fp)) { | |
|
2548
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
637 | line2 = g_strchug(line); |
| 2382 | 638 | if (strstr(line2, "group") == line2) { |
| 639 | name = strpbrk(line2, " \t\n\r\f") + 1; | |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
640 | dest = g_string_append(dest, "g "); |
| 2382 | 641 | for (i = 0; i < strcspn(name, "\n\r"); i++) |
| 642 | if (name[i] != '\"') | |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
643 | dest = g_string_append_c(dest, name[i]); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
644 | dest = g_string_append_c(dest, '\n'); |
| 2382 | 645 | } |
| 646 | if (strstr(line2, "buddy") == line2) { | |
| 647 | name = strpbrk(line2, " \t\n\r\f") + 1; | |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
648 | dest = g_string_append(dest, "b "); |
| 2382 | 649 | for (i = 0; i < strcspn(name, "\n\r"); i++) |
| 650 | if (name[i] != '\"') | |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
651 | dest = g_string_append_c(dest, name[i]); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
652 | dest = g_string_append_c(dest, '\n'); |
| 2382 | 653 | } |
| 654 | } | |
| 655 | ||
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
656 | return dest; |
| 2382 | 657 | } |
| 658 | ||
| 659 | ||
|
2536
84dd244c1b98
[gaim-migrate @ 2549]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2526
diff
changeset
|
660 | /* translate an AIM 4 buddylist (*.blt) to Gaim format */ |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
661 | static GString *translate_blt(FILE *src_fp) |
| 2382 | 662 | { |
| 663 | int i; | |
| 664 | char line[BUF_LEN]; | |
| 665 | char *buddy; | |
| 666 | ||
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
667 | GString *dest = g_string_new("m 1\n"); |
| 2382 | 668 | |
| 669 | while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL); | |
| 670 | while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL); | |
| 671 | ||
| 672 | while (1) { | |
|
2548
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
673 | fgets(line, BUF_LEN, src_fp); g_strchomp(line); |
| 2382 | 674 | if (strchr(line, '}') != NULL) |
| 675 | break; | |
| 676 | ||
| 677 | if (strchr(line, '{') != NULL) { | |
|
2548
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
678 | /* Syntax starting with "<group> {" */ |
|
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
679 | |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
680 | dest = g_string_append(dest, "g "); |
|
2548
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
681 | buddy = g_strchug(strtok(line, "{")); |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
682 | for (i = 0; i < strlen(buddy); i++) |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
683 | if (buddy[i] != '\"') |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
684 | dest = g_string_append_c(dest, buddy[i]); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
685 | dest = g_string_append_c(dest, '\n'); |
| 2382 | 686 | while (strchr(fgets(line, BUF_LEN, src_fp), '}') == NULL) { |
|
2548
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
687 | gboolean pounce = FALSE; |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
688 | char *e; |
|
2548
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
689 | g_strchomp(line); |
|
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
690 | buddy = g_strchug(line); |
|
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
691 | debug_printf("\nbuddy: \"%s\"\n\n", buddy); |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
692 | dest = g_string_append(dest, "b "); |
|
2548
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
693 | if (strchr(buddy, '{') != NULL) { |
|
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
694 | /* buddy pounce, etc */ |
|
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
695 | char *pos = strchr(buddy, '{') - 1; |
|
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
696 | *pos = 0; |
|
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
697 | pounce = TRUE; |
|
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
698 | } |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
699 | if ((e = strchr(buddy, '\"')) != NULL) { |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
700 | *e = '\0'; |
| 2382 | 701 | buddy++; |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
702 | } |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
703 | dest = g_string_append(dest, buddy); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
704 | dest = g_string_append_c(dest, '\n'); |
|
2548
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
705 | if (pounce) |
|
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
706 | do |
|
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
707 | fgets(line, BUF_LEN, src_fp); |
|
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
708 | while (!strchr(line, '}')); |
| 2382 | 709 | } |
|
2548
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
710 | } else { |
|
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
711 | |
|
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
712 | /* Syntax "group buddy buddy ..." */ |
|
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
713 | buddy = g_strchug(strtok(line, " \n")); |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
714 | dest = g_string_append(dest, "g "); |
| 2382 | 715 | if (strchr(buddy, '\"') != NULL) { |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
716 | dest = g_string_append(dest, &buddy[1]); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
717 | dest = g_string_append_c(dest, ' '); |
|
2548
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
718 | buddy = g_strchug(strtok(NULL, " \n")); |
| 2382 | 719 | while (strchr(buddy, '\"') == NULL) { |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
720 | dest = g_string_append(dest, buddy); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
721 | dest = g_string_append_c(dest, ' '); |
|
2548
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
722 | buddy = g_strchug(strtok(NULL, " \n")); |
| 2382 | 723 | } |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
724 | buddy[strlen(buddy) - 1] = '\0'; |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
725 | dest = g_string_append(dest, buddy); |
| 2382 | 726 | } else { |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
727 | dest = g_string_append(dest, buddy); |
| 2382 | 728 | } |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
729 | dest = g_string_append_c(dest, '\n'); |
|
2548
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
730 | while ((buddy = g_strchug(strtok(NULL, " \n"))) != NULL) { |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
731 | dest = g_string_append(dest, "b "); |
| 2382 | 732 | if (strchr(buddy, '\"') != NULL) { |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
733 | dest = g_string_append(dest, &buddy[1]); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
734 | dest = g_string_append_c(dest, ' '); |
|
2548
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
735 | buddy = g_strchug(strtok(NULL, " \n")); |
| 2382 | 736 | while (strchr(buddy, '\"') == NULL) { |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
737 | dest = g_string_append(dest, buddy); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
738 | dest = g_string_append_c(dest, ' '); |
|
2548
1ad1da32caf8
[gaim-migrate @ 2561]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2536
diff
changeset
|
739 | buddy = g_strchug(strtok(NULL, " \n")); |
| 2382 | 740 | } |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
741 | buddy[strlen(buddy) - 1] = '\0'; |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
742 | dest = g_string_append(dest, buddy); |
| 2382 | 743 | } else { |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
744 | dest = g_string_append(dest, buddy); |
| 2382 | 745 | } |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
746 | dest = g_string_append_c(dest, '\n'); |
| 2382 | 747 | } |
| 748 | } | |
| 749 | } | |
| 750 | ||
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
751 | return dest; |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
752 | } |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
753 | |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
754 | static GString *translate_gnomeicu(FILE *src_fp) |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
755 | { |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
756 | char line[BUF_LEN]; |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
757 | GString *dest = g_string_new("m 1\ng Buddies\n"); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
758 | |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
759 | while (strstr(fgets(line, BUF_LEN, src_fp), "NewContacts") == NULL); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
760 | |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
761 | while (fgets(line, BUF_LEN, src_fp)) { |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
762 | char *eq; |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
763 | g_strchomp(line); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
764 | if (line[0] == '\n' || line[0] == '[') |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
765 | break; |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
766 | eq = strchr(line, '='); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
767 | if (!eq) |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
768 | break; |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
769 | *eq = ':'; |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
770 | eq = strchr(eq, ','); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
771 | if (eq) |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
772 | *eq = '\0'; |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
773 | dest = g_string_append(dest, "b "); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
774 | dest = g_string_append(dest, line); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
775 | dest = g_string_append_c(dest, '\n'); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
776 | } |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
777 | |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
778 | return dest; |
| 2382 | 779 | } |
| 4687 | 780 | #endif |
| 2382 | 781 | |
| 782 | static gchar *get_screenname_filename(const char *name) | |
| 783 | { | |
| 784 | gchar **split; | |
| 785 | gchar *good; | |
| 4793 | 786 | gchar *ret; |
| 2382 | 787 | |
| 788 | split = g_strsplit(name, G_DIR_SEPARATOR_S, -1); | |
| 789 | good = g_strjoinv(NULL, split); | |
| 790 | g_strfreev(split); | |
| 791 | ||
| 4793 | 792 | ret = g_utf8_strup(good, -1); |
| 2382 | 793 | |
| 4793 | 794 | g_free(good); |
| 795 | ||
| 796 | return ret; | |
| 2382 | 797 | } |
| 798 | ||
| 4349 | 799 | static gboolean gaim_blist_read(const char *filename); |
| 2382 | 800 | |
| 4687 | 801 | |
| 802 | static void do_import(struct gaim_account *account, const char *filename) | |
| 2382 | 803 | { |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
804 | GString *buf = NULL; |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
805 | char first[64]; |
| 2382 | 806 | char path[PATHSIZE]; |
| 807 | int len; | |
| 808 | FILE *f; | |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
809 | struct stat st; |
| 2382 | 810 | |
| 811 | if (filename) { | |
| 812 | g_snprintf(path, sizeof(path), "%s", filename); | |
| 813 | } else { | |
| 4491 | 814 | char *g_screenname = get_screenname_filename(account->username); |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
815 | char *file = gaim_user_dir(); |
| 4491 | 816 | int protocol = (account->protocol == PROTO_OSCAR) ? (isalpha(account->username[0]) ? PROTO_TOC : PROTO_ICQ): account->protocol; |
| 2382 | 817 | |
| 818 | if (file != (char *)NULL) { | |
| 4349 | 819 | sprintf(path, "%s" G_DIR_SEPARATOR_S "%s.%d.blist", file, g_screenname, protocol); |
| 2382 | 820 | g_free(g_screenname); |
| 821 | } else { | |
| 822 | g_free(g_screenname); | |
| 823 | return; | |
| 824 | } | |
| 825 | } | |
| 826 | ||
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
827 | if (stat(path, &st)) { |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
828 | debug_printf("Unable to stat %s.\n", path); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
829 | return; |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
830 | } |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
831 | |
| 2382 | 832 | if (!(f = fopen(path, "r"))) { |
| 833 | debug_printf("Unable to open %s.\n", path); | |
| 834 | return; | |
| 835 | } | |
| 836 | ||
| 837 | fgets(first, 64, f); | |
| 838 | ||
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
839 | if ((first[0] == '\n') || (first[0] == '\r' && first[1] == '\n')) |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
840 | fgets(first, 64, f); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
841 | |
| 4687 | 842 | #if 0 |
| 4349 | 843 | if (!g_strncasecmp(first, "<xml", strlen("<xml"))) { |
| 844 | /* new gaim XML buddy list */ | |
| 845 | gaim_blist_read(path); | |
| 4687 | 846 | |
| 847 | /* We really don't need to bother doing stuf like translating AIM 3 buddy lists anymore */ | |
| 848 | ||
| 4349 | 849 | } else if (!g_strncasecmp(first, "Config {", strlen("Config {"))) { |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
850 | /* AIM 4 buddy list */ |
| 2382 | 851 | debug_printf("aim 4\n"); |
| 852 | rewind(f); | |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
853 | buf = translate_blt(f); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
854 | } else if (strstr(first, "group") != NULL) { |
| 2382 | 855 | /* AIM 3 buddy list */ |
| 856 | debug_printf("aim 3\n"); | |
| 857 | rewind(f); | |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
858 | buf = translate_lst(f); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
859 | } else if (!g_strncasecmp(first, "[User]", strlen("[User]"))) { |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
860 | /* GnomeICU (hopefully) */ |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
861 | debug_printf("gnomeicu\n"); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
862 | rewind(f); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
863 | buf = translate_gnomeicu(f); |
| 4687 | 864 | |
| 865 | } else | |
| 866 | #endif | |
| 867 | if (first[0] == 'm') { | |
| 868 | /* Gaim buddy list - no translation */ | |
| 869 | char buf2[BUF_LONG * 2]; | |
| 870 | buf = g_string_new(""); | |
| 871 | rewind(f); | |
| 872 | while (1) { | |
| 873 | len = fread(buf2, 1, BUF_LONG * 2 - 1, f); | |
| 874 | if (len <= 0) | |
| 875 | break; | |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
876 | buf2[len] = '\0'; |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
877 | buf = g_string_append(buf, buf2); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
878 | if (len != BUF_LONG * 2 - 1) |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
879 | break; |
| 4687 | 880 | } |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
881 | } |
| 4687 | 882 | |
| 2382 | 883 | fclose(f); |
| 884 | ||
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
885 | if (buf) { |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
886 | buf = g_string_prepend(buf, "toc_set_config {"); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
887 | buf = g_string_append(buf, "}\n"); |
| 4491 | 888 | parse_toc_buddy_list(account, buf->str); |
|
2825
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
889 | g_string_free(buf, TRUE); |
|
73063a92cab1
[gaim-migrate @ 2838]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2681
diff
changeset
|
890 | } |
| 2382 | 891 | } |
| 892 | ||
| 4491 | 893 | gboolean gaim_group_on_account(struct group *g, struct gaim_account *account) { |
| 4785 | 894 | GaimBlistNode *bnode; |
| 895 | for(bnode = g->node.child; bnode; bnode = bnode->next) { | |
| 896 | struct buddy *b = (struct buddy *)bnode; | |
| 897 | if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
| 898 | continue; | |
| 4491 | 899 | if((!account && b->account->gc) || b->account == account) |
| 4349 | 900 | return TRUE; |
| 901 | } | |
| 902 | return FALSE; | |
| 903 | } | |
| 904 | ||
| 4497 | 905 | static gboolean blist_safe_to_write = FALSE; |
| 4349 | 906 | |
| 907 | static char *blist_parser_group_name = NULL; | |
| 908 | static char *blist_parser_person_name = NULL; | |
| 909 | static char *blist_parser_account_name = NULL; | |
| 910 | static int blist_parser_account_protocol = 0; | |
| 911 | static char *blist_parser_buddy_name = NULL; | |
| 912 | static char *blist_parser_buddy_alias = NULL; | |
| 913 | static char *blist_parser_setting_name = NULL; | |
| 914 | static char *blist_parser_setting_value = NULL; | |
| 915 | static GHashTable *blist_parser_buddy_settings = NULL; | |
| 5142 | 916 | static GHashTable *blist_parser_group_settings = NULL; |
| 4349 | 917 | static int blist_parser_privacy_mode = 0; |
| 5142 | 918 | static GList *tag_stack = NULL; |
| 919 | enum { | |
| 4349 | 920 | BLIST_TAG_GAIM, |
| 921 | BLIST_TAG_BLIST, | |
| 922 | BLIST_TAG_GROUP, | |
| 923 | BLIST_TAG_PERSON, | |
| 924 | BLIST_TAG_BUDDY, | |
| 925 | BLIST_TAG_NAME, | |
| 926 | BLIST_TAG_ALIAS, | |
| 927 | BLIST_TAG_SETTING, | |
| 928 | BLIST_TAG_PRIVACY, | |
| 929 | BLIST_TAG_ACCOUNT, | |
| 930 | BLIST_TAG_PERMIT, | |
| 931 | BLIST_TAG_BLOCK, | |
| 932 | BLIST_TAG_IGNORE | |
| 5142 | 933 | }; |
| 4439 | 934 | static gboolean blist_parser_error_occurred = FALSE; |
| 4349 | 935 | |
| 936 | static void blist_start_element_handler (GMarkupParseContext *context, | |
| 937 | const gchar *element_name, | |
| 938 | const gchar **attribute_names, | |
| 939 | const gchar **attribute_values, | |
| 940 | gpointer user_data, | |
| 941 | GError **error) { | |
| 942 | int i; | |
| 943 | ||
| 944 | if(!strcmp(element_name, "gaim")) { | |
| 5142 | 945 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_GAIM)); |
| 4349 | 946 | } else if(!strcmp(element_name, "blist")) { |
| 5142 | 947 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BLIST)); |
| 4349 | 948 | } else if(!strcmp(element_name, "group")) { |
| 5142 | 949 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_GROUP)); |
| 4349 | 950 | for(i=0; attribute_names[i]; i++) { |
| 4444 | 951 | if(!strcmp(attribute_names[i], "name")) { |
| 952 | g_free(blist_parser_group_name); | |
| 4349 | 953 | blist_parser_group_name = g_strdup(attribute_values[i]); |
| 4444 | 954 | } |
| 4349 | 955 | } |
| 956 | if(blist_parser_group_name) { | |
| 4687 | 957 | struct group *g = gaim_group_new(blist_parser_group_name); |
| 958 | gaim_blist_add_group(g,NULL); | |
| 4349 | 959 | } |
| 960 | } else if(!strcmp(element_name, "person")) { | |
| 5142 | 961 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PERSON)); |
| 4349 | 962 | for(i=0; attribute_names[i]; i++) { |
| 4444 | 963 | if(!strcmp(attribute_names[i], "name")) { |
| 964 | g_free(blist_parser_person_name); | |
| 4349 | 965 | blist_parser_person_name = g_strdup(attribute_values[i]); |
| 4444 | 966 | } |
| 4349 | 967 | } |
| 968 | } else if(!strcmp(element_name, "buddy")) { | |
| 5142 | 969 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BUDDY)); |
| 4349 | 970 | for(i=0; attribute_names[i]; i++) { |
| 4444 | 971 | if(!strcmp(attribute_names[i], "account")) { |
| 972 | g_free(blist_parser_account_name); | |
| 4349 | 973 | blist_parser_account_name = g_strdup(attribute_values[i]); |
| 4444 | 974 | } else if(!strcmp(attribute_names[i], "protocol")) { |
| 4349 | 975 | blist_parser_account_protocol = atoi(attribute_values[i]); |
| 4444 | 976 | } |
| 4349 | 977 | } |
| 978 | } else if(!strcmp(element_name, "name")) { | |
| 5142 | 979 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_NAME)); |
| 4349 | 980 | } else if(!strcmp(element_name, "alias")) { |
| 5142 | 981 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_ALIAS)); |
| 4349 | 982 | } else if(!strcmp(element_name, "setting")) { |
| 5142 | 983 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_SETTING)); |
| 4349 | 984 | for(i=0; attribute_names[i]; i++) { |
| 4444 | 985 | if(!strcmp(attribute_names[i], "name")) { |
| 986 | g_free(blist_parser_setting_name); | |
| 4349 | 987 | blist_parser_setting_name = g_strdup(attribute_values[i]); |
| 4444 | 988 | } |
| 4349 | 989 | } |
| 990 | } else if(!strcmp(element_name, "privacy")) { | |
| 5142 | 991 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PRIVACY)); |
| 4349 | 992 | } else if(!strcmp(element_name, "account")) { |
| 5142 | 993 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_ACCOUNT)); |
| 4349 | 994 | for(i=0; attribute_names[i]; i++) { |
| 995 | if(!strcmp(attribute_names[i], "protocol")) | |
| 996 | blist_parser_account_protocol = atoi(attribute_values[i]); | |
| 997 | else if(!strcmp(attribute_names[i], "mode")) | |
| 998 | blist_parser_privacy_mode = atoi(attribute_values[i]); | |
| 4444 | 999 | else if(!strcmp(attribute_names[i], "name")) { |
| 1000 | g_free(blist_parser_account_name); | |
| 4349 | 1001 | blist_parser_account_name = g_strdup(attribute_values[i]); |
| 4444 | 1002 | } |
| 4349 | 1003 | } |
| 1004 | } else if(!strcmp(element_name, "permit")) { | |
| 5142 | 1005 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PERMIT)); |
| 4349 | 1006 | } else if(!strcmp(element_name, "block")) { |
| 5142 | 1007 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BLOCK)); |
| 4349 | 1008 | } else if(!strcmp(element_name, "ignore")) { |
| 5142 | 1009 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_IGNORE)); |
| 4349 | 1010 | } |
| 1011 | } | |
| 1012 | ||
| 1013 | static void blist_end_element_handler(GMarkupParseContext *context, | |
| 1014 | const gchar *element_name, gpointer user_data, GError **error) { | |
| 1015 | if(!strcmp(element_name, "gaim")) { | |
| 5142 | 1016 | tag_stack = g_list_delete_link(tag_stack, tag_stack); |
| 4349 | 1017 | } else if(!strcmp(element_name, "blist")) { |
| 5142 | 1018 | tag_stack = g_list_delete_link(tag_stack, tag_stack); |
| 4349 | 1019 | } else if(!strcmp(element_name, "group")) { |
| 5142 | 1020 | if(blist_parser_group_settings) { |
| 1021 | struct group *g = gaim_find_group(blist_parser_group_name); | |
| 1022 | g_hash_table_destroy(g->settings); | |
| 1023 | g->settings = blist_parser_group_settings; | |
| 1024 | } | |
| 1025 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1026 | blist_parser_group_settings = NULL; | |
| 4349 | 1027 | } else if(!strcmp(element_name, "person")) { |
| 1028 | g_free(blist_parser_person_name); | |
| 1029 | blist_parser_person_name = NULL; | |
| 5142 | 1030 | tag_stack = g_list_delete_link(tag_stack, tag_stack); |
| 4349 | 1031 | } else if(!strcmp(element_name, "buddy")) { |
| 4491 | 1032 | struct gaim_account *account = gaim_account_find(blist_parser_account_name, |
| 4349 | 1033 | blist_parser_account_protocol); |
| 4491 | 1034 | if(account) { |
| 4687 | 1035 | struct buddy *b = gaim_buddy_new(account, blist_parser_buddy_name, blist_parser_buddy_alias); |
| 1036 | struct group *g = gaim_find_group(blist_parser_group_name); | |
| 1037 | gaim_blist_add_buddy(b,g,NULL); | |
| 4349 | 1038 | if(blist_parser_buddy_settings) { |
| 1039 | g_hash_table_destroy(b->settings); | |
| 1040 | b->settings = blist_parser_buddy_settings; | |
| 1041 | } | |
| 1042 | } | |
| 1043 | g_free(blist_parser_buddy_name); | |
| 1044 | blist_parser_buddy_name = NULL; | |
| 1045 | g_free(blist_parser_buddy_alias); | |
| 1046 | blist_parser_buddy_alias = NULL; | |
| 1047 | g_free(blist_parser_account_name); | |
| 1048 | blist_parser_account_name = NULL; | |
| 1049 | blist_parser_buddy_settings = NULL; | |
| 5142 | 1050 | tag_stack = g_list_delete_link(tag_stack, tag_stack); |
| 4349 | 1051 | } else if(!strcmp(element_name, "name")) { |
| 5142 | 1052 | tag_stack = g_list_delete_link(tag_stack, tag_stack); |
| 4349 | 1053 | } else if(!strcmp(element_name, "alias")) { |
| 5142 | 1054 | tag_stack = g_list_delete_link(tag_stack, tag_stack); |
| 4349 | 1055 | } else if(!strcmp(element_name, "setting")) { |
| 5142 | 1056 | if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_BUDDY) { |
| 1057 | if(!blist_parser_buddy_settings) | |
| 1058 | blist_parser_buddy_settings = g_hash_table_new_full(g_str_hash, | |
| 1059 | g_str_equal, g_free, g_free); | |
| 1060 | if(blist_parser_setting_name && blist_parser_setting_value) { | |
| 1061 | g_hash_table_replace(blist_parser_buddy_settings, | |
| 1062 | g_strdup(blist_parser_setting_name), | |
| 1063 | g_strdup(blist_parser_setting_value)); | |
| 1064 | } | |
| 1065 | } else if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_GROUP) { | |
| 1066 | if(!blist_parser_group_settings) | |
| 1067 | blist_parser_group_settings = g_hash_table_new_full(g_str_hash, | |
| 1068 | g_str_equal, g_free, g_free); | |
| 1069 | if(blist_parser_setting_name && blist_parser_setting_value) { | |
| 1070 | g_hash_table_replace(blist_parser_group_settings, | |
| 1071 | g_strdup(blist_parser_setting_name), | |
| 1072 | g_strdup(blist_parser_setting_value)); | |
| 1073 | } | |
| 4349 | 1074 | } |
| 1075 | g_free(blist_parser_setting_name); | |
| 1076 | g_free(blist_parser_setting_value); | |
| 4720 | 1077 | blist_parser_setting_name = NULL; |
| 1078 | blist_parser_setting_value = NULL; | |
| 5142 | 1079 | tag_stack = g_list_delete_link(tag_stack, tag_stack); |
| 4349 | 1080 | } else if(!strcmp(element_name, "privacy")) { |
| 5142 | 1081 | tag_stack = g_list_delete_link(tag_stack, tag_stack); |
| 4349 | 1082 | } else if(!strcmp(element_name, "account")) { |
| 4491 | 1083 | struct gaim_account *account = gaim_account_find(blist_parser_account_name, |
| 4349 | 1084 | blist_parser_account_protocol); |
| 4491 | 1085 | if(account) { |
| 1086 | account->permdeny = blist_parser_privacy_mode; | |
| 4349 | 1087 | } |
| 1088 | g_free(blist_parser_account_name); | |
| 1089 | blist_parser_account_name = NULL; | |
| 5142 | 1090 | tag_stack = g_list_delete_link(tag_stack, tag_stack); |
| 4349 | 1091 | } else if(!strcmp(element_name, "permit")) { |
| 4491 | 1092 | struct gaim_account *account = gaim_account_find(blist_parser_account_name, |
| 4349 | 1093 | blist_parser_account_protocol); |
| 4491 | 1094 | if(account) { |
| 1095 | gaim_privacy_permit_add(account, blist_parser_buddy_name); | |
| 4349 | 1096 | } |
| 4442 | 1097 | g_free(blist_parser_buddy_name); |
| 4444 | 1098 | blist_parser_buddy_name = NULL; |
| 5142 | 1099 | tag_stack = g_list_delete_link(tag_stack, tag_stack); |
| 4349 | 1100 | } else if(!strcmp(element_name, "block")) { |
| 4491 | 1101 | struct gaim_account *account = gaim_account_find(blist_parser_account_name, |
| 4349 | 1102 | blist_parser_account_protocol); |
| 4491 | 1103 | if(account) { |
| 1104 | gaim_privacy_deny_add(account, blist_parser_buddy_name); | |
| 4349 | 1105 | } |
| 4442 | 1106 | g_free(blist_parser_buddy_name); |
| 4444 | 1107 | blist_parser_buddy_name = NULL; |
| 5142 | 1108 | tag_stack = g_list_delete_link(tag_stack, tag_stack); |
| 4349 | 1109 | } else if(!strcmp(element_name, "ignore")) { |
| 1110 | /* we'll apparently do something with this later */ | |
| 5142 | 1111 | tag_stack = g_list_delete_link(tag_stack, tag_stack); |
| 4349 | 1112 | } |
| 1113 | } | |
| 1114 | ||
| 1115 | static void blist_text_handler(GMarkupParseContext *context, const gchar *text, | |
| 1116 | gsize text_len, gpointer user_data, GError **error) { | |
| 5142 | 1117 | switch(GPOINTER_TO_INT(tag_stack->data)) { |
| 4349 | 1118 | case BLIST_TAG_NAME: |
| 1119 | blist_parser_buddy_name = g_strndup(text, text_len); | |
| 1120 | break; | |
| 1121 | case BLIST_TAG_ALIAS: | |
| 1122 | blist_parser_buddy_alias = g_strndup(text, text_len); | |
| 1123 | break; | |
| 1124 | case BLIST_TAG_PERMIT: | |
| 1125 | case BLIST_TAG_BLOCK: | |
| 1126 | case BLIST_TAG_IGNORE: | |
| 1127 | blist_parser_buddy_name = g_strndup(text, text_len); | |
| 1128 | break; | |
| 1129 | case BLIST_TAG_SETTING: | |
| 1130 | blist_parser_setting_value = g_strndup(text, text_len); | |
| 1131 | break; | |
| 1132 | default: | |
| 1133 | break; | |
| 1134 | } | |
| 1135 | } | |
| 1136 | ||
| 4439 | 1137 | static void blist_error_handler(GMarkupParseContext *context, GError *error, |
| 1138 | gpointer user_data) { | |
| 1139 | blist_parser_error_occurred = TRUE; | |
| 1140 | debug_printf("error parsing blist.xml: %s\n", error->message); | |
| 1141 | } | |
| 1142 | ||
| 4349 | 1143 | static GMarkupParser blist_parser = { |
| 1144 | blist_start_element_handler, | |
| 1145 | blist_end_element_handler, | |
| 1146 | blist_text_handler, | |
| 1147 | NULL, | |
| 4439 | 1148 | blist_error_handler |
| 4349 | 1149 | }; |
| 1150 | ||
| 1151 | static gboolean gaim_blist_read(const char *filename) { | |
| 4441 | 1152 | gchar *contents = NULL; |
| 4349 | 1153 | gsize length; |
| 1154 | GMarkupParseContext *context; | |
| 1155 | GError *error = NULL; | |
| 4496 | 1156 | |
| 1157 | debug_printf("gaim_blist_read: reading %s\n", filename); | |
| 4349 | 1158 | if(!g_file_get_contents(filename, &contents, &length, &error)) { |
| 1159 | debug_printf("error reading blist: %s\n", error->message); | |
| 1160 | g_error_free(error); | |
| 1161 | return FALSE; | |
| 1162 | } | |
| 1163 | ||
| 1164 | context = g_markup_parse_context_new(&blist_parser, 0, NULL, NULL); | |
| 1165 | ||
| 1166 | if(!g_markup_parse_context_parse(context, contents, length, NULL)) { | |
| 1167 | g_markup_parse_context_free(context); | |
| 4441 | 1168 | g_free(contents); |
| 4349 | 1169 | return FALSE; |
| 1170 | } | |
| 1171 | ||
| 1172 | if(!g_markup_parse_context_end_parse(context, NULL)) { | |
| 1173 | debug_printf("error parsing blist\n"); | |
| 1174 | g_markup_parse_context_free(context); | |
| 4441 | 1175 | g_free(contents); |
| 4349 | 1176 | return FALSE; |
| 1177 | } | |
| 1178 | ||
| 1179 | g_markup_parse_context_free(context); | |
| 4441 | 1180 | g_free(contents); |
| 1181 | ||
| 4439 | 1182 | if(blist_parser_error_occurred) |
| 1183 | return FALSE; | |
| 1184 | ||
| 4496 | 1185 | debug_printf("gaim_blist_read: finished reading %s\n", filename); |
| 1186 | ||
| 4349 | 1187 | return TRUE; |
| 1188 | } | |
| 1189 | ||
| 1190 | void gaim_blist_load() { | |
| 1191 | GSList *accts; | |
| 1192 | char *user_dir = gaim_user_dir(); | |
| 1193 | char *filename; | |
| 1194 | char *msg; | |
| 1195 | ||
| 4497 | 1196 | blist_safe_to_write = TRUE; |
| 1197 | ||
| 1198 | if(!user_dir) | |
| 4349 | 1199 | return; |
| 1200 | ||
| 1201 | filename = g_build_filename(user_dir, "blist.xml", NULL); | |
| 1202 | ||
| 1203 | if(g_file_test(filename, G_FILE_TEST_EXISTS)) { | |
| 1204 | if(!gaim_blist_read(filename)) { | |
| 1205 | msg = g_strdup_printf(_("An error was encountered parsing your " | |
| 1206 | "buddy list. It has not been loaded.")); | |
| 1207 | do_error_dialog(_("Buddy List Error"), msg, GAIM_ERROR); | |
| 1208 | g_free(msg); | |
| 1209 | } | |
| 4491 | 1210 | } else if(g_slist_length(gaim_accounts)) { |
| 4349 | 1211 | /* rob wants to inform the user that their buddy lists are |
| 1212 | * being converted */ | |
| 1213 | msg = g_strdup_printf(_("Gaim is converting your old buddy lists " | |
| 1214 | "to a new format, which will now be located at %s"), | |
| 1215 | filename); | |
| 1216 | do_error_dialog(_("Converting Buddy List"), msg, GAIM_INFO); | |
| 1217 | g_free(msg); | |
| 1218 | ||
| 1219 | /* now, let gtk actually display the dialog before we start anything */ | |
| 1220 | while(gtk_events_pending()) | |
| 1221 | gtk_main_iteration(); | |
| 1222 | ||
| 1223 | /* read in the old lists, then save to the new format */ | |
| 4491 | 1224 | for(accts = gaim_accounts; accts; accts = accts->next) { |
| 4349 | 1225 | do_import(accts->data, NULL); |
| 1226 | } | |
| 1227 | gaim_blist_save(); | |
| 1228 | } | |
| 1229 | ||
| 1230 | g_free(filename); | |
| 1231 | } | |
| 1232 | ||
| 5142 | 1233 | static void blist_print_group_settings(gpointer key, gpointer data, |
| 1234 | gpointer user_data) { | |
| 1235 | char *key_val; | |
| 1236 | char *data_val; | |
| 1237 | FILE *file = user_data; | |
| 1238 | ||
| 1239 | if(!key || !data) | |
| 1240 | return; | |
| 1241 | ||
| 1242 | key_val = g_markup_escape_text(key, -1); | |
| 1243 | data_val = g_markup_escape_text(data, -1); | |
| 1244 | ||
| 1245 | fprintf(file, "\t\t\t<setting name=\"%s\">%s</setting>\n", key_val, | |
| 1246 | data_val); | |
| 1247 | g_free(key_val); | |
| 1248 | g_free(data_val); | |
| 1249 | } | |
| 1250 | ||
| 4349 | 1251 | static void blist_print_buddy_settings(gpointer key, gpointer data, |
| 1252 | gpointer user_data) { | |
| 5125 | 1253 | char *key_val; |
| 1254 | char *data_val; | |
| 4349 | 1255 | FILE *file = user_data; |
| 5125 | 1256 | |
| 1257 | if(!key || !data) | |
| 1258 | return; | |
| 1259 | ||
| 1260 | key_val = g_markup_escape_text(key, -1); | |
| 1261 | data_val = g_markup_escape_text(data, -1); | |
| 1262 | ||
| 4349 | 1263 | fprintf(file, "\t\t\t\t\t<setting name=\"%s\">%s</setting>\n", key_val, |
| 1264 | data_val); | |
| 1265 | g_free(key_val); | |
| 1266 | g_free(data_val); | |
| 1267 | } | |
| 1268 | ||
| 4491 | 1269 | static void gaim_blist_write(FILE *file, struct gaim_account *exp_acct) { |
| 4687 | 1270 | GSList *accounts, *buds; |
| 4785 | 1271 | GaimBlistNode *gnode,*bnode; |
| 4687 | 1272 | struct group *group; |
| 1273 | struct buddy *bud; | |
| 4349 | 1274 | fprintf(file, "<?xml version='1.0' encoding='UTF-8' ?>\n"); |
| 1275 | fprintf(file, "<gaim version=\"1\">\n"); | |
| 1276 | fprintf(file, "\t<blist>\n"); | |
| 1277 | ||
| 4785 | 1278 | for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { |
| 1279 | if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
| 1280 | continue; | |
| 1281 | group = (struct group *)gnode; | |
| 4687 | 1282 | if(!exp_acct || gaim_group_on_account(group, exp_acct)) { |
| 1283 | char *group_name = g_markup_escape_text(group->name, -1); | |
| 4349 | 1284 | fprintf(file, "\t\t<group name=\"%s\">\n", group_name); |
| 5142 | 1285 | g_hash_table_foreach(group->settings, blist_print_group_settings, file); |
| 4785 | 1286 | for(bnode = gnode->child; bnode; bnode = bnode->next) { |
| 1287 | if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
| 1288 | continue; | |
| 1289 | bud = (struct buddy *)bnode; | |
| 4687 | 1290 | if(!exp_acct || bud->account == exp_acct) { |
| 1291 | char *bud_name = g_markup_escape_text(bud->name, -1); | |
| 4349 | 1292 | char *bud_alias = NULL; |
| 4687 | 1293 | char *acct_name = g_markup_escape_text(bud->account->username, -1); |
| 1294 | if(bud->alias) | |
| 1295 | bud_alias= g_markup_escape_text(bud->alias, -1); | |
| 4349 | 1296 | fprintf(file, "\t\t\t<person name=\"%s\">\n", |
| 1297 | bud_alias ? bud_alias : bud_name); | |
| 1298 | fprintf(file, "\t\t\t\t<buddy protocol=\"%d\" " | |
| 4687 | 1299 | "account=\"%s\">\n", bud->account->protocol, |
| 4349 | 1300 | acct_name); |
| 1301 | fprintf(file, "\t\t\t\t\t<name>%s</name>\n", bud_name); | |
| 1302 | if(bud_alias) { | |
| 1303 | fprintf(file, "\t\t\t\t\t<alias>%s</alias>\n", | |
| 1304 | bud_alias); | |
| 1305 | } | |
| 4687 | 1306 | g_hash_table_foreach(bud->settings, |
| 4349 | 1307 | blist_print_buddy_settings, file); |
| 1308 | fprintf(file, "\t\t\t\t</buddy>\n"); | |
| 1309 | fprintf(file, "\t\t\t</person>\n"); | |
| 1310 | g_free(bud_name); | |
| 1311 | g_free(bud_alias); | |
| 1312 | g_free(acct_name); | |
| 1313 | } | |
| 1314 | } | |
| 1315 | fprintf(file, "\t\t</group>\n"); | |
| 1316 | g_free(group_name); | |
| 1317 | } | |
| 1318 | } | |
| 1319 | ||
| 1320 | fprintf(file, "\t</blist>\n"); | |
| 1321 | fprintf(file, "\t<privacy>\n"); | |
| 1322 | ||
| 4491 | 1323 | for(accounts = gaim_accounts; accounts; accounts = accounts->next) { |
| 1324 | struct gaim_account *account = accounts->data; | |
| 1325 | char *acct_name = g_markup_escape_text(account->username, -1); | |
| 1326 | if(!exp_acct || account == exp_acct) { | |
| 4349 | 1327 | fprintf(file, "\t\t<account protocol=\"%d\" name=\"%s\" " |
| 4491 | 1328 | "mode=\"%d\">\n", account->protocol, acct_name, account->permdeny); |
| 1329 | for(buds = account->permit; buds; buds = buds->next) { | |
| 4349 | 1330 | char *bud_name = g_markup_escape_text(buds->data, -1); |
| 1331 | fprintf(file, "\t\t\t<permit>%s</permit>\n", bud_name); | |
| 1332 | g_free(bud_name); | |
| 1333 | } | |
| 4491 | 1334 | for(buds = account->deny; buds; buds = buds->next) { |
| 4349 | 1335 | char *bud_name = g_markup_escape_text(buds->data, -1); |
| 1336 | fprintf(file, "\t\t\t<block>%s</block>\n", bud_name); | |
| 1337 | g_free(bud_name); | |
| 1338 | } | |
| 1339 | fprintf(file, "\t\t</account>\n"); | |
| 1340 | } | |
| 4491 | 1341 | g_free(acct_name); |
| 4349 | 1342 | } |
| 1343 | ||
| 1344 | fprintf(file, "\t</privacy>\n"); | |
| 1345 | fprintf(file, "</gaim>\n"); | |
| 1346 | } | |
| 1347 | ||
| 1348 | void gaim_blist_save() { | |
| 1349 | FILE *file; | |
| 1350 | char *user_dir = gaim_user_dir(); | |
| 1351 | char *filename; | |
| 4891 | 1352 | char *filename_real; |
| 4349 | 1353 | |
| 1354 | if(!user_dir) | |
| 1355 | return; | |
| 4497 | 1356 | if(!blist_safe_to_write) { |
| 1357 | debug_printf("AHH!! tried to write the blist before we read it!\n"); | |
| 1358 | return; | |
| 1359 | } | |
| 1360 | ||
| 4349 | 1361 | file = fopen(user_dir, "r"); |
| 1362 | if(!file) | |
| 1363 | mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 1364 | else | |
| 1365 | fclose(file); | |
| 1366 | ||
| 4891 | 1367 | filename = g_build_filename(user_dir, "blist.xml.save", NULL); |
| 4349 | 1368 | |
| 1369 | if((file = fopen(filename, "w"))) { | |
| 1370 | gaim_blist_write(file, NULL); | |
| 1371 | fclose(file); | |
| 1372 | chmod(filename, S_IRUSR | S_IWUSR); | |
| 1373 | } else { | |
| 1374 | debug_printf("unable to write %s\n", filename); | |
| 1375 | } | |
| 1376 | ||
| 4891 | 1377 | filename_real = g_build_filename(user_dir, "blist.xml", NULL); |
| 1378 | ||
| 1379 | if(rename(filename, filename_real) < 0) | |
| 1380 | debug_printf("error renaming %s to %s\n", filename, filename_real); | |
| 1381 | ||
| 1382 | ||
| 4349 | 1383 | g_free(filename); |
| 4891 | 1384 | g_free(filename_real); |
| 4349 | 1385 | } |
| 1386 | ||
| 4491 | 1387 | gboolean gaim_privacy_permit_add(struct gaim_account *account, const char *who) { |
| 1388 | GSList *d = account->permit; | |
| 4349 | 1389 | char *n = g_strdup(normalize(who)); |
| 1390 | while(d) { | |
| 4793 | 1391 | if(!gaim_utf8_strcasecmp(n, normalize(d->data))) |
| 4349 | 1392 | break; |
| 1393 | d = d->next; | |
| 1394 | } | |
| 1395 | g_free(n); | |
| 1396 | if(!d) { | |
| 4491 | 1397 | account->permit = g_slist_append(account->permit, g_strdup(who)); |
| 4349 | 1398 | return TRUE; |
| 1399 | } | |
| 1400 | ||
| 1401 | return FALSE; | |
| 1402 | } | |
| 1403 | ||
| 4491 | 1404 | gboolean gaim_privacy_permit_remove(struct gaim_account *account, const char *who) { |
| 1405 | GSList *d = account->permit; | |
| 4349 | 1406 | char *n = g_strdup(normalize(who)); |
| 1407 | while(d) { | |
| 4793 | 1408 | if(!gaim_utf8_strcasecmp(n, normalize(d->data))) |
| 4349 | 1409 | break; |
| 1410 | d = d->next; | |
| 1411 | } | |
| 1412 | g_free(n); | |
| 1413 | if(d) { | |
| 4491 | 1414 | account->permit = g_slist_remove(account->permit, d->data); |
| 4349 | 1415 | g_free(d->data); |
| 1416 | return TRUE; | |
| 1417 | } | |
| 1418 | return FALSE; | |
| 1419 | } | |
| 1420 | ||
| 4491 | 1421 | gboolean gaim_privacy_deny_add(struct gaim_account *account, const char *who) { |
| 1422 | GSList *d = account->deny; | |
| 4349 | 1423 | char *n = g_strdup(normalize(who)); |
| 1424 | while(d) { | |
| 4793 | 1425 | if(!gaim_utf8_strcasecmp(n, normalize(d->data))) |
| 4349 | 1426 | break; |
| 1427 | d = d->next; | |
| 1428 | } | |
| 1429 | g_free(n); | |
| 1430 | if(!d) { | |
| 4491 | 1431 | account->deny = g_slist_append(account->deny, g_strdup(who)); |
| 4349 | 1432 | return TRUE; |
| 1433 | } | |
| 1434 | ||
| 1435 | return FALSE; | |
| 1436 | } | |
| 1437 | ||
| 4491 | 1438 | gboolean gaim_privacy_deny_remove(struct gaim_account *account, const char *who) { |
| 1439 | GSList *d = account->deny; | |
| 4349 | 1440 | char *n = g_strdup(normalize(who)); |
| 1441 | while(d) { | |
| 4793 | 1442 | if(!gaim_utf8_strcasecmp(n, normalize(d->data))) |
| 4349 | 1443 | break; |
| 1444 | d = d->next; | |
| 1445 | } | |
| 1446 | g_free(n); | |
| 1447 | if(d) { | |
| 4491 | 1448 | account->deny = g_slist_remove(account->deny, d->data); |
| 4349 | 1449 | g_free(d->data); |
| 1450 | return TRUE; | |
| 1451 | } | |
| 1452 | return FALSE; | |
| 1453 | } | |
| 1454 | ||
| 5142 | 1455 | void gaim_group_set_setting(struct group *g, const char *key, |
| 1456 | const char *value) { | |
| 1457 | if(!g) | |
| 1458 | return; | |
| 1459 | g_hash_table_replace(g->settings, g_strdup(key), g_strdup(value)); | |
| 1460 | } | |
| 1461 | ||
| 1462 | char *gaim_group_get_setting(struct group *g, const char *key) { | |
| 1463 | if(!g) | |
| 1464 | return NULL; | |
| 1465 | return g_strdup(g_hash_table_lookup(g->settings, key)); | |
| 1466 | } | |
| 1467 | ||
| 4349 | 1468 | void gaim_buddy_set_setting(struct buddy *b, const char *key, |
| 1469 | const char *value) { | |
| 1470 | if(!b) | |
| 1471 | return; | |
| 1472 | g_hash_table_replace(b->settings, g_strdup(key), g_strdup(value)); | |
| 1473 | } | |
| 1474 | ||
| 1475 | char *gaim_buddy_get_setting(struct buddy *b, const char *key) { | |
| 1476 | if(!b) | |
| 1477 | return NULL; | |
| 1478 | return g_strdup(g_hash_table_lookup(b->settings, key)); | |
| 1479 | } | |
| 4687 | 1480 | |
| 1481 | void gaim_set_blist_ui_ops(struct gaim_blist_ui_ops *ops) | |
| 1482 | { | |
|
4695
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1483 | blist_ui_ops = ops; |
| 4687 | 1484 | } |
|
4695
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1485 | |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1486 | struct gaim_blist_ui_ops * |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1487 | gaim_get_blist_ui_ops(void) |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1488 | { |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1489 | return blist_ui_ops; |
|
82df59fb9931
[gaim-migrate @ 5006]
Christian Hammond <chipx86@chipx86.com>
parents:
4690
diff
changeset
|
1490 | } |
| 4701 | 1491 | |
| 1492 | int gaim_blist_get_group_size(struct group *group, gboolean offline) { | |
| 1493 | GaimBlistNode *node; | |
| 1494 | int count = 0; | |
| 1495 | ||
| 1496 | if(!group) | |
| 1497 | return 0; | |
| 1498 | ||
| 1499 | for(node = group->node.child; node; node = node->next) { | |
| 1500 | if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
| 1501 | struct buddy *b = (struct buddy *)node; | |
| 1502 | if(b->account->gc || offline) | |
| 1503 | count++; | |
| 1504 | } | |
| 1505 | } | |
| 1506 | ||
| 1507 | return count; | |
| 1508 | } | |
| 1509 | ||
| 1510 | int gaim_blist_get_group_online_count(struct group *group) { | |
| 1511 | GaimBlistNode *node; | |
| 1512 | int count = 0; | |
| 1513 | ||
| 1514 | if(!group) | |
| 1515 | return 0; | |
| 1516 | ||
| 1517 | for(node = group->node.child; node; node = node->next) { | |
| 1518 | if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
| 1519 | struct buddy *b = (struct buddy *)node; | |
| 5068 | 1520 | if(GAIM_BUDDY_IS_ONLINE(b)) |
| 4701 | 1521 | count++; |
| 1522 | } | |
| 1523 | } | |
| 1524 | ||
| 1525 | return count; | |
| 1526 | } | |
| 1527 | ||
| 1528 |