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