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