Mercurial > pidgin
annotate src/blist.c @ 10368:ffb5f76d6188
[gaim-migrate @ 11587]
whitespace, and remove a unused variable
committer: Tailor Script <tailor@pidgin.im>
| author | Tim Ringenbach <marv@pidgin.im> |
|---|---|
| date | Tue, 14 Dec 2004 20:08:13 +0000 |
| parents | 655c48791b3c |
| children | 28135f8c226d |
| 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; |
| 7420 | 137 |
| 9285 | 138 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode)) |
| 6843 | 139 continue; |
| 9949 | 140 |
| 6843 | 141 buddy = (GaimBuddy*)bnode; |
| 9949 | 142 |
| 9285 | 143 if (!gaim_account_is_connected(buddy->account)) |
| 6843 | 144 continue; |
| 9949 | 145 if (new_priority == NULL) |
| 146 new_priority = buddy; | |
| 147 else | |
| 148 { | |
| 149 int cmp; | |
| 150 | |
| 10368 | 151 cmp = gaim_presence_compare(gaim_buddy_get_presence(new_priority), |
| 152 gaim_buddy_get_presence(buddy)); | |
| 9949 | 153 |
| 154 if (cmp > 0 || (cmp == 0 && | |
| 10368 | 155 gaim_prefs_get_bool("/core/contact/last_match"))) |
| 9949 | 156 { |
| 157 new_priority = buddy; | |
| 158 } | |
| 159 } | |
| 6843 | 160 } |
| 9949 | 161 |
| 162 contact->priority = new_priority; | |
| 6843 | 163 } |
| 164 | |
| 9285 | 165 static gboolean blist_save_callback(gpointer data) |
| 166 { | |
| 167 gaim_blist_sync(); | |
| 168 blist_save_timer = 0; | |
| 169 return FALSE; | |
| 170 } | |
| 171 | |
| 9741 | 172 static void schedule_blist_save() |
| 9285 | 173 { |
| 174 if (blist_save_timer != 0) | |
| 175 gaim_timeout_remove(blist_save_timer); | |
| 176 blist_save_timer = gaim_timeout_add(1000, blist_save_callback, NULL); | |
| 177 } | |
| 178 | |
| 6843 | 179 |
| 5228 | 180 /***************************************************************************** |
| 181 * Public API functions * | |
| 182 *****************************************************************************/ | |
| 183 | |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
184 GaimBuddyList *gaim_blist_new() |
| 5228 | 185 { |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
186 GaimBuddyList *gbl = g_new0(GaimBuddyList, 1); |
| 5228 | 187 |
|
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
188 gbl->ui_ops = gaim_blist_get_ui_ops(); |
| 5228 | 189 |
| 6742 | 190 gbl->buddies = g_hash_table_new_full((GHashFunc)_gaim_blist_hbuddy_hash, |
| 191 (GEqualFunc)_gaim_blist_hbuddy_equal, | |
| 192 (GDestroyNotify)_gaim_blist_hbuddy_free_key, NULL); | |
| 5247 | 193 |
| 5228 | 194 if (gbl->ui_ops != NULL && gbl->ui_ops->new_list != NULL) |
| 195 gbl->ui_ops->new_list(gbl); | |
| 196 | |
| 10087 | 197 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
|
198 blist_pref_cb, NULL); |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
199 |
| 5228 | 200 return gbl; |
| 201 } | |
| 202 | |
| 203 void | |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
204 gaim_set_blist(GaimBuddyList *list) |
| 5228 | 205 { |
| 206 gaimbuddylist = list; | |
| 207 } | |
| 208 | |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
209 GaimBuddyList * |
| 9285 | 210 gaim_get_blist() |
| 5228 | 211 { |
| 212 return gaimbuddylist; | |
| 213 } | |
| 214 | |
| 9285 | 215 void gaim_blist_show() |
| 5228 | 216 { |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
217 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
| 9285 | 218 |
| 219 if (ops && ops->show) | |
| 5228 | 220 ops->show(gaimbuddylist); |
| 221 } | |
| 222 | |
| 223 void gaim_blist_destroy() | |
| 224 { | |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
225 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
| 9285 | 226 |
|
8259
4f9f68ab8770
[gaim-migrate @ 8982]
Christian Hammond <chipx86@chipx86.com>
parents:
8200
diff
changeset
|
227 gaim_debug(GAIM_DEBUG_INFO, "blist", "Destroying\n"); |
| 9285 | 228 |
| 229 if (ops && ops->destroy) | |
| 5228 | 230 ops->destroy(gaimbuddylist); |
| 231 } | |
| 232 | |
| 9285 | 233 void gaim_blist_set_visible(gboolean show) |
| 5228 | 234 { |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
235 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
| 9285 | 236 |
| 237 if (ops && ops->set_visible) | |
| 5228 | 238 ops->set_visible(gaimbuddylist, show); |
| 239 } | |
| 240 | |
| 9285 | 241 static gboolean presence_update_timeout_cb(GaimBuddy *buddy) |
| 242 { | |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
243 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
|
6640
314111e7b601
[gaim-migrate @ 7165]
Christian Hammond <chipx86@chipx86.com>
parents:
6564
diff
changeset
|
244 GaimConversation *conv; |
|
314111e7b601
[gaim-migrate @ 7165]
Christian Hammond <chipx86@chipx86.com>
parents:
6564
diff
changeset
|
245 |
| 9285 | 246 g_return_val_if_fail(buddy != NULL, FALSE); |
| 247 | |
| 248 if (buddy->present == GAIM_BUDDY_SIGNING_ON) { | |
| 5228 | 249 buddy->present = GAIM_BUDDY_ONLINE; |
| 9285 | 250 } else if (buddy->present == GAIM_BUDDY_SIGNING_OFF) { |
| 5228 | 251 buddy->present = GAIM_BUDDY_OFFLINE; |
| 6860 | 252 ((GaimContact*)((GaimBlistNode*)buddy)->parent)->online--; |
| 9285 | 253 if (((GaimContact*)((GaimBlistNode*)buddy)->parent)->online == 0) |
| 6860 | 254 ((GaimGroup *)((GaimBlistNode *)buddy)->parent->parent)->online--; |
| 5228 | 255 } |
| 256 | |
| 257 buddy->timer = 0; | |
| 258 | |
| 9285 | 259 if (ops && ops->update) |
| 5228 | 260 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); |
| 261 | |
| 10246 | 262 conv = gaim_find_conversation_with_account(GAIM_CONV_IM, buddy->name, |
| 263 buddy->account); | |
|
6392
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
264 if (conv) { |
|
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
265 if (buddy->present == GAIM_BUDDY_ONLINE) |
|
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
266 gaim_conversation_update(conv, GAIM_CONV_ACCOUNT_ONLINE); |
|
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
267 else if (buddy->present == GAIM_BUDDY_OFFLINE) |
|
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
268 gaim_conversation_update(conv, GAIM_CONV_ACCOUNT_OFFLINE); |
|
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
269 } |
|
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
270 |
| 5228 | 271 return FALSE; |
| 272 } | |
| 273 | |
| 10052 | 274 void |
| 275 gaim_blist_update_buddy_status(GaimBuddy *buddy, GaimStatus *old_status) | |
| 9285 | 276 { |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
277 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
| 10052 | 278 GaimPresence *presence; |
| 279 GaimStatus *status; | |
| 9285 | 280 |
| 281 g_return_if_fail(buddy != NULL); | |
| 5228 | 282 |
| 10052 | 283 presence = gaim_buddy_get_presence(buddy); |
| 284 status = gaim_presence_get_active_status(presence); | |
| 285 | |
| 286 gaim_debug_info("blist", "Updating buddy status\n"); | |
| 287 | |
| 288 if (gaim_status_is_online(status) && | |
| 289 !gaim_status_is_online(old_status)) { | |
| 6901 | 290 int old_present = buddy->present; |
| 10052 | 291 |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
292 gaim_signal_emit(gaim_blist_get_handle(), "buddy-signed-on", buddy); |
| 9285 | 293 if (old_present != GAIM_BUDDY_SIGNING_OFF) { |
| 6901 | 294 ((GaimContact*)((GaimBlistNode*)buddy)->parent)->online++; |
| 9285 | 295 if (((GaimContact*)((GaimBlistNode*)buddy)->parent)->online == 1) |
| 6901 | 296 ((GaimGroup *)((GaimBlistNode *)buddy)->parent->parent)->online++; |
| 297 } | |
| 10052 | 298 if (buddy->timer > 0) |
| 299 gaim_timeout_remove(buddy->timer); | |
| 300 buddy->timer = gaim_timeout_add(10000, (GSourceFunc)presence_update_timeout_cb, buddy); | |
| 301 | |
| 302 } else if (!gaim_status_is_online(status) && | |
| 303 gaim_status_is_online(old_status)) { | |
| 5228 | 304 buddy->present = GAIM_BUDDY_SIGNING_OFF; |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
305 gaim_signal_emit(gaim_blist_get_handle(), "buddy-signed-off", buddy); |
| 10052 | 306 if (buddy->timer > 0) |
| 307 gaim_timeout_remove(buddy->timer); | |
| 308 buddy->timer = gaim_timeout_add(10000, (GSourceFunc)presence_update_timeout_cb, buddy); | |
| 309 | |
| 310 } else if (gaim_status_is_available(status) && | |
| 311 !gaim_status_is_available(old_status)) { | |
| 312 gaim_signal_emit(gaim_blist_get_handle(), "buddy-back", buddy); | |
| 313 | |
| 314 } else if (!gaim_status_is_available(status) && | |
| 315 gaim_status_is_available(old_status)) { | |
| 316 gaim_signal_emit(gaim_blist_get_handle(), "buddy-away", buddy); | |
| 317 | |
| 5228 | 318 } |
| 319 | |
| 10205 | 320 /* |
| 321 * This function used to only call the following two functions if one of | |
| 322 * the above signals had been triggered, but that's not good, because | |
| 323 * if someone's away message changes and they don't go from away to back | |
| 324 * to away then no signal is triggered. | |
| 325 * | |
| 326 * It's a safe assumption that SOMETHING called this function. PROBABLY | |
| 327 * because something, somewhere changed. Calling the stuff below | |
| 328 * certainly won't hurt anything. Unless you're on a K6-2 300. | |
| 329 */ | |
| 330 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); | |
| 331 if (ops && ops->update) | |
| 332 ops->update(gaimbuddylist, (GaimBlistNode *)buddy); | |
| 5228 | 333 } |
| 334 | |
| 9285 | 335 void gaim_blist_update_buddy_signon(GaimBuddy *buddy, time_t signon) |
| 7950 | 336 { |
| 337 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; | |
| 9285 | 338 |
| 339 g_return_if_fail(buddy != NULL); | |
| 340 | |
| 341 if (buddy->signon == signon) | |
| 7950 | 342 return; |
| 343 | |
| 344 buddy->signon = signon; | |
| 9285 | 345 |
| 346 if (ops && ops->update) | |
| 347 ops->update(gaimbuddylist, (GaimBlistNode *)buddy); | |
| 7950 | 348 } |
| 5228 | 349 |
| 9285 | 350 void gaim_blist_update_buddy_icon(GaimBuddy *buddy) |
| 5228 | 351 { |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
352 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
| 9285 | 353 |
| 354 g_return_if_fail(buddy != NULL); | |
| 355 | |
| 356 if (ops && ops->update) | |
| 357 ops->update(gaimbuddylist, (GaimBlistNode *)buddy); | |
| 358 } | |
| 359 | |
| 360 /* | |
| 361 * XXX - Maybe remove the call to this from server.c and call it | |
| 362 * from oscar.c and toc.c instead? | |
| 363 */ | |
| 364 void gaim_blist_rename_buddy(GaimBuddy *buddy, const char *name) | |
| 365 { | |
| 366 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; | |
| 367 struct _gaim_hbuddy *hb; | |
| 368 | |
| 369 g_return_if_fail(buddy != NULL); | |
| 370 | |
| 371 hb = g_new(struct _gaim_hbuddy, 1); | |
| 8675 | 372 hb->name = g_strdup(gaim_normalize(buddy->account, buddy->name)); |
| 373 hb->account = buddy->account; | |
| 374 hb->group = ((GaimBlistNode *)buddy)->parent->parent; | |
| 375 g_hash_table_remove(gaimbuddylist->buddies, hb); | |
| 376 | |
| 377 g_free(hb->name); | |
| 378 hb->name = g_strdup(gaim_normalize(buddy->account, name)); | |
| 379 g_hash_table_replace(gaimbuddylist->buddies, hb, buddy); | |
| 380 | |
| 5634 | 381 g_free(buddy->name); |
| 5228 | 382 buddy->name = g_strdup(name); |
| 9285 | 383 |
| 384 schedule_blist_save(); | |
| 385 | |
| 386 if (ops && ops->update) | |
| 387 ops->update(gaimbuddylist, (GaimBlistNode *)buddy); | |
| 5228 | 388 } |
| 5234 | 389 |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
390 void gaim_blist_alias_chat(GaimChat *chat, const char *alias) |
| 5234 | 391 { |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
392 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
| 5234 | 393 |
| 9285 | 394 g_return_if_fail(chat != NULL); |
| 395 | |
| 5237 | 396 g_free(chat->alias); |
| 9285 | 397 if ((alias != NULL) && (*alias != '\0')) |
| 5237 | 398 chat->alias = g_strdup(alias); |
| 399 else | |
| 400 chat->alias = NULL; | |
| 401 | |
| 9285 | 402 schedule_blist_save(); |
| 403 | |
| 404 if (ops && ops->update) | |
| 405 ops->update(gaimbuddylist, (GaimBlistNode *)chat); | |
| 5234 | 406 } |
| 407 | |
| 9285 | 408 void gaim_blist_alias_buddy(GaimBuddy *buddy, const char *alias) |
| 5228 | 409 { |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
410 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
|
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5634
diff
changeset
|
411 GaimConversation *conv; |
| 5228 | 412 |
| 9285 | 413 g_return_if_fail(buddy != NULL); |
| 414 | |
| 5228 | 415 g_free(buddy->alias); |
| 9285 | 416 if ((alias != NULL) && (*alias != '\0')) |
| 5228 | 417 buddy->alias = g_strdup(alias); |
| 418 else | |
| 419 buddy->alias = NULL; | |
| 420 | |
| 9285 | 421 schedule_blist_save(); |
| 422 | |
| 423 if (ops && ops->update) | |
| 424 ops->update(gaimbuddylist, (GaimBlistNode *)buddy); | |
| 5228 | 425 |
| 10246 | 426 conv = gaim_find_conversation_with_account(GAIM_CONV_IM, buddy->name, |
| 427 buddy->account); | |
| 5228 | 428 if (conv) |
| 429 gaim_conversation_autoset_title(conv); | |
| 430 } | |
| 431 | |
| 9285 | 432 void gaim_blist_server_alias_buddy(GaimBuddy *buddy, const char *alias) |
| 6058 | 433 { |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
434 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
| 6058 | 435 GaimConversation *conv; |
| 436 | |
| 9285 | 437 g_return_if_fail(buddy != NULL); |
| 438 | |
| 6058 | 439 g_free(buddy->server_alias); |
| 9285 | 440 if ((alias != NULL) && (*alias != '\0') && g_utf8_validate(alias, -1, NULL)) |
| 6058 | 441 buddy->server_alias = g_strdup(alias); |
| 442 else | |
| 443 buddy->server_alias = NULL; | |
| 444 | |
| 9285 | 445 schedule_blist_save(); |
| 446 | |
| 447 if (ops && ops->update) | |
| 448 ops->update(gaimbuddylist, (GaimBlistNode *)buddy); | |
| 6058 | 449 |
| 10246 | 450 conv = gaim_find_conversation_with_account(GAIM_CONV_IM, buddy->name, |
| 451 buddy->account); | |
| 6058 | 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 | |
| 10349 | 1431 /* The server alias */ |
| 1432 if ((buddy->server_alias) && (*buddy->server_alias)) | |
| 9620 | 1433 return buddy->server_alias; |
| 1434 | |
| 1435 /* The buddy's user name (i.e. no alias) */ | |
| 1436 return buddy->name; | |
| 5228 | 1437 } |
| 1438 | |
| 9620 | 1439 |
| 1440 const char *gaim_buddy_get_alias(GaimBuddy *buddy) | |
| 1441 { | |
| 1442 g_return_val_if_fail(buddy != NULL, NULL); | |
| 1443 | |
| 1444 /* Search for an alias for the buddy. In order of precedence: */ | |
| 1445 /* The buddy alias */ | |
| 1446 if (buddy->alias != NULL) | |
| 1447 return buddy->alias; | |
| 1448 | |
| 1449 /* The server alias, if preferences say so */ | |
| 1450 if ((buddy->server_alias) && (*buddy->server_alias) && | |
| 1451 (gaim_prefs_get_bool("/core/buddies/use_server_alias"))) | |
| 1452 return buddy->server_alias; | |
| 1453 | |
| 1454 /* The buddy's user name (i.e. no alias) */ | |
| 1455 return buddy->name; | |
| 1456 } | |
| 1457 | |
| 10349 | 1458 const char *gaim_buddy_get_local_alias(GaimBuddy *buddy) |
| 1459 { | |
| 1460 GaimContact *c; | |
| 1461 | |
| 1462 g_return_val_if_fail(buddy != NULL, NULL); | |
| 1463 | |
| 1464 /* Search for an alias for the buddy. In order of precedence: */ | |
| 1465 /* The buddy alias */ | |
| 1466 if (buddy->alias != NULL) | |
| 1467 return buddy->alias; | |
| 1468 | |
| 1469 /* The contact alias */ | |
| 1470 c = gaim_buddy_get_contact(buddy); | |
| 1471 if ((c != NULL) && (c->alias != NULL)) | |
| 1472 return c->alias; | |
| 1473 | |
| 1474 /* The buddy's user name (i.e. no alias) */ | |
| 1475 return buddy->name; | |
| 1476 } | |
| 9620 | 1477 |
| 7125 | 1478 const char *gaim_chat_get_name(GaimChat *chat) |
| 6744 | 1479 { |
| 9285 | 1480 struct proto_chat_entry *pce; |
| 1481 GList *parts, *tmp; | |
| 1482 char *ret; | |
| 1483 | |
| 1484 g_return_val_if_fail(chat != NULL, NULL); | |
| 1485 | |
| 1486 if ((chat->alias != NULL) && (*chat->alias != '\0')) | |
| 6744 | 1487 return chat->alias; |
| 9285 | 1488 |
| 1489 parts = GAIM_PLUGIN_PROTOCOL_INFO(chat->account->gc->prpl)->chat_info(chat->account->gc); | |
| 1490 pce = parts->data; | |
| 1491 ret = g_hash_table_lookup(chat->components, pce->identifier); | |
| 1492 for (tmp = parts; tmp; tmp = tmp->next) | |
| 1493 g_free(tmp->data); | |
| 1494 g_list_free(parts); | |
| 1495 | |
| 1496 return ret; | |
| 6744 | 1497 } |
| 1498 | |
| 6695 | 1499 GaimBuddy *gaim_find_buddy(GaimAccount *account, const char *name) |
| 5228 | 1500 { |
| 6695 | 1501 GaimBuddy *buddy; |
| 5247 | 1502 struct _gaim_hbuddy hb; |
| 5758 | 1503 GaimBlistNode *group; |
| 5228 | 1504 |
| 9285 | 1505 g_return_val_if_fail(gaimbuddylist != NULL, NULL); |
| 1506 g_return_val_if_fail(account != NULL, NULL); | |
| 1507 g_return_val_if_fail((name != NULL) && (*name != '\0'), NULL); | |
| 5228 | 1508 |
| 7429 | 1509 hb.account = account; |
| 7261 | 1510 hb.name = g_strdup(gaim_normalize(account, name)); |
| 7429 | 1511 |
| 9285 | 1512 for (group = gaimbuddylist->root; group; group = group->next) { |
| 5758 | 1513 hb.group = group; |
| 7162 | 1514 if ((buddy = g_hash_table_lookup(gaimbuddylist->buddies, &hb))) { |
| 1515 g_free(hb.name); | |
| 5758 | 1516 return buddy; |
| 7162 | 1517 } |
| 5758 | 1518 } |
| 7162 | 1519 g_free(hb.name); |
| 9285 | 1520 |
| 5758 | 1521 return NULL; |
| 5228 | 1522 } |
| 1523 | |
| 6872 | 1524 GaimBuddy *gaim_find_buddy_in_group(GaimAccount *account, const char *name, |
| 1525 GaimGroup *group) | |
| 1526 { | |
| 1527 struct _gaim_hbuddy hb; | |
| 7162 | 1528 GaimBuddy *ret; |
| 6872 | 1529 |
| 9285 | 1530 g_return_val_if_fail(gaimbuddylist != NULL, NULL); |
| 1531 g_return_val_if_fail(account != NULL, NULL); | |
| 1532 g_return_val_if_fail((name != NULL) && (*name != '\0'), NULL); | |
| 6872 | 1533 |
| 7261 | 1534 hb.name = g_strdup(gaim_normalize(account, name)); |
| 6872 | 1535 hb.account = account; |
| 1536 hb.group = (GaimBlistNode*)group; | |
| 1537 | |
| 7162 | 1538 ret = g_hash_table_lookup(gaimbuddylist->buddies, &hb); |
| 1539 g_free(hb.name); | |
| 9285 | 1540 |
| 7162 | 1541 return ret; |
| 6872 | 1542 } |
| 1543 | |
| 6245 | 1544 GSList *gaim_find_buddies(GaimAccount *account, const char *name) |
| 1545 { | |
| 1546 struct buddy *buddy; | |
| 1547 struct _gaim_hbuddy hb; | |
| 9285 | 1548 GaimBlistNode *node; |
| 6245 | 1549 GSList *ret = NULL; |
| 1550 | |
| 9285 | 1551 g_return_val_if_fail(gaimbuddylist != NULL, NULL); |
| 1552 g_return_val_if_fail(account != NULL, NULL); | |
| 1553 g_return_val_if_fail((name != NULL) && (*name != '\0'), NULL); | |
| 6245 | 1554 |
| 7261 | 1555 hb.name = g_strdup(gaim_normalize(account, name)); |
| 6245 | 1556 hb.account = account; |
| 1557 | |
| 9285 | 1558 for (node = gaimbuddylist->root; node != NULL; node = node->next) { |
| 1559 hb.group = node; | |
| 6245 | 1560 if ((buddy = g_hash_table_lookup(gaimbuddylist->buddies, &hb)) != NULL) |
| 1561 ret = g_slist_append(ret, buddy); | |
| 1562 } | |
| 7162 | 1563 g_free(hb.name); |
| 9285 | 1564 |
| 6245 | 1565 return ret; |
| 1566 } | |
| 1567 | |
| 6695 | 1568 GaimGroup *gaim_find_group(const char *name) |
| 5228 | 1569 { |
| 1570 GaimBlistNode *node; | |
| 9285 | 1571 |
| 1572 g_return_val_if_fail(gaimbuddylist != NULL, NULL); | |
| 1573 g_return_val_if_fail((name != NULL) && (*name != '\0'), NULL); | |
| 1574 | |
| 1575 for (node = gaimbuddylist->root; node != NULL; node = node->next) { | |
| 6695 | 1576 if (!strcmp(((GaimGroup *)node)->name, name)) |
| 1577 return (GaimGroup *)node; | |
| 5228 | 1578 } |
| 9285 | 1579 |
| 5228 | 1580 return NULL; |
| 1581 } | |
|
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1582 |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1583 GaimChat * |
|
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1584 gaim_blist_find_chat(GaimAccount *account, const char *name) |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1585 { |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1586 char *chat_name; |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1587 GaimChat *chat; |
|
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1588 GaimPlugin *prpl; |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1589 GaimPluginProtocolInfo *prpl_info = NULL; |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1590 struct proto_chat_entry *pce; |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1591 GaimBlistNode *node, *group; |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1592 GList *parts; |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1593 |
| 9285 | 1594 g_return_val_if_fail(gaimbuddylist != NULL, NULL); |
| 1595 g_return_val_if_fail((name != NULL) && (*name != '\0'), NULL); | |
| 1596 | |
| 1597 if (!gaim_account_is_connected(account)) | |
| 7970 | 1598 return NULL; |
| 1599 | |
| 7999 | 1600 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); |
| 1601 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
| 1602 | |
| 9285 | 1603 if (prpl_info->find_blist_chat != NULL) |
| 7999 | 1604 return prpl_info->find_blist_chat(account, name); |
| 1605 | |
|
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1606 for (group = gaimbuddylist->root; group != NULL; group = group->next) { |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1607 for (node = group->child; node != NULL; node = node->next) { |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1608 if (GAIM_BLIST_NODE_IS_CHAT(node)) { |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1609 |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1610 chat = (GaimChat*)node; |
|
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1611 |
| 9285 | 1612 if (account != chat->account) |
| 7970 | 1613 continue; |
| 1614 | |
|
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1615 parts = prpl_info->chat_info( |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1616 gaim_account_get_connection(chat->account)); |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1617 |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1618 pce = parts->data; |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1619 chat_name = g_hash_table_lookup(chat->components, |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1620 pce->identifier); |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1621 |
| 9153 | 1622 if (chat->account == account && chat_name != NULL && |
|
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1623 name != NULL && !strcmp(chat_name, name)) { |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1624 |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1625 return chat; |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1626 } |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1627 } |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1628 } |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1629 } |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1630 |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1631 return NULL; |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1632 } |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1633 |
| 6695 | 1634 GaimGroup * |
| 7125 | 1635 gaim_chat_get_group(GaimChat *chat) |
|
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1636 { |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1637 g_return_val_if_fail(chat != NULL, NULL); |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1638 |
| 6695 | 1639 return (GaimGroup *)(((GaimBlistNode *)chat)->parent); |
|
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1640 } |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1641 |
| 9285 | 1642 GaimContact *gaim_buddy_get_contact(GaimBuddy *buddy) |
| 1643 { | |
| 1644 g_return_val_if_fail(buddy != NULL, NULL); | |
| 1645 | |
| 1646 return (GaimContact*)((GaimBlistNode*)buddy)->parent; | |
| 1647 } | |
| 1648 | |
| 9949 | 1649 GaimPresence *gaim_buddy_get_presence(const GaimBuddy *buddy) |
| 1650 { | |
| 1651 g_return_val_if_fail(buddy != NULL, NULL); | |
| 1652 return buddy->presence; | |
| 1653 } | |
| 1654 | |
| 1655 | |
| 6695 | 1656 GaimGroup *gaim_find_buddys_group(GaimBuddy *buddy) |
| 5228 | 1657 { |
| 9285 | 1658 g_return_val_if_fail(buddy != NULL, NULL); |
|
6706
854a435d2cc3
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1659 |
|
854a435d2cc3
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1660 if (((GaimBlistNode *)buddy)->parent == NULL) |
|
854a435d2cc3
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1661 return NULL; |
|
854a435d2cc3
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1662 |
| 6695 | 1663 return (GaimGroup *)(((GaimBlistNode*)buddy)->parent->parent); |
| 5228 | 1664 } |
| 1665 | |
| 9285 | 1666 GSList *gaim_group_get_accounts(GaimGroup *group) |
| 5228 | 1667 { |
| 1668 GSList *l = NULL; | |
| 6695 | 1669 GaimBlistNode *gnode, *cnode, *bnode; |
| 1670 | |
| 9285 | 1671 gnode = (GaimBlistNode *)group; |
| 1672 | |
| 1673 for (cnode = gnode->child; cnode; cnode = cnode->next) { | |
| 6695 | 1674 if (GAIM_BLIST_NODE_IS_CHAT(cnode)) { |
| 9285 | 1675 if (!g_slist_find(l, ((GaimChat *)cnode)->account)) |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1676 l = g_slist_append(l, ((GaimChat *)cnode)->account); |
| 9285 | 1677 } else if (GAIM_BLIST_NODE_IS_CONTACT(cnode)) { |
| 1678 for (bnode = cnode->child; bnode; bnode = bnode->next) { | |
| 1679 if (GAIM_BLIST_NODE_IS_BUDDY(bnode)) { | |
| 1680 if (!g_slist_find(l, ((GaimBuddy *)bnode)->account)) | |
| 6695 | 1681 l = g_slist_append(l, ((GaimBuddy *)bnode)->account); |
| 1682 } | |
| 1683 } | |
| 1684 } | |
| 5228 | 1685 } |
| 6695 | 1686 |
| 5228 | 1687 return l; |
| 1688 } | |
| 1689 | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1690 void gaim_blist_add_account(GaimAccount *account) |
| 5234 | 1691 { |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
1692 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
| 6695 | 1693 GaimBlistNode *gnode, *cnode, *bnode; |
| 5234 | 1694 |
| 9285 | 1695 g_return_if_fail(gaimbuddylist != NULL); |
| 1696 | |
| 1697 if (!ops || !ops->update) | |
| 6695 | 1698 return; |
| 1699 | |
| 9285 | 1700 for (gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { |
| 1701 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
| 5234 | 1702 continue; |
| 9285 | 1703 for (cnode = gnode->child; cnode; cnode = cnode->next) { |
| 1704 if (GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
| 6956 | 1705 gboolean recompute = FALSE; |
| 9285 | 1706 for (bnode = cnode->child; bnode; bnode = bnode->next) { |
| 1707 if (GAIM_BLIST_NODE_IS_BUDDY(bnode) && | |
| 6695 | 1708 ((GaimBuddy*)bnode)->account == account) { |
| 6956 | 1709 recompute = TRUE; |
| 6695 | 1710 ((GaimContact*)cnode)->currentsize++; |
| 9285 | 1711 if (((GaimContact*)cnode)->currentsize == 1) |
| 6695 | 1712 ((GaimGroup*)gnode)->currentsize++; |
| 1713 ops->update(gaimbuddylist, bnode); | |
| 1714 } | |
| 1715 } | |
| 9285 | 1716 if (recompute || |
| 8960 | 1717 gaim_blist_node_get_bool(cnode, "show_offline")) { |
| 6956 | 1718 gaim_contact_compute_priority_buddy((GaimContact*)cnode); |
| 1719 ops->update(gaimbuddylist, cnode); | |
| 1720 } | |
| 9285 | 1721 } else if (GAIM_BLIST_NODE_IS_CHAT(cnode) && |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1722 ((GaimChat*)cnode)->account == account) { |
| 6901 | 1723 ((GaimGroup *)gnode)->online++; |
| 1724 ((GaimGroup *)gnode)->currentsize++; | |
| 1725 ops->update(gaimbuddylist, cnode); | |
| 5234 | 1726 } |
| 1727 } | |
| 6695 | 1728 ops->update(gaimbuddylist, gnode); |
| 5234 | 1729 } |
| 1730 } | |
| 1731 | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1732 void gaim_blist_remove_account(GaimAccount *account) |
| 5228 | 1733 { |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
1734 GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
| 6695 | 1735 GaimBlistNode *gnode, *cnode, *bnode; |
| 5234 | 1736 |
| 9285 | 1737 g_return_if_fail(gaimbuddylist != NULL); |
| 1738 | |
| 1739 for (gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { | |
| 1740 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
| 5234 | 1741 continue; |
| 9285 | 1742 for (cnode = gnode->child; cnode; cnode = cnode->next) { |
| 1743 if (GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
| 6957 | 1744 gboolean recompute = FALSE; |
| 9285 | 1745 for (bnode = cnode->child; bnode; bnode = bnode->next) { |
| 1746 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
| 6695 | 1747 continue; |
| 9285 | 1748 if (account == ((GaimBuddy *)bnode)->account) { |
| 6957 | 1749 recompute = TRUE; |
| 9285 | 1750 if (((GaimBuddy*)bnode)->present == GAIM_BUDDY_ONLINE || |
| 6695 | 1751 ((GaimBuddy*)bnode)->present == GAIM_BUDDY_SIGNING_ON) { |
| 1752 ((GaimContact*)cnode)->online--; | |
| 9285 | 1753 if (((GaimContact*)cnode)->online == 0) |
| 6695 | 1754 ((GaimGroup*)gnode)->online--; |
| 1755 } | |
| 1756 ((GaimContact*)cnode)->currentsize--; | |
| 9285 | 1757 if (((GaimContact*)cnode)->currentsize == 0) |
| 6695 | 1758 ((GaimGroup*)gnode)->currentsize--; |
| 1759 | |
| 1760 ((GaimBuddy*)bnode)->present = GAIM_BUDDY_OFFLINE; | |
| 1761 | |
| 6803 | 1762 ((GaimBuddy*)bnode)->uc = 0; |
| 9944 | 1763 /* XXX ((GaimBuddy*)bnode)->idle = 0; */ |
| 6803 | 1764 |
| 6945 | 1765 |
| 9285 | 1766 if (ops && ops->remove) |
| 6695 | 1767 ops->remove(gaimbuddylist, bnode); |
| 1768 } | |
| 5234 | 1769 } |
| 9285 | 1770 if (recompute) { |
| 6959 | 1771 gaim_contact_compute_priority_buddy((GaimContact*)cnode); |
| 9285 | 1772 if (ops && ops->update) |
| 6983 | 1773 ops->update(gaimbuddylist, cnode); |
| 1774 } | |
| 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*)cnode)->account == account) { |
| 6695 | 1777 ((GaimGroup*)gnode)->currentsize--; |
| 1778 ((GaimGroup*)gnode)->online--; | |
| 9285 | 1779 if (ops && ops->remove) |
| 6695 | 1780 ops->remove(gaimbuddylist, cnode); |
| 5228 | 1781 } |
| 1782 } | |
| 1783 } | |
| 1784 } | |
| 1785 | |
| 9285 | 1786 gboolean gaim_group_on_account(GaimGroup *g, GaimAccount *account) |
| 1787 { | |
| 9787 | 1788 GaimBlistNode *cnode; |
| 9285 | 1789 for (cnode = ((GaimBlistNode *)g)->child; cnode; cnode = cnode->next) { |
| 1790 if (GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
| 9787 | 1791 if(gaim_contact_on_account((GaimContact *) cnode, account)) |
| 1792 return TRUE; | |
| 9285 | 1793 } else if (GAIM_BLIST_NODE_IS_CHAT(cnode)) { |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1794 GaimChat *chat = (GaimChat *)cnode; |
| 9285 | 1795 if ((!account && gaim_account_is_connected(chat->account)) |
| 6695 | 1796 || chat->account == account) |
| 1797 return TRUE; | |
| 1798 } | |
| 5228 | 1799 } |
| 1800 return FALSE; | |
| 1801 } | |
| 1802 | |
| 1803 static gboolean blist_safe_to_write = FALSE; | |
| 1804 | |
| 7132 | 1805 static void parse_setting(GaimBlistNode *node, xmlnode *setting) |
| 1806 { | |
| 1807 const char *name = xmlnode_get_attrib(setting, "name"); | |
| 7693 | 1808 const char *type = xmlnode_get_attrib(setting, "type"); |
| 7132 | 1809 char *value = xmlnode_get_data(setting); |
| 1810 | |
| 9285 | 1811 if (!value) |
| 7693 | 1812 return; |
| 1813 | |
| 9285 | 1814 if (!type || !strcmp(type, "string")) |
| 7693 | 1815 gaim_blist_node_set_string(node, name, value); |
| 9285 | 1816 else if (!strcmp(type, "bool")) |
| 7693 | 1817 gaim_blist_node_set_bool(node, name, atoi(value)); |
| 9285 | 1818 else if (!strcmp(type, "int")) |
| 7693 | 1819 gaim_blist_node_set_int(node, name, atoi(value)); |
| 7132 | 1820 |
| 1821 g_free(value); | |
| 1822 } | |
| 1823 | |
| 1824 static void parse_buddy(GaimGroup *group, GaimContact *contact, xmlnode *bnode) | |
| 1825 { | |
| 1826 GaimAccount *account; | |
| 1827 GaimBuddy *buddy; | |
| 7727 | 1828 char *name = NULL, *alias = NULL; |
| 7153 | 1829 const char *acct_name, *proto, *protocol; |
| 7132 | 1830 xmlnode *x; |
| 1831 | |
| 1832 acct_name = xmlnode_get_attrib(bnode, "account"); | |
| 7153 | 1833 protocol = xmlnode_get_attrib(bnode, "protocol"); |
| 1834 proto = xmlnode_get_attrib(bnode, "proto"); | |
| 1835 | |
| 9285 | 1836 if (!acct_name || (!proto && !protocol)) |
| 7132 | 1837 return; |
| 1838 | |
| 7153 | 1839 account = gaim_accounts_find(acct_name, proto ? proto : protocol); |
| 7132 | 1840 |
| 9285 | 1841 if (!account) |
| 7132 | 1842 return; |
| 1843 | |
| 9285 | 1844 if ((x = xmlnode_get_child(bnode, "name"))) |
| 7132 | 1845 name = xmlnode_get_data(x); |
| 1846 | |
| 9285 | 1847 if (!name) |
| 7132 | 1848 return; |
| 1849 | |
| 9285 | 1850 if ((x = xmlnode_get_child(bnode, "alias"))) |
| 7132 | 1851 alias = xmlnode_get_data(x); |
| 1852 | |
| 1853 buddy = gaim_buddy_new(account, name, alias); | |
| 1854 gaim_blist_add_buddy(buddy, contact, group, | |
| 1855 gaim_blist_get_last_child((GaimBlistNode*)contact)); | |
| 1856 | |
| 9285 | 1857 for (x = xmlnode_get_child(bnode, "setting"); x; x = xmlnode_get_next_twin(x)) { |
| 7132 | 1858 parse_setting((GaimBlistNode*)buddy, x); |
| 1859 } | |
| 1860 | |
| 1861 g_free(name); | |
| 9285 | 1862 if (alias) |
| 7132 | 1863 g_free(alias); |
| 1864 } | |
| 1865 | |
| 1866 static void parse_contact(GaimGroup *group, xmlnode *cnode) | |
| 1867 { | |
| 1868 GaimContact *contact = gaim_contact_new(); | |
| 1869 xmlnode *x; | |
| 7245 | 1870 const char *alias; |
| 7132 | 1871 |
| 1872 gaim_blist_add_contact(contact, group, | |
| 1873 gaim_blist_get_last_child((GaimBlistNode*)group)); | |
| 1874 | |
| 9285 | 1875 if ((alias = xmlnode_get_attrib(cnode, "alias"))) { |
| 7132 | 1876 gaim_contact_set_alias(contact, alias); |
| 1877 } | |
| 1878 | |
| 9285 | 1879 for (x = cnode->child; x; x = x->next) { |
| 1880 if (x->type != XMLNODE_TYPE_TAG) | |
| 7132 | 1881 continue; |
| 9285 | 1882 if (!strcmp(x->name, "buddy")) |
| 7132 | 1883 parse_buddy(group, contact, x); |
| 9285 | 1884 else if (!strcmp(x->name, "setting")) |
| 7132 | 1885 parse_setting((GaimBlistNode*)contact, x); |
| 5228 | 1886 } |
| 7825 | 1887 |
| 1888 /* if the contact is empty, don't keep it around. it causes problems */ | |
| 9285 | 1889 if (!((GaimBlistNode*)contact)->child) |
| 7825 | 1890 gaim_blist_remove_contact(contact); |
| 5228 | 1891 } |
| 1892 | |
| 7132 | 1893 static void parse_chat(GaimGroup *group, xmlnode *cnode) |
| 1894 { | |
| 1895 GaimChat *chat; | |
| 1896 GaimAccount *account; | |
| 7153 | 1897 const char *acct_name, *proto, *protocol; |
| 7132 | 1898 xmlnode *x; |
| 1899 char *alias = NULL; | |
| 1900 GHashTable *components; | |
| 1901 | |
| 1902 acct_name = xmlnode_get_attrib(cnode, "account"); | |
| 7153 | 1903 protocol = xmlnode_get_attrib(cnode, "protocol"); |
| 1904 proto = xmlnode_get_attrib(cnode, "proto"); | |
| 1905 | |
| 9285 | 1906 if (!acct_name || (!proto && !protocol)) |
| 7132 | 1907 return; |
| 1908 | |
| 7153 | 1909 account = gaim_accounts_find(acct_name, proto ? proto : protocol); |
| 7132 | 1910 |
| 9285 | 1911 if (!account) |
| 7132 | 1912 return; |
| 1913 | |
| 9285 | 1914 if ((x = xmlnode_get_child(cnode, "alias"))) |
| 7132 | 1915 alias = xmlnode_get_data(x); |
| 1916 | |
| 1917 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
| 1918 | |
| 9285 | 1919 for (x = xmlnode_get_child(cnode, "component"); x; x = xmlnode_get_next_twin(x)) { |
| 7132 | 1920 const char *name; |
| 1921 char *value; | |
| 1922 | |
| 1923 name = xmlnode_get_attrib(x, "name"); | |
| 1924 value = xmlnode_get_data(x); | |
| 1925 g_hash_table_replace(components, g_strdup(name), value); | |
| 1926 } | |
| 1927 | |
| 1928 chat = gaim_chat_new(account, alias, components); | |
| 7151 | 1929 gaim_blist_add_chat(chat, group, |
| 1930 gaim_blist_get_last_child((GaimBlistNode*)group)); | |
| 7132 | 1931 |
| 9285 | 1932 for (x = xmlnode_get_child(cnode, "setting"); x; x = xmlnode_get_next_twin(x)) { |
| 7132 | 1933 parse_setting((GaimBlistNode*)chat, x); |
| 1934 } | |
| 1935 | |
| 9285 | 1936 if (alias) |
| 7132 | 1937 g_free(alias); |
| 1938 } | |
| 1939 | |
| 1940 | |
| 1941 static void parse_group(xmlnode *groupnode) | |
| 1942 { | |
| 1943 const char *name = xmlnode_get_attrib(groupnode, "name"); | |
| 1944 GaimGroup *group; | |
| 1945 xmlnode *cnode; | |
| 1946 | |
| 9285 | 1947 if (!name) |
| 7132 | 1948 name = _("Buddies"); |
| 1949 | |
| 1950 group = gaim_group_new(name); | |
| 1951 gaim_blist_add_group(group, | |
| 1952 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
| 1953 | |
| 9285 | 1954 for (cnode = groupnode->child; cnode; cnode = cnode->next) { |
| 1955 if (cnode->type != XMLNODE_TYPE_TAG) | |
| 7132 | 1956 continue; |
| 9285 | 1957 if (!strcmp(cnode->name, "setting")) |
| 7132 | 1958 parse_setting((GaimBlistNode*)group, cnode); |
| 9285 | 1959 else if (!strcmp(cnode->name, "contact") || |
| 7132 | 1960 !strcmp(cnode->name, "person")) |
| 1961 parse_contact(group, cnode); | |
| 9285 | 1962 else if (!strcmp(cnode->name, "chat")) |
| 7132 | 1963 parse_chat(group, cnode); |
| 5228 | 1964 } |
| 1965 } | |
| 1966 | |
| 9285 | 1967 static gboolean gaim_blist_read(const char *filename) |
| 1968 { | |
| 7132 | 1969 GError *error; |
| 5228 | 1970 gchar *contents = NULL; |
| 1971 gsize length; | |
| 7132 | 1972 xmlnode *gaim, *blist, *privacy; |
| 5228 | 1973 |
| 10337 | 1974 gaim_debug_info("blist", "Reading %s\n", filename); |
| 1975 | |
| 9285 | 1976 if (!g_file_get_contents(filename, &contents, &length, &error)) { |
| 10343 | 1977 gaim_debug_error("blist", "Error reading buddy list: %s\n", |
| 10337 | 1978 error->message); |
| 5228 | 1979 g_error_free(error); |
| 1980 return FALSE; | |
| 1981 } | |
| 1982 | |
| 7132 | 1983 gaim = xmlnode_from_str(contents, length); |
| 10337 | 1984 |
| 1985 if (gaim == NULL) { | |
| 8826 | 1986 FILE *backup; |
| 1987 char *name; | |
| 10343 | 1988 gaim_debug_error("blist", "Error parsing buddy list\n"); |
| 1989 name = g_strdup_printf("%s~", filename); | |
| 9285 | 1990 if ((backup = fopen(name, "w"))) { |
| 8826 | 1991 fwrite(contents, length, 1, backup); |
| 1992 fclose(backup); | |
| 1993 chmod(name, S_IRUSR | S_IWUSR); | |
| 1994 } else { | |
| 10337 | 1995 gaim_debug_error("blist", "Unable to write backup %s\n", name); |
| 8826 | 1996 } |
| 1997 g_free(name); | |
| 1998 g_free(contents); | |
| 5228 | 1999 return FALSE; |
| 2000 } | |
| 10337 | 2001 |
| 8826 | 2002 g_free(contents); |
| 10337 | 2003 |
| 7132 | 2004 blist = xmlnode_get_child(gaim, "blist"); |
| 9285 | 2005 if (blist) { |
| 7132 | 2006 xmlnode *groupnode; |
| 10337 | 2007 for (groupnode = xmlnode_get_child(blist, "group"); groupnode != NULL; |
| 8135 | 2008 groupnode = xmlnode_get_next_twin(groupnode)) { |
| 7132 | 2009 parse_group(groupnode); |
| 2010 } | |
| 5228 | 2011 } |
| 2012 | |
| 7132 | 2013 privacy = xmlnode_get_child(gaim, "privacy"); |
| 9285 | 2014 if (privacy) { |
| 7132 | 2015 xmlnode *anode; |
| 9285 | 2016 for (anode = privacy->child; anode; anode = anode->next) { |
| 7132 | 2017 xmlnode *x; |
| 2018 GaimAccount *account; | |
| 7153 | 2019 const char *acct_name, *proto, *mode, *protocol; |
| 7132 | 2020 |
| 2021 acct_name = xmlnode_get_attrib(anode, "name"); | |
| 7153 | 2022 protocol = xmlnode_get_attrib(anode, "protocol"); |
| 2023 proto = xmlnode_get_attrib(anode, "proto"); | |
| 7132 | 2024 mode = xmlnode_get_attrib(anode, "mode"); |
| 2025 | |
| 9285 | 2026 if (!acct_name || (!proto && !protocol) || !mode) |
| 7132 | 2027 continue; |
| 2028 | |
| 7153 | 2029 account = gaim_accounts_find(acct_name, proto ? proto : protocol); |
| 7132 | 2030 |
| 9285 | 2031 if (!account) |
| 7132 | 2032 continue; |
| 2033 | |
| 2034 account->perm_deny = atoi(mode); | |
| 2035 | |
| 9285 | 2036 for (x = anode->child; x; x = x->next) { |
| 7132 | 2037 char *name; |
| 9285 | 2038 if (x->type != XMLNODE_TYPE_TAG) |
| 7132 | 2039 continue; |
| 2040 | |
| 9285 | 2041 if (!strcmp(x->name, "permit")) { |
| 7132 | 2042 name = xmlnode_get_data(x); |
| 2043 gaim_privacy_permit_add(account, name, TRUE); | |
| 2044 g_free(name); | |
| 9285 | 2045 } else if (!strcmp(x->name, "block")) { |
| 7132 | 2046 name = xmlnode_get_data(x); |
| 2047 gaim_privacy_deny_add(account, name, TRUE); | |
| 2048 g_free(name); | |
| 2049 } | |
| 2050 } | |
| 2051 } | |
| 2052 } | |
| 5228 | 2053 |
| 10343 | 2054 gaim_debug_info("blist", "Finished reading buddy list\n"); |
| 5228 | 2055 |
| 8200 | 2056 xmlnode_free(gaim); |
| 10337 | 2057 |
| 5228 | 2058 return TRUE; |
| 2059 } | |
| 2060 | |
| 9285 | 2061 void gaim_blist_load() |
| 2062 { | |
| 10332 | 2063 const char *user_dir = gaim_user_dir(); |
| 10337 | 2064 gchar *filename; |
| 2065 gchar *msg; | |
| 5228 | 2066 |
| 2067 blist_safe_to_write = TRUE; | |
| 2068 | |
| 10337 | 2069 if (user_dir == NULL) |
| 5228 | 2070 return; |
| 2071 | |
| 2072 filename = g_build_filename(user_dir, "blist.xml", NULL); | |
| 2073 | |
| 9285 | 2074 if (g_file_test(filename, G_FILE_TEST_EXISTS)) { |
| 2075 if (!gaim_blist_read(filename)) { | |
| 10337 | 2076 msg = g_strdup_printf(_("An error was encountered parsing the " |
| 2077 "file containing your buddy list (%s). It has not " | |
| 2078 "been loaded, and the old file has been renamed " | |
| 2079 "to blist.xml~."), filename); | |
|
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
2080 gaim_notify_error(NULL, NULL, _("Buddy List Error"), msg); |
| 5228 | 2081 g_free(msg); |
| 2082 } | |
| 2083 } | |
| 2084 | |
| 2085 g_free(filename); | |
| 2086 } | |
| 2087 | |
|
7060
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2088 void |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2089 gaim_blist_request_add_buddy(GaimAccount *account, const char *username, |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2090 const char *group, const char *alias) |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2091 { |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2092 GaimBlistUiOps *ui_ops; |
|
7060
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2093 |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2094 ui_ops = gaim_blist_get_ui_ops(); |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2095 |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2096 if (ui_ops != NULL && ui_ops->request_add_buddy != NULL) |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2097 ui_ops->request_add_buddy(account, username, group, alias); |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2098 } |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2099 |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2100 void |
| 9754 | 2101 gaim_blist_request_add_chat(GaimAccount *account, GaimGroup *group, |
| 2102 const char *alias, const char *name) | |
|
7060
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2103 { |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2104 GaimBlistUiOps *ui_ops; |
|
7060
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 ui_ops = gaim_blist_get_ui_ops(); |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2107 |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2108 if (ui_ops != NULL && ui_ops->request_add_chat != NULL) |
| 9754 | 2109 ui_ops->request_add_chat(account, group, alias, name); |
|
7060
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2110 } |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2111 |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2112 void |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2113 gaim_blist_request_add_group(void) |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2114 { |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2115 GaimBlistUiOps *ui_ops; |
|
7060
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2116 |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2117 ui_ops = gaim_blist_get_ui_ops(); |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2118 |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2119 if (ui_ops != NULL && ui_ops->request_add_group != NULL) |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2120 ui_ops->request_add_group(); |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2121 } |
|
9946001989a3
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2122 |
| 7693 | 2123 static void blist_print_setting(const char *key, |
| 2124 struct gaim_blist_node_setting *setting, FILE *file, int indent) | |
| 2125 { | |
| 2126 char *key_val, *data_val = NULL; | |
| 2127 const char *type = NULL; | |
| 2128 int i; | |
| 2129 | |
| 9285 | 2130 if (!key) |
| 7693 | 2131 return; |
| 2132 | |
| 2133 switch(setting->type) { | |
| 2134 case GAIM_BLIST_NODE_SETTING_BOOL: | |
| 2135 type = "bool"; | |
| 2136 data_val = g_strdup_printf("%d", setting->value.boolean); | |
| 2137 break; | |
| 2138 case GAIM_BLIST_NODE_SETTING_INT: | |
| 2139 type = "int"; | |
| 2140 data_val = g_strdup_printf("%d", setting->value.integer); | |
| 2141 break; | |
| 2142 case GAIM_BLIST_NODE_SETTING_STRING: | |
| 9285 | 2143 if (!setting->value.string) |
| 7693 | 2144 return; |
| 2145 | |
| 2146 type = "string"; | |
| 2147 data_val = g_markup_escape_text(setting->value.string, -1); | |
| 2148 break; | |
| 2149 } | |
| 2150 | |
| 2151 /* this can't happen */ | |
| 9285 | 2152 if (!type || !data_val) |
| 7693 | 2153 return; |
| 2154 | |
| 9285 | 2155 for (i=0; i<indent; i++) fprintf(file, "\t"); |
| 7693 | 2156 |
| 2157 key_val = g_markup_escape_text(key, -1); | |
| 2158 fprintf(file, "<setting name=\"%s\" type=\"%s\">%s</setting>\n", key_val, type, | |
| 2159 data_val); | |
| 2160 | |
| 2161 g_free(key_val); | |
| 2162 g_free(data_val); | |
| 2163 } | |
| 2164 | |
| 5228 | 2165 static void blist_print_group_settings(gpointer key, gpointer data, |
| 9285 | 2166 gpointer user_data) |
| 2167 { | |
| 7693 | 2168 blist_print_setting(key, data, user_data, 3); |
| 5228 | 2169 } |
| 2170 | |
| 2171 static void blist_print_buddy_settings(gpointer key, gpointer data, | |
| 9285 | 2172 gpointer user_data) |
| 2173 { | |
| 7693 | 2174 blist_print_setting(key, data, user_data, 5); |
| 5228 | 2175 } |
| 2176 | |
| 6695 | 2177 static void blist_print_cnode_settings(gpointer key, gpointer data, |
| 9285 | 2178 gpointer user_data) |
| 2179 { | |
| 7693 | 2180 blist_print_setting(key, data, user_data, 4); |
| 6695 | 2181 } |
| 2182 | |
| 5234 | 2183 static void blist_print_chat_components(gpointer key, gpointer data, |
| 2184 gpointer user_data) { | |
| 2185 char *key_val; | |
| 2186 char *data_val; | |
| 2187 FILE *file = user_data; | |
| 2188 | |
| 9285 | 2189 if (!key || !data) |
| 5234 | 2190 return; |
| 2191 | |
| 2192 key_val = g_markup_escape_text(key, -1); | |
| 2193 data_val = g_markup_escape_text(data, -1); | |
| 2194 | |
| 2195 fprintf(file, "\t\t\t\t<component name=\"%s\">%s</component>\n", key_val, | |
| 2196 data_val); | |
| 2197 g_free(key_val); | |
| 2198 g_free(data_val); | |
| 2199 } | |
| 2200 | |
| 9285 | 2201 static void print_buddy(FILE *file, GaimBuddy *buddy) |
| 2202 { | |
| 6695 | 2203 char *bud_name = g_markup_escape_text(buddy->name, -1); |
| 2204 char *bud_alias = NULL; | |
| 2205 char *acct_name = g_markup_escape_text(buddy->account->username, -1); | |
| 9285 | 2206 if (buddy->alias) |
| 6695 | 2207 bud_alias= g_markup_escape_text(buddy->alias, -1); |
| 9460 | 2208 fprintf(file, "\t\t\t\t<buddy account=\"%s\" proto=\"%s\">\n", acct_name, |
| 7153 | 2209 gaim_account_get_protocol_id(buddy->account)); |
| 2210 | |
| 6695 | 2211 fprintf(file, "\t\t\t\t\t<name>%s</name>\n", bud_name); |
| 9285 | 2212 if (bud_alias) { |
| 6695 | 2213 fprintf(file, "\t\t\t\t\t<alias>%s</alias>\n", bud_alias); |
| 2214 } | |
| 7726 | 2215 g_hash_table_foreach(buddy->node.settings, blist_print_buddy_settings, file); |
| 6695 | 2216 fprintf(file, "\t\t\t\t</buddy>\n"); |
| 2217 g_free(bud_name); | |
| 2218 g_free(bud_alias); | |
| 2219 g_free(acct_name); | |
| 2220 } | |
| 2221 | |
| 9787 | 2222 |
| 2223 /* check for flagging and account exclusion on buddy */ | |
| 2224 static gboolean blist_buddy_should_save(GaimAccount *exp_acct, GaimBuddy *buddy) | |
| 2225 { | |
| 2226 if (! GAIM_BLIST_NODE_SHOULD_SAVE((GaimBlistNode *) buddy)) | |
| 2227 return FALSE; | |
| 2228 | |
| 2229 if (exp_acct && buddy->account != exp_acct) | |
| 2230 return FALSE; | |
| 2231 | |
| 2232 return TRUE; | |
| 2233 } | |
| 2234 | |
| 2235 | |
| 2236 static void blist_write_buddy(FILE *file, GaimAccount *exp_acct, GaimBuddy *buddy) | |
| 2237 { | |
| 2238 if (blist_buddy_should_save(exp_acct, buddy)) | |
| 2239 print_buddy(file, buddy); | |
| 2240 } | |
| 2241 | |
| 2242 | |
| 2243 /* check for flagging and account exclusion on contact and all members */ | |
| 2244 static gboolean blist_contact_should_save(GaimAccount *exp_acct, GaimContact *contact) | |
| 2245 { | |
| 2246 GaimBlistNode *bnode, *cnode = (GaimBlistNode *) contact; | |
| 2247 | |
| 2248 if (! GAIM_BLIST_NODE_SHOULD_SAVE(cnode)) | |
| 2249 return FALSE; | |
| 2250 | |
| 2251 for (bnode = cnode->child; bnode; bnode = bnode->next) { | |
| 2252 if (! GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
| 2253 continue; | |
| 2254 | |
| 2255 if (blist_buddy_should_save(exp_acct, (GaimBuddy *) bnode)) | |
| 2256 return TRUE; | |
| 2257 } | |
| 2258 | |
| 2259 return FALSE; | |
| 2260 } | |
| 2261 | |
| 2262 | |
| 2263 static void blist_write_contact(FILE *file, GaimAccount *exp_acct, GaimContact *contact) | |
| 2264 { | |
| 2265 GaimBlistNode *bnode, *cnode = (GaimBlistNode *) contact; | |
| 2266 | |
| 2267 if (! blist_contact_should_save(exp_acct, contact)) | |
| 2268 return; | |
| 2269 | |
| 2270 fprintf(file, "\t\t\t<contact"); | |
| 2271 if (contact->alias) { | |
| 2272 char *alias = g_markup_escape_text(contact->alias, -1); | |
| 2273 fprintf(file, " alias=\"%s\"", alias); | |
| 2274 g_free(alias); | |
| 2275 } | |
| 2276 fprintf(file, ">\n"); | |
| 2277 | |
| 2278 for (bnode = cnode->child; bnode; bnode = bnode->next) { | |
| 2279 if (GAIM_BLIST_NODE_IS_BUDDY(bnode)) { | |
| 2280 blist_write_buddy(file, exp_acct, (GaimBuddy *) bnode); | |
| 2281 } | |
| 2282 } | |
| 2283 | |
| 2284 g_hash_table_foreach(cnode->settings, blist_print_cnode_settings, file); | |
| 2285 fprintf(file, "\t\t\t</contact>\n"); | |
| 2286 } | |
| 2287 | |
| 2288 | |
| 2289 static void blist_write_chat(FILE *file, GaimAccount *exp_acct, GaimChat *chat) | |
| 2290 { | |
| 2291 char *acct_name; | |
| 2292 | |
| 2293 if (! GAIM_BLIST_NODE_SHOULD_SAVE((GaimBlistNode *) chat)) | |
| 2294 return; | |
| 2295 | |
| 2296 if (exp_acct && chat->account != exp_acct) | |
| 2297 return; | |
| 10343 | 2298 |
| 9787 | 2299 acct_name = g_markup_escape_text(chat->account->username, -1); |
| 2300 fprintf(file, "\t\t\t<chat proto=\"%s\" account=\"%s\">\n", | |
| 2301 gaim_account_get_protocol_id(chat->account), acct_name); | |
| 2302 g_free(acct_name); | |
| 2303 | |
| 2304 if (chat->alias) { | |
| 2305 char *chat_alias = g_markup_escape_text(chat->alias, -1); | |
| 2306 fprintf(file, "\t\t\t\t<alias>%s</alias>\n", chat_alias); | |
| 2307 g_free(chat_alias); | |
| 2308 } | |
| 2309 | |
| 2310 g_hash_table_foreach(chat->components, blist_print_chat_components, file); | |
| 2311 g_hash_table_foreach(chat->node.settings, blist_print_cnode_settings, file); | |
| 2312 | |
| 2313 fprintf(file, "\t\t\t</chat>\n"); | |
| 2314 } | |
| 2315 | |
| 2316 | |
| 2317 static void blist_write_group(FILE *file, GaimAccount *exp_acct, GaimGroup *group) | |
| 2318 { | |
| 2319 GaimBlistNode *cnode, *gnode = (GaimBlistNode *) group; | |
| 2320 char *group_name; | |
| 2321 | |
| 2322 if (! GAIM_BLIST_NODE_SHOULD_SAVE(gnode)) | |
| 2323 return; | |
| 2324 | |
| 2325 if (exp_acct && ! gaim_group_on_account(group, exp_acct)) | |
| 2326 return; | |
| 2327 | |
| 2328 group_name = g_markup_escape_text(group->name, -1); | |
| 2329 fprintf(file, "\t\t<group name=\"%s\">\n", group_name); | |
| 2330 g_free(group_name); | |
| 2331 | |
| 2332 g_hash_table_foreach(group->node.settings, | |
| 2333 blist_print_group_settings, file); | |
| 2334 | |
| 2335 for (cnode = gnode->child; cnode; cnode = cnode->next) { | |
| 2336 if (GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
| 2337 blist_write_contact(file, exp_acct, (GaimContact *) cnode); | |
| 2338 } else if (GAIM_BLIST_NODE_IS_CHAT(cnode)) { | |
| 2339 blist_write_chat(file, exp_acct, (GaimChat *) cnode); | |
| 2340 } | |
| 2341 } | |
| 2342 | |
| 2343 fprintf(file, "\t\t</group>\n"); | |
| 2344 } | |
| 2345 | |
| 2346 | |
| 2347 static void blist_write_privacy_account(FILE *file, GaimAccount *exp_acct, GaimAccount *account) | |
| 2348 { | |
| 2349 char *acct_name; | |
| 2350 GSList *buds; | |
| 2351 | |
| 2352 if(exp_acct && exp_acct != account) | |
| 2353 return; | |
| 2354 | |
| 2355 acct_name = g_markup_escape_text(account->username, -1); | |
| 2356 fprintf(file, "\t\t<account proto=\"%s\" name=\"%s\" mode=\"%d\">\n", | |
| 2357 gaim_account_get_protocol_id(account), | |
| 2358 acct_name, account->perm_deny); | |
| 2359 g_free(acct_name); | |
| 2360 | |
| 2361 for (buds = account->permit; buds; buds = buds->next) { | |
| 2362 char *bud_name = g_markup_escape_text(buds->data, -1); | |
| 2363 fprintf(file, "\t\t\t<permit>%s</permit>\n", bud_name); | |
| 2364 g_free(bud_name); | |
| 2365 } | |
| 2366 | |
| 2367 for (buds = account->deny; buds; buds = buds->next) { | |
| 2368 char *bud_name = g_markup_escape_text(buds->data, -1); | |
| 2369 fprintf(file, "\t\t\t<block>%s</block>\n", bud_name); | |
| 2370 g_free(bud_name); | |
| 2371 } | |
| 2372 | |
| 2373 fprintf(file, "\t\t</account>\n"); | |
| 2374 } | |
| 2375 | |
| 2376 | |
| 9285 | 2377 static void gaim_blist_write(FILE *file, GaimAccount *exp_acct) |
| 2378 { | |
|
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2379 GList *accounts; |
| 9787 | 2380 GaimBlistNode *gnode; |
| 2381 | |
| 5228 | 2382 fprintf(file, "<?xml version='1.0' encoding='UTF-8' ?>\n"); |
| 2383 fprintf(file, "<gaim version=\"1\">\n"); | |
| 2384 fprintf(file, "\t<blist>\n"); | |
| 2385 | |
| 9285 | 2386 for (gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { |
| 9787 | 2387 if (GAIM_BLIST_NODE_IS_GROUP(gnode)) |
| 2388 blist_write_group(file, exp_acct, (GaimGroup *) gnode); | |
| 5228 | 2389 } |
| 2390 | |
| 2391 fprintf(file, "\t</blist>\n"); | |
| 2392 fprintf(file, "\t<privacy>\n"); | |
| 2393 | |
| 9787 | 2394 for (accounts = gaim_accounts_get_all(); accounts; accounts = accounts->next) { |
| 2395 blist_write_privacy_account(file, exp_acct, (GaimAccount *) accounts->data); | |
| 5228 | 2396 } |
| 2397 | |
| 2398 fprintf(file, "\t</privacy>\n"); | |
| 2399 fprintf(file, "</gaim>\n"); | |
| 2400 } | |
| 2401 | |
| 9787 | 2402 |
| 9285 | 2403 void gaim_blist_sync() |
| 2404 { | |
| 5228 | 2405 FILE *file; |
| 10332 | 2406 const char *user_dir = gaim_user_dir(); |
| 5228 | 2407 char *filename; |
| 2408 char *filename_real; | |
| 2409 | |
| 9285 | 2410 if (!user_dir) |
| 5228 | 2411 return; |
| 9285 | 2412 |
| 2413 if (!blist_safe_to_write) { | |
| 5228 | 2414 gaim_debug(GAIM_DEBUG_WARNING, "blist save", |
| 2415 "AHH!! Tried to write the blist before we read it!\n"); | |
| 2416 return; | |
| 2417 } | |
| 2418 | |
| 2419 file = fopen(user_dir, "r"); | |
| 9285 | 2420 if (!file) |
| 5228 | 2421 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); |
| 2422 else | |
| 2423 fclose(file); | |
| 2424 | |
| 2425 filename = g_build_filename(user_dir, "blist.xml.save", NULL); | |
| 2426 | |
| 9285 | 2427 if ((file = fopen(filename, "w"))) { |
| 5228 | 2428 gaim_blist_write(file, NULL); |
| 2429 fclose(file); | |
| 2430 chmod(filename, S_IRUSR | S_IWUSR); | |
| 2431 } else { | |
| 2432 gaim_debug(GAIM_DEBUG_ERROR, "blist save", "Unable to write %s\n", | |
| 2433 filename); | |
| 8549 | 2434 g_free(filename); |
| 2435 return; | |
| 5228 | 2436 } |
| 2437 | |
| 2438 filename_real = g_build_filename(user_dir, "blist.xml", NULL); | |
| 2439 | |
| 9285 | 2440 if (rename(filename, filename_real) < 0) |
| 5228 | 2441 gaim_debug(GAIM_DEBUG_ERROR, "blist save", |
| 2442 "Error renaming %s to %s\n", filename, filename_real); | |
| 2443 | |
| 2444 | |
| 2445 g_free(filename); | |
| 2446 g_free(filename_real); | |
| 2447 } | |
| 2448 | |
| 7693 | 2449 |
| 2450 static void gaim_blist_node_setting_free(struct gaim_blist_node_setting *setting) | |
| 2451 { | |
| 2452 switch(setting->type) { | |
| 2453 case GAIM_BLIST_NODE_SETTING_BOOL: | |
| 2454 case GAIM_BLIST_NODE_SETTING_INT: | |
| 2455 break; | |
| 2456 case GAIM_BLIST_NODE_SETTING_STRING: | |
| 2457 g_free(setting->value.string); | |
| 2458 break; | |
| 2459 } | |
| 8020 | 2460 g_free(setting); |
| 7693 | 2461 } |
| 2462 | |
| 9285 | 2463 static void gaim_blist_node_initialize_settings(GaimBlistNode *node) |
| 7693 | 2464 { |
| 9285 | 2465 if (node->settings) |
| 5228 | 2466 return; |
| 7693 | 2467 |
| 2468 node->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, | |
| 2469 (GDestroyNotify)gaim_blist_node_setting_free); | |
| 2470 } | |
| 2471 | |
| 2472 void gaim_blist_node_remove_setting(GaimBlistNode *node, const char *key) | |
| 2473 { | |
| 2474 g_return_if_fail(node != NULL); | |
| 2475 g_return_if_fail(node->settings != NULL); | |
| 2476 g_return_if_fail(key != NULL); | |
| 2477 | |
| 2478 g_hash_table_remove(node->settings, key); | |
| 9285 | 2479 |
| 2480 schedule_blist_save(); | |
| 5228 | 2481 } |
| 2482 | |
| 7693 | 2483 |
| 2484 void gaim_blist_node_set_bool(GaimBlistNode* node, const char *key, gboolean value) | |
| 2485 { | |
| 2486 struct gaim_blist_node_setting *setting; | |
| 2487 | |
| 2488 g_return_if_fail(node != NULL); | |
| 2489 g_return_if_fail(node->settings != NULL); | |
| 2490 g_return_if_fail(key != NULL); | |
| 2491 | |
| 2492 setting = g_new0(struct gaim_blist_node_setting, 1); | |
| 2493 setting->type = GAIM_BLIST_NODE_SETTING_BOOL; | |
| 2494 setting->value.boolean = value; | |
| 2495 | |
| 2496 g_hash_table_replace(node->settings, g_strdup(key), setting); | |
| 9285 | 2497 |
| 2498 schedule_blist_save(); | |
| 7693 | 2499 } |
| 2500 | |
| 2501 gboolean gaim_blist_node_get_bool(GaimBlistNode* node, const char *key) | |
| 2502 { | |
| 2503 struct gaim_blist_node_setting *setting; | |
| 2504 | |
| 2505 g_return_val_if_fail(node != NULL, FALSE); | |
| 2506 g_return_val_if_fail(node->settings != NULL, FALSE); | |
| 2507 g_return_val_if_fail(key != NULL, FALSE); | |
| 2508 | |
| 2509 setting = g_hash_table_lookup(node->settings, key); | |
| 2510 | |
| 9285 | 2511 if (!setting) |
| 7849 | 2512 return FALSE; |
| 2513 | |
| 7848 | 2514 g_return_val_if_fail(setting->type == GAIM_BLIST_NODE_SETTING_BOOL, FALSE); |
| 2515 | |
| 2516 return setting->value.boolean; | |
| 5228 | 2517 } |
| 2518 | |
| 7693 | 2519 void gaim_blist_node_set_int(GaimBlistNode* node, const char *key, int value) |
| 2520 { | |
| 2521 struct gaim_blist_node_setting *setting; | |
| 2522 | |
| 2523 g_return_if_fail(node != NULL); | |
| 2524 g_return_if_fail(node->settings != NULL); | |
| 2525 g_return_if_fail(key != NULL); | |
| 2526 | |
| 2527 setting = g_new0(struct gaim_blist_node_setting, 1); | |
| 8071 | 2528 setting->type = GAIM_BLIST_NODE_SETTING_INT; |
| 7693 | 2529 setting->value.integer = value; |
| 2530 | |
| 2531 g_hash_table_replace(node->settings, g_strdup(key), setting); | |
| 9285 | 2532 |
| 2533 schedule_blist_save(); | |
| 7693 | 2534 } |
| 2535 | |
| 2536 int gaim_blist_node_get_int(GaimBlistNode* node, const char *key) | |
| 2537 { | |
| 2538 struct gaim_blist_node_setting *setting; | |
| 2539 | |
| 2540 g_return_val_if_fail(node != NULL, 0); | |
| 2541 g_return_val_if_fail(node->settings != NULL, 0); | |
| 2542 g_return_val_if_fail(key != NULL, 0); | |
| 2543 | |
| 2544 setting = g_hash_table_lookup(node->settings, key); | |
| 2545 | |
| 9285 | 2546 if (!setting) |
| 7849 | 2547 return 0; |
| 2548 | |
| 7848 | 2549 g_return_val_if_fail(setting->type == GAIM_BLIST_NODE_SETTING_INT, 0); |
| 2550 | |
| 2551 return setting->value.integer; | |
| 7693 | 2552 } |
| 2553 | |
| 2554 void gaim_blist_node_set_string(GaimBlistNode* node, const char *key, | |
| 5906 | 2555 const char *value) |
| 2556 { | |
| 7693 | 2557 struct gaim_blist_node_setting *setting; |
| 2558 | |
| 2559 g_return_if_fail(node != NULL); | |
| 2560 g_return_if_fail(node->settings != NULL); | |
| 2561 g_return_if_fail(key != NULL); | |
| 2562 | |
| 2563 setting = g_new0(struct gaim_blist_node_setting, 1); | |
| 2564 setting->type = GAIM_BLIST_NODE_SETTING_STRING; | |
| 2565 setting->value.string = g_strdup(value); | |
| 2566 | |
| 2567 g_hash_table_replace(node->settings, g_strdup(key), setting); | |
| 9285 | 2568 |
| 2569 schedule_blist_save(); | |
| 7693 | 2570 } |
| 2571 | |
| 2572 const char *gaim_blist_node_get_string(GaimBlistNode* node, const char *key) | |
| 2573 { | |
| 2574 struct gaim_blist_node_setting *setting; | |
| 2575 | |
| 2576 g_return_val_if_fail(node != NULL, NULL); | |
| 2577 g_return_val_if_fail(node->settings != NULL, NULL); | |
| 2578 g_return_val_if_fail(key != NULL, NULL); | |
| 2579 | |
| 2580 setting = g_hash_table_lookup(node->settings, key); | |
| 2581 | |
| 9285 | 2582 if (!setting) |
| 7849 | 2583 return NULL; |
| 2584 | |
| 7848 | 2585 g_return_val_if_fail(setting->type == GAIM_BLIST_NODE_SETTING_STRING, NULL); |
| 2586 | |
| 2587 return setting->value.string; | |
| 7693 | 2588 } |
| 2589 | |
| 9285 | 2590 GList *gaim_blist_node_get_extended_menu(GaimBlistNode *n) |
| 7693 | 2591 { |
|
8710
36b043fe2740
[gaim-migrate @ 9464]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
2592 GList *menu = NULL; |
| 9030 | 2593 |
| 2594 g_return_val_if_fail(n, NULL); | |
| 2595 | |
| 2596 gaim_signal_emit(gaim_blist_get_handle(), | |
| 2597 "blist-node-extended-menu", | |
| 2598 n, &menu); | |
|
8710
36b043fe2740
[gaim-migrate @ 9464]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
2599 return menu; |
|
36b043fe2740
[gaim-migrate @ 9464]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
2600 } |
|
36b043fe2740
[gaim-migrate @ 9464]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
2601 |
| 9030 | 2602 |
| 2603 GaimBlistNodeAction * | |
| 2604 gaim_blist_node_action_new(char *label, | |
| 2605 void (*callback)(GaimBlistNode *, gpointer), | |
| 2606 gpointer data) | |
| 2607 { | |
| 2608 GaimBlistNodeAction *act = g_new0(GaimBlistNodeAction, 1); | |
| 2609 act->label = label; | |
| 2610 act->callback = callback; | |
| 2611 act->data = data; | |
| 2612 return act; | |
| 8952 | 2613 } |
| 2614 | |
|
8710
36b043fe2740
[gaim-migrate @ 9464]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
2615 |
| 9285 | 2616 int gaim_blist_get_group_size(GaimGroup *group, gboolean offline) |
| 2617 { | |
| 2618 if (!group) | |
| 5228 | 2619 return 0; |
| 2620 | |
| 5277 | 2621 return offline ? group->totalsize : group->currentsize; |
| 5228 | 2622 } |
| 2623 | |
| 9285 | 2624 int gaim_blist_get_group_online_count(GaimGroup *group) |
| 2625 { | |
| 2626 if (!group) | |
| 5228 | 2627 return 0; |
| 2628 | |
| 5277 | 2629 return group->online; |
| 5228 | 2630 } |
| 2631 | |
|
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2632 void |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2633 gaim_blist_set_ui_ops(GaimBlistUiOps *ops) |
|
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2634 { |
|
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2635 blist_ui_ops = ops; |
|
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2636 } |
|
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2637 |
|
7098
770233dad86c
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2638 GaimBlistUiOps * |
|
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2639 gaim_blist_get_ui_ops(void) |
|
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2640 { |
|
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2641 return blist_ui_ops; |
|
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2642 } |
|
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2643 |
|
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2644 |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2645 void * |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2646 gaim_blist_get_handle(void) |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2647 { |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2648 static int handle; |
| 5228 | 2649 |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2650 return &handle; |
|
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 |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2653 void |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2654 gaim_blist_init(void) |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2655 { |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2656 void *handle = gaim_blist_get_handle(); |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2657 |
|
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2658 gaim_signal_register(handle, "buddy-away", |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2659 gaim_marshal_VOID__POINTER, NULL, 1, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2660 gaim_value_new(GAIM_TYPE_SUBTYPE, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2661 GAIM_SUBTYPE_BLIST_BUDDY)); |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2662 |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2663 gaim_signal_register(handle, "buddy-back", |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2664 gaim_marshal_VOID__POINTER, NULL, 1, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2665 gaim_value_new(GAIM_TYPE_SUBTYPE, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2666 GAIM_SUBTYPE_BLIST_BUDDY)); |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2667 |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2668 gaim_signal_register(handle, "buddy-idle", |
|
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2669 gaim_marshal_VOID__POINTER, NULL, 1, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2670 gaim_value_new(GAIM_TYPE_SUBTYPE, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2671 GAIM_SUBTYPE_BLIST_BUDDY)); |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2672 gaim_signal_register(handle, "buddy-unidle", |
|
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2673 gaim_marshal_VOID__POINTER, NULL, 1, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2674 gaim_value_new(GAIM_TYPE_SUBTYPE, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2675 GAIM_SUBTYPE_BLIST_BUDDY)); |
|
9109
9f21659ecf11
[gaim-migrate @ 9886]
Christian Hammond <chipx86@chipx86.com>
parents:
9030
diff
changeset
|
2676 gaim_signal_register(handle, "buddy-idle-updated", |
|
9f21659ecf11
[gaim-migrate @ 9886]
Christian Hammond <chipx86@chipx86.com>
parents:
9030
diff
changeset
|
2677 gaim_marshal_VOID__POINTER, NULL, 1, |
|
9f21659ecf11
[gaim-migrate @ 9886]
Christian Hammond <chipx86@chipx86.com>
parents:
9030
diff
changeset
|
2678 gaim_value_new(GAIM_TYPE_SUBTYPE, |
|
9f21659ecf11
[gaim-migrate @ 9886]
Christian Hammond <chipx86@chipx86.com>
parents:
9030
diff
changeset
|
2679 GAIM_SUBTYPE_BLIST_BUDDY)); |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2680 |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2681 gaim_signal_register(handle, "buddy-signed-on", |
|
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2682 gaim_marshal_VOID__POINTER, NULL, 1, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2683 gaim_value_new(GAIM_TYPE_SUBTYPE, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2684 GAIM_SUBTYPE_BLIST_BUDDY)); |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2685 |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2686 gaim_signal_register(handle, "buddy-signed-off", |
|
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2687 gaim_marshal_VOID__POINTER, NULL, 1, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2688 gaim_value_new(GAIM_TYPE_SUBTYPE, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2689 GAIM_SUBTYPE_BLIST_BUDDY)); |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2690 |
|
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2691 gaim_signal_register(handle, "update-idle", gaim_marshal_VOID, NULL, 0); |
| 9030 | 2692 |
| 2693 gaim_signal_register(handle, "blist-node-extended-menu", | |
|
8710
36b043fe2740
[gaim-migrate @ 9464]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
2694 gaim_marshal_VOID__POINTER_POINTER, NULL, 2, |
|
36b043fe2740
[gaim-migrate @ 9464]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
2695 gaim_value_new(GAIM_TYPE_SUBTYPE, |
| 9030 | 2696 GAIM_SUBTYPE_BLIST_NODE), |
| 8952 | 2697 gaim_value_new(GAIM_TYPE_BOXED, "GList **")); |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2698 } |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2699 |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2700 void |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2701 gaim_blist_uninit(void) |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2702 { |
| 9285 | 2703 if (blist_save_timer != 0) { |
| 2704 gaim_timeout_remove(blist_save_timer); | |
| 2705 blist_save_timer = 0; | |
| 2706 gaim_blist_sync(); | |
| 2707 } | |
| 2708 | |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2709 gaim_signals_unregister_by_instance(gaim_blist_get_handle()); |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2710 } |
