Mercurial > pidgin
annotate src/status.c @ 13515:f5d4300aeed8
[gaim-migrate @ 15891]
Fix sf bug #1443092, Events logging not working properly?
"signed on" and "signed off" for people in your buddy list
are now correctly logged to the system log.
Richard, someone had already left a note in this function
to make a change after the string freeze (I think it was
you). We should still make a change after the string freeze,
but the change is different now than it was before this commit.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Wed, 15 Mar 2006 04:41:44 +0000 |
| parents | 702107dd58f1 |
| children | 207f974ca030 |
| 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 | |
| 13515 | 619 if ((old_status != NULL) && |
| 620 !gaim_status_is_online(old_status) && | |
| 621 gaim_status_is_online(new_status)) | |
| 9949 | 622 { |
| 13515 | 623 tmp = g_strdup_printf(_("%s signed on"), buddy_alias); |
| 9949 | 624 } |
| 13515 | 625 else if ((old_status != NULL) && |
| 626 gaim_status_is_online(old_status) && | |
| 627 !gaim_status_is_online(new_status)) | |
| 9949 | 628 { |
| 13515 | 629 tmp = g_strdup_printf(_("%s signed off"), buddy_alias); |
| 9949 | 630 } |
| 13515 | 631 else if (((old_status == NULL) || !gaim_status_is_available(old_status)) && |
| 632 gaim_status_is_available(new_status)) | |
|
13506
c358be635301
[gaim-migrate @ 15882]
Richard Laager <rlaager@wiktel.com>
parents:
13373
diff
changeset
|
633 { |
| 13515 | 634 tmp = g_strdup_printf(_("%s came back"), buddy_alias); |
| 635 } | |
| 636 else if (((old_status == NULL) || gaim_status_is_available(old_status)) && | |
| 637 !gaim_status_is_available(new_status)) | |
| 638 { | |
|
13506
c358be635301
[gaim-migrate @ 15882]
Richard Laager <rlaager@wiktel.com>
parents:
13373
diff
changeset
|
639 tmp = g_strdup_printf(_("%s went away"), buddy_alias); |
|
c358be635301
[gaim-migrate @ 15882]
Richard Laager <rlaager@wiktel.com>
parents:
13373
diff
changeset
|
640 } |
| 9949 | 641 |
| 13515 | 642 /* After the string freeze, get rid of the above crap and use this. */ |
| 643 /* | |
| 644 tmp = g_strdup_printf(_("%s is now %s"), buddy_alias, | |
| 645 gaim_status_get_name(new_status)); | |
| 646 */ | |
| 647 | |
| 9949 | 648 if (tmp != NULL) |
| 649 { | |
|
13507
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
650 GaimLog *log = gaim_account_get_log(buddy->account, FALSE); |
| 9949 | 651 |
|
13507
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
652 if (log != NULL) |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
653 { |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
654 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, buddy_alias, |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
655 current_time, tmp); |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
656 } |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
657 |
| 9949 | 658 g_free(tmp); |
| 659 } | |
| 660 } | |
| 661 | |
| 10012 | 662 if (ops != NULL && ops->update != NULL) |
| 663 ops->update(gaim_get_blist(), (GaimBlistNode*)buddy); | |
| 9949 | 664 } |
| 665 | |
| 666 static void | |
| 667 notify_status_update(GaimPresence *presence, GaimStatus *old_status, | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
668 GaimStatus *new_status) |
| 6065 | 669 { |
| 9949 | 670 GaimPresenceContext context = gaim_presence_get_context(presence); |
| 671 | |
| 672 if (context == GAIM_PRESENCE_CONTEXT_ACCOUNT) | |
| 673 { | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
674 GaimAccount *account = gaim_presence_get_account(presence); |
| 9949 | 675 GaimAccountUiOps *ops = gaim_accounts_get_ui_ops(); |
| 676 | |
| 10400 | 677 if (gaim_account_get_enabled(account, gaim_core_get_ui())) |
| 10447 | 678 gaim_prpl_change_account_status(account, old_status, new_status); |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
679 |
| 9949 | 680 if (ops != NULL && ops->status_changed != NULL) |
| 681 { | |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
682 ops->status_changed(account, new_status); |
| 9949 | 683 } |
| 684 } | |
| 685 else if (context == GAIM_PRESENCE_CONTEXT_BUDDY) | |
| 686 { | |
| 687 const GList *l; | |
| 688 | |
| 689 for (l = gaim_presence_get_buddies(presence); l != NULL; l = l->next) | |
| 690 { | |
| 691 notify_buddy_status_update((GaimBuddy *)l->data, presence, | |
| 692 old_status, new_status); | |
| 693 } | |
| 694 } | |
| 695 } | |
| 696 | |
| 10204 | 697 static void |
| 698 status_has_changed(GaimStatus *status) | |
| 9949 | 699 { |
| 700 GaimPresence *presence; | |
| 701 GaimStatus *old_status; | |
| 702 | |
| 703 presence = gaim_status_get_presence(status); | |
| 704 | |
| 10204 | 705 /* |
| 706 * If this status is exclusive, then we must be setting it to "active." | |
| 707 * Since we are setting it to active, we want to set the currently | |
| 708 * active status to "inactive." | |
| 709 */ | |
| 710 if (gaim_status_is_exclusive(status)) | |
| 9949 | 711 { |
| 10754 | 712 old_status = gaim_presence_get_active_status(presence); |
| 10760 | 713 if (old_status != NULL && (old_status != status)) |
| 10754 | 714 old_status->active = FALSE; |
| 715 presence->active_status = status; | |
| 9949 | 716 } |
| 10754 | 717 else |
| 718 old_status = NULL; | |
| 9949 | 719 |
| 10204 | 720 notify_status_update(presence, old_status, status); |
| 721 } | |
| 722 | |
| 723 void | |
| 724 gaim_status_set_active(GaimStatus *status, gboolean active) | |
| 725 { | |
| 13192 | 726 gaim_status_set_active_with_attrs_list(status, active, NULL); |
| 10204 | 727 } |
| 728 | |
| 11249 | 729 /* |
| 730 * This used to parse the va_list directly, but now it creates a GList | |
| 731 * and passes it to gaim_status_set_active_with_attrs_list(). That | |
| 732 * function was created because accounts.c needs to pass a GList of | |
| 733 * attributes to the status API. | |
| 734 */ | |
| 10204 | 735 void |
| 736 gaim_status_set_active_with_attrs(GaimStatus *status, gboolean active, va_list args) | |
| 737 { | |
| 11249 | 738 GList *attrs = NULL; |
| 739 const gchar *id; | |
| 740 gpointer data; | |
| 741 | |
| 742 if (args != NULL) | |
| 743 { | |
| 744 while ((id = va_arg(args, const char *)) != NULL) | |
| 745 { | |
| 746 attrs = g_list_append(attrs, (char *)id); | |
| 747 data = va_arg(args, void *); | |
| 748 attrs = g_list_append(attrs, data); | |
| 749 } | |
| 750 } | |
| 751 gaim_status_set_active_with_attrs_list(status, active, attrs); | |
| 752 g_list_free(attrs); | |
| 753 } | |
| 754 | |
| 755 void | |
| 756 gaim_status_set_active_with_attrs_list(GaimStatus *status, gboolean active, | |
| 757 const GList *attrs) | |
| 758 { | |
| 10204 | 759 gboolean changed = FALSE; |
| 13373 | 760 const GList *l; |
| 761 GList *specified_attr_ids = NULL; | |
| 762 GaimStatusType *status_type; | |
| 10204 | 763 |
| 10714 | 764 g_return_if_fail(status != NULL); |
| 765 | |
| 10204 | 766 if (!active && gaim_status_is_exclusive(status)) |
| 767 { | |
| 768 gaim_debug_error("status", | |
| 769 "Cannot deactivate an exclusive status (%s).\n", | |
| 770 gaim_status_get_id(status)); | |
| 771 return; | |
| 772 } | |
| 773 | |
| 774 if (status->active != active) | |
| 10738 | 775 { |
| 10204 | 776 changed = TRUE; |
| 10738 | 777 } |
| 10204 | 778 |
| 9949 | 779 status->active = active; |
| 6065 | 780 |
| 10204 | 781 /* Set any attributes */ |
| 13373 | 782 l = attrs; |
| 783 while (l != NULL) | |
| 10204 | 784 { |
| 13373 | 785 const gchar *id; |
| 10204 | 786 GaimValue *value; |
| 11249 | 787 |
| 13373 | 788 id = l->data; |
| 789 l = l->next; | |
| 10204 | 790 value = gaim_status_get_attr_value(status, id); |
| 10713 | 791 if (value == NULL) |
| 792 { | |
| 793 gaim_debug_warning("status", "The attribute \"%s\" on the status \"%s\" is " | |
| 10714 | 794 "not supported.\n", id, status->type->name); |
| 10713 | 795 /* Skip over the data and move on to the next attribute */ |
| 13373 | 796 l = l->next; |
| 10713 | 797 continue; |
| 798 } | |
| 799 | |
| 13373 | 800 specified_attr_ids = g_list_prepend(specified_attr_ids, (gpointer)id); |
| 801 | |
| 10204 | 802 if (value->type == GAIM_TYPE_STRING) |
| 803 { | |
| 13373 | 804 const gchar *string_data = l->data; |
| 805 l = l->next; | |
| 10204 | 806 if (((string_data == NULL) && (value->data.string_data == NULL)) || |
| 807 ((string_data != NULL) && (value->data.string_data != NULL) && | |
| 808 !strcmp(string_data, value->data.string_data))) | |
| 809 { | |
| 810 continue; | |
| 811 } | |
| 812 gaim_status_set_attr_string(status, id, string_data); | |
| 813 changed = TRUE; | |
| 814 } | |
| 815 else if (value->type == GAIM_TYPE_INT) | |
| 816 { | |
| 13373 | 817 int int_data = GPOINTER_TO_INT(l->data); |
| 818 l = l->next; | |
| 10204 | 819 if (int_data == value->data.int_data) |
| 820 continue; | |
| 821 gaim_status_set_attr_int(status, id, int_data); | |
| 822 changed = TRUE; | |
| 823 } | |
| 824 else if (value->type == GAIM_TYPE_BOOLEAN) | |
| 825 { | |
| 13373 | 826 gboolean boolean_data = GPOINTER_TO_INT(l->data); |
| 827 l = l->next; | |
| 10204 | 828 if (boolean_data == value->data.boolean_data) |
| 829 continue; | |
| 13373 | 830 gaim_status_set_attr_boolean(status, id, boolean_data); |
| 10204 | 831 changed = TRUE; |
| 832 } | |
| 833 else | |
| 834 { | |
| 835 /* We don't know what the data is--skip over it */ | |
| 13373 | 836 l = l->next; |
| 10204 | 837 } |
| 838 } | |
| 839 | |
| 13373 | 840 /* Reset any unspecified attributes to their default value */ |
| 841 status_type = gaim_status_get_type(status); | |
| 842 l = gaim_status_type_get_attrs(status_type); | |
| 843 while (l != NULL) | |
| 844 { | |
| 845 GaimStatusAttr *attr; | |
| 846 | |
| 847 attr = l->data; | |
| 848 if (!g_list_find_custom(specified_attr_ids, attr->id, (GCompareFunc)strcmp)) | |
| 849 { | |
| 850 GaimValue *default_value; | |
| 851 default_value = gaim_status_attr_get_value(attr); | |
| 852 if (default_value->type == GAIM_TYPE_STRING) | |
| 853 gaim_status_set_attr_string(status, attr->id, | |
| 854 gaim_value_get_string(default_value)); | |
| 855 else if (default_value->type == GAIM_TYPE_INT) | |
| 856 gaim_status_set_attr_int(status, attr->id, | |
| 857 gaim_value_get_int(default_value)); | |
| 858 else if (default_value->type == GAIM_TYPE_BOOLEAN) | |
| 859 gaim_status_set_attr_boolean(status, attr->id, | |
| 860 gaim_value_get_boolean(default_value)); | |
| 861 changed = TRUE; | |
| 862 } | |
| 863 | |
| 864 l = l->next; | |
| 865 } | |
| 866 g_list_free(specified_attr_ids); | |
| 867 | |
| 10204 | 868 if (!changed) |
| 869 return; | |
| 870 status_has_changed(status); | |
| 9949 | 871 } |
| 872 | |
| 873 void | |
| 874 gaim_status_set_attr_boolean(GaimStatus *status, const char *id, | |
| 875 gboolean value) | |
| 876 { | |
| 877 GaimStatusType *status_type; | |
| 878 GaimValue *attr_value; | |
| 879 | |
| 880 g_return_if_fail(status != NULL); | |
| 881 g_return_if_fail(id != NULL); | |
| 882 | |
| 883 status_type = gaim_status_get_type(status); | |
| 884 | |
| 10197 | 885 /* Make sure this attribute exists and is the correct type. */ |
| 886 attr_value = gaim_status_get_attr_value(status, id); | |
| 887 g_return_if_fail(attr_value != NULL); | |
| 9949 | 888 g_return_if_fail(gaim_value_get_type(attr_value) == GAIM_TYPE_BOOLEAN); |
| 889 | |
| 890 gaim_value_set_boolean(attr_value, value); | |
| 891 } | |
| 892 | |
| 893 void | |
| 894 gaim_status_set_attr_int(GaimStatus *status, const char *id, int value) | |
| 895 { | |
| 896 GaimStatusType *status_type; | |
| 897 GaimValue *attr_value; | |
| 898 | |
| 899 g_return_if_fail(status != NULL); | |
| 900 g_return_if_fail(id != NULL); | |
| 901 | |
| 902 status_type = gaim_status_get_type(status); | |
| 903 | |
| 10197 | 904 /* Make sure this attribute exists and is the correct type. */ |
| 905 attr_value = gaim_status_get_attr_value(status, id); | |
| 906 g_return_if_fail(attr_value != NULL); | |
| 9949 | 907 g_return_if_fail(gaim_value_get_type(attr_value) == GAIM_TYPE_INT); |
| 908 | |
| 909 gaim_value_set_int(attr_value, value); | |
| 6065 | 910 } |
| 911 | |
| 9949 | 912 void |
| 913 gaim_status_set_attr_string(GaimStatus *status, const char *id, | |
| 914 const char *value) | |
| 915 { | |
| 916 GaimStatusType *status_type; | |
| 917 GaimValue *attr_value; | |
| 918 | |
| 919 g_return_if_fail(status != NULL); | |
| 920 g_return_if_fail(id != NULL); | |
| 921 | |
| 922 status_type = gaim_status_get_type(status); | |
| 923 | |
| 10197 | 924 /* Make sure this attribute exists and is the correct type. */ |
| 10196 | 925 attr_value = gaim_status_get_attr_value(status, id); |
| 12434 | 926 /* This used to be g_return_if_fail, but it's failing a LOT, so |
| 927 * let's generate a log error for now. */ | |
| 928 /* g_return_if_fail(attr_value != NULL); */ | |
| 929 if (attr_value == NULL) { | |
| 930 gaim_debug_error("status", | |
| 931 "Attempted to set status attribute '%s' for " | |
| 932 "status '%s', which is not legal. Fix " | |
| 933 "this!\n", id, | |
| 934 gaim_status_type_get_name(gaim_status_get_type(status))); | |
| 935 return; | |
| 936 } | |
| 9949 | 937 g_return_if_fail(gaim_value_get_type(attr_value) == GAIM_TYPE_STRING); |
| 938 | |
| 939 gaim_value_set_string(attr_value, value); | |
| 940 } | |
| 941 | |
| 942 GaimStatusType * | |
| 943 gaim_status_get_type(const GaimStatus *status) | |
| 944 { | |
| 945 g_return_val_if_fail(status != NULL, NULL); | |
| 946 | |
| 947 return status->type; | |
| 948 } | |
| 949 | |
| 950 GaimPresence * | |
| 951 gaim_status_get_presence(const GaimStatus *status) | |
| 6065 | 952 { |
| 9949 | 953 g_return_val_if_fail(status != NULL, NULL); |
| 954 | |
| 955 return status->presence; | |
| 956 } | |
| 957 | |
| 958 const char * | |
| 959 gaim_status_get_id(const GaimStatus *status) | |
| 960 { | |
| 961 g_return_val_if_fail(status != NULL, NULL); | |
| 962 | |
| 963 return gaim_status_type_get_id(gaim_status_get_type(status)); | |
| 964 } | |
| 965 | |
| 966 const char * | |
| 967 gaim_status_get_name(const GaimStatus *status) | |
| 968 { | |
| 969 g_return_val_if_fail(status != NULL, NULL); | |
| 970 | |
| 971 return gaim_status_type_get_name(gaim_status_get_type(status)); | |
| 972 } | |
| 973 | |
| 974 gboolean | |
| 975 gaim_status_is_independent(const GaimStatus *status) | |
| 976 { | |
| 977 g_return_val_if_fail(status != NULL, FALSE); | |
| 978 | |
| 979 return gaim_status_type_is_independent(gaim_status_get_type(status)); | |
| 980 } | |
| 981 | |
| 982 gboolean | |
| 10067 | 983 gaim_status_is_exclusive(const GaimStatus *status) |
| 984 { | |
| 985 g_return_val_if_fail(status != NULL, FALSE); | |
| 986 | |
| 987 return gaim_status_type_is_exclusive(gaim_status_get_type(status)); | |
| 988 } | |
| 989 | |
| 990 gboolean | |
| 9949 | 991 gaim_status_is_available(const GaimStatus *status) |
| 992 { | |
| 993 g_return_val_if_fail(status != NULL, FALSE); | |
| 994 | |
| 995 return gaim_status_type_is_available(gaim_status_get_type(status)); | |
| 996 } | |
| 6216 | 997 |
| 9949 | 998 gboolean |
| 999 gaim_status_is_active(const GaimStatus *status) | |
| 1000 { | |
| 1001 g_return_val_if_fail(status != NULL, FALSE); | |
| 1002 | |
| 1003 return status->active; | |
| 1004 } | |
| 1005 | |
|
10040
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
1006 gboolean |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
1007 gaim_status_is_online(const GaimStatus *status) |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
1008 { |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
1009 GaimStatusPrimitive primitive; |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
1010 |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
1011 g_return_val_if_fail( status != NULL, FALSE); |
|
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 primitive = gaim_status_type_get_primitive(gaim_status_get_type(status)); |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
1014 |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
1015 return (primitive != GAIM_STATUS_UNSET && |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
1016 primitive != GAIM_STATUS_OFFLINE); |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
1017 } |
|
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
1018 |
| 9949 | 1019 GaimValue * |
| 1020 gaim_status_get_attr_value(const GaimStatus *status, const char *id) | |
| 1021 { | |
| 1022 g_return_val_if_fail(status != NULL, NULL); | |
| 1023 g_return_val_if_fail(id != NULL, NULL); | |
| 1024 | |
| 1025 return (GaimValue *)g_hash_table_lookup(status->attr_values, id); | |
| 1026 } | |
| 1027 | |
| 1028 gboolean | |
| 1029 gaim_status_get_attr_boolean(const GaimStatus *status, const char *id) | |
| 1030 { | |
| 1031 const GaimValue *value; | |
| 1032 | |
| 1033 g_return_val_if_fail(status != NULL, FALSE); | |
| 1034 g_return_val_if_fail(id != NULL, FALSE); | |
| 1035 | |
| 1036 if ((value = gaim_status_get_attr_value(status, id)) == NULL) | |
| 1037 return FALSE; | |
| 1038 | |
| 10197 | 1039 g_return_val_if_fail(gaim_value_get_type(value) == GAIM_TYPE_BOOLEAN, FALSE); |
| 9949 | 1040 |
| 1041 return gaim_value_get_boolean(value); | |
| 1042 } | |
| 1043 | |
| 1044 int | |
| 1045 gaim_status_get_attr_int(const GaimStatus *status, const char *id) | |
| 1046 { | |
| 1047 const GaimValue *value; | |
| 1048 | |
| 10507 | 1049 g_return_val_if_fail(status != NULL, 0); |
| 1050 g_return_val_if_fail(id != NULL, 0); | |
| 9949 | 1051 |
| 1052 if ((value = gaim_status_get_attr_value(status, id)) == NULL) | |
| 10507 | 1053 return 0; |
| 9949 | 1054 |
| 1055 g_return_val_if_fail(gaim_value_get_type(value) == GAIM_TYPE_INT, 0); | |
| 1056 | |
| 1057 return gaim_value_get_int(value); | |
| 1058 } | |
| 1059 | |
| 1060 const char * | |
| 1061 gaim_status_get_attr_string(const GaimStatus *status, const char *id) | |
| 1062 { | |
| 1063 const GaimValue *value; | |
| 1064 | |
| 10507 | 1065 g_return_val_if_fail(status != NULL, NULL); |
| 1066 g_return_val_if_fail(id != NULL, NULL); | |
| 9949 | 1067 |
| 1068 if ((value = gaim_status_get_attr_value(status, id)) == NULL) | |
| 10504 | 1069 return NULL; |
| 9949 | 1070 |
| 1071 g_return_val_if_fail(gaim_value_get_type(value) == GAIM_TYPE_STRING, NULL); | |
| 1072 | |
| 1073 return gaim_value_get_string(value); | |
| 1074 } | |
| 1075 | |
| 1076 gint | |
| 1077 gaim_status_compare(const GaimStatus *status1, const GaimStatus *status2) | |
| 1078 { | |
| 1079 GaimStatusType *type1, *type2; | |
| 1080 int score1 = 0, score2 = 0; | |
| 6065 | 1081 |
| 9949 | 1082 if ((status1 == NULL && status2 == NULL) || |
| 1083 (status1 == status2)) | |
| 1084 { | |
| 1085 return 0; | |
| 1086 } | |
| 1087 else if (status1 == NULL) | |
| 1088 return 1; | |
| 1089 else if (status2 == NULL) | |
| 1090 return -1; | |
| 1091 | |
| 1092 type1 = gaim_status_get_type(status1); | |
| 1093 type2 = gaim_status_get_type(status2); | |
| 1094 | |
| 1095 if (gaim_status_is_active(status1)) | |
| 1096 score1 = primitive_scores[gaim_status_type_get_primitive(type1)]; | |
| 1097 | |
| 1098 if (gaim_status_is_active(status2)) | |
| 1099 score2 = primitive_scores[gaim_status_type_get_primitive(type2)]; | |
| 1100 | |
| 1101 if (score1 > score2) | |
| 1102 return -1; | |
| 1103 else if (score1 < score2) | |
| 1104 return 1; | |
| 1105 | |
| 1106 return 0; | |
| 1107 } | |
| 1108 | |
| 1109 | |
| 1110 /************************************************************************** | |
| 1111 * GaimPresence API | |
| 1112 **************************************************************************/ | |
| 1113 GaimPresence * | |
| 1114 gaim_presence_new(GaimPresenceContext context) | |
| 1115 { | |
| 1116 GaimPresence *presence; | |
| 1117 | |
| 1118 g_return_val_if_fail(context != GAIM_PRESENCE_CONTEXT_UNSET, NULL); | |
| 1119 | |
| 1120 presence = g_new0(GaimPresence, 1); | |
| 11187 | 1121 GAIM_DBUS_REGISTER_POINTER(presence, GaimPresence); |
| 9949 | 1122 |
| 1123 presence->context = context; | |
| 1124 | |
| 1125 presence->status_table = | |
| 10009 | 1126 g_hash_table_new_full(g_str_hash, g_str_equal, |
| 11638 | 1127 g_free, NULL); |
| 9949 | 1128 |
| 1129 return presence; | |
| 1130 } | |
| 1131 | |
| 1132 GaimPresence * | |
| 1133 gaim_presence_new_for_account(GaimAccount *account) | |
| 1134 { | |
| 10012 | 1135 GaimPresence *presence = NULL; |
| 9949 | 1136 g_return_val_if_fail(account != NULL, NULL); |
| 1137 | |
| 1138 presence = gaim_presence_new(GAIM_PRESENCE_CONTEXT_ACCOUNT); | |
| 1139 presence->u.account = account; | |
| 10006 | 1140 presence->statuses = gaim_prpl_get_statuses(account, presence); |
| 9949 | 1141 |
| 1142 return presence; | |
| 1143 } | |
| 1144 | |
| 1145 GaimPresence * | |
| 1146 gaim_presence_new_for_conv(GaimConversation *conv) | |
| 1147 { | |
| 1148 GaimPresence *presence; | |
| 1149 | |
| 1150 g_return_val_if_fail(conv != NULL, NULL); | |
| 1151 | |
| 1152 presence = gaim_presence_new(GAIM_PRESENCE_CONTEXT_CONV); | |
| 1153 presence->u.chat.conv = conv; | |
| 10006 | 1154 /* presence->statuses = gaim_prpl_get_statuses(conv->account, presence); ? */ |
| 9949 | 1155 |
| 1156 return presence; | |
| 1157 } | |
| 6216 | 1158 |
| 9949 | 1159 GaimPresence * |
| 1160 gaim_presence_new_for_buddy(GaimBuddy *buddy) | |
| 1161 { | |
| 1162 GaimPresence *presence; | |
| 1163 GaimStatusBuddyKey *key; | |
| 10006 | 1164 GaimAccount *account; |
| 9949 | 1165 |
| 1166 g_return_val_if_fail(buddy != NULL, NULL); | |
| 10012 | 1167 account = buddy->account; |
| 9949 | 1168 |
| 1169 key = g_new0(GaimStatusBuddyKey, 1); | |
| 1170 key->account = buddy->account; | |
| 1171 key->name = g_strdup(buddy->name); | |
| 10006 | 1172 |
| 1173 presence = g_hash_table_lookup(buddy_presences, key); | |
| 1174 if (presence == NULL) | |
| 9949 | 1175 { |
| 1176 presence = gaim_presence_new(GAIM_PRESENCE_CONTEXT_BUDDY); | |
| 1177 | |
| 1178 presence->u.buddy.name = g_strdup(buddy->name); | |
| 1179 presence->u.buddy.account = buddy->account; | |
| 10006 | 1180 presence->statuses = gaim_prpl_get_statuses(buddy->account, presence); |
| 9949 | 1181 |
| 1182 g_hash_table_insert(buddy_presences, key, presence); | |
| 1183 } | |
| 1184 else | |
| 1185 { | |
| 1186 g_free(key->name); | |
| 1187 g_free(key); | |
| 1188 } | |
| 1189 | |
| 1190 presence->u.buddy.ref_count++; | |
| 1191 presence->u.buddy.buddies = g_list_append(presence->u.buddy.buddies, | |
| 1192 buddy); | |
| 1193 | |
| 1194 return presence; | |
| 1195 } | |
| 1196 | |
| 1197 void | |
| 1198 gaim_presence_destroy(GaimPresence *presence) | |
| 1199 { | |
| 1200 g_return_if_fail(presence != NULL); | |
| 6216 | 1201 |
| 9949 | 1202 if (gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_BUDDY) |
| 1203 { | |
| 1204 GaimStatusBuddyKey key; | |
| 1205 | |
| 10077 | 1206 if(presence->u.buddy.ref_count != 0) |
| 1207 return; | |
| 9949 | 1208 |
| 1209 key.account = presence->u.buddy.account; | |
| 1210 key.name = presence->u.buddy.name; | |
| 1211 | |
| 1212 g_hash_table_remove(buddy_presences, &key); | |
| 1213 | |
| 1214 if (presence->u.buddy.name != NULL) | |
| 1215 g_free(presence->u.buddy.name); | |
| 1216 } | |
| 1217 else if (gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_CONV) | |
| 1218 { | |
| 1219 if (presence->u.chat.user != NULL) | |
| 1220 g_free(presence->u.chat.user); | |
| 1221 } | |
| 1222 | |
| 11638 | 1223 if (presence->statuses != NULL) { |
| 1224 g_list_foreach(presence->statuses, (GFunc)gaim_status_destroy, NULL); | |
| 9949 | 1225 g_list_free(presence->statuses); |
| 11638 | 1226 } |
| 9949 | 1227 |
| 1228 g_hash_table_destroy(presence->status_table); | |
| 1229 | |
| 11187 | 1230 GAIM_DBUS_UNREGISTER_POINTER(presence); |
| 9949 | 1231 g_free(presence); |
| 1232 } | |
| 1233 | |
| 10580 | 1234 /* |
| 1235 * TODO: Maybe we should cal gaim_presence_destroy() after we | |
| 1236 * decrement the ref count? I don't see why we should | |
| 1237 * make other places do it manually when we can do it here. | |
| 1238 */ | |
| 9949 | 1239 void |
| 1240 gaim_presence_remove_buddy(GaimPresence *presence, GaimBuddy *buddy) | |
| 1241 { | |
| 1242 g_return_if_fail(presence != NULL); | |
| 1243 g_return_if_fail(buddy != NULL); | |
| 1244 g_return_if_fail(gaim_presence_get_context(presence) == | |
| 1245 GAIM_PRESENCE_CONTEXT_BUDDY); | |
| 1246 | |
| 1247 if (g_list_find(presence->u.buddy.buddies, buddy) != NULL) | |
| 1248 { | |
| 1249 presence->u.buddy.buddies = g_list_remove(presence->u.buddy.buddies, | |
| 1250 buddy); | |
| 1251 presence->u.buddy.ref_count--; | |
| 1252 } | |
| 6065 | 1253 } |
| 1254 | |
| 9949 | 1255 void |
| 1256 gaim_presence_add_status(GaimPresence *presence, GaimStatus *status) | |
| 1257 { | |
| 1258 g_return_if_fail(presence != NULL); | |
| 1259 g_return_if_fail(status != NULL); | |
| 1260 | |
| 1261 presence->statuses = g_list_append(presence->statuses, status); | |
| 1262 | |
| 1263 g_hash_table_insert(presence->status_table, | |
| 1264 g_strdup(gaim_status_get_id(status)), status); | |
| 1265 } | |
| 1266 | |
| 1267 void | |
| 11318 | 1268 gaim_presence_add_list(GaimPresence *presence, const GList *source_list) |
| 9949 | 1269 { |
| 1270 const GList *l; | |
| 1271 | |
| 1272 g_return_if_fail(presence != NULL); | |
| 1273 g_return_if_fail(source_list != NULL); | |
| 1274 | |
| 1275 for (l = source_list; l != NULL; l = l->next) | |
| 1276 gaim_presence_add_status(presence, (GaimStatus *)l->data); | |
| 1277 } | |
| 1278 | |
| 1279 void | |
| 1280 gaim_presence_set_status_active(GaimPresence *presence, const char *status_id, | |
| 1281 gboolean active) | |
| 1282 { | |
| 1283 GaimStatus *status; | |
| 1284 | |
| 1285 g_return_if_fail(presence != NULL); | |
| 1286 g_return_if_fail(status_id != NULL); | |
| 1287 | |
| 1288 status = gaim_presence_get_status(presence, status_id); | |
| 1289 | |
| 1290 g_return_if_fail(status != NULL); | |
| 10348 | 1291 /* TODO: Should we do the following? */ |
| 1292 /* g_return_if_fail(active == status->active); */ | |
| 9949 | 1293 |
| 10067 | 1294 if (gaim_status_is_exclusive(status)) |
| 9949 | 1295 { |
| 1296 if (!active) | |
| 1297 { | |
| 1298 gaim_debug_warning("status", | |
| 1299 "Attempted to set a non-independent status " | |
| 1300 "(%s) inactive. Only independent statuses " | |
| 1301 "can be specifically marked inactive.", | |
| 1302 status_id); | |
| 1303 return; | |
| 1304 } | |
| 1305 } | |
| 1306 | |
| 1307 gaim_status_set_active(status, active); | |
| 1308 } | |
| 1309 | |
| 1310 void | |
| 1311 gaim_presence_switch_status(GaimPresence *presence, const char *status_id) | |
| 1312 { | |
| 10754 | 1313 gaim_presence_set_status_active(presence, status_id, TRUE); |
| 9949 | 1314 } |
| 1315 | |
| 1316 static void | |
| 1317 update_buddy_idle(GaimBuddy *buddy, GaimPresence *presence, | |
| 1318 time_t current_time, gboolean old_idle, gboolean idle) | |
| 1319 { | |
| 1320 GaimBlistUiOps *ops = gaim_get_blist()->ui_ops; | |
| 1321 | |
| 1322 if (!old_idle && idle) | |
| 1323 { | |
| 11698 | 1324 if (gaim_prefs_get_bool("/core/logging/log_system")) |
| 9949 | 1325 { |
|
13507
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1326 GaimLog *log = gaim_account_get_log(buddy->account, FALSE); |
| 9949 | 1327 |
|
13507
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1328 if (log != NULL) |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1329 { |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1330 char *tmp = g_strdup_printf(_("%s became idle"), |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1331 gaim_buddy_get_alias(buddy)); |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1332 |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1333 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1334 gaim_buddy_get_alias(buddy), current_time, tmp); |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1335 g_free(tmp); |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1336 } |
| 9949 | 1337 } |
| 1338 } | |
| 1339 else if (old_idle && !idle) | |
| 1340 { | |
| 11698 | 1341 if (gaim_prefs_get_bool("/core/logging/log_system")) |
| 9949 | 1342 { |
|
13507
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1343 GaimLog *log = gaim_account_get_log(buddy->account, FALSE); |
| 9949 | 1344 |
|
13507
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1345 if (log != NULL) |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1346 { |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1347 char *tmp = g_strdup_printf(_("%s became unidle"), |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1348 gaim_buddy_get_alias(buddy)); |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1349 |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1350 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1351 gaim_buddy_get_alias(buddy), current_time, tmp); |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1352 g_free(tmp); |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1353 } |
| 9949 | 1354 } |
| 1355 } | |
| 1356 | |
|
11935
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11905
diff
changeset
|
1357 if (old_idle != idle) |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11905
diff
changeset
|
1358 gaim_signal_emit(gaim_blist_get_handle(), "buddy-idle-changed", buddy, |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11905
diff
changeset
|
1359 old_idle, idle); |
|
cb73483c9f63
[gaim-migrate @ 14226]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11905
diff
changeset
|
1360 |
| 10378 | 1361 gaim_contact_invalidate_priority_buddy(gaim_buddy_get_contact(buddy)); |
| 9949 | 1362 |
|
12015
5a63ea24ac83
[gaim-migrate @ 14308]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11975
diff
changeset
|
1363 /* 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
|
1364 * connect to buddy-[un]idle signals and update from there |
|
5a63ea24ac83
[gaim-migrate @ 14308]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11975
diff
changeset
|
1365 */ |
|
5a63ea24ac83
[gaim-migrate @ 14308]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11975
diff
changeset
|
1366 |
| 9949 | 1367 if (ops != NULL && ops->update != NULL) |
| 1368 ops->update(gaim_get_blist(), (GaimBlistNode *)buddy); | |
| 1369 } | |
| 1370 | |
| 1371 void | |
| 1372 gaim_presence_set_idle(GaimPresence *presence, gboolean idle, time_t idle_time) | |
| 1373 { | |
| 1374 gboolean old_idle; | |
| 1375 | |
| 1376 g_return_if_fail(presence != NULL); | |
| 1377 | |
| 1378 if (presence->idle == idle && presence->idle_time == idle_time) | |
| 1379 return; | |
| 1380 | |
| 1381 old_idle = presence->idle; | |
| 1382 presence->idle = idle; | |
| 1383 presence->idle_time = (idle ? idle_time : 0); | |
| 1384 | |
| 1385 if (gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_BUDDY) | |
| 1386 { | |
| 1387 const GList *l; | |
| 1388 time_t current_time = time(NULL); | |
| 1389 | |
| 1390 for (l = gaim_presence_get_buddies(presence); l != NULL; l = l->next) | |
| 1391 { | |
| 1392 update_buddy_idle((GaimBuddy *)l->data, presence, current_time, | |
| 1393 old_idle, idle); | |
| 1394 } | |
| 1395 } | |
|
11551
78aad676fdb2
[gaim-migrate @ 13806]
Luke Schierer <lschiere@pidgin.im>
parents:
11522
diff
changeset
|
1396 else if(gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_ACCOUNT) |
|
78aad676fdb2
[gaim-migrate @ 13806]
Luke Schierer <lschiere@pidgin.im>
parents:
11522
diff
changeset
|
1397 { |
| 11975 | 1398 GaimAccount *account; |
| 1399 GaimConnection *gc; | |
|
11551
78aad676fdb2
[gaim-migrate @ 13806]
Luke Schierer <lschiere@pidgin.im>
parents:
11522
diff
changeset
|
1400 GaimPluginProtocolInfo *prpl_info = NULL; |
|
78aad676fdb2
[gaim-migrate @ 13806]
Luke Schierer <lschiere@pidgin.im>
parents:
11522
diff
changeset
|
1401 |
| 11975 | 1402 account = gaim_presence_get_account(presence); |
|
12145
5bda6a03d43b
[gaim-migrate @ 14446]
Richard Laager <rlaager@wiktel.com>
parents:
12123
diff
changeset
|
1403 |
|
5bda6a03d43b
[gaim-migrate @ 14446]
Richard Laager <rlaager@wiktel.com>
parents:
12123
diff
changeset
|
1404 if (gaim_prefs_get_bool("/core/logging/log_system")) |
|
5bda6a03d43b
[gaim-migrate @ 14446]
Richard Laager <rlaager@wiktel.com>
parents:
12123
diff
changeset
|
1405 { |
|
13507
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1406 GaimLog *log = gaim_account_get_log(account, FALSE); |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1407 |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1408 if (log != NULL) |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1409 { |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1410 char *msg; |
| 11975 | 1411 |
|
13507
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1412 if (idle) |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1413 msg = g_strdup_printf(_("+++ %s became idle"), gaim_account_get_username(account)); |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1414 else |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1415 msg = g_strdup_printf(_("+++ %s became unidle"), gaim_account_get_username(account)); |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1416 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1417 gaim_account_get_username(account), |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1418 idle_time, msg); |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1419 g_free(msg); |
|
702107dd58f1
[gaim-migrate @ 15883]
Richard Laager <rlaager@wiktel.com>
parents:
13506
diff
changeset
|
1420 } |
|
12145
5bda6a03d43b
[gaim-migrate @ 14446]
Richard Laager <rlaager@wiktel.com>
parents:
12123
diff
changeset
|
1421 } |
| 11975 | 1422 |
| 1423 gc = gaim_account_get_connection(account); | |
| 1424 | |
|
11551
78aad676fdb2
[gaim-migrate @ 13806]
Luke Schierer <lschiere@pidgin.im>
parents:
11522
diff
changeset
|
1425 if (gc != NULL && gc->prpl != NULL) |
|
78aad676fdb2
[gaim-migrate @ 13806]
Luke Schierer <lschiere@pidgin.im>
parents:
11522
diff
changeset
|
1426 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); |
|
78aad676fdb2
[gaim-migrate @ 13806]
Luke Schierer <lschiere@pidgin.im>
parents:
11522
diff
changeset
|
1427 |
|
78aad676fdb2
[gaim-migrate @ 13806]
Luke Schierer <lschiere@pidgin.im>
parents:
11522
diff
changeset
|
1428 if (prpl_info && g_list_find(gaim_connections_get_all(), gc) && |
|
78aad676fdb2
[gaim-migrate @ 13806]
Luke Schierer <lschiere@pidgin.im>
parents:
11522
diff
changeset
|
1429 prpl_info->set_idle) |
|
78aad676fdb2
[gaim-migrate @ 13806]
Luke Schierer <lschiere@pidgin.im>
parents:
11522
diff
changeset
|
1430 prpl_info->set_idle(gc, time(NULL) - idle_time); |
|
78aad676fdb2
[gaim-migrate @ 13806]
Luke Schierer <lschiere@pidgin.im>
parents:
11522
diff
changeset
|
1431 } |
| 9949 | 1432 } |
| 1433 | |
| 1434 void | |
| 10006 | 1435 gaim_presence_set_login_time(GaimPresence *presence, time_t login_time) |
| 1436 { | |
| 1437 g_return_if_fail(presence != NULL); | |
| 1438 | |
| 1439 if (presence->login_time == login_time) | |
| 1440 return; | |
| 1441 | |
| 1442 presence->login_time = login_time; | |
| 1443 } | |
| 1444 | |
| 9949 | 1445 GaimPresenceContext |
| 1446 gaim_presence_get_context(const GaimPresence *presence) | |
| 1447 { | |
| 1448 g_return_val_if_fail(presence != NULL, GAIM_PRESENCE_CONTEXT_UNSET); | |
| 1449 | |
| 1450 return presence->context; | |
| 1451 } | |
| 1452 | |
| 1453 GaimAccount * | |
| 1454 gaim_presence_get_account(const GaimPresence *presence) | |
| 1455 { | |
| 1456 GaimPresenceContext context; | |
| 1457 | |
| 1458 g_return_val_if_fail(presence != NULL, NULL); | |
| 1459 | |
| 1460 context = gaim_presence_get_context(presence); | |
| 1461 | |
| 1462 g_return_val_if_fail(context == GAIM_PRESENCE_CONTEXT_ACCOUNT || | |
| 1463 context == GAIM_PRESENCE_CONTEXT_BUDDY, NULL); | |
| 1464 | |
| 1465 return presence->u.account; | |
| 1466 } | |
| 1467 | |
| 1468 GaimConversation * | |
| 1469 gaim_presence_get_conversation(const GaimPresence *presence) | |
| 1470 { | |
| 1471 g_return_val_if_fail(presence != NULL, NULL); | |
| 1472 g_return_val_if_fail(gaim_presence_get_context(presence) == | |
| 1473 GAIM_PRESENCE_CONTEXT_CONV, NULL); | |
| 1474 | |
| 1475 return presence->u.chat.conv; | |
| 1476 } | |
| 1477 | |
| 1478 const char * | |
| 1479 gaim_presence_get_chat_user(const GaimPresence *presence) | |
| 1480 { | |
| 1481 g_return_val_if_fail(presence != NULL, NULL); | |
| 1482 g_return_val_if_fail(gaim_presence_get_context(presence) == | |
| 1483 GAIM_PRESENCE_CONTEXT_CONV, NULL); | |
| 1484 | |
| 1485 return presence->u.chat.user; | |
| 1486 } | |
| 1487 | |
| 1488 const GList * | |
| 1489 gaim_presence_get_buddies(const GaimPresence *presence) | |
| 1490 { | |
| 1491 g_return_val_if_fail(presence != NULL, NULL); | |
| 1492 g_return_val_if_fail(gaim_presence_get_context(presence) == | |
| 1493 GAIM_PRESENCE_CONTEXT_BUDDY, NULL); | |
| 1494 | |
| 1495 return presence->u.buddy.buddies; | |
| 1496 } | |
| 1497 | |
| 1498 const GList * | |
| 1499 gaim_presence_get_statuses(const GaimPresence *presence) | |
| 1500 { | |
| 1501 g_return_val_if_fail(presence != NULL, NULL); | |
| 1502 | |
| 1503 return presence->statuses; | |
| 1504 } | |
| 1505 | |
| 1506 GaimStatus * | |
| 1507 gaim_presence_get_status(const GaimPresence *presence, const char *status_id) | |
| 1508 { | |
| 1509 GaimStatus *status; | |
| 10006 | 1510 const GList *l = NULL; |
| 9949 | 1511 |
| 1512 g_return_val_if_fail(presence != NULL, NULL); | |
| 1513 g_return_val_if_fail(status_id != NULL, NULL); | |
| 1514 | |
| 10006 | 1515 /* What's the purpose of this hash table? */ |
| 10012 | 1516 status = (GaimStatus *)g_hash_table_lookup(presence->status_table, |
| 10006 | 1517 status_id); |
| 10012 | 1518 |
| 10006 | 1519 if (status == NULL) { |
| 10012 | 1520 for (l = gaim_presence_get_statuses(presence); |
| 10006 | 1521 l != NULL && status == NULL; l = l->next) |
| 1522 { | |
| 1523 GaimStatus *temp_status = l->data; | |
| 10012 | 1524 |
| 10006 | 1525 if (!strcmp(status_id, gaim_status_get_id(temp_status))) |
| 1526 status = temp_status; | |
| 1527 } | |
| 1528 | |
| 1529 if (status != NULL) | |
| 1530 g_hash_table_insert(presence->status_table, | |
| 1531 g_strdup(gaim_status_get_id(status)), status); | |
| 10012 | 1532 } |
| 9949 | 1533 |
| 1534 return status; | |
| 1535 } | |
| 1536 | |
| 1537 GaimStatus * | |
| 1538 gaim_presence_get_active_status(const GaimPresence *presence) | |
| 1539 { | |
| 1540 g_return_val_if_fail(presence != NULL, NULL); | |
| 1541 | |
| 1542 return presence->active_status; | |
| 1543 } | |
| 1544 | |
| 1545 gboolean | |
| 1546 gaim_presence_is_available(const GaimPresence *presence) | |
| 1547 { | |
| 1548 GaimStatus *status; | |
| 1549 | |
| 1550 g_return_val_if_fail(presence != NULL, FALSE); | |
| 1551 | |
| 1552 status = gaim_presence_get_active_status(presence); | |
| 1553 | |
| 1554 return ((status != NULL && gaim_status_is_available(status)) && | |
| 1555 !gaim_presence_is_idle(presence)); | |
| 1556 } | |
| 1557 | |
| 1558 gboolean | |
| 1559 gaim_presence_is_online(const GaimPresence *presence) | |
| 1560 { | |
| 1561 GaimStatus *status; | |
| 1562 | |
| 1563 g_return_val_if_fail(presence != NULL, FALSE); | |
| 1564 | |
| 1565 if ((status = gaim_presence_get_active_status(presence)) == NULL) | |
| 1566 return FALSE; | |
| 1567 | |
|
10040
81059dce3aed
[gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents:
10013
diff
changeset
|
1568 return gaim_status_is_online(status); |
| 9949 | 1569 } |
| 1570 | |
| 1571 gboolean | |
| 1572 gaim_presence_is_status_active(const GaimPresence *presence, | |
| 1573 const char *status_id) | |
| 1574 { | |
| 1575 GaimStatus *status; | |
| 1576 | |
| 1577 g_return_val_if_fail(presence != NULL, FALSE); | |
| 1578 g_return_val_if_fail(status_id != NULL, FALSE); | |
| 1579 | |
| 1580 status = gaim_presence_get_status(presence, status_id); | |
| 1581 | |
| 1582 return (status != NULL && gaim_status_is_active(status)); | |
| 1583 } | |
| 1584 | |
| 1585 gboolean | |
| 1586 gaim_presence_is_status_primitive_active(const GaimPresence *presence, | |
| 1587 GaimStatusPrimitive primitive) | |
| 1588 { | |
| 1589 GaimStatus *status; | |
| 1590 GaimStatusType *status_type; | |
| 1591 | |
| 1592 g_return_val_if_fail(presence != NULL, FALSE); | |
| 1593 g_return_val_if_fail(primitive != GAIM_STATUS_UNSET, FALSE); | |
| 1594 | |
| 1595 status = gaim_presence_get_active_status(presence); | |
| 1596 status_type = gaim_status_get_type(status); | |
| 1597 | |
| 1598 if (gaim_status_type_get_primitive(status_type) == primitive) | |
| 1599 return TRUE; | |
| 6065 | 1600 |
| 1601 return FALSE; | |
| 1602 } | |
| 1603 | |
| 9949 | 1604 gboolean |
| 1605 gaim_presence_is_idle(const GaimPresence *presence) | |
| 6065 | 1606 { |
| 9949 | 1607 g_return_val_if_fail(presence != NULL, FALSE); |
| 1608 | |
| 11634 | 1609 return gaim_presence_is_online(presence) && presence->idle; |
| 6065 | 1610 } |
| 1611 | |
| 9949 | 1612 time_t |
| 1613 gaim_presence_get_idle_time(const GaimPresence *presence) | |
| 6065 | 1614 { |
| 9949 | 1615 g_return_val_if_fail(presence != NULL, 0); |
| 6065 | 1616 |
| 9949 | 1617 return presence->idle_time; |
| 1618 } | |
| 6065 | 1619 |
| 10567 | 1620 time_t |
| 1621 gaim_presence_get_login_time(const GaimPresence *presence) | |
| 1622 { | |
| 1623 g_return_val_if_fail(presence != NULL, 0); | |
| 1624 | |
| 11973 | 1625 return gaim_presence_is_online(presence) ? presence->login_time : 0; |
| 10567 | 1626 } |
| 1627 | |
| 9949 | 1628 gint |
| 1629 gaim_presence_compare(const GaimPresence *presence1, | |
| 1630 const GaimPresence *presence2) | |
| 6065 | 1631 { |
| 9949 | 1632 gboolean idle1, idle2; |
| 10860 | 1633 time_t idle_time_1, idle_time_2; |
| 9949 | 1634 int score1 = 0, score2 = 0; |
| 1635 const GList *l; | |
| 6065 | 1636 |
|
12164
281ab2ecc08c
[gaim-migrate @ 14465]
Richard Laager <rlaager@wiktel.com>
parents:
12145
diff
changeset
|
1637 if (presence1 == presence2) |
| 9949 | 1638 return 0; |
| 1639 else if (presence1 == NULL) | |
|
10151
d83e6f2125b1
[gaim-migrate @ 11228]
Christian Hammond <chipx86@chipx86.com>
parents:
10087
diff
changeset
|
1640 return 1; |
| 9949 | 1641 else if (presence2 == NULL) |
|
10151
d83e6f2125b1
[gaim-migrate @ 11228]
Christian Hammond <chipx86@chipx86.com>
parents:
10087
diff
changeset
|
1642 return -1; |
| 6065 | 1643 |
| 9949 | 1644 /* Compute the score of the first set of statuses. */ |
| 1645 for (l = gaim_presence_get_statuses(presence1); l != NULL; l = l->next) | |
| 1646 { | |
| 1647 GaimStatus *status = (GaimStatus *)l->data; | |
| 1648 GaimStatusType *type = gaim_status_get_type(status); | |
| 6065 | 1649 |
| 9949 | 1650 if (gaim_status_is_active(status)) |
| 1651 score1 += primitive_scores[gaim_status_type_get_primitive(type)]; | |
| 6065 | 1652 } |
|
12164
281ab2ecc08c
[gaim-migrate @ 14465]
Richard Laager <rlaager@wiktel.com>
parents:
12145
diff
changeset
|
1653 score1 += gaim_account_get_int(gaim_presence_get_account(presence1), "score", 0); |
| 6065 | 1654 |
| 9949 | 1655 /* Compute the score of the second set of statuses. */ |
|
10151
d83e6f2125b1
[gaim-migrate @ 11228]
Christian Hammond <chipx86@chipx86.com>
parents:
10087
diff
changeset
|
1656 for (l = gaim_presence_get_statuses(presence2); l != NULL; l = l->next) |
| 9949 | 1657 { |
| 1658 GaimStatus *status = (GaimStatus *)l->data; | |
| 1659 GaimStatusType *type = gaim_status_get_type(status); | |
| 6065 | 1660 |
| 9949 | 1661 if (gaim_status_is_active(status)) |
| 1662 score2 += primitive_scores[gaim_status_type_get_primitive(type)]; | |
| 6065 | 1663 } |
|
12164
281ab2ecc08c
[gaim-migrate @ 14465]
Richard Laager <rlaager@wiktel.com>
parents:
12145
diff
changeset
|
1664 score2 += gaim_account_get_int(gaim_presence_get_account(presence2), "score", 0); |
| 6065 | 1665 |
| 9949 | 1666 idle1 = gaim_presence_is_idle(presence1); |
| 1667 idle2 = gaim_presence_is_idle(presence2); | |
| 6065 | 1668 |
| 9949 | 1669 if (idle1) |
| 1670 score1 += primitive_scores[SCORE_IDLE]; | |
| 6065 | 1671 |
| 9949 | 1672 if (idle2) |
| 1673 score2 += primitive_scores[SCORE_IDLE]; | |
| 6065 | 1674 |
| 10860 | 1675 idle_time_1 = time(NULL) - gaim_presence_get_idle_time(presence1); |
| 1676 idle_time_2 = time(NULL) - gaim_presence_get_idle_time(presence2); | |
| 6065 | 1677 |
| 9949 | 1678 if (idle_time_1 > idle_time_2) |
| 1679 score1 += primitive_scores[SCORE_IDLE_TIME]; | |
| 1680 else if (idle_time_1 < idle_time_2) | |
| 1681 score2 += primitive_scores[SCORE_IDLE_TIME]; | |
| 6065 | 1682 |
| 9949 | 1683 if (score1 < score2) |
| 1684 return 1; | |
| 1685 else if (score1 > score2) | |
| 1686 return -1; | |
| 1687 | |
| 1688 return 0; | |
| 1689 } | |
| 1690 | |
| 6065 | 1691 |
| 9949 | 1692 /************************************************************************** |
| 1693 * Status subsystem | |
| 1694 **************************************************************************/ | |
| 1695 static void | |
| 12816 | 1696 score_pref_changed_cb(const char *name, GaimPrefType type, |
| 1697 gconstpointer value, gpointer data) | |
| 9949 | 1698 { |
| 1699 int index = GPOINTER_TO_INT(data); | |
| 6065 | 1700 |
| 9949 | 1701 primitive_scores[index] = GPOINTER_TO_INT(value); |
| 6065 | 1702 } |
| 1703 | |
| 10519 | 1704 static guint |
| 10006 | 1705 gaim_buddy_presences_hash(gconstpointer key) |
| 1706 { | |
| 10012 | 1707 const GaimStatusBuddyKey *me = key; |
| 1708 guint ret; | |
| 1709 char *str; | |
| 1710 | |
| 1711 str = g_strdup_printf("%p%s", me->account, me->name); | |
| 1712 ret = g_str_hash(str); | |
| 1713 g_free(str); | |
| 1714 | |
| 1715 return ret; | |
| 10006 | 1716 } |
| 1717 | |
| 10519 | 1718 static gboolean |
| 10006 | 1719 gaim_buddy_presences_equal(gconstpointer a, gconstpointer b) |
| 1720 { | |
| 1721 GaimStatusBuddyKey *key_a = (GaimStatusBuddyKey *)a; | |
| 1722 GaimStatusBuddyKey *key_b = (GaimStatusBuddyKey *)b; | |
| 1723 | |
| 10012 | 1724 if(key_a->account == key_b->account && |
| 1725 !strcmp(key_a->name, key_b->name)) | |
| 10006 | 1726 return TRUE; |
| 1727 else | |
| 1728 return FALSE; | |
| 1729 } | |
| 1730 | |
| 10519 | 1731 static void |
| 1732 gaim_buddy_presences_key_free(gpointer a) | |
| 1733 { | |
| 1734 GaimStatusBuddyKey *key = (GaimStatusBuddyKey *)a; | |
| 1735 g_free(key->name); | |
| 1736 g_free(key); | |
| 1737 } | |
| 1738 | |
| 10087 | 1739 void * |
| 10418 | 1740 gaim_status_get_handle(void) { |
| 10087 | 1741 static int handle; |
| 1742 | |
| 1743 return &handle; | |
| 1744 } | |
| 1745 | |
| 9949 | 1746 void |
| 10418 | 1747 gaim_status_init(void) |
| 6065 | 1748 { |
| 10418 | 1749 void *handle = gaim_status_get_handle; |
| 10087 | 1750 |
| 9949 | 1751 gaim_prefs_add_none("/core/status"); |
| 1752 gaim_prefs_add_none("/core/status/scores"); | |
| 6065 | 1753 |
| 9949 | 1754 gaim_prefs_add_int("/core/status/scores/offline", |
| 1755 primitive_scores[GAIM_STATUS_OFFLINE]); | |
| 1756 gaim_prefs_add_int("/core/status/scores/available", | |
| 1757 primitive_scores[GAIM_STATUS_AVAILABLE]); | |
|
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12587
diff
changeset
|
1758 gaim_prefs_add_int("/core/status/scores/invisible", |
|
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12587
diff
changeset
|
1759 primitive_scores[GAIM_STATUS_INVISIBLE]); |
| 9949 | 1760 gaim_prefs_add_int("/core/status/scores/away", |
| 1761 primitive_scores[GAIM_STATUS_AWAY]); | |
| 1762 gaim_prefs_add_int("/core/status/scores/extended_away", | |
| 1763 primitive_scores[GAIM_STATUS_EXTENDED_AWAY]); | |
| 1764 gaim_prefs_add_int("/core/status/scores/idle", | |
| 1765 primitive_scores[SCORE_IDLE]); | |
| 6065 | 1766 |
| 10087 | 1767 gaim_prefs_connect_callback(handle, "/core/status/scores/offline", |
| 9949 | 1768 score_pref_changed_cb, |
| 1769 GINT_TO_POINTER(GAIM_STATUS_OFFLINE)); | |
| 10087 | 1770 gaim_prefs_connect_callback(handle, "/core/status/scores/available", |
| 9949 | 1771 score_pref_changed_cb, |
| 1772 GINT_TO_POINTER(GAIM_STATUS_AVAILABLE)); | |
|
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12587
diff
changeset
|
1773 gaim_prefs_connect_callback(handle, "/core/status/scores/invisible", |
| 9949 | 1774 score_pref_changed_cb, |
|
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12587
diff
changeset
|
1775 GINT_TO_POINTER(GAIM_STATUS_INVISIBLE)); |
| 10087 | 1776 gaim_prefs_connect_callback(handle, "/core/status/scores/away", |
| 9949 | 1777 score_pref_changed_cb, |
| 1778 GINT_TO_POINTER(GAIM_STATUS_AWAY)); | |
| 10087 | 1779 gaim_prefs_connect_callback(handle, "/core/status/scores/extended_away", |
| 9949 | 1780 score_pref_changed_cb, |
| 1781 GINT_TO_POINTER(GAIM_STATUS_EXTENDED_AWAY)); | |
| 10087 | 1782 gaim_prefs_connect_callback(handle, "/core/status/scores/idle", |
| 9949 | 1783 score_pref_changed_cb, |
| 1784 GINT_TO_POINTER(SCORE_IDLE)); | |
| 10006 | 1785 |
| 10519 | 1786 buddy_presences = g_hash_table_new_full(gaim_buddy_presences_hash, |
| 1787 gaim_buddy_presences_equal, | |
| 1788 gaim_buddy_presences_key_free, NULL); | |
| 9949 | 1789 } |
| 6065 | 1790 |
| 9949 | 1791 void |
| 10418 | 1792 gaim_status_uninit(void) |
| 9949 | 1793 { |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1794 if (buddy_presences != NULL) |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1795 { |
| 10077 | 1796 g_hash_table_destroy(buddy_presences); |
|
10176
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1797 |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1798 buddy_presences = NULL; |
|
0109f3a518d2
[gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents:
10153
diff
changeset
|
1799 } |
| 9949 | 1800 } |
