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