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