Mercurial > pidgin
annotate src/blist.c @ 6302:511003c99302
[gaim-migrate @ 6801]
Notify plugin.
It seems to work pretty well for me. One thing I did notice, it doesn't
really handle getting IMs from different people very well. It makes a
different counter in title of the IM for each person, and then only
updates the most recently added one.
I also didn't try chat stuff at all, but I need to go to sleep pretty soon.
Pretty much all of the changes were done by Brian Tarricon, I just renamed
a few things and did a few other patent-pending actions.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 25 Jul 2003 04:30:52 +0000 |
parents | 9083f92e0d58 |
children | 55588b222901 |
rev | line source |
---|---|
5228 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 2003, Sean Egan <sean.egan@binghamton.edu> | |
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 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
22 #include "internal.h" |
5228 | 23 #include "blist.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
24 #include "conversation.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
25 #include "debug.h" |
6034 | 26 #include "multi.h" |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
27 #include "notify.h" |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
28 #include "prefs.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
29 #include "privacy.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
30 #include "prpl.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
31 #include "server.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
32 #include "util.h" |
5228 | 33 |
34 #define PATHSIZE 1024 | |
35 | |
36 struct gaim_buddy_list *gaimbuddylist = NULL; | |
37 static struct gaim_blist_ui_ops *blist_ui_ops = NULL; | |
38 | |
39 /***************************************************************************** | |
40 * Private Utility functions * | |
41 *****************************************************************************/ | |
42 static GaimBlistNode *gaim_blist_get_last_sibling(GaimBlistNode *node) | |
43 { | |
44 GaimBlistNode *n = node; | |
45 if (!n) | |
46 return NULL; | |
47 while (n->next) | |
48 n = n->next; | |
49 return n; | |
50 } | |
51 static GaimBlistNode *gaim_blist_get_last_child(GaimBlistNode *node) | |
52 { | |
53 if (!node) | |
54 return NULL; | |
55 return gaim_blist_get_last_sibling(node->child); | |
56 } | |
57 | |
5247 | 58 struct _gaim_hbuddy { |
59 char *name; | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
60 GaimAccount *account; |
5758 | 61 GaimBlistNode *group; |
5247 | 62 }; |
63 | |
64 static guint _gaim_blist_hbuddy_hash (struct _gaim_hbuddy *hb) | |
65 { | |
66 return g_str_hash(hb->name); | |
67 } | |
68 | |
69 static guint _gaim_blist_hbuddy_equal (struct _gaim_hbuddy *hb1, struct _gaim_hbuddy *hb2) | |
70 { | |
5758 | 71 return ((!strcmp(hb1->name, hb2->name)) && hb1->account == hb2->account && hb1->group == hb2->group); |
5247 | 72 } |
73 | |
6006 | 74 static void blist_pref_cb(const char *name, GaimPrefType typ, gpointer value, gpointer data) |
75 { | |
6012 | 76 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; |
77 GaimBlistNode *group, *buddy; | |
78 | |
79 if (!ops) | |
80 return; | |
81 | |
82 for(group = gaimbuddylist->root; group; group = group->next) { | |
83 if(!GAIM_BLIST_NODE_IS_GROUP(group)) | |
84 continue; | |
85 for(buddy = group->child; buddy; buddy = buddy->next) { | |
86 if(!GAIM_BLIST_NODE_IS_BUDDY(buddy)) | |
87 continue; | |
88 ops->update(gaimbuddylist, buddy); | |
89 } | |
90 } | |
6006 | 91 } |
92 | |
5228 | 93 /***************************************************************************** |
94 * Public API functions * | |
95 *****************************************************************************/ | |
96 | |
97 struct gaim_buddy_list *gaim_blist_new() | |
98 { | |
99 struct gaim_buddy_list *gbl = g_new0(struct gaim_buddy_list, 1); | |
100 | |
101 gbl->ui_ops = gaim_get_blist_ui_ops(); | |
102 | |
5247 | 103 gbl->buddies = g_hash_table_new ((GHashFunc)_gaim_blist_hbuddy_hash, |
104 (GEqualFunc)_gaim_blist_hbuddy_equal); | |
105 | |
5228 | 106 if (gbl->ui_ops != NULL && gbl->ui_ops->new_list != NULL) |
107 gbl->ui_ops->new_list(gbl); | |
108 | |
6006 | 109 gaim_prefs_connect_callback("/core/buddies/use_server_alias", blist_pref_cb, NULL); |
110 | |
5228 | 111 return gbl; |
112 } | |
113 | |
114 void | |
115 gaim_set_blist(struct gaim_buddy_list *list) | |
116 { | |
117 gaimbuddylist = list; | |
118 } | |
119 | |
120 struct gaim_buddy_list * | |
121 gaim_get_blist(void) | |
122 { | |
123 return gaimbuddylist; | |
124 } | |
125 | |
126 void gaim_blist_show () | |
127 { | |
128 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
129 if (ops) | |
130 ops->show(gaimbuddylist); | |
131 } | |
132 | |
133 void gaim_blist_destroy() | |
134 { | |
135 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
136 if (ops) | |
137 ops->destroy(gaimbuddylist); | |
138 } | |
139 | |
140 void gaim_blist_set_visible (gboolean show) | |
141 { | |
142 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
143 if (ops) | |
144 ops->set_visible(gaimbuddylist, show); | |
145 } | |
146 | |
147 void gaim_blist_update_buddy_status (struct buddy *buddy, int status) | |
148 { | |
5266
b3a03b86b09b
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
149 struct gaim_blist_ui_ops *ops; |
b3a03b86b09b
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
150 |
b3a03b86b09b
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
151 if (buddy->uc == status) |
b3a03b86b09b
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
152 return; |
b3a03b86b09b
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
153 |
b3a03b86b09b
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
154 ops = gaimbuddylist->ui_ops; |
5228 | 155 |
5305 | 156 if((status & UC_UNAVAILABLE) != (buddy->uc & UC_UNAVAILABLE)) { |
157 if(status & UC_UNAVAILABLE) | |
158 gaim_event_broadcast(event_buddy_away, buddy->account->gc, buddy->name); | |
159 else | |
160 gaim_event_broadcast(event_buddy_back, buddy->account->gc, buddy->name); | |
161 } | |
5228 | 162 |
5305 | 163 buddy->uc = status; |
5228 | 164 if (ops) |
165 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
166 } | |
167 | |
168 static gboolean presence_update_timeout_cb(struct buddy *buddy) { | |
169 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
170 | |
171 if(buddy->present == GAIM_BUDDY_SIGNING_ON) { | |
172 buddy->present = GAIM_BUDDY_ONLINE; | |
173 } else if(buddy->present == GAIM_BUDDY_SIGNING_OFF) { | |
174 buddy->present = GAIM_BUDDY_OFFLINE; | |
175 } | |
176 | |
177 buddy->timer = 0; | |
178 | |
179 if (ops) | |
180 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
181 | |
182 return FALSE; | |
183 } | |
184 | |
185 void gaim_blist_update_buddy_presence(struct buddy *buddy, int presence) { | |
186 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
187 gboolean do_timer = FALSE; | |
188 | |
189 if (!GAIM_BUDDY_IS_ONLINE(buddy) && presence) { | |
190 buddy->present = GAIM_BUDDY_SIGNING_ON; | |
191 gaim_event_broadcast(event_buddy_signon, buddy->account->gc, buddy->name); | |
192 do_timer = TRUE; | |
5277 | 193 ((struct group *)((GaimBlistNode *)buddy)->parent)->online++; |
5228 | 194 } else if(GAIM_BUDDY_IS_ONLINE(buddy) && !presence) { |
195 buddy->present = GAIM_BUDDY_SIGNING_OFF; | |
196 gaim_event_broadcast(event_buddy_signoff, buddy->account->gc, buddy->name); | |
197 do_timer = TRUE; | |
5394 | 198 ((struct group *)((GaimBlistNode *)buddy)->parent)->online--; |
5228 | 199 } |
200 | |
201 if(do_timer) { | |
202 if(buddy->timer > 0) | |
203 g_source_remove(buddy->timer); | |
204 buddy->timer = g_timeout_add(10000, (GSourceFunc)presence_update_timeout_cb, buddy); | |
205 } | |
206 | |
207 if (ops) | |
208 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
209 } | |
210 | |
211 | |
212 void gaim_blist_update_buddy_idle (struct buddy *buddy, int idle) | |
213 { | |
214 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
215 buddy->idle = idle; | |
216 if (ops) | |
217 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
218 } | |
219 void gaim_blist_update_buddy_evil (struct buddy *buddy, int warning) | |
220 { | |
221 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
222 buddy->evil = warning; | |
223 if (ops) | |
224 ops->update(gaimbuddylist,(GaimBlistNode*)buddy); | |
225 } | |
226 void gaim_blist_update_buddy_icon(struct buddy *buddy) { | |
227 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
228 if(ops) | |
229 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
230 } | |
231 void gaim_blist_rename_buddy (struct buddy *buddy, const char *name) | |
232 { | |
233 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
5634 | 234 g_free(buddy->name); |
5228 | 235 buddy->name = g_strdup(name); |
236 if (ops) | |
237 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
238 } | |
5234 | 239 |
240 void gaim_blist_alias_chat(struct chat *chat, const char *alias) | |
241 { | |
242 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
243 | |
5237 | 244 g_free(chat->alias); |
5234 | 245 |
5237 | 246 if(alias && strlen(alias)) |
247 chat->alias = g_strdup(alias); | |
248 else | |
249 chat->alias = NULL; | |
250 | |
5234 | 251 if(ops) |
252 ops->update(gaimbuddylist, (GaimBlistNode*)chat); | |
253 } | |
254 | |
5228 | 255 void gaim_blist_alias_buddy (struct buddy *buddy, const char *alias) |
256 { | |
257 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5634
diff
changeset
|
258 GaimConversation *conv; |
5228 | 259 |
260 g_free(buddy->alias); | |
261 | |
262 if(alias && strlen(alias)) | |
263 buddy->alias = g_strdup(alias); | |
264 else | |
265 buddy->alias = NULL; | |
266 | |
267 if (ops) | |
268 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
269 | |
270 conv = gaim_find_conversation_with_account(buddy->name, buddy->account); | |
271 | |
272 if (conv) | |
273 gaim_conversation_autoset_title(conv); | |
274 } | |
275 | |
6058 | 276 void gaim_blist_server_alias_buddy (struct buddy *buddy, const char *alias) |
277 { | |
278 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
279 GaimConversation *conv; | |
280 | |
281 g_free(buddy->server_alias); | |
282 | |
283 if(alias && strlen(alias) && g_utf8_validate(alias, -1, NULL)) | |
284 buddy->server_alias = g_strdup(alias); | |
285 else | |
286 buddy->server_alias = NULL; | |
287 | |
288 if (ops) | |
289 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
290 | |
291 conv = gaim_find_conversation_with_account(buddy->name, buddy->account); | |
292 | |
293 if (conv) | |
294 gaim_conversation_autoset_title(conv); | |
295 } | |
296 | |
5228 | 297 void gaim_blist_rename_group(struct group *group, const char *name) |
298 { | |
299 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
5346 | 300 struct group *dest_group; |
301 GaimBlistNode *prev, *child, *next; | |
302 GSList *accts; | |
303 | |
304 if(!name || !strlen(name) || !strcmp(name, group->name)) { | |
305 /* nothing to do here */ | |
306 return; | |
307 } else if((dest_group = gaim_find_group(name))) { | |
308 /* here we're merging two groups */ | |
309 prev = gaim_blist_get_last_child((GaimBlistNode*)dest_group); | |
310 child = ((GaimBlistNode*)group)->child; | |
311 | |
312 while(child) | |
313 { | |
314 next = child->next; | |
315 if(GAIM_BLIST_NODE_IS_BUDDY(child)) { | |
316 gaim_blist_add_buddy((struct buddy *)child, dest_group, prev); | |
317 prev = child; | |
318 } else if(GAIM_BLIST_NODE_IS_CHAT(child)) { | |
319 gaim_blist_add_chat((struct chat *)child, dest_group, prev); | |
320 prev = child; | |
321 } else { | |
322 gaim_debug(GAIM_DEBUG_ERROR, "blist", | |
323 "Unknown child type in group %s\n", group->name); | |
324 } | |
325 child = next; | |
326 } | |
327 for (accts = gaim_group_get_accounts(group); accts; accts = g_slist_remove(accts, accts->data)) { | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
328 GaimAccount *account = accts->data; |
5346 | 329 serv_rename_group(account->gc, group, name); |
330 } | |
331 gaim_blist_remove_group(group); | |
332 } else { | |
333 /* a simple rename */ | |
334 for (accts = gaim_group_get_accounts(group); accts; accts = g_slist_remove(accts, accts->data)) { | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
335 GaimAccount *account = accts->data; |
5346 | 336 serv_rename_group(account->gc, group, name); |
337 } | |
338 g_free(group->name); | |
339 group->name = g_strdup(name); | |
340 if (ops) | |
341 ops->update(gaimbuddylist, (GaimBlistNode*)group); | |
342 } | |
5228 | 343 } |
5234 | 344 |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
345 struct chat *gaim_chat_new(GaimAccount *account, const char *alias, GHashTable *components) |
5234 | 346 { |
347 struct chat *chat; | |
348 struct gaim_blist_ui_ops *ops; | |
349 | |
5237 | 350 if(!components) |
5234 | 351 return NULL; |
352 | |
353 chat = g_new0(struct chat, 1); | |
354 chat->account = account; | |
5237 | 355 if(alias && strlen(alias)) |
356 chat->alias = g_strdup(alias); | |
5234 | 357 chat->components = components; |
5906 | 358 chat->settings = g_hash_table_new_full(g_str_hash, g_str_equal, |
359 g_free, g_free); | |
5234 | 360 |
361 ((GaimBlistNode*)chat)->type = GAIM_BLIST_CHAT_NODE; | |
362 | |
363 ops = gaim_get_blist_ui_ops(); | |
364 | |
365 if (ops != NULL && ops->new_node != NULL) | |
366 ops->new_node((GaimBlistNode *)chat); | |
367 | |
368 return chat; | |
369 } | |
370 | |
6036 | 371 char *gaim_chat_get_display_name(struct chat *chat) |
6034 | 372 { |
373 char *name; | |
374 | |
375 if(chat->alias){ | |
376 name = g_strdup(chat->alias); | |
377 } | |
378 else{ | |
379 GList *parts; | |
380 GaimPlugin *prpl; | |
381 GaimPluginProtocolInfo *prpl_info; | |
382 struct proto_chat_entry *pce; | |
383 | |
384 prpl = gaim_find_prpl(gaim_account_get_protocol(chat->account)); | |
385 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
386 | |
387 parts = prpl_info->chat_info(chat->account->gc); | |
388 | |
389 pce = parts->data; | |
390 name = g_markup_escape_text(g_hash_table_lookup(chat->components, | |
391 pce->identifier), -1); | |
392 g_list_free(parts); | |
393 } | |
394 | |
395 return name; | |
396 } | |
397 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
398 struct buddy *gaim_buddy_new(GaimAccount *account, const char *screenname, const char *alias) |
5228 | 399 { |
400 struct buddy *b; | |
401 struct gaim_blist_ui_ops *ops; | |
402 | |
403 b = g_new0(struct buddy, 1); | |
404 b->account = account; | |
405 b->name = g_strdup(screenname); | |
406 b->alias = g_strdup(alias); | |
407 b->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
408 ((GaimBlistNode*)b)->type = GAIM_BLIST_BUDDY_NODE; | |
409 | |
410 ops = gaim_get_blist_ui_ops(); | |
411 | |
412 if (ops != NULL && ops->new_node != NULL) | |
413 ops->new_node((GaimBlistNode *)b); | |
414 | |
415 return b; | |
416 } | |
5634 | 417 |
5234 | 418 void gaim_blist_add_chat(struct chat *chat, struct group *group, GaimBlistNode *node) |
419 { | |
420 GaimBlistNode *n = node, *cnode = (GaimBlistNode*)chat; | |
421 struct group *g = group; | |
422 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
423 gboolean save = FALSE; | |
424 | |
425 if (!n) { | |
426 if (!g) { | |
427 g = gaim_group_new(_("Chats")); | |
5634 | 428 gaim_blist_add_group(g, |
429 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
5234 | 430 } |
431 } else { | |
432 g = (struct group*)n->parent; | |
433 } | |
434 | |
435 /* if we're moving to overtop of ourselves, do nothing */ | |
436 if(cnode == n) | |
437 return; | |
438 | |
439 if (cnode->parent) { | |
440 /* This chat was already in the list and is | |
441 * being moved. | |
442 */ | |
5277 | 443 ((struct group *)cnode->parent)->totalsize--; |
5855 | 444 if (gaim_account_is_connected(chat->account)) { |
5287 | 445 ((struct group *)cnode->parent)->online--; |
5277 | 446 ((struct group *)cnode->parent)->currentsize--; |
5287 | 447 } |
5234 | 448 if(cnode->next) |
449 cnode->next->prev = cnode->prev; | |
450 if(cnode->prev) | |
451 cnode->prev->next = cnode->next; | |
452 if(cnode->parent->child == cnode) | |
453 cnode->parent->child = cnode->next; | |
454 | |
455 ops->remove(gaimbuddylist, cnode); | |
456 | |
457 save = TRUE; | |
458 } | |
459 | |
460 if (n) { | |
461 if(n->next) | |
462 n->next->prev = cnode; | |
463 cnode->next = n->next; | |
464 cnode->prev = n; | |
465 cnode->parent = n->parent; | |
466 n->next = cnode; | |
5277 | 467 ((struct group *)n->parent)->totalsize++; |
5855 | 468 if (gaim_account_is_connected(chat->account)) { |
5287 | 469 ((struct group *)n->parent)->online++; |
5277 | 470 ((struct group *)n->parent)->currentsize++; |
5287 | 471 } |
5234 | 472 } else { |
5634 | 473 if(((GaimBlistNode*)g)->child) |
474 ((GaimBlistNode*)g)->child->prev = cnode; | |
475 cnode->next = ((GaimBlistNode*)g)->child; | |
476 cnode->prev = NULL; | |
5234 | 477 ((GaimBlistNode*)g)->child = cnode; |
478 cnode->parent = (GaimBlistNode*)g; | |
5277 | 479 g->totalsize++; |
5855 | 480 if (gaim_account_is_connected(chat->account)) { |
5287 | 481 g->online++; |
5277 | 482 g->currentsize++; |
5287 | 483 } |
5234 | 484 } |
485 | |
486 if (ops) | |
487 ops->update(gaimbuddylist, (GaimBlistNode*)cnode); | |
488 if (save) | |
489 gaim_blist_save(); | |
490 } | |
491 | |
5228 | 492 void gaim_blist_add_buddy (struct buddy *buddy, struct group *group, GaimBlistNode *node) |
493 { | |
494 GaimBlistNode *n = node, *bnode = (GaimBlistNode*)buddy; | |
495 struct group *g = group; | |
496 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
5247 | 497 struct _gaim_hbuddy *hb; |
5228 | 498 gboolean save = FALSE; |
499 | |
500 if (!n) { | |
501 if (!g) { | |
502 g = gaim_group_new(_("Buddies")); | |
5634 | 503 gaim_blist_add_group(g, |
504 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
5228 | 505 } |
506 } else { | |
507 g = (struct group*)n->parent; | |
508 } | |
509 | |
510 /* if we're moving to overtop of ourselves, do nothing */ | |
511 if(bnode == n) | |
512 return; | |
513 | |
514 if (bnode->parent) { | |
515 /* This buddy was already in the list and is | |
516 * being moved. | |
517 */ | |
5394 | 518 ((struct group *)bnode->parent)->totalsize--; |
5855 | 519 if (gaim_account_is_connected(buddy->account)) |
5277 | 520 ((struct group *)bnode->parent)->currentsize--; |
5394 | 521 if (GAIM_BUDDY_IS_ONLINE(buddy)) |
5313 | 522 ((struct group *)bnode->parent)->online--; |
5277 | 523 |
5228 | 524 if(bnode->next) |
525 bnode->next->prev = bnode->prev; | |
526 if(bnode->prev) | |
527 bnode->prev->next = bnode->next; | |
528 if(bnode->parent->child == bnode) | |
529 bnode->parent->child = bnode->next; | |
530 | |
531 ops->remove(gaimbuddylist, bnode); | |
532 | |
5277 | 533 if (bnode->parent != ((GaimBlistNode*)g)) { |
5228 | 534 serv_move_buddy(buddy, (struct group*)bnode->parent, g); |
5277 | 535 } |
5228 | 536 save = TRUE; |
537 } | |
538 | |
539 if (n) { | |
540 if(n->next) | |
541 n->next->prev = (GaimBlistNode*)buddy; | |
542 ((GaimBlistNode*)buddy)->next = n->next; | |
543 ((GaimBlistNode*)buddy)->prev = n; | |
544 ((GaimBlistNode*)buddy)->parent = n->parent; | |
545 n->next = (GaimBlistNode*)buddy; | |
5277 | 546 ((struct group *)n->parent)->totalsize++; |
5855 | 547 if (gaim_account_is_connected(buddy->account)) |
5277 | 548 ((struct group *)n->parent)->currentsize++; |
5394 | 549 if (GAIM_BUDDY_IS_ONLINE(buddy)) |
5313 | 550 ((struct group *)n->parent)->online++; |
5228 | 551 } else { |
5634 | 552 if(((GaimBlistNode*)g)->child) |
553 ((GaimBlistNode*)g)->child->prev = (GaimBlistNode*)buddy; | |
554 ((GaimBlistNode*)buddy)->prev = NULL; | |
555 ((GaimBlistNode*)buddy)->next = ((GaimBlistNode*)g)->child; | |
5228 | 556 ((GaimBlistNode*)g)->child = (GaimBlistNode*)buddy; |
557 ((GaimBlistNode*)buddy)->parent = (GaimBlistNode*)g; | |
5277 | 558 g->totalsize++; |
5855 | 559 if (gaim_account_is_connected(buddy->account)) |
5277 | 560 g->currentsize++; |
5394 | 561 if (GAIM_BUDDY_IS_ONLINE(buddy)) |
5313 | 562 g->online++; |
5228 | 563 } |
564 | |
5247 | 565 hb = g_malloc(sizeof(struct _gaim_hbuddy)); |
566 hb->name = g_strdup(normalize(buddy->name)); | |
567 hb->account = buddy->account; | |
5758 | 568 hb->group = ((GaimBlistNode*)buddy)->parent; |
5247 | 569 |
570 if (g_hash_table_lookup(gaimbuddylist->buddies, (gpointer)hb)) { | |
571 /* This guy already exists */ | |
572 g_free(hb->name); | |
573 g_free(hb); | |
574 } else { | |
575 g_hash_table_insert(gaimbuddylist->buddies, (gpointer)hb, (gpointer)buddy); | |
576 } | |
577 | |
5228 | 578 if (ops) |
579 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
580 if (save) | |
581 gaim_blist_save(); | |
582 } | |
583 | |
584 struct group *gaim_group_new(const char *name) | |
585 { | |
586 struct group *g = gaim_find_group(name); | |
587 | |
588 if (!g) { | |
589 struct gaim_blist_ui_ops *ops; | |
590 g= g_new0(struct group, 1); | |
591 g->name = g_strdup(name); | |
5277 | 592 g->totalsize = 0; |
593 g->currentsize = 0; | |
594 g->online = 0; | |
5228 | 595 g->settings = g_hash_table_new_full(g_str_hash, g_str_equal, |
596 g_free, g_free); | |
597 ((GaimBlistNode*)g)->type = GAIM_BLIST_GROUP_NODE; | |
598 | |
599 ops = gaim_get_blist_ui_ops(); | |
600 | |
601 if (ops != NULL && ops->new_node != NULL) | |
602 ops->new_node((GaimBlistNode *)g); | |
603 | |
604 } | |
605 return g; | |
606 } | |
607 | |
608 void gaim_blist_add_group (struct group *group, GaimBlistNode *node) | |
609 { | |
610 struct gaim_blist_ui_ops *ops; | |
611 GaimBlistNode *gnode = (GaimBlistNode*)group; | |
612 gboolean save = FALSE; | |
613 | |
614 if (!gaimbuddylist) | |
615 gaimbuddylist = gaim_blist_new(); | |
616 ops = gaimbuddylist->ui_ops; | |
617 | |
618 if (!gaimbuddylist->root) { | |
619 gaimbuddylist->root = gnode; | |
620 return; | |
621 } | |
622 | |
623 /* if we're moving to overtop of ourselves, do nothing */ | |
624 if(gnode == node) | |
625 return; | |
626 | |
627 if (gaim_find_group(group->name)) { | |
628 /* This is just being moved */ | |
629 | |
630 ops->remove(gaimbuddylist, (GaimBlistNode*)group); | |
631 | |
632 if(gnode == gaimbuddylist->root) | |
633 gaimbuddylist->root = gnode->next; | |
634 if(gnode->prev) | |
635 gnode->prev->next = gnode->next; | |
636 if(gnode->next) | |
637 gnode->next->prev = gnode->prev; | |
638 | |
639 save = TRUE; | |
640 } | |
641 | |
5634 | 642 if (node) { |
643 gnode->next = node->next; | |
644 gnode->prev = node; | |
645 if(node->next) | |
646 node->next->prev = gnode; | |
647 node->next = gnode; | |
648 } else { | |
649 gaimbuddylist->root->prev = gnode; | |
650 gnode->next = gaimbuddylist->root; | |
651 gnode->prev = NULL; | |
652 gaimbuddylist->root = gnode; | |
653 } | |
654 | |
5228 | 655 |
656 if (ops) { | |
657 ops->update(gaimbuddylist, gnode); | |
658 for(node = gnode->child; node; node = node->next) | |
659 ops->update(gaimbuddylist, node); | |
660 } | |
661 if (save) | |
662 gaim_blist_save(); | |
663 } | |
664 | |
665 void gaim_blist_remove_buddy (struct buddy *buddy) | |
666 { | |
667 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
668 | |
669 GaimBlistNode *gnode, *node = (GaimBlistNode*)buddy; | |
670 struct group *group; | |
5247 | 671 struct _gaim_hbuddy hb, *key; |
672 struct buddy *val; | |
5228 | 673 |
674 gnode = node->parent; | |
675 group = (struct group *)gnode; | |
676 | |
677 if(gnode->child == node) | |
678 gnode->child = node->next; | |
679 if (node->prev) | |
680 node->prev->next = node->next; | |
681 if (node->next) | |
682 node->next->prev = node->prev; | |
5394 | 683 group->totalsize--; |
5855 | 684 if (gaim_account_is_connected(buddy->account)) |
5277 | 685 group->currentsize--; |
5394 | 686 if (GAIM_BUDDY_IS_ONLINE(buddy)) |
687 group->online--; | |
5228 | 688 |
5247 | 689 hb.name = normalize(buddy->name); |
690 hb.account = buddy->account; | |
5758 | 691 hb.group = ((GaimBlistNode*)buddy)->parent; |
5247 | 692 if (g_hash_table_lookup_extended(gaimbuddylist->buddies, &hb, (gpointer *)&key, (gpointer *)&val)) { |
693 g_hash_table_remove(gaimbuddylist->buddies, &hb); | |
694 g_free(key->name); | |
695 g_free(key); | |
696 } | |
697 | |
5292 | 698 if(buddy->timer > 0) |
699 g_source_remove(buddy->timer); | |
700 | |
5228 | 701 ops->remove(gaimbuddylist, node); |
702 g_hash_table_destroy(buddy->settings); | |
703 g_free(buddy->name); | |
704 g_free(buddy->alias); | |
705 g_free(buddy); | |
706 } | |
707 | |
5234 | 708 void gaim_blist_remove_chat (struct chat *chat) |
709 { | |
710 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
711 | |
712 GaimBlistNode *gnode, *node = (GaimBlistNode*)chat; | |
713 struct group *group; | |
714 | |
715 gnode = node->parent; | |
716 group = (struct group *)gnode; | |
717 | |
718 if(gnode->child == node) | |
719 gnode->child = node->next; | |
720 if (node->prev) | |
721 node->prev->next = node->next; | |
722 if (node->next) | |
723 node->next->prev = node->prev; | |
5277 | 724 group->totalsize--; |
5855 | 725 if (gaim_account_is_connected(chat->account)) { |
5277 | 726 group->currentsize--; |
5394 | 727 group->online--; |
728 } | |
5234 | 729 |
730 ops->remove(gaimbuddylist, node); | |
731 g_hash_table_destroy(chat->components); | |
732 g_free(chat->alias); | |
733 g_free(chat); | |
734 } | |
735 | |
5228 | 736 void gaim_blist_remove_group (struct group *group) |
737 { | |
738 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
739 GaimBlistNode *node = (GaimBlistNode*)group; | |
740 | |
741 if(node->child) { | |
742 char *buf; | |
743 int count = 0; | |
744 GaimBlistNode *child = node->child; | |
745 | |
746 while(child) { | |
747 count++; | |
748 child = child->next; | |
749 } | |
750 | |
751 buf = g_strdup_printf(_("%d buddies from group %s were not " | |
752 "removed because their accounts were not logged in. These " | |
5541
aee0ee458974
[gaim-migrate @ 5941]
Christian Hammond <chipx86@chipx86.com>
parents:
5436
diff
changeset
|
753 "buddies and the group were not removed.\n"), |
5228 | 754 count, group->name); |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
755 |
5541
aee0ee458974
[gaim-migrate @ 5941]
Christian Hammond <chipx86@chipx86.com>
parents:
5436
diff
changeset
|
756 gaim_notify_error(NULL, NULL, _("Group not removed"), buf); |
5228 | 757 g_free(buf); |
758 return; | |
759 } | |
760 | |
761 if(gaimbuddylist->root == node) | |
762 gaimbuddylist->root = node->next; | |
763 if (node->prev) | |
764 node->prev->next = node->next; | |
765 if (node->next) | |
766 node->next->prev = node->prev; | |
767 | |
768 ops->remove(gaimbuddylist, node); | |
769 g_free(group->name); | |
770 g_free(group); | |
771 } | |
772 | |
773 char *gaim_get_buddy_alias_only(struct buddy *b) { | |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
774 if(!b) |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
775 return NULL; |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
776 |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
777 if(b->alias && b->alias[0]) { |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
778 return b->alias; |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
779 } |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
780 else if (b->server_alias != NULL && |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
781 gaim_prefs_get_bool("/core/buddies/use_server_alias")) { |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
782 |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
783 return b->server_alias; |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
784 } |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
785 |
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
786 return NULL; |
5228 | 787 } |
788 | |
789 char * gaim_get_buddy_alias (struct buddy *buddy) | |
790 { | |
791 char *ret = gaim_get_buddy_alias_only(buddy); | |
792 | |
6036 | 793 if(!ret) |
794 return buddy ? buddy->name : _("Unknown"); | |
795 | |
796 return ret; | |
5228 | 797 } |
798 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
799 struct buddy *gaim_find_buddy(GaimAccount *account, const char *name) |
5228 | 800 { |
6245 | 801 struct buddy *buddy; |
5247 | 802 struct _gaim_hbuddy hb; |
5758 | 803 GaimBlistNode *group; |
5228 | 804 |
805 if (!gaimbuddylist) | |
806 return NULL; | |
6245 | 807 |
808 if (!name) | |
5985
60d9cbfb6bf8
[gaim-migrate @ 6433]
Christian Hammond <chipx86@chipx86.com>
parents:
5947
diff
changeset
|
809 return NULL; |
5228 | 810 |
6245 | 811 hb.name = normalize(name); |
812 hb.account = account; | |
5247 | 813 |
6245 | 814 for(group = gaimbuddylist->root; group; group = group->next) { |
5758 | 815 hb.group = group; |
5776 | 816 if ((buddy = g_hash_table_lookup(gaimbuddylist->buddies, &hb)) != NULL) |
5758 | 817 return buddy; |
818 } | |
6245 | 819 |
5758 | 820 return NULL; |
5228 | 821 } |
822 | |
6245 | 823 GSList *gaim_find_buddies(GaimAccount *account, const char *name) |
824 { | |
825 struct buddy *buddy; | |
826 struct _gaim_hbuddy hb; | |
827 GaimBlistNode *group; | |
828 GSList *ret = NULL; | |
829 | |
830 if (!gaimbuddylist) | |
831 return NULL; | |
832 | |
833 if (!name) | |
834 return NULL; | |
835 | |
836 hb.name = normalize(name); | |
837 hb.account = account; | |
838 | |
839 for(group = gaimbuddylist->root; group; group = group->next) { | |
840 hb.group = group; | |
841 if ((buddy = g_hash_table_lookup(gaimbuddylist->buddies, &hb)) != NULL) | |
842 ret = g_slist_append(ret, buddy); | |
843 } | |
844 | |
845 return ret; | |
846 } | |
847 | |
5228 | 848 struct group *gaim_find_group(const char *name) |
849 { | |
850 GaimBlistNode *node; | |
851 if (!gaimbuddylist) | |
852 return NULL; | |
853 node = gaimbuddylist->root; | |
854 while(node) { | |
855 if (!strcmp(((struct group*)node)->name, name)) | |
856 return (struct group*)node; | |
857 node = node->next; | |
858 } | |
859 return NULL; | |
860 } | |
861 struct group *gaim_find_buddys_group(struct buddy *buddy) | |
862 { | |
863 if (!buddy) | |
864 return NULL; | |
865 return (struct group*)(((GaimBlistNode*)buddy)->parent); | |
866 } | |
867 | |
868 GSList *gaim_group_get_accounts(struct group *g) | |
869 { | |
870 GSList *l = NULL; | |
871 GaimBlistNode *child = ((GaimBlistNode *)g)->child; | |
872 | |
873 while (child) { | |
874 if (!g_slist_find(l, ((struct buddy*)child)->account)) | |
875 l = g_slist_append(l, ((struct buddy*)child)->account); | |
876 child = child->next; | |
877 } | |
878 return l; | |
879 } | |
880 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
881 void gaim_blist_add_account(GaimAccount *account) |
5234 | 882 { |
883 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
884 GaimBlistNode *group, *buddy; | |
885 | |
886 if(!gaimbuddylist) | |
887 return; | |
888 | |
889 for(group = gaimbuddylist->root; group; group = group->next) { | |
890 if(!GAIM_BLIST_NODE_IS_GROUP(group)) | |
891 continue; | |
892 for(buddy = group->child; buddy; buddy = buddy->next) { | |
893 if(GAIM_BLIST_NODE_IS_BUDDY(buddy)) { | |
894 if (account == ((struct buddy*)buddy)->account) { | |
5277 | 895 ((struct group *)group)->currentsize++; |
5234 | 896 if(ops) |
897 ops->update(gaimbuddylist, buddy); | |
898 } | |
899 } else if(GAIM_BLIST_NODE_IS_CHAT(buddy)) { | |
900 if (account == ((struct chat*)buddy)->account) { | |
5287 | 901 ((struct group *)group)->online++; |
5277 | 902 ((struct group *)group)->currentsize++; |
5234 | 903 if(ops) |
904 ops->update(gaimbuddylist, buddy); | |
905 } | |
906 } | |
907 } | |
908 } | |
909 } | |
910 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
911 void gaim_blist_remove_account(GaimAccount *account) |
5228 | 912 { |
913 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
5234 | 914 GaimBlistNode *group, *buddy; |
915 | |
5228 | 916 if (!gaimbuddylist) |
917 return; | |
5234 | 918 |
919 for(group = gaimbuddylist->root; group; group = group->next) { | |
920 if(!GAIM_BLIST_NODE_IS_GROUP(group)) | |
921 continue; | |
922 for(buddy = group->child; buddy; buddy = buddy->next) { | |
923 if(GAIM_BLIST_NODE_IS_BUDDY(buddy)) { | |
924 if (account == ((struct buddy*)buddy)->account) { | |
5394 | 925 if (GAIM_BUDDY_IS_ONLINE((struct buddy*)buddy)) |
5277 | 926 ((struct group *)group)->online--; |
5234 | 927 ((struct buddy*)buddy)->present = GAIM_BUDDY_OFFLINE; |
5394 | 928 ((struct group *)group)->currentsize--; |
5234 | 929 if(ops) |
930 ops->remove(gaimbuddylist, buddy); | |
931 } | |
932 } else if(GAIM_BLIST_NODE_IS_CHAT(buddy)) { | |
933 if (account == ((struct chat*)buddy)->account) { | |
5277 | 934 ((struct group *)group)->online--; |
935 ((struct group *)group)->currentsize--; | |
5234 | 936 if(ops) |
937 ops->remove(gaimbuddylist, buddy); | |
938 } | |
5228 | 939 } |
940 } | |
941 } | |
942 } | |
943 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
944 void parse_toc_buddy_list(GaimAccount *account, char *config) |
5228 | 945 { |
946 char *c; | |
947 char current[256]; | |
948 GList *bud = NULL; | |
949 | |
950 | |
951 if (config != NULL) { | |
952 | |
953 /* skip "CONFIG:" (if it exists) */ | |
954 c = strncmp(config + 6 /* sizeof(struct sflap_hdr) */ , "CONFIG:", strlen("CONFIG:")) ? | |
955 strtok(config, "\n") : | |
956 strtok(config + 6 /* sizeof(struct sflap_hdr) */ + strlen("CONFIG:"), "\n"); | |
957 do { | |
958 if (c == NULL) | |
959 break; | |
960 if (*c == 'g') { | |
961 char *utf8 = NULL; | |
962 utf8 = gaim_try_conv_to_utf8(c + 2); | |
963 if (utf8 == NULL) { | |
964 g_strlcpy(current, _("Invalid Groupname"), sizeof(current)); | |
965 } else { | |
966 g_strlcpy(current, utf8, sizeof(current)); | |
967 g_free(utf8); | |
968 } | |
969 if (!gaim_find_group(current)) { | |
970 struct group *g = gaim_group_new(current); | |
5634 | 971 gaim_blist_add_group(g, |
972 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
5228 | 973 } |
974 } else if (*c == 'b') { /*&& !gaim_find_buddy(user, c + 2)) {*/ | |
975 char nm[80], sw[388], *a, *utf8 = NULL; | |
976 | |
977 if ((a = strchr(c + 2, ':')) != NULL) { | |
978 *a++ = '\0'; /* nul the : */ | |
979 } | |
980 | |
981 g_strlcpy(nm, c + 2, sizeof(nm)); | |
982 if (a) { | |
983 utf8 = gaim_try_conv_to_utf8(a); | |
984 if (utf8 == NULL) { | |
985 gaim_debug(GAIM_DEBUG_ERROR, "toc blist", | |
986 "Failed to convert alias for " | |
987 "'%s' to UTF-8\n", nm); | |
988 } | |
989 } | |
990 if (utf8 == NULL) { | |
991 sw[0] = '\0'; | |
992 } else { | |
993 /* This can leave a partial sequence at the end, | |
994 * but who cares? */ | |
995 g_strlcpy(sw, utf8, sizeof(sw)); | |
996 g_free(utf8); | |
997 } | |
998 | |
999 if (!gaim_find_buddy(account, nm)) { | |
1000 struct buddy *b = gaim_buddy_new(account, nm, sw); | |
1001 struct group *g = gaim_find_group(current); | |
5634 | 1002 gaim_blist_add_buddy(b, g, |
1003 gaim_blist_get_last_child((GaimBlistNode*)g)); | |
5228 | 1004 bud = g_list_append(bud, g_strdup(nm)); |
1005 } | |
1006 } else if (*c == 'p') { | |
1007 gaim_privacy_permit_add(account, c + 2); | |
1008 } else if (*c == 'd') { | |
1009 gaim_privacy_deny_add(account, c + 2); | |
1010 } else if (!strncmp("toc", c, 3)) { | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1011 sscanf(c + strlen(c) - 1, "%d", &account->perm_deny); |
5228 | 1012 gaim_debug(GAIM_DEBUG_MISC, "toc blist", |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1013 "permdeny: %d\n", account->perm_deny); |
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1014 if (account->perm_deny == 0) |
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1015 account->perm_deny = 1; |
5228 | 1016 } else if (*c == 'm') { |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1017 sscanf(c + 2, "%d", &account->perm_deny); |
5228 | 1018 gaim_debug(GAIM_DEBUG_MISC, "toc blist", |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1019 "permdeny: %d\n", account->perm_deny); |
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1020 if (account->perm_deny == 0) |
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1021 account->perm_deny = 1; |
5228 | 1022 } |
1023 } while ((c = strtok(NULL, "\n"))); | |
1024 | |
1025 if(account->gc) { | |
1026 if(bud) { | |
1027 GList *node = bud; | |
1028 serv_add_buddies(account->gc, bud); | |
1029 while(node) { | |
1030 g_free(node->data); | |
1031 node = node->next; | |
1032 } | |
1033 } | |
1034 serv_set_permit_deny(account->gc); | |
1035 } | |
1036 g_list_free(bud); | |
1037 } | |
1038 } | |
1039 | |
1040 #if 0 | |
1041 /* translate an AIM 3 buddylist (*.lst) to a Gaim buddylist */ | |
1042 static GString *translate_lst(FILE *src_fp) | |
1043 { | |
1044 char line[BUF_LEN], *line2; | |
1045 char *name; | |
1046 int i; | |
1047 | |
1048 GString *dest = g_string_new("m 1\n"); | |
1049 | |
1050 while (fgets(line, BUF_LEN, src_fp)) { | |
1051 line2 = g_strchug(line); | |
1052 if (strstr(line2, "group") == line2) { | |
1053 name = strpbrk(line2, " \t\n\r\f") + 1; | |
1054 dest = g_string_append(dest, "g "); | |
1055 for (i = 0; i < strcspn(name, "\n\r"); i++) | |
1056 if (name[i] != '\"') | |
1057 dest = g_string_append_c(dest, name[i]); | |
1058 dest = g_string_append_c(dest, '\n'); | |
1059 } | |
1060 if (strstr(line2, "buddy") == line2) { | |
1061 name = strpbrk(line2, " \t\n\r\f") + 1; | |
1062 dest = g_string_append(dest, "b "); | |
1063 for (i = 0; i < strcspn(name, "\n\r"); i++) | |
1064 if (name[i] != '\"') | |
1065 dest = g_string_append_c(dest, name[i]); | |
1066 dest = g_string_append_c(dest, '\n'); | |
1067 } | |
1068 } | |
1069 | |
1070 return dest; | |
1071 } | |
1072 | |
1073 | |
1074 /* translate an AIM 4 buddylist (*.blt) to Gaim format */ | |
1075 static GString *translate_blt(FILE *src_fp) | |
1076 { | |
1077 int i; | |
1078 char line[BUF_LEN]; | |
1079 char *buddy; | |
1080 | |
1081 GString *dest = g_string_new("m 1\n"); | |
1082 | |
1083 while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL); | |
1084 while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL); | |
1085 | |
1086 while (1) { | |
1087 fgets(line, BUF_LEN, src_fp); g_strchomp(line); | |
1088 if (strchr(line, '}') != NULL) | |
1089 break; | |
1090 | |
1091 if (strchr(line, '{') != NULL) { | |
1092 /* Syntax starting with "<group> {" */ | |
1093 | |
1094 dest = g_string_append(dest, "g "); | |
1095 buddy = g_strchug(strtok(line, "{")); | |
1096 for (i = 0; i < strlen(buddy); i++) | |
1097 if (buddy[i] != '\"') | |
1098 dest = g_string_append_c(dest, buddy[i]); | |
1099 dest = g_string_append_c(dest, '\n'); | |
1100 while (strchr(fgets(line, BUF_LEN, src_fp), '}') == NULL) { | |
1101 gboolean pounce = FALSE; | |
1102 char *e; | |
1103 g_strchomp(line); | |
1104 buddy = g_strchug(line); | |
1105 gaim_debug(GAIM_DEBUG_MISC, "AIM 4 blt import", | |
1106 "buddy: \"%s\"\n", buddy); | |
1107 dest = g_string_append(dest, "b "); | |
1108 if (strchr(buddy, '{') != NULL) { | |
1109 /* buddy pounce, etc */ | |
1110 char *pos = strchr(buddy, '{') - 1; | |
1111 *pos = 0; | |
1112 pounce = TRUE; | |
1113 } | |
1114 if ((e = strchr(buddy, '\"')) != NULL) { | |
1115 *e = '\0'; | |
1116 buddy++; | |
1117 } | |
1118 dest = g_string_append(dest, buddy); | |
1119 dest = g_string_append_c(dest, '\n'); | |
1120 if (pounce) | |
1121 do | |
1122 fgets(line, BUF_LEN, src_fp); | |
1123 while (!strchr(line, '}')); | |
1124 } | |
1125 } else { | |
1126 | |
1127 /* Syntax "group buddy buddy ..." */ | |
1128 buddy = g_strchug(strtok(line, " \n")); | |
1129 dest = g_string_append(dest, "g "); | |
1130 if (strchr(buddy, '\"') != NULL) { | |
1131 dest = g_string_append(dest, &buddy[1]); | |
1132 dest = g_string_append_c(dest, ' '); | |
1133 buddy = g_strchug(strtok(NULL, " \n")); | |
1134 while (strchr(buddy, '\"') == NULL) { | |
1135 dest = g_string_append(dest, buddy); | |
1136 dest = g_string_append_c(dest, ' '); | |
1137 buddy = g_strchug(strtok(NULL, " \n")); | |
1138 } | |
1139 buddy[strlen(buddy) - 1] = '\0'; | |
1140 dest = g_string_append(dest, buddy); | |
1141 } else { | |
1142 dest = g_string_append(dest, buddy); | |
1143 } | |
1144 dest = g_string_append_c(dest, '\n'); | |
1145 while ((buddy = g_strchug(strtok(NULL, " \n"))) != NULL) { | |
1146 dest = g_string_append(dest, "b "); | |
1147 if (strchr(buddy, '\"') != NULL) { | |
1148 dest = g_string_append(dest, &buddy[1]); | |
1149 dest = g_string_append_c(dest, ' '); | |
1150 buddy = g_strchug(strtok(NULL, " \n")); | |
1151 while (strchr(buddy, '\"') == NULL) { | |
1152 dest = g_string_append(dest, buddy); | |
1153 dest = g_string_append_c(dest, ' '); | |
1154 buddy = g_strchug(strtok(NULL, " \n")); | |
1155 } | |
1156 buddy[strlen(buddy) - 1] = '\0'; | |
1157 dest = g_string_append(dest, buddy); | |
1158 } else { | |
1159 dest = g_string_append(dest, buddy); | |
1160 } | |
1161 dest = g_string_append_c(dest, '\n'); | |
1162 } | |
1163 } | |
1164 } | |
1165 | |
1166 return dest; | |
1167 } | |
1168 | |
1169 static GString *translate_gnomeicu(FILE *src_fp) | |
1170 { | |
1171 char line[BUF_LEN]; | |
1172 GString *dest = g_string_new("m 1\ng Buddies\n"); | |
1173 | |
1174 while (strstr(fgets(line, BUF_LEN, src_fp), "NewContacts") == NULL); | |
1175 | |
1176 while (fgets(line, BUF_LEN, src_fp)) { | |
1177 char *eq; | |
1178 g_strchomp(line); | |
1179 if (line[0] == '\n' || line[0] == '[') | |
1180 break; | |
1181 eq = strchr(line, '='); | |
1182 if (!eq) | |
1183 break; | |
1184 *eq = ':'; | |
1185 eq = strchr(eq, ','); | |
1186 if (eq) | |
1187 *eq = '\0'; | |
1188 dest = g_string_append(dest, "b "); | |
1189 dest = g_string_append(dest, line); | |
1190 dest = g_string_append_c(dest, '\n'); | |
1191 } | |
1192 | |
1193 return dest; | |
1194 } | |
1195 #endif | |
1196 | |
1197 static gchar *get_screenname_filename(const char *name) | |
1198 { | |
1199 gchar **split; | |
1200 gchar *good; | |
1201 gchar *ret; | |
1202 | |
1203 split = g_strsplit(name, G_DIR_SEPARATOR_S, -1); | |
1204 good = g_strjoinv(NULL, split); | |
1205 g_strfreev(split); | |
1206 | |
1207 ret = g_utf8_strup(good, -1); | |
1208 | |
1209 g_free(good); | |
1210 | |
1211 return ret; | |
1212 } | |
1213 | |
1214 static gboolean gaim_blist_read(const char *filename); | |
1215 | |
1216 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1217 static void do_import(GaimAccount *account, const char *filename) |
5228 | 1218 { |
1219 GString *buf = NULL; | |
1220 char first[64]; | |
1221 char path[PATHSIZE]; | |
1222 int len; | |
1223 FILE *f; | |
1224 struct stat st; | |
1225 | |
1226 if (filename) { | |
1227 g_snprintf(path, sizeof(path), "%s", filename); | |
1228 } else { | |
1229 char *g_screenname = get_screenname_filename(account->username); | |
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1230 const char *username; |
5228 | 1231 char *file = gaim_user_dir(); |
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1232 GaimProtocol prpl_num; |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1233 int protocol; |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1234 |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1235 prpl_num = gaim_account_get_protocol(account); |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1236 |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1237 protocol = prpl_num; |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1238 |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1239 if (prpl_num == GAIM_PROTO_OSCAR) { |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1240 if ((username = gaim_account_get_username(account)) != NULL) { |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1241 protocol = (isalpha(*username) |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1242 ? GAIM_PROTO_TOC : GAIM_PROTO_ICQ); |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1243 } |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1244 } |
5228 | 1245 |
1246 if (file != (char *)NULL) { | |
5435 | 1247 snprintf(path, PATHSIZE, "%s" G_DIR_SEPARATOR_S "%s.%d.blist", file, g_screenname, protocol); |
5228 | 1248 g_free(g_screenname); |
1249 } else { | |
1250 g_free(g_screenname); | |
1251 return; | |
1252 } | |
1253 } | |
1254 | |
1255 if (stat(path, &st)) { | |
1256 gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Unable to stat %s.\n", | |
1257 path); | |
1258 return; | |
1259 } | |
1260 | |
1261 if (!(f = fopen(path, "r"))) { | |
1262 gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Unable to open %s.\n", | |
1263 path); | |
1264 return; | |
1265 } | |
1266 | |
1267 fgets(first, 64, f); | |
1268 | |
1269 if ((first[0] == '\n') || (first[0] == '\r' && first[1] == '\n')) | |
1270 fgets(first, 64, f); | |
1271 | |
1272 #if 0 | |
1273 if (!g_strncasecmp(first, "<xml", strlen("<xml"))) { | |
1274 /* new gaim XML buddy list */ | |
1275 gaim_blist_read(path); | |
1276 | |
1277 /* We really don't need to bother doing stuf like translating AIM 3 buddy lists anymore */ | |
1278 | |
1279 } else if (!g_strncasecmp(first, "Config {", strlen("Config {"))) { | |
1280 /* AIM 4 buddy list */ | |
1281 gaim_debug(GAIM_DEBUG_MISC, "blist import", "aim 4\n"); | |
1282 rewind(f); | |
1283 buf = translate_blt(f); | |
1284 } else if (strstr(first, "group") != NULL) { | |
1285 /* AIM 3 buddy list */ | |
1286 gaim_debug(GAIM_DEBUG_MISC, "blist import", "aim 3\n"); | |
1287 rewind(f); | |
1288 buf = translate_lst(f); | |
1289 } else if (!g_strncasecmp(first, "[User]", strlen("[User]"))) { | |
1290 /* GnomeICU (hopefully) */ | |
1291 gaim_debug(GAIM_DEBUG_MISC, "blist import", "gnomeicu\n"); | |
1292 rewind(f); | |
1293 buf = translate_gnomeicu(f); | |
1294 | |
1295 } else | |
1296 #endif | |
1297 if (first[0] == 'm') { | |
1298 /* Gaim buddy list - no translation */ | |
1299 char buf2[BUF_LONG * 2]; | |
1300 buf = g_string_new(""); | |
1301 rewind(f); | |
1302 while (1) { | |
1303 len = fread(buf2, 1, BUF_LONG * 2 - 1, f); | |
1304 if (len <= 0) | |
1305 break; | |
1306 buf2[len] = '\0'; | |
1307 buf = g_string_append(buf, buf2); | |
1308 if (len != BUF_LONG * 2 - 1) | |
1309 break; | |
1310 } | |
1311 } | |
1312 | |
1313 fclose(f); | |
1314 | |
1315 if (buf) { | |
1316 buf = g_string_prepend(buf, "toc_set_config {"); | |
1317 buf = g_string_append(buf, "}\n"); | |
1318 parse_toc_buddy_list(account, buf->str); | |
1319 g_string_free(buf, TRUE); | |
1320 } | |
1321 } | |
1322 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1323 gboolean gaim_group_on_account(struct group *g, GaimAccount *account) { |
5228 | 1324 GaimBlistNode *bnode; |
1325 for(bnode = g->node.child; bnode; bnode = bnode->next) { | |
1326 struct buddy *b = (struct buddy *)bnode; | |
1327 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
1328 continue; | |
5855 | 1329 if((!account && gaim_account_is_connected(b->account)) |
1330 || b->account == account) | |
5228 | 1331 return TRUE; |
1332 } | |
1333 return FALSE; | |
1334 } | |
1335 | |
1336 static gboolean blist_safe_to_write = FALSE; | |
1337 | |
1338 static char *blist_parser_group_name = NULL; | |
1339 static char *blist_parser_person_name = NULL; | |
1340 static char *blist_parser_account_name = NULL; | |
1341 static int blist_parser_account_protocol = 0; | |
5234 | 1342 static char *blist_parser_chat_alias = NULL; |
1343 static char *blist_parser_component_name = NULL; | |
1344 static char *blist_parser_component_value = NULL; | |
5228 | 1345 static char *blist_parser_buddy_name = NULL; |
1346 static char *blist_parser_buddy_alias = NULL; | |
1347 static char *blist_parser_setting_name = NULL; | |
1348 static char *blist_parser_setting_value = NULL; | |
1349 static GHashTable *blist_parser_buddy_settings = NULL; | |
5906 | 1350 static GHashTable *blist_parser_chat_settings = NULL; |
5228 | 1351 static GHashTable *blist_parser_group_settings = NULL; |
5234 | 1352 static GHashTable *blist_parser_chat_components = NULL; |
5228 | 1353 static int blist_parser_privacy_mode = 0; |
1354 static GList *tag_stack = NULL; | |
1355 enum { | |
1356 BLIST_TAG_GAIM, | |
1357 BLIST_TAG_BLIST, | |
1358 BLIST_TAG_GROUP, | |
5234 | 1359 BLIST_TAG_CHAT, |
1360 BLIST_TAG_COMPONENT, | |
5228 | 1361 BLIST_TAG_PERSON, |
1362 BLIST_TAG_BUDDY, | |
1363 BLIST_TAG_NAME, | |
1364 BLIST_TAG_ALIAS, | |
1365 BLIST_TAG_SETTING, | |
1366 BLIST_TAG_PRIVACY, | |
1367 BLIST_TAG_ACCOUNT, | |
1368 BLIST_TAG_PERMIT, | |
1369 BLIST_TAG_BLOCK, | |
1370 BLIST_TAG_IGNORE | |
1371 }; | |
1372 static gboolean blist_parser_error_occurred = FALSE; | |
1373 | |
1374 static void blist_start_element_handler (GMarkupParseContext *context, | |
1375 const gchar *element_name, | |
1376 const gchar **attribute_names, | |
1377 const gchar **attribute_values, | |
1378 gpointer user_data, | |
1379 GError **error) { | |
1380 int i; | |
1381 | |
1382 if(!strcmp(element_name, "gaim")) { | |
1383 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_GAIM)); | |
1384 } else if(!strcmp(element_name, "blist")) { | |
1385 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BLIST)); | |
1386 } else if(!strcmp(element_name, "group")) { | |
1387 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_GROUP)); | |
1388 for(i=0; attribute_names[i]; i++) { | |
1389 if(!strcmp(attribute_names[i], "name")) { | |
1390 g_free(blist_parser_group_name); | |
1391 blist_parser_group_name = g_strdup(attribute_values[i]); | |
1392 } | |
1393 } | |
1394 if(blist_parser_group_name) { | |
1395 struct group *g = gaim_group_new(blist_parser_group_name); | |
5634 | 1396 gaim_blist_add_group(g, |
1397 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
5228 | 1398 } |
5234 | 1399 } else if(!strcmp(element_name, "chat")) { |
1400 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_CHAT)); | |
1401 for(i=0; attribute_names[i]; i++) { | |
1402 if(!strcmp(attribute_names[i], "account")) { | |
1403 g_free(blist_parser_account_name); | |
1404 blist_parser_account_name = g_strdup(attribute_values[i]); | |
1405 } else if(!strcmp(attribute_names[i], "protocol")) { | |
1406 blist_parser_account_protocol = atoi(attribute_values[i]); | |
1407 } | |
1408 } | |
5228 | 1409 } else if(!strcmp(element_name, "person")) { |
1410 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PERSON)); | |
1411 for(i=0; attribute_names[i]; i++) { | |
1412 if(!strcmp(attribute_names[i], "name")) { | |
1413 g_free(blist_parser_person_name); | |
1414 blist_parser_person_name = g_strdup(attribute_values[i]); | |
1415 } | |
1416 } | |
1417 } else if(!strcmp(element_name, "buddy")) { | |
1418 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BUDDY)); | |
1419 for(i=0; attribute_names[i]; i++) { | |
1420 if(!strcmp(attribute_names[i], "account")) { | |
1421 g_free(blist_parser_account_name); | |
1422 blist_parser_account_name = g_strdup(attribute_values[i]); | |
1423 } else if(!strcmp(attribute_names[i], "protocol")) { | |
1424 blist_parser_account_protocol = atoi(attribute_values[i]); | |
1425 } | |
1426 } | |
1427 } else if(!strcmp(element_name, "name")) { | |
1428 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_NAME)); | |
1429 } else if(!strcmp(element_name, "alias")) { | |
1430 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_ALIAS)); | |
1431 } else if(!strcmp(element_name, "setting")) { | |
1432 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_SETTING)); | |
1433 for(i=0; attribute_names[i]; i++) { | |
1434 if(!strcmp(attribute_names[i], "name")) { | |
1435 g_free(blist_parser_setting_name); | |
1436 blist_parser_setting_name = g_strdup(attribute_values[i]); | |
1437 } | |
1438 } | |
5234 | 1439 } else if(!strcmp(element_name, "component")) { |
1440 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_COMPONENT)); | |
1441 for(i=0; attribute_names[i]; i++) { | |
1442 if(!strcmp(attribute_names[i], "name")) { | |
1443 g_free(blist_parser_component_name); | |
1444 blist_parser_component_name = g_strdup(attribute_values[i]); | |
1445 } | |
1446 } | |
1447 | |
5228 | 1448 } else if(!strcmp(element_name, "privacy")) { |
1449 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PRIVACY)); | |
1450 } else if(!strcmp(element_name, "account")) { | |
1451 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_ACCOUNT)); | |
1452 for(i=0; attribute_names[i]; i++) { | |
1453 if(!strcmp(attribute_names[i], "protocol")) | |
1454 blist_parser_account_protocol = atoi(attribute_values[i]); | |
1455 else if(!strcmp(attribute_names[i], "mode")) | |
1456 blist_parser_privacy_mode = atoi(attribute_values[i]); | |
1457 else if(!strcmp(attribute_names[i], "name")) { | |
1458 g_free(blist_parser_account_name); | |
1459 blist_parser_account_name = g_strdup(attribute_values[i]); | |
1460 } | |
1461 } | |
1462 } else if(!strcmp(element_name, "permit")) { | |
1463 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PERMIT)); | |
1464 } else if(!strcmp(element_name, "block")) { | |
1465 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BLOCK)); | |
1466 } else if(!strcmp(element_name, "ignore")) { | |
1467 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_IGNORE)); | |
1468 } | |
1469 } | |
1470 | |
1471 static void blist_end_element_handler(GMarkupParseContext *context, | |
1472 const gchar *element_name, gpointer user_data, GError **error) { | |
1473 if(!strcmp(element_name, "gaim")) { | |
1474 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1475 } else if(!strcmp(element_name, "blist")) { | |
1476 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1477 } else if(!strcmp(element_name, "group")) { | |
1478 if(blist_parser_group_settings) { | |
1479 struct group *g = gaim_find_group(blist_parser_group_name); | |
1480 g_hash_table_destroy(g->settings); | |
1481 g->settings = blist_parser_group_settings; | |
1482 } | |
1483 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1484 blist_parser_group_settings = NULL; | |
5234 | 1485 } else if(!strcmp(element_name, "chat")) { |
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1486 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
5234 | 1487 blist_parser_account_protocol); |
5237 | 1488 if(account) { |
5234 | 1489 struct chat *chat = gaim_chat_new(account, blist_parser_chat_alias, blist_parser_chat_components); |
1490 struct group *g = gaim_find_group(blist_parser_group_name); | |
5634 | 1491 gaim_blist_add_chat(chat,g, |
1492 gaim_blist_get_last_child((GaimBlistNode*)g)); | |
5906 | 1493 if(blist_parser_chat_settings) { |
1494 g_hash_table_destroy(chat->settings); | |
1495 chat->settings = blist_parser_chat_settings; | |
1496 } | |
5234 | 1497 } |
1498 g_free(blist_parser_chat_alias); | |
1499 blist_parser_chat_alias = NULL; | |
1500 g_free(blist_parser_account_name); | |
1501 blist_parser_account_name = NULL; | |
1502 blist_parser_chat_components = NULL; | |
5906 | 1503 blist_parser_chat_settings = NULL; |
5234 | 1504 tag_stack = g_list_delete_link(tag_stack, tag_stack); |
5228 | 1505 } else if(!strcmp(element_name, "person")) { |
1506 g_free(blist_parser_person_name); | |
1507 blist_parser_person_name = NULL; | |
1508 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1509 } else if(!strcmp(element_name, "buddy")) { | |
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1510 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
5228 | 1511 blist_parser_account_protocol); |
1512 if(account) { | |
1513 struct buddy *b = gaim_buddy_new(account, blist_parser_buddy_name, blist_parser_buddy_alias); | |
1514 struct group *g = gaim_find_group(blist_parser_group_name); | |
5634 | 1515 gaim_blist_add_buddy(b,g, |
1516 gaim_blist_get_last_child((GaimBlistNode*)g)); | |
5228 | 1517 if(blist_parser_buddy_settings) { |
1518 g_hash_table_destroy(b->settings); | |
1519 b->settings = blist_parser_buddy_settings; | |
1520 } | |
1521 } | |
1522 g_free(blist_parser_buddy_name); | |
1523 blist_parser_buddy_name = NULL; | |
1524 g_free(blist_parser_buddy_alias); | |
1525 blist_parser_buddy_alias = NULL; | |
1526 g_free(blist_parser_account_name); | |
1527 blist_parser_account_name = NULL; | |
1528 blist_parser_buddy_settings = NULL; | |
1529 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1530 } else if(!strcmp(element_name, "name")) { | |
1531 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1532 } else if(!strcmp(element_name, "alias")) { | |
1533 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
5234 | 1534 } else if(!strcmp(element_name, "component")) { |
1535 if(!blist_parser_chat_components) | |
1536 blist_parser_chat_components = g_hash_table_new_full(g_str_hash, | |
1537 g_str_equal, g_free, g_free); | |
1538 if(blist_parser_component_name && blist_parser_component_value) { | |
1539 g_hash_table_replace(blist_parser_chat_components, | |
1540 g_strdup(blist_parser_component_name), | |
1541 g_strdup(blist_parser_component_value)); | |
1542 } | |
1543 g_free(blist_parser_component_name); | |
1544 g_free(blist_parser_component_value); | |
1545 blist_parser_component_name = NULL; | |
1546 blist_parser_component_value = NULL; | |
1547 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
5228 | 1548 } else if(!strcmp(element_name, "setting")) { |
1549 if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_BUDDY) { | |
1550 if(!blist_parser_buddy_settings) | |
1551 blist_parser_buddy_settings = g_hash_table_new_full(g_str_hash, | |
1552 g_str_equal, g_free, g_free); | |
1553 if(blist_parser_setting_name && blist_parser_setting_value) { | |
1554 g_hash_table_replace(blist_parser_buddy_settings, | |
1555 g_strdup(blist_parser_setting_name), | |
1556 g_strdup(blist_parser_setting_value)); | |
1557 } | |
5906 | 1558 } else if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_CHAT) { |
1559 if(!blist_parser_chat_settings) | |
1560 blist_parser_chat_settings = g_hash_table_new_full(g_str_hash, | |
1561 g_str_equal, g_free, g_free); | |
1562 if(blist_parser_setting_name && blist_parser_setting_value) { | |
1563 g_hash_table_replace(blist_parser_buddy_settings, | |
1564 g_strdup(blist_parser_setting_name), | |
1565 g_strdup(blist_parser_setting_value)); | |
1566 } | |
5228 | 1567 } else if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_GROUP) { |
1568 if(!blist_parser_group_settings) | |
1569 blist_parser_group_settings = g_hash_table_new_full(g_str_hash, | |
1570 g_str_equal, g_free, g_free); | |
1571 if(blist_parser_setting_name && blist_parser_setting_value) { | |
1572 g_hash_table_replace(blist_parser_group_settings, | |
1573 g_strdup(blist_parser_setting_name), | |
1574 g_strdup(blist_parser_setting_value)); | |
1575 } | |
1576 } | |
1577 g_free(blist_parser_setting_name); | |
1578 g_free(blist_parser_setting_value); | |
1579 blist_parser_setting_name = NULL; | |
1580 blist_parser_setting_value = NULL; | |
1581 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1582 } else if(!strcmp(element_name, "privacy")) { | |
1583 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1584 } else if(!strcmp(element_name, "account")) { | |
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1585 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
5228 | 1586 blist_parser_account_protocol); |
1587 if(account) { | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1588 account->perm_deny = blist_parser_privacy_mode; |
5228 | 1589 } |
1590 g_free(blist_parser_account_name); | |
1591 blist_parser_account_name = NULL; | |
1592 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1593 } else if(!strcmp(element_name, "permit")) { | |
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1594 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
5228 | 1595 blist_parser_account_protocol); |
1596 if(account) { | |
1597 gaim_privacy_permit_add(account, blist_parser_buddy_name); | |
1598 } | |
1599 g_free(blist_parser_buddy_name); | |
1600 blist_parser_buddy_name = NULL; | |
1601 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1602 } else if(!strcmp(element_name, "block")) { | |
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1603 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
5228 | 1604 blist_parser_account_protocol); |
1605 if(account) { | |
1606 gaim_privacy_deny_add(account, blist_parser_buddy_name); | |
1607 } | |
1608 g_free(blist_parser_buddy_name); | |
1609 blist_parser_buddy_name = NULL; | |
1610 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1611 } else if(!strcmp(element_name, "ignore")) { | |
1612 /* we'll apparently do something with this later */ | |
1613 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
1614 } | |
1615 } | |
1616 | |
1617 static void blist_text_handler(GMarkupParseContext *context, const gchar *text, | |
1618 gsize text_len, gpointer user_data, GError **error) { | |
1619 switch(GPOINTER_TO_INT(tag_stack->data)) { | |
1620 case BLIST_TAG_NAME: | |
1621 blist_parser_buddy_name = g_strndup(text, text_len); | |
1622 break; | |
1623 case BLIST_TAG_ALIAS: | |
5234 | 1624 if(tag_stack->next && |
1625 GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_BUDDY) | |
1626 blist_parser_buddy_alias = g_strndup(text, text_len); | |
1627 else if(tag_stack->next && | |
1628 GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_CHAT) | |
1629 blist_parser_chat_alias = g_strndup(text, text_len); | |
5228 | 1630 break; |
1631 case BLIST_TAG_PERMIT: | |
1632 case BLIST_TAG_BLOCK: | |
1633 case BLIST_TAG_IGNORE: | |
1634 blist_parser_buddy_name = g_strndup(text, text_len); | |
1635 break; | |
5234 | 1636 case BLIST_TAG_COMPONENT: |
1637 blist_parser_component_value = g_strndup(text, text_len); | |
1638 break; | |
5228 | 1639 case BLIST_TAG_SETTING: |
1640 blist_parser_setting_value = g_strndup(text, text_len); | |
1641 break; | |
1642 default: | |
1643 break; | |
1644 } | |
1645 } | |
1646 | |
1647 static void blist_error_handler(GMarkupParseContext *context, GError *error, | |
1648 gpointer user_data) { | |
1649 blist_parser_error_occurred = TRUE; | |
1650 gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
1651 "Error parsing blist.xml: %s\n", error->message); | |
1652 } | |
1653 | |
1654 static GMarkupParser blist_parser = { | |
1655 blist_start_element_handler, | |
1656 blist_end_element_handler, | |
1657 blist_text_handler, | |
1658 NULL, | |
1659 blist_error_handler | |
1660 }; | |
1661 | |
1662 static gboolean gaim_blist_read(const char *filename) { | |
1663 gchar *contents = NULL; | |
1664 gsize length; | |
1665 GMarkupParseContext *context; | |
1666 GError *error = NULL; | |
1667 | |
1668 gaim_debug(GAIM_DEBUG_INFO, "blist import", | |
1669 "Reading %s\n", filename); | |
1670 if(!g_file_get_contents(filename, &contents, &length, &error)) { | |
1671 gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
1672 "Error reading blist: %s\n", error->message); | |
1673 g_error_free(error); | |
1674 return FALSE; | |
1675 } | |
1676 | |
1677 context = g_markup_parse_context_new(&blist_parser, 0, NULL, NULL); | |
1678 | |
1679 if(!g_markup_parse_context_parse(context, contents, length, NULL)) { | |
1680 g_markup_parse_context_free(context); | |
1681 g_free(contents); | |
1682 return FALSE; | |
1683 } | |
1684 | |
1685 if(!g_markup_parse_context_end_parse(context, NULL)) { | |
1686 gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
1687 "Error parsing %s\n", filename); | |
1688 g_markup_parse_context_free(context); | |
1689 g_free(contents); | |
1690 return FALSE; | |
1691 } | |
1692 | |
1693 g_markup_parse_context_free(context); | |
1694 g_free(contents); | |
1695 | |
1696 if(blist_parser_error_occurred) | |
1697 return FALSE; | |
1698 | |
1699 gaim_debug(GAIM_DEBUG_INFO, "blist import", "Finished reading %s\n", | |
1700 filename); | |
1701 | |
1702 return TRUE; | |
1703 } | |
1704 | |
1705 void gaim_blist_load() { | |
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1706 GList *accts; |
5228 | 1707 char *user_dir = gaim_user_dir(); |
1708 char *filename; | |
1709 char *msg; | |
1710 | |
1711 blist_safe_to_write = TRUE; | |
1712 | |
1713 if(!user_dir) | |
1714 return; | |
1715 | |
1716 filename = g_build_filename(user_dir, "blist.xml", NULL); | |
1717 | |
1718 if(g_file_test(filename, G_FILE_TEST_EXISTS)) { | |
1719 if(!gaim_blist_read(filename)) { | |
1720 msg = g_strdup_printf(_("An error was encountered parsing your " | |
1721 "buddy list. It has not been loaded.")); | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
1722 gaim_notify_error(NULL, NULL, _("Buddy List Error"), msg); |
5228 | 1723 g_free(msg); |
1724 } | |
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1725 } else if(g_list_length(gaim_accounts_get_all())) { |
5947
ac4dd1d0ee39
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1726 GMainContext *ctx; |
ac4dd1d0ee39
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1727 |
5228 | 1728 /* rob wants to inform the user that their buddy lists are |
1729 * being converted */ | |
1730 msg = g_strdup_printf(_("Gaim is converting your old buddy lists " | |
1731 "to a new format, which will now be located at %s"), | |
1732 filename); | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
1733 gaim_notify_info(NULL, NULL, _("Converting Buddy List"), msg); |
5228 | 1734 g_free(msg); |
1735 | |
1736 /* now, let gtk actually display the dialog before we start anything */ | |
5947
ac4dd1d0ee39
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1737 ctx = g_main_context_default(); |
ac4dd1d0ee39
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1738 |
ac4dd1d0ee39
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1739 while(g_main_context_pending(ctx)) |
ac4dd1d0ee39
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1740 g_main_context_iteration(ctx, FALSE); |
5228 | 1741 |
1742 /* read in the old lists, then save to the new format */ | |
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1743 for(accts = gaim_accounts_get_all(); accts; accts = accts->next) { |
5228 | 1744 do_import(accts->data, NULL); |
1745 } | |
1746 gaim_blist_save(); | |
1747 } | |
1748 | |
1749 g_free(filename); | |
1750 } | |
1751 | |
1752 static void blist_print_group_settings(gpointer key, gpointer data, | |
1753 gpointer user_data) { | |
1754 char *key_val; | |
1755 char *data_val; | |
1756 FILE *file = user_data; | |
1757 | |
1758 if(!key || !data) | |
1759 return; | |
1760 | |
1761 key_val = g_markup_escape_text(key, -1); | |
1762 data_val = g_markup_escape_text(data, -1); | |
1763 | |
1764 fprintf(file, "\t\t\t<setting name=\"%s\">%s</setting>\n", key_val, | |
1765 data_val); | |
1766 g_free(key_val); | |
1767 g_free(data_val); | |
1768 } | |
1769 | |
1770 static void blist_print_buddy_settings(gpointer key, gpointer data, | |
1771 gpointer user_data) { | |
1772 char *key_val; | |
1773 char *data_val; | |
1774 FILE *file = user_data; | |
1775 | |
1776 if(!key || !data) | |
1777 return; | |
1778 | |
1779 key_val = g_markup_escape_text(key, -1); | |
1780 data_val = g_markup_escape_text(data, -1); | |
1781 | |
1782 fprintf(file, "\t\t\t\t\t<setting name=\"%s\">%s</setting>\n", key_val, | |
1783 data_val); | |
1784 g_free(key_val); | |
1785 g_free(data_val); | |
1786 } | |
1787 | |
5234 | 1788 static void blist_print_chat_components(gpointer key, gpointer data, |
1789 gpointer user_data) { | |
1790 char *key_val; | |
1791 char *data_val; | |
1792 FILE *file = user_data; | |
1793 | |
1794 if(!key || !data) | |
1795 return; | |
1796 | |
1797 key_val = g_markup_escape_text(key, -1); | |
1798 data_val = g_markup_escape_text(data, -1); | |
1799 | |
1800 fprintf(file, "\t\t\t\t<component name=\"%s\">%s</component>\n", key_val, | |
1801 data_val); | |
1802 g_free(key_val); | |
1803 g_free(data_val); | |
1804 } | |
1805 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1806 static void gaim_blist_write(FILE *file, GaimAccount *exp_acct) { |
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1807 GList *accounts; |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1808 GSList *buds; |
5228 | 1809 GaimBlistNode *gnode,*bnode; |
1810 struct group *group; | |
1811 struct buddy *bud; | |
1812 fprintf(file, "<?xml version='1.0' encoding='UTF-8' ?>\n"); | |
1813 fprintf(file, "<gaim version=\"1\">\n"); | |
1814 fprintf(file, "\t<blist>\n"); | |
1815 | |
1816 for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { | |
1817 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
1818 continue; | |
1819 group = (struct group *)gnode; | |
1820 if(!exp_acct || gaim_group_on_account(group, exp_acct)) { | |
1821 char *group_name = g_markup_escape_text(group->name, -1); | |
1822 fprintf(file, "\t\t<group name=\"%s\">\n", group_name); | |
1823 g_hash_table_foreach(group->settings, blist_print_group_settings, file); | |
1824 for(bnode = gnode->child; bnode; bnode = bnode->next) { | |
5234 | 1825 if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { |
1826 bud = (struct buddy *)bnode; | |
1827 if(!exp_acct || bud->account == exp_acct) { | |
1828 char *bud_name = g_markup_escape_text(bud->name, -1); | |
1829 char *bud_alias = NULL; | |
1830 char *acct_name = g_markup_escape_text(bud->account->username, -1); | |
1831 if(bud->alias) | |
1832 bud_alias= g_markup_escape_text(bud->alias, -1); | |
1833 fprintf(file, "\t\t\t<person name=\"%s\">\n", | |
1834 bud_alias ? bud_alias : bud_name); | |
1835 fprintf(file, "\t\t\t\t<buddy protocol=\"%d\" " | |
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1836 "account=\"%s\">\n", |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1837 gaim_account_get_protocol(bud->account), |
5234 | 1838 acct_name); |
1839 fprintf(file, "\t\t\t\t\t<name>%s</name>\n", bud_name); | |
1840 if(bud_alias) { | |
1841 fprintf(file, "\t\t\t\t\t<alias>%s</alias>\n", | |
1842 bud_alias); | |
1843 } | |
1844 g_hash_table_foreach(bud->settings, | |
1845 blist_print_buddy_settings, file); | |
1846 fprintf(file, "\t\t\t\t</buddy>\n"); | |
1847 fprintf(file, "\t\t\t</person>\n"); | |
1848 g_free(bud_name); | |
1849 g_free(bud_alias); | |
1850 g_free(acct_name); | |
5228 | 1851 } |
5234 | 1852 } else if(GAIM_BLIST_NODE_IS_CHAT(bnode)) { |
1853 struct chat *chat = (struct chat *)bnode; | |
1854 if(!exp_acct || chat->account == exp_acct) { | |
1855 char *acct_name = g_markup_escape_text(chat->account->username, -1); | |
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1856 fprintf(file, "\t\t\t<chat protocol=\"%d\" account=\"%s\">\n", |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1857 gaim_account_get_protocol(chat->account), |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1858 acct_name); |
5237 | 1859 if(chat->alias) { |
1860 char *chat_alias = g_markup_escape_text(chat->alias, -1); | |
1861 fprintf(file, "\t\t\t\t<alias>%s</alias>\n", chat_alias); | |
1862 g_free(chat_alias); | |
1863 } | |
5234 | 1864 g_hash_table_foreach(chat->components, |
1865 blist_print_chat_components, file); | |
5906 | 1866 /* works for chats too, I don't feel like renaming */ |
1867 g_hash_table_foreach(chat->settings, | |
1868 blist_print_buddy_settings, file); | |
5234 | 1869 fprintf(file, "\t\t\t</chat>\n"); |
5237 | 1870 g_free(acct_name); |
5234 | 1871 } |
5228 | 1872 } |
1873 } | |
1874 fprintf(file, "\t\t</group>\n"); | |
1875 g_free(group_name); | |
1876 } | |
1877 } | |
1878 | |
1879 fprintf(file, "\t</blist>\n"); | |
1880 fprintf(file, "\t<privacy>\n"); | |
1881 | |
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1882 for(accounts = gaim_accounts_get_all(); |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1883 accounts != NULL; |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1884 accounts = accounts->next) { |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1885 |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1886 GaimAccount *account = accounts->data; |
5228 | 1887 char *acct_name = g_markup_escape_text(account->username, -1); |
1888 if(!exp_acct || account == exp_acct) { | |
1889 fprintf(file, "\t\t<account protocol=\"%d\" name=\"%s\" " | |
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1890 "mode=\"%d\">\n", gaim_account_get_protocol(account), |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1891 acct_name, account->perm_deny); |
5228 | 1892 for(buds = account->permit; buds; buds = buds->next) { |
1893 char *bud_name = g_markup_escape_text(buds->data, -1); | |
1894 fprintf(file, "\t\t\t<permit>%s</permit>\n", bud_name); | |
1895 g_free(bud_name); | |
1896 } | |
1897 for(buds = account->deny; buds; buds = buds->next) { | |
1898 char *bud_name = g_markup_escape_text(buds->data, -1); | |
1899 fprintf(file, "\t\t\t<block>%s</block>\n", bud_name); | |
1900 g_free(bud_name); | |
1901 } | |
1902 fprintf(file, "\t\t</account>\n"); | |
1903 } | |
1904 g_free(acct_name); | |
1905 } | |
1906 | |
1907 fprintf(file, "\t</privacy>\n"); | |
1908 fprintf(file, "</gaim>\n"); | |
1909 } | |
1910 | |
1911 void gaim_blist_save() { | |
1912 FILE *file; | |
1913 char *user_dir = gaim_user_dir(); | |
1914 char *filename; | |
1915 char *filename_real; | |
1916 | |
1917 if(!user_dir) | |
1918 return; | |
1919 if(!blist_safe_to_write) { | |
1920 gaim_debug(GAIM_DEBUG_WARNING, "blist save", | |
1921 "AHH!! Tried to write the blist before we read it!\n"); | |
1922 return; | |
1923 } | |
1924 | |
1925 file = fopen(user_dir, "r"); | |
1926 if(!file) | |
1927 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
1928 else | |
1929 fclose(file); | |
1930 | |
1931 filename = g_build_filename(user_dir, "blist.xml.save", NULL); | |
1932 | |
1933 if((file = fopen(filename, "w"))) { | |
1934 gaim_blist_write(file, NULL); | |
1935 fclose(file); | |
1936 chmod(filename, S_IRUSR | S_IWUSR); | |
1937 } else { | |
1938 gaim_debug(GAIM_DEBUG_ERROR, "blist save", "Unable to write %s\n", | |
1939 filename); | |
1940 } | |
1941 | |
1942 filename_real = g_build_filename(user_dir, "blist.xml", NULL); | |
1943 | |
1944 if(rename(filename, filename_real) < 0) | |
1945 gaim_debug(GAIM_DEBUG_ERROR, "blist save", | |
1946 "Error renaming %s to %s\n", filename, filename_real); | |
1947 | |
1948 | |
1949 g_free(filename); | |
1950 g_free(filename_real); | |
1951 } | |
1952 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1953 gboolean gaim_privacy_permit_add(GaimAccount *account, const char *who) { |
5228 | 1954 GSList *d = account->permit; |
1955 char *n = g_strdup(normalize(who)); | |
1956 while(d) { | |
1957 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) | |
1958 break; | |
1959 d = d->next; | |
1960 } | |
1961 g_free(n); | |
1962 if(!d) { | |
1963 account->permit = g_slist_append(account->permit, g_strdup(who)); | |
1964 return TRUE; | |
1965 } | |
1966 | |
1967 return FALSE; | |
1968 } | |
1969 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1970 gboolean gaim_privacy_permit_remove(GaimAccount *account, const char *who) { |
5228 | 1971 GSList *d = account->permit; |
1972 char *n = g_strdup(normalize(who)); | |
1973 while(d) { | |
1974 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) | |
1975 break; | |
1976 d = d->next; | |
1977 } | |
1978 g_free(n); | |
1979 if(d) { | |
1980 account->permit = g_slist_remove(account->permit, d->data); | |
1981 g_free(d->data); | |
1982 return TRUE; | |
1983 } | |
1984 return FALSE; | |
1985 } | |
1986 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1987 gboolean gaim_privacy_deny_add(GaimAccount *account, const char *who) { |
5228 | 1988 GSList *d = account->deny; |
1989 char *n = g_strdup(normalize(who)); | |
1990 while(d) { | |
1991 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) | |
1992 break; | |
1993 d = d->next; | |
1994 } | |
1995 g_free(n); | |
1996 if(!d) { | |
1997 account->deny = g_slist_append(account->deny, g_strdup(who)); | |
1998 return TRUE; | |
1999 } | |
2000 | |
2001 return FALSE; | |
2002 } | |
2003 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
2004 gboolean gaim_privacy_deny_remove(GaimAccount *account, const char *who) { |
5228 | 2005 GSList *d = account->deny; |
2006 char *n = g_strdup(normalize(who)); | |
2007 while(d) { | |
2008 if(!gaim_utf8_strcasecmp(n, normalize(d->data))) | |
2009 break; | |
2010 d = d->next; | |
2011 } | |
2012 g_free(n); | |
2013 if(d) { | |
2014 account->deny = g_slist_remove(account->deny, d->data); | |
2015 g_free(d->data); | |
2016 return TRUE; | |
2017 } | |
2018 return FALSE; | |
2019 } | |
2020 | |
2021 void gaim_group_set_setting(struct group *g, const char *key, | |
2022 const char *value) { | |
2023 if(!g) | |
2024 return; | |
2025 g_hash_table_replace(g->settings, g_strdup(key), g_strdup(value)); | |
2026 } | |
2027 | |
2028 char *gaim_group_get_setting(struct group *g, const char *key) { | |
2029 if(!g) | |
2030 return NULL; | |
2031 return g_strdup(g_hash_table_lookup(g->settings, key)); | |
2032 } | |
2033 | |
5906 | 2034 void gaim_chat_set_setting(struct chat *c, const char *key, |
2035 const char *value) | |
2036 { | |
2037 if(!c) | |
2038 return; | |
2039 g_hash_table_replace(c->settings, g_strdup(key), g_strdup(value)); | |
2040 } | |
2041 | |
2042 char *gaim_chat_get_setting(struct chat *c, const char *key) | |
2043 { | |
2044 if(!c) | |
2045 return NULL; | |
2046 return g_strdup(g_hash_table_lookup(c->settings, key)); | |
2047 } | |
2048 | |
5228 | 2049 void gaim_buddy_set_setting(struct buddy *b, const char *key, |
2050 const char *value) { | |
2051 if(!b) | |
2052 return; | |
2053 g_hash_table_replace(b->settings, g_strdup(key), g_strdup(value)); | |
2054 } | |
2055 | |
2056 char *gaim_buddy_get_setting(struct buddy *b, const char *key) { | |
2057 if(!b) | |
2058 return NULL; | |
2059 return g_strdup(g_hash_table_lookup(b->settings, key)); | |
2060 } | |
2061 | |
2062 void gaim_set_blist_ui_ops(struct gaim_blist_ui_ops *ops) | |
2063 { | |
2064 blist_ui_ops = ops; | |
2065 } | |
2066 | |
2067 struct gaim_blist_ui_ops * | |
2068 gaim_get_blist_ui_ops(void) | |
2069 { | |
2070 return blist_ui_ops; | |
2071 } | |
2072 | |
2073 int gaim_blist_get_group_size(struct group *group, gboolean offline) { | |
2074 if(!group) | |
2075 return 0; | |
2076 | |
5277 | 2077 return offline ? group->totalsize : group->currentsize; |
5228 | 2078 } |
2079 | |
2080 int gaim_blist_get_group_online_count(struct group *group) { | |
2081 if(!group) | |
2082 return 0; | |
2083 | |
5277 | 2084 return group->online; |
5228 | 2085 } |
2086 | |
2087 |