Mercurial > pidgin
annotate src/status.c @ 10417:823ad21cd95a
[gaim-migrate @ 11668]
Save substatuses as well.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Sat, 25 Dec 2004 20:24:17 +0000 |
| parents | 5b7a74d397cc |
| children | bed2c96bc1fb |
| rev | line source |
|---|---|
| 9944 | 1 /** |
| 10067 | 2 * @file status.c Status API |
| 9944 | 3 * @ingroup core |
| 4 * | |
| 6065 | 5 * gaim |
| 6 * | |
| 8046 | 7 * Gaim is the legal property of its developers, whose names are too numerous |
| 8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 9 * source distribution. | |
| 9944 | 10 * |
| 6065 | 11 * This program is free software; you can redistribute it and/or modify |
| 12 * it under the terms of the GNU General Public License as published by | |
| 13 * the Free Software Foundation; either version 2 of the License, or | |
| 14 * (at your option) any later version. | |
| 15 * | |
| 16 * This program is distributed in the hope that it will be useful, | |
| 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 * GNU General Public License for more details. | |
| 20 * | |
| 21 * You should have received a copy of the GNU General Public License | |
| 22 * along with this program; if not, write to the Free Software | |
| 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 24 */ | |
| 9949 | 25 #include "internal.h" |
| 6065 | 26 |
| 9949 | 27 #include "blist.h" |
| 10400 | 28 #include "core.h" |
| 9949 | 29 #include "debug.h" |
| 10337 | 30 #include "notify.h" |
| 9949 | 31 #include "prefs.h" |
| 6065 | 32 #include "status.h" |
| 33 #include "util.h" | |
| 10337 | 34 #include "xmlnode.h" |
| 6065 | 35 |
| 9949 | 36 /** |
| 37 * A type of status. | |
| 38 */ | |
| 39 struct _GaimStatusType | |
| 40 { | |
| 41 GaimStatusPrimitive primitive; | |
|
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6321
diff
changeset
|
42 |
| 9949 | 43 char *id; |
| 44 char *name; | |
| 45 char *primary_attr_id; | |
| 46 | |
| 47 gboolean saveable; | |
| 48 gboolean user_settable; | |
| 49 gboolean independent; | |
| 50 | |
| 51 GList *attrs; | |
| 52 }; | |
|
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6321
diff
changeset
|
53 |
| 9949 | 54 /** |
| 55 * A status attribute. | |
| 56 */ | |
| 57 struct _GaimStatusAttr | |
| 58 { | |
| 59 char *id; | |
| 60 char *name; | |
| 61 GaimValue *value_type; | |
| 62 }; | |
| 6065 | 63 |
| 9949 | 64 /** |
| 65 * A list of statuses. | |
| 66 */ | |
| 67 struct _GaimPresence | |
| 68 { | |
| 69 GaimPresenceContext context; | |
| 70 | |
| 71 gboolean idle; | |
| 72 time_t idle_time; | |
| 10006 | 73 time_t login_time; |
| 9949 | 74 |
| 75 unsigned int warning_level; | |
| 6065 | 76 |
| 9949 | 77 GList *statuses; |
| 78 GHashTable *status_table; | |
| 79 | |
| 80 GaimStatus *active_status; | |
| 6065 | 81 |
| 9949 | 82 union |
| 83 { | |
| 84 GaimAccount *account; | |
| 85 | |
| 86 struct | |
| 87 { | |
| 88 GaimConversation *conv; | |
| 89 char *user; | |
| 90 | |
| 91 } chat; | |
| 6065 | 92 |
| 9949 | 93 struct |
| 94 { | |
| 95 GaimAccount *account; | |
| 96 char *name; | |
| 97 size_t ref_count; | |
| 98 GList *buddies; | |
| 99 | |
| 100 } buddy; | |
| 101 | |
| 102 } u; | |
| 103 }; | |
| 104 | |
| 105 /** | |
| 106 * An active status. | |
| 107 */ | |
| 108 struct _GaimStatus | |
| 6065 | 109 { |
| 9949 | 110 GaimStatusType *type; |
| 111 GaimPresence *presence; | |
| 112 | |
| 113 const char *title; | |
| 6065 | 114 |
| 9949 | 115 gboolean active; |
| 6065 | 116 |
| 9949 | 117 GHashTable *attr_values; |
| 118 }; | |
| 6065 | 119 |
| 120 typedef struct | |
| 121 { | |
| 9949 | 122 GaimAccount *account; |
| 123 char *name; | |
| 124 } GaimStatusBuddyKey; | |
| 125 | |
| 10337 | 126 /** |
| 127 * The information of a snap-shot of the statuses of all | |
| 128 * your accounts. Basically these are your saved away messages. | |
| 129 * There is an overall status and message that applies to | |
| 130 * all your accounts, and then each individual account can | |
| 131 * optionally have a different custom status and message. | |
| 9949 | 132 * |
| 10337 | 133 * The changes to status.xml caused by the new status API |
| 134 * are fully backward compatible. The new status API just | |
| 135 * adds the optional sub-statuses to the XML file. | |
| 9949 | 136 */ |
| 10337 | 137 struct _GaimStatusSaved |
| 9949 | 138 { |
| 10348 | 139 char *title; |
| 140 GaimStatusPrimitive type; | |
| 9949 | 141 char *message; |
| 142 | |
| 10348 | 143 GList *substatuses; /**< A list of GaimStatusSavedSub's. */ |
| 10337 | 144 }; |
| 9949 | 145 |
| 10337 | 146 struct _GaimStatusSavedSub |
| 147 { | |
| 148 GaimAccount *account; | |
| 10348 | 149 const GaimStatusType *type; |
| 10337 | 150 char *message; |
| 151 }; | |
| 9949 | 152 |
| 153 static int primitive_scores[] = | |
| 154 { | |
| 155 0, /* unset */ | |
| 156 -500, /* offline */ | |
| 157 0, /* online */ | |
| 158 100, /* available */ | |
| 159 -75, /* unavailable */ | |
| 160 -50, /* hidden */ | |
| 161 -100, /* away */ | |
| 162 -200 /* extended away */ | |
| 163 -10, /* idle, special case. */ | |
| 164 -5 /* idle time, special case. */ | |
| 165 }; | |
| 166 | |
| 167 static GHashTable *buddy_presences = NULL; | |
| 10337 | 168 static GList *saved_statuses = NULL; |
| 10415 | 169 gboolean have_read_saved_statuses = FALSE; |
| 9949 | 170 |
| 171 #define SCORE_IDLE 5 | |
| 172 #define SCORE_IDLE_TIME 6 | |
| 173 | |
| 10348 | 174 /** |
| 175 * Elements of this array correspond to the GaimStatusPrimitive | |
| 176 * enumeration. | |
| 177 */ | |
| 178 static const char *primitive_names[] = | |
| 179 { | |
| 180 "unset", | |
| 181 "offline", | |
| 182 "available", | |
| 183 "unavailable", | |
| 184 "hidden", | |
| 185 "away", | |
| 186 "extended_away" | |
| 187 }; | |
| 188 | |
| 189 static GaimStatusPrimitive | |
| 190 gaim_primitive_get_type(const char *name) | |
| 191 { | |
| 192 int i; | |
| 193 | |
| 194 g_return_val_if_fail(name != NULL, GAIM_STATUS_UNSET); | |
| 195 | |
| 196 for (i = 0; i < GAIM_STATUS_NUM_PRIMITIVES; i++) | |
| 197 { | |
| 198 if (!strcmp(name, primitive_names[i])) | |
| 199 return i; | |
| 200 } | |
| 201 | |
| 202 return GAIM_STATUS_UNSET; | |
| 203 } | |
| 204 | |
| 9949 | 205 /************************************************************************** |
| 206 * GaimStatusType API | |
| 207 **************************************************************************/ | |
| 208 GaimStatusType * | |
| 209 gaim_status_type_new_full(GaimStatusPrimitive primitive, const char *id, | |
| 10009 | 210 const char *name, gboolean saveable, |
| 211 gboolean user_settable, gboolean independent) | |
| 9949 | 212 { |
| 213 GaimStatusType *status_type; | |
| 214 | |
| 215 g_return_val_if_fail(primitive != GAIM_STATUS_UNSET, NULL); | |
| 216 g_return_val_if_fail(id != NULL, NULL); | |
| 217 g_return_val_if_fail(name != NULL, NULL); | |
| 218 | |
| 219 status_type = g_new0(GaimStatusType, 1); | |
| 220 | |
| 221 status_type->primitive = primitive; | |
| 222 status_type->id = g_strdup(id); | |
| 223 status_type->name = g_strdup(name); | |
| 224 status_type->saveable = saveable; | |
| 225 status_type->user_settable = user_settable; | |
| 226 status_type->independent = independent; | |
| 227 | |
| 228 return status_type; | |
| 229 } | |
| 230 | |
| 231 GaimStatusType * | |
| 232 gaim_status_type_new(GaimStatusPrimitive primitive, const char *id, | |
| 10009 | 233 const char *name, gboolean user_settable) |
| 9949 | 234 { |
| 235 g_return_val_if_fail(primitive != GAIM_STATUS_UNSET, NULL); | |
| 236 g_return_val_if_fail(id != NULL, NULL); | |
| 237 g_return_val_if_fail(name != NULL, NULL); | |
| 238 | |
| 239 return gaim_status_type_new_full(primitive, id, name, FALSE, | |
| 240 user_settable, FALSE); | |
| 241 } | |
| 242 | |
| 243 GaimStatusType * | |
| 244 gaim_status_type_new_with_attrs(GaimStatusPrimitive primitive, | |
| 245 const char *id, const char *name, | |
| 246 gboolean saveable, gboolean user_settable, | |
| 247 gboolean independent, const char *attr_id, | |
| 248 const char *attr_name, GaimValue *attr_value, | |
| 249 ...) | |
| 250 { | |
| 251 GaimStatusType *status_type; | |
| 252 va_list args; | |
| 253 | |
| 254 g_return_val_if_fail(primitive != GAIM_STATUS_UNSET, NULL); | |
| 255 g_return_val_if_fail(id != NULL, NULL); | |
| 256 g_return_val_if_fail(name != NULL, NULL); | |
| 10012 | 257 g_return_val_if_fail(attr_id != NULL, NULL); |
| 9949 | 258 g_return_val_if_fail(attr_name != NULL, NULL); |
| 259 g_return_val_if_fail(attr_value != NULL, NULL); | |
| 260 | |
| 261 status_type = gaim_status_type_new_full(primitive, id, name, saveable, | |
| 262 user_settable, independent); | |
| 263 | |
| 10010 | 264 /* Add the first attribute */ |
| 9949 | 265 gaim_status_type_add_attr(status_type, attr_id, attr_name, attr_value); |
| 266 | |
| 267 va_start(args, attr_value); | |
| 268 gaim_status_type_add_attrs_vargs(status_type, args); | |
| 269 va_end(args); | |
| 270 | |
| 271 return status_type; | |
| 272 } | |
| 273 | |
| 274 void | |
| 275 gaim_status_type_destroy(GaimStatusType *status_type) | |
| 276 { | |
| 277 GList *l; | |
| 278 | |
| 279 g_return_if_fail(status_type != NULL); | |
| 280 | |
| 281 g_free(status_type->id); | |
| 282 g_free(status_type->name); | |
| 283 | |
| 284 if (status_type->primary_attr_id != NULL) | |
| 285 g_free(status_type->primary_attr_id); | |
| 286 | |
| 287 if (status_type->attrs != NULL) | |
| 288 { | |
| 289 for (l = status_type->attrs; l != NULL; l = l->next) | |
| 290 gaim_status_attr_destroy((GaimStatusAttr *)l->data); | |
| 291 | |
| 292 g_list_free(status_type->attrs); | |
| 293 } | |
| 294 | |
| 295 g_free(status_type); | |
| 296 } | |
| 297 | |
| 298 void | |
| 299 gaim_status_type_set_primary_attr(GaimStatusType *status_type, const char *id) | |
| 300 { | |
| 301 g_return_if_fail(status_type != NULL); | |
| 302 | |
| 303 if (status_type->primary_attr_id != NULL) | |
| 304 g_free(status_type->primary_attr_id); | |
| 305 | |
| 306 status_type->primary_attr_id = (id == NULL ? NULL : g_strdup(id)); | |
| 307 } | |
| 308 | |
| 309 void | |
| 10197 | 310 gaim_status_type_add_attr(GaimStatusType *status_type, const char *id, |
| 9949 | 311 const char *name, GaimValue *value) |
| 312 { | |
| 313 GaimStatusAttr *attr; | |
| 314 | |
| 315 g_return_if_fail(status_type != NULL); | |
| 316 g_return_if_fail(id != NULL); | |
| 317 g_return_if_fail(name != NULL); | |
| 318 g_return_if_fail(value != NULL); | |
| 319 | |
| 320 attr = gaim_status_attr_new(id, name, value); | |
| 321 | |
| 322 status_type->attrs = g_list_append(status_type->attrs, attr); | |
| 323 } | |
| 324 | |
| 325 void | |
| 326 gaim_status_type_add_attrs_vargs(GaimStatusType *status_type, va_list args) | |
| 327 { | |
| 328 const char *id, *name; | |
| 329 GaimValue *value; | |
| 330 | |
| 331 g_return_if_fail(status_type != NULL); | |
| 332 | |
| 333 while ((id = va_arg(args, const char *)) != NULL) | |
| 334 { | |
| 335 name = va_arg(args, const char *); | |
| 336 g_return_if_fail(name != NULL); | |
| 337 | |
| 338 value = va_arg(args, GaimValue *); | |
| 339 g_return_if_fail(value != NULL); | |
| 6065 | 340 |
| 9949 | 341 gaim_status_type_add_attr(status_type, id, name, value); |
| 342 } | |
| 343 } | |
| 344 | |
| 10010 | 345 void |
| 346 gaim_status_type_add_attrs(GaimStatusType *status_type, const char *id, | |
| 347 const char *name, GaimValue *value, ...) | |
| 348 { | |
| 349 va_list args; | |
| 350 | |
| 351 g_return_if_fail(status_type != NULL); | |
| 352 g_return_if_fail(id != NULL); | |
| 353 g_return_if_fail(name != NULL); | |
| 354 g_return_if_fail(value != NULL); | |
| 355 | |
| 356 /* Add the first attribute */ | |
| 357 gaim_status_type_add_attr(status_type, id, name, value); | |
| 358 | |
| 359 va_start(args, value); | |
| 360 gaim_status_type_add_attrs_vargs(status_type, args); | |
| 361 va_end(args); | |
| 362 } | |
| 363 | |
| 9949 | 364 GaimStatusPrimitive |
| 365 gaim_status_type_get_primitive(const GaimStatusType *status_type) | |
| 366 { | |
| 367 g_return_val_if_fail(status_type != NULL, GAIM_STATUS_UNSET); | |
| 368 | |
| 369 return status_type->primitive; | |
| 370 } | |
| 371 | |
| 372 const char * | |
| 373 gaim_status_type_get_id(const GaimStatusType *status_type) | |
| 374 { | |
| 375 g_return_val_if_fail(status_type != NULL, NULL); | |
| 376 | |
| 377 return status_type->id; | |
| 378 } | |
| 379 | |
| 380 const char * | |
| 381 gaim_status_type_get_name(const GaimStatusType *status_type) | |
| 382 { | |
| 383 g_return_val_if_fail(status_type != NULL, NULL); | |
| 384 | |
| 385 return status_type->name; | |
| 386 } | |
| 387 | |
| 388 gboolean | |
| 389 gaim_status_type_is_saveable(const GaimStatusType *status_type) | |
| 390 { | |
| 391 g_return_val_if_fail(status_type != NULL, FALSE); | |
| 392 | |
| 393 return status_type->saveable; | |
| 394 } | |
| 395 | |
| 396 gboolean | |
| 397 gaim_status_type_is_user_settable(const GaimStatusType *status_type) | |
| 398 { | |
| 399 g_return_val_if_fail(status_type != NULL, FALSE); | |
| 400 | |
| 401 return status_type->user_settable; | |
| 402 } | |
| 403 | |
| 404 gboolean | |
| 405 gaim_status_type_is_independent(const GaimStatusType *status_type) | |
| 406 { | |
| 407 g_return_val_if_fail(status_type != NULL, FALSE); | |
| 408 | |
| 409 return status_type->independent; | |
| 410 } | |
| 411 | |
| 412 gboolean | |
| 10067 | 413 gaim_status_type_is_exclusive(const GaimStatusType *status_type) |
| 414 { | |
| 415 g_return_val_if_fail(status_type != NULL, FALSE); | |
| 416 | |
| 417 return !status_type->independent; | |
| 418 } | |
| 419 | |
| 420 gboolean | |
| 9949 | 421 gaim_status_type_is_available(const GaimStatusType *status_type) |
| 422 { | |
| 423 GaimStatusPrimitive primitive; | |
| 424 | |
| 425 g_return_val_if_fail(status_type != NULL, FALSE); | |
| 426 | |
| 427 primitive = gaim_status_type_get_primitive(status_type); | |
| 428 | |
| 429 return (primitive == GAIM_STATUS_AVAILABLE || | |
| 430 primitive == GAIM_STATUS_HIDDEN); | |
| 431 } | |
| 432 | |
| 433 const char * | |
| 434 gaim_status_type_get_primary_attr(const GaimStatusType *status_type) | |
| 435 { | |
| 436 g_return_val_if_fail(status_type != NULL, NULL); | |
| 437 | |
| 438 return status_type->primary_attr_id; | |
| 439 } | |
| 440 | |
| 441 GaimStatusAttr * | |
| 442 gaim_status_type_get_attr(const GaimStatusType *status_type, const char *id) | |
| 443 { | |
| 444 GList *l; | |
| 445 | |
| 446 g_return_val_if_fail(status_type != NULL, NULL); | |
| 447 g_return_val_if_fail(id != NULL, NULL); | |
| 448 | |
| 449 for (l = status_type->attrs; l != NULL; l = l->next) | |
| 450 { | |
| 451 GaimStatusAttr *attr = (GaimStatusAttr *)l->data; | |
| 452 | |
| 453 if (!strcmp(gaim_status_attr_get_id(attr), id)) | |
| 454 return attr; | |
| 455 } | |
| 456 | |
| 457 return NULL; | |
| 458 } | |
| 459 | |
| 460 const GList * | |
| 461 gaim_status_type_get_attrs(const GaimStatusType *status_type) | |
| 462 { | |
| 463 g_return_val_if_fail(status_type != NULL, NULL); | |
| 464 | |
| 465 return status_type->attrs; | |
| 466 } | |
| 467 | |
| 10348 | 468 const GaimStatusType * |
| 469 gaim_status_type_find_with_id(GList *status_types, const char *id) | |
| 470 { | |
| 471 GaimStatusType *status_type; | |
| 472 | |
| 473 g_return_val_if_fail(id != NULL, NULL); | |
| 474 | |
| 475 while (status_types != NULL) | |
| 476 { | |
| 477 status_type = status_types->data; | |
| 478 | |
| 479 if (!strcmp(id, status_type->id)) | |
| 480 return status_type; | |
| 481 } | |
| 482 | |
| 483 return NULL; | |
| 484 } | |
| 485 | |
| 9949 | 486 |
| 487 /************************************************************************** | |
| 488 * GaimStatusAttr API | |
| 489 **************************************************************************/ | |
| 490 GaimStatusAttr * | |
| 491 gaim_status_attr_new(const char *id, const char *name, GaimValue *value_type) | |
| 492 { | |
| 493 GaimStatusAttr *attr; | |
| 494 | |
| 495 g_return_val_if_fail(id != NULL, NULL); | |
| 496 g_return_val_if_fail(name != NULL, NULL); | |
| 497 g_return_val_if_fail(value_type != NULL, NULL); | |
| 498 | |
| 499 attr = g_new0(GaimStatusAttr, 1); | |
| 500 | |
| 501 attr->id = g_strdup(id); | |
| 502 attr->name = g_strdup(name); | |
| 503 attr->value_type = value_type; | |
| 504 | |
| 505 return attr; | |
| 506 } | |
| 507 | |
| 508 void | |
| 509 gaim_status_attr_destroy(GaimStatusAttr *attr) | |
| 510 { | |
| 511 g_return_if_fail(attr != NULL); | |
| 512 | |
| 513 g_free(attr->id); | |
| 514 g_free(attr->name); | |
| 515 | |
| 516 gaim_value_destroy(attr->value_type); | |
| 517 | |
| 518 g_free(attr); | |
| 519 } | |
| 520 | |
| 521 const char * | |
| 522 gaim_status_attr_get_id(const GaimStatusAttr *attr) | |
| 523 { | |
| 524 g_return_val_if_fail(attr != NULL, NULL); | |
| 525 | |
| 526 return attr->id; | |
| 527 } | |
| 528 | |
| 529 const char * | |
| 530 gaim_status_attr_get_name(const GaimStatusAttr *attr) | |
| 531 { | |
| 532 g_return_val_if_fail(attr != NULL, NULL); | |
| 533 | |
| 534 return attr->name; | |
| 535 } | |
| 536 | |
| 537 GaimValue * | |
| 538 gaim_status_attr_get_value_type(const GaimStatusAttr *attr) | |
| 539 { | |
| 540 g_return_val_if_fail(attr != NULL, NULL); | |
| 541 | |
| 542 return attr->value_type; | |
| 543 } | |
| 544 | |
| 545 | |
| 546 /************************************************************************** | |
| 547 * GaimStatus API | |
| 548 **************************************************************************/ | |
| 549 GaimStatus * | |
| 550 gaim_status_new(GaimStatusType *status_type, GaimPresence *presence) | |
| 551 { | |
| 552 GaimStatus *status; | |
| 553 const GList *l; | |
| 554 | |
| 555 g_return_val_if_fail(status_type != NULL, NULL); | |
| 556 g_return_val_if_fail(presence != NULL, NULL); | |
| 557 | |
| 558 status = g_new0(GaimStatus, 1); | |
| 559 | |
| 560 status->type = status_type; | |
| 561 status->presence = presence; | |
| 562 | |
| 563 status->attr_values = | |
| 564 g_hash_table_new_full(g_str_hash, g_str_equal, g_free, | |
| 565 (GDestroyNotify)gaim_value_destroy); | |
| 566 | |
| 567 for (l = gaim_status_type_get_attrs(status_type); l != NULL; l = l->next) | |
| 568 { | |
| 569 GaimStatusAttr *attr = (GaimStatusAttr *)l->data; | |
| 570 GaimValue *value = gaim_status_attr_get_value_type(attr); | |
| 571 GaimValue *new_value = gaim_value_dup(value); | |
| 572 | |
| 573 g_hash_table_insert(status->attr_values, | |
| 10197 | 574 g_strdup(gaim_status_attr_get_id(attr)), |
| 575 new_value); | |
| 9949 | 576 } |
| 577 | |
| 578 return status; | |
| 579 } | |
| 580 | |
| 581 void | |
| 582 gaim_status_destroy(GaimStatus *status) | |
| 583 { | |
| 584 g_return_if_fail(status != NULL); | |
| 585 | |
| 586 gaim_status_set_active(status, FALSE); | |
| 587 | |
| 588 g_hash_table_destroy(status->attr_values); | |
| 589 | |
| 590 g_free(status); | |
| 591 } | |
| 6065 | 592 |
| 593 static void | |
| 9949 | 594 notify_buddy_status_update(GaimBuddy *buddy, GaimPresence *presence, |
| 595 GaimStatus *old_status, GaimStatus *new_status) | |
| 596 { | |
| 597 GaimBlistUiOps *ops = gaim_blist_get_ui_ops(); | |
| 598 | |
| 599 if (gaim_prefs_get_bool("/core/logging/log_system") && | |
| 600 gaim_prefs_get_bool("/core/logging/log_away_state")) | |
| 601 { | |
| 602 time_t current_time = time(NULL); | |
| 603 const char *buddy_alias = gaim_buddy_get_alias(buddy); | |
| 604 char *tmp = NULL; | |
| 605 | |
| 606 if (!gaim_status_is_available(old_status) && | |
| 607 gaim_status_is_available(new_status)) | |
| 608 { | |
| 609 tmp = g_strdup_printf(_("%s came back"), buddy_alias); | |
| 610 } | |
| 611 else if (gaim_status_is_available(old_status) && | |
| 612 !gaim_status_is_available(new_status)) | |
| 613 { | |
| 614 tmp = g_strdup_printf(_("%s went away"), buddy_alias); | |
| 615 } | |
| 616 | |
| 617 if (tmp != NULL) | |
| 618 { | |
| 619 GaimLog *log = gaim_account_get_log(buddy->account); | |
| 620 | |
| 621 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, buddy_alias, | |
| 622 current_time, tmp); | |
| 623 g_free(tmp); | |
| 624 } | |
| 625 } | |
| 626 | |
| 10012 | 627 |
| 628 | |
| 629 if (ops != NULL && ops->update != NULL) | |
| 630 ops->update(gaim_get_blist(), (GaimBlistNode*)buddy); | |
| 9949 | 631 } |
| 632 | |
| 633 static void | |
| 634 notify_status_update(GaimPresence *presence, GaimStatus *old_status, | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
635 GaimStatus *new_status) |
| 6065 | 636 { |
| 9949 | 637 GaimPresenceContext context = gaim_presence_get_context(presence); |
| 638 | |
| 639 if (context == GAIM_PRESENCE_CONTEXT_ACCOUNT) | |
| 640 { | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
641 GaimAccount *account = gaim_presence_get_account(presence); |
| 9949 | 642 GaimAccountUiOps *ops = gaim_accounts_get_ui_ops(); |
| 643 | |
| 10400 | 644 if (gaim_account_get_enabled(account, gaim_core_get_ui())) |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
645 { |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
646 GaimPluginProtocolInfo *prpl_info = NULL; |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
647 GaimPlugin *prpl; |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
648 |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
649 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
650 |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
651 if (prpl != NULL) |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
652 { |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
653 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
654 |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
655 if (prpl_info != NULL && prpl_info->set_status != NULL) |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
656 prpl_info->set_status(account, new_status); |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
657 } |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
658 } |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
659 |
| 9949 | 660 if (ops != NULL && ops->status_changed != NULL) |
| 661 { | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
662 ops->status_changed(account, new_status); |
| 9949 | 663 } |
| 664 } | |
| 665 else if (context == GAIM_PRESENCE_CONTEXT_CONV) | |
| 666 { | |
| 667 #if 0 | |
| 668 GaimConversationUiOps *ops; | |
| 669 GaimConversation *conv; | |
| 670 | |
| 671 conv = gaim_status_get_conversation(new_status); | |
| 10348 | 672 /* |
| 673 * TODO: Probably need to do some of the following here? This is copied | |
| 674 * from some old status code that was removed. | |
| 675 * | |
| 676 * char *tmp = g_strdup_printf(_("%s logged in."), alias); | |
| 677 * gaim_conversation_write(c, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
| 678 * g_free(tmp); | |
| 679 * | |
| 680 * char *tmp = g_strdup_printf(_("%s logged out."), alias); | |
| 681 * gaim_conversation_write(c, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
| 682 * g_free(tmp); | |
| 683 * | |
| 684 * char *tmp = g_strdup_printf(_("%s signed off"), alias); | |
| 685 * gaim_log_write(log, GAIM_MESSAGE_SYSTEM, (alias ? alias : name), current_time, tmp); | |
| 686 * g_free(tmp); | |
| 687 * | |
| 688 * serv_got_typing_stopped(gc, name); | |
| 689 * | |
| 690 * gaim_conversation_update(c, GAIM_CONV_UPDATE_AWAY); | |
| 691 */ | |
| 9949 | 692 #endif |
| 693 } | |
| 694 else if (context == GAIM_PRESENCE_CONTEXT_BUDDY) | |
| 695 { | |
| 696 const GList *l; | |
| 697 | |
| 698 for (l = gaim_presence_get_buddies(presence); l != NULL; l = l->next) | |
| 699 { | |
| 700 notify_buddy_status_update((GaimBuddy *)l->data, presence, | |
| 701 old_status, new_status); | |
| 702 } | |
| 10348 | 703 |
| 704 /* | |
| 705 * TODO: Maybe we should do this here? | |
| 706 * GaimLog *log = gaim_account_get_log(account); | |
| 707 * char *tmp = g_strdup_printf(_("%s signed on"), alias); | |
| 708 * gaim_log_write(log, GAIM_MESSAGE_SYSTEM, (alias ? alias : name), current_time, tmp); | |
| 709 * g_free(tmp); | |
| 710 */ | |
| 9949 | 711 } |
| 712 } | |
| 713 | |
| 10204 | 714 static void |
| 715 status_has_changed(GaimStatus *status) | |
| 9949 | 716 { |
| 717 GaimPresence *presence; | |
| 718 GaimStatus *old_status; | |
| 719 | |
| 720 presence = gaim_status_get_presence(status); | |
| 721 old_status = gaim_presence_get_active_status(presence); | |
| 722 | |
| 10204 | 723 /* |
| 724 * If this status is exclusive, then we must be setting it to "active." | |
| 725 * Since we are setting it to active, we want to set the currently | |
| 726 * active status to "inactive." | |
| 727 */ | |
| 728 if (gaim_status_is_exclusive(status)) | |
| 9949 | 729 { |
| 730 const GList *l; | |
| 731 | |
| 10006 | 732 for (l = gaim_presence_get_statuses(presence); l != NULL; l = l->next) |
| 9949 | 733 { |
|
10056
b566449d45f8
[gaim-migrate @ 11021]
Luke Schierer <lschiere@pidgin.im>
parents:
10052
diff
changeset
|
734 GaimStatus *temp_status = l->data; |
| 9949 | 735 |
| 10204 | 736 if (temp_status == status) |
| 737 continue; | |
| 9949 | 738 |
| 10204 | 739 if (gaim_status_is_independent(temp_status)) |
| 9949 | 740 continue; |
| 741 | |
| 742 if (gaim_status_is_active(temp_status)) | |
| 743 { | |
| 744 /* | |
| 10204 | 745 * Since we don't want infinite recursion, we have to set |
| 746 * the active variable ourself instead of calling | |
| 747 * gaim_status_set_active(). | |
| 9949 | 748 */ |
| 749 temp_status->active = FALSE; | |
| 750 | |
| 751 notify_status_update(presence, old_status, temp_status); | |
| 752 | |
| 753 break; | |
| 754 } | |
| 755 } | |
| 756 } | |
| 757 | |
| 10204 | 758 notify_status_update(presence, old_status, status); |
| 759 } | |
| 760 | |
| 761 void | |
| 762 gaim_status_set_active(GaimStatus *status, gboolean active) | |
| 763 { | |
| 764 if (!active && gaim_status_is_exclusive(status)) | |
| 765 { | |
| 766 gaim_debug_error("status", | |
| 767 "Cannot deactivate an exclusive status (%s).\n", | |
| 768 gaim_status_get_id(status)); | |
| 769 return; | |
| 770 } | |
| 771 | |
| 772 g_return_if_fail(status != NULL); | |
| 773 | |
| 774 if (status->active == active) | |
| 775 return; | |
| 776 | |
| 777 status->active = active; | |
| 778 | |
| 779 status_has_changed(status); | |
| 780 } | |
| 781 | |
| 782 void | |
| 783 gaim_status_set_active_with_attrs(GaimStatus *status, gboolean active, va_list args) | |
| 784 { | |
| 785 gboolean changed = FALSE; | |
| 786 const gchar *id; | |
| 787 | |
| 788 if (!active && gaim_status_is_exclusive(status)) | |
| 789 { | |
| 790 gaim_debug_error("status", | |
| 791 "Cannot deactivate an exclusive status (%s).\n", | |
| 792 gaim_status_get_id(status)); | |
| 793 return; | |
| 794 } | |
| 795 | |
| 796 g_return_if_fail(status != NULL); | |
| 797 | |
| 798 if (status->active != active) | |
| 799 changed = TRUE; | |
| 800 | |
| 9949 | 801 status->active = active; |
| 6065 | 802 |
| 10204 | 803 /* Set any attributes */ |
| 804 while ((id = va_arg(args, const char *)) != NULL) | |
| 805 { | |
| 806 GaimValue *value; | |
| 807 value = gaim_status_get_attr_value(status, id); | |
| 808 if (value->type == GAIM_TYPE_STRING) | |
| 809 { | |
| 810 const gchar *string_data = va_arg(args, const char *); | |
| 811 if (((string_data == NULL) && (value->data.string_data == NULL)) || | |
| 812 ((string_data != NULL) && (value->data.string_data != NULL) && | |
| 813 !strcmp(string_data, value->data.string_data))) | |
| 814 { | |
| 815 continue; | |
| 816 } | |
| 817 gaim_status_set_attr_string(status, id, string_data); | |
| 818 changed = TRUE; | |
| 819 } | |
| 820 else if (value->type == GAIM_TYPE_INT) | |
| 821 { | |
| 822 int int_data = va_arg(args, int); | |
| 823 if (int_data == value->data.int_data) | |
| 824 continue; | |
| 825 gaim_status_set_attr_int(status, id, int_data); | |
| 826 changed = TRUE; | |
| 827 } | |
| 828 else if (value->type == GAIM_TYPE_BOOLEAN) | |
| 829 { | |
| 830 gboolean boolean_data = va_arg(args, gboolean); | |
| 831 if (boolean_data == value->data.boolean_data) | |
| 832 continue; | |
| 833 gaim_status_set_attr_int(status, id, boolean_data); | |
| 834 changed = TRUE; | |
| 835 } | |
| 836 else | |
| 837 { | |
| 838 /* We don't know what the data is--skip over it */ | |
| 839 va_arg(args, void *); | |
| 840 } | |
| 841 } | |
| 842 | |
| 843 if (!changed) | |
| 844 return; | |
| 845 | |
| 846 status_has_changed(status); | |
| 9949 | 847 } |
| 848 | |
| 849 void | |
| 850 gaim_status_set_attr_boolean(GaimStatus *status, const char *id, | |
| 851 gboolean value) | |
| 852 { | |
| 853 GaimStatusType *status_type; | |
| 854 GaimValue *attr_value; | |
| 855 | |
| 856 g_return_if_fail(status != NULL); | |
| 857 g_return_if_fail(id != NULL); | |
| 858 | |
| 859 status_type = gaim_status_get_type(status); | |
| 860 | |
| 10197 | 861 /* Make sure this attribute exists and is the correct type. */ |
| 862 attr_value = gaim_status_get_attr_value(status, id); | |
| 863 g_return_if_fail(attr_value != NULL); | |
| 9949 | 864 g_return_if_fail(gaim_value_get_type(attr_value) == GAIM_TYPE_BOOLEAN); |
| 865 | |
| 866 gaim_value_set_boolean(attr_value, value); | |
| 867 } | |
| 868 | |
| 869 void | |
| 870 gaim_status_set_attr_int(GaimStatus *status, const char *id, int value) | |
| 871 { | |
| 872 GaimStatusType *status_type; | |
| 873 GaimValue *attr_value; | |
| 874 | |
| 875 g_return_if_fail(status != NULL); | |
| 876 g_return_if_fail(id != NULL); | |
| 877 | |
| 878 status_type = gaim_status_get_type(status); | |
| 879 | |
| 10197 | 880 /* Make sure this attribute exists and is the correct type. */ |
| 881 attr_value = gaim_status_get_attr_value(status, id); | |
| 882 g_return_if_fail(attr_value != NULL); | |
| 9949 | 883 g_return_if_fail(gaim_value_get_type(attr_value) == GAIM_TYPE_INT); |
| 884 | |
| 885 gaim_value_set_int(attr_value, value); | |
| 6065 | 886 } |
| 887 | |
| 9949 | 888 void |
| 889 gaim_status_set_attr_string(GaimStatus *status, const char *id, | |
| 890 const char *value) | |
| 891 { | |
| 892 GaimStatusType *status_type; | |
| 893 GaimValue *attr_value; | |
| 894 | |
| 895 g_return_if_fail(status != NULL); | |
| 896 g_return_if_fail(id != NULL); | |
| 897 | |
| 898 status_type = gaim_status_get_type(status); | |
| 899 | |
| 10197 | 900 /* Make sure this attribute exists and is the correct type. */ |
| 10196 | 901 attr_value = gaim_status_get_attr_value(status, id); |
| 10197 | 902 g_return_if_fail(attr_value != NULL); |
| 9949 | 903 g_return_if_fail(gaim_value_get_type(attr_value) == GAIM_TYPE_STRING); |
| 904 | |
| 905 gaim_value_set_string(attr_value, value); | |
| 906 } | |
| 907 | |
| 908 GaimStatusType * | |
| 909 gaim_status_get_type(const GaimStatus *status) | |
| 910 { | |
| 911 g_return_val_if_fail(status != NULL, NULL); | |
| 912 | |
| 913 return status->type; | |
| 914 } | |
| 915 | |
| 916 GaimPresence * | |
| 917 gaim_status_get_presence(const GaimStatus *status) | |
| 6065 | 918 { |
| 9949 | 919 g_return_val_if_fail(status != NULL, NULL); |
| 920 | |
| 921 return status->presence; | |
| 922 } | |
| 923 | |
| 924 const char * | |
| 925 gaim_status_get_id(const GaimStatus *status) | |
| 926 { | |
| 927 g_return_val_if_fail(status != NULL, NULL); | |
| 928 | |
| 929 return gaim_status_type_get_id(gaim_status_get_type(status)); | |
| 930 } | |
| 931 | |
| 932 const char * | |
| 933 gaim_status_get_name(const GaimStatus *status) | |
| 934 { | |
| 935 g_return_val_if_fail(status != NULL, NULL); | |
| 936 | |
| 937 return gaim_status_type_get_name(gaim_status_get_type(status)); | |
| 938 } | |
| 939 | |
| 940 gboolean | |
| 941 gaim_status_is_independent(const GaimStatus *status) | |
| 942 { | |
| 943 g_return_val_if_fail(status != NULL, FALSE); | |
| 944 | |
| 945 return gaim_status_type_is_independent(gaim_status_get_type(status)); | |
| 946 } | |
| 947 | |
| 948 gboolean | |
| 10067 | 949 gaim_status_is_exclusive(const GaimStatus *status) |
| 950 { | |
| 951 g_return_val_if_fail(status != NULL, FALSE); | |
| 952 | |
| 953 return gaim_status_type_is_exclusive(gaim_status_get_type(status)); | |
| 954 } | |
| 955 | |
| 956 gboolean | |
| 9949 | 957 gaim_status_is_available(const GaimStatus *status) |
| 958 { | |
| 959 g_return_val_if_fail(status != NULL, FALSE); | |
| 960 | |
| 961 return gaim_status_type_is_available(gaim_status_get_type(status)); | |
| 962 } | |
| 6216 | 963 |
| 9949 | 964 gboolean |
| 965 gaim_status_is_active(const GaimStatus *status) | |
| 966 { | |
| 967 g_return_val_if_fail(status != NULL, FALSE); | |
| 968 | |
| 969 return status->active; | |
| 970 } | |
| 971 | |
|
10040
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
972 gboolean |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
973 gaim_status_is_online(const GaimStatus *status) |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
974 { |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
975 GaimStatusPrimitive primitive; |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
976 |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
977 g_return_val_if_fail( status != NULL, FALSE); |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
978 |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
979 primitive = gaim_status_type_get_primitive(gaim_status_get_type(status)); |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
980 |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
981 return (primitive != GAIM_STATUS_UNSET && |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
982 primitive != GAIM_STATUS_OFFLINE); |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
983 } |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
984 |
| 9949 | 985 GaimValue * |
| 986 gaim_status_get_attr_value(const GaimStatus *status, const char *id) | |
| 987 { | |
| 988 GaimStatusType *status_type; | |
| 989 GaimStatusAttr *attr; | |
| 990 | |
| 991 g_return_val_if_fail(status != NULL, NULL); | |
| 992 g_return_val_if_fail(id != NULL, NULL); | |
| 993 | |
| 994 status_type = gaim_status_get_type(status); | |
| 995 | |
| 996 /* Make sure this attribute exists. */ | |
| 997 attr = gaim_status_type_get_attr(status_type, id); | |
| 998 g_return_val_if_fail(attr != NULL, NULL); | |
| 999 | |
| 1000 return (GaimValue *)g_hash_table_lookup(status->attr_values, id); | |
| 1001 } | |
| 1002 | |
| 1003 gboolean | |
| 1004 gaim_status_get_attr_boolean(const GaimStatus *status, const char *id) | |
| 1005 { | |
| 1006 const GaimValue *value; | |
| 1007 | |
| 1008 g_return_val_if_fail(status != NULL, FALSE); | |
| 1009 g_return_val_if_fail(id != NULL, FALSE); | |
| 1010 | |
| 1011 if ((value = gaim_status_get_attr_value(status, id)) == NULL) | |
| 1012 return FALSE; | |
| 1013 | |
| 10197 | 1014 g_return_val_if_fail(gaim_value_get_type(value) == GAIM_TYPE_BOOLEAN, FALSE); |
| 9949 | 1015 |
| 1016 return gaim_value_get_boolean(value); | |
| 1017 } | |
| 1018 | |
| 1019 int | |
| 1020 gaim_status_get_attr_int(const GaimStatus *status, const char *id) | |
| 1021 { | |
| 1022 const GaimValue *value; | |
| 1023 | |
| 1024 g_return_val_if_fail(status != NULL, FALSE); | |
| 1025 g_return_val_if_fail(id != NULL, FALSE); | |
| 1026 | |
| 1027 if ((value = gaim_status_get_attr_value(status, id)) == NULL) | |
| 1028 return FALSE; | |
| 1029 | |
| 1030 g_return_val_if_fail(gaim_value_get_type(value) == GAIM_TYPE_INT, 0); | |
| 1031 | |
| 1032 return gaim_value_get_int(value); | |
| 1033 } | |
| 1034 | |
| 1035 const char * | |
| 1036 gaim_status_get_attr_string(const GaimStatus *status, const char *id) | |
| 1037 { | |
| 1038 const GaimValue *value; | |
| 1039 | |
| 1040 g_return_val_if_fail(status != NULL, FALSE); | |
| 1041 g_return_val_if_fail(id != NULL, FALSE); | |
| 1042 | |
| 1043 if ((value = gaim_status_get_attr_value(status, id)) == NULL) | |
| 1044 return FALSE; | |
| 1045 | |
| 1046 g_return_val_if_fail(gaim_value_get_type(value) == GAIM_TYPE_STRING, NULL); | |
| 1047 | |
| 1048 return gaim_value_get_string(value); | |
| 1049 } | |
| 1050 | |
| 1051 gint | |
| 1052 gaim_status_compare(const GaimStatus *status1, const GaimStatus *status2) | |
| 1053 { | |
| 1054 GaimStatusType *type1, *type2; | |
| 1055 int score1 = 0, score2 = 0; | |
| 6065 | 1056 |
| 9949 | 1057 if ((status1 == NULL && status2 == NULL) || |
| 1058 (status1 == status2)) | |
| 1059 { | |
| 1060 return 0; | |
| 1061 } | |
| 1062 else if (status1 == NULL) | |
| 1063 return 1; | |
| 1064 else if (status2 == NULL) | |
| 1065 return -1; | |
| 1066 | |
| 1067 type1 = gaim_status_get_type(status1); | |
| 1068 type2 = gaim_status_get_type(status2); | |
| 1069 | |
| 1070 if (gaim_status_is_active(status1)) | |
| 1071 score1 = primitive_scores[gaim_status_type_get_primitive(type1)]; | |
| 1072 | |
| 1073 if (gaim_status_is_active(status2)) | |
| 1074 score2 = primitive_scores[gaim_status_type_get_primitive(type2)]; | |
| 1075 | |
| 1076 if (score1 > score2) | |
| 1077 return -1; | |
| 1078 else if (score1 < score2) | |
| 1079 return 1; | |
| 1080 | |
| 1081 return 0; | |
| 1082 } | |
| 1083 | |
| 1084 | |
| 1085 /************************************************************************** | |
| 1086 * GaimPresence API | |
| 1087 **************************************************************************/ | |
| 1088 GaimPresence * | |
| 1089 gaim_presence_new(GaimPresenceContext context) | |
| 1090 { | |
| 1091 GaimPresence *presence; | |
| 1092 | |
| 1093 g_return_val_if_fail(context != GAIM_PRESENCE_CONTEXT_UNSET, NULL); | |
| 1094 | |
| 1095 presence = g_new0(GaimPresence, 1); | |
| 1096 | |
| 1097 presence->context = context; | |
| 1098 | |
| 1099 presence->status_table = | |
| 10009 | 1100 g_hash_table_new_full(g_str_hash, g_str_equal, |
| 1101 g_free, (GFreeFunc)gaim_status_destroy); | |
| 9949 | 1102 |
| 1103 return presence; | |
| 1104 } | |
| 1105 | |
| 1106 GaimPresence * | |
| 1107 gaim_presence_new_for_account(GaimAccount *account) | |
| 1108 { | |
| 10012 | 1109 GaimPresence *presence = NULL; |
| 9949 | 1110 g_return_val_if_fail(account != NULL, NULL); |
| 1111 | |
| 1112 presence = gaim_presence_new(GAIM_PRESENCE_CONTEXT_ACCOUNT); | |
| 1113 presence->u.account = account; | |
| 10006 | 1114 presence->statuses = gaim_prpl_get_statuses(account, presence); |
| 9949 | 1115 |
| 1116 return presence; | |
| 1117 } | |
| 1118 | |
| 1119 GaimPresence * | |
| 1120 gaim_presence_new_for_conv(GaimConversation *conv) | |
| 1121 { | |
| 1122 GaimPresence *presence; | |
| 1123 | |
| 1124 g_return_val_if_fail(conv != NULL, NULL); | |
| 1125 | |
| 1126 presence = gaim_presence_new(GAIM_PRESENCE_CONTEXT_CONV); | |
| 1127 presence->u.chat.conv = conv; | |
| 10006 | 1128 /* presence->statuses = gaim_prpl_get_statuses(conv->account, presence); ? */ |
| 9949 | 1129 |
| 1130 return presence; | |
| 1131 } | |
| 6216 | 1132 |
| 9949 | 1133 GaimPresence * |
| 1134 gaim_presence_new_for_buddy(GaimBuddy *buddy) | |
| 1135 { | |
| 1136 GaimPresence *presence; | |
| 1137 GaimStatusBuddyKey *key; | |
| 10006 | 1138 GaimAccount *account; |
| 9949 | 1139 |
| 1140 g_return_val_if_fail(buddy != NULL, NULL); | |
| 10012 | 1141 account = buddy->account; |
| 9949 | 1142 |
| 10006 | 1143 account = buddy->account; |
| 1144 | |
| 9949 | 1145 key = g_new0(GaimStatusBuddyKey, 1); |
| 1146 key->account = buddy->account; | |
| 1147 key->name = g_strdup(buddy->name); | |
| 10006 | 1148 |
| 1149 presence = g_hash_table_lookup(buddy_presences, key); | |
| 1150 if (presence == NULL) | |
| 9949 | 1151 { |
| 1152 presence = gaim_presence_new(GAIM_PRESENCE_CONTEXT_BUDDY); | |
| 1153 | |
| 1154 presence->u.buddy.name = g_strdup(buddy->name); | |
| 1155 presence->u.buddy.account = buddy->account; | |
| 10006 | 1156 presence->statuses = gaim_prpl_get_statuses(buddy->account, presence); |
| 9949 | 1157 |
| 1158 g_hash_table_insert(buddy_presences, key, presence); | |
| 1159 } | |
| 1160 else | |
| 1161 { | |
| 1162 g_free(key->name); | |
| 1163 g_free(key); | |
| 1164 } | |
| 1165 | |
| 1166 presence->u.buddy.ref_count++; | |
| 1167 presence->u.buddy.buddies = g_list_append(presence->u.buddy.buddies, | |
| 1168 buddy); | |
| 1169 | |
| 1170 return presence; | |
| 1171 } | |
| 1172 | |
| 1173 void | |
| 1174 gaim_presence_destroy(GaimPresence *presence) | |
| 1175 { | |
| 1176 g_return_if_fail(presence != NULL); | |
| 6216 | 1177 |
| 9949 | 1178 if (gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_BUDDY) |
| 1179 { | |
| 1180 GaimStatusBuddyKey key; | |
| 1181 | |
| 1182 presence->u.buddy.ref_count--; | |
| 1183 | |
| 10077 | 1184 if(presence->u.buddy.ref_count != 0) |
| 1185 return; | |
| 9949 | 1186 |
| 1187 key.account = presence->u.buddy.account; | |
| 1188 key.name = presence->u.buddy.name; | |
| 1189 | |
| 1190 g_hash_table_remove(buddy_presences, &key); | |
| 1191 | |
| 1192 if (presence->u.buddy.name != NULL) | |
| 1193 g_free(presence->u.buddy.name); | |
| 1194 } | |
| 1195 else if (gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_CONV) | |
| 1196 { | |
| 1197 if (presence->u.chat.user != NULL) | |
| 1198 g_free(presence->u.chat.user); | |
| 1199 } | |
| 1200 | |
| 1201 if (presence->statuses != NULL) | |
| 1202 g_list_free(presence->statuses); | |
| 1203 | |
| 1204 g_hash_table_destroy(presence->status_table); | |
| 1205 | |
| 1206 g_free(presence); | |
| 1207 } | |
| 1208 | |
| 1209 void | |
| 1210 gaim_presence_remove_buddy(GaimPresence *presence, GaimBuddy *buddy) | |
| 1211 { | |
| 1212 g_return_if_fail(presence != NULL); | |
| 1213 g_return_if_fail(buddy != NULL); | |
| 1214 g_return_if_fail(gaim_presence_get_context(presence) == | |
| 1215 GAIM_PRESENCE_CONTEXT_BUDDY); | |
| 1216 | |
| 1217 if (g_list_find(presence->u.buddy.buddies, buddy) != NULL) | |
| 1218 { | |
| 1219 presence->u.buddy.buddies = g_list_remove(presence->u.buddy.buddies, | |
| 1220 buddy); | |
| 1221 presence->u.buddy.ref_count--; | |
| 1222 } | |
| 6065 | 1223 } |
| 1224 | |
| 9949 | 1225 void |
| 1226 gaim_presence_add_status(GaimPresence *presence, GaimStatus *status) | |
| 1227 { | |
| 1228 g_return_if_fail(presence != NULL); | |
| 1229 g_return_if_fail(status != NULL); | |
| 1230 | |
| 1231 presence->statuses = g_list_append(presence->statuses, status); | |
| 1232 | |
| 1233 g_hash_table_insert(presence->status_table, | |
| 1234 g_strdup(gaim_status_get_id(status)), status); | |
| 1235 } | |
| 1236 | |
| 1237 void | |
| 1238 gaim_presence_add_presence(GaimPresence *presence, const GList *source_list) | |
| 1239 { | |
| 1240 const GList *l; | |
| 1241 | |
| 1242 g_return_if_fail(presence != NULL); | |
| 1243 g_return_if_fail(source_list != NULL); | |
| 1244 | |
| 1245 for (l = source_list; l != NULL; l = l->next) | |
| 1246 gaim_presence_add_status(presence, (GaimStatus *)l->data); | |
| 1247 } | |
| 1248 | |
| 1249 void | |
| 1250 gaim_presence_set_status_active(GaimPresence *presence, const char *status_id, | |
| 1251 gboolean active) | |
| 1252 { | |
| 1253 GaimStatus *status; | |
| 1254 | |
| 1255 g_return_if_fail(presence != NULL); | |
| 1256 g_return_if_fail(status_id != NULL); | |
| 1257 | |
| 1258 status = gaim_presence_get_status(presence, status_id); | |
| 1259 | |
| 1260 g_return_if_fail(status != NULL); | |
| 10348 | 1261 /* TODO: Should we do the following? */ |
| 1262 /* g_return_if_fail(active == status->active); */ | |
| 9949 | 1263 |
| 10067 | 1264 if (gaim_status_is_exclusive(status)) |
| 9949 | 1265 { |
| 1266 if (!active) | |
| 1267 { | |
| 1268 gaim_debug_warning("status", | |
| 1269 "Attempted to set a non-independent status " | |
| 1270 "(%s) inactive. Only independent statuses " | |
| 1271 "can be specifically marked inactive.", | |
| 1272 status_id); | |
| 1273 | |
| 1274 return; | |
| 1275 } | |
| 1276 | |
| 10052 | 1277 } else if (presence->active_status != NULL) { |
| 1278 gaim_status_set_active(presence->active_status, FALSE); | |
| 9949 | 1279 |
| 1280 } | |
| 1281 | |
| 1282 gaim_status_set_active(status, active); | |
| 10052 | 1283 presence->active_status = status; |
| 9949 | 1284 } |
| 1285 | |
| 1286 void | |
| 1287 gaim_presence_switch_status(GaimPresence *presence, const char *status_id) | |
| 1288 { | |
| 1289 GaimStatus *status; | |
| 1290 | |
| 1291 g_return_if_fail(presence != NULL); | |
| 1292 g_return_if_fail(status_id != NULL); | |
| 1293 | |
| 1294 status = gaim_presence_get_status(presence, status_id); | |
| 1295 | |
| 1296 g_return_if_fail(status != NULL); | |
| 1297 | |
| 1298 if (gaim_status_is_independent(status)) | |
| 1299 return; | |
| 1300 | |
| 1301 if (presence->active_status != NULL) | |
| 1302 gaim_status_set_active(presence->active_status, FALSE); | |
| 1303 | |
| 1304 gaim_status_set_active(status, TRUE); | |
| 1305 } | |
| 1306 | |
| 1307 static void | |
| 1308 update_buddy_idle(GaimBuddy *buddy, GaimPresence *presence, | |
| 1309 time_t current_time, gboolean old_idle, gboolean idle) | |
| 1310 { | |
| 1311 GaimBlistUiOps *ops = gaim_get_blist()->ui_ops; | |
| 1312 | |
| 1313 if (!old_idle && idle) | |
| 1314 { | |
| 1315 gaim_signal_emit(gaim_blist_get_handle(), "buddy-idle", buddy); | |
| 1316 | |
| 1317 if (gaim_prefs_get_bool("/core/logging/log_system") && | |
| 1318 gaim_prefs_get_bool("/core/logging/log_idle_state")) | |
| 1319 { | |
| 1320 GaimLog *log = gaim_account_get_log(buddy->account); | |
| 1321 char *tmp = g_strdup_printf(_("%s became idle"), | |
| 1322 gaim_buddy_get_alias(buddy)); | |
| 1323 | |
| 1324 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, | |
| 1325 gaim_buddy_get_alias(buddy), current_time, tmp); | |
| 1326 g_free(tmp); | |
| 1327 } | |
| 1328 } | |
| 1329 else if (old_idle && !idle) | |
| 1330 { | |
| 1331 gaim_signal_emit(gaim_blist_get_handle(), "buddy-unidle", buddy); | |
| 1332 | |
| 1333 if (gaim_prefs_get_bool("/core/logging/log_system") && | |
| 1334 gaim_prefs_get_bool("/core/logging/log_idle_state")) | |
| 1335 { | |
| 1336 GaimLog *log = gaim_account_get_log(buddy->account); | |
| 1337 char *tmp = g_strdup_printf(_("%s became unidle"), | |
| 1338 gaim_buddy_get_alias(buddy)); | |
| 1339 | |
| 1340 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, | |
| 1341 gaim_buddy_get_alias(buddy), current_time, tmp); | |
| 1342 g_free(tmp); | |
| 1343 } | |
| 1344 } | |
| 1345 | |
| 10378 | 1346 gaim_contact_invalidate_priority_buddy(gaim_buddy_get_contact(buddy)); |
| 9949 | 1347 |
| 1348 if (ops != NULL && ops->update != NULL) | |
| 1349 ops->update(gaim_get_blist(), (GaimBlistNode *)buddy); | |
| 1350 } | |
| 1351 | |
| 1352 void | |
| 1353 gaim_presence_set_idle(GaimPresence *presence, gboolean idle, time_t idle_time) | |
| 1354 { | |
| 1355 gboolean old_idle; | |
| 1356 | |
| 1357 g_return_if_fail(presence != NULL); | |
| 1358 | |
| 1359 if (presence->idle == idle && presence->idle_time == idle_time) | |
| 1360 return; | |
| 1361 | |
| 1362 old_idle = presence->idle; | |
| 1363 presence->idle = idle; | |
| 1364 presence->idle_time = (idle ? idle_time : 0); | |
| 1365 | |
| 1366 if (gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_BUDDY) | |
| 1367 { | |
| 1368 const GList *l; | |
| 1369 time_t current_time = time(NULL); | |
| 1370 | |
| 1371 for (l = gaim_presence_get_buddies(presence); l != NULL; l = l->next) | |
| 1372 { | |
| 1373 update_buddy_idle((GaimBuddy *)l->data, presence, current_time, | |
| 1374 old_idle, idle); | |
| 1375 } | |
| 1376 } | |
| 1377 } | |
| 1378 | |
| 1379 void | |
| 10006 | 1380 gaim_presence_set_login_time(GaimPresence *presence, time_t login_time) |
| 1381 { | |
| 1382 g_return_if_fail(presence != NULL); | |
| 1383 | |
| 1384 if (presence->login_time == login_time) | |
| 1385 return; | |
| 1386 | |
| 1387 presence->login_time = login_time; | |
| 1388 } | |
| 1389 | |
| 1390 void | |
| 9949 | 1391 gaim_presence_set_warning_level(GaimPresence *presence, unsigned int level) |
| 6065 | 1392 { |
| 9949 | 1393 g_return_if_fail(presence != NULL); |
| 1394 g_return_if_fail(level <= 100); | |
| 1395 | |
| 1396 if (presence->warning_level == level) | |
| 1397 return; | |
| 1398 | |
| 1399 presence->warning_level = level; | |
| 1400 | |
| 1401 if (gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_BUDDY) | |
| 1402 { | |
| 1403 GaimBlistUiOps *ops = gaim_get_blist()->ui_ops; | |
| 1404 | |
| 1405 if (ops != NULL && ops->update != NULL) | |
| 1406 { | |
| 1407 const GList *l; | |
| 1408 | |
| 1409 for (l = gaim_presence_get_buddies(presence); | |
| 1410 l != NULL; | |
| 1411 l = l->next) | |
| 1412 { | |
| 1413 ops->update(gaim_get_blist(), (GaimBlistNode *)l->data); | |
| 1414 } | |
| 1415 } | |
| 1416 } | |
| 1417 } | |
| 1418 | |
| 1419 GaimPresenceContext | |
| 1420 gaim_presence_get_context(const GaimPresence *presence) | |
| 1421 { | |
| 1422 g_return_val_if_fail(presence != NULL, GAIM_PRESENCE_CONTEXT_UNSET); | |
| 1423 | |
| 1424 return presence->context; | |
| 1425 } | |
| 1426 | |
| 1427 GaimAccount * | |
| 1428 gaim_presence_get_account(const GaimPresence *presence) | |
| 1429 { | |
| 1430 GaimPresenceContext context; | |
| 1431 | |
| 1432 g_return_val_if_fail(presence != NULL, NULL); | |
| 1433 | |
| 1434 context = gaim_presence_get_context(presence); | |
| 1435 | |
| 1436 g_return_val_if_fail(context == GAIM_PRESENCE_CONTEXT_ACCOUNT || | |
| 1437 context == GAIM_PRESENCE_CONTEXT_BUDDY, NULL); | |
| 1438 | |
| 1439 return presence->u.account; | |
| 1440 } | |
| 1441 | |
| 1442 GaimConversation * | |
| 1443 gaim_presence_get_conversation(const GaimPresence *presence) | |
| 1444 { | |
| 1445 g_return_val_if_fail(presence != NULL, NULL); | |
| 1446 g_return_val_if_fail(gaim_presence_get_context(presence) == | |
| 1447 GAIM_PRESENCE_CONTEXT_CONV, NULL); | |
| 1448 | |
| 1449 return presence->u.chat.conv; | |
| 1450 } | |
| 1451 | |
| 1452 const char * | |
| 1453 gaim_presence_get_chat_user(const GaimPresence *presence) | |
| 1454 { | |
| 1455 g_return_val_if_fail(presence != NULL, NULL); | |
| 1456 g_return_val_if_fail(gaim_presence_get_context(presence) == | |
| 1457 GAIM_PRESENCE_CONTEXT_CONV, NULL); | |
| 1458 | |
| 1459 return presence->u.chat.user; | |
| 1460 } | |
| 1461 | |
| 1462 const GList * | |
| 1463 gaim_presence_get_buddies(const GaimPresence *presence) | |
| 1464 { | |
| 1465 g_return_val_if_fail(presence != NULL, NULL); | |
| 1466 g_return_val_if_fail(gaim_presence_get_context(presence) == | |
| 1467 GAIM_PRESENCE_CONTEXT_BUDDY, NULL); | |
| 1468 | |
| 1469 return presence->u.buddy.buddies; | |
| 1470 } | |
| 1471 | |
| 1472 const GList * | |
| 1473 gaim_presence_get_statuses(const GaimPresence *presence) | |
| 1474 { | |
| 1475 g_return_val_if_fail(presence != NULL, NULL); | |
| 1476 | |
| 1477 return presence->statuses; | |
| 1478 } | |
| 1479 | |
| 1480 GaimStatus * | |
| 1481 gaim_presence_get_status(const GaimPresence *presence, const char *status_id) | |
| 1482 { | |
| 1483 GaimStatus *status; | |
| 10006 | 1484 const GList *l = NULL; |
| 9949 | 1485 |
| 1486 g_return_val_if_fail(presence != NULL, NULL); | |
| 1487 g_return_val_if_fail(status_id != NULL, NULL); | |
| 1488 | |
| 10006 | 1489 /* What's the purpose of this hash table? */ |
| 10012 | 1490 status = (GaimStatus *)g_hash_table_lookup(presence->status_table, |
| 10006 | 1491 status_id); |
| 10012 | 1492 |
| 10006 | 1493 if (status == NULL) { |
| 10012 | 1494 for (l = gaim_presence_get_statuses(presence); |
| 10006 | 1495 l != NULL && status == NULL; l = l->next) |
| 1496 { | |
| 1497 GaimStatus *temp_status = l->data; | |
| 10012 | 1498 |
| 10006 | 1499 if (!strcmp(status_id, gaim_status_get_id(temp_status))) |
| 1500 status = temp_status; | |
| 1501 } | |
| 1502 | |
| 1503 if (status != NULL) | |
| 1504 g_hash_table_insert(presence->status_table, | |
| 1505 g_strdup(gaim_status_get_id(status)), status); | |
| 10012 | 1506 } |
| 9949 | 1507 |
| 1508 return status; | |
| 1509 } | |
| 1510 | |
| 1511 GaimStatus * | |
| 1512 gaim_presence_get_active_status(const GaimPresence *presence) | |
| 1513 { | |
| 1514 g_return_val_if_fail(presence != NULL, NULL); | |
| 1515 | |
| 1516 return presence->active_status; | |
| 1517 } | |
| 1518 | |
| 1519 gboolean | |
| 1520 gaim_presence_is_available(const GaimPresence *presence) | |
| 1521 { | |
| 1522 GaimStatus *status; | |
| 1523 | |
| 1524 g_return_val_if_fail(presence != NULL, FALSE); | |
| 1525 | |
| 1526 status = gaim_presence_get_active_status(presence); | |
| 1527 | |
| 1528 return ((status != NULL && gaim_status_is_available(status)) && | |
| 1529 !gaim_presence_is_idle(presence)); | |
| 1530 } | |
| 1531 | |
| 1532 gboolean | |
| 1533 gaim_presence_is_online(const GaimPresence *presence) | |
| 1534 { | |
| 1535 GaimStatus *status; | |
| 1536 | |
| 1537 g_return_val_if_fail(presence != NULL, FALSE); | |
| 1538 | |
| 1539 if ((status = gaim_presence_get_active_status(presence)) == NULL) | |
| 1540 return FALSE; | |
| 1541 | |
|
10040
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
1542 return gaim_status_is_online(status); |
| 9949 | 1543 } |
| 1544 | |
| 1545 gboolean | |
| 1546 gaim_presence_is_status_active(const GaimPresence *presence, | |
| 1547 const char *status_id) | |
| 1548 { | |
| 1549 GaimStatus *status; | |
| 1550 | |
| 1551 g_return_val_if_fail(presence != NULL, FALSE); | |
| 1552 g_return_val_if_fail(status_id != NULL, FALSE); | |
| 1553 | |
| 1554 status = gaim_presence_get_status(presence, status_id); | |
| 1555 | |
| 1556 return (status != NULL && gaim_status_is_active(status)); | |
| 1557 } | |
| 1558 | |
| 1559 gboolean | |
| 1560 gaim_presence_is_status_primitive_active(const GaimPresence *presence, | |
| 1561 GaimStatusPrimitive primitive) | |
| 1562 { | |
| 1563 GaimStatus *status; | |
| 1564 GaimStatusType *status_type; | |
| 1565 | |
| 1566 g_return_val_if_fail(presence != NULL, FALSE); | |
| 1567 g_return_val_if_fail(primitive != GAIM_STATUS_UNSET, FALSE); | |
| 1568 | |
| 1569 status = gaim_presence_get_active_status(presence); | |
| 1570 status_type = gaim_status_get_type(status); | |
| 1571 | |
| 1572 if (gaim_status_type_get_primitive(status_type) == primitive) | |
| 1573 return TRUE; | |
| 6065 | 1574 |
| 1575 return FALSE; | |
| 1576 } | |
| 1577 | |
| 9949 | 1578 gboolean |
| 1579 gaim_presence_is_idle(const GaimPresence *presence) | |
| 6065 | 1580 { |
| 9949 | 1581 g_return_val_if_fail(presence != NULL, FALSE); |
| 1582 | |
| 1583 return presence->idle; | |
| 6065 | 1584 } |
| 1585 | |
| 9949 | 1586 time_t |
| 1587 gaim_presence_get_idle_time(const GaimPresence *presence) | |
| 6065 | 1588 { |
| 9949 | 1589 g_return_val_if_fail(presence != NULL, 0); |
| 6065 | 1590 |
| 9949 | 1591 return presence->idle_time; |
| 1592 } | |
| 6065 | 1593 |
| 9949 | 1594 unsigned int |
| 1595 gaim_presence_get_warning_level(const GaimPresence *presence) | |
| 1596 { | |
| 1597 g_return_val_if_fail(presence != NULL, 0); | |
| 6216 | 1598 |
| 9949 | 1599 return presence->warning_level; |
| 6065 | 1600 } |
| 1601 | |
| 9949 | 1602 gint |
| 1603 gaim_presence_compare(const GaimPresence *presence1, | |
| 1604 const GaimPresence *presence2) | |
| 6065 | 1605 { |
| 9949 | 1606 gboolean idle1, idle2; |
| 1607 size_t idle_time_1, idle_time_2; | |
| 1608 int score1 = 0, score2 = 0; | |
| 1609 const GList *l; | |
| 6065 | 1610 |
| 9949 | 1611 if ((presence1 == NULL && presence2 == NULL) || (presence1 == presence2)) |
| 1612 return 0; | |
| 1613 else if (presence1 == NULL) | |
|
10151
d83e6f2125b1
[gaim-migrate @ 11228]
Christian Hammond <chipx86@chipx86.com>
parents:
10087
diff
changeset
|
1614 return 1; |
| 9949 | 1615 else if (presence2 == NULL) |
|
10151
d83e6f2125b1
[gaim-migrate @ 11228]
Christian Hammond <chipx86@chipx86.com>
parents:
10087
diff
changeset
|
1616 return -1; |
| 6065 | 1617 |
| 9949 | 1618 /* Compute the score of the first set of statuses. */ |
| 1619 for (l = gaim_presence_get_statuses(presence1); l != NULL; l = l->next) | |
| 1620 { | |
| 1621 GaimStatus *status = (GaimStatus *)l->data; | |
| 1622 GaimStatusType *type = gaim_status_get_type(status); | |
| 6065 | 1623 |
| 9949 | 1624 if (gaim_status_is_active(status)) |
| 1625 score1 += primitive_scores[gaim_status_type_get_primitive(type)]; | |
| 6065 | 1626 } |
| 1627 | |
| 9949 | 1628 /* Compute the score of the second set of statuses. */ |
|
10151
d83e6f2125b1
[gaim-migrate @ 11228]
Christian Hammond <chipx86@chipx86.com>
parents:
10087
diff
changeset
|
1629 for (l = gaim_presence_get_statuses(presence2); l != NULL; l = l->next) |
| 9949 | 1630 { |
| 1631 GaimStatus *status = (GaimStatus *)l->data; | |
| 1632 GaimStatusType *type = gaim_status_get_type(status); | |
| 6065 | 1633 |
| 9949 | 1634 if (gaim_status_is_active(status)) |
| 1635 score2 += primitive_scores[gaim_status_type_get_primitive(type)]; | |
| 6065 | 1636 } |
| 1637 | |
| 9949 | 1638 idle1 = gaim_presence_is_idle(presence1); |
| 1639 idle2 = gaim_presence_is_idle(presence2); | |
| 6065 | 1640 |
| 9949 | 1641 if (idle1) |
| 1642 score1 += primitive_scores[SCORE_IDLE]; | |
| 6065 | 1643 |
| 9949 | 1644 if (idle2) |
| 1645 score2 += primitive_scores[SCORE_IDLE]; | |
| 6065 | 1646 |
| 9949 | 1647 idle_time_1 = gaim_presence_get_idle_time(presence1); |
| 1648 idle_time_2 = gaim_presence_get_idle_time(presence2); | |
| 6065 | 1649 |
| 9949 | 1650 if (idle_time_1 > idle_time_2) |
| 1651 score1 += primitive_scores[SCORE_IDLE_TIME]; | |
| 1652 else if (idle_time_1 < idle_time_2) | |
| 1653 score2 += primitive_scores[SCORE_IDLE_TIME]; | |
| 6065 | 1654 |
| 9949 | 1655 if (score1 < score2) |
| 1656 return 1; | |
| 1657 else if (score1 > score2) | |
| 1658 return -1; | |
| 1659 | |
| 1660 return 0; | |
| 1661 } | |
| 1662 | |
| 6065 | 1663 |
| 9949 | 1664 /************************************************************************** |
| 1665 * Status subsystem | |
| 1666 **************************************************************************/ | |
| 1667 static void | |
| 1668 score_pref_changed_cb(const char *name, GaimPrefType type, gpointer value, | |
| 1669 gpointer data) | |
| 1670 { | |
| 1671 int index = GPOINTER_TO_INT(data); | |
| 6065 | 1672 |
| 9949 | 1673 primitive_scores[index] = GPOINTER_TO_INT(value); |
| 6065 | 1674 } |
| 1675 | |
| 10012 | 1676 guint |
| 10006 | 1677 gaim_buddy_presences_hash(gconstpointer key) |
| 1678 { | |
| 10012 | 1679 const GaimStatusBuddyKey *me = key; |
| 1680 guint ret; | |
| 1681 char *str; | |
| 1682 | |
| 1683 str = g_strdup_printf("%p%s", me->account, me->name); | |
| 1684 ret = g_str_hash(str); | |
| 1685 g_free(str); | |
| 1686 | |
| 1687 return ret; | |
| 10006 | 1688 } |
| 1689 | |
| 10012 | 1690 gboolean |
| 10006 | 1691 gaim_buddy_presences_equal(gconstpointer a, gconstpointer b) |
| 1692 { | |
| 1693 GaimStatusBuddyKey *key_a = (GaimStatusBuddyKey *)a; | |
| 1694 GaimStatusBuddyKey *key_b = (GaimStatusBuddyKey *)b; | |
| 1695 | |
| 10012 | 1696 if(key_a->account == key_b->account && |
| 1697 !strcmp(key_a->name, key_b->name)) | |
| 10006 | 1698 return TRUE; |
| 1699 else | |
| 1700 return FALSE; | |
| 1701 } | |
| 1702 | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1703 const GList * |
| 10337 | 1704 gaim_statuses_get_saved(void) |
| 1705 { | |
| 1706 return saved_statuses; | |
| 1707 } | |
| 1708 | |
| 1709 GaimStatusSaved * | |
| 10348 | 1710 gaim_statuses_find_saved(const char *title) |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1711 { |
| 10340 | 1712 GList *l; |
| 1713 GaimStatusSaved *status; | |
| 1714 | |
| 1715 for (l = saved_statuses; l != NULL; l = g_list_next(l)) | |
| 1716 { | |
| 1717 status = (GaimStatusSaved *)l->data; | |
| 10348 | 1718 if (!strcmp(status->title, title)) |
| 10340 | 1719 return status; |
| 1720 } | |
| 1721 | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1722 return NULL; |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1723 } |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1724 |
| 10337 | 1725 const char * |
| 10348 | 1726 gaim_statuses_saved_get_title(const GaimStatusSaved *saved_status) |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1727 { |
| 10348 | 1728 return saved_status->title; |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1729 } |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1730 |
| 10348 | 1731 GaimStatusPrimitive |
| 10340 | 1732 gaim_statuses_saved_get_type(const GaimStatusSaved *saved_status) |
| 1733 { | |
| 1734 return saved_status->type; | |
| 1735 } | |
| 1736 | |
| 1737 const char * | |
| 1738 gaim_statuses_saved_get_message(const GaimStatusSaved *saved_status) | |
| 1739 { | |
| 1740 return saved_status->message; | |
| 1741 } | |
| 1742 | |
| 10087 | 1743 void * |
| 1744 gaim_statuses_get_handle() { | |
| 1745 static int handle; | |
| 1746 | |
| 1747 return &handle; | |
| 1748 } | |
| 1749 | |
| 9949 | 1750 void |
| 1751 gaim_statuses_init(void) | |
| 6065 | 1752 { |
| 10087 | 1753 void *handle = gaim_statuses_get_handle; |
| 1754 | |
| 9949 | 1755 gaim_prefs_add_none("/core/status"); |
| 1756 gaim_prefs_add_none("/core/status/scores"); | |
| 6065 | 1757 |
| 9949 | 1758 gaim_prefs_add_int("/core/status/scores/offline", |
| 1759 primitive_scores[GAIM_STATUS_OFFLINE]); | |
| 1760 gaim_prefs_add_int("/core/status/scores/available", | |
| 1761 primitive_scores[GAIM_STATUS_AVAILABLE]); | |
| 1762 gaim_prefs_add_int("/core/status/scores/hidden", | |
| 1763 primitive_scores[GAIM_STATUS_HIDDEN]); | |
| 1764 gaim_prefs_add_int("/core/status/scores/away", | |
| 1765 primitive_scores[GAIM_STATUS_AWAY]); | |
| 1766 gaim_prefs_add_int("/core/status/scores/extended_away", | |
| 1767 primitive_scores[GAIM_STATUS_EXTENDED_AWAY]); | |
| 1768 gaim_prefs_add_int("/core/status/scores/idle", | |
| 1769 primitive_scores[SCORE_IDLE]); | |
| 6065 | 1770 |
| 10087 | 1771 gaim_prefs_connect_callback(handle, "/core/status/scores/offline", |
| 9949 | 1772 score_pref_changed_cb, |
| 1773 GINT_TO_POINTER(GAIM_STATUS_OFFLINE)); | |
| 10087 | 1774 gaim_prefs_connect_callback(handle, "/core/status/scores/available", |
| 9949 | 1775 score_pref_changed_cb, |
| 1776 GINT_TO_POINTER(GAIM_STATUS_AVAILABLE)); | |
| 10087 | 1777 gaim_prefs_connect_callback(handle, "/core/status/scores/hidden", |
| 9949 | 1778 score_pref_changed_cb, |
| 1779 GINT_TO_POINTER(GAIM_STATUS_HIDDEN)); | |
| 10087 | 1780 gaim_prefs_connect_callback(handle, "/core/status/scores/away", |
| 9949 | 1781 score_pref_changed_cb, |
| 1782 GINT_TO_POINTER(GAIM_STATUS_AWAY)); | |
| 10087 | 1783 gaim_prefs_connect_callback(handle, "/core/status/scores/extended_away", |
| 9949 | 1784 score_pref_changed_cb, |
| 1785 GINT_TO_POINTER(GAIM_STATUS_EXTENDED_AWAY)); | |
| 10087 | 1786 gaim_prefs_connect_callback(handle, "/core/status/scores/idle", |
| 9949 | 1787 score_pref_changed_cb, |
| 1788 GINT_TO_POINTER(SCORE_IDLE)); | |
| 10006 | 1789 |
| 1790 buddy_presences = g_hash_table_new(gaim_buddy_presences_hash, | |
| 1791 gaim_buddy_presences_equal); | |
| 9949 | 1792 } |
| 6065 | 1793 |
| 9949 | 1794 void |
| 1795 gaim_statuses_uninit(void) | |
| 1796 { | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1797 if (buddy_presences != NULL) |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1798 { |
| 10077 | 1799 g_hash_table_destroy(buddy_presences); |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1800 |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1801 buddy_presences = NULL; |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1802 } |
| 9949 | 1803 } |
| 6065 | 1804 |
| 10348 | 1805 static GaimStatusSavedSub * |
| 1806 gaim_statuses_read_parse_substatus(xmlnode *substatus) | |
| 9949 | 1807 { |
| 10348 | 1808 GaimStatusSavedSub *ret; |
| 1809 xmlnode *node; | |
| 10359 | 1810 char *data = NULL; |
| 10348 | 1811 |
| 1812 ret = g_new0(GaimStatusSavedSub, 1); | |
| 1813 | |
| 1814 /* Read the account */ | |
| 1815 node = xmlnode_get_child(substatus, "account"); | |
| 1816 if (node != NULL) | |
| 1817 { | |
| 10359 | 1818 char *acct_name; |
| 10348 | 1819 const char *protocol; |
| 1820 acct_name = xmlnode_get_data(node); | |
| 1821 protocol = xmlnode_get_attrib(node, "protocol"); | |
| 1822 if ((acct_name != NULL) && (protocol != NULL)) | |
| 1823 ret->account = gaim_accounts_find(acct_name, protocol); | |
| 10359 | 1824 g_free(acct_name); |
| 10348 | 1825 } |
| 1826 | |
| 1827 if (ret->account == NULL) | |
| 1828 { | |
| 1829 g_free(ret); | |
| 1830 return NULL; | |
| 1831 } | |
| 1832 | |
| 1833 /* Read the state */ | |
| 1834 node = xmlnode_get_child(substatus, "state"); | |
| 1835 if (node != NULL) | |
| 10359 | 1836 data = xmlnode_get_data(node); |
| 1837 if (data != NULL) { | |
| 10348 | 1838 ret->type = gaim_status_type_find_with_id(ret->account->status_types, |
| 10359 | 1839 data); |
| 1840 g_free(data); | |
| 1841 data = NULL; | |
| 1842 } | |
| 10348 | 1843 |
| 1844 /* Read the message */ | |
| 1845 node = xmlnode_get_child(substatus, "message"); | |
| 1846 if (node != NULL) | |
| 10359 | 1847 data = xmlnode_get_data(node); |
| 1848 if (data != NULL) | |
| 1849 ret->message = data; | |
| 10348 | 1850 |
| 1851 return ret; | |
| 6065 | 1852 } |
| 9949 | 1853 |
| 10337 | 1854 /** |
| 1855 * Parse a saved status and add it to the saved_statuses linked list. | |
| 1856 * | |
| 1857 * Here's an example of the XML for a saved status: | |
| 1858 * <status name="Girls"> | |
| 1859 * <state>away</state> | |
| 1860 * <message>I like the way that they walk | |
| 1861 * And it's chill to hear them talk | |
| 1862 * And I can always make them smile | |
| 1863 * From White Castle to the Nile</message> | |
| 10348 | 1864 * <substatus> |
| 1865 * <account protocol='prpl-oscar'>markdoliner</account> | |
| 1866 * <state>available</state> | |
| 1867 * <message>The ladies man is here to answer your queries.</message> | |
| 1868 * </substatus> | |
| 1869 * <substatus> | |
| 1870 * <account protocol='prpl-oscar'>giantgraypanda</account> | |
| 1871 * <state>away</state> | |
| 1872 * <message>A.C. ain't in charge no more.</message> | |
| 1873 * </substatus> | |
| 10337 | 1874 * </status> |
| 1875 * | |
| 1876 * I know. Moving, huh? | |
| 1877 */ | |
| 10348 | 1878 static GaimStatusSaved * |
| 10337 | 1879 gaim_statuses_read_parse_status(xmlnode *status) |
| 1880 { | |
| 10348 | 1881 GaimStatusSaved *ret; |
| 10337 | 1882 xmlnode *node; |
| 10359 | 1883 const char *attrib; |
| 1884 char *data = NULL; | |
| 10340 | 1885 int i; |
| 10337 | 1886 |
| 10348 | 1887 ret = g_new0(GaimStatusSaved, 1); |
| 10337 | 1888 |
| 10348 | 1889 /* Read the title */ |
| 10359 | 1890 attrib = xmlnode_get_attrib(status, "name"); |
| 1891 if (attrib == NULL) | |
| 1892 attrib = "No Title"; | |
| 10340 | 1893 /* Ensure the title is unique */ |
| 10359 | 1894 ret->title = g_strdup(attrib); |
| 10340 | 1895 i = 2; |
| 10348 | 1896 while (gaim_statuses_find_saved(ret->title) != NULL) |
| 1897 { | |
| 1898 g_free(ret->title); | |
| 10359 | 1899 ret->title = g_strdup_printf("%s %d", attrib, i); |
| 10340 | 1900 i++; |
| 1901 } | |
| 1902 | |
| 10348 | 1903 /* Read the primitive status type */ |
| 1904 node = xmlnode_get_child(status, "state"); | |
| 1905 if (node != NULL) | |
| 10359 | 1906 data = xmlnode_get_data(node); |
| 1907 if (data != NULL) { | |
| 1908 ret->type = gaim_primitive_get_type(data); | |
| 1909 g_free(data); | |
| 1910 data = NULL; | |
| 1911 } | |
| 10348 | 1912 |
| 1913 /* Read the message */ | |
| 1914 node = xmlnode_get_child(status, "message"); | |
| 1915 if (node != NULL) | |
| 10359 | 1916 data = xmlnode_get_data(node); |
| 1917 if (data != NULL) | |
| 1918 ret->message = data; | |
| 10348 | 1919 |
| 1920 /* Read substatuses */ | |
| 1921 for (node = xmlnode_get_child(status, "status"); node != NULL; | |
| 1922 node = xmlnode_get_next_twin(node)) | |
| 1923 { | |
| 1924 GaimStatusSavedSub *new; | |
| 1925 new = gaim_statuses_read_parse_substatus(node); | |
| 1926 if (new != NULL) | |
| 1927 ret->substatuses = g_list_append(ret->substatuses, new); | |
| 1928 } | |
| 1929 | |
| 1930 return ret; | |
| 10337 | 1931 } |
| 1932 | |
| 1933 /** | |
| 1934 * @return TRUE on success, FALSE on failure (if the file can not | |
| 1935 * be opened, or if it contains invalid XML). | |
| 1936 */ | |
| 10348 | 1937 static gboolean |
| 10337 | 1938 gaim_statuses_read(const char *filename) |
| 1939 { | |
| 1940 GError *error; | |
| 1941 gchar *contents = NULL; | |
| 1942 gsize length; | |
| 1943 xmlnode *statuses, *status; | |
| 1944 | |
| 1945 gaim_debug_info("status", "Reading %s\n", filename); | |
| 1946 | |
| 10348 | 1947 if (!g_file_get_contents(filename, &contents, &length, &error)) |
| 1948 { | |
| 10343 | 1949 gaim_debug_error("status", "Error reading statuses: %s\n", |
| 10337 | 1950 error->message); |
| 1951 g_error_free(error); | |
| 1952 return FALSE; | |
| 1953 } | |
| 1954 | |
| 1955 statuses = xmlnode_from_str(contents, length); | |
| 1956 | |
| 10348 | 1957 if (statuses == NULL) |
| 1958 { | |
| 10337 | 1959 FILE *backup; |
| 1960 gchar *name; | |
| 10343 | 1961 gaim_debug_error("status", "Error parsing statuses\n"); |
| 1962 name = g_strdup_printf("%s~", filename); | |
| 10348 | 1963 if ((backup = fopen(name, "w"))) |
| 1964 { | |
| 10337 | 1965 fwrite(contents, length, 1, backup); |
| 1966 fclose(backup); | |
| 1967 chmod(name, S_IRUSR | S_IWUSR); | |
| 10348 | 1968 } |
| 1969 else | |
| 1970 { | |
| 10337 | 1971 gaim_debug_error("status", "Unable to write backup %s\n", name); |
| 1972 } | |
| 1973 g_free(name); | |
| 1974 g_free(contents); | |
| 1975 return FALSE; | |
| 1976 } | |
| 1977 | |
| 1978 g_free(contents); | |
| 1979 | |
| 1980 for (status = xmlnode_get_child(statuses, "status"); status != NULL; | |
| 10348 | 1981 status = xmlnode_get_next_twin(status)) |
| 1982 { | |
| 1983 GaimStatusSaved *new; | |
| 1984 new = gaim_statuses_read_parse_status(status); | |
| 1985 saved_statuses = g_list_append(saved_statuses, new); | |
| 10337 | 1986 } |
| 1987 | |
| 10343 | 1988 gaim_debug_info("status", "Finished reading statuses\n"); |
| 10337 | 1989 |
| 1990 xmlnode_free(statuses); | |
| 1991 | |
| 1992 return TRUE; | |
| 1993 } | |
| 1994 | |
| 9949 | 1995 void |
| 1996 gaim_statuses_load(void) | |
| 1997 { | |
| 10337 | 1998 const char *user_dir = gaim_user_dir(); |
| 1999 gchar *filename; | |
| 2000 gchar *msg; | |
| 2001 | |
| 10414 | 2002 g_return_if_fail(user_dir != NULL); |
| 10337 | 2003 |
| 10415 | 2004 have_read_saved_statuses = TRUE; |
| 2005 | |
| 10337 | 2006 filename = g_build_filename(user_dir, "status.xml", NULL); |
| 2007 | |
| 10348 | 2008 if (g_file_test(filename, G_FILE_TEST_EXISTS)) |
| 2009 { | |
| 2010 if (!gaim_statuses_read(filename)) | |
| 2011 { | |
| 10337 | 2012 msg = g_strdup_printf(_("An error was encountered parsing the " |
| 2013 "file containing your saved statuses (%s). They " | |
| 2014 "have not been loaded, and the old file has been " | |
| 2015 "renamed to status.xml~."), filename); | |
| 2016 gaim_notify_error(NULL, NULL, _("Saved Statuses Error"), msg); | |
| 2017 g_free(msg); | |
| 2018 } | |
| 2019 } | |
| 2020 | |
| 2021 g_free(filename); | |
| 9949 | 2022 } |
| 10348 | 2023 |
| 10415 | 2024 static xmlnode * |
| 10417 | 2025 gaim_substatus_get_as_xmlnode(GaimStatusSavedSub *substatus) |
| 2026 { | |
| 2027 xmlnode *node, *child; | |
| 2028 | |
| 2029 node = xmlnode_new("substatus"); | |
| 2030 | |
| 2031 child = xmlnode_new("account"); | |
| 2032 xmlnode_set_attrib(node, "protocol", | |
| 2033 gaim_account_get_protocol_id(substatus->account)); | |
| 2034 xmlnode_insert_data(child, | |
| 2035 gaim_account_get_username(substatus->account), -1); | |
| 2036 xmlnode_insert_child(node, child); | |
| 2037 | |
| 2038 child = xmlnode_new("state"); | |
| 2039 xmlnode_insert_data(child, substatus->type->id, -1); | |
| 2040 xmlnode_insert_child(node, child); | |
| 2041 | |
| 2042 if (substatus->message != NULL) | |
| 2043 { | |
| 2044 child = xmlnode_new("message"); | |
| 2045 xmlnode_insert_data(child, substatus->message, -1); | |
| 2046 xmlnode_insert_child(node, child); | |
| 2047 } | |
| 2048 | |
| 2049 return node; | |
| 2050 } | |
| 2051 | |
| 2052 static xmlnode * | |
| 10415 | 2053 gaim_status_get_as_xmlnode(GaimStatusSaved *status) |
| 2054 { | |
| 2055 xmlnode *node, *child; | |
| 10417 | 2056 GList *cur; |
| 10415 | 2057 |
| 2058 node = xmlnode_new("status"); | |
| 2059 xmlnode_set_attrib(node, "name", status->title); | |
| 2060 | |
| 2061 child = xmlnode_new("state"); | |
| 2062 xmlnode_insert_data(child, primitive_names[status->type], -1); | |
| 2063 xmlnode_insert_child(node, child); | |
| 2064 | |
| 2065 child = xmlnode_new("message"); | |
| 2066 xmlnode_insert_data(child, status->message, -1); | |
| 2067 xmlnode_insert_child(node, child); | |
| 2068 | |
| 10417 | 2069 for (cur = status->substatuses; cur != NULL; cur = cur->next) |
| 2070 { | |
| 2071 child = gaim_substatus_get_as_xmlnode(cur->data); | |
| 2072 xmlnode_insert_child(node, child); | |
| 2073 } | |
| 10415 | 2074 |
| 2075 return node; | |
| 2076 } | |
| 2077 | |
| 2078 static xmlnode * | |
| 2079 gaim_statuses_get_as_xmlnode() | |
| 2080 { | |
| 2081 xmlnode *node, *child; | |
| 2082 GList *cur; | |
| 2083 | |
| 2084 node = xmlnode_new("statuses"); | |
| 2085 xmlnode_set_attrib(node, "version", "1"); | |
| 2086 | |
| 2087 for (cur = saved_statuses; cur != NULL; cur = cur->next) | |
| 2088 { | |
| 2089 child = gaim_status_get_as_xmlnode(cur->data); | |
| 2090 xmlnode_insert_child(node, child); | |
| 2091 } | |
| 2092 | |
| 2093 return node; | |
| 2094 } | |
| 2095 | |
| 10348 | 2096 void |
| 2097 gaim_statuses_sync(void) | |
| 2098 { | |
| 10415 | 2099 xmlnode *statuses; |
| 2100 char *data; | |
| 10414 | 2101 |
| 10415 | 2102 if (!have_read_saved_statuses) { |
| 2103 gaim_debug_error("status", "Attempted to save statuses before they " | |
| 2104 "were read!\n"); | |
| 2105 return; | |
| 2106 } | |
| 2107 | |
| 2108 statuses = gaim_statuses_get_as_xmlnode(); | |
| 2109 data = xmlnode_to_formatted_str(statuses, NULL); | |
| 2110 gaim_util_write_data_to_file("status.xml", data, -1); | |
| 2111 g_free(data); | |
| 2112 xmlnode_free(statuses); | |
| 10348 | 2113 } |
