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