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