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