Mercurial > pidgin
annotate src/status.c @ 10196:760e690a5f30
[gaim-migrate @ 11313]
A few steps closer to being able to set an oscar away message.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Tue, 16 Nov 2004 23:29:53 +0000 |
| parents | 0109f3a518d2 |
| children | 7369bf2bf593 |
| 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" |
| 28 #include "debug.h" | |
| 29 #include "prefs.h" | |
| 6065 | 30 #include "status.h" |
| 31 #include "util.h" | |
| 32 | |
| 9949 | 33 /** |
| 34 * A type of status. | |
| 35 */ | |
| 36 struct _GaimStatusType | |
| 37 { | |
| 38 GaimStatusPrimitive primitive; | |
|
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6321
diff
changeset
|
39 |
| 9949 | 40 char *id; |
| 41 char *name; | |
| 42 char *primary_attr_id; | |
| 43 | |
| 44 gboolean saveable; | |
| 45 gboolean user_settable; | |
| 46 gboolean independent; | |
| 47 | |
| 48 GList *attrs; | |
| 49 }; | |
|
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6321
diff
changeset
|
50 |
| 9949 | 51 /** |
| 52 * A status attribute. | |
| 53 */ | |
| 54 struct _GaimStatusAttr | |
| 55 { | |
| 56 char *id; | |
| 57 char *name; | |
| 58 GaimValue *value_type; | |
| 59 }; | |
| 6065 | 60 |
| 9949 | 61 /** |
| 62 * A list of statuses. | |
| 63 */ | |
| 64 struct _GaimPresence | |
| 65 { | |
| 66 GaimPresenceContext context; | |
| 67 | |
| 68 gboolean idle; | |
| 69 time_t idle_time; | |
| 10006 | 70 time_t login_time; |
| 9949 | 71 |
| 72 unsigned int warning_level; | |
| 6065 | 73 |
| 9949 | 74 GList *statuses; |
| 75 GHashTable *status_table; | |
| 76 | |
| 77 GaimStatus *active_status; | |
| 6065 | 78 |
| 9949 | 79 union |
| 80 { | |
| 81 GaimAccount *account; | |
| 82 | |
| 83 struct | |
| 84 { | |
| 85 GaimConversation *conv; | |
| 86 char *user; | |
| 87 | |
| 88 } chat; | |
| 6065 | 89 |
| 9949 | 90 struct |
| 91 { | |
| 92 GaimAccount *account; | |
| 93 char *name; | |
| 94 size_t ref_count; | |
| 95 GList *buddies; | |
| 96 | |
| 97 } buddy; | |
| 98 | |
| 99 } u; | |
| 100 }; | |
| 101 | |
| 102 /** | |
| 103 * An active status. | |
| 104 */ | |
| 105 struct _GaimStatus | |
| 6065 | 106 { |
| 9949 | 107 GaimStatusType *type; |
| 108 GaimPresence *presence; | |
| 109 | |
| 110 const char *title; | |
| 6065 | 111 |
| 9949 | 112 gboolean active; |
| 6065 | 113 |
| 9949 | 114 GHashTable *attr_values; |
| 115 }; | |
| 6065 | 116 |
| 117 typedef struct | |
| 118 { | |
| 9949 | 119 GaimAccount *account; |
| 120 char *name; | |
| 121 } GaimStatusBuddyKey; | |
| 122 | |
| 123 | |
| 124 #if 0 | |
| 125 static GList *stored_statuses = NULL; | |
| 126 | |
| 127 /* | |
| 128 * XXX This stuff should be removed in a few versions. It stores the | |
| 129 * old v1 status stuff so we can write it later. We don't write out | |
| 130 * the new status stuff, though. These should all die soon, as the | |
| 131 * old status.xml was created before the new status system's design | |
| 132 * was created. | |
| 133 * | |
| 134 * -- ChipX86 | |
| 135 */ | |
| 136 typedef struct | |
| 137 { | |
| 138 char *name; | |
| 139 char *state; | |
| 140 char *message; | |
| 141 | |
| 142 } GaimStatusV1Info; | |
| 143 | |
| 144 static GList *v1_statuses = NULL; | |
| 145 #endif | |
| 146 | |
| 147 | |
| 148 static int primitive_scores[] = | |
| 149 { | |
| 150 0, /* unset */ | |
| 151 -500, /* offline */ | |
| 152 0, /* online */ | |
| 153 100, /* available */ | |
| 154 -75, /* unavailable */ | |
| 155 -50, /* hidden */ | |
| 156 -100, /* away */ | |
| 157 -200 /* extended away */ | |
| 158 -10, /* idle, special case. */ | |
| 159 -5 /* idle time, special case. */ | |
| 160 }; | |
| 161 | |
| 162 static GHashTable *buddy_presences = NULL; | |
| 163 | |
| 164 #define SCORE_IDLE 5 | |
| 165 #define SCORE_IDLE_TIME 6 | |
| 166 | |
| 167 /************************************************************************** | |
| 168 * GaimStatusType API | |
| 169 **************************************************************************/ | |
| 170 GaimStatusType * | |
| 171 gaim_status_type_new_full(GaimStatusPrimitive primitive, const char *id, | |
| 10009 | 172 const char *name, gboolean saveable, |
| 173 gboolean user_settable, gboolean independent) | |
| 9949 | 174 { |
| 175 GaimStatusType *status_type; | |
| 176 | |
| 177 g_return_val_if_fail(primitive != GAIM_STATUS_UNSET, NULL); | |
| 178 g_return_val_if_fail(id != NULL, NULL); | |
| 179 g_return_val_if_fail(name != NULL, NULL); | |
| 180 | |
| 181 status_type = g_new0(GaimStatusType, 1); | |
| 182 | |
| 183 status_type->primitive = primitive; | |
| 184 status_type->id = g_strdup(id); | |
| 185 status_type->name = g_strdup(name); | |
| 186 status_type->saveable = saveable; | |
| 187 status_type->user_settable = user_settable; | |
| 188 status_type->independent = independent; | |
| 189 | |
| 190 return status_type; | |
| 191 } | |
| 192 | |
| 193 GaimStatusType * | |
| 194 gaim_status_type_new(GaimStatusPrimitive primitive, const char *id, | |
| 10009 | 195 const char *name, gboolean user_settable) |
| 9949 | 196 { |
| 197 g_return_val_if_fail(primitive != GAIM_STATUS_UNSET, NULL); | |
| 198 g_return_val_if_fail(id != NULL, NULL); | |
| 199 g_return_val_if_fail(name != NULL, NULL); | |
| 200 | |
| 201 return gaim_status_type_new_full(primitive, id, name, FALSE, | |
| 202 user_settable, FALSE); | |
| 203 } | |
| 204 | |
| 205 GaimStatusType * | |
| 206 gaim_status_type_new_with_attrs(GaimStatusPrimitive primitive, | |
| 207 const char *id, const char *name, | |
| 208 gboolean saveable, gboolean user_settable, | |
| 209 gboolean independent, const char *attr_id, | |
| 210 const char *attr_name, GaimValue *attr_value, | |
| 211 ...) | |
| 212 { | |
| 213 GaimStatusType *status_type; | |
| 214 va_list args; | |
| 215 | |
| 216 g_return_val_if_fail(primitive != GAIM_STATUS_UNSET, NULL); | |
| 217 g_return_val_if_fail(id != NULL, NULL); | |
| 218 g_return_val_if_fail(name != NULL, NULL); | |
| 10012 | 219 g_return_val_if_fail(attr_id != NULL, NULL); |
| 9949 | 220 g_return_val_if_fail(attr_name != NULL, NULL); |
| 221 g_return_val_if_fail(attr_value != NULL, NULL); | |
| 222 | |
| 223 status_type = gaim_status_type_new_full(primitive, id, name, saveable, | |
| 224 user_settable, independent); | |
| 225 | |
| 10010 | 226 /* Add the first attribute */ |
| 9949 | 227 gaim_status_type_add_attr(status_type, attr_id, attr_name, attr_value); |
| 228 | |
| 229 va_start(args, attr_value); | |
| 230 gaim_status_type_add_attrs_vargs(status_type, args); | |
| 231 va_end(args); | |
| 232 | |
| 233 return status_type; | |
| 234 } | |
| 235 | |
| 236 void | |
| 237 gaim_status_type_destroy(GaimStatusType *status_type) | |
| 238 { | |
| 239 GList *l; | |
| 240 | |
| 241 g_return_if_fail(status_type != NULL); | |
| 242 | |
| 243 g_free(status_type->id); | |
| 244 g_free(status_type->name); | |
| 245 | |
| 246 if (status_type->primary_attr_id != NULL) | |
| 247 g_free(status_type->primary_attr_id); | |
| 248 | |
| 249 if (status_type->attrs != NULL) | |
| 250 { | |
| 251 for (l = status_type->attrs; l != NULL; l = l->next) | |
| 252 gaim_status_attr_destroy((GaimStatusAttr *)l->data); | |
| 253 | |
| 254 g_list_free(status_type->attrs); | |
| 255 } | |
| 256 | |
| 257 g_free(status_type); | |
| 258 } | |
| 259 | |
| 260 void | |
| 261 gaim_status_type_set_primary_attr(GaimStatusType *status_type, const char *id) | |
| 262 { | |
| 263 g_return_if_fail(status_type != NULL); | |
| 264 | |
| 265 if (status_type->primary_attr_id != NULL) | |
| 266 g_free(status_type->primary_attr_id); | |
| 267 | |
| 268 status_type->primary_attr_id = (id == NULL ? NULL : g_strdup(id)); | |
| 269 } | |
| 270 | |
| 271 void | |
| 272 gaim_status_type_add_attr(GaimStatusType *status_type, const char *id,\ | |
| 273 const char *name, GaimValue *value) | |
| 274 { | |
| 275 GaimStatusAttr *attr; | |
| 276 | |
| 277 g_return_if_fail(status_type != NULL); | |
| 278 g_return_if_fail(id != NULL); | |
| 279 g_return_if_fail(name != NULL); | |
| 280 g_return_if_fail(value != NULL); | |
| 281 | |
| 282 attr = gaim_status_attr_new(id, name, value); | |
| 283 | |
| 284 status_type->attrs = g_list_append(status_type->attrs, attr); | |
| 285 } | |
| 286 | |
| 287 void | |
| 288 gaim_status_type_add_attrs_vargs(GaimStatusType *status_type, va_list args) | |
| 289 { | |
| 290 const char *id, *name; | |
| 291 GaimValue *value; | |
| 292 | |
| 293 g_return_if_fail(status_type != NULL); | |
| 294 | |
| 295 while ((id = va_arg(args, const char *)) != NULL) | |
| 296 { | |
| 297 name = va_arg(args, const char *); | |
| 298 g_return_if_fail(name != NULL); | |
| 299 | |
| 300 value = va_arg(args, GaimValue *); | |
| 301 g_return_if_fail(value != NULL); | |
| 6065 | 302 |
| 9949 | 303 gaim_status_type_add_attr(status_type, id, name, value); |
| 304 } | |
| 305 } | |
| 306 | |
| 10010 | 307 void |
| 308 gaim_status_type_add_attrs(GaimStatusType *status_type, const char *id, | |
| 309 const char *name, GaimValue *value, ...) | |
| 310 { | |
| 311 va_list args; | |
| 312 | |
| 313 g_return_if_fail(status_type != NULL); | |
| 314 g_return_if_fail(id != NULL); | |
| 315 g_return_if_fail(name != NULL); | |
| 316 g_return_if_fail(value != NULL); | |
| 317 | |
| 318 /* Add the first attribute */ | |
| 319 gaim_status_type_add_attr(status_type, id, name, value); | |
| 320 | |
| 321 va_start(args, value); | |
| 322 gaim_status_type_add_attrs_vargs(status_type, args); | |
| 323 va_end(args); | |
| 324 } | |
| 325 | |
| 9949 | 326 GaimStatusPrimitive |
| 327 gaim_status_type_get_primitive(const GaimStatusType *status_type) | |
| 328 { | |
| 329 g_return_val_if_fail(status_type != NULL, GAIM_STATUS_UNSET); | |
| 330 | |
| 331 return status_type->primitive; | |
| 332 } | |
| 333 | |
| 334 const char * | |
| 335 gaim_status_type_get_id(const GaimStatusType *status_type) | |
| 336 { | |
| 337 g_return_val_if_fail(status_type != NULL, NULL); | |
| 338 | |
| 339 return status_type->id; | |
| 340 } | |
| 341 | |
| 342 const char * | |
| 343 gaim_status_type_get_name(const GaimStatusType *status_type) | |
| 344 { | |
| 345 g_return_val_if_fail(status_type != NULL, NULL); | |
| 346 | |
| 347 return status_type->name; | |
| 348 } | |
| 349 | |
| 350 gboolean | |
| 351 gaim_status_type_is_saveable(const GaimStatusType *status_type) | |
| 352 { | |
| 353 g_return_val_if_fail(status_type != NULL, FALSE); | |
| 354 | |
| 355 return status_type->saveable; | |
| 356 } | |
| 357 | |
| 358 gboolean | |
| 359 gaim_status_type_is_user_settable(const GaimStatusType *status_type) | |
| 360 { | |
| 361 g_return_val_if_fail(status_type != NULL, FALSE); | |
| 362 | |
| 363 return status_type->user_settable; | |
| 364 } | |
| 365 | |
| 366 gboolean | |
| 367 gaim_status_type_is_independent(const GaimStatusType *status_type) | |
| 368 { | |
| 369 g_return_val_if_fail(status_type != NULL, FALSE); | |
| 370 | |
| 371 return status_type->independent; | |
| 372 } | |
| 373 | |
| 374 gboolean | |
| 10067 | 375 gaim_status_type_is_exclusive(const GaimStatusType *status_type) |
| 376 { | |
| 377 g_return_val_if_fail(status_type != NULL, FALSE); | |
| 378 | |
| 379 return !status_type->independent; | |
| 380 } | |
| 381 | |
| 382 gboolean | |
| 9949 | 383 gaim_status_type_is_available(const GaimStatusType *status_type) |
| 384 { | |
| 385 GaimStatusPrimitive primitive; | |
| 386 | |
| 387 g_return_val_if_fail(status_type != NULL, FALSE); | |
| 388 | |
| 389 primitive = gaim_status_type_get_primitive(status_type); | |
| 390 | |
| 391 return (primitive == GAIM_STATUS_AVAILABLE || | |
| 392 primitive == GAIM_STATUS_HIDDEN); | |
| 393 } | |
| 394 | |
| 395 const char * | |
| 396 gaim_status_type_get_primary_attr(const GaimStatusType *status_type) | |
| 397 { | |
| 398 g_return_val_if_fail(status_type != NULL, NULL); | |
| 399 | |
| 400 return status_type->primary_attr_id; | |
| 401 } | |
| 402 | |
| 403 GaimStatusAttr * | |
| 404 gaim_status_type_get_attr(const GaimStatusType *status_type, const char *id) | |
| 405 { | |
| 406 GList *l; | |
| 407 | |
| 408 g_return_val_if_fail(status_type != NULL, NULL); | |
| 409 g_return_val_if_fail(id != NULL, NULL); | |
| 410 | |
| 411 for (l = status_type->attrs; l != NULL; l = l->next) | |
| 412 { | |
| 413 GaimStatusAttr *attr = (GaimStatusAttr *)l->data; | |
| 414 | |
| 415 if (!strcmp(gaim_status_attr_get_id(attr), id)) | |
| 416 return attr; | |
| 417 } | |
| 418 | |
| 419 return NULL; | |
| 420 } | |
| 421 | |
| 422 const GList * | |
| 423 gaim_status_type_get_attrs(const GaimStatusType *status_type) | |
| 424 { | |
| 425 g_return_val_if_fail(status_type != NULL, NULL); | |
| 426 | |
| 427 return status_type->attrs; | |
| 428 } | |
| 429 | |
| 430 | |
| 431 /************************************************************************** | |
| 432 * GaimStatusAttr API | |
| 433 **************************************************************************/ | |
| 434 GaimStatusAttr * | |
| 435 gaim_status_attr_new(const char *id, const char *name, GaimValue *value_type) | |
| 436 { | |
| 437 GaimStatusAttr *attr; | |
| 438 | |
| 439 g_return_val_if_fail(id != NULL, NULL); | |
| 440 g_return_val_if_fail(name != NULL, NULL); | |
| 441 g_return_val_if_fail(value_type != NULL, NULL); | |
| 442 | |
| 443 attr = g_new0(GaimStatusAttr, 1); | |
| 444 | |
| 445 attr->id = g_strdup(id); | |
| 446 attr->name = g_strdup(name); | |
| 447 attr->value_type = value_type; | |
| 448 | |
| 449 return attr; | |
| 450 } | |
| 451 | |
| 452 void | |
| 453 gaim_status_attr_destroy(GaimStatusAttr *attr) | |
| 454 { | |
| 455 g_return_if_fail(attr != NULL); | |
| 456 | |
| 457 g_free(attr->id); | |
| 458 g_free(attr->name); | |
| 459 | |
| 460 gaim_value_destroy(attr->value_type); | |
| 461 | |
| 462 g_free(attr); | |
| 463 } | |
| 464 | |
| 465 const char * | |
| 466 gaim_status_attr_get_id(const GaimStatusAttr *attr) | |
| 467 { | |
| 468 g_return_val_if_fail(attr != NULL, NULL); | |
| 469 | |
| 470 return attr->id; | |
| 471 } | |
| 472 | |
| 473 const char * | |
| 474 gaim_status_attr_get_name(const GaimStatusAttr *attr) | |
| 475 { | |
| 476 g_return_val_if_fail(attr != NULL, NULL); | |
| 477 | |
| 478 return attr->name; | |
| 479 } | |
| 480 | |
| 481 GaimValue * | |
| 482 gaim_status_attr_get_value_type(const GaimStatusAttr *attr) | |
| 483 { | |
| 484 g_return_val_if_fail(attr != NULL, NULL); | |
| 485 | |
| 486 return attr->value_type; | |
| 487 } | |
| 488 | |
| 489 | |
| 490 /************************************************************************** | |
| 491 * GaimStatus API | |
| 492 **************************************************************************/ | |
| 493 GaimStatus * | |
| 494 gaim_status_new(GaimStatusType *status_type, GaimPresence *presence) | |
| 495 { | |
| 496 GaimStatus *status; | |
| 497 const GList *l; | |
| 498 | |
| 499 g_return_val_if_fail(status_type != NULL, NULL); | |
| 500 g_return_val_if_fail(presence != NULL, NULL); | |
| 501 | |
| 502 status = g_new0(GaimStatus, 1); | |
| 503 | |
| 504 status->type = status_type; | |
| 505 status->presence = presence; | |
| 506 | |
| 507 status->attr_values = | |
| 508 g_hash_table_new_full(g_str_hash, g_str_equal, g_free, | |
| 509 (GDestroyNotify)gaim_value_destroy); | |
| 510 | |
| 511 for (l = gaim_status_type_get_attrs(status_type); l != NULL; l = l->next) | |
| 512 { | |
| 513 GaimStatusAttr *attr = (GaimStatusAttr *)l->data; | |
| 514 GaimValue *value = gaim_status_attr_get_value_type(attr); | |
| 515 GaimValue *new_value = gaim_value_dup(value); | |
| 516 | |
| 517 g_hash_table_insert(status->attr_values, | |
| 518 g_strdup(gaim_status_attr_get_id(attr)), new_value); | |
| 519 } | |
| 520 | |
| 521 return status; | |
| 522 } | |
| 523 | |
| 524 void | |
| 525 gaim_status_destroy(GaimStatus *status) | |
| 526 { | |
| 527 g_return_if_fail(status != NULL); | |
| 528 | |
| 529 gaim_status_set_active(status, FALSE); | |
| 530 | |
| 531 g_hash_table_destroy(status->attr_values); | |
| 532 | |
| 533 g_free(status); | |
| 534 } | |
| 6065 | 535 |
| 536 static void | |
| 9949 | 537 notify_buddy_status_update(GaimBuddy *buddy, GaimPresence *presence, |
| 538 GaimStatus *old_status, GaimStatus *new_status) | |
| 539 { | |
| 540 GaimBlistUiOps *ops = gaim_blist_get_ui_ops(); | |
| 541 | |
| 542 if (gaim_prefs_get_bool("/core/logging/log_system") && | |
| 543 gaim_prefs_get_bool("/core/logging/log_away_state")) | |
| 544 { | |
| 545 time_t current_time = time(NULL); | |
| 546 const char *buddy_alias = gaim_buddy_get_alias(buddy); | |
| 547 char *tmp = NULL; | |
| 548 | |
| 549 if (!gaim_status_is_available(old_status) && | |
| 550 gaim_status_is_available(new_status)) | |
| 551 { | |
| 552 tmp = g_strdup_printf(_("%s came back"), buddy_alias); | |
| 553 } | |
| 554 else if (gaim_status_is_available(old_status) && | |
| 555 !gaim_status_is_available(new_status)) | |
| 556 { | |
| 557 tmp = g_strdup_printf(_("%s went away"), buddy_alias); | |
| 558 } | |
| 559 | |
| 560 if (tmp != NULL) | |
| 561 { | |
| 562 GaimLog *log = gaim_account_get_log(buddy->account); | |
| 563 | |
| 564 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, buddy_alias, | |
| 565 current_time, tmp); | |
| 566 g_free(tmp); | |
| 567 } | |
| 568 } | |
| 569 | |
| 10012 | 570 |
| 571 | |
| 572 if (ops != NULL && ops->update != NULL) | |
| 573 ops->update(gaim_get_blist(), (GaimBlistNode*)buddy); | |
| 9949 | 574 } |
| 575 | |
| 576 static void | |
| 577 notify_status_update(GaimPresence *presence, GaimStatus *old_status, | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
578 GaimStatus *new_status) |
| 6065 | 579 { |
| 9949 | 580 GaimPresenceContext context = gaim_presence_get_context(presence); |
| 581 | |
| 10006 | 582 gaim_debug_info("notify_status_update", "Context is %d\n", context); |
| 583 | |
| 9949 | 584 if (context == GAIM_PRESENCE_CONTEXT_ACCOUNT) |
| 585 { | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
586 GaimAccount *account = gaim_presence_get_account(presence); |
| 9949 | 587 GaimAccountUiOps *ops = gaim_accounts_get_ui_ops(); |
| 588 | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
589 if (gaim_account_is_connected(account)) |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
590 { |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
591 GaimPluginProtocolInfo *prpl_info = NULL; |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
592 GaimPlugin *prpl; |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
593 |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
594 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
595 |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
596 if (prpl != NULL) |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
597 { |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
598 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
599 |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
600 if (prpl_info != NULL && prpl_info->set_status != NULL) |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
601 prpl_info->set_status(account, new_status); |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
602 } |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
603 } |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
604 |
| 9949 | 605 if (ops != NULL && ops->status_changed != NULL) |
| 606 { | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
607 ops->status_changed(account, new_status); |
| 9949 | 608 } |
| 609 } | |
| 610 else if (context == GAIM_PRESENCE_CONTEXT_CONV) | |
| 611 { | |
| 612 /* TODO */ | |
| 613 #if 0 | |
| 614 GaimConversationUiOps *ops; | |
| 615 GaimConversation *conv; | |
| 616 | |
| 617 conv = gaim_status_get_conversation(new_status); | |
| 618 #endif | |
| 619 } | |
| 620 else if (context == GAIM_PRESENCE_CONTEXT_BUDDY) | |
| 621 { | |
| 622 const GList *l; | |
| 623 | |
| 624 for (l = gaim_presence_get_buddies(presence); l != NULL; l = l->next) | |
| 625 { | |
| 626 notify_buddy_status_update((GaimBuddy *)l->data, presence, | |
| 627 old_status, new_status); | |
| 628 } | |
| 629 } | |
| 630 } | |
| 631 | |
| 632 void | |
| 633 gaim_status_set_active(GaimStatus *status, gboolean active) | |
| 634 { | |
| 635 GaimStatusType *status_type; | |
| 636 GaimPresence *presence; | |
| 637 GaimStatus *old_status; | |
| 638 | |
| 639 g_return_if_fail(status != NULL); | |
| 640 | |
| 641 if (status->active == active) | |
| 642 return; | |
| 643 | |
| 644 status_type = gaim_status_get_type(status); | |
| 6065 | 645 |
| 10067 | 646 if (!active && gaim_status_type_is_exclusive(status_type)) |
| 9949 | 647 { |
| 10052 | 648 gaim_debug_error("status", |
| 10006 | 649 "Cannot deactivate an exclusive status (%s).\n", |
| 650 gaim_status_type_get_id(status_type)); | |
| 9949 | 651 return; |
| 652 } | |
| 653 | |
| 654 presence = gaim_status_get_presence(status); | |
| 655 old_status = gaim_presence_get_active_status(presence); | |
| 656 | |
| 10067 | 657 if (gaim_status_type_is_exclusive(status_type)) |
| 9949 | 658 { |
| 659 const GList *l; | |
| 660 | |
| 10006 | 661 for (l = gaim_presence_get_statuses(presence); l != NULL; l = l->next) |
| 9949 | 662 { |
|
10056
b566449d45f8
[gaim-migrate @ 11021]
Luke Schierer <lschiere@pidgin.im>
parents:
10052
diff
changeset
|
663 GaimStatus *temp_status = l->data; |
|
b566449d45f8
[gaim-migrate @ 11021]
Luke Schierer <lschiere@pidgin.im>
parents:
10052
diff
changeset
|
664 GaimStatusType *temp_type; |
| 9949 | 665 |
|
10056
b566449d45f8
[gaim-migrate @ 11021]
Luke Schierer <lschiere@pidgin.im>
parents:
10052
diff
changeset
|
666 temp_type = gaim_status_get_type(temp_status); |
| 9949 | 667 |
| 668 if (gaim_status_type_is_independent(temp_type)) | |
| 669 continue; | |
| 670 | |
| 671 if (gaim_status_is_active(temp_status)) | |
| 672 { | |
| 673 /* | |
| 674 * Since we don't want an infinite loop, we have to set | |
| 675 * the active variable ourself. | |
| 676 */ | |
| 677 temp_status->active = FALSE; | |
| 678 | |
| 679 notify_status_update(presence, old_status, temp_status); | |
| 680 | |
| 681 break; | |
| 682 } | |
| 683 } | |
| 684 } | |
| 685 | |
| 686 status->active = active; | |
| 6065 | 687 |
| 9949 | 688 notify_status_update(presence, old_status, status); |
| 689 } | |
| 690 | |
| 691 void | |
| 692 gaim_status_set_attr_boolean(GaimStatus *status, const char *id, | |
| 693 gboolean value) | |
| 694 { | |
| 695 GaimStatusType *status_type; | |
| 696 GaimStatusAttr *attr; | |
| 697 GaimValue *attr_value; | |
| 698 | |
| 699 g_return_if_fail(status != NULL); | |
| 700 g_return_if_fail(id != NULL); | |
| 701 | |
| 702 status_type = gaim_status_get_type(status); | |
| 703 | |
| 704 /* Make sure this attribute exists. */ | |
| 705 attr = gaim_status_type_get_attr(status_type, id); | |
| 706 g_return_if_fail(attr != NULL); | |
| 707 | |
| 708 attr_value = gaim_status_attr_get_value_type(attr); | |
| 709 g_return_if_fail(gaim_value_get_type(attr_value) == GAIM_TYPE_BOOLEAN); | |
| 710 | |
| 711 gaim_value_set_boolean(attr_value, value); | |
| 712 } | |
| 713 | |
| 714 void | |
| 715 gaim_status_set_attr_int(GaimStatus *status, const char *id, int value) | |
| 716 { | |
| 717 GaimStatusType *status_type; | |
| 718 GaimStatusAttr *attr; | |
| 719 GaimValue *attr_value; | |
| 720 | |
| 721 g_return_if_fail(status != NULL); | |
| 722 g_return_if_fail(id != NULL); | |
| 723 | |
| 724 status_type = gaim_status_get_type(status); | |
| 725 | |
| 726 /* Make sure this attribute exists. */ | |
| 727 attr = gaim_status_type_get_attr(status_type, id); | |
| 728 g_return_if_fail(attr != NULL); | |
| 729 | |
| 730 attr_value = gaim_status_attr_get_value_type(attr); | |
| 731 g_return_if_fail(gaim_value_get_type(attr_value) == GAIM_TYPE_INT); | |
| 732 | |
| 733 gaim_value_set_int(attr_value, value); | |
| 6065 | 734 } |
| 735 | |
| 9949 | 736 void |
| 737 gaim_status_set_attr_string(GaimStatus *status, const char *id, | |
| 738 const char *value) | |
| 739 { | |
| 740 GaimStatusType *status_type; | |
| 741 GaimStatusAttr *attr; | |
| 742 GaimValue *attr_value; | |
| 743 | |
| 744 g_return_if_fail(status != NULL); | |
| 745 g_return_if_fail(id != NULL); | |
| 746 | |
| 747 status_type = gaim_status_get_type(status); | |
| 748 | |
| 749 /* Make sure this attribute exists. */ | |
| 750 attr = gaim_status_type_get_attr(status_type, id); | |
| 751 g_return_if_fail(attr != NULL); | |
| 752 | |
| 10196 | 753 attr_value = gaim_status_get_attr_value(status, id); |
| 9949 | 754 g_return_if_fail(gaim_value_get_type(attr_value) == GAIM_TYPE_STRING); |
| 755 | |
| 756 gaim_value_set_string(attr_value, value); | |
| 757 } | |
| 758 | |
| 759 GaimStatusType * | |
| 760 gaim_status_get_type(const GaimStatus *status) | |
| 761 { | |
| 762 g_return_val_if_fail(status != NULL, NULL); | |
| 763 | |
| 764 return status->type; | |
| 765 } | |
| 766 | |
| 767 GaimPresence * | |
| 768 gaim_status_get_presence(const GaimStatus *status) | |
| 6065 | 769 { |
| 9949 | 770 g_return_val_if_fail(status != NULL, NULL); |
| 771 | |
| 772 return status->presence; | |
| 773 } | |
| 774 | |
| 775 const char * | |
| 776 gaim_status_get_id(const GaimStatus *status) | |
| 777 { | |
| 778 g_return_val_if_fail(status != NULL, NULL); | |
| 779 | |
| 780 return gaim_status_type_get_id(gaim_status_get_type(status)); | |
| 781 } | |
| 782 | |
| 783 const char * | |
| 784 gaim_status_get_name(const GaimStatus *status) | |
| 785 { | |
| 786 g_return_val_if_fail(status != NULL, NULL); | |
| 787 | |
| 788 return gaim_status_type_get_name(gaim_status_get_type(status)); | |
| 789 } | |
| 790 | |
| 791 gboolean | |
| 792 gaim_status_is_independent(const GaimStatus *status) | |
| 793 { | |
| 794 g_return_val_if_fail(status != NULL, FALSE); | |
| 795 | |
| 796 return gaim_status_type_is_independent(gaim_status_get_type(status)); | |
| 797 } | |
| 798 | |
| 799 gboolean | |
| 10067 | 800 gaim_status_is_exclusive(const GaimStatus *status) |
| 801 { | |
| 802 g_return_val_if_fail(status != NULL, FALSE); | |
| 803 | |
| 804 return gaim_status_type_is_exclusive(gaim_status_get_type(status)); | |
| 805 } | |
| 806 | |
| 807 gboolean | |
| 9949 | 808 gaim_status_is_available(const GaimStatus *status) |
| 809 { | |
| 810 g_return_val_if_fail(status != NULL, FALSE); | |
| 811 | |
| 812 return gaim_status_type_is_available(gaim_status_get_type(status)); | |
| 813 } | |
| 6216 | 814 |
| 9949 | 815 gboolean |
| 816 gaim_status_is_active(const GaimStatus *status) | |
| 817 { | |
| 818 g_return_val_if_fail(status != NULL, FALSE); | |
| 819 | |
| 820 return status->active; | |
| 821 } | |
| 822 | |
|
10040
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
823 gboolean |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
824 gaim_status_is_online(const GaimStatus *status) |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
825 { |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
826 GaimStatusPrimitive primitive; |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
827 |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
828 g_return_val_if_fail( status != NULL, FALSE); |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
829 |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
830 primitive = gaim_status_type_get_primitive(gaim_status_get_type(status)); |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
831 |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
832 return (primitive != GAIM_STATUS_UNSET && |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
833 primitive != GAIM_STATUS_OFFLINE); |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
834 } |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
835 |
| 10196 | 836 /* |
| 837 * What's the difference between | |
| 838 * gaim_status_get_attr_value(GaimStatus *status, const char *id) | |
| 839 * gaim_status_attr_get_value_type(GaimStatusAttr *attr) | |
| 840 * and I think there was another similar one... | |
| 841 */ | |
| 9949 | 842 GaimValue * |
| 843 gaim_status_get_attr_value(const GaimStatus *status, const char *id) | |
| 844 { | |
| 845 GaimStatusType *status_type; | |
| 846 GaimStatusAttr *attr; | |
| 847 | |
| 848 g_return_val_if_fail(status != NULL, NULL); | |
| 849 g_return_val_if_fail(id != NULL, NULL); | |
| 850 | |
| 851 status_type = gaim_status_get_type(status); | |
| 852 | |
| 853 /* Make sure this attribute exists. */ | |
| 854 attr = gaim_status_type_get_attr(status_type, id); | |
| 855 g_return_val_if_fail(attr != NULL, NULL); | |
| 856 | |
| 857 return (GaimValue *)g_hash_table_lookup(status->attr_values, id); | |
| 858 } | |
| 859 | |
| 860 gboolean | |
| 861 gaim_status_get_attr_boolean(const GaimStatus *status, const char *id) | |
| 862 { | |
| 863 const GaimValue *value; | |
| 864 | |
| 865 g_return_val_if_fail(status != NULL, FALSE); | |
| 866 g_return_val_if_fail(id != NULL, FALSE); | |
| 867 | |
| 868 if ((value = gaim_status_get_attr_value(status, id)) == NULL) | |
| 869 return FALSE; | |
| 870 | |
| 871 g_return_val_if_fail(gaim_value_get_type(value) == GAIM_TYPE_STRING, FALSE); | |
| 872 | |
| 873 return gaim_value_get_boolean(value); | |
| 874 } | |
| 875 | |
| 876 int | |
| 877 gaim_status_get_attr_int(const GaimStatus *status, const char *id) | |
| 878 { | |
| 879 const GaimValue *value; | |
| 880 | |
| 881 g_return_val_if_fail(status != NULL, FALSE); | |
| 882 g_return_val_if_fail(id != NULL, FALSE); | |
| 883 | |
| 884 if ((value = gaim_status_get_attr_value(status, id)) == NULL) | |
| 885 return FALSE; | |
| 886 | |
| 887 g_return_val_if_fail(gaim_value_get_type(value) == GAIM_TYPE_INT, 0); | |
| 888 | |
| 889 return gaim_value_get_int(value); | |
| 890 } | |
| 891 | |
| 892 const char * | |
| 893 gaim_status_get_attr_string(const GaimStatus *status, const char *id) | |
| 894 { | |
| 895 const GaimValue *value; | |
| 896 | |
| 897 g_return_val_if_fail(status != NULL, FALSE); | |
| 898 g_return_val_if_fail(id != NULL, FALSE); | |
| 899 | |
| 900 if ((value = gaim_status_get_attr_value(status, id)) == NULL) | |
| 901 return FALSE; | |
| 902 | |
| 903 g_return_val_if_fail(gaim_value_get_type(value) == GAIM_TYPE_STRING, NULL); | |
| 904 | |
| 905 return gaim_value_get_string(value); | |
| 906 } | |
| 907 | |
| 908 gint | |
| 909 gaim_status_compare(const GaimStatus *status1, const GaimStatus *status2) | |
| 910 { | |
| 911 GaimStatusType *type1, *type2; | |
| 912 int score1 = 0, score2 = 0; | |
| 6065 | 913 |
| 9949 | 914 if ((status1 == NULL && status2 == NULL) || |
| 915 (status1 == status2)) | |
| 916 { | |
| 917 return 0; | |
| 918 } | |
| 919 else if (status1 == NULL) | |
| 920 return 1; | |
| 921 else if (status2 == NULL) | |
| 922 return -1; | |
| 923 | |
| 924 type1 = gaim_status_get_type(status1); | |
| 925 type2 = gaim_status_get_type(status2); | |
| 926 | |
| 927 if (gaim_status_is_active(status1)) | |
| 928 score1 = primitive_scores[gaim_status_type_get_primitive(type1)]; | |
| 929 | |
| 930 if (gaim_status_is_active(status2)) | |
| 931 score2 = primitive_scores[gaim_status_type_get_primitive(type2)]; | |
| 932 | |
| 933 if (score1 > score2) | |
| 934 return -1; | |
| 935 else if (score1 < score2) | |
| 936 return 1; | |
| 937 | |
| 938 return 0; | |
| 939 } | |
| 940 | |
| 941 | |
| 942 /************************************************************************** | |
| 943 * GaimPresence API | |
| 944 **************************************************************************/ | |
| 945 GaimPresence * | |
| 946 gaim_presence_new(GaimPresenceContext context) | |
| 947 { | |
| 948 GaimPresence *presence; | |
| 949 | |
| 950 g_return_val_if_fail(context != GAIM_PRESENCE_CONTEXT_UNSET, NULL); | |
| 951 | |
| 952 presence = g_new0(GaimPresence, 1); | |
| 953 | |
| 954 presence->context = context; | |
| 955 | |
| 956 presence->status_table = | |
| 10009 | 957 g_hash_table_new_full(g_str_hash, g_str_equal, |
| 958 g_free, (GFreeFunc)gaim_status_destroy); | |
| 9949 | 959 |
| 960 return presence; | |
| 961 } | |
| 962 | |
| 963 GaimPresence * | |
| 964 gaim_presence_new_for_account(GaimAccount *account) | |
| 965 { | |
| 10012 | 966 GaimPresence *presence = NULL; |
| 9949 | 967 g_return_val_if_fail(account != NULL, NULL); |
| 968 | |
| 969 presence = gaim_presence_new(GAIM_PRESENCE_CONTEXT_ACCOUNT); | |
| 970 presence->u.account = account; | |
| 10006 | 971 presence->statuses = gaim_prpl_get_statuses(account, presence); |
| 9949 | 972 |
| 973 return presence; | |
| 974 } | |
| 975 | |
| 976 GaimPresence * | |
| 977 gaim_presence_new_for_conv(GaimConversation *conv) | |
| 978 { | |
| 979 GaimPresence *presence; | |
| 980 | |
| 981 g_return_val_if_fail(conv != NULL, NULL); | |
| 982 | |
| 983 presence = gaim_presence_new(GAIM_PRESENCE_CONTEXT_CONV); | |
| 984 presence->u.chat.conv = conv; | |
| 10006 | 985 /* presence->statuses = gaim_prpl_get_statuses(conv->account, presence); ? */ |
| 9949 | 986 |
| 987 return presence; | |
| 988 } | |
| 6216 | 989 |
| 9949 | 990 GaimPresence * |
| 991 gaim_presence_new_for_buddy(GaimBuddy *buddy) | |
| 992 { | |
| 993 GaimPresence *presence; | |
| 994 GaimStatusBuddyKey *key; | |
| 10006 | 995 GaimAccount *account; |
| 9949 | 996 |
| 997 g_return_val_if_fail(buddy != NULL, NULL); | |
| 10012 | 998 account = buddy->account; |
| 9949 | 999 |
| 10006 | 1000 account = buddy->account; |
| 1001 | |
| 9949 | 1002 key = g_new0(GaimStatusBuddyKey, 1); |
| 1003 key->account = buddy->account; | |
| 1004 key->name = g_strdup(buddy->name); | |
| 10006 | 1005 |
| 1006 presence = g_hash_table_lookup(buddy_presences, key); | |
| 1007 if (presence == NULL) | |
| 9949 | 1008 { |
| 1009 presence = gaim_presence_new(GAIM_PRESENCE_CONTEXT_BUDDY); | |
| 1010 | |
| 1011 presence->u.buddy.name = g_strdup(buddy->name); | |
| 1012 presence->u.buddy.account = buddy->account; | |
| 10006 | 1013 presence->statuses = gaim_prpl_get_statuses(buddy->account, presence); |
| 9949 | 1014 |
| 1015 g_hash_table_insert(buddy_presences, key, presence); | |
| 1016 } | |
| 1017 else | |
| 1018 { | |
| 1019 g_free(key->name); | |
| 1020 g_free(key); | |
| 1021 } | |
| 1022 | |
| 1023 presence->u.buddy.ref_count++; | |
| 1024 presence->u.buddy.buddies = g_list_append(presence->u.buddy.buddies, | |
| 1025 buddy); | |
| 1026 | |
| 1027 return presence; | |
| 1028 } | |
| 1029 | |
| 1030 void | |
| 1031 gaim_presence_destroy(GaimPresence *presence) | |
| 1032 { | |
| 1033 g_return_if_fail(presence != NULL); | |
| 6216 | 1034 |
| 9949 | 1035 if (gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_BUDDY) |
| 1036 { | |
| 1037 GaimStatusBuddyKey key; | |
| 1038 | |
| 1039 presence->u.buddy.ref_count--; | |
| 1040 | |
| 10077 | 1041 if(presence->u.buddy.ref_count != 0) |
| 1042 return; | |
| 9949 | 1043 |
| 1044 key.account = presence->u.buddy.account; | |
| 1045 key.name = presence->u.buddy.name; | |
| 1046 | |
| 1047 g_hash_table_remove(buddy_presences, &key); | |
| 1048 | |
| 1049 if (presence->u.buddy.name != NULL) | |
| 1050 g_free(presence->u.buddy.name); | |
| 1051 } | |
| 1052 else if (gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_CONV) | |
| 1053 { | |
| 1054 if (presence->u.chat.user != NULL) | |
| 1055 g_free(presence->u.chat.user); | |
| 1056 } | |
| 1057 | |
| 1058 if (presence->statuses != NULL) | |
| 1059 g_list_free(presence->statuses); | |
| 1060 | |
| 1061 g_hash_table_destroy(presence->status_table); | |
| 1062 | |
| 1063 g_free(presence); | |
| 1064 } | |
| 1065 | |
| 1066 void | |
| 1067 gaim_presence_remove_buddy(GaimPresence *presence, GaimBuddy *buddy) | |
| 1068 { | |
| 1069 g_return_if_fail(presence != NULL); | |
| 1070 g_return_if_fail(buddy != NULL); | |
| 1071 g_return_if_fail(gaim_presence_get_context(presence) == | |
| 1072 GAIM_PRESENCE_CONTEXT_BUDDY); | |
| 1073 | |
| 1074 if (g_list_find(presence->u.buddy.buddies, buddy) != NULL) | |
| 1075 { | |
| 1076 presence->u.buddy.buddies = g_list_remove(presence->u.buddy.buddies, | |
| 1077 buddy); | |
| 1078 presence->u.buddy.ref_count--; | |
| 1079 } | |
| 6065 | 1080 } |
| 1081 | |
| 9949 | 1082 void |
| 1083 gaim_presence_add_status(GaimPresence *presence, GaimStatus *status) | |
| 1084 { | |
| 1085 g_return_if_fail(presence != NULL); | |
| 1086 g_return_if_fail(status != NULL); | |
| 1087 | |
| 1088 presence->statuses = g_list_append(presence->statuses, status); | |
| 1089 | |
| 1090 g_hash_table_insert(presence->status_table, | |
| 1091 g_strdup(gaim_status_get_id(status)), status); | |
| 1092 } | |
| 1093 | |
| 1094 void | |
| 1095 gaim_presence_add_presence(GaimPresence *presence, const GList *source_list) | |
| 1096 { | |
| 1097 const GList *l; | |
| 1098 | |
| 1099 g_return_if_fail(presence != NULL); | |
| 1100 g_return_if_fail(source_list != NULL); | |
| 1101 | |
| 1102 for (l = source_list; l != NULL; l = l->next) | |
| 1103 gaim_presence_add_status(presence, (GaimStatus *)l->data); | |
| 1104 } | |
| 1105 | |
| 10153 | 1106 /* |
| 1107 * TODO: Should we g_return_if_fail(active == status_id->active); ? | |
| 1108 * | |
| 1109 * TODO: If a buddy signed on or off, should we do any of the following? | |
| 1110 * (Note: We definitely need to do some of this somewhere, I'm just | |
| 1111 * not sure if here is the correct place.) | |
| 1112 * | |
| 1113 * char *tmp = g_strdup_printf(_("%s logged in."), alias); | |
| 1114 * gaim_conversation_write(c, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
| 1115 * g_free(tmp); | |
| 1116 * | |
| 1117 * GaimLog *log = gaim_account_get_log(account); | |
| 1118 * char *tmp = g_strdup_printf(_("%s signed on"), alias); | |
| 1119 * gaim_log_write(log, GAIM_MESSAGE_SYSTEM, (alias ? alias : name), current_time, tmp); | |
| 1120 * g_free(tmp); | |
| 1121 * | |
| 1122 * gaim_sound_play_event(GAIM_SOUND_BUDDY_ARRIVE); | |
| 1123 * | |
| 1124 * char *tmp = g_strdup_printf(_("%s logged out."), alias); | |
| 1125 * gaim_conversation_write(c, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
| 1126 * g_free(tmp); | |
| 1127 * | |
| 1128 * char *tmp = g_strdup_printf(_("%s signed off"), alias); | |
| 1129 * gaim_log_write(log, GAIM_MESSAGE_SYSTEM, (alias ? alias : name), current_time, tmp); | |
| 1130 * g_free(tmp); | |
| 1131 * | |
| 1132 * serv_got_typing_stopped(gc, name); | |
| 1133 * | |
| 1134 * gaim_sound_play_event(GAIM_SOUND_BUDDY_LEAVE); | |
| 1135 * | |
| 1136 * gaim_conversation_update(c, GAIM_CONV_UPDATE_AWAY); | |
| 1137 * | |
| 1138 */ | |
| 9949 | 1139 void |
| 1140 gaim_presence_set_status_active(GaimPresence *presence, const char *status_id, | |
| 1141 gboolean active) | |
| 1142 { | |
| 1143 GaimStatus *status; | |
| 1144 | |
| 1145 g_return_if_fail(presence != NULL); | |
| 1146 g_return_if_fail(status_id != NULL); | |
| 1147 | |
| 1148 status = gaim_presence_get_status(presence, status_id); | |
| 1149 | |
| 1150 g_return_if_fail(status != NULL); | |
| 1151 | |
| 10067 | 1152 if (gaim_status_is_exclusive(status)) |
| 9949 | 1153 { |
| 1154 if (!active) | |
| 1155 { | |
| 1156 gaim_debug_warning("status", | |
| 1157 "Attempted to set a non-independent status " | |
| 1158 "(%s) inactive. Only independent statuses " | |
| 1159 "can be specifically marked inactive.", | |
| 1160 status_id); | |
| 1161 | |
| 1162 return; | |
| 1163 } | |
| 1164 | |
| 10052 | 1165 } else if (presence->active_status != NULL) { |
| 1166 gaim_status_set_active(presence->active_status, FALSE); | |
| 9949 | 1167 |
| 1168 } | |
| 1169 | |
| 1170 gaim_status_set_active(status, active); | |
| 10052 | 1171 presence->active_status = status; |
| 9949 | 1172 } |
| 1173 | |
| 1174 void | |
| 1175 gaim_presence_switch_status(GaimPresence *presence, const char *status_id) | |
| 1176 { | |
| 1177 GaimStatus *status; | |
| 1178 | |
| 1179 g_return_if_fail(presence != NULL); | |
| 1180 g_return_if_fail(status_id != NULL); | |
| 1181 | |
| 1182 status = gaim_presence_get_status(presence, status_id); | |
| 1183 | |
| 1184 g_return_if_fail(status != NULL); | |
| 1185 | |
| 1186 if (gaim_status_is_independent(status)) | |
| 1187 return; | |
| 1188 | |
| 1189 if (presence->active_status != NULL) | |
| 1190 gaim_status_set_active(presence->active_status, FALSE); | |
| 1191 | |
| 1192 gaim_status_set_active(status, TRUE); | |
| 1193 } | |
| 1194 | |
| 1195 static void | |
| 1196 update_buddy_idle(GaimBuddy *buddy, GaimPresence *presence, | |
| 1197 time_t current_time, gboolean old_idle, gboolean idle) | |
| 1198 { | |
| 1199 GaimBlistUiOps *ops = gaim_get_blist()->ui_ops; | |
| 1200 | |
| 1201 if (!old_idle && idle) | |
| 1202 { | |
| 1203 gaim_signal_emit(gaim_blist_get_handle(), "buddy-idle", buddy); | |
| 1204 | |
| 1205 if (gaim_prefs_get_bool("/core/logging/log_system") && | |
| 1206 gaim_prefs_get_bool("/core/logging/log_idle_state")) | |
| 1207 { | |
| 1208 GaimLog *log = gaim_account_get_log(buddy->account); | |
| 1209 char *tmp = g_strdup_printf(_("%s became idle"), | |
| 1210 gaim_buddy_get_alias(buddy)); | |
| 1211 | |
| 1212 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, | |
| 1213 gaim_buddy_get_alias(buddy), current_time, tmp); | |
| 1214 g_free(tmp); | |
| 1215 } | |
| 1216 } | |
| 1217 else if (old_idle && !idle) | |
| 1218 { | |
| 1219 gaim_signal_emit(gaim_blist_get_handle(), "buddy-unidle", buddy); | |
| 1220 | |
| 1221 if (gaim_prefs_get_bool("/core/logging/log_system") && | |
| 1222 gaim_prefs_get_bool("/core/logging/log_idle_state")) | |
| 1223 { | |
| 1224 GaimLog *log = gaim_account_get_log(buddy->account); | |
| 1225 char *tmp = g_strdup_printf(_("%s became unidle"), | |
| 1226 gaim_buddy_get_alias(buddy)); | |
| 1227 | |
| 1228 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, | |
| 1229 gaim_buddy_get_alias(buddy), current_time, tmp); | |
| 1230 g_free(tmp); | |
| 1231 } | |
| 1232 } | |
| 1233 | |
| 1234 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); | |
| 1235 | |
| 1236 if (ops != NULL && ops->update != NULL) | |
| 1237 ops->update(gaim_get_blist(), (GaimBlistNode *)buddy); | |
| 1238 } | |
| 1239 | |
| 1240 void | |
| 1241 gaim_presence_set_idle(GaimPresence *presence, gboolean idle, time_t idle_time) | |
| 1242 { | |
| 1243 gboolean old_idle; | |
| 1244 | |
| 1245 g_return_if_fail(presence != NULL); | |
| 1246 | |
| 1247 if (presence->idle == idle && presence->idle_time == idle_time) | |
| 1248 return; | |
| 1249 | |
| 1250 old_idle = presence->idle; | |
| 1251 presence->idle = idle; | |
| 1252 presence->idle_time = (idle ? idle_time : 0); | |
| 1253 | |
| 1254 if (gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_BUDDY) | |
| 1255 { | |
| 1256 const GList *l; | |
| 1257 time_t current_time = time(NULL); | |
| 1258 | |
| 1259 for (l = gaim_presence_get_buddies(presence); l != NULL; l = l->next) | |
| 1260 { | |
| 1261 update_buddy_idle((GaimBuddy *)l->data, presence, current_time, | |
| 1262 old_idle, idle); | |
| 1263 } | |
| 1264 } | |
| 1265 } | |
| 1266 | |
| 1267 void | |
| 10006 | 1268 gaim_presence_set_login_time(GaimPresence *presence, time_t login_time) |
| 1269 { | |
| 1270 g_return_if_fail(presence != NULL); | |
| 1271 | |
| 1272 if (presence->login_time == login_time) | |
| 1273 return; | |
| 1274 | |
| 1275 presence->login_time = login_time; | |
| 1276 } | |
| 1277 | |
| 1278 void | |
| 9949 | 1279 gaim_presence_set_warning_level(GaimPresence *presence, unsigned int level) |
| 6065 | 1280 { |
| 9949 | 1281 g_return_if_fail(presence != NULL); |
| 1282 g_return_if_fail(level <= 100); | |
| 1283 | |
| 1284 if (presence->warning_level == level) | |
| 1285 return; | |
| 1286 | |
| 1287 presence->warning_level = level; | |
| 1288 | |
| 1289 if (gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_BUDDY) | |
| 1290 { | |
| 1291 GaimBlistUiOps *ops = gaim_get_blist()->ui_ops; | |
| 1292 | |
| 1293 if (ops != NULL && ops->update != NULL) | |
| 1294 { | |
| 1295 const GList *l; | |
| 1296 | |
| 1297 for (l = gaim_presence_get_buddies(presence); | |
| 1298 l != NULL; | |
| 1299 l = l->next) | |
| 1300 { | |
| 1301 ops->update(gaim_get_blist(), (GaimBlistNode *)l->data); | |
| 1302 } | |
| 1303 } | |
| 1304 } | |
| 1305 } | |
| 1306 | |
| 1307 GaimPresenceContext | |
| 1308 gaim_presence_get_context(const GaimPresence *presence) | |
| 1309 { | |
| 1310 g_return_val_if_fail(presence != NULL, GAIM_PRESENCE_CONTEXT_UNSET); | |
| 1311 | |
| 1312 return presence->context; | |
| 1313 } | |
| 1314 | |
| 1315 GaimAccount * | |
| 1316 gaim_presence_get_account(const GaimPresence *presence) | |
| 1317 { | |
| 1318 GaimPresenceContext context; | |
| 1319 | |
| 1320 g_return_val_if_fail(presence != NULL, NULL); | |
| 1321 | |
| 1322 context = gaim_presence_get_context(presence); | |
| 1323 | |
| 1324 g_return_val_if_fail(context == GAIM_PRESENCE_CONTEXT_ACCOUNT || | |
| 1325 context == GAIM_PRESENCE_CONTEXT_BUDDY, NULL); | |
| 1326 | |
| 1327 return presence->u.account; | |
| 1328 } | |
| 1329 | |
| 1330 GaimConversation * | |
| 1331 gaim_presence_get_conversation(const GaimPresence *presence) | |
| 1332 { | |
| 1333 g_return_val_if_fail(presence != NULL, NULL); | |
| 1334 g_return_val_if_fail(gaim_presence_get_context(presence) == | |
| 1335 GAIM_PRESENCE_CONTEXT_CONV, NULL); | |
| 1336 | |
| 1337 return presence->u.chat.conv; | |
| 1338 } | |
| 1339 | |
| 1340 const char * | |
| 1341 gaim_presence_get_chat_user(const GaimPresence *presence) | |
| 1342 { | |
| 1343 g_return_val_if_fail(presence != NULL, NULL); | |
| 1344 g_return_val_if_fail(gaim_presence_get_context(presence) == | |
| 1345 GAIM_PRESENCE_CONTEXT_CONV, NULL); | |
| 1346 | |
| 1347 return presence->u.chat.user; | |
| 1348 } | |
| 1349 | |
| 1350 const GList * | |
| 1351 gaim_presence_get_buddies(const GaimPresence *presence) | |
| 1352 { | |
| 1353 g_return_val_if_fail(presence != NULL, NULL); | |
| 1354 g_return_val_if_fail(gaim_presence_get_context(presence) == | |
| 1355 GAIM_PRESENCE_CONTEXT_BUDDY, NULL); | |
| 1356 | |
| 1357 return presence->u.buddy.buddies; | |
| 1358 } | |
| 1359 | |
| 1360 const GList * | |
| 1361 gaim_presence_get_statuses(const GaimPresence *presence) | |
| 1362 { | |
| 1363 g_return_val_if_fail(presence != NULL, NULL); | |
| 1364 | |
| 1365 return presence->statuses; | |
| 1366 } | |
| 1367 | |
| 1368 GaimStatus * | |
| 1369 gaim_presence_get_status(const GaimPresence *presence, const char *status_id) | |
| 1370 { | |
| 1371 GaimStatus *status; | |
| 10006 | 1372 const GList *l = NULL; |
| 9949 | 1373 |
| 1374 g_return_val_if_fail(presence != NULL, NULL); | |
| 1375 g_return_val_if_fail(status_id != NULL, NULL); | |
| 1376 | |
| 10006 | 1377 /* What's the purpose of this hash table? */ |
| 10012 | 1378 status = (GaimStatus *)g_hash_table_lookup(presence->status_table, |
| 10006 | 1379 status_id); |
| 10012 | 1380 |
| 10006 | 1381 if (status == NULL) { |
| 10012 | 1382 for (l = gaim_presence_get_statuses(presence); |
| 10006 | 1383 l != NULL && status == NULL; l = l->next) |
| 1384 { | |
| 1385 GaimStatus *temp_status = l->data; | |
| 10012 | 1386 |
| 10006 | 1387 if (!strcmp(status_id, gaim_status_get_id(temp_status))) |
| 1388 status = temp_status; | |
| 1389 } | |
| 1390 | |
| 1391 if (status != NULL) | |
| 1392 g_hash_table_insert(presence->status_table, | |
| 1393 g_strdup(gaim_status_get_id(status)), status); | |
| 10012 | 1394 } |
| 9949 | 1395 |
| 1396 return status; | |
| 1397 } | |
| 1398 | |
| 1399 GaimStatus * | |
| 1400 gaim_presence_get_active_status(const GaimPresence *presence) | |
| 1401 { | |
| 1402 g_return_val_if_fail(presence != NULL, NULL); | |
| 1403 | |
| 1404 return presence->active_status; | |
| 1405 } | |
| 1406 | |
| 1407 gboolean | |
| 1408 gaim_presence_is_available(const GaimPresence *presence) | |
| 1409 { | |
| 1410 GaimStatus *status; | |
| 1411 | |
| 1412 g_return_val_if_fail(presence != NULL, FALSE); | |
| 1413 | |
| 1414 status = gaim_presence_get_active_status(presence); | |
| 1415 | |
| 1416 return ((status != NULL && gaim_status_is_available(status)) && | |
| 1417 !gaim_presence_is_idle(presence)); | |
| 1418 } | |
| 1419 | |
| 1420 gboolean | |
| 1421 gaim_presence_is_online(const GaimPresence *presence) | |
| 1422 { | |
| 1423 GaimStatus *status; | |
| 1424 | |
| 1425 g_return_val_if_fail(presence != NULL, FALSE); | |
| 1426 | |
| 1427 if ((status = gaim_presence_get_active_status(presence)) == NULL) | |
| 1428 return FALSE; | |
| 1429 | |
|
10040
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
1430 return gaim_status_is_online(status); |
| 9949 | 1431 } |
| 1432 | |
| 1433 gboolean | |
| 1434 gaim_presence_is_status_active(const GaimPresence *presence, | |
| 1435 const char *status_id) | |
| 1436 { | |
| 1437 GaimStatus *status; | |
| 1438 | |
| 1439 g_return_val_if_fail(presence != NULL, FALSE); | |
| 1440 g_return_val_if_fail(status_id != NULL, FALSE); | |
| 1441 | |
| 1442 status = gaim_presence_get_status(presence, status_id); | |
| 1443 | |
| 1444 return (status != NULL && gaim_status_is_active(status)); | |
| 1445 } | |
| 1446 | |
| 1447 gboolean | |
| 1448 gaim_presence_is_status_primitive_active(const GaimPresence *presence, | |
| 1449 GaimStatusPrimitive primitive) | |
| 1450 { | |
| 1451 GaimStatus *status; | |
| 1452 GaimStatusType *status_type; | |
| 1453 | |
| 1454 g_return_val_if_fail(presence != NULL, FALSE); | |
| 1455 g_return_val_if_fail(primitive != GAIM_STATUS_UNSET, FALSE); | |
| 1456 | |
| 1457 status = gaim_presence_get_active_status(presence); | |
| 1458 status_type = gaim_status_get_type(status); | |
| 1459 | |
| 1460 if (gaim_status_type_get_primitive(status_type) == primitive) | |
| 1461 return TRUE; | |
| 6065 | 1462 |
| 1463 return FALSE; | |
| 1464 } | |
| 1465 | |
| 9949 | 1466 gboolean |
| 1467 gaim_presence_is_idle(const GaimPresence *presence) | |
| 6065 | 1468 { |
| 9949 | 1469 g_return_val_if_fail(presence != NULL, FALSE); |
| 1470 | |
| 1471 return presence->idle; | |
| 6065 | 1472 } |
| 1473 | |
| 9949 | 1474 time_t |
| 1475 gaim_presence_get_idle_time(const GaimPresence *presence) | |
| 6065 | 1476 { |
| 9949 | 1477 g_return_val_if_fail(presence != NULL, 0); |
| 6065 | 1478 |
| 9949 | 1479 return presence->idle_time; |
| 1480 } | |
| 6065 | 1481 |
| 9949 | 1482 unsigned int |
| 1483 gaim_presence_get_warning_level(const GaimPresence *presence) | |
| 1484 { | |
| 1485 g_return_val_if_fail(presence != NULL, 0); | |
| 6216 | 1486 |
| 9949 | 1487 return presence->warning_level; |
| 6065 | 1488 } |
| 1489 | |
| 9949 | 1490 gint |
| 1491 gaim_presence_compare(const GaimPresence *presence1, | |
| 1492 const GaimPresence *presence2) | |
| 6065 | 1493 { |
| 9949 | 1494 gboolean idle1, idle2; |
| 1495 size_t idle_time_1, idle_time_2; | |
| 1496 int score1 = 0, score2 = 0; | |
| 1497 const GList *l; | |
| 6065 | 1498 |
| 9949 | 1499 if ((presence1 == NULL && presence2 == NULL) || (presence1 == presence2)) |
| 1500 return 0; | |
| 1501 else if (presence1 == NULL) | |
|
10151
d83e6f2125b1
[gaim-migrate @ 11228]
Christian Hammond <chipx86@chipx86.com>
parents:
10087
diff
changeset
|
1502 return 1; |
| 9949 | 1503 else if (presence2 == NULL) |
|
10151
d83e6f2125b1
[gaim-migrate @ 11228]
Christian Hammond <chipx86@chipx86.com>
parents:
10087
diff
changeset
|
1504 return -1; |
| 6065 | 1505 |
| 9949 | 1506 /* Compute the score of the first set of statuses. */ |
| 1507 for (l = gaim_presence_get_statuses(presence1); l != NULL; l = l->next) | |
| 1508 { | |
| 1509 GaimStatus *status = (GaimStatus *)l->data; | |
| 1510 GaimStatusType *type = gaim_status_get_type(status); | |
| 6065 | 1511 |
| 9949 | 1512 if (gaim_status_is_active(status)) |
| 1513 score1 += primitive_scores[gaim_status_type_get_primitive(type)]; | |
| 6065 | 1514 } |
| 1515 | |
| 9949 | 1516 /* Compute the score of the second set of statuses. */ |
|
10151
d83e6f2125b1
[gaim-migrate @ 11228]
Christian Hammond <chipx86@chipx86.com>
parents:
10087
diff
changeset
|
1517 for (l = gaim_presence_get_statuses(presence2); l != NULL; l = l->next) |
| 9949 | 1518 { |
| 1519 GaimStatus *status = (GaimStatus *)l->data; | |
| 1520 GaimStatusType *type = gaim_status_get_type(status); | |
| 6065 | 1521 |
| 9949 | 1522 if (gaim_status_is_active(status)) |
| 1523 score2 += primitive_scores[gaim_status_type_get_primitive(type)]; | |
| 6065 | 1524 } |
| 1525 | |
| 9949 | 1526 idle1 = gaim_presence_is_idle(presence1); |
| 1527 idle2 = gaim_presence_is_idle(presence2); | |
| 6065 | 1528 |
| 9949 | 1529 if (idle1) |
| 1530 score1 += primitive_scores[SCORE_IDLE]; | |
| 6065 | 1531 |
| 9949 | 1532 if (idle2) |
| 1533 score2 += primitive_scores[SCORE_IDLE]; | |
| 6065 | 1534 |
| 9949 | 1535 idle_time_1 = gaim_presence_get_idle_time(presence1); |
| 1536 idle_time_2 = gaim_presence_get_idle_time(presence2); | |
| 6065 | 1537 |
| 9949 | 1538 if (idle_time_1 > idle_time_2) |
| 1539 score1 += primitive_scores[SCORE_IDLE_TIME]; | |
| 1540 else if (idle_time_1 < idle_time_2) | |
| 1541 score2 += primitive_scores[SCORE_IDLE_TIME]; | |
| 6065 | 1542 |
| 9949 | 1543 if (score1 < score2) |
| 1544 return 1; | |
| 1545 else if (score1 > score2) | |
| 1546 return -1; | |
| 1547 | |
| 1548 return 0; | |
| 1549 } | |
| 1550 | |
| 6065 | 1551 |
| 9949 | 1552 /************************************************************************** |
| 1553 * Status subsystem | |
| 1554 **************************************************************************/ | |
| 1555 static void | |
| 1556 score_pref_changed_cb(const char *name, GaimPrefType type, gpointer value, | |
| 1557 gpointer data) | |
| 1558 { | |
| 1559 int index = GPOINTER_TO_INT(data); | |
| 6065 | 1560 |
| 9949 | 1561 primitive_scores[index] = GPOINTER_TO_INT(value); |
| 6065 | 1562 } |
| 1563 | |
| 10012 | 1564 guint |
| 10006 | 1565 gaim_buddy_presences_hash(gconstpointer key) |
| 1566 { | |
| 10012 | 1567 const GaimStatusBuddyKey *me = key; |
| 1568 guint ret; | |
| 1569 char *str; | |
| 1570 | |
| 1571 str = g_strdup_printf("%p%s", me->account, me->name); | |
| 1572 ret = g_str_hash(str); | |
| 1573 g_free(str); | |
| 1574 | |
| 1575 return ret; | |
| 10006 | 1576 } |
| 1577 | |
| 10012 | 1578 gboolean |
| 10006 | 1579 gaim_buddy_presences_equal(gconstpointer a, gconstpointer b) |
| 1580 { | |
| 1581 GaimStatusBuddyKey *key_a = (GaimStatusBuddyKey *)a; | |
| 1582 GaimStatusBuddyKey *key_b = (GaimStatusBuddyKey *)b; | |
| 1583 | |
| 10012 | 1584 if(key_a->account == key_b->account && |
| 1585 !strcmp(key_a->name, key_b->name)) | |
| 10006 | 1586 return TRUE; |
| 1587 else | |
| 1588 return FALSE; | |
| 1589 } | |
| 1590 | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1591 const GList * |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1592 gaim_statuses_get_stored(void) |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1593 { |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1594 return NULL; |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1595 } |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1596 |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1597 GaimStatus * |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1598 gaim_statuses_find_stored(const GaimStatusType *status_type, const char *id) |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1599 { |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1600 return NULL; |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1601 } |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1602 |
| 10087 | 1603 void * |
| 1604 gaim_statuses_get_handle() { | |
| 1605 static int handle; | |
| 1606 | |
| 1607 return &handle; | |
| 1608 } | |
| 1609 | |
| 9949 | 1610 void |
| 1611 gaim_statuses_init(void) | |
| 6065 | 1612 { |
| 10087 | 1613 void *handle = gaim_statuses_get_handle; |
| 1614 | |
| 9949 | 1615 gaim_prefs_add_none("/core/status"); |
| 1616 gaim_prefs_add_none("/core/status/scores"); | |
| 6065 | 1617 |
| 9949 | 1618 gaim_prefs_add_int("/core/status/scores/offline", |
| 1619 primitive_scores[GAIM_STATUS_OFFLINE]); | |
| 1620 gaim_prefs_add_int("/core/status/scores/available", | |
| 1621 primitive_scores[GAIM_STATUS_AVAILABLE]); | |
| 1622 gaim_prefs_add_int("/core/status/scores/hidden", | |
| 1623 primitive_scores[GAIM_STATUS_HIDDEN]); | |
| 1624 gaim_prefs_add_int("/core/status/scores/away", | |
| 1625 primitive_scores[GAIM_STATUS_AWAY]); | |
| 1626 gaim_prefs_add_int("/core/status/scores/extended_away", | |
| 1627 primitive_scores[GAIM_STATUS_EXTENDED_AWAY]); | |
| 1628 gaim_prefs_add_int("/core/status/scores/idle", | |
| 1629 primitive_scores[SCORE_IDLE]); | |
| 6065 | 1630 |
| 10087 | 1631 gaim_prefs_connect_callback(handle, "/core/status/scores/offline", |
| 9949 | 1632 score_pref_changed_cb, |
| 1633 GINT_TO_POINTER(GAIM_STATUS_OFFLINE)); | |
| 10087 | 1634 gaim_prefs_connect_callback(handle, "/core/status/scores/available", |
| 9949 | 1635 score_pref_changed_cb, |
| 1636 GINT_TO_POINTER(GAIM_STATUS_AVAILABLE)); | |
| 10087 | 1637 gaim_prefs_connect_callback(handle, "/core/status/scores/hidden", |
| 9949 | 1638 score_pref_changed_cb, |
| 1639 GINT_TO_POINTER(GAIM_STATUS_HIDDEN)); | |
| 10087 | 1640 gaim_prefs_connect_callback(handle, "/core/status/scores/away", |
| 9949 | 1641 score_pref_changed_cb, |
| 1642 GINT_TO_POINTER(GAIM_STATUS_AWAY)); | |
| 10087 | 1643 gaim_prefs_connect_callback(handle, "/core/status/scores/extended_away", |
| 9949 | 1644 score_pref_changed_cb, |
| 1645 GINT_TO_POINTER(GAIM_STATUS_EXTENDED_AWAY)); | |
| 10087 | 1646 gaim_prefs_connect_callback(handle, "/core/status/scores/idle", |
| 9949 | 1647 score_pref_changed_cb, |
| 1648 GINT_TO_POINTER(SCORE_IDLE)); | |
| 10006 | 1649 |
| 1650 buddy_presences = g_hash_table_new(gaim_buddy_presences_hash, | |
| 1651 gaim_buddy_presences_equal); | |
| 9949 | 1652 } |
| 6065 | 1653 |
| 9949 | 1654 void |
| 1655 gaim_statuses_uninit(void) | |
| 1656 { | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1657 if (buddy_presences != NULL) |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1658 { |
| 10077 | 1659 g_hash_table_destroy(buddy_presences); |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1660 |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1661 buddy_presences = NULL; |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1662 } |
| 9949 | 1663 } |
| 6065 | 1664 |
| 9949 | 1665 void |
| 1666 gaim_statuses_sync(void) | |
| 1667 { | |
| 6065 | 1668 } |
| 9949 | 1669 |
| 1670 void | |
| 1671 gaim_statuses_load(void) | |
| 1672 { | |
| 1673 } |
