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