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