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