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