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