Mercurial > pidgin
annotate src/status.c @ 10201:5e1ca11db043
[gaim-migrate @ 11319]
silc added
committer: Tailor Script <tailor@pidgin.im>
| author | Herman Bloggs <hermanator12002@yahoo.com> |
|---|---|
| date | Wed, 17 Nov 2004 23:08:24 +0000 |
| parents | f086269582b1 |
| children | 393f85d9f8dd |
| 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 | |
| 10197 | 272 gaim_status_type_add_attr(GaimStatusType *status_type, const char *id, |
| 9949 | 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, | |
| 10197 | 518 g_strdup(gaim_status_attr_get_id(attr)), |
| 519 new_value); | |
| 9949 | 520 } |
| 521 | |
| 522 return status; | |
| 523 } | |
| 524 | |
| 525 void | |
| 526 gaim_status_destroy(GaimStatus *status) | |
| 527 { | |
| 528 g_return_if_fail(status != NULL); | |
| 529 | |
| 530 gaim_status_set_active(status, FALSE); | |
| 531 | |
| 532 g_hash_table_destroy(status->attr_values); | |
| 533 | |
| 534 g_free(status); | |
| 535 } | |
| 6065 | 536 |
| 537 static void | |
| 9949 | 538 notify_buddy_status_update(GaimBuddy *buddy, GaimPresence *presence, |
| 539 GaimStatus *old_status, GaimStatus *new_status) | |
| 540 { | |
| 541 GaimBlistUiOps *ops = gaim_blist_get_ui_ops(); | |
| 542 | |
| 543 if (gaim_prefs_get_bool("/core/logging/log_system") && | |
| 544 gaim_prefs_get_bool("/core/logging/log_away_state")) | |
| 545 { | |
| 546 time_t current_time = time(NULL); | |
| 547 const char *buddy_alias = gaim_buddy_get_alias(buddy); | |
| 548 char *tmp = NULL; | |
| 549 | |
| 550 if (!gaim_status_is_available(old_status) && | |
| 551 gaim_status_is_available(new_status)) | |
| 552 { | |
| 553 tmp = g_strdup_printf(_("%s came back"), buddy_alias); | |
| 554 } | |
| 555 else if (gaim_status_is_available(old_status) && | |
| 556 !gaim_status_is_available(new_status)) | |
| 557 { | |
| 558 tmp = g_strdup_printf(_("%s went away"), buddy_alias); | |
| 559 } | |
| 560 | |
| 561 if (tmp != NULL) | |
| 562 { | |
| 563 GaimLog *log = gaim_account_get_log(buddy->account); | |
| 564 | |
| 565 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, buddy_alias, | |
| 566 current_time, tmp); | |
| 567 g_free(tmp); | |
| 568 } | |
| 569 } | |
| 570 | |
| 10012 | 571 |
| 572 | |
| 573 if (ops != NULL && ops->update != NULL) | |
| 574 ops->update(gaim_get_blist(), (GaimBlistNode*)buddy); | |
| 9949 | 575 } |
| 576 | |
| 577 static void | |
| 578 notify_status_update(GaimPresence *presence, GaimStatus *old_status, | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
579 GaimStatus *new_status) |
| 6065 | 580 { |
| 9949 | 581 GaimPresenceContext context = gaim_presence_get_context(presence); |
| 582 | |
| 583 if (context == GAIM_PRESENCE_CONTEXT_ACCOUNT) | |
| 584 { | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
585 GaimAccount *account = gaim_presence_get_account(presence); |
| 9949 | 586 GaimAccountUiOps *ops = gaim_accounts_get_ui_ops(); |
| 587 | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
588 if (gaim_account_is_connected(account)) |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
589 { |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
590 GaimPluginProtocolInfo *prpl_info = NULL; |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
591 GaimPlugin *prpl; |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
592 |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
593 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
594 |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
595 if (prpl != NULL) |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
596 { |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
597 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
598 |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
599 if (prpl_info != NULL && prpl_info->set_status != NULL) |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
600 prpl_info->set_status(account, new_status); |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
601 } |
|
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 |
| 9949 | 604 if (ops != NULL && ops->status_changed != NULL) |
| 605 { | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
606 ops->status_changed(account, new_status); |
| 9949 | 607 } |
| 608 } | |
| 609 else if (context == GAIM_PRESENCE_CONTEXT_CONV) | |
| 610 { | |
| 611 /* TODO */ | |
| 612 #if 0 | |
| 613 GaimConversationUiOps *ops; | |
| 614 GaimConversation *conv; | |
| 615 | |
| 616 conv = gaim_status_get_conversation(new_status); | |
| 617 #endif | |
| 618 } | |
| 619 else if (context == GAIM_PRESENCE_CONTEXT_BUDDY) | |
| 620 { | |
| 621 const GList *l; | |
| 622 | |
| 623 for (l = gaim_presence_get_buddies(presence); l != NULL; l = l->next) | |
| 624 { | |
| 625 notify_buddy_status_update((GaimBuddy *)l->data, presence, | |
| 626 old_status, new_status); | |
| 627 } | |
| 628 } | |
| 629 } | |
| 630 | |
| 631 void | |
| 632 gaim_status_set_active(GaimStatus *status, gboolean active) | |
| 633 { | |
| 634 GaimStatusType *status_type; | |
| 635 GaimPresence *presence; | |
| 636 GaimStatus *old_status; | |
| 637 | |
| 638 g_return_if_fail(status != NULL); | |
| 639 | |
| 640 if (status->active == active) | |
| 641 return; | |
| 642 | |
| 643 status_type = gaim_status_get_type(status); | |
| 6065 | 644 |
| 10067 | 645 if (!active && gaim_status_type_is_exclusive(status_type)) |
| 9949 | 646 { |
| 10052 | 647 gaim_debug_error("status", |
| 10006 | 648 "Cannot deactivate an exclusive status (%s).\n", |
| 649 gaim_status_type_get_id(status_type)); | |
| 9949 | 650 return; |
| 651 } | |
| 652 | |
| 653 presence = gaim_status_get_presence(status); | |
| 654 old_status = gaim_presence_get_active_status(presence); | |
| 655 | |
| 10067 | 656 if (gaim_status_type_is_exclusive(status_type)) |
| 9949 | 657 { |
| 658 const GList *l; | |
| 659 | |
| 10006 | 660 for (l = gaim_presence_get_statuses(presence); l != NULL; l = l->next) |
| 9949 | 661 { |
|
10056
b566449d45f8
[gaim-migrate @ 11021]
Luke Schierer <lschiere@pidgin.im>
parents:
10052
diff
changeset
|
662 GaimStatus *temp_status = l->data; |
|
b566449d45f8
[gaim-migrate @ 11021]
Luke Schierer <lschiere@pidgin.im>
parents:
10052
diff
changeset
|
663 GaimStatusType *temp_type; |
| 9949 | 664 |
|
10056
b566449d45f8
[gaim-migrate @ 11021]
Luke Schierer <lschiere@pidgin.im>
parents:
10052
diff
changeset
|
665 temp_type = gaim_status_get_type(temp_status); |
| 9949 | 666 |
| 667 if (gaim_status_type_is_independent(temp_type)) | |
| 668 continue; | |
| 669 | |
| 670 if (gaim_status_is_active(temp_status)) | |
| 671 { | |
| 672 /* | |
| 673 * Since we don't want an infinite loop, we have to set | |
| 674 * the active variable ourself. | |
| 675 */ | |
| 676 temp_status->active = FALSE; | |
| 677 | |
| 678 notify_status_update(presence, old_status, temp_status); | |
| 679 | |
| 680 break; | |
| 681 } | |
| 682 } | |
| 683 } | |
| 684 | |
| 685 status->active = active; | |
| 6065 | 686 |
| 9949 | 687 notify_status_update(presence, old_status, status); |
| 688 } | |
| 689 | |
| 690 void | |
| 691 gaim_status_set_attr_boolean(GaimStatus *status, const char *id, | |
| 692 gboolean value) | |
| 693 { | |
| 694 GaimStatusType *status_type; | |
| 695 GaimValue *attr_value; | |
| 696 | |
| 697 g_return_if_fail(status != NULL); | |
| 698 g_return_if_fail(id != NULL); | |
| 699 | |
| 700 status_type = gaim_status_get_type(status); | |
| 701 | |
| 10197 | 702 /* Make sure this attribute exists and is the correct type. */ |
| 703 attr_value = gaim_status_get_attr_value(status, id); | |
| 704 g_return_if_fail(attr_value != NULL); | |
| 9949 | 705 g_return_if_fail(gaim_value_get_type(attr_value) == GAIM_TYPE_BOOLEAN); |
| 706 | |
| 707 gaim_value_set_boolean(attr_value, value); | |
| 708 } | |
| 709 | |
| 710 void | |
| 711 gaim_status_set_attr_int(GaimStatus *status, const char *id, int value) | |
| 712 { | |
| 713 GaimStatusType *status_type; | |
| 714 GaimValue *attr_value; | |
| 715 | |
| 716 g_return_if_fail(status != NULL); | |
| 717 g_return_if_fail(id != NULL); | |
| 718 | |
| 719 status_type = gaim_status_get_type(status); | |
| 720 | |
| 10197 | 721 /* Make sure this attribute exists and is the correct type. */ |
| 722 attr_value = gaim_status_get_attr_value(status, id); | |
| 723 g_return_if_fail(attr_value != NULL); | |
| 9949 | 724 g_return_if_fail(gaim_value_get_type(attr_value) == GAIM_TYPE_INT); |
| 725 | |
| 726 gaim_value_set_int(attr_value, value); | |
| 6065 | 727 } |
| 728 | |
| 9949 | 729 void |
| 730 gaim_status_set_attr_string(GaimStatus *status, const char *id, | |
| 731 const char *value) | |
| 732 { | |
| 733 GaimStatusType *status_type; | |
| 734 GaimValue *attr_value; | |
| 735 | |
| 736 g_return_if_fail(status != NULL); | |
| 737 g_return_if_fail(id != NULL); | |
| 738 | |
| 739 status_type = gaim_status_get_type(status); | |
| 740 | |
| 10197 | 741 /* Make sure this attribute exists and is the correct type. */ |
| 10196 | 742 attr_value = gaim_status_get_attr_value(status, id); |
| 10197 | 743 g_return_if_fail(attr_value != NULL); |
| 9949 | 744 g_return_if_fail(gaim_value_get_type(attr_value) == GAIM_TYPE_STRING); |
| 745 | |
| 746 gaim_value_set_string(attr_value, value); | |
| 747 } | |
| 748 | |
| 749 GaimStatusType * | |
| 750 gaim_status_get_type(const GaimStatus *status) | |
| 751 { | |
| 752 g_return_val_if_fail(status != NULL, NULL); | |
| 753 | |
| 754 return status->type; | |
| 755 } | |
| 756 | |
| 757 GaimPresence * | |
| 758 gaim_status_get_presence(const GaimStatus *status) | |
| 6065 | 759 { |
| 9949 | 760 g_return_val_if_fail(status != NULL, NULL); |
| 761 | |
| 762 return status->presence; | |
| 763 } | |
| 764 | |
| 765 const char * | |
| 766 gaim_status_get_id(const GaimStatus *status) | |
| 767 { | |
| 768 g_return_val_if_fail(status != NULL, NULL); | |
| 769 | |
| 770 return gaim_status_type_get_id(gaim_status_get_type(status)); | |
| 771 } | |
| 772 | |
| 773 const char * | |
| 774 gaim_status_get_name(const GaimStatus *status) | |
| 775 { | |
| 776 g_return_val_if_fail(status != NULL, NULL); | |
| 777 | |
| 778 return gaim_status_type_get_name(gaim_status_get_type(status)); | |
| 779 } | |
| 780 | |
| 781 gboolean | |
| 782 gaim_status_is_independent(const GaimStatus *status) | |
| 783 { | |
| 784 g_return_val_if_fail(status != NULL, FALSE); | |
| 785 | |
| 786 return gaim_status_type_is_independent(gaim_status_get_type(status)); | |
| 787 } | |
| 788 | |
| 789 gboolean | |
| 10067 | 790 gaim_status_is_exclusive(const GaimStatus *status) |
| 791 { | |
| 792 g_return_val_if_fail(status != NULL, FALSE); | |
| 793 | |
| 794 return gaim_status_type_is_exclusive(gaim_status_get_type(status)); | |
| 795 } | |
| 796 | |
| 797 gboolean | |
| 9949 | 798 gaim_status_is_available(const GaimStatus *status) |
| 799 { | |
| 800 g_return_val_if_fail(status != NULL, FALSE); | |
| 801 | |
| 802 return gaim_status_type_is_available(gaim_status_get_type(status)); | |
| 803 } | |
| 6216 | 804 |
| 9949 | 805 gboolean |
| 806 gaim_status_is_active(const GaimStatus *status) | |
| 807 { | |
| 808 g_return_val_if_fail(status != NULL, FALSE); | |
| 809 | |
| 810 return status->active; | |
| 811 } | |
| 812 | |
|
10040
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
813 gboolean |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
814 gaim_status_is_online(const GaimStatus *status) |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
815 { |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
816 GaimStatusPrimitive primitive; |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
817 |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
818 g_return_val_if_fail( status != NULL, FALSE); |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
819 |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
820 primitive = gaim_status_type_get_primitive(gaim_status_get_type(status)); |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
821 |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
822 return (primitive != GAIM_STATUS_UNSET && |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
823 primitive != GAIM_STATUS_OFFLINE); |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
824 } |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
825 |
| 9949 | 826 GaimValue * |
| 827 gaim_status_get_attr_value(const GaimStatus *status, const char *id) | |
| 828 { | |
| 829 GaimStatusType *status_type; | |
| 830 GaimStatusAttr *attr; | |
| 831 | |
| 832 g_return_val_if_fail(status != NULL, NULL); | |
| 833 g_return_val_if_fail(id != NULL, NULL); | |
| 834 | |
| 835 status_type = gaim_status_get_type(status); | |
| 836 | |
| 837 /* Make sure this attribute exists. */ | |
| 838 attr = gaim_status_type_get_attr(status_type, id); | |
| 839 g_return_val_if_fail(attr != NULL, NULL); | |
| 840 | |
| 841 return (GaimValue *)g_hash_table_lookup(status->attr_values, id); | |
| 842 } | |
| 843 | |
| 844 gboolean | |
| 845 gaim_status_get_attr_boolean(const GaimStatus *status, const char *id) | |
| 846 { | |
| 847 const GaimValue *value; | |
| 848 | |
| 849 g_return_val_if_fail(status != NULL, FALSE); | |
| 850 g_return_val_if_fail(id != NULL, FALSE); | |
| 851 | |
| 852 if ((value = gaim_status_get_attr_value(status, id)) == NULL) | |
| 853 return FALSE; | |
| 854 | |
| 10197 | 855 g_return_val_if_fail(gaim_value_get_type(value) == GAIM_TYPE_BOOLEAN, FALSE); |
| 9949 | 856 |
| 857 return gaim_value_get_boolean(value); | |
| 858 } | |
| 859 | |
| 860 int | |
| 861 gaim_status_get_attr_int(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_INT, 0); | |
| 872 | |
| 873 return gaim_value_get_int(value); | |
| 874 } | |
| 875 | |
| 876 const char * | |
| 877 gaim_status_get_attr_string(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_STRING, NULL); | |
| 888 | |
| 889 return gaim_value_get_string(value); | |
| 890 } | |
| 891 | |
| 892 gint | |
| 893 gaim_status_compare(const GaimStatus *status1, const GaimStatus *status2) | |
| 894 { | |
| 895 GaimStatusType *type1, *type2; | |
| 896 int score1 = 0, score2 = 0; | |
| 6065 | 897 |
| 9949 | 898 if ((status1 == NULL && status2 == NULL) || |
| 899 (status1 == status2)) | |
| 900 { | |
| 901 return 0; | |
| 902 } | |
| 903 else if (status1 == NULL) | |
| 904 return 1; | |
| 905 else if (status2 == NULL) | |
| 906 return -1; | |
| 907 | |
| 908 type1 = gaim_status_get_type(status1); | |
| 909 type2 = gaim_status_get_type(status2); | |
| 910 | |
| 911 if (gaim_status_is_active(status1)) | |
| 912 score1 = primitive_scores[gaim_status_type_get_primitive(type1)]; | |
| 913 | |
| 914 if (gaim_status_is_active(status2)) | |
| 915 score2 = primitive_scores[gaim_status_type_get_primitive(type2)]; | |
| 916 | |
| 917 if (score1 > score2) | |
| 918 return -1; | |
| 919 else if (score1 < score2) | |
| 920 return 1; | |
| 921 | |
| 922 return 0; | |
| 923 } | |
| 924 | |
| 925 | |
| 926 /************************************************************************** | |
| 927 * GaimPresence API | |
| 928 **************************************************************************/ | |
| 929 GaimPresence * | |
| 930 gaim_presence_new(GaimPresenceContext context) | |
| 931 { | |
| 932 GaimPresence *presence; | |
| 933 | |
| 934 g_return_val_if_fail(context != GAIM_PRESENCE_CONTEXT_UNSET, NULL); | |
| 935 | |
| 936 presence = g_new0(GaimPresence, 1); | |
| 937 | |
| 938 presence->context = context; | |
| 939 | |
| 940 presence->status_table = | |
| 10009 | 941 g_hash_table_new_full(g_str_hash, g_str_equal, |
| 942 g_free, (GFreeFunc)gaim_status_destroy); | |
| 9949 | 943 |
| 944 return presence; | |
| 945 } | |
| 946 | |
| 947 GaimPresence * | |
| 948 gaim_presence_new_for_account(GaimAccount *account) | |
| 949 { | |
| 10012 | 950 GaimPresence *presence = NULL; |
| 9949 | 951 g_return_val_if_fail(account != NULL, NULL); |
| 952 | |
| 953 presence = gaim_presence_new(GAIM_PRESENCE_CONTEXT_ACCOUNT); | |
| 954 presence->u.account = account; | |
| 10006 | 955 presence->statuses = gaim_prpl_get_statuses(account, presence); |
| 9949 | 956 |
| 957 return presence; | |
| 958 } | |
| 959 | |
| 960 GaimPresence * | |
| 961 gaim_presence_new_for_conv(GaimConversation *conv) | |
| 962 { | |
| 963 GaimPresence *presence; | |
| 964 | |
| 965 g_return_val_if_fail(conv != NULL, NULL); | |
| 966 | |
| 967 presence = gaim_presence_new(GAIM_PRESENCE_CONTEXT_CONV); | |
| 968 presence->u.chat.conv = conv; | |
| 10006 | 969 /* presence->statuses = gaim_prpl_get_statuses(conv->account, presence); ? */ |
| 9949 | 970 |
| 971 return presence; | |
| 972 } | |
| 6216 | 973 |
| 9949 | 974 GaimPresence * |
| 975 gaim_presence_new_for_buddy(GaimBuddy *buddy) | |
| 976 { | |
| 977 GaimPresence *presence; | |
| 978 GaimStatusBuddyKey *key; | |
| 10006 | 979 GaimAccount *account; |
| 9949 | 980 |
| 981 g_return_val_if_fail(buddy != NULL, NULL); | |
| 10012 | 982 account = buddy->account; |
| 9949 | 983 |
| 10006 | 984 account = buddy->account; |
| 985 | |
| 9949 | 986 key = g_new0(GaimStatusBuddyKey, 1); |
| 987 key->account = buddy->account; | |
| 988 key->name = g_strdup(buddy->name); | |
| 10006 | 989 |
| 990 presence = g_hash_table_lookup(buddy_presences, key); | |
| 991 if (presence == NULL) | |
| 9949 | 992 { |
| 993 presence = gaim_presence_new(GAIM_PRESENCE_CONTEXT_BUDDY); | |
| 994 | |
| 995 presence->u.buddy.name = g_strdup(buddy->name); | |
| 996 presence->u.buddy.account = buddy->account; | |
| 10006 | 997 presence->statuses = gaim_prpl_get_statuses(buddy->account, presence); |
| 9949 | 998 |
| 999 g_hash_table_insert(buddy_presences, key, presence); | |
| 1000 } | |
| 1001 else | |
| 1002 { | |
| 1003 g_free(key->name); | |
| 1004 g_free(key); | |
| 1005 } | |
| 1006 | |
| 1007 presence->u.buddy.ref_count++; | |
| 1008 presence->u.buddy.buddies = g_list_append(presence->u.buddy.buddies, | |
| 1009 buddy); | |
| 1010 | |
| 1011 return presence; | |
| 1012 } | |
| 1013 | |
| 1014 void | |
| 1015 gaim_presence_destroy(GaimPresence *presence) | |
| 1016 { | |
| 1017 g_return_if_fail(presence != NULL); | |
| 6216 | 1018 |
| 9949 | 1019 if (gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_BUDDY) |
| 1020 { | |
| 1021 GaimStatusBuddyKey key; | |
| 1022 | |
| 1023 presence->u.buddy.ref_count--; | |
| 1024 | |
| 10077 | 1025 if(presence->u.buddy.ref_count != 0) |
| 1026 return; | |
| 9949 | 1027 |
| 1028 key.account = presence->u.buddy.account; | |
| 1029 key.name = presence->u.buddy.name; | |
| 1030 | |
| 1031 g_hash_table_remove(buddy_presences, &key); | |
| 1032 | |
| 1033 if (presence->u.buddy.name != NULL) | |
| 1034 g_free(presence->u.buddy.name); | |
| 1035 } | |
| 1036 else if (gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_CONV) | |
| 1037 { | |
| 1038 if (presence->u.chat.user != NULL) | |
| 1039 g_free(presence->u.chat.user); | |
| 1040 } | |
| 1041 | |
| 1042 if (presence->statuses != NULL) | |
| 1043 g_list_free(presence->statuses); | |
| 1044 | |
| 1045 g_hash_table_destroy(presence->status_table); | |
| 1046 | |
| 1047 g_free(presence); | |
| 1048 } | |
| 1049 | |
| 1050 void | |
| 1051 gaim_presence_remove_buddy(GaimPresence *presence, GaimBuddy *buddy) | |
| 1052 { | |
| 1053 g_return_if_fail(presence != NULL); | |
| 1054 g_return_if_fail(buddy != NULL); | |
| 1055 g_return_if_fail(gaim_presence_get_context(presence) == | |
| 1056 GAIM_PRESENCE_CONTEXT_BUDDY); | |
| 1057 | |
| 1058 if (g_list_find(presence->u.buddy.buddies, buddy) != NULL) | |
| 1059 { | |
| 1060 presence->u.buddy.buddies = g_list_remove(presence->u.buddy.buddies, | |
| 1061 buddy); | |
| 1062 presence->u.buddy.ref_count--; | |
| 1063 } | |
| 6065 | 1064 } |
| 1065 | |
| 9949 | 1066 void |
| 1067 gaim_presence_add_status(GaimPresence *presence, GaimStatus *status) | |
| 1068 { | |
| 1069 g_return_if_fail(presence != NULL); | |
| 1070 g_return_if_fail(status != NULL); | |
| 1071 | |
| 1072 presence->statuses = g_list_append(presence->statuses, status); | |
| 1073 | |
| 1074 g_hash_table_insert(presence->status_table, | |
| 1075 g_strdup(gaim_status_get_id(status)), status); | |
| 1076 } | |
| 1077 | |
| 1078 void | |
| 1079 gaim_presence_add_presence(GaimPresence *presence, const GList *source_list) | |
| 1080 { | |
| 1081 const GList *l; | |
| 1082 | |
| 1083 g_return_if_fail(presence != NULL); | |
| 1084 g_return_if_fail(source_list != NULL); | |
| 1085 | |
| 1086 for (l = source_list; l != NULL; l = l->next) | |
| 1087 gaim_presence_add_status(presence, (GaimStatus *)l->data); | |
| 1088 } | |
| 1089 | |
| 10153 | 1090 /* |
| 1091 * TODO: Should we g_return_if_fail(active == status_id->active); ? | |
| 1092 * | |
| 1093 * TODO: If a buddy signed on or off, should we do any of the following? | |
| 1094 * (Note: We definitely need to do some of this somewhere, I'm just | |
| 1095 * not sure if here is the correct place.) | |
| 1096 * | |
| 1097 * char *tmp = g_strdup_printf(_("%s logged in."), alias); | |
| 1098 * gaim_conversation_write(c, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
| 1099 * g_free(tmp); | |
| 1100 * | |
| 1101 * GaimLog *log = gaim_account_get_log(account); | |
| 1102 * char *tmp = g_strdup_printf(_("%s signed on"), alias); | |
| 1103 * gaim_log_write(log, GAIM_MESSAGE_SYSTEM, (alias ? alias : name), current_time, tmp); | |
| 1104 * g_free(tmp); | |
| 1105 * | |
| 1106 * gaim_sound_play_event(GAIM_SOUND_BUDDY_ARRIVE); | |
| 1107 * | |
| 1108 * char *tmp = g_strdup_printf(_("%s logged out."), alias); | |
| 1109 * gaim_conversation_write(c, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
| 1110 * g_free(tmp); | |
| 1111 * | |
| 1112 * char *tmp = g_strdup_printf(_("%s signed off"), alias); | |
| 1113 * gaim_log_write(log, GAIM_MESSAGE_SYSTEM, (alias ? alias : name), current_time, tmp); | |
| 1114 * g_free(tmp); | |
| 1115 * | |
| 1116 * serv_got_typing_stopped(gc, name); | |
| 1117 * | |
| 1118 * gaim_sound_play_event(GAIM_SOUND_BUDDY_LEAVE); | |
| 1119 * | |
| 1120 * gaim_conversation_update(c, GAIM_CONV_UPDATE_AWAY); | |
| 1121 * | |
| 1122 */ | |
| 9949 | 1123 void |
| 1124 gaim_presence_set_status_active(GaimPresence *presence, const char *status_id, | |
| 1125 gboolean active) | |
| 1126 { | |
| 1127 GaimStatus *status; | |
| 1128 | |
| 1129 g_return_if_fail(presence != NULL); | |
| 1130 g_return_if_fail(status_id != NULL); | |
| 1131 | |
| 1132 status = gaim_presence_get_status(presence, status_id); | |
| 1133 | |
| 1134 g_return_if_fail(status != NULL); | |
| 1135 | |
| 10067 | 1136 if (gaim_status_is_exclusive(status)) |
| 9949 | 1137 { |
| 1138 if (!active) | |
| 1139 { | |
| 1140 gaim_debug_warning("status", | |
| 1141 "Attempted to set a non-independent status " | |
| 1142 "(%s) inactive. Only independent statuses " | |
| 1143 "can be specifically marked inactive.", | |
| 1144 status_id); | |
| 1145 | |
| 1146 return; | |
| 1147 } | |
| 1148 | |
| 10052 | 1149 } else if (presence->active_status != NULL) { |
| 1150 gaim_status_set_active(presence->active_status, FALSE); | |
| 9949 | 1151 |
| 1152 } | |
| 1153 | |
| 1154 gaim_status_set_active(status, active); | |
| 10052 | 1155 presence->active_status = status; |
| 9949 | 1156 } |
| 1157 | |
| 1158 void | |
| 1159 gaim_presence_switch_status(GaimPresence *presence, const char *status_id) | |
| 1160 { | |
| 1161 GaimStatus *status; | |
| 1162 | |
| 1163 g_return_if_fail(presence != NULL); | |
| 1164 g_return_if_fail(status_id != NULL); | |
| 1165 | |
| 1166 status = gaim_presence_get_status(presence, status_id); | |
| 1167 | |
| 1168 g_return_if_fail(status != NULL); | |
| 1169 | |
| 1170 if (gaim_status_is_independent(status)) | |
| 1171 return; | |
| 1172 | |
| 1173 if (presence->active_status != NULL) | |
| 1174 gaim_status_set_active(presence->active_status, FALSE); | |
| 1175 | |
| 1176 gaim_status_set_active(status, TRUE); | |
| 1177 } | |
| 1178 | |
| 1179 static void | |
| 1180 update_buddy_idle(GaimBuddy *buddy, GaimPresence *presence, | |
| 1181 time_t current_time, gboolean old_idle, gboolean idle) | |
| 1182 { | |
| 1183 GaimBlistUiOps *ops = gaim_get_blist()->ui_ops; | |
| 1184 | |
| 1185 if (!old_idle && idle) | |
| 1186 { | |
| 1187 gaim_signal_emit(gaim_blist_get_handle(), "buddy-idle", buddy); | |
| 1188 | |
| 1189 if (gaim_prefs_get_bool("/core/logging/log_system") && | |
| 1190 gaim_prefs_get_bool("/core/logging/log_idle_state")) | |
| 1191 { | |
| 1192 GaimLog *log = gaim_account_get_log(buddy->account); | |
| 1193 char *tmp = g_strdup_printf(_("%s became idle"), | |
| 1194 gaim_buddy_get_alias(buddy)); | |
| 1195 | |
| 1196 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, | |
| 1197 gaim_buddy_get_alias(buddy), current_time, tmp); | |
| 1198 g_free(tmp); | |
| 1199 } | |
| 1200 } | |
| 1201 else if (old_idle && !idle) | |
| 1202 { | |
| 1203 gaim_signal_emit(gaim_blist_get_handle(), "buddy-unidle", 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 unidle"), | |
| 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 | |
| 1218 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); | |
| 1219 | |
| 1220 if (ops != NULL && ops->update != NULL) | |
| 1221 ops->update(gaim_get_blist(), (GaimBlistNode *)buddy); | |
| 1222 } | |
| 1223 | |
| 1224 void | |
| 1225 gaim_presence_set_idle(GaimPresence *presence, gboolean idle, time_t idle_time) | |
| 1226 { | |
| 1227 gboolean old_idle; | |
| 1228 | |
| 1229 g_return_if_fail(presence != NULL); | |
| 1230 | |
| 1231 if (presence->idle == idle && presence->idle_time == idle_time) | |
| 1232 return; | |
| 1233 | |
| 1234 old_idle = presence->idle; | |
| 1235 presence->idle = idle; | |
| 1236 presence->idle_time = (idle ? idle_time : 0); | |
| 1237 | |
| 1238 if (gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_BUDDY) | |
| 1239 { | |
| 1240 const GList *l; | |
| 1241 time_t current_time = time(NULL); | |
| 1242 | |
| 1243 for (l = gaim_presence_get_buddies(presence); l != NULL; l = l->next) | |
| 1244 { | |
| 1245 update_buddy_idle((GaimBuddy *)l->data, presence, current_time, | |
| 1246 old_idle, idle); | |
| 1247 } | |
| 1248 } | |
| 1249 } | |
| 1250 | |
| 1251 void | |
| 10006 | 1252 gaim_presence_set_login_time(GaimPresence *presence, time_t login_time) |
| 1253 { | |
| 1254 g_return_if_fail(presence != NULL); | |
| 1255 | |
| 1256 if (presence->login_time == login_time) | |
| 1257 return; | |
| 1258 | |
| 1259 presence->login_time = login_time; | |
| 1260 } | |
| 1261 | |
| 1262 void | |
| 9949 | 1263 gaim_presence_set_warning_level(GaimPresence *presence, unsigned int level) |
| 6065 | 1264 { |
| 9949 | 1265 g_return_if_fail(presence != NULL); |
| 1266 g_return_if_fail(level <= 100); | |
| 1267 | |
| 1268 if (presence->warning_level == level) | |
| 1269 return; | |
| 1270 | |
| 1271 presence->warning_level = level; | |
| 1272 | |
| 1273 if (gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_BUDDY) | |
| 1274 { | |
| 1275 GaimBlistUiOps *ops = gaim_get_blist()->ui_ops; | |
| 1276 | |
| 1277 if (ops != NULL && ops->update != NULL) | |
| 1278 { | |
| 1279 const GList *l; | |
| 1280 | |
| 1281 for (l = gaim_presence_get_buddies(presence); | |
| 1282 l != NULL; | |
| 1283 l = l->next) | |
| 1284 { | |
| 1285 ops->update(gaim_get_blist(), (GaimBlistNode *)l->data); | |
| 1286 } | |
| 1287 } | |
| 1288 } | |
| 1289 } | |
| 1290 | |
| 1291 GaimPresenceContext | |
| 1292 gaim_presence_get_context(const GaimPresence *presence) | |
| 1293 { | |
| 1294 g_return_val_if_fail(presence != NULL, GAIM_PRESENCE_CONTEXT_UNSET); | |
| 1295 | |
| 1296 return presence->context; | |
| 1297 } | |
| 1298 | |
| 1299 GaimAccount * | |
| 1300 gaim_presence_get_account(const GaimPresence *presence) | |
| 1301 { | |
| 1302 GaimPresenceContext context; | |
| 1303 | |
| 1304 g_return_val_if_fail(presence != NULL, NULL); | |
| 1305 | |
| 1306 context = gaim_presence_get_context(presence); | |
| 1307 | |
| 1308 g_return_val_if_fail(context == GAIM_PRESENCE_CONTEXT_ACCOUNT || | |
| 1309 context == GAIM_PRESENCE_CONTEXT_BUDDY, NULL); | |
| 1310 | |
| 1311 return presence->u.account; | |
| 1312 } | |
| 1313 | |
| 1314 GaimConversation * | |
| 1315 gaim_presence_get_conversation(const GaimPresence *presence) | |
| 1316 { | |
| 1317 g_return_val_if_fail(presence != NULL, NULL); | |
| 1318 g_return_val_if_fail(gaim_presence_get_context(presence) == | |
| 1319 GAIM_PRESENCE_CONTEXT_CONV, NULL); | |
| 1320 | |
| 1321 return presence->u.chat.conv; | |
| 1322 } | |
| 1323 | |
| 1324 const char * | |
| 1325 gaim_presence_get_chat_user(const GaimPresence *presence) | |
| 1326 { | |
| 1327 g_return_val_if_fail(presence != NULL, NULL); | |
| 1328 g_return_val_if_fail(gaim_presence_get_context(presence) == | |
| 1329 GAIM_PRESENCE_CONTEXT_CONV, NULL); | |
| 1330 | |
| 1331 return presence->u.chat.user; | |
| 1332 } | |
| 1333 | |
| 1334 const GList * | |
| 1335 gaim_presence_get_buddies(const GaimPresence *presence) | |
| 1336 { | |
| 1337 g_return_val_if_fail(presence != NULL, NULL); | |
| 1338 g_return_val_if_fail(gaim_presence_get_context(presence) == | |
| 1339 GAIM_PRESENCE_CONTEXT_BUDDY, NULL); | |
| 1340 | |
| 1341 return presence->u.buddy.buddies; | |
| 1342 } | |
| 1343 | |
| 1344 const GList * | |
| 1345 gaim_presence_get_statuses(const GaimPresence *presence) | |
| 1346 { | |
| 1347 g_return_val_if_fail(presence != NULL, NULL); | |
| 1348 | |
| 1349 return presence->statuses; | |
| 1350 } | |
| 1351 | |
| 1352 GaimStatus * | |
| 1353 gaim_presence_get_status(const GaimPresence *presence, const char *status_id) | |
| 1354 { | |
| 1355 GaimStatus *status; | |
| 10006 | 1356 const GList *l = NULL; |
| 9949 | 1357 |
| 1358 g_return_val_if_fail(presence != NULL, NULL); | |
| 1359 g_return_val_if_fail(status_id != NULL, NULL); | |
| 1360 | |
| 10006 | 1361 /* What's the purpose of this hash table? */ |
| 10012 | 1362 status = (GaimStatus *)g_hash_table_lookup(presence->status_table, |
| 10006 | 1363 status_id); |
| 10012 | 1364 |
| 10006 | 1365 if (status == NULL) { |
| 10012 | 1366 for (l = gaim_presence_get_statuses(presence); |
| 10006 | 1367 l != NULL && status == NULL; l = l->next) |
| 1368 { | |
| 1369 GaimStatus *temp_status = l->data; | |
| 10012 | 1370 |
| 10006 | 1371 if (!strcmp(status_id, gaim_status_get_id(temp_status))) |
| 1372 status = temp_status; | |
| 1373 } | |
| 1374 | |
| 1375 if (status != NULL) | |
| 1376 g_hash_table_insert(presence->status_table, | |
| 1377 g_strdup(gaim_status_get_id(status)), status); | |
| 10012 | 1378 } |
| 9949 | 1379 |
| 1380 return status; | |
| 1381 } | |
| 1382 | |
| 1383 GaimStatus * | |
| 1384 gaim_presence_get_active_status(const GaimPresence *presence) | |
| 1385 { | |
| 1386 g_return_val_if_fail(presence != NULL, NULL); | |
| 1387 | |
| 1388 return presence->active_status; | |
| 1389 } | |
| 1390 | |
| 1391 gboolean | |
| 1392 gaim_presence_is_available(const GaimPresence *presence) | |
| 1393 { | |
| 1394 GaimStatus *status; | |
| 1395 | |
| 1396 g_return_val_if_fail(presence != NULL, FALSE); | |
| 1397 | |
| 1398 status = gaim_presence_get_active_status(presence); | |
| 1399 | |
| 1400 return ((status != NULL && gaim_status_is_available(status)) && | |
| 1401 !gaim_presence_is_idle(presence)); | |
| 1402 } | |
| 1403 | |
| 1404 gboolean | |
| 1405 gaim_presence_is_online(const GaimPresence *presence) | |
| 1406 { | |
| 1407 GaimStatus *status; | |
| 1408 | |
| 1409 g_return_val_if_fail(presence != NULL, FALSE); | |
| 1410 | |
| 1411 if ((status = gaim_presence_get_active_status(presence)) == NULL) | |
| 1412 return FALSE; | |
| 1413 | |
|
10040
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
1414 return gaim_status_is_online(status); |
| 9949 | 1415 } |
| 1416 | |
| 1417 gboolean | |
| 1418 gaim_presence_is_status_active(const GaimPresence *presence, | |
| 1419 const char *status_id) | |
| 1420 { | |
| 1421 GaimStatus *status; | |
| 1422 | |
| 1423 g_return_val_if_fail(presence != NULL, FALSE); | |
| 1424 g_return_val_if_fail(status_id != NULL, FALSE); | |
| 1425 | |
| 1426 status = gaim_presence_get_status(presence, status_id); | |
| 1427 | |
| 1428 return (status != NULL && gaim_status_is_active(status)); | |
| 1429 } | |
| 1430 | |
| 1431 gboolean | |
| 1432 gaim_presence_is_status_primitive_active(const GaimPresence *presence, | |
| 1433 GaimStatusPrimitive primitive) | |
| 1434 { | |
| 1435 GaimStatus *status; | |
| 1436 GaimStatusType *status_type; | |
| 1437 | |
| 1438 g_return_val_if_fail(presence != NULL, FALSE); | |
| 1439 g_return_val_if_fail(primitive != GAIM_STATUS_UNSET, FALSE); | |
| 1440 | |
| 1441 status = gaim_presence_get_active_status(presence); | |
| 1442 status_type = gaim_status_get_type(status); | |
| 1443 | |
| 1444 if (gaim_status_type_get_primitive(status_type) == primitive) | |
| 1445 return TRUE; | |
| 6065 | 1446 |
| 1447 return FALSE; | |
| 1448 } | |
| 1449 | |
| 9949 | 1450 gboolean |
| 1451 gaim_presence_is_idle(const GaimPresence *presence) | |
| 6065 | 1452 { |
| 9949 | 1453 g_return_val_if_fail(presence != NULL, FALSE); |
| 1454 | |
| 1455 return presence->idle; | |
| 6065 | 1456 } |
| 1457 | |
| 9949 | 1458 time_t |
| 1459 gaim_presence_get_idle_time(const GaimPresence *presence) | |
| 6065 | 1460 { |
| 9949 | 1461 g_return_val_if_fail(presence != NULL, 0); |
| 6065 | 1462 |
| 9949 | 1463 return presence->idle_time; |
| 1464 } | |
| 6065 | 1465 |
| 9949 | 1466 unsigned int |
| 1467 gaim_presence_get_warning_level(const GaimPresence *presence) | |
| 1468 { | |
| 1469 g_return_val_if_fail(presence != NULL, 0); | |
| 6216 | 1470 |
| 9949 | 1471 return presence->warning_level; |
| 6065 | 1472 } |
| 1473 | |
| 9949 | 1474 gint |
| 1475 gaim_presence_compare(const GaimPresence *presence1, | |
| 1476 const GaimPresence *presence2) | |
| 6065 | 1477 { |
| 9949 | 1478 gboolean idle1, idle2; |
| 1479 size_t idle_time_1, idle_time_2; | |
| 1480 int score1 = 0, score2 = 0; | |
| 1481 const GList *l; | |
| 6065 | 1482 |
| 9949 | 1483 if ((presence1 == NULL && presence2 == NULL) || (presence1 == presence2)) |
| 1484 return 0; | |
| 1485 else if (presence1 == NULL) | |
|
10151
d83e6f2125b1
[gaim-migrate @ 11228]
Christian Hammond <chipx86@chipx86.com>
parents:
10087
diff
changeset
|
1486 return 1; |
| 9949 | 1487 else if (presence2 == NULL) |
|
10151
d83e6f2125b1
[gaim-migrate @ 11228]
Christian Hammond <chipx86@chipx86.com>
parents:
10087
diff
changeset
|
1488 return -1; |
| 6065 | 1489 |
| 9949 | 1490 /* Compute the score of the first set of statuses. */ |
| 1491 for (l = gaim_presence_get_statuses(presence1); l != NULL; l = l->next) | |
| 1492 { | |
| 1493 GaimStatus *status = (GaimStatus *)l->data; | |
| 1494 GaimStatusType *type = gaim_status_get_type(status); | |
| 6065 | 1495 |
| 9949 | 1496 if (gaim_status_is_active(status)) |
| 1497 score1 += primitive_scores[gaim_status_type_get_primitive(type)]; | |
| 6065 | 1498 } |
| 1499 | |
| 9949 | 1500 /* Compute the score of the second set of statuses. */ |
|
10151
d83e6f2125b1
[gaim-migrate @ 11228]
Christian Hammond <chipx86@chipx86.com>
parents:
10087
diff
changeset
|
1501 for (l = gaim_presence_get_statuses(presence2); l != NULL; l = l->next) |
| 9949 | 1502 { |
| 1503 GaimStatus *status = (GaimStatus *)l->data; | |
| 1504 GaimStatusType *type = gaim_status_get_type(status); | |
| 6065 | 1505 |
| 9949 | 1506 if (gaim_status_is_active(status)) |
| 1507 score2 += primitive_scores[gaim_status_type_get_primitive(type)]; | |
| 6065 | 1508 } |
| 1509 | |
| 9949 | 1510 idle1 = gaim_presence_is_idle(presence1); |
| 1511 idle2 = gaim_presence_is_idle(presence2); | |
| 6065 | 1512 |
| 9949 | 1513 if (idle1) |
| 1514 score1 += primitive_scores[SCORE_IDLE]; | |
| 6065 | 1515 |
| 9949 | 1516 if (idle2) |
| 1517 score2 += primitive_scores[SCORE_IDLE]; | |
| 6065 | 1518 |
| 9949 | 1519 idle_time_1 = gaim_presence_get_idle_time(presence1); |
| 1520 idle_time_2 = gaim_presence_get_idle_time(presence2); | |
| 6065 | 1521 |
| 9949 | 1522 if (idle_time_1 > idle_time_2) |
| 1523 score1 += primitive_scores[SCORE_IDLE_TIME]; | |
| 1524 else if (idle_time_1 < idle_time_2) | |
| 1525 score2 += primitive_scores[SCORE_IDLE_TIME]; | |
| 6065 | 1526 |
| 9949 | 1527 if (score1 < score2) |
| 1528 return 1; | |
| 1529 else if (score1 > score2) | |
| 1530 return -1; | |
| 1531 | |
| 1532 return 0; | |
| 1533 } | |
| 1534 | |
| 6065 | 1535 |
| 9949 | 1536 /************************************************************************** |
| 1537 * Status subsystem | |
| 1538 **************************************************************************/ | |
| 1539 static void | |
| 1540 score_pref_changed_cb(const char *name, GaimPrefType type, gpointer value, | |
| 1541 gpointer data) | |
| 1542 { | |
| 1543 int index = GPOINTER_TO_INT(data); | |
| 6065 | 1544 |
| 9949 | 1545 primitive_scores[index] = GPOINTER_TO_INT(value); |
| 6065 | 1546 } |
| 1547 | |
| 10012 | 1548 guint |
| 10006 | 1549 gaim_buddy_presences_hash(gconstpointer key) |
| 1550 { | |
| 10012 | 1551 const GaimStatusBuddyKey *me = key; |
| 1552 guint ret; | |
| 1553 char *str; | |
| 1554 | |
| 1555 str = g_strdup_printf("%p%s", me->account, me->name); | |
| 1556 ret = g_str_hash(str); | |
| 1557 g_free(str); | |
| 1558 | |
| 1559 return ret; | |
| 10006 | 1560 } |
| 1561 | |
| 10012 | 1562 gboolean |
| 10006 | 1563 gaim_buddy_presences_equal(gconstpointer a, gconstpointer b) |
| 1564 { | |
| 1565 GaimStatusBuddyKey *key_a = (GaimStatusBuddyKey *)a; | |
| 1566 GaimStatusBuddyKey *key_b = (GaimStatusBuddyKey *)b; | |
| 1567 | |
| 10012 | 1568 if(key_a->account == key_b->account && |
| 1569 !strcmp(key_a->name, key_b->name)) | |
| 10006 | 1570 return TRUE; |
| 1571 else | |
| 1572 return FALSE; | |
| 1573 } | |
| 1574 | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1575 const GList * |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1576 gaim_statuses_get_stored(void) |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1577 { |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1578 return NULL; |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1579 } |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1580 |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1581 GaimStatus * |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1582 gaim_statuses_find_stored(const GaimStatusType *status_type, const char *id) |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1583 { |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1584 return NULL; |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1585 } |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1586 |
| 10087 | 1587 void * |
| 1588 gaim_statuses_get_handle() { | |
| 1589 static int handle; | |
| 1590 | |
| 1591 return &handle; | |
| 1592 } | |
| 1593 | |
| 9949 | 1594 void |
| 1595 gaim_statuses_init(void) | |
| 6065 | 1596 { |
| 10087 | 1597 void *handle = gaim_statuses_get_handle; |
| 1598 | |
| 9949 | 1599 gaim_prefs_add_none("/core/status"); |
| 1600 gaim_prefs_add_none("/core/status/scores"); | |
| 6065 | 1601 |
| 9949 | 1602 gaim_prefs_add_int("/core/status/scores/offline", |
| 1603 primitive_scores[GAIM_STATUS_OFFLINE]); | |
| 1604 gaim_prefs_add_int("/core/status/scores/available", | |
| 1605 primitive_scores[GAIM_STATUS_AVAILABLE]); | |
| 1606 gaim_prefs_add_int("/core/status/scores/hidden", | |
| 1607 primitive_scores[GAIM_STATUS_HIDDEN]); | |
| 1608 gaim_prefs_add_int("/core/status/scores/away", | |
| 1609 primitive_scores[GAIM_STATUS_AWAY]); | |
| 1610 gaim_prefs_add_int("/core/status/scores/extended_away", | |
| 1611 primitive_scores[GAIM_STATUS_EXTENDED_AWAY]); | |
| 1612 gaim_prefs_add_int("/core/status/scores/idle", | |
| 1613 primitive_scores[SCORE_IDLE]); | |
| 6065 | 1614 |
| 10087 | 1615 gaim_prefs_connect_callback(handle, "/core/status/scores/offline", |
| 9949 | 1616 score_pref_changed_cb, |
| 1617 GINT_TO_POINTER(GAIM_STATUS_OFFLINE)); | |
| 10087 | 1618 gaim_prefs_connect_callback(handle, "/core/status/scores/available", |
| 9949 | 1619 score_pref_changed_cb, |
| 1620 GINT_TO_POINTER(GAIM_STATUS_AVAILABLE)); | |
| 10087 | 1621 gaim_prefs_connect_callback(handle, "/core/status/scores/hidden", |
| 9949 | 1622 score_pref_changed_cb, |
| 1623 GINT_TO_POINTER(GAIM_STATUS_HIDDEN)); | |
| 10087 | 1624 gaim_prefs_connect_callback(handle, "/core/status/scores/away", |
| 9949 | 1625 score_pref_changed_cb, |
| 1626 GINT_TO_POINTER(GAIM_STATUS_AWAY)); | |
| 10087 | 1627 gaim_prefs_connect_callback(handle, "/core/status/scores/extended_away", |
| 9949 | 1628 score_pref_changed_cb, |
| 1629 GINT_TO_POINTER(GAIM_STATUS_EXTENDED_AWAY)); | |
| 10087 | 1630 gaim_prefs_connect_callback(handle, "/core/status/scores/idle", |
| 9949 | 1631 score_pref_changed_cb, |
| 1632 GINT_TO_POINTER(SCORE_IDLE)); | |
| 10006 | 1633 |
| 1634 buddy_presences = g_hash_table_new(gaim_buddy_presences_hash, | |
| 1635 gaim_buddy_presences_equal); | |
| 9949 | 1636 } |
| 6065 | 1637 |
| 9949 | 1638 void |
| 1639 gaim_statuses_uninit(void) | |
| 1640 { | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1641 if (buddy_presences != NULL) |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1642 { |
| 10077 | 1643 g_hash_table_destroy(buddy_presences); |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1644 |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1645 buddy_presences = NULL; |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1646 } |
| 9949 | 1647 } |
| 6065 | 1648 |
| 9949 | 1649 void |
| 1650 gaim_statuses_sync(void) | |
| 1651 { | |
| 6065 | 1652 } |
| 9949 | 1653 |
| 1654 void | |
| 1655 gaim_statuses_load(void) | |
| 1656 { | |
| 1657 } |
