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