annotate src/status.c @ 10358:524674a4f6bb

[gaim-migrate @ 11576] N/C committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 13 Dec 2004 06:29:45 +0000
parents 64bc206c7473
children 242b5482910e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9944
e4a27c9aec4c [gaim-migrate @ 10838]
Luke Schierer <lschiere@pidgin.im>
parents: 9791
diff changeset
1 /**
10067
39142bdd5ba6 [gaim-migrate @ 11043]
Mark Doliner <mark@kingant.net>
parents: 10056
diff changeset
2 * @file status.c Status API
9944
e4a27c9aec4c [gaim-migrate @ 10838]
Luke Schierer <lschiere@pidgin.im>
parents: 9791
diff changeset
3 * @ingroup core
e4a27c9aec4c [gaim-migrate @ 10838]
Luke Schierer <lschiere@pidgin.im>
parents: 9791
diff changeset
4 *
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5 * gaim
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
6 *
8046
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 6371
diff changeset
7 * Gaim is the legal property of its developers, whose names are too numerous
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 6371
diff changeset
8 * to list here. Please refer to the COPYRIGHT file distributed with this
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 6371
diff changeset
9 * source distribution.
9944
e4a27c9aec4c [gaim-migrate @ 10838]
Luke Schierer <lschiere@pidgin.im>
parents: 9791
diff changeset
10 *
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 * (at your option) any later version.
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 *
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 * GNU General Public License for more details.
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 *
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 */
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
25 #include "internal.h"
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
27 #include "blist.h"
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
28 #include "debug.h"
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
29 #include "notify.h"
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
30 #include "prefs.h"
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 #include "status.h"
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 #include "util.h"
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
33 #include "xmlnode.h"
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
35 /**
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
36 * A type of status.
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
37 */
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
38 struct _GaimStatusType
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
39 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
40 GaimStatusPrimitive primitive;
6371
8f94cce8faa5 [gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents: 6321
diff changeset
41
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
42 char *id;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
43 char *name;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
44 char *primary_attr_id;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
45
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
46 gboolean saveable;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
47 gboolean user_settable;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
48 gboolean independent;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
49
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
50 GList *attrs;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
51 };
6371
8f94cce8faa5 [gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents: 6321
diff changeset
52
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
53 /**
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
54 * A status attribute.
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
55 */
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
56 struct _GaimStatusAttr
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
57 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
58 char *id;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
59 char *name;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
60 GaimValue *value_type;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
61 };
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
63 /**
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
64 * A list of statuses.
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
65 */
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
66 struct _GaimPresence
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
67 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
68 GaimPresenceContext context;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
69
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
70 gboolean idle;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
71 time_t idle_time;
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
72 time_t login_time;
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
73
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
74 unsigned int warning_level;
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
76 GList *statuses;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
77 GHashTable *status_table;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
78
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
79 GaimStatus *active_status;
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
81 union
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
82 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
83 GaimAccount *account;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
84
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
85 struct
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
86 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
87 GaimConversation *conv;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
88 char *user;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
89
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
90 } chat;
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
91
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
92 struct
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
93 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
94 GaimAccount *account;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
95 char *name;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
96 size_t ref_count;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
97 GList *buddies;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
98
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
99 } buddy;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
100
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
101 } u;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
102 };
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
103
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
104 /**
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
105 * An active status.
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
106 */
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
107 struct _GaimStatus
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108 {
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
109 GaimStatusType *type;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
110 GaimPresence *presence;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
111
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
112 const char *title;
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
114 gboolean active;
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
116 GHashTable *attr_values;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
117 };
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 typedef struct
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120 {
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
121 GaimAccount *account;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
122 char *name;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
123 } GaimStatusBuddyKey;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
124
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
125 /**
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
126 * The information of a snap-shot of the statuses of all
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
127 * your accounts. Basically these are your saved away messages.
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
128 * There is an overall status and message that applies to
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
129 * all your accounts, and then each individual account can
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
130 * optionally have a different custom status and message.
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
131 *
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
132 * The changes to status.xml caused by the new status API
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
133 * are fully backward compatible. The new status API just
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
134 * adds the optional sub-statuses to the XML file.
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
135 */
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
136 struct _GaimStatusSaved
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
137 {
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
138 char *title;
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
139 GaimStatusPrimitive type;
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
140 char *message;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
141
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
142 GList *substatuses; /**< A list of GaimStatusSavedSub's. */
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
143 };
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
144
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
145 struct _GaimStatusSavedSub
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
146 {
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
147 GaimAccount *account;
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
148 const GaimStatusType *type;
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
149 char *message;
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
150 };
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
151
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
152 static int primitive_scores[] =
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
153 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
154 0, /* unset */
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
155 -500, /* offline */
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
156 0, /* online */
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
157 100, /* available */
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
158 -75, /* unavailable */
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
159 -50, /* hidden */
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
160 -100, /* away */
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
161 -200 /* extended away */
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
162 -10, /* idle, special case. */
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
163 -5 /* idle time, special case. */
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
164 };
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
165
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
166 static GHashTable *buddy_presences = NULL;
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
167 static GList *saved_statuses = NULL;
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
168
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
169 #define SCORE_IDLE 5
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
170 #define SCORE_IDLE_TIME 6
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
171
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
172 /**
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
173 * Elements of this array correspond to the GaimStatusPrimitive
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
174 * enumeration.
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
175 */
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
176 static const char *primitive_names[] =
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
177 {
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
178 "unset",
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
179 "offline",
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
180 "available",
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
181 "unavailable",
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
182 "hidden",
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
183 "away",
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
184 "extended_away"
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
185 };
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
186
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
187 static GaimStatusPrimitive
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
188 gaim_primitive_get_type(const char *name)
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
189 {
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
190 int i;
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
191
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
192 g_return_val_if_fail(name != NULL, GAIM_STATUS_UNSET);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
193
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
194 for (i = 0; i < GAIM_STATUS_NUM_PRIMITIVES; i++)
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
195 {
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
196 if (!strcmp(name, primitive_names[i]))
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
197 return i;
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
198 }
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
199
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
200 return GAIM_STATUS_UNSET;
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
201 }
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
202
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
203 /**************************************************************************
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
204 * GaimStatusType API
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
205 **************************************************************************/
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
206 GaimStatusType *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
207 gaim_status_type_new_full(GaimStatusPrimitive primitive, const char *id,
10009
c124bef68132 [gaim-migrate @ 10926]
Mark Doliner <mark@kingant.net>
parents: 10006
diff changeset
208 const char *name, gboolean saveable,
c124bef68132 [gaim-migrate @ 10926]
Mark Doliner <mark@kingant.net>
parents: 10006
diff changeset
209 gboolean user_settable, gboolean independent)
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
210 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
211 GaimStatusType *status_type;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
212
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
213 g_return_val_if_fail(primitive != GAIM_STATUS_UNSET, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
214 g_return_val_if_fail(id != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
215 g_return_val_if_fail(name != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
216
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
217 status_type = g_new0(GaimStatusType, 1);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
218
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
219 status_type->primitive = primitive;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
220 status_type->id = g_strdup(id);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
221 status_type->name = g_strdup(name);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
222 status_type->saveable = saveable;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
223 status_type->user_settable = user_settable;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
224 status_type->independent = independent;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
225
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
226 return status_type;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
227 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
228
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
229 GaimStatusType *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
230 gaim_status_type_new(GaimStatusPrimitive primitive, const char *id,
10009
c124bef68132 [gaim-migrate @ 10926]
Mark Doliner <mark@kingant.net>
parents: 10006
diff changeset
231 const char *name, gboolean user_settable)
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
232 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
233 g_return_val_if_fail(primitive != GAIM_STATUS_UNSET, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
234 g_return_val_if_fail(id != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
235 g_return_val_if_fail(name != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
236
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
237 return gaim_status_type_new_full(primitive, id, name, FALSE,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
238 user_settable, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
239 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
240
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
241 GaimStatusType *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
242 gaim_status_type_new_with_attrs(GaimStatusPrimitive primitive,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
243 const char *id, const char *name,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
244 gboolean saveable, gboolean user_settable,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
245 gboolean independent, const char *attr_id,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
246 const char *attr_name, GaimValue *attr_value,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
247 ...)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
248 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
249 GaimStatusType *status_type;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
250 va_list args;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
251
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
252 g_return_val_if_fail(primitive != GAIM_STATUS_UNSET, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
253 g_return_val_if_fail(id != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
254 g_return_val_if_fail(name != NULL, NULL);
10012
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
255 g_return_val_if_fail(attr_id != NULL, NULL);
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
256 g_return_val_if_fail(attr_name != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
257 g_return_val_if_fail(attr_value != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
258
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
259 status_type = gaim_status_type_new_full(primitive, id, name, saveable,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
260 user_settable, independent);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
261
10010
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
262 /* Add the first attribute */
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
263 gaim_status_type_add_attr(status_type, attr_id, attr_name, attr_value);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
264
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
265 va_start(args, attr_value);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
266 gaim_status_type_add_attrs_vargs(status_type, args);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
267 va_end(args);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
268
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
269 return status_type;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
270 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
271
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
272 void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
273 gaim_status_type_destroy(GaimStatusType *status_type)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
274 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
275 GList *l;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
276
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
277 g_return_if_fail(status_type != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
278
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
279 g_free(status_type->id);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
280 g_free(status_type->name);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
281
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
282 if (status_type->primary_attr_id != NULL)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
283 g_free(status_type->primary_attr_id);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
284
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
285 if (status_type->attrs != NULL)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
286 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
287 for (l = status_type->attrs; l != NULL; l = l->next)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
288 gaim_status_attr_destroy((GaimStatusAttr *)l->data);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
289
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
290 g_list_free(status_type->attrs);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
291 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
292
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
293 g_free(status_type);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
294 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
295
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
296 void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
297 gaim_status_type_set_primary_attr(GaimStatusType *status_type, const char *id)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
298 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
299 g_return_if_fail(status_type != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
300
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
301 if (status_type->primary_attr_id != NULL)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
302 g_free(status_type->primary_attr_id);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
303
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
304 status_type->primary_attr_id = (id == NULL ? NULL : g_strdup(id));
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
305 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
306
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
307 void
10197
7369bf2bf593 [gaim-migrate @ 11314]
Mark Doliner <mark@kingant.net>
parents: 10196
diff changeset
308 gaim_status_type_add_attr(GaimStatusType *status_type, const char *id,
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
309 const char *name, GaimValue *value)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
310 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
311 GaimStatusAttr *attr;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
312
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
313 g_return_if_fail(status_type != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
314 g_return_if_fail(id != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
315 g_return_if_fail(name != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
316 g_return_if_fail(value != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
317
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
318 attr = gaim_status_attr_new(id, name, value);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
319
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
320 status_type->attrs = g_list_append(status_type->attrs, attr);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
321 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
322
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
323 void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
324 gaim_status_type_add_attrs_vargs(GaimStatusType *status_type, va_list args)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
325 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
326 const char *id, *name;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
327 GaimValue *value;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
328
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
329 g_return_if_fail(status_type != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
330
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
331 while ((id = va_arg(args, const char *)) != NULL)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
332 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
333 name = va_arg(args, const char *);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
334 g_return_if_fail(name != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
335
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
336 value = va_arg(args, GaimValue *);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
337 g_return_if_fail(value != NULL);
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
338
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
339 gaim_status_type_add_attr(status_type, id, name, value);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
340 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
341 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
342
10010
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
343 void
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
344 gaim_status_type_add_attrs(GaimStatusType *status_type, const char *id,
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
345 const char *name, GaimValue *value, ...)
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
346 {
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
347 va_list args;
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
348
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
349 g_return_if_fail(status_type != NULL);
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
350 g_return_if_fail(id != NULL);
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
351 g_return_if_fail(name != NULL);
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
352 g_return_if_fail(value != NULL);
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
353
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
354 /* Add the first attribute */
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
355 gaim_status_type_add_attr(status_type, id, name, value);
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
356
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
357 va_start(args, value);
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
358 gaim_status_type_add_attrs_vargs(status_type, args);
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
359 va_end(args);
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
360 }
56e34a659db2 [gaim-migrate @ 10927]
Mark Doliner <mark@kingant.net>
parents: 10009
diff changeset
361
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
362 GaimStatusPrimitive
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
363 gaim_status_type_get_primitive(const GaimStatusType *status_type)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
364 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
365 g_return_val_if_fail(status_type != NULL, GAIM_STATUS_UNSET);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
366
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
367 return status_type->primitive;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
368 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
369
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
370 const char *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
371 gaim_status_type_get_id(const GaimStatusType *status_type)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
372 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
373 g_return_val_if_fail(status_type != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
374
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
375 return status_type->id;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
376 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
377
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
378 const char *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
379 gaim_status_type_get_name(const GaimStatusType *status_type)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
380 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
381 g_return_val_if_fail(status_type != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
382
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
383 return status_type->name;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
384 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
385
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
386 gboolean
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
387 gaim_status_type_is_saveable(const GaimStatusType *status_type)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
388 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
389 g_return_val_if_fail(status_type != NULL, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
390
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
391 return status_type->saveable;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
392 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
393
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
394 gboolean
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
395 gaim_status_type_is_user_settable(const GaimStatusType *status_type)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
396 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
397 g_return_val_if_fail(status_type != NULL, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
398
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
399 return status_type->user_settable;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
400 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
401
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
402 gboolean
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
403 gaim_status_type_is_independent(const GaimStatusType *status_type)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
404 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
405 g_return_val_if_fail(status_type != NULL, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
406
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
407 return status_type->independent;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
408 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
409
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
410 gboolean
10067
39142bdd5ba6 [gaim-migrate @ 11043]
Mark Doliner <mark@kingant.net>
parents: 10056
diff changeset
411 gaim_status_type_is_exclusive(const GaimStatusType *status_type)
39142bdd5ba6 [gaim-migrate @ 11043]
Mark Doliner <mark@kingant.net>
parents: 10056
diff changeset
412 {
39142bdd5ba6 [gaim-migrate @ 11043]
Mark Doliner <mark@kingant.net>
parents: 10056
diff changeset
413 g_return_val_if_fail(status_type != NULL, FALSE);
39142bdd5ba6 [gaim-migrate @ 11043]
Mark Doliner <mark@kingant.net>
parents: 10056
diff changeset
414
39142bdd5ba6 [gaim-migrate @ 11043]
Mark Doliner <mark@kingant.net>
parents: 10056
diff changeset
415 return !status_type->independent;
39142bdd5ba6 [gaim-migrate @ 11043]
Mark Doliner <mark@kingant.net>
parents: 10056
diff changeset
416 }
39142bdd5ba6 [gaim-migrate @ 11043]
Mark Doliner <mark@kingant.net>
parents: 10056
diff changeset
417
39142bdd5ba6 [gaim-migrate @ 11043]
Mark Doliner <mark@kingant.net>
parents: 10056
diff changeset
418 gboolean
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
419 gaim_status_type_is_available(const GaimStatusType *status_type)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
420 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
421 GaimStatusPrimitive primitive;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
422
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
423 g_return_val_if_fail(status_type != NULL, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
424
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
425 primitive = gaim_status_type_get_primitive(status_type);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
426
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
427 return (primitive == GAIM_STATUS_AVAILABLE ||
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
428 primitive == GAIM_STATUS_HIDDEN);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
429 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
430
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
431 const char *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
432 gaim_status_type_get_primary_attr(const GaimStatusType *status_type)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
433 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
434 g_return_val_if_fail(status_type != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
435
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
436 return status_type->primary_attr_id;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
437 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
438
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
439 GaimStatusAttr *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
440 gaim_status_type_get_attr(const GaimStatusType *status_type, const char *id)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
441 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
442 GList *l;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
443
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
444 g_return_val_if_fail(status_type != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
445 g_return_val_if_fail(id != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
446
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
447 for (l = status_type->attrs; l != NULL; l = l->next)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
448 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
449 GaimStatusAttr *attr = (GaimStatusAttr *)l->data;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
450
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
451 if (!strcmp(gaim_status_attr_get_id(attr), id))
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
452 return attr;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
453 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
454
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
455 return NULL;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
456 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
457
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
458 const GList *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
459 gaim_status_type_get_attrs(const GaimStatusType *status_type)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
460 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
461 g_return_val_if_fail(status_type != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
462
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
463 return status_type->attrs;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
464 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
465
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
466 const GaimStatusType *
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
467 gaim_status_type_find_with_id(GList *status_types, const char *id)
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
468 {
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
469 GaimStatusType *status_type;
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
470
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
471 g_return_val_if_fail(id != NULL, NULL);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
472
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
473 while (status_types != NULL)
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
474 {
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
475 status_type = status_types->data;
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
476
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
477 if (!strcmp(id, status_type->id))
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
478 return status_type;
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
479 }
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
480
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
481 return NULL;
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
482 }
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
483
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
484
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
485 /**************************************************************************
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
486 * GaimStatusAttr API
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
487 **************************************************************************/
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
488 GaimStatusAttr *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
489 gaim_status_attr_new(const char *id, const char *name, GaimValue *value_type)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
490 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
491 GaimStatusAttr *attr;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
492
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
493 g_return_val_if_fail(id != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
494 g_return_val_if_fail(name != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
495 g_return_val_if_fail(value_type != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
496
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
497 attr = g_new0(GaimStatusAttr, 1);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
498
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
499 attr->id = g_strdup(id);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
500 attr->name = g_strdup(name);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
501 attr->value_type = value_type;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
502
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
503 return attr;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
504 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
505
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
506 void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
507 gaim_status_attr_destroy(GaimStatusAttr *attr)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
508 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
509 g_return_if_fail(attr != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
510
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
511 g_free(attr->id);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
512 g_free(attr->name);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
513
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
514 gaim_value_destroy(attr->value_type);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
515
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
516 g_free(attr);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
517 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
518
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
519 const char *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
520 gaim_status_attr_get_id(const GaimStatusAttr *attr)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
521 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
522 g_return_val_if_fail(attr != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
523
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
524 return attr->id;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
525 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
526
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
527 const char *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
528 gaim_status_attr_get_name(const GaimStatusAttr *attr)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
529 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
530 g_return_val_if_fail(attr != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
531
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
532 return attr->name;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
533 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
534
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
535 GaimValue *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
536 gaim_status_attr_get_value_type(const GaimStatusAttr *attr)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
537 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
538 g_return_val_if_fail(attr != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
539
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
540 return attr->value_type;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
541 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
542
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
543
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
544 /**************************************************************************
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
545 * GaimStatus API
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
546 **************************************************************************/
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
547 GaimStatus *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
548 gaim_status_new(GaimStatusType *status_type, GaimPresence *presence)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
549 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
550 GaimStatus *status;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
551 const GList *l;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
552
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
553 g_return_val_if_fail(status_type != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
554 g_return_val_if_fail(presence != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
555
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
556 status = g_new0(GaimStatus, 1);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
557
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
558 status->type = status_type;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
559 status->presence = presence;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
560
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
561 status->attr_values =
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
562 g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
563 (GDestroyNotify)gaim_value_destroy);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
564
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
565 for (l = gaim_status_type_get_attrs(status_type); l != NULL; l = l->next)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
566 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
567 GaimStatusAttr *attr = (GaimStatusAttr *)l->data;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
568 GaimValue *value = gaim_status_attr_get_value_type(attr);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
569 GaimValue *new_value = gaim_value_dup(value);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
570
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
571 g_hash_table_insert(status->attr_values,
10197
7369bf2bf593 [gaim-migrate @ 11314]
Mark Doliner <mark@kingant.net>
parents: 10196
diff changeset
572 g_strdup(gaim_status_attr_get_id(attr)),
7369bf2bf593 [gaim-migrate @ 11314]
Mark Doliner <mark@kingant.net>
parents: 10196
diff changeset
573 new_value);
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
574 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
575
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
576 return status;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
577 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
578
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
579 void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
580 gaim_status_destroy(GaimStatus *status)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
581 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
582 g_return_if_fail(status != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
583
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
584 gaim_status_set_active(status, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
585
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
586 g_hash_table_destroy(status->attr_values);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
587
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
588 g_free(status);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
589 }
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
590
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
591 static void
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
592 notify_buddy_status_update(GaimBuddy *buddy, GaimPresence *presence,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
593 GaimStatus *old_status, GaimStatus *new_status)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
594 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
595 GaimBlistUiOps *ops = gaim_blist_get_ui_ops();
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
596
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
597 if (gaim_prefs_get_bool("/core/logging/log_system") &&
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
598 gaim_prefs_get_bool("/core/logging/log_away_state"))
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
599 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
600 time_t current_time = time(NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
601 const char *buddy_alias = gaim_buddy_get_alias(buddy);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
602 char *tmp = NULL;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
603
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
604 if (!gaim_status_is_available(old_status) &&
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
605 gaim_status_is_available(new_status))
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
606 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
607 tmp = g_strdup_printf(_("%s came back"), buddy_alias);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
608 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
609 else if (gaim_status_is_available(old_status) &&
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
610 !gaim_status_is_available(new_status))
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
611 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
612 tmp = g_strdup_printf(_("%s went away"), buddy_alias);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
613 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
614
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
615 if (tmp != NULL)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
616 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
617 GaimLog *log = gaim_account_get_log(buddy->account);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
618
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
619 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, buddy_alias,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
620 current_time, tmp);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
621 g_free(tmp);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
622 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
623 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
624
10012
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
625
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
626
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
627 if (ops != NULL && ops->update != NULL)
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
628 ops->update(gaim_get_blist(), (GaimBlistNode*)buddy);
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
629 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
630
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
631 static void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
632 notify_status_update(GaimPresence *presence, GaimStatus *old_status,
10176
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
633 GaimStatus *new_status)
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
634 {
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
635 GaimPresenceContext context = gaim_presence_get_context(presence);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
636
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
637 if (context == GAIM_PRESENCE_CONTEXT_ACCOUNT)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
638 {
10176
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
639 GaimAccount *account = gaim_presence_get_account(presence);
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
640 GaimAccountUiOps *ops = gaim_accounts_get_ui_ops();
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
641
10176
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
642 if (gaim_account_is_connected(account))
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
643 {
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
644 GaimPluginProtocolInfo *prpl_info = NULL;
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
645 GaimPlugin *prpl;
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
646
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
647 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
648
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
649 if (prpl != NULL)
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
650 {
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
651 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
652
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
653 if (prpl_info != NULL && prpl_info->set_status != NULL)
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
654 prpl_info->set_status(account, new_status);
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
655 }
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
656 }
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
657
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
658 if (ops != NULL && ops->status_changed != NULL)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
659 {
10176
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
660 ops->status_changed(account, new_status);
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
661 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
662 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
663 else if (context == GAIM_PRESENCE_CONTEXT_CONV)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
664 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
665 #if 0
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
666 GaimConversationUiOps *ops;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
667 GaimConversation *conv;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
668
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
669 conv = gaim_status_get_conversation(new_status);
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
670 /*
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
671 * TODO: Probably need to do some of the following here? This is copied
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
672 * from some old status code that was removed.
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
673 *
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
674 * char *tmp = g_strdup_printf(_("%s logged in."), alias);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
675 * gaim_conversation_write(c, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL));
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
676 * g_free(tmp);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
677 *
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
678 * char *tmp = g_strdup_printf(_("%s logged out."), alias);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
679 * gaim_conversation_write(c, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL));
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
680 * g_free(tmp);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
681 *
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
682 * char *tmp = g_strdup_printf(_("%s signed off"), alias);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
683 * gaim_log_write(log, GAIM_MESSAGE_SYSTEM, (alias ? alias : name), current_time, tmp);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
684 * g_free(tmp);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
685 *
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
686 * serv_got_typing_stopped(gc, name);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
687 *
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
688 * gaim_conversation_update(c, GAIM_CONV_UPDATE_AWAY);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
689 */
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
690 #endif
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
691 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
692 else if (context == GAIM_PRESENCE_CONTEXT_BUDDY)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
693 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
694 const GList *l;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
695
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
696 for (l = gaim_presence_get_buddies(presence); l != NULL; l = l->next)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
697 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
698 notify_buddy_status_update((GaimBuddy *)l->data, presence,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
699 old_status, new_status);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
700 }
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
701
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
702 /*
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
703 * TODO: Maybe we should do this here?
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
704 * GaimLog *log = gaim_account_get_log(account);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
705 * char *tmp = g_strdup_printf(_("%s signed on"), alias);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
706 * gaim_log_write(log, GAIM_MESSAGE_SYSTEM, (alias ? alias : name), current_time, tmp);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
707 * g_free(tmp);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
708 */
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
709 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
710 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
711
10204
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
712 static void
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
713 status_has_changed(GaimStatus *status)
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
714 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
715 GaimPresence *presence;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
716 GaimStatus *old_status;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
717
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
718 presence = gaim_status_get_presence(status);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
719 old_status = gaim_presence_get_active_status(presence);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
720
10204
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
721 /*
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
722 * If this status is exclusive, then we must be setting it to "active."
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
723 * Since we are setting it to active, we want to set the currently
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
724 * active status to "inactive."
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
725 */
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
726 if (gaim_status_is_exclusive(status))
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
727 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
728 const GList *l;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
729
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
730 for (l = gaim_presence_get_statuses(presence); l != NULL; l = l->next)
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
731 {
10056
b566449d45f8 [gaim-migrate @ 11021]
Luke Schierer <lschiere@pidgin.im>
parents: 10052
diff changeset
732 GaimStatus *temp_status = l->data;
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
733
10204
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
734 if (temp_status == status)
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
735 continue;
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
736
10204
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
737 if (gaim_status_is_independent(temp_status))
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
738 continue;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
739
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
740 if (gaim_status_is_active(temp_status))
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
741 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
742 /*
10204
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
743 * Since we don't want infinite recursion, we have to set
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
744 * the active variable ourself instead of calling
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
745 * gaim_status_set_active().
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
746 */
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
747 temp_status->active = FALSE;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
748
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
749 notify_status_update(presence, old_status, temp_status);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
750
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
751 break;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
752 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
753 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
754 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
755
10204
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
756 notify_status_update(presence, old_status, status);
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
757 }
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
758
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
759 void
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
760 gaim_status_set_active(GaimStatus *status, gboolean active)
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
761 {
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
762 if (!active && gaim_status_is_exclusive(status))
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
763 {
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
764 gaim_debug_error("status",
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
765 "Cannot deactivate an exclusive status (%s).\n",
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
766 gaim_status_get_id(status));
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
767 return;
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
768 }
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
769
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
770 g_return_if_fail(status != NULL);
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
771
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
772 if (status->active == active)
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
773 return;
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
774
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
775 status->active = active;
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
776
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
777 status_has_changed(status);
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
778 }
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
779
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
780 void
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
781 gaim_status_set_active_with_attrs(GaimStatus *status, gboolean active, va_list args)
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
782 {
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
783 gboolean changed = FALSE;
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
784 const gchar *id;
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
785
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
786 if (!active && gaim_status_is_exclusive(status))
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
787 {
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
788 gaim_debug_error("status",
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
789 "Cannot deactivate an exclusive status (%s).\n",
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
790 gaim_status_get_id(status));
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
791 return;
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
792 }
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
793
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
794 g_return_if_fail(status != NULL);
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
795
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
796 if (status->active != active)
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
797 changed = TRUE;
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
798
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
799 status->active = active;
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
800
10204
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
801 /* Set any attributes */
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
802 while ((id = va_arg(args, const char *)) != NULL)
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
803 {
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
804 GaimValue *value;
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
805 value = gaim_status_get_attr_value(status, id);
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
806 if (value->type == GAIM_TYPE_STRING)
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
807 {
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
808 const gchar *string_data = va_arg(args, const char *);
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
809 if (((string_data == NULL) && (value->data.string_data == NULL)) ||
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
810 ((string_data != NULL) && (value->data.string_data != NULL) &&
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
811 !strcmp(string_data, value->data.string_data)))
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
812 {
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
813 continue;
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
814 }
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
815 gaim_status_set_attr_string(status, id, string_data);
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
816 changed = TRUE;
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
817 }
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
818 else if (value->type == GAIM_TYPE_INT)
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
819 {
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
820 int int_data = va_arg(args, int);
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
821 if (int_data == value->data.int_data)
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
822 continue;
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
823 gaim_status_set_attr_int(status, id, int_data);
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
824 changed = TRUE;
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
825 }
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
826 else if (value->type == GAIM_TYPE_BOOLEAN)
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
827 {
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
828 gboolean boolean_data = va_arg(args, gboolean);
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
829 if (boolean_data == value->data.boolean_data)
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
830 continue;
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
831 gaim_status_set_attr_int(status, id, boolean_data);
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
832 changed = TRUE;
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
833 }
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
834 else
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
835 {
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
836 /* We don't know what the data is--skip over it */
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
837 va_arg(args, void *);
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
838 }
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
839 }
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
840
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
841 if (!changed)
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
842 return;
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
843
393f85d9f8dd [gaim-migrate @ 11325]
Mark Doliner <mark@kingant.net>
parents: 10200
diff changeset
844 status_has_changed(status);
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
845 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
846
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
847 void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
848 gaim_status_set_attr_boolean(GaimStatus *status, const char *id,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
849 gboolean value)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
850 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
851 GaimStatusType *status_type;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
852 GaimValue *attr_value;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
853
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
854 g_return_if_fail(status != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
855 g_return_if_fail(id != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
856
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
857 status_type = gaim_status_get_type(status);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
858
10197
7369bf2bf593 [gaim-migrate @ 11314]
Mark Doliner <mark@kingant.net>
parents: 10196
diff changeset
859 /* Make sure this attribute exists and is the correct type. */
7369bf2bf593 [gaim-migrate @ 11314]
Mark Doliner <mark@kingant.net>
parents: 10196
diff changeset
860 attr_value = gaim_status_get_attr_value(status, id);
7369bf2bf593 [gaim-migrate @ 11314]
Mark Doliner <mark@kingant.net>
parents: 10196
diff changeset
861 g_return_if_fail(attr_value != NULL);
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
862 g_return_if_fail(gaim_value_get_type(attr_value) == GAIM_TYPE_BOOLEAN);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
863
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
864 gaim_value_set_boolean(attr_value, value);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
865 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
866
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
867 void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
868 gaim_status_set_attr_int(GaimStatus *status, const char *id, int value)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
869 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
870 GaimStatusType *status_type;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
871 GaimValue *attr_value;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
872
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
873 g_return_if_fail(status != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
874 g_return_if_fail(id != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
875
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
876 status_type = gaim_status_get_type(status);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
877
10197
7369bf2bf593 [gaim-migrate @ 11314]
Mark Doliner <mark@kingant.net>
parents: 10196
diff changeset
878 /* Make sure this attribute exists and is the correct type. */
7369bf2bf593 [gaim-migrate @ 11314]
Mark Doliner <mark@kingant.net>
parents: 10196
diff changeset
879 attr_value = gaim_status_get_attr_value(status, id);
7369bf2bf593 [gaim-migrate @ 11314]
Mark Doliner <mark@kingant.net>
parents: 10196
diff changeset
880 g_return_if_fail(attr_value != NULL);
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
881 g_return_if_fail(gaim_value_get_type(attr_value) == GAIM_TYPE_INT);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
882
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
883 gaim_value_set_int(attr_value, value);
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
884 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
885
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
886 void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
887 gaim_status_set_attr_string(GaimStatus *status, const char *id,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
888 const char *value)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
889 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
890 GaimStatusType *status_type;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
891 GaimValue *attr_value;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
892
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
893 g_return_if_fail(status != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
894 g_return_if_fail(id != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
895
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
896 status_type = gaim_status_get_type(status);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
897
10197
7369bf2bf593 [gaim-migrate @ 11314]
Mark Doliner <mark@kingant.net>
parents: 10196
diff changeset
898 /* Make sure this attribute exists and is the correct type. */
10196
760e690a5f30 [gaim-migrate @ 11313]
Mark Doliner <mark@kingant.net>
parents: 10176
diff changeset
899 attr_value = gaim_status_get_attr_value(status, id);
10197
7369bf2bf593 [gaim-migrate @ 11314]
Mark Doliner <mark@kingant.net>
parents: 10196
diff changeset
900 g_return_if_fail(attr_value != NULL);
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
901 g_return_if_fail(gaim_value_get_type(attr_value) == GAIM_TYPE_STRING);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
902
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
903 gaim_value_set_string(attr_value, value);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
904 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
905
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
906 GaimStatusType *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
907 gaim_status_get_type(const GaimStatus *status)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
908 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
909 g_return_val_if_fail(status != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
910
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
911 return status->type;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
912 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
913
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
914 GaimPresence *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
915 gaim_status_get_presence(const GaimStatus *status)
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
916 {
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
917 g_return_val_if_fail(status != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
918
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
919 return status->presence;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
920 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
921
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
922 const char *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
923 gaim_status_get_id(const GaimStatus *status)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
924 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
925 g_return_val_if_fail(status != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
926
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
927 return gaim_status_type_get_id(gaim_status_get_type(status));
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
928 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
929
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
930 const char *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
931 gaim_status_get_name(const GaimStatus *status)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
932 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
933 g_return_val_if_fail(status != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
934
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
935 return gaim_status_type_get_name(gaim_status_get_type(status));
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
936 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
937
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
938 gboolean
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
939 gaim_status_is_independent(const GaimStatus *status)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
940 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
941 g_return_val_if_fail(status != NULL, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
942
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
943 return gaim_status_type_is_independent(gaim_status_get_type(status));
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
944 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
945
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
946 gboolean
10067
39142bdd5ba6 [gaim-migrate @ 11043]
Mark Doliner <mark@kingant.net>
parents: 10056
diff changeset
947 gaim_status_is_exclusive(const GaimStatus *status)
39142bdd5ba6 [gaim-migrate @ 11043]
Mark Doliner <mark@kingant.net>
parents: 10056
diff changeset
948 {
39142bdd5ba6 [gaim-migrate @ 11043]
Mark Doliner <mark@kingant.net>
parents: 10056
diff changeset
949 g_return_val_if_fail(status != NULL, FALSE);
39142bdd5ba6 [gaim-migrate @ 11043]
Mark Doliner <mark@kingant.net>
parents: 10056
diff changeset
950
39142bdd5ba6 [gaim-migrate @ 11043]
Mark Doliner <mark@kingant.net>
parents: 10056
diff changeset
951 return gaim_status_type_is_exclusive(gaim_status_get_type(status));
39142bdd5ba6 [gaim-migrate @ 11043]
Mark Doliner <mark@kingant.net>
parents: 10056
diff changeset
952 }
39142bdd5ba6 [gaim-migrate @ 11043]
Mark Doliner <mark@kingant.net>
parents: 10056
diff changeset
953
39142bdd5ba6 [gaim-migrate @ 11043]
Mark Doliner <mark@kingant.net>
parents: 10056
diff changeset
954 gboolean
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
955 gaim_status_is_available(const GaimStatus *status)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
956 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
957 g_return_val_if_fail(status != NULL, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
958
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
959 return gaim_status_type_is_available(gaim_status_get_type(status));
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
960 }
6216
dc42b27101c0 [gaim-migrate @ 6702]
Nathan Walp <nwalp@pidgin.im>
parents: 6113
diff changeset
961
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
962 gboolean
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
963 gaim_status_is_active(const GaimStatus *status)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
964 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
965 g_return_val_if_fail(status != NULL, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
966
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
967 return status->active;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
968 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
969
10040
81059dce3aed [gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
970 gboolean
81059dce3aed [gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
971 gaim_status_is_online(const GaimStatus *status)
81059dce3aed [gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
972 {
81059dce3aed [gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
973 GaimStatusPrimitive primitive;
81059dce3aed [gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
974
81059dce3aed [gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
975 g_return_val_if_fail( status != NULL, FALSE);
81059dce3aed [gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
976
81059dce3aed [gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
977 primitive = gaim_status_type_get_primitive(gaim_status_get_type(status));
81059dce3aed [gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
978
81059dce3aed [gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
979 return (primitive != GAIM_STATUS_UNSET &&
81059dce3aed [gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
980 primitive != GAIM_STATUS_OFFLINE);
81059dce3aed [gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
981 }
81059dce3aed [gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
982
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
983 GaimValue *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
984 gaim_status_get_attr_value(const GaimStatus *status, const char *id)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
985 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
986 GaimStatusType *status_type;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
987 GaimStatusAttr *attr;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
988
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
989 g_return_val_if_fail(status != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
990 g_return_val_if_fail(id != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
991
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
992 status_type = gaim_status_get_type(status);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
993
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
994 /* Make sure this attribute exists. */
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
995 attr = gaim_status_type_get_attr(status_type, id);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
996 g_return_val_if_fail(attr != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
997
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
998 return (GaimValue *)g_hash_table_lookup(status->attr_values, id);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
999 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1000
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1001 gboolean
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1002 gaim_status_get_attr_boolean(const GaimStatus *status, const char *id)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1003 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1004 const GaimValue *value;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1005
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1006 g_return_val_if_fail(status != NULL, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1007 g_return_val_if_fail(id != NULL, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1008
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1009 if ((value = gaim_status_get_attr_value(status, id)) == NULL)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1010 return FALSE;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1011
10197
7369bf2bf593 [gaim-migrate @ 11314]
Mark Doliner <mark@kingant.net>
parents: 10196
diff changeset
1012 g_return_val_if_fail(gaim_value_get_type(value) == GAIM_TYPE_BOOLEAN, FALSE);
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1013
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1014 return gaim_value_get_boolean(value);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1015 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1016
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1017 int
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1018 gaim_status_get_attr_int(const GaimStatus *status, const char *id)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1019 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1020 const GaimValue *value;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1021
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1022 g_return_val_if_fail(status != NULL, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1023 g_return_val_if_fail(id != NULL, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1024
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1025 if ((value = gaim_status_get_attr_value(status, id)) == NULL)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1026 return FALSE;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1027
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1028 g_return_val_if_fail(gaim_value_get_type(value) == GAIM_TYPE_INT, 0);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1029
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1030 return gaim_value_get_int(value);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1031 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1032
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1033 const char *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1034 gaim_status_get_attr_string(const GaimStatus *status, const char *id)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1035 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1036 const GaimValue *value;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1037
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1038 g_return_val_if_fail(status != NULL, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1039 g_return_val_if_fail(id != NULL, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1040
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1041 if ((value = gaim_status_get_attr_value(status, id)) == NULL)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1042 return FALSE;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1043
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1044 g_return_val_if_fail(gaim_value_get_type(value) == GAIM_TYPE_STRING, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1045
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1046 return gaim_value_get_string(value);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1047 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1048
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1049 gint
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1050 gaim_status_compare(const GaimStatus *status1, const GaimStatus *status2)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1051 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1052 GaimStatusType *type1, *type2;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1053 int score1 = 0, score2 = 0;
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1054
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1055 if ((status1 == NULL && status2 == NULL) ||
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1056 (status1 == status2))
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1057 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1058 return 0;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1059 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1060 else if (status1 == NULL)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1061 return 1;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1062 else if (status2 == NULL)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1063 return -1;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1064
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1065 type1 = gaim_status_get_type(status1);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1066 type2 = gaim_status_get_type(status2);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1067
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1068 if (gaim_status_is_active(status1))
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1069 score1 = primitive_scores[gaim_status_type_get_primitive(type1)];
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1070
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1071 if (gaim_status_is_active(status2))
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1072 score2 = primitive_scores[gaim_status_type_get_primitive(type2)];
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1073
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1074 if (score1 > score2)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1075 return -1;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1076 else if (score1 < score2)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1077 return 1;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1078
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1079 return 0;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1080 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1081
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1082
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1083 /**************************************************************************
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1084 * GaimPresence API
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1085 **************************************************************************/
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1086 GaimPresence *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1087 gaim_presence_new(GaimPresenceContext context)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1088 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1089 GaimPresence *presence;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1090
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1091 g_return_val_if_fail(context != GAIM_PRESENCE_CONTEXT_UNSET, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1092
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1093 presence = g_new0(GaimPresence, 1);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1094
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1095 presence->context = context;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1096
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1097 presence->status_table =
10009
c124bef68132 [gaim-migrate @ 10926]
Mark Doliner <mark@kingant.net>
parents: 10006
diff changeset
1098 g_hash_table_new_full(g_str_hash, g_str_equal,
c124bef68132 [gaim-migrate @ 10926]
Mark Doliner <mark@kingant.net>
parents: 10006
diff changeset
1099 g_free, (GFreeFunc)gaim_status_destroy);
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1100
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1101 return presence;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1102 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1103
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1104 GaimPresence *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1105 gaim_presence_new_for_account(GaimAccount *account)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1106 {
10012
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1107 GaimPresence *presence = NULL;
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1108 g_return_val_if_fail(account != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1109
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1110 presence = gaim_presence_new(GAIM_PRESENCE_CONTEXT_ACCOUNT);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1111 presence->u.account = account;
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1112 presence->statuses = gaim_prpl_get_statuses(account, presence);
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1113
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1114 return presence;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1115 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1116
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1117 GaimPresence *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1118 gaim_presence_new_for_conv(GaimConversation *conv)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1119 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1120 GaimPresence *presence;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1121
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1122 g_return_val_if_fail(conv != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1123
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1124 presence = gaim_presence_new(GAIM_PRESENCE_CONTEXT_CONV);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1125 presence->u.chat.conv = conv;
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1126 /* presence->statuses = gaim_prpl_get_statuses(conv->account, presence); ? */
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1127
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1128 return presence;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1129 }
6216
dc42b27101c0 [gaim-migrate @ 6702]
Nathan Walp <nwalp@pidgin.im>
parents: 6113
diff changeset
1130
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1131 GaimPresence *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1132 gaim_presence_new_for_buddy(GaimBuddy *buddy)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1133 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1134 GaimPresence *presence;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1135 GaimStatusBuddyKey *key;
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1136 GaimAccount *account;
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1137
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1138 g_return_val_if_fail(buddy != NULL, NULL);
10012
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1139 account = buddy->account;
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1140
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1141 account = buddy->account;
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1142
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1143 key = g_new0(GaimStatusBuddyKey, 1);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1144 key->account = buddy->account;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1145 key->name = g_strdup(buddy->name);
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1146
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1147 presence = g_hash_table_lookup(buddy_presences, key);
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1148 if (presence == NULL)
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1149 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1150 presence = gaim_presence_new(GAIM_PRESENCE_CONTEXT_BUDDY);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1151
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1152 presence->u.buddy.name = g_strdup(buddy->name);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1153 presence->u.buddy.account = buddy->account;
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1154 presence->statuses = gaim_prpl_get_statuses(buddy->account, presence);
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1155
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1156 g_hash_table_insert(buddy_presences, key, presence);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1157 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1158 else
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1159 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1160 g_free(key->name);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1161 g_free(key);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1162 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1163
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1164 presence->u.buddy.ref_count++;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1165 presence->u.buddy.buddies = g_list_append(presence->u.buddy.buddies,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1166 buddy);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1167
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1168 return presence;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1169 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1170
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1171 void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1172 gaim_presence_destroy(GaimPresence *presence)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1173 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1174 g_return_if_fail(presence != NULL);
6216
dc42b27101c0 [gaim-migrate @ 6702]
Nathan Walp <nwalp@pidgin.im>
parents: 6113
diff changeset
1175
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1176 if (gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_BUDDY)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1177 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1178 GaimStatusBuddyKey key;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1179
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1180 presence->u.buddy.ref_count--;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1181
10077
0fb9cf6b9240 [gaim-migrate @ 11058]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10067
diff changeset
1182 if(presence->u.buddy.ref_count != 0)
0fb9cf6b9240 [gaim-migrate @ 11058]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10067
diff changeset
1183 return;
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1184
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1185 key.account = presence->u.buddy.account;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1186 key.name = presence->u.buddy.name;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1187
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1188 g_hash_table_remove(buddy_presences, &key);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1189
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1190 if (presence->u.buddy.name != NULL)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1191 g_free(presence->u.buddy.name);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1192 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1193 else if (gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_CONV)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1194 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1195 if (presence->u.chat.user != NULL)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1196 g_free(presence->u.chat.user);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1197 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1198
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1199 if (presence->statuses != NULL)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1200 g_list_free(presence->statuses);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1201
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1202 g_hash_table_destroy(presence->status_table);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1203
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1204 g_free(presence);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1205 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1206
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1207 void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1208 gaim_presence_remove_buddy(GaimPresence *presence, GaimBuddy *buddy)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1209 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1210 g_return_if_fail(presence != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1211 g_return_if_fail(buddy != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1212 g_return_if_fail(gaim_presence_get_context(presence) ==
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1213 GAIM_PRESENCE_CONTEXT_BUDDY);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1214
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1215 if (g_list_find(presence->u.buddy.buddies, buddy) != NULL)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1216 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1217 presence->u.buddy.buddies = g_list_remove(presence->u.buddy.buddies,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1218 buddy);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1219 presence->u.buddy.ref_count--;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1220 }
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1221 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1222
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1223 void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1224 gaim_presence_add_status(GaimPresence *presence, GaimStatus *status)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1225 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1226 g_return_if_fail(presence != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1227 g_return_if_fail(status != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1228
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1229 presence->statuses = g_list_append(presence->statuses, status);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1230
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1231 g_hash_table_insert(presence->status_table,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1232 g_strdup(gaim_status_get_id(status)), status);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1233 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1234
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1235 void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1236 gaim_presence_add_presence(GaimPresence *presence, const GList *source_list)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1237 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1238 const GList *l;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1239
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1240 g_return_if_fail(presence != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1241 g_return_if_fail(source_list != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1242
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1243 for (l = source_list; l != NULL; l = l->next)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1244 gaim_presence_add_status(presence, (GaimStatus *)l->data);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1245 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1246
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1247 void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1248 gaim_presence_set_status_active(GaimPresence *presence, const char *status_id,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1249 gboolean active)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1250 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1251 GaimStatus *status;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1252
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1253 g_return_if_fail(presence != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1254 g_return_if_fail(status_id != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1255
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1256 status = gaim_presence_get_status(presence, status_id);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1257
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1258 g_return_if_fail(status != NULL);
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1259 /* TODO: Should we do the following? */
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1260 /* g_return_if_fail(active == status->active); */
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1261
10067
39142bdd5ba6 [gaim-migrate @ 11043]
Mark Doliner <mark@kingant.net>
parents: 10056
diff changeset
1262 if (gaim_status_is_exclusive(status))
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1263 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1264 if (!active)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1265 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1266 gaim_debug_warning("status",
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1267 "Attempted to set a non-independent status "
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1268 "(%s) inactive. Only independent statuses "
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1269 "can be specifically marked inactive.",
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1270 status_id);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1271
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1272 return;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1273 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1274
10052
eaec201b2688 [gaim-migrate @ 11013]
Mark Doliner <mark@kingant.net>
parents: 10040
diff changeset
1275 } else if (presence->active_status != NULL) {
eaec201b2688 [gaim-migrate @ 11013]
Mark Doliner <mark@kingant.net>
parents: 10040
diff changeset
1276 gaim_status_set_active(presence->active_status, FALSE);
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1277
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1278 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1279
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1280 gaim_status_set_active(status, active);
10052
eaec201b2688 [gaim-migrate @ 11013]
Mark Doliner <mark@kingant.net>
parents: 10040
diff changeset
1281 presence->active_status = status;
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1282 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1283
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1284 void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1285 gaim_presence_switch_status(GaimPresence *presence, const char *status_id)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1286 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1287 GaimStatus *status;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1288
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1289 g_return_if_fail(presence != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1290 g_return_if_fail(status_id != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1291
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1292 status = gaim_presence_get_status(presence, status_id);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1293
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1294 g_return_if_fail(status != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1295
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1296 if (gaim_status_is_independent(status))
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1297 return;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1298
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1299 if (presence->active_status != NULL)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1300 gaim_status_set_active(presence->active_status, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1301
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1302 gaim_status_set_active(status, TRUE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1303 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1304
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1305 static void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1306 update_buddy_idle(GaimBuddy *buddy, GaimPresence *presence,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1307 time_t current_time, gboolean old_idle, gboolean idle)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1308 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1309 GaimBlistUiOps *ops = gaim_get_blist()->ui_ops;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1310
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1311 if (!old_idle && idle)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1312 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1313 gaim_signal_emit(gaim_blist_get_handle(), "buddy-idle", buddy);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1314
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1315 if (gaim_prefs_get_bool("/core/logging/log_system") &&
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1316 gaim_prefs_get_bool("/core/logging/log_idle_state"))
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1317 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1318 GaimLog *log = gaim_account_get_log(buddy->account);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1319 char *tmp = g_strdup_printf(_("%s became idle"),
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1320 gaim_buddy_get_alias(buddy));
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1321
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1322 gaim_log_write(log, GAIM_MESSAGE_SYSTEM,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1323 gaim_buddy_get_alias(buddy), current_time, tmp);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1324 g_free(tmp);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1325 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1326 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1327 else if (old_idle && !idle)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1328 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1329 gaim_signal_emit(gaim_blist_get_handle(), "buddy-unidle", buddy);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1330
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1331 if (gaim_prefs_get_bool("/core/logging/log_system") &&
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1332 gaim_prefs_get_bool("/core/logging/log_idle_state"))
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1333 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1334 GaimLog *log = gaim_account_get_log(buddy->account);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1335 char *tmp = g_strdup_printf(_("%s became unidle"),
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1336 gaim_buddy_get_alias(buddy));
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1337
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1338 gaim_log_write(log, GAIM_MESSAGE_SYSTEM,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1339 gaim_buddy_get_alias(buddy), current_time, tmp);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1340 g_free(tmp);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1341 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1342 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1343
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1344 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy));
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1345
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1346 if (ops != NULL && ops->update != NULL)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1347 ops->update(gaim_get_blist(), (GaimBlistNode *)buddy);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1348 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1349
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1350 void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1351 gaim_presence_set_idle(GaimPresence *presence, gboolean idle, time_t idle_time)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1352 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1353 gboolean old_idle;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1354
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1355 g_return_if_fail(presence != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1356
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1357 if (presence->idle == idle && presence->idle_time == idle_time)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1358 return;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1359
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1360 old_idle = presence->idle;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1361 presence->idle = idle;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1362 presence->idle_time = (idle ? idle_time : 0);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1363
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1364 if (gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_BUDDY)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1365 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1366 const GList *l;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1367 time_t current_time = time(NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1368
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1369 for (l = gaim_presence_get_buddies(presence); l != NULL; l = l->next)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1370 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1371 update_buddy_idle((GaimBuddy *)l->data, presence, current_time,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1372 old_idle, idle);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1373 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1374 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1375 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1376
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1377 void
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1378 gaim_presence_set_login_time(GaimPresence *presence, time_t login_time)
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1379 {
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1380 g_return_if_fail(presence != NULL);
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1381
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1382 if (presence->login_time == login_time)
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1383 return;
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1384
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1385 presence->login_time = login_time;
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1386 }
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1387
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1388 void
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1389 gaim_presence_set_warning_level(GaimPresence *presence, unsigned int level)
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1390 {
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1391 g_return_if_fail(presence != NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1392 g_return_if_fail(level <= 100);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1393
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1394 if (presence->warning_level == level)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1395 return;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1396
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1397 presence->warning_level = level;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1398
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1399 if (gaim_presence_get_context(presence) == GAIM_PRESENCE_CONTEXT_BUDDY)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1400 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1401 GaimBlistUiOps *ops = gaim_get_blist()->ui_ops;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1402
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1403 if (ops != NULL && ops->update != NULL)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1404 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1405 const GList *l;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1406
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1407 for (l = gaim_presence_get_buddies(presence);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1408 l != NULL;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1409 l = l->next)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1410 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1411 ops->update(gaim_get_blist(), (GaimBlistNode *)l->data);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1412 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1413 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1414 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1415 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1416
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1417 GaimPresenceContext
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1418 gaim_presence_get_context(const GaimPresence *presence)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1419 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1420 g_return_val_if_fail(presence != NULL, GAIM_PRESENCE_CONTEXT_UNSET);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1421
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1422 return presence->context;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1423 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1424
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1425 GaimAccount *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1426 gaim_presence_get_account(const GaimPresence *presence)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1427 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1428 GaimPresenceContext context;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1429
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1430 g_return_val_if_fail(presence != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1431
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1432 context = gaim_presence_get_context(presence);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1433
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1434 g_return_val_if_fail(context == GAIM_PRESENCE_CONTEXT_ACCOUNT ||
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1435 context == GAIM_PRESENCE_CONTEXT_BUDDY, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1436
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1437 return presence->u.account;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1438 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1439
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1440 GaimConversation *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1441 gaim_presence_get_conversation(const GaimPresence *presence)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1442 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1443 g_return_val_if_fail(presence != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1444 g_return_val_if_fail(gaim_presence_get_context(presence) ==
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1445 GAIM_PRESENCE_CONTEXT_CONV, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1446
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1447 return presence->u.chat.conv;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1448 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1449
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1450 const char *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1451 gaim_presence_get_chat_user(const GaimPresence *presence)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1452 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1453 g_return_val_if_fail(presence != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1454 g_return_val_if_fail(gaim_presence_get_context(presence) ==
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1455 GAIM_PRESENCE_CONTEXT_CONV, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1456
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1457 return presence->u.chat.user;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1458 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1459
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1460 const GList *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1461 gaim_presence_get_buddies(const GaimPresence *presence)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1462 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1463 g_return_val_if_fail(presence != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1464 g_return_val_if_fail(gaim_presence_get_context(presence) ==
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1465 GAIM_PRESENCE_CONTEXT_BUDDY, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1466
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1467 return presence->u.buddy.buddies;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1468 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1469
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1470 const GList *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1471 gaim_presence_get_statuses(const GaimPresence *presence)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1472 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1473 g_return_val_if_fail(presence != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1474
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1475 return presence->statuses;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1476 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1477
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1478 GaimStatus *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1479 gaim_presence_get_status(const GaimPresence *presence, const char *status_id)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1480 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1481 GaimStatus *status;
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1482 const GList *l = NULL;
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1483
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1484 g_return_val_if_fail(presence != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1485 g_return_val_if_fail(status_id != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1486
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1487 /* What's the purpose of this hash table? */
10012
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1488 status = (GaimStatus *)g_hash_table_lookup(presence->status_table,
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1489 status_id);
10012
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1490
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1491 if (status == NULL) {
10012
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1492 for (l = gaim_presence_get_statuses(presence);
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1493 l != NULL && status == NULL; l = l->next)
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1494 {
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1495 GaimStatus *temp_status = l->data;
10012
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1496
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1497 if (!strcmp(status_id, gaim_status_get_id(temp_status)))
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1498 status = temp_status;
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1499 }
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1500
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1501 if (status != NULL)
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1502 g_hash_table_insert(presence->status_table,
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1503 g_strdup(gaim_status_get_id(status)), status);
10012
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1504 }
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1505
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1506 return status;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1507 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1508
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1509 GaimStatus *
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1510 gaim_presence_get_active_status(const GaimPresence *presence)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1511 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1512 g_return_val_if_fail(presence != NULL, NULL);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1513
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1514 return presence->active_status;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1515 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1516
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1517 gboolean
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1518 gaim_presence_is_available(const GaimPresence *presence)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1519 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1520 GaimStatus *status;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1521
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1522 g_return_val_if_fail(presence != NULL, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1523
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1524 status = gaim_presence_get_active_status(presence);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1525
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1526 return ((status != NULL && gaim_status_is_available(status)) &&
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1527 !gaim_presence_is_idle(presence));
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1528 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1529
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1530 gboolean
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1531 gaim_presence_is_online(const GaimPresence *presence)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1532 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1533 GaimStatus *status;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1534
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1535 g_return_val_if_fail(presence != NULL, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1536
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1537 if ((status = gaim_presence_get_active_status(presence)) == NULL)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1538 return FALSE;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1539
10040
81059dce3aed [gaim-migrate @ 10999]
Luke Schierer <lschiere@pidgin.im>
parents: 10013
diff changeset
1540 return gaim_status_is_online(status);
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1541 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1542
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1543 gboolean
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1544 gaim_presence_is_status_active(const GaimPresence *presence,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1545 const char *status_id)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1546 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1547 GaimStatus *status;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1548
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1549 g_return_val_if_fail(presence != NULL, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1550 g_return_val_if_fail(status_id != NULL, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1551
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1552 status = gaim_presence_get_status(presence, status_id);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1553
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1554 return (status != NULL && gaim_status_is_active(status));
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1555 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1556
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1557 gboolean
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1558 gaim_presence_is_status_primitive_active(const GaimPresence *presence,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1559 GaimStatusPrimitive primitive)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1560 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1561 GaimStatus *status;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1562 GaimStatusType *status_type;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1563
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1564 g_return_val_if_fail(presence != NULL, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1565 g_return_val_if_fail(primitive != GAIM_STATUS_UNSET, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1566
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1567 status = gaim_presence_get_active_status(presence);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1568 status_type = gaim_status_get_type(status);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1569
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1570 if (gaim_status_type_get_primitive(status_type) == primitive)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1571 return TRUE;
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1572
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1573 return FALSE;
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1574 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1575
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1576 gboolean
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1577 gaim_presence_is_idle(const GaimPresence *presence)
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1578 {
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1579 g_return_val_if_fail(presence != NULL, FALSE);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1580
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1581 return presence->idle;
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1582 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1583
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1584 time_t
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1585 gaim_presence_get_idle_time(const GaimPresence *presence)
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1586 {
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1587 g_return_val_if_fail(presence != NULL, 0);
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1588
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1589 return presence->idle_time;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1590 }
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1591
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1592 unsigned int
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1593 gaim_presence_get_warning_level(const GaimPresence *presence)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1594 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1595 g_return_val_if_fail(presence != NULL, 0);
6216
dc42b27101c0 [gaim-migrate @ 6702]
Nathan Walp <nwalp@pidgin.im>
parents: 6113
diff changeset
1596
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1597 return presence->warning_level;
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1598 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1599
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1600 gint
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1601 gaim_presence_compare(const GaimPresence *presence1,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1602 const GaimPresence *presence2)
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1603 {
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1604 gboolean idle1, idle2;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1605 size_t idle_time_1, idle_time_2;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1606 int score1 = 0, score2 = 0;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1607 const GList *l;
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1608
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1609 if ((presence1 == NULL && presence2 == NULL) || (presence1 == presence2))
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1610 return 0;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1611 else if (presence1 == NULL)
10151
d83e6f2125b1 [gaim-migrate @ 11228]
Christian Hammond <chipx86@chipx86.com>
parents: 10087
diff changeset
1612 return 1;
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1613 else if (presence2 == NULL)
10151
d83e6f2125b1 [gaim-migrate @ 11228]
Christian Hammond <chipx86@chipx86.com>
parents: 10087
diff changeset
1614 return -1;
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1615
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1616 /* Compute the score of the first set of statuses. */
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1617 for (l = gaim_presence_get_statuses(presence1); l != NULL; l = l->next)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1618 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1619 GaimStatus *status = (GaimStatus *)l->data;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1620 GaimStatusType *type = gaim_status_get_type(status);
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1621
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1622 if (gaim_status_is_active(status))
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1623 score1 += primitive_scores[gaim_status_type_get_primitive(type)];
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1624 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1625
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1626 /* Compute the score of the second set of statuses. */
10151
d83e6f2125b1 [gaim-migrate @ 11228]
Christian Hammond <chipx86@chipx86.com>
parents: 10087
diff changeset
1627 for (l = gaim_presence_get_statuses(presence2); l != NULL; l = l->next)
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1628 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1629 GaimStatus *status = (GaimStatus *)l->data;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1630 GaimStatusType *type = gaim_status_get_type(status);
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1631
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1632 if (gaim_status_is_active(status))
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1633 score2 += primitive_scores[gaim_status_type_get_primitive(type)];
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1634 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1635
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1636 idle1 = gaim_presence_is_idle(presence1);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1637 idle2 = gaim_presence_is_idle(presence2);
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1638
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1639 if (idle1)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1640 score1 += primitive_scores[SCORE_IDLE];
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1641
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1642 if (idle2)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1643 score2 += primitive_scores[SCORE_IDLE];
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1644
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1645 idle_time_1 = gaim_presence_get_idle_time(presence1);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1646 idle_time_2 = gaim_presence_get_idle_time(presence2);
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1647
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1648 if (idle_time_1 > idle_time_2)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1649 score1 += primitive_scores[SCORE_IDLE_TIME];
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1650 else if (idle_time_1 < idle_time_2)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1651 score2 += primitive_scores[SCORE_IDLE_TIME];
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1652
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1653 if (score1 < score2)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1654 return 1;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1655 else if (score1 > score2)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1656 return -1;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1657
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1658 return 0;
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1659 }
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1660
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1661
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1662 /**************************************************************************
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1663 * Status subsystem
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1664 **************************************************************************/
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1665 static void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1666 score_pref_changed_cb(const char *name, GaimPrefType type, gpointer value,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1667 gpointer data)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1668 {
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1669 int index = GPOINTER_TO_INT(data);
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1670
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1671 primitive_scores[index] = GPOINTER_TO_INT(value);
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1672 }
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1673
10012
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1674 guint
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1675 gaim_buddy_presences_hash(gconstpointer key)
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1676 {
10012
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1677 const GaimStatusBuddyKey *me = key;
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1678 guint ret;
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1679 char *str;
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1680
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1681 str = g_strdup_printf("%p%s", me->account, me->name);
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1682 ret = g_str_hash(str);
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1683 g_free(str);
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1684
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1685 return ret;
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1686 }
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1687
10012
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1688 gboolean
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1689 gaim_buddy_presences_equal(gconstpointer a, gconstpointer b)
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1690 {
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1691 GaimStatusBuddyKey *key_a = (GaimStatusBuddyKey *)a;
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1692 GaimStatusBuddyKey *key_b = (GaimStatusBuddyKey *)b;
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1693
10012
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1694 if(key_a->account == key_b->account &&
a38881ec9c0f [gaim-migrate @ 10929]
Nathan Walp <nwalp@pidgin.im>
parents: 10010
diff changeset
1695 !strcmp(key_a->name, key_b->name))
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1696 return TRUE;
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1697 else
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1698 return FALSE;
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1699 }
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1700
10176
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
1701 const GList *
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1702 gaim_statuses_get_saved(void)
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1703 {
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1704 return saved_statuses;
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1705 }
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1706
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1707 GaimStatusSaved *
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1708 gaim_statuses_find_saved(const char *title)
10176
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
1709 {
10340
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1710 GList *l;
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1711 GaimStatusSaved *status;
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1712
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1713 for (l = saved_statuses; l != NULL; l = g_list_next(l))
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1714 {
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1715 status = (GaimStatusSaved *)l->data;
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1716 if (!strcmp(status->title, title))
10340
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1717 return status;
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1718 }
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1719
10176
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
1720 return NULL;
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
1721 }
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
1722
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1723 const char *
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1724 gaim_statuses_saved_get_title(const GaimStatusSaved *saved_status)
10176
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
1725 {
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1726 return saved_status->title;
10176
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
1727 }
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
1728
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1729 GaimStatusPrimitive
10340
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1730 gaim_statuses_saved_get_type(const GaimStatusSaved *saved_status)
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1731 {
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1732 return saved_status->type;
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1733 }
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1734
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1735 const char *
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1736 gaim_statuses_saved_get_message(const GaimStatusSaved *saved_status)
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1737 {
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1738 return saved_status->message;
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1739 }
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1740
10087
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10077
diff changeset
1741 void *
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10077
diff changeset
1742 gaim_statuses_get_handle() {
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10077
diff changeset
1743 static int handle;
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10077
diff changeset
1744
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10077
diff changeset
1745 return &handle;
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10077
diff changeset
1746 }
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10077
diff changeset
1747
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1748 void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1749 gaim_statuses_init(void)
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1750 {
10087
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10077
diff changeset
1751 void *handle = gaim_statuses_get_handle;
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10077
diff changeset
1752
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1753 gaim_prefs_add_none("/core/status");
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1754 gaim_prefs_add_none("/core/status/scores");
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1755
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1756 gaim_prefs_add_int("/core/status/scores/offline",
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1757 primitive_scores[GAIM_STATUS_OFFLINE]);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1758 gaim_prefs_add_int("/core/status/scores/available",
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1759 primitive_scores[GAIM_STATUS_AVAILABLE]);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1760 gaim_prefs_add_int("/core/status/scores/hidden",
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1761 primitive_scores[GAIM_STATUS_HIDDEN]);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1762 gaim_prefs_add_int("/core/status/scores/away",
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1763 primitive_scores[GAIM_STATUS_AWAY]);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1764 gaim_prefs_add_int("/core/status/scores/extended_away",
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1765 primitive_scores[GAIM_STATUS_EXTENDED_AWAY]);
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1766 gaim_prefs_add_int("/core/status/scores/idle",
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1767 primitive_scores[SCORE_IDLE]);
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1768
10087
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10077
diff changeset
1769 gaim_prefs_connect_callback(handle, "/core/status/scores/offline",
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1770 score_pref_changed_cb,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1771 GINT_TO_POINTER(GAIM_STATUS_OFFLINE));
10087
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10077
diff changeset
1772 gaim_prefs_connect_callback(handle, "/core/status/scores/available",
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1773 score_pref_changed_cb,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1774 GINT_TO_POINTER(GAIM_STATUS_AVAILABLE));
10087
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10077
diff changeset
1775 gaim_prefs_connect_callback(handle, "/core/status/scores/hidden",
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1776 score_pref_changed_cb,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1777 GINT_TO_POINTER(GAIM_STATUS_HIDDEN));
10087
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10077
diff changeset
1778 gaim_prefs_connect_callback(handle, "/core/status/scores/away",
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1779 score_pref_changed_cb,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1780 GINT_TO_POINTER(GAIM_STATUS_AWAY));
10087
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10077
diff changeset
1781 gaim_prefs_connect_callback(handle, "/core/status/scores/extended_away",
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1782 score_pref_changed_cb,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1783 GINT_TO_POINTER(GAIM_STATUS_EXTENDED_AWAY));
10087
9fdbfe832fac [gaim-migrate @ 11098]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10077
diff changeset
1784 gaim_prefs_connect_callback(handle, "/core/status/scores/idle",
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1785 score_pref_changed_cb,
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1786 GINT_TO_POINTER(SCORE_IDLE));
10006
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1787
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1788 buddy_presences = g_hash_table_new(gaim_buddy_presences_hash,
9baedaca25c7 [gaim-migrate @ 10923]
Mark Doliner <mark@kingant.net>
parents: 9949
diff changeset
1789 gaim_buddy_presences_equal);
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1790 }
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1791
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1792 void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1793 gaim_statuses_uninit(void)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1794 {
10176
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
1795 if (buddy_presences != NULL)
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
1796 {
10077
0fb9cf6b9240 [gaim-migrate @ 11058]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10067
diff changeset
1797 g_hash_table_destroy(buddy_presences);
10176
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
1798
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
1799 buddy_presences = NULL;
0109f3a518d2 [gaim-migrate @ 11291]
Christian Hammond <chipx86@chipx86.com>
parents: 10153
diff changeset
1800 }
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1801 }
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1802
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1803 static GaimStatusSavedSub *
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1804 gaim_statuses_read_parse_substatus(xmlnode *substatus)
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1805 {
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1806 GaimStatusSavedSub *ret;
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1807 xmlnode *node;
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1808 const char *tmp;
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1809
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1810 ret = g_new0(GaimStatusSavedSub, 1);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1811
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1812 /* Read the account */
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1813 node = xmlnode_get_child(substatus, "account");
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1814 if (node != NULL)
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1815 {
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1816 const char *acct_name;
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1817 const char *protocol;
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1818 acct_name = xmlnode_get_data(node);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1819 protocol = xmlnode_get_attrib(node, "protocol");
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1820 if ((acct_name != NULL) && (protocol != NULL))
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1821 ret->account = gaim_accounts_find(acct_name, protocol);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1822 }
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1823
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1824 if (ret->account == NULL)
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1825 {
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1826 g_free(ret);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1827 return NULL;
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1828 }
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1829
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1830 /* Read the state */
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1831 node = xmlnode_get_child(substatus, "state");
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1832 if (node != NULL)
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1833 tmp = xmlnode_get_data(node);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1834 if (tmp != NULL)
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1835 ret->type = gaim_status_type_find_with_id(ret->account->status_types,
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1836 tmp);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1837
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1838 /* Read the message */
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1839 node = xmlnode_get_child(substatus, "message");
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1840 if (node != NULL)
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1841 tmp = xmlnode_get_data(node);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1842 if (tmp != NULL)
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1843 ret->message = g_strdup(tmp);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1844
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1845 return ret;
6065
3a40666c08b4 [gaim-migrate @ 6515]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1846 }
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1847
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1848 /**
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1849 * Parse a saved status and add it to the saved_statuses linked list.
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1850 *
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1851 * Here's an example of the XML for a saved status:
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1852 * <status name="Girls">
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1853 * <state>away</state>
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1854 * <message>I like the way that they walk
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1855 * And it's chill to hear them talk
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1856 * And I can always make them smile
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1857 * From White Castle to the Nile</message>
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1858 * <substatus>
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1859 * <account protocol='prpl-oscar'>markdoliner</account>
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1860 * <state>available</state>
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1861 * <message>The ladies man is here to answer your queries.</message>
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1862 * </substatus>
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1863 * <substatus>
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1864 * <account protocol='prpl-oscar'>giantgraypanda</account>
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1865 * <state>away</state>
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1866 * <message>A.C. ain't in charge no more.</message>
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1867 * </substatus>
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1868 * </status>
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1869 *
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1870 * I know. Moving, huh?
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1871 */
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1872 static GaimStatusSaved *
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1873 gaim_statuses_read_parse_status(xmlnode *status)
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1874 {
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1875 GaimStatusSaved *ret;
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1876 xmlnode *node;
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1877 const char *tmp;
10340
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1878 int i;
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1879
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1880 ret = g_new0(GaimStatusSaved, 1);
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1881
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1882 /* Read the title */
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1883 tmp = xmlnode_get_attrib(status, "name");
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1884 if (tmp == NULL)
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1885 tmp = "No Title";
10340
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1886 /* Ensure the title is unique */
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1887 ret->title = g_strdup(tmp);
10340
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1888 i = 2;
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1889 while (gaim_statuses_find_saved(ret->title) != NULL)
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1890 {
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1891 g_free(ret->title);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1892 ret->title = g_strdup_printf("%s %d", tmp, i);
10340
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1893 i++;
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1894 }
84d73473c019 [gaim-migrate @ 11549]
Mark Doliner <mark@kingant.net>
parents: 10337
diff changeset
1895
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1896 /* Read the primitive status type */
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1897 node = xmlnode_get_child(status, "state");
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1898 if (node != NULL)
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1899 tmp = xmlnode_get_data(node);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1900 if (tmp != NULL)
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1901 ret->type = gaim_primitive_get_type(tmp);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1902
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1903 /* Read the message */
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1904 node = xmlnode_get_child(status, "message");
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1905 if (node != NULL)
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1906 tmp = xmlnode_get_data(node);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1907 if (tmp != NULL)
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1908 ret->message = g_strdup(tmp);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1909
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1910 /* Read substatuses */
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1911 for (node = xmlnode_get_child(status, "status"); node != NULL;
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1912 node = xmlnode_get_next_twin(node))
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1913 {
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1914 GaimStatusSavedSub *new;
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1915 new = gaim_statuses_read_parse_substatus(node);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1916 if (new != NULL)
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1917 ret->substatuses = g_list_append(ret->substatuses, new);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1918 }
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1919
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1920 return ret;
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1921 }
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1922
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1923 /**
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1924 * @return TRUE on success, FALSE on failure (if the file can not
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1925 * be opened, or if it contains invalid XML).
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1926 */
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1927 static gboolean
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1928 gaim_statuses_read(const char *filename)
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1929 {
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1930 GError *error;
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1931 gchar *contents = NULL;
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1932 gsize length;
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1933 xmlnode *statuses, *status;
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1934
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1935 gaim_debug_info("status", "Reading %s\n", filename);
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1936
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1937 if (!g_file_get_contents(filename, &contents, &length, &error))
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1938 {
10343
ee4f477fc8cf [gaim-migrate @ 11553]
Mark Doliner <mark@kingant.net>
parents: 10340
diff changeset
1939 gaim_debug_error("status", "Error reading statuses: %s\n",
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1940 error->message);
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1941 g_error_free(error);
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1942 return FALSE;
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1943 }
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1944
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1945 statuses = xmlnode_from_str(contents, length);
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1946
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1947 if (statuses == NULL)
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1948 {
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1949 FILE *backup;
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1950 gchar *name;
10343
ee4f477fc8cf [gaim-migrate @ 11553]
Mark Doliner <mark@kingant.net>
parents: 10340
diff changeset
1951 gaim_debug_error("status", "Error parsing statuses\n");
ee4f477fc8cf [gaim-migrate @ 11553]
Mark Doliner <mark@kingant.net>
parents: 10340
diff changeset
1952 name = g_strdup_printf("%s~", filename);
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1953 if ((backup = fopen(name, "w")))
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1954 {
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1955 fwrite(contents, length, 1, backup);
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1956 fclose(backup);
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1957 chmod(name, S_IRUSR | S_IWUSR);
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1958 }
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1959 else
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1960 {
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1961 gaim_debug_error("status", "Unable to write backup %s\n", name);
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1962 }
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1963 g_free(name);
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1964 g_free(contents);
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1965 return FALSE;
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1966 }
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1967
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1968 g_free(contents);
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1969
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1970 for (status = xmlnode_get_child(statuses, "status"); status != NULL;
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1971 status = xmlnode_get_next_twin(status))
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1972 {
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1973 GaimStatusSaved *new;
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1974 new = gaim_statuses_read_parse_status(status);
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1975 saved_statuses = g_list_append(saved_statuses, new);
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1976 }
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1977
10343
ee4f477fc8cf [gaim-migrate @ 11553]
Mark Doliner <mark@kingant.net>
parents: 10340
diff changeset
1978 gaim_debug_info("status", "Finished reading statuses\n");
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1979
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1980 xmlnode_free(statuses);
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1981
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1982 return TRUE;
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1983 }
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1984
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1985 void
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1986 gaim_statuses_load(void)
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
1987 {
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1988 const char *user_dir = gaim_user_dir();
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1989 gchar *filename;
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1990 gchar *msg;
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1991
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1992 if (user_dir == NULL)
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1993 return;
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1994
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1995 filename = g_build_filename(user_dir, "status.xml", NULL);
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
1996
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1997 if (g_file_test(filename, G_FILE_TEST_EXISTS))
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1998 {
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
1999 if (!gaim_statuses_read(filename))
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
2000 {
10337
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
2001 msg = g_strdup_printf(_("An error was encountered parsing the "
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
2002 "file containing your saved statuses (%s). They "
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
2003 "have not been loaded, and the old file has been "
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
2004 "renamed to status.xml~."), filename);
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
2005 gaim_notify_error(NULL, NULL, _("Saved Statuses Error"), msg);
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
2006 g_free(msg);
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
2007 }
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
2008 }
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
2009
682201b69107 [gaim-migrate @ 11545]
Mark Doliner <mark@kingant.net>
parents: 10322
diff changeset
2010 g_free(filename);
9949
ced29c7b396c [gaim-migrate @ 10845]
Luke Schierer <lschiere@pidgin.im>
parents: 9944
diff changeset
2011 }
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
2012
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
2013 void
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
2014 gaim_statuses_sync(void)
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
2015 {
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
2016 /* TODO: Write me, baby. */
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10343
diff changeset
2017 }