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