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