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