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