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