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