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