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