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