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