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