Mercurial > pidgin
annotate src/blist.c @ 7968:64e94b6823c3
[gaim-migrate @ 8645]
ok, jabber chat invites don't suck now
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Thu, 01 Jan 2004 06:38:55 +0000 |
parents | 1b8261f374ea |
children | 69c511278aef |
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 |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1346 for (group = gaimbuddylist->root; group != NULL; group = group->next) { |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1347 for (node = group->child; node != NULL; node = node->next) { |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1348 if (GAIM_BLIST_NODE_IS_CHAT(node)) { |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1349 |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1350 chat = (GaimChat*)node; |
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1351 |
7956 | 1352 prpl = gaim_find_prpl(gaim_account_get_protocol_id(chat->account)); |
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1353 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1354 |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1355 parts = prpl_info->chat_info( |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1356 gaim_account_get_connection(chat->account)); |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1357 |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1358 pce = parts->data; |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1359 chat_name = g_hash_table_lookup(chat->components, |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1360 pce->identifier); |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1361 |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1362 if (chat->account == account && |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1363 name != NULL && !strcmp(chat_name, name)) { |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1364 |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1365 return chat; |
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 } |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1368 } |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1369 } |
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 return NULL; |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1372 } |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1373 |
6695 | 1374 GaimGroup * |
7125 | 1375 gaim_chat_get_group(GaimChat *chat) |
6456
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 g_return_val_if_fail(chat != NULL, NULL); |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1378 |
6695 | 1379 return (GaimGroup *)(((GaimBlistNode *)chat)->parent); |
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1380 } |
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1381 |
6695 | 1382 GaimGroup *gaim_find_buddys_group(GaimBuddy *buddy) |
5228 | 1383 { |
1384 if (!buddy) | |
1385 return NULL; | |
6706
854a435d2cc3
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1386 |
854a435d2cc3
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1387 if (((GaimBlistNode *)buddy)->parent == NULL) |
854a435d2cc3
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1388 return NULL; |
854a435d2cc3
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1389 |
6695 | 1390 return (GaimGroup *)(((GaimBlistNode*)buddy)->parent->parent); |
5228 | 1391 } |
1392 | |
6695 | 1393 GSList *gaim_group_get_accounts(GaimGroup *g) |
5228 | 1394 { |
1395 GSList *l = NULL; | |
6695 | 1396 GaimBlistNode *gnode, *cnode, *bnode; |
1397 | |
1398 gnode = (GaimBlistNode *)g; | |
5228 | 1399 |
6695 | 1400 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
1401 if (GAIM_BLIST_NODE_IS_CHAT(cnode)) { | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1402 if(!g_slist_find(l, ((GaimChat *)cnode)->account)) |
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1403 l = g_slist_append(l, ((GaimChat *)cnode)->account); |
6695 | 1404 } else if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { |
1405 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
1406 if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { | |
1407 if(!g_slist_find(l, ((GaimBuddy *)bnode)->account)) | |
1408 l = g_slist_append(l, ((GaimBuddy *)bnode)->account); | |
1409 } | |
1410 } | |
1411 } | |
5228 | 1412 } |
6695 | 1413 |
5228 | 1414 return l; |
1415 } | |
1416 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1417 void gaim_blist_add_account(GaimAccount *account) |
5234 | 1418 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
1419 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
6695 | 1420 GaimBlistNode *gnode, *cnode, *bnode; |
5234 | 1421 |
1422 if(!gaimbuddylist) | |
1423 return; | |
1424 | |
6695 | 1425 if(!ops) |
1426 return; | |
1427 | |
1428 for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { | |
1429 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
5234 | 1430 continue; |
6695 | 1431 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
1432 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
6956 | 1433 gboolean recompute = FALSE; |
6695 | 1434 for(bnode = cnode->child; bnode; bnode = bnode->next) { |
1435 if(GAIM_BLIST_NODE_IS_BUDDY(bnode) && | |
1436 ((GaimBuddy*)bnode)->account == account) { | |
6956 | 1437 recompute = TRUE; |
6695 | 1438 ((GaimContact*)cnode)->currentsize++; |
1439 if(((GaimContact*)cnode)->currentsize == 1) | |
1440 ((GaimGroup*)gnode)->currentsize++; | |
1441 if(GAIM_BUDDY_IS_ONLINE((GaimBuddy*)bnode)) { | |
1442 ((GaimContact*)cnode)->online++; | |
1443 if(((GaimContact*)cnode)->online == 1) | |
1444 ((GaimGroup*)gnode)->online++; | |
1445 } | |
1446 ops->update(gaimbuddylist, bnode); | |
1447 } | |
1448 } | |
6956 | 1449 if(recompute) { |
1450 gaim_contact_compute_priority_buddy((GaimContact*)cnode); | |
1451 ops->update(gaimbuddylist, cnode); | |
1452 } | |
6695 | 1453 } else if(GAIM_BLIST_NODE_IS_CHAT(cnode) && |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1454 ((GaimChat*)cnode)->account == account) { |
6901 | 1455 ((GaimGroup *)gnode)->online++; |
1456 ((GaimGroup *)gnode)->currentsize++; | |
1457 ops->update(gaimbuddylist, cnode); | |
5234 | 1458 } |
1459 } | |
6695 | 1460 ops->update(gaimbuddylist, gnode); |
5234 | 1461 } |
1462 } | |
1463 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1464 void gaim_blist_remove_account(GaimAccount *account) |
5228 | 1465 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
1466 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
6695 | 1467 GaimBlistNode *gnode, *cnode, *bnode; |
5234 | 1468 |
5228 | 1469 if (!gaimbuddylist) |
1470 return; | |
5234 | 1471 |
6695 | 1472 for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { |
1473 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
5234 | 1474 continue; |
6695 | 1475 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
1476 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
6957 | 1477 gboolean recompute = FALSE; |
6695 | 1478 for(bnode = cnode->child; bnode; bnode = bnode->next) { |
1479 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
1480 continue; | |
1481 if(account == ((GaimBuddy *)bnode)->account) { | |
6957 | 1482 recompute = TRUE; |
6695 | 1483 if(((GaimBuddy*)bnode)->present == GAIM_BUDDY_ONLINE || |
1484 ((GaimBuddy*)bnode)->present == GAIM_BUDDY_SIGNING_ON) { | |
1485 ((GaimContact*)cnode)->online--; | |
1486 if(((GaimContact*)cnode)->online == 0) | |
1487 ((GaimGroup*)gnode)->online--; | |
1488 } | |
1489 ((GaimContact*)cnode)->currentsize--; | |
1490 if(((GaimContact*)cnode)->currentsize == 0) | |
1491 ((GaimGroup*)gnode)->currentsize--; | |
1492 | |
1493 ((GaimBuddy*)bnode)->present = GAIM_BUDDY_OFFLINE; | |
1494 | |
6803 | 1495 ((GaimBuddy*)bnode)->uc = 0; |
1496 ((GaimBuddy*)bnode)->idle = 0; | |
1497 ((GaimBuddy*)bnode)->evil = 0; | |
1498 | |
6945 | 1499 |
6695 | 1500 if(ops) |
1501 ops->remove(gaimbuddylist, bnode); | |
1502 } | |
5234 | 1503 } |
6983 | 1504 if(recompute) { |
6959 | 1505 gaim_contact_compute_priority_buddy((GaimContact*)cnode); |
6983 | 1506 if(ops) |
1507 ops->update(gaimbuddylist, cnode); | |
1508 } | |
6695 | 1509 } else if(GAIM_BLIST_NODE_IS_CHAT(cnode) && |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1510 ((GaimChat*)cnode)->account == account) { |
6695 | 1511 ((GaimGroup*)gnode)->currentsize--; |
1512 ((GaimGroup*)gnode)->online--; | |
1513 if(ops) | |
1514 ops->remove(gaimbuddylist, cnode); | |
5228 | 1515 } |
1516 } | |
1517 } | |
1518 } | |
1519 | |
7117
943085b0ff8b
[gaim-migrate @ 7684]
Christian Hammond <chipx86@chipx86.com>
parents:
7115
diff
changeset
|
1520 void gaim_blist_parse_toc_buddy_list(GaimAccount *account, char *config) |
5228 | 1521 { |
1522 char *c; | |
1523 char current[256]; | |
1524 GList *bud = NULL; | |
1525 | |
1526 | |
1527 if (config != NULL) { | |
1528 | |
1529 /* skip "CONFIG:" (if it exists) */ | |
1530 c = strncmp(config + 6 /* sizeof(struct sflap_hdr) */ , "CONFIG:", strlen("CONFIG:")) ? | |
1531 strtok(config, "\n") : | |
1532 strtok(config + 6 /* sizeof(struct sflap_hdr) */ + strlen("CONFIG:"), "\n"); | |
1533 do { | |
1534 if (c == NULL) | |
1535 break; | |
1536 if (*c == 'g') { | |
1537 char *utf8 = NULL; | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
1538 utf8 = gaim_utf8_try_convert(c + 2); |
5228 | 1539 if (utf8 == NULL) { |
1540 g_strlcpy(current, _("Invalid Groupname"), sizeof(current)); | |
1541 } else { | |
1542 g_strlcpy(current, utf8, sizeof(current)); | |
1543 g_free(utf8); | |
1544 } | |
1545 if (!gaim_find_group(current)) { | |
6695 | 1546 GaimGroup *g = gaim_group_new(current); |
5634 | 1547 gaim_blist_add_group(g, |
1548 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
5228 | 1549 } |
1550 } else if (*c == 'b') { /*&& !gaim_find_buddy(user, c + 2)) {*/ | |
1551 char nm[80], sw[388], *a, *utf8 = NULL; | |
1552 | |
1553 if ((a = strchr(c + 2, ':')) != NULL) { | |
1554 *a++ = '\0'; /* nul the : */ | |
1555 } | |
1556 | |
1557 g_strlcpy(nm, c + 2, sizeof(nm)); | |
1558 if (a) { | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
1559 utf8 = gaim_utf8_try_convert(a); |
5228 | 1560 if (utf8 == NULL) { |
1561 gaim_debug(GAIM_DEBUG_ERROR, "toc blist", | |
1562 "Failed to convert alias for " | |
1563 "'%s' to UTF-8\n", nm); | |
1564 } | |
1565 } | |
1566 if (utf8 == NULL) { | |
1567 sw[0] = '\0'; | |
1568 } else { | |
1569 /* This can leave a partial sequence at the end, | |
1570 * but who cares? */ | |
1571 g_strlcpy(sw, utf8, sizeof(sw)); | |
1572 g_free(utf8); | |
1573 } | |
1574 | |
1575 if (!gaim_find_buddy(account, nm)) { | |
6695 | 1576 GaimBuddy *b = gaim_buddy_new(account, nm, sw); |
1577 GaimGroup *g = gaim_find_group(current); | |
1578 gaim_blist_add_buddy(b, NULL, g, | |
5634 | 1579 gaim_blist_get_last_child((GaimBlistNode*)g)); |
5228 | 1580 bud = g_list_append(bud, g_strdup(nm)); |
1581 } | |
1582 } else if (*c == 'p') { | |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1583 gaim_privacy_permit_add(account, c + 2, TRUE); |
5228 | 1584 } else if (*c == 'd') { |
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1585 gaim_privacy_deny_add(account, c + 2, TRUE); |
5228 | 1586 } else if (!strncmp("toc", c, 3)) { |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1587 sscanf(c + strlen(c) - 1, "%d", &account->perm_deny); |
5228 | 1588 gaim_debug(GAIM_DEBUG_MISC, "toc blist", |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1589 "permdeny: %d\n", account->perm_deny); |
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1590 if (account->perm_deny == 0) |
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1591 account->perm_deny = 1; |
5228 | 1592 } else if (*c == 'm') { |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1593 sscanf(c + 2, "%d", &account->perm_deny); |
5228 | 1594 gaim_debug(GAIM_DEBUG_MISC, "toc blist", |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1595 "permdeny: %d\n", account->perm_deny); |
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1596 if (account->perm_deny == 0) |
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1597 account->perm_deny = 1; |
5228 | 1598 } |
1599 } while ((c = strtok(NULL, "\n"))); | |
1600 | |
1601 if(account->gc) { | |
1602 if(bud) { | |
1603 GList *node = bud; | |
1604 serv_add_buddies(account->gc, bud); | |
1605 while(node) { | |
1606 g_free(node->data); | |
1607 node = node->next; | |
1608 } | |
1609 } | |
1610 serv_set_permit_deny(account->gc); | |
1611 } | |
1612 g_list_free(bud); | |
1613 } | |
1614 } | |
1615 | |
1616 #if 0 | |
1617 /* translate an AIM 3 buddylist (*.lst) to a Gaim buddylist */ | |
1618 static GString *translate_lst(FILE *src_fp) | |
1619 { | |
1620 char line[BUF_LEN], *line2; | |
1621 char *name; | |
1622 int i; | |
1623 | |
1624 GString *dest = g_string_new("m 1\n"); | |
1625 | |
1626 while (fgets(line, BUF_LEN, src_fp)) { | |
1627 line2 = g_strchug(line); | |
1628 if (strstr(line2, "group") == line2) { | |
1629 name = strpbrk(line2, " \t\n\r\f") + 1; | |
1630 dest = g_string_append(dest, "g "); | |
1631 for (i = 0; i < strcspn(name, "\n\r"); i++) | |
1632 if (name[i] != '\"') | |
1633 dest = g_string_append_c(dest, name[i]); | |
1634 dest = g_string_append_c(dest, '\n'); | |
1635 } | |
1636 if (strstr(line2, "buddy") == line2) { | |
1637 name = strpbrk(line2, " \t\n\r\f") + 1; | |
1638 dest = g_string_append(dest, "b "); | |
1639 for (i = 0; i < strcspn(name, "\n\r"); i++) | |
1640 if (name[i] != '\"') | |
1641 dest = g_string_append_c(dest, name[i]); | |
1642 dest = g_string_append_c(dest, '\n'); | |
1643 } | |
1644 } | |
1645 | |
1646 return dest; | |
1647 } | |
1648 | |
1649 | |
1650 /* translate an AIM 4 buddylist (*.blt) to Gaim format */ | |
1651 static GString *translate_blt(FILE *src_fp) | |
1652 { | |
1653 int i; | |
1654 char line[BUF_LEN]; | |
1655 char *buddy; | |
1656 | |
1657 GString *dest = g_string_new("m 1\n"); | |
1658 | |
1659 while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL); | |
1660 while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL); | |
1661 | |
1662 while (1) { | |
1663 fgets(line, BUF_LEN, src_fp); g_strchomp(line); | |
1664 if (strchr(line, '}') != NULL) | |
1665 break; | |
1666 | |
1667 if (strchr(line, '{') != NULL) { | |
1668 /* Syntax starting with "<group> {" */ | |
1669 | |
1670 dest = g_string_append(dest, "g "); | |
1671 buddy = g_strchug(strtok(line, "{")); | |
1672 for (i = 0; i < strlen(buddy); i++) | |
1673 if (buddy[i] != '\"') | |
1674 dest = g_string_append_c(dest, buddy[i]); | |
1675 dest = g_string_append_c(dest, '\n'); | |
1676 while (strchr(fgets(line, BUF_LEN, src_fp), '}') == NULL) { | |
1677 gboolean pounce = FALSE; | |
1678 char *e; | |
1679 g_strchomp(line); | |
1680 buddy = g_strchug(line); | |
1681 gaim_debug(GAIM_DEBUG_MISC, "AIM 4 blt import", | |
1682 "buddy: \"%s\"\n", buddy); | |
1683 dest = g_string_append(dest, "b "); | |
1684 if (strchr(buddy, '{') != NULL) { | |
1685 /* buddy pounce, etc */ | |
1686 char *pos = strchr(buddy, '{') - 1; | |
1687 *pos = 0; | |
1688 pounce = TRUE; | |
1689 } | |
1690 if ((e = strchr(buddy, '\"')) != NULL) { | |
1691 *e = '\0'; | |
1692 buddy++; | |
1693 } | |
1694 dest = g_string_append(dest, buddy); | |
1695 dest = g_string_append_c(dest, '\n'); | |
1696 if (pounce) | |
1697 do | |
1698 fgets(line, BUF_LEN, src_fp); | |
1699 while (!strchr(line, '}')); | |
1700 } | |
1701 } else { | |
1702 | |
1703 /* Syntax "group buddy buddy ..." */ | |
1704 buddy = g_strchug(strtok(line, " \n")); | |
1705 dest = g_string_append(dest, "g "); | |
1706 if (strchr(buddy, '\"') != NULL) { | |
1707 dest = g_string_append(dest, &buddy[1]); | |
1708 dest = g_string_append_c(dest, ' '); | |
1709 buddy = g_strchug(strtok(NULL, " \n")); | |
1710 while (strchr(buddy, '\"') == NULL) { | |
1711 dest = g_string_append(dest, buddy); | |
1712 dest = g_string_append_c(dest, ' '); | |
1713 buddy = g_strchug(strtok(NULL, " \n")); | |
1714 } | |
1715 buddy[strlen(buddy) - 1] = '\0'; | |
1716 dest = g_string_append(dest, buddy); | |
1717 } else { | |
1718 dest = g_string_append(dest, buddy); | |
1719 } | |
1720 dest = g_string_append_c(dest, '\n'); | |
1721 while ((buddy = g_strchug(strtok(NULL, " \n"))) != NULL) { | |
1722 dest = g_string_append(dest, "b "); | |
1723 if (strchr(buddy, '\"') != NULL) { | |
1724 dest = g_string_append(dest, &buddy[1]); | |
1725 dest = g_string_append_c(dest, ' '); | |
1726 buddy = g_strchug(strtok(NULL, " \n")); | |
1727 while (strchr(buddy, '\"') == NULL) { | |
1728 dest = g_string_append(dest, buddy); | |
1729 dest = g_string_append_c(dest, ' '); | |
1730 buddy = g_strchug(strtok(NULL, " \n")); | |
1731 } | |
1732 buddy[strlen(buddy) - 1] = '\0'; | |
1733 dest = g_string_append(dest, buddy); | |
1734 } else { | |
1735 dest = g_string_append(dest, buddy); | |
1736 } | |
1737 dest = g_string_append_c(dest, '\n'); | |
1738 } | |
1739 } | |
1740 } | |
1741 | |
1742 return dest; | |
1743 } | |
1744 | |
1745 static GString *translate_gnomeicu(FILE *src_fp) | |
1746 { | |
1747 char line[BUF_LEN]; | |
1748 GString *dest = g_string_new("m 1\ng Buddies\n"); | |
1749 | |
1750 while (strstr(fgets(line, BUF_LEN, src_fp), "NewContacts") == NULL); | |
1751 | |
1752 while (fgets(line, BUF_LEN, src_fp)) { | |
1753 char *eq; | |
1754 g_strchomp(line); | |
1755 if (line[0] == '\n' || line[0] == '[') | |
1756 break; | |
1757 eq = strchr(line, '='); | |
1758 if (!eq) | |
1759 break; | |
1760 *eq = ':'; | |
1761 eq = strchr(eq, ','); | |
1762 if (eq) | |
1763 *eq = '\0'; | |
1764 dest = g_string_append(dest, "b "); | |
1765 dest = g_string_append(dest, line); | |
1766 dest = g_string_append_c(dest, '\n'); | |
1767 } | |
1768 | |
1769 return dest; | |
1770 } | |
1771 #endif | |
1772 | |
1773 static gchar *get_screenname_filename(const char *name) | |
1774 { | |
1775 gchar **split; | |
1776 gchar *good; | |
1777 gchar *ret; | |
1778 | |
1779 split = g_strsplit(name, G_DIR_SEPARATOR_S, -1); | |
1780 good = g_strjoinv(NULL, split); | |
1781 g_strfreev(split); | |
1782 | |
1783 ret = g_utf8_strup(good, -1); | |
1784 | |
1785 g_free(good); | |
1786 | |
1787 return ret; | |
1788 } | |
1789 | |
1790 static gboolean gaim_blist_read(const char *filename); | |
1791 | |
1792 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1793 static void do_import(GaimAccount *account, const char *filename) |
5228 | 1794 { |
1795 GString *buf = NULL; | |
1796 char first[64]; | |
1797 char path[PATHSIZE]; | |
1798 int len; | |
1799 FILE *f; | |
1800 struct stat st; | |
1801 | |
1802 if (filename) { | |
1803 g_snprintf(path, sizeof(path), "%s", filename); | |
1804 } else { | |
1805 char *g_screenname = get_screenname_filename(account->username); | |
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1806 const char *username; |
5228 | 1807 char *file = gaim_user_dir(); |
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1808 GaimProtocol prpl_num; |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1809 int protocol; |
6695 | 1810 |
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1811 prpl_num = gaim_account_get_protocol(account); |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1812 |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1813 protocol = prpl_num; |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1814 |
6450
e7b87c8e8c0a
[gaim-migrate @ 6959]
Christian Hammond <chipx86@chipx86.com>
parents:
6392
diff
changeset
|
1815 /* TODO Somehow move this checking into prpls */ |
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1816 if (prpl_num == GAIM_PROTO_OSCAR) { |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1817 if ((username = gaim_account_get_username(account)) != NULL) { |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1818 protocol = (isalpha(*username) |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1819 ? GAIM_PROTO_TOC : GAIM_PROTO_ICQ); |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1820 } |
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1821 } |
5228 | 1822 |
1823 if (file != (char *)NULL) { | |
5435 | 1824 snprintf(path, PATHSIZE, "%s" G_DIR_SEPARATOR_S "%s.%d.blist", file, g_screenname, protocol); |
5228 | 1825 g_free(g_screenname); |
1826 } else { | |
1827 g_free(g_screenname); | |
1828 return; | |
1829 } | |
1830 } | |
1831 | |
1832 if (stat(path, &st)) { | |
1833 gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Unable to stat %s.\n", | |
1834 path); | |
1835 return; | |
1836 } | |
1837 | |
1838 if (!(f = fopen(path, "r"))) { | |
1839 gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Unable to open %s.\n", | |
1840 path); | |
1841 return; | |
1842 } | |
1843 | |
1844 fgets(first, 64, f); | |
1845 | |
1846 if ((first[0] == '\n') || (first[0] == '\r' && first[1] == '\n')) | |
1847 fgets(first, 64, f); | |
1848 | |
1849 #if 0 | |
1850 if (!g_strncasecmp(first, "<xml", strlen("<xml"))) { | |
1851 /* new gaim XML buddy list */ | |
1852 gaim_blist_read(path); | |
1853 | |
1854 /* We really don't need to bother doing stuf like translating AIM 3 buddy lists anymore */ | |
1855 | |
1856 } else if (!g_strncasecmp(first, "Config {", strlen("Config {"))) { | |
1857 /* AIM 4 buddy list */ | |
1858 gaim_debug(GAIM_DEBUG_MISC, "blist import", "aim 4\n"); | |
1859 rewind(f); | |
1860 buf = translate_blt(f); | |
1861 } else if (strstr(first, "group") != NULL) { | |
1862 /* AIM 3 buddy list */ | |
1863 gaim_debug(GAIM_DEBUG_MISC, "blist import", "aim 3\n"); | |
1864 rewind(f); | |
1865 buf = translate_lst(f); | |
1866 } else if (!g_strncasecmp(first, "[User]", strlen("[User]"))) { | |
1867 /* GnomeICU (hopefully) */ | |
1868 gaim_debug(GAIM_DEBUG_MISC, "blist import", "gnomeicu\n"); | |
1869 rewind(f); | |
1870 buf = translate_gnomeicu(f); | |
1871 | |
1872 } else | |
1873 #endif | |
1874 if (first[0] == 'm') { | |
1875 /* Gaim buddy list - no translation */ | |
1876 char buf2[BUF_LONG * 2]; | |
1877 buf = g_string_new(""); | |
1878 rewind(f); | |
1879 while (1) { | |
1880 len = fread(buf2, 1, BUF_LONG * 2 - 1, f); | |
1881 if (len <= 0) | |
1882 break; | |
1883 buf2[len] = '\0'; | |
1884 buf = g_string_append(buf, buf2); | |
1885 if (len != BUF_LONG * 2 - 1) | |
1886 break; | |
1887 } | |
1888 } | |
1889 | |
1890 fclose(f); | |
1891 | |
1892 if (buf) { | |
1893 buf = g_string_prepend(buf, "toc_set_config {"); | |
1894 buf = g_string_append(buf, "}\n"); | |
7117
943085b0ff8b
[gaim-migrate @ 7684]
Christian Hammond <chipx86@chipx86.com>
parents:
7115
diff
changeset
|
1895 gaim_blist_parse_toc_buddy_list(account, buf->str); |
5228 | 1896 g_string_free(buf, TRUE); |
1897 } | |
1898 } | |
1899 | |
6695 | 1900 gboolean gaim_group_on_account(GaimGroup *g, GaimAccount *account) { |
1901 GaimBlistNode *cnode, *bnode; | |
1902 for(cnode = ((GaimBlistNode *)g)->child; cnode; cnode = cnode->next) { | |
1903 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
1904 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
1905 if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { | |
1906 GaimBuddy *buddy = (GaimBuddy *)bnode; | |
1907 if((!account && gaim_account_is_connected(buddy->account)) | |
1908 || buddy->account == account) | |
1909 return TRUE; | |
1910 } | |
1911 } | |
1912 } else if(GAIM_BLIST_NODE_IS_CHAT(cnode)) { | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1913 GaimChat *chat = (GaimChat *)cnode; |
6695 | 1914 if((!account && gaim_account_is_connected(chat->account)) |
1915 || chat->account == account) | |
1916 return TRUE; | |
1917 } | |
5228 | 1918 } |
1919 return FALSE; | |
1920 } | |
1921 | |
1922 static gboolean blist_safe_to_write = FALSE; | |
1923 | |
7132 | 1924 static void parse_setting(GaimBlistNode *node, xmlnode *setting) |
1925 { | |
1926 const char *name = xmlnode_get_attrib(setting, "name"); | |
7693 | 1927 const char *type = xmlnode_get_attrib(setting, "type"); |
7132 | 1928 char *value = xmlnode_get_data(setting); |
1929 | |
7693 | 1930 if(!value) |
1931 return; | |
1932 | |
1933 if(!type || !strcmp(type, "string")) | |
1934 gaim_blist_node_set_string(node, name, value); | |
1935 else if(!strcmp(type, "bool")) | |
1936 gaim_blist_node_set_bool(node, name, atoi(value)); | |
1937 else if(!strcmp(type, "int")) | |
1938 gaim_blist_node_set_int(node, name, atoi(value)); | |
7132 | 1939 |
1940 g_free(value); | |
1941 } | |
1942 | |
1943 static void parse_buddy(GaimGroup *group, GaimContact *contact, xmlnode *bnode) | |
1944 { | |
1945 GaimAccount *account; | |
1946 GaimBuddy *buddy; | |
7727 | 1947 char *name = NULL, *alias = NULL; |
7153 | 1948 const char *acct_name, *proto, *protocol; |
7132 | 1949 xmlnode *x; |
1950 | |
1951 acct_name = xmlnode_get_attrib(bnode, "account"); | |
7153 | 1952 protocol = xmlnode_get_attrib(bnode, "protocol"); |
1953 proto = xmlnode_get_attrib(bnode, "proto"); | |
1954 | |
1955 if(!acct_name || (!proto && !protocol)) | |
7132 | 1956 return; |
1957 | |
7153 | 1958 account = gaim_accounts_find(acct_name, proto ? proto : protocol); |
7132 | 1959 |
1960 if(!account) | |
1961 return; | |
1962 | |
1963 if((x = xmlnode_get_child(bnode, "name"))) | |
1964 name = xmlnode_get_data(x); | |
1965 | |
1966 if(!name) | |
1967 return; | |
1968 | |
1969 if((x = xmlnode_get_child(bnode, "alias"))) | |
1970 alias = xmlnode_get_data(x); | |
1971 | |
1972 buddy = gaim_buddy_new(account, name, alias); | |
1973 gaim_blist_add_buddy(buddy, contact, group, | |
1974 gaim_blist_get_last_child((GaimBlistNode*)contact)); | |
1975 | |
1976 for(x = bnode->child; x; x = x->next) { | |
1977 if(x->type != NODE_TYPE_TAG || strcmp(x->name, "setting")) | |
1978 continue; | |
1979 parse_setting((GaimBlistNode*)buddy, x); | |
1980 } | |
1981 | |
1982 g_free(name); | |
1983 if(alias) | |
1984 g_free(alias); | |
1985 } | |
1986 | |
1987 static void parse_contact(GaimGroup *group, xmlnode *cnode) | |
1988 { | |
1989 GaimContact *contact = gaim_contact_new(); | |
1990 xmlnode *x; | |
7245 | 1991 const char *alias; |
7132 | 1992 |
1993 gaim_blist_add_contact(contact, group, | |
1994 gaim_blist_get_last_child((GaimBlistNode*)group)); | |
1995 | |
7245 | 1996 if((alias = xmlnode_get_attrib(cnode, "alias"))) { |
7132 | 1997 gaim_contact_set_alias(contact, alias); |
1998 } | |
1999 | |
2000 for(x = cnode->child; x; x = x->next) { | |
2001 if(x->type != NODE_TYPE_TAG) | |
2002 continue; | |
2003 if(!strcmp(x->name, "buddy")) | |
2004 parse_buddy(group, contact, x); | |
2005 else if(strcmp(x->name, "setting")) | |
2006 parse_setting((GaimBlistNode*)contact, x); | |
5228 | 2007 } |
7825 | 2008 |
2009 /* if the contact is empty, don't keep it around. it causes problems */ | |
2010 if(!((GaimBlistNode*)contact)->child) | |
2011 gaim_blist_remove_contact(contact); | |
5228 | 2012 } |
2013 | |
7132 | 2014 static void parse_chat(GaimGroup *group, xmlnode *cnode) |
2015 { | |
2016 GaimChat *chat; | |
2017 GaimAccount *account; | |
7153 | 2018 const char *acct_name, *proto, *protocol; |
7132 | 2019 xmlnode *x; |
2020 char *alias = NULL; | |
2021 GHashTable *components; | |
2022 | |
2023 acct_name = xmlnode_get_attrib(cnode, "account"); | |
7153 | 2024 protocol = xmlnode_get_attrib(cnode, "protocol"); |
2025 proto = xmlnode_get_attrib(cnode, "proto"); | |
2026 | |
2027 if(!acct_name || (!proto && !protocol)) | |
7132 | 2028 return; |
2029 | |
7153 | 2030 account = gaim_accounts_find(acct_name, proto ? proto : protocol); |
7132 | 2031 |
2032 if(!account) | |
2033 return; | |
2034 | |
2035 if((x = xmlnode_get_child(cnode, "alias"))) | |
2036 alias = xmlnode_get_data(x); | |
2037 | |
2038 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
2039 | |
2040 for(x = cnode->child; x; x = x->next) { | |
2041 const char *name; | |
2042 char *value; | |
2043 if(x->type != NODE_TYPE_TAG || strcmp(x->name, "component")) | |
2044 continue; | |
2045 | |
2046 name = xmlnode_get_attrib(x, "name"); | |
2047 value = xmlnode_get_data(x); | |
2048 g_hash_table_replace(components, g_strdup(name), value); | |
2049 } | |
2050 | |
2051 chat = gaim_chat_new(account, alias, components); | |
7151 | 2052 gaim_blist_add_chat(chat, group, |
2053 gaim_blist_get_last_child((GaimBlistNode*)group)); | |
7132 | 2054 |
2055 for(x = cnode->child; x; x = x->next) { | |
2056 if(x->type != NODE_TYPE_TAG || strcmp(x->name, "setting")) | |
2057 continue; | |
2058 parse_setting((GaimBlistNode*)chat, x); | |
2059 } | |
2060 | |
2061 if(alias) | |
2062 g_free(alias); | |
2063 } | |
2064 | |
2065 | |
2066 static void parse_group(xmlnode *groupnode) | |
2067 { | |
2068 const char *name = xmlnode_get_attrib(groupnode, "name"); | |
2069 GaimGroup *group; | |
2070 xmlnode *cnode; | |
2071 | |
2072 if(!name) | |
2073 name = _("Buddies"); | |
2074 | |
2075 group = gaim_group_new(name); | |
2076 gaim_blist_add_group(group, | |
2077 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
2078 | |
2079 for(cnode = groupnode->child; cnode; cnode = cnode->next) { | |
2080 if(cnode->type != NODE_TYPE_TAG) | |
2081 continue; | |
2082 if(!strcmp(cnode->name, "setting")) | |
2083 parse_setting((GaimBlistNode*)group, cnode); | |
2084 else if(!strcmp(cnode->name, "contact") || | |
2085 !strcmp(cnode->name, "person")) | |
2086 parse_contact(group, cnode); | |
2087 else if(!strcmp(cnode->name, "chat")) | |
2088 parse_chat(group, cnode); | |
5228 | 2089 } |
2090 } | |
2091 | |
2092 static gboolean gaim_blist_read(const char *filename) { | |
7132 | 2093 GError *error; |
5228 | 2094 gchar *contents = NULL; |
2095 gsize length; | |
7132 | 2096 xmlnode *gaim, *blist, *privacy; |
5228 | 2097 |
2098 gaim_debug(GAIM_DEBUG_INFO, "blist import", | |
2099 "Reading %s\n", filename); | |
2100 if(!g_file_get_contents(filename, &contents, &length, &error)) { | |
2101 gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
2102 "Error reading blist: %s\n", error->message); | |
2103 g_error_free(error); | |
2104 return FALSE; | |
2105 } | |
2106 | |
7132 | 2107 gaim = xmlnode_from_str(contents, length); |
2108 g_free(contents); | |
2109 | |
2110 if(!gaim) { | |
2111 gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Error parsing %s\n", | |
2112 filename); | |
5228 | 2113 return FALSE; |
2114 } | |
2115 | |
7132 | 2116 blist = xmlnode_get_child(gaim, "blist"); |
2117 if(blist) { | |
2118 xmlnode *groupnode; | |
2119 for(groupnode = blist->child; groupnode; groupnode = groupnode->next) { | |
2120 if(groupnode->type != NODE_TYPE_TAG || | |
2121 strcmp(groupnode->name, "group")) | |
2122 continue; | |
2123 | |
2124 parse_group(groupnode); | |
2125 } | |
5228 | 2126 } |
2127 | |
7132 | 2128 privacy = xmlnode_get_child(gaim, "privacy"); |
2129 if(privacy) { | |
2130 xmlnode *anode; | |
2131 for(anode = privacy->child; anode; anode = anode->next) { | |
2132 xmlnode *x; | |
2133 GaimAccount *account; | |
7153 | 2134 const char *acct_name, *proto, *mode, *protocol; |
7132 | 2135 |
2136 acct_name = xmlnode_get_attrib(anode, "name"); | |
7153 | 2137 protocol = xmlnode_get_attrib(anode, "protocol"); |
2138 proto = xmlnode_get_attrib(anode, "proto"); | |
7132 | 2139 mode = xmlnode_get_attrib(anode, "mode"); |
2140 | |
7153 | 2141 if(!acct_name || (!proto && !protocol) || !mode) |
7132 | 2142 continue; |
2143 | |
7153 | 2144 account = gaim_accounts_find(acct_name, proto ? proto : protocol); |
7132 | 2145 |
2146 if(!account) | |
2147 continue; | |
2148 | |
2149 account->perm_deny = atoi(mode); | |
2150 | |
2151 for(x = anode->child; x; x = x->next) { | |
2152 char *name; | |
2153 if(x->type != NODE_TYPE_TAG) | |
2154 continue; | |
2155 | |
2156 if(!strcmp(x->name, "permit")) { | |
2157 name = xmlnode_get_data(x); | |
2158 gaim_privacy_permit_add(account, name, TRUE); | |
2159 g_free(name); | |
2160 } else if(!strcmp(x->name, "block")) { | |
2161 name = xmlnode_get_data(x); | |
2162 gaim_privacy_deny_add(account, name, TRUE); | |
2163 g_free(name); | |
2164 } | |
2165 } | |
2166 } | |
2167 } | |
5228 | 2168 |
2169 gaim_debug(GAIM_DEBUG_INFO, "blist import", "Finished reading %s\n", | |
2170 filename); | |
2171 | |
2172 return TRUE; | |
2173 } | |
2174 | |
2175 void gaim_blist_load() { | |
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2176 GList *accts; |
5228 | 2177 char *user_dir = gaim_user_dir(); |
2178 char *filename; | |
2179 char *msg; | |
2180 | |
2181 blist_safe_to_write = TRUE; | |
2182 | |
2183 if(!user_dir) | |
2184 return; | |
2185 | |
2186 filename = g_build_filename(user_dir, "blist.xml", NULL); | |
2187 | |
2188 if(g_file_test(filename, G_FILE_TEST_EXISTS)) { | |
2189 if(!gaim_blist_read(filename)) { | |
2190 msg = g_strdup_printf(_("An error was encountered parsing your " | |
2191 "buddy list. It has not been loaded.")); | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
2192 gaim_notify_error(NULL, NULL, _("Buddy List Error"), msg); |
5228 | 2193 g_free(msg); |
2194 } | |
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2195 } else if(g_list_length(gaim_accounts_get_all())) { |
5228 | 2196 /* 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
|
2197 for(accts = gaim_accounts_get_all(); accts; accts = accts->next) { |
5228 | 2198 do_import(accts->data, NULL); |
2199 } | |
2200 gaim_blist_save(); | |
2201 } | |
2202 | |
2203 g_free(filename); | |
2204 } | |
2205 | |
7060
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2206 void |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2207 gaim_blist_request_add_buddy(GaimAccount *account, const char *username, |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2208 const char *group, const char *alias) |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2209 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2210 GaimBlistUiOps *ui_ops; |
7060
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2211 |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2212 ui_ops = gaim_blist_get_ui_ops(); |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2213 |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2214 if (ui_ops != NULL && ui_ops->request_add_buddy != NULL) |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2215 ui_ops->request_add_buddy(account, username, group, alias); |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2216 } |
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 void |
7859 | 2219 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
|
2220 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2221 GaimBlistUiOps *ui_ops; |
7060
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2222 |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2223 ui_ops = gaim_blist_get_ui_ops(); |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2224 |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2225 if (ui_ops != NULL && ui_ops->request_add_chat != NULL) |
7859 | 2226 ui_ops->request_add_chat(account, group, alias); |
7060
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2227 } |
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 void |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2230 gaim_blist_request_add_group(void) |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2231 { |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2232 GaimBlistUiOps *ui_ops; |
7060
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2233 |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2234 ui_ops = gaim_blist_get_ui_ops(); |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2235 |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2236 if (ui_ops != NULL && ui_ops->request_add_group != NULL) |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2237 ui_ops->request_add_group(); |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2238 } |
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2239 |
7693 | 2240 static void blist_print_setting(const char *key, |
2241 struct gaim_blist_node_setting *setting, FILE *file, int indent) | |
2242 { | |
2243 char *key_val, *data_val = NULL; | |
2244 const char *type = NULL; | |
2245 int i; | |
2246 | |
2247 if(!key) | |
2248 return; | |
2249 | |
2250 switch(setting->type) { | |
2251 case GAIM_BLIST_NODE_SETTING_BOOL: | |
2252 type = "bool"; | |
2253 data_val = g_strdup_printf("%d", setting->value.boolean); | |
2254 break; | |
2255 case GAIM_BLIST_NODE_SETTING_INT: | |
2256 type = "int"; | |
2257 data_val = g_strdup_printf("%d", setting->value.integer); | |
2258 break; | |
2259 case GAIM_BLIST_NODE_SETTING_STRING: | |
2260 if(!setting->value.string) | |
2261 return; | |
2262 | |
2263 type = "string"; | |
2264 data_val = g_markup_escape_text(setting->value.string, -1); | |
2265 break; | |
2266 } | |
2267 | |
2268 /* this can't happen */ | |
2269 if(!type || !data_val) | |
2270 return; | |
2271 | |
2272 for(i=0; i<indent; i++) fprintf(file, "\t"); | |
2273 | |
2274 key_val = g_markup_escape_text(key, -1); | |
2275 fprintf(file, "<setting name=\"%s\" type=\"%s\">%s</setting>\n", key_val, type, | |
2276 data_val); | |
2277 | |
2278 g_free(key_val); | |
2279 g_free(data_val); | |
2280 } | |
2281 | |
5228 | 2282 static void blist_print_group_settings(gpointer key, gpointer data, |
2283 gpointer user_data) { | |
7693 | 2284 blist_print_setting(key, data, user_data, 3); |
5228 | 2285 } |
2286 | |
2287 static void blist_print_buddy_settings(gpointer key, gpointer data, | |
2288 gpointer user_data) { | |
7693 | 2289 blist_print_setting(key, data, user_data, 5); |
5228 | 2290 } |
2291 | |
6695 | 2292 static void blist_print_cnode_settings(gpointer key, gpointer data, |
2293 gpointer user_data) { | |
7693 | 2294 blist_print_setting(key, data, user_data, 4); |
6695 | 2295 } |
2296 | |
5234 | 2297 static void blist_print_chat_components(gpointer key, gpointer data, |
2298 gpointer user_data) { | |
2299 char *key_val; | |
2300 char *data_val; | |
2301 FILE *file = user_data; | |
2302 | |
2303 if(!key || !data) | |
2304 return; | |
2305 | |
2306 key_val = g_markup_escape_text(key, -1); | |
2307 data_val = g_markup_escape_text(data, -1); | |
2308 | |
2309 fprintf(file, "\t\t\t\t<component name=\"%s\">%s</component>\n", key_val, | |
2310 data_val); | |
2311 g_free(key_val); | |
2312 g_free(data_val); | |
2313 } | |
2314 | |
6695 | 2315 static void print_buddy(FILE *file, GaimBuddy *buddy) { |
2316 char *bud_name = g_markup_escape_text(buddy->name, -1); | |
2317 char *bud_alias = NULL; | |
2318 char *acct_name = g_markup_escape_text(buddy->account->username, -1); | |
7153 | 2319 int proto_num = gaim_account_get_protocol(buddy->account); |
6695 | 2320 if(buddy->alias) |
2321 bud_alias= g_markup_escape_text(buddy->alias, -1); | |
7153 | 2322 fprintf(file, "\t\t\t\t<buddy account=\"%s\" proto=\"%s\"", acct_name, |
2323 gaim_account_get_protocol_id(buddy->account)); | |
2324 if(proto_num != -1) | |
2325 fprintf(file, " protocol=\"%d\"", proto_num); | |
2326 fprintf(file, ">\n"); | |
2327 | |
6695 | 2328 fprintf(file, "\t\t\t\t\t<name>%s</name>\n", bud_name); |
2329 if(bud_alias) { | |
2330 fprintf(file, "\t\t\t\t\t<alias>%s</alias>\n", bud_alias); | |
2331 } | |
7726 | 2332 g_hash_table_foreach(buddy->node.settings, blist_print_buddy_settings, file); |
6695 | 2333 fprintf(file, "\t\t\t\t</buddy>\n"); |
2334 g_free(bud_name); | |
2335 g_free(bud_alias); | |
2336 g_free(acct_name); | |
2337 } | |
2338 | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
2339 static void gaim_blist_write(FILE *file, GaimAccount *exp_acct) { |
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2340 GList *accounts; |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2341 GSList *buds; |
6695 | 2342 GaimBlistNode *gnode, *cnode, *bnode; |
5228 | 2343 fprintf(file, "<?xml version='1.0' encoding='UTF-8' ?>\n"); |
2344 fprintf(file, "<gaim version=\"1\">\n"); | |
2345 fprintf(file, "\t<blist>\n"); | |
2346 | |
2347 for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { | |
6695 | 2348 GaimGroup *group; |
2349 | |
5228 | 2350 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) |
2351 continue; | |
6695 | 2352 |
2353 group = (GaimGroup *)gnode; | |
5228 | 2354 if(!exp_acct || gaim_group_on_account(group, exp_acct)) { |
2355 char *group_name = g_markup_escape_text(group->name, -1); | |
2356 fprintf(file, "\t\t<group name=\"%s\">\n", group_name); | |
7693 | 2357 g_hash_table_foreach(group->node.settings, |
2358 blist_print_group_settings, file); | |
6695 | 2359 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
2360 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
6755 | 2361 GaimContact *contact = (GaimContact*)cnode; |
2362 fprintf(file, "\t\t\t<contact"); | |
2363 if(contact->alias) { | |
2364 char *alias = g_markup_escape_text(contact->alias, -1); | |
2365 fprintf(file, " alias=\"%s\"", alias); | |
2366 g_free(alias); | |
2367 } | |
2368 fprintf(file, ">\n"); | |
6695 | 2369 |
2370 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
2371 if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { | |
2372 GaimBuddy *buddy = (GaimBuddy *)bnode; | |
2373 if(!exp_acct || buddy->account == exp_acct) { | |
2374 print_buddy(file, buddy); | |
2375 } | |
5234 | 2376 } |
5228 | 2377 } |
6695 | 2378 |
2379 fprintf(file, "\t\t\t</contact>\n"); | |
2380 } else if(GAIM_BLIST_NODE_IS_CHAT(cnode)) { | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
2381 GaimChat *chat = (GaimChat *)cnode; |
5234 | 2382 if(!exp_acct || chat->account == exp_acct) { |
2383 char *acct_name = g_markup_escape_text(chat->account->username, -1); | |
7153 | 2384 int proto_num = gaim_account_get_protocol(chat->account); |
2385 fprintf(file, "\t\t\t<chat proto=\"%s\" account=\"%s\"", | |
7133 | 2386 gaim_account_get_protocol_id(chat->account), |
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
2387 acct_name); |
7153 | 2388 if(proto_num != -1) |
2389 fprintf(file, " protocol=\"%d\"", proto_num); | |
2390 fprintf(file, ">\n"); | |
2391 | |
5237 | 2392 if(chat->alias) { |
2393 char *chat_alias = g_markup_escape_text(chat->alias, -1); | |
2394 fprintf(file, "\t\t\t\t<alias>%s</alias>\n", chat_alias); | |
2395 g_free(chat_alias); | |
2396 } | |
5234 | 2397 g_hash_table_foreach(chat->components, |
2398 blist_print_chat_components, file); | |
7693 | 2399 g_hash_table_foreach(chat->node.settings, |
6695 | 2400 blist_print_cnode_settings, file); |
5234 | 2401 fprintf(file, "\t\t\t</chat>\n"); |
5237 | 2402 g_free(acct_name); |
5234 | 2403 } |
5228 | 2404 } |
2405 } | |
2406 fprintf(file, "\t\t</group>\n"); | |
2407 g_free(group_name); | |
2408 } | |
2409 } | |
2410 | |
2411 fprintf(file, "\t</blist>\n"); | |
2412 fprintf(file, "\t<privacy>\n"); | |
2413 | |
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2414 for(accounts = gaim_accounts_get_all(); |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2415 accounts != NULL; |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2416 accounts = accounts->next) { |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2417 |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
2418 GaimAccount *account = accounts->data; |
5228 | 2419 char *acct_name = g_markup_escape_text(account->username, -1); |
7153 | 2420 int proto_num = gaim_account_get_protocol(account); |
5228 | 2421 if(!exp_acct || account == exp_acct) { |
7153 | 2422 fprintf(file, "\t\t<account proto=\"%s\" name=\"%s\" " |
2423 "mode=\"%d\"", gaim_account_get_protocol_id(account), | |
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
2424 acct_name, account->perm_deny); |
7153 | 2425 if(proto_num != -1) |
2426 fprintf(file, " protocol=\"%d\"", proto_num); | |
2427 fprintf(file, ">\n"); | |
2428 | |
5228 | 2429 for(buds = account->permit; buds; buds = buds->next) { |
2430 char *bud_name = g_markup_escape_text(buds->data, -1); | |
2431 fprintf(file, "\t\t\t<permit>%s</permit>\n", bud_name); | |
2432 g_free(bud_name); | |
2433 } | |
2434 for(buds = account->deny; buds; buds = buds->next) { | |
2435 char *bud_name = g_markup_escape_text(buds->data, -1); | |
2436 fprintf(file, "\t\t\t<block>%s</block>\n", bud_name); | |
2437 g_free(bud_name); | |
2438 } | |
2439 fprintf(file, "\t\t</account>\n"); | |
2440 } | |
2441 g_free(acct_name); | |
2442 } | |
2443 | |
2444 fprintf(file, "\t</privacy>\n"); | |
2445 fprintf(file, "</gaim>\n"); | |
2446 } | |
2447 | |
2448 void gaim_blist_save() { | |
2449 FILE *file; | |
2450 char *user_dir = gaim_user_dir(); | |
2451 char *filename; | |
2452 char *filename_real; | |
2453 | |
2454 if(!user_dir) | |
2455 return; | |
2456 if(!blist_safe_to_write) { | |
2457 gaim_debug(GAIM_DEBUG_WARNING, "blist save", | |
2458 "AHH!! Tried to write the blist before we read it!\n"); | |
2459 return; | |
2460 } | |
2461 | |
2462 file = fopen(user_dir, "r"); | |
2463 if(!file) | |
2464 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
2465 else | |
2466 fclose(file); | |
2467 | |
2468 filename = g_build_filename(user_dir, "blist.xml.save", NULL); | |
2469 | |
2470 if((file = fopen(filename, "w"))) { | |
2471 gaim_blist_write(file, NULL); | |
2472 fclose(file); | |
2473 chmod(filename, S_IRUSR | S_IWUSR); | |
2474 } else { | |
2475 gaim_debug(GAIM_DEBUG_ERROR, "blist save", "Unable to write %s\n", | |
2476 filename); | |
2477 } | |
2478 | |
2479 filename_real = g_build_filename(user_dir, "blist.xml", NULL); | |
2480 | |
2481 if(rename(filename, filename_real) < 0) | |
2482 gaim_debug(GAIM_DEBUG_ERROR, "blist save", | |
2483 "Error renaming %s to %s\n", filename, filename_real); | |
2484 | |
2485 | |
2486 g_free(filename); | |
2487 g_free(filename_real); | |
2488 } | |
2489 | |
7693 | 2490 |
2491 static void gaim_blist_node_setting_free(struct gaim_blist_node_setting *setting) | |
2492 { | |
2493 switch(setting->type) { | |
2494 case GAIM_BLIST_NODE_SETTING_BOOL: | |
2495 case GAIM_BLIST_NODE_SETTING_INT: | |
2496 break; | |
2497 case GAIM_BLIST_NODE_SETTING_STRING: | |
2498 g_free(setting->value.string); | |
2499 break; | |
2500 } | |
2501 } | |
2502 | |
2503 static void gaim_blist_node_initialize_settings(GaimBlistNode* node) | |
2504 { | |
2505 if(node->settings) | |
5228 | 2506 return; |
7693 | 2507 |
2508 node->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, | |
2509 (GDestroyNotify)gaim_blist_node_setting_free); | |
2510 } | |
2511 | |
2512 void gaim_blist_node_remove_setting(GaimBlistNode *node, const char *key) | |
2513 { | |
2514 g_return_if_fail(node != NULL); | |
2515 g_return_if_fail(node->settings != NULL); | |
2516 g_return_if_fail(key != NULL); | |
2517 | |
2518 g_hash_table_remove(node->settings, key); | |
5228 | 2519 } |
2520 | |
7693 | 2521 |
2522 void gaim_blist_node_set_bool(GaimBlistNode* node, const char *key, gboolean value) | |
2523 { | |
2524 struct gaim_blist_node_setting *setting; | |
2525 | |
2526 g_return_if_fail(node != NULL); | |
2527 g_return_if_fail(node->settings != NULL); | |
2528 g_return_if_fail(key != NULL); | |
2529 | |
2530 setting = g_new0(struct gaim_blist_node_setting, 1); | |
2531 setting->type = GAIM_BLIST_NODE_SETTING_BOOL; | |
2532 setting->value.boolean = value; | |
2533 | |
2534 g_hash_table_replace(node->settings, g_strdup(key), setting); | |
2535 } | |
2536 | |
2537 gboolean gaim_blist_node_get_bool(GaimBlistNode* node, const char *key) | |
2538 { | |
2539 struct gaim_blist_node_setting *setting; | |
2540 | |
2541 g_return_val_if_fail(node != NULL, FALSE); | |
2542 g_return_val_if_fail(node->settings != NULL, FALSE); | |
2543 g_return_val_if_fail(key != NULL, FALSE); | |
2544 | |
2545 setting = g_hash_table_lookup(node->settings, key); | |
2546 | |
7849 | 2547 if(!setting) |
2548 return FALSE; | |
2549 | |
7848 | 2550 g_return_val_if_fail(setting->type == GAIM_BLIST_NODE_SETTING_BOOL, FALSE); |
2551 | |
2552 return setting->value.boolean; | |
5228 | 2553 } |
2554 | |
7693 | 2555 void gaim_blist_node_set_int(GaimBlistNode* node, const char *key, int value) |
2556 { | |
2557 struct gaim_blist_node_setting *setting; | |
2558 | |
2559 g_return_if_fail(node != NULL); | |
2560 g_return_if_fail(node->settings != NULL); | |
2561 g_return_if_fail(key != NULL); | |
2562 | |
2563 setting = g_new0(struct gaim_blist_node_setting, 1); | |
2564 setting->type = GAIM_BLIST_NODE_SETTING_STRING; | |
2565 setting->value.integer = value; | |
2566 | |
2567 g_hash_table_replace(node->settings, g_strdup(key), setting); | |
2568 } | |
2569 | |
2570 int gaim_blist_node_get_int(GaimBlistNode* node, const char *key) | |
2571 { | |
2572 struct gaim_blist_node_setting *setting; | |
2573 | |
2574 g_return_val_if_fail(node != NULL, 0); | |
2575 g_return_val_if_fail(node->settings != NULL, 0); | |
2576 g_return_val_if_fail(key != NULL, 0); | |
2577 | |
2578 setting = g_hash_table_lookup(node->settings, key); | |
2579 | |
7849 | 2580 if(!setting) |
2581 return 0; | |
2582 | |
7848 | 2583 g_return_val_if_fail(setting->type == GAIM_BLIST_NODE_SETTING_INT, 0); |
2584 | |
2585 return setting->value.integer; | |
7693 | 2586 } |
2587 | |
2588 void gaim_blist_node_set_string(GaimBlistNode* node, const char *key, | |
5906 | 2589 const char *value) |
2590 { | |
7693 | 2591 struct gaim_blist_node_setting *setting; |
2592 | |
2593 g_return_if_fail(node != NULL); | |
2594 g_return_if_fail(node->settings != NULL); | |
2595 g_return_if_fail(key != NULL); | |
2596 | |
2597 setting = g_new0(struct gaim_blist_node_setting, 1); | |
2598 setting->type = GAIM_BLIST_NODE_SETTING_STRING; | |
2599 setting->value.string = g_strdup(value); | |
2600 | |
2601 g_hash_table_replace(node->settings, g_strdup(key), setting); | |
2602 } | |
2603 | |
2604 const char *gaim_blist_node_get_string(GaimBlistNode* node, const char *key) | |
2605 { | |
2606 struct gaim_blist_node_setting *setting; | |
2607 | |
2608 g_return_val_if_fail(node != NULL, NULL); | |
2609 g_return_val_if_fail(node->settings != NULL, NULL); | |
2610 g_return_val_if_fail(key != NULL, NULL); | |
2611 | |
2612 setting = g_hash_table_lookup(node->settings, key); | |
2613 | |
7849 | 2614 if(!setting) |
2615 return NULL; | |
2616 | |
7848 | 2617 g_return_val_if_fail(setting->type == GAIM_BLIST_NODE_SETTING_STRING, NULL); |
2618 | |
2619 return setting->value.string; | |
7693 | 2620 } |
2621 | |
2622 | |
2623 /* XXX: this is compatability stuff. Remove after.... oh, I dunno... 0.77 or so */ | |
2624 | |
2625 void gaim_group_set_setting(GaimGroup *g, const char *key, const char *value) | |
2626 { | |
2627 gaim_debug_warning("blist", "gaim_group_set_setting() is deprecated\n"); | |
2628 | |
2629 gaim_blist_node_set_string((GaimBlistNode*)g, key, value); | |
2630 } | |
2631 | |
2632 const char *gaim_group_get_setting(GaimGroup *g, const char *key) | |
2633 { | |
2634 gaim_debug_warning("blist", "gaim_group_get_setting() is deprecated\n"); | |
2635 | |
2636 return gaim_blist_node_get_string((GaimBlistNode*)g, key); | |
2637 } | |
2638 | |
2639 void gaim_chat_set_setting(GaimChat *c, const char *key, const char *value) | |
2640 { | |
2641 gaim_debug_warning("blist", "gaim_chat_set_setting() is deprecated\n"); | |
2642 | |
2643 gaim_blist_node_set_string((GaimBlistNode*)c, key, value); | |
5906 | 2644 } |
2645 | |
7125 | 2646 const char *gaim_chat_get_setting(GaimChat *c, const char *key) |
5906 | 2647 { |
7693 | 2648 gaim_debug_warning("blist", "gaim_chat_get_setting() is deprecated\n"); |
2649 | |
2650 return gaim_blist_node_get_string((GaimBlistNode*)c, key); | |
5906 | 2651 } |
2652 | |
7693 | 2653 void gaim_buddy_set_setting(GaimBuddy *b, const char *key, const char *value) |
2654 { | |
2655 gaim_debug_warning("blist", "gaim_buddy_set_setting() is deprecated\n"); | |
2656 | |
2657 gaim_blist_node_set_string((GaimBlistNode*)b, key, value); | |
5228 | 2658 } |
2659 | |
7693 | 2660 const char *gaim_buddy_get_setting(GaimBuddy *b, const char *key) |
2661 { | |
2662 gaim_debug_warning("blist", "gaim_buddy_get_setting() is deprecated\n"); | |
2663 | |
2664 return gaim_blist_node_get_string((GaimBlistNode*)b, key); | |
5228 | 2665 } |
2666 | |
7693 | 2667 /* XXX: end compat crap */ |
2668 | |
6695 | 2669 int gaim_blist_get_group_size(GaimGroup *group, gboolean offline) { |
5228 | 2670 if(!group) |
2671 return 0; | |
2672 | |
5277 | 2673 return offline ? group->totalsize : group->currentsize; |
5228 | 2674 } |
2675 | |
6695 | 2676 int gaim_blist_get_group_online_count(GaimGroup *group) { |
5228 | 2677 if(!group) |
2678 return 0; | |
2679 | |
5277 | 2680 return group->online; |
5228 | 2681 } |
2682 | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2683 void |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2684 gaim_blist_set_ui_ops(GaimBlistUiOps *ops) |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2685 { |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2686 blist_ui_ops = ops; |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2687 } |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2688 |
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2689 GaimBlistUiOps * |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2690 gaim_blist_get_ui_ops(void) |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2691 { |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2692 return blist_ui_ops; |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2693 } |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2694 |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2695 |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2696 void * |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2697 gaim_blist_get_handle(void) |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2698 { |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2699 static int handle; |
5228 | 2700 |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2701 return &handle; |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2702 } |
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 void |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2705 gaim_blist_init(void) |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2706 { |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2707 void *handle = gaim_blist_get_handle(); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2708 |
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2709 gaim_signal_register(handle, "buddy-away", |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2710 gaim_marshal_VOID__POINTER, NULL, 1, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2711 gaim_value_new(GAIM_TYPE_SUBTYPE, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2712 GAIM_SUBTYPE_BLIST_BUDDY)); |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2713 |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2714 gaim_signal_register(handle, "buddy-back", |
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)); |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2718 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2719 gaim_signal_register(handle, "buddy-idle", |
6564
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 gaim_signal_register(handle, "buddy-unidle", |
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2724 gaim_marshal_VOID__POINTER, NULL, 1, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2725 gaim_value_new(GAIM_TYPE_SUBTYPE, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2726 GAIM_SUBTYPE_BLIST_BUDDY)); |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2727 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2728 gaim_signal_register(handle, "buddy-signed-on", |
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)); |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2732 |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2733 gaim_signal_register(handle, "buddy-signed-off", |
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)); |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2737 |
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2738 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
|
2739 } |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2740 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2741 void |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2742 gaim_blist_uninit(void) |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2743 { |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2744 gaim_signals_unregister_by_instance(gaim_blist_get_handle()); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2745 } |