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