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