14192
|
1 /*
|
|
2 * gaim
|
|
3 *
|
|
4 * Gaim is the legal property of its developers, whose names are too numerous
|
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
6 * source distribution.
|
|
7 *
|
|
8 * This program is free software; you can redistribute it and/or modify
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
10 * the Free Software Foundation; either version 2 of the License, or
|
|
11 * (at your option) any later version.
|
|
12 *
|
|
13 * This program is distributed in the hope that it will be useful,
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 * GNU General Public License for more details.
|
|
17 *
|
|
18 * You should have received a copy of the GNU General Public License
|
|
19 * along with this program; if not, write to the Free Software
|
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 *
|
|
22 */
|
|
23 #include "internal.h"
|
|
24 #include "conversation.h"
|
|
25 #include "debug.h"
|
|
26 #include "notify.h"
|
|
27 #include "prpl.h"
|
|
28 #include "request.h"
|
|
29 #include "util.h"
|
|
30
|
|
31 /**************************************************************************/
|
|
32 /** @name Protocol Plugin API */
|
|
33 /**************************************************************************/
|
|
34 void
|
|
35 gaim_prpl_got_account_idle(GaimAccount *account, gboolean idle,
|
|
36 time_t idle_time)
|
|
37 {
|
|
38 g_return_if_fail(account != NULL);
|
|
39 g_return_if_fail(gaim_account_is_connected(account));
|
|
40
|
|
41 gaim_presence_set_idle(gaim_account_get_presence(account),
|
|
42 idle, idle_time);
|
|
43 }
|
|
44
|
|
45 void
|
|
46 gaim_prpl_got_account_login_time(GaimAccount *account, time_t login_time)
|
|
47 {
|
|
48 GaimPresence *presence;
|
|
49
|
|
50 g_return_if_fail(account != NULL);
|
|
51 g_return_if_fail(gaim_account_is_connected(account));
|
|
52
|
|
53 if (login_time == 0)
|
|
54 login_time = time(NULL);
|
|
55
|
|
56 presence = gaim_account_get_presence(account);
|
|
57
|
|
58 gaim_presence_set_login_time(presence, login_time);
|
|
59 }
|
|
60
|
|
61 void
|
|
62 gaim_prpl_got_account_status(GaimAccount *account, const char *status_id, ...)
|
|
63 {
|
|
64 GaimPresence *presence;
|
|
65 GaimStatus *status;
|
|
66 va_list args;
|
|
67
|
|
68 g_return_if_fail(account != NULL);
|
|
69 g_return_if_fail(status_id != NULL);
|
|
70 g_return_if_fail(gaim_account_is_connected(account));
|
|
71
|
|
72 presence = gaim_account_get_presence(account);
|
|
73 status = gaim_presence_get_status(presence, status_id);
|
|
74
|
|
75 g_return_if_fail(status != NULL);
|
|
76
|
|
77 va_start(args, status_id);
|
|
78 gaim_status_set_active_with_attrs(status, TRUE, args);
|
|
79 va_end(args);
|
|
80 }
|
|
81
|
|
82 void
|
|
83 gaim_prpl_got_user_idle(GaimAccount *account, const char *name,
|
|
84 gboolean idle, time_t idle_time)
|
|
85 {
|
|
86 GaimBuddy *buddy;
|
|
87 GaimPresence *presence;
|
|
88
|
|
89 g_return_if_fail(account != NULL);
|
|
90 g_return_if_fail(name != NULL);
|
|
91 g_return_if_fail(gaim_account_is_connected(account));
|
|
92
|
|
93 if ((buddy = gaim_find_buddy(account, name)) == NULL)
|
|
94 return;
|
|
95
|
|
96 presence = gaim_buddy_get_presence(buddy);
|
|
97
|
|
98 gaim_presence_set_idle(presence, idle, idle_time);
|
|
99 }
|
|
100
|
|
101 void
|
|
102 gaim_prpl_got_user_login_time(GaimAccount *account, const char *name,
|
|
103 time_t login_time)
|
|
104 {
|
|
105 GaimBuddy *buddy;
|
|
106 GaimPresence *presence;
|
|
107
|
|
108 g_return_if_fail(account != NULL);
|
|
109 g_return_if_fail(name != NULL);
|
|
110
|
|
111 if ((buddy = gaim_find_buddy(account, name)) == NULL)
|
|
112 return;
|
|
113
|
|
114 if (login_time == 0)
|
|
115 login_time = time(NULL);
|
|
116
|
|
117 presence = gaim_buddy_get_presence(buddy);
|
|
118
|
|
119 gaim_presence_set_login_time(presence, login_time);
|
|
120 }
|
|
121
|
|
122 void
|
|
123 gaim_prpl_got_user_status(GaimAccount *account, const char *name,
|
|
124 const char *status_id, ...)
|
|
125 {
|
|
126 GSList *list;
|
|
127 GaimBuddy *buddy;
|
|
128 GaimPresence *presence;
|
|
129 GaimStatus *status;
|
|
130 GaimStatus *old_status;
|
|
131 va_list args;
|
|
132
|
|
133 g_return_if_fail(account != NULL);
|
|
134 g_return_if_fail(name != NULL);
|
|
135 g_return_if_fail(status_id != NULL);
|
|
136 g_return_if_fail(gaim_account_is_connected(account) || gaim_account_is_connecting(account));
|
|
137
|
|
138 if ((buddy = gaim_find_buddy(account, name)) == NULL)
|
|
139 return;
|
|
140
|
|
141 presence = gaim_buddy_get_presence(buddy);
|
|
142 status = gaim_presence_get_status(presence, status_id);
|
|
143
|
|
144 g_return_if_fail(status != NULL);
|
|
145
|
|
146 old_status = gaim_presence_get_active_status(presence);
|
|
147
|
|
148 va_start(args, status_id);
|
|
149 gaim_status_set_active_with_attrs(status, TRUE, args);
|
|
150 va_end(args);
|
|
151
|
|
152 list = gaim_find_buddies(account, name);
|
|
153 g_slist_foreach(list, (GFunc)gaim_blist_update_buddy_status, old_status);
|
|
154 g_slist_free(list);
|
|
155
|
|
156 if (!gaim_status_is_online(status))
|
|
157 serv_got_typing_stopped(gaim_account_get_connection(account), name);
|
|
158 }
|
|
159
|
|
160 static void
|
|
161 do_prpl_change_account_status(GaimAccount *account,
|
|
162 GaimStatus *old_status, GaimStatus *new_status)
|
|
163 {
|
|
164 GaimPlugin *prpl;
|
|
165 GaimPluginProtocolInfo *prpl_info;
|
|
166
|
|
167 if (gaim_status_is_online(new_status) &&
|
|
168 gaim_account_is_disconnected(account))
|
|
169 {
|
|
170 gaim_account_connect(account);
|
|
171 return;
|
|
172 }
|
|
173
|
|
174 if (!gaim_status_is_online(new_status))
|
|
175 {
|
|
176 if (!gaim_account_is_disconnected(account))
|
|
177 gaim_account_disconnect(account);
|
|
178 return;
|
|
179 }
|
|
180
|
|
181 if (gaim_account_is_connecting(account))
|
|
182 /*
|
|
183 * We don't need to call the set_status PRPL function because
|
|
184 * the PRPL will take care of setting its status during the
|
|
185 * connection process.
|
|
186 */
|
|
187 return;
|
|
188
|
|
189 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));
|
|
190
|
|
191 if (prpl == NULL)
|
|
192 return;
|
|
193
|
|
194 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
|
|
195
|
|
196 if (!gaim_account_is_disconnected(account) && prpl_info->set_status != NULL)
|
|
197 {
|
|
198 prpl_info->set_status(account, new_status);
|
|
199 }
|
|
200 }
|
|
201
|
|
202 void
|
|
203 gaim_prpl_change_account_status(GaimAccount *account,
|
|
204 GaimStatus *old_status, GaimStatus *new_status)
|
|
205 {
|
|
206 g_return_if_fail(account != NULL);
|
|
207 g_return_if_fail(old_status != NULL);
|
|
208 g_return_if_fail(new_status != NULL);
|
|
209
|
|
210 do_prpl_change_account_status(account, old_status, new_status);
|
|
211
|
|
212 gaim_signal_emit(gaim_accounts_get_handle(), "account-status-changed",
|
|
213 account, old_status, new_status);
|
|
214 }
|
|
215
|
|
216 GList *
|
|
217 gaim_prpl_get_statuses(GaimAccount *account, GaimPresence *presence)
|
|
218 {
|
|
219 GaimPlugin *prpl;
|
|
220 GaimPluginProtocolInfo *prpl_info;
|
|
221 GList *statuses = NULL;
|
|
222 GList *l, *list;
|
|
223 GaimStatus *status;
|
|
224
|
|
225 g_return_val_if_fail(account != NULL, NULL);
|
|
226 g_return_val_if_fail(presence != NULL, NULL);
|
|
227
|
|
228 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));
|
|
229
|
|
230 if (prpl == NULL)
|
|
231 return NULL;
|
|
232
|
|
233 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
|
|
234 if (prpl_info == NULL || prpl_info->status_types == NULL)
|
|
235 return NULL;
|
|
236
|
|
237 for (l = list = prpl_info->status_types(account); l != NULL; l = l->next)
|
|
238 {
|
|
239 status = gaim_status_new((GaimStatusType *)l->data, presence);
|
|
240 statuses = g_list_append(statuses, status);
|
|
241 }
|
|
242
|
|
243 g_list_free(list);
|
|
244
|
|
245 return statuses;
|
|
246 }
|
|
247
|
|
248
|
|
249 /**************************************************************************
|
|
250 * Protocol Plugin Subsystem API
|
|
251 **************************************************************************/
|
|
252
|
|
253 GaimPlugin *
|
|
254 gaim_find_prpl(const char *id)
|
|
255 {
|
|
256 GList *l;
|
|
257 GaimPlugin *plugin;
|
|
258
|
|
259 g_return_val_if_fail(id != NULL, NULL);
|
|
260
|
|
261 for (l = gaim_plugins_get_protocols(); l != NULL; l = l->next) {
|
|
262 plugin = (GaimPlugin *)l->data;
|
|
263
|
|
264 if (!strcmp(plugin->info->id, id))
|
|
265 return plugin;
|
|
266 }
|
|
267
|
|
268 return NULL;
|
|
269 }
|