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