comparison src/prpl.c @ 9949:ced29c7b396c

[gaim-migrate @ 10845] (00:25:10) LSchiere: datallah: commit message? (00:25:40) datallah: LSchiere: nah.. nothing comes to me datallah undertook the heroic effort of merging in all the .rejs and fixing things up from the unclean merge of the status rewrite committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Sat, 04 Sep 2004 04:27:05 +0000
parents eae7e049d639
children 9baedaca25c7
comparison
equal deleted inserted replaced
9948:b13013595c08 9949:ced29c7b396c
26 #include "notify.h" 26 #include "notify.h"
27 #include "prpl.h" 27 #include "prpl.h"
28 #include "request.h" 28 #include "request.h"
29 #include "util.h" 29 #include "util.h"
30 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, const char *name,
47 time_t login_time)
48 {
49 GaimPresence *presence;
50
51 g_return_if_fail(account != NULL);
52 g_return_if_fail(name != NULL && *name != '\0');
53 g_return_if_fail(gaim_account_is_connected(account));
54
55 if (login_time == 0)
56 login_time = time(NULL);
57
58 presence = gaim_account_get_presence(account);
59
60 /*
61 * TODO: Set a presence's sign-on time. We don't support this yet.
62 */
63 gaim_debug_warning("prpl",
64 "Attempting to set an account's sign-on time, but we "
65 "don't support this yet! FIX IT!\n");
66 }
67
68 static gboolean
69 set_value_from_arg(GaimStatus *status, const char *id, va_list *args)
70 {
71 GaimValue *value;
72
73 value = gaim_status_get_attr_value(status, id);
74
75 if (value == NULL)
76 {
77 gaim_debug_error("prpl",
78 "Attempted to set an unknown attribute %s on "
79 "status %s\n",
80 id, gaim_status_get_id(status));
81 return FALSE;
82 }
83
84 switch (gaim_value_get_type(value))
85 {
86 case GAIM_TYPE_CHAR:
87 gaim_value_set_char(value, (char)va_arg(*args, int));
88 break;
89
90 case GAIM_TYPE_UCHAR:
91 gaim_value_set_uchar(value,
92 (unsigned char)va_arg(*args, unsigned int));
93 break;
94
95 case GAIM_TYPE_BOOLEAN:
96 gaim_value_set_boolean(value, va_arg(*args, gboolean));
97 break;
98
99 case GAIM_TYPE_SHORT:
100 gaim_value_set_short(value, (short)va_arg(*args, int));
101 break;
102
103 case GAIM_TYPE_USHORT:
104 gaim_value_set_ushort(value,
105 (unsigned short)va_arg(*args, unsigned int));
106 break;
107
108 case GAIM_TYPE_INT:
109 gaim_value_set_int(value, va_arg(*args, int));
110 break;
111
112 case GAIM_TYPE_UINT:
113 gaim_value_set_uint(value, va_arg(*args, unsigned int));
114 break;
115
116 case GAIM_TYPE_LONG:
117 gaim_value_set_long(value, va_arg(*args, long));
118 break;
119
120 case GAIM_TYPE_ULONG:
121 gaim_value_set_ulong(value, va_arg(*args, unsigned long));
122 break;
123
124 case GAIM_TYPE_INT64:
125 gaim_value_set_int64(value, va_arg(*args, gint64));
126 break;
127
128 case GAIM_TYPE_UINT64:
129 gaim_value_set_uint64(value, va_arg(*args, guint64));
130 break;
131
132 case GAIM_TYPE_STRING:
133 gaim_value_set_string(value, va_arg(*args, char *));
134 break;
135
136 case GAIM_TYPE_OBJECT:
137 gaim_value_set_object(value, va_arg(*args, void *));
138 break;
139
140 case GAIM_TYPE_POINTER:
141 gaim_value_set_pointer(value, va_arg(*args, void *));
142 break;
143
144 case GAIM_TYPE_ENUM:
145 gaim_value_set_enum(value, va_arg(*args, int));
146 break;
147
148 case GAIM_TYPE_BOXED:
149 gaim_value_set_boxed(value, va_arg(*args, void *));
150 break;
151
152 default:
153 return FALSE;
154 }
155
156 return TRUE;
157 }
158
159 void
160 gaim_prpl_got_account_status(GaimAccount *account, const char *status_id,
161 const char *attr_id, ...)
162 {
163 GaimPresence *presence;
164 GaimStatus *status;
165
166 g_return_if_fail(account != NULL);
167 g_return_if_fail(status_id != NULL);
168 g_return_if_fail(gaim_account_is_connected(account));
169
170 presence = gaim_account_get_presence(account);
171 status = gaim_presence_get_status(presence, status_id);
172
173 g_return_if_fail(status != NULL);
174
175 if (attr_id != NULL)
176 {
177 va_list args;
178
179 va_start(args, attr_id);
180
181 while (attr_id != NULL)
182 {
183 set_value_from_arg(status, attr_id, &args);
184
185 attr_id = va_arg(args, char *);
186 }
187
188 va_end(args);
189 }
190
191 gaim_presence_set_status_active(presence, status_id, TRUE);
192 }
193
194 void
195 gaim_prpl_got_account_warning_level(GaimAccount *account, const char *username,
196 unsigned int level)
197 {
198 GaimPresence *presence;
199 unsigned int old_level;
200 char buf2[1024];
201
202 g_return_if_fail(account != NULL);
203
204 presence = gaim_account_get_presence(account);
205
206 gaim_signal_emit(gaim_accounts_get_handle(), "account-warned",
207 account, username, level);
208
209 old_level = gaim_presence_get_warning_level(presence);
210 gaim_presence_set_warning_level(presence, level);
211
212 if (old_level >= level)
213 return;
214
215 g_snprintf(buf2, sizeof(buf2),
216 _("%s has just been warned by %s.\n"
217 "Your new warning level is %d%%"),
218 gaim_account_get_username(account),
219 (username == NULL ? _("an anonymous person") : username),
220 level);
221
222 gaim_notify_info(NULL, NULL, buf2, NULL);
223 }
224
225 void
226 gaim_prpl_got_user_idle(GaimAccount *account, const char *name,
227 gboolean idle, time_t idle_time)
228 {
229 GaimBuddy *buddy;
230
231 g_return_if_fail(account != NULL);
232 g_return_if_fail(name != NULL);
233 g_return_if_fail(gaim_account_is_connected(account));
234
235 if ((buddy = gaim_find_buddy(account, name)) == NULL)
236 return;
237
238 gaim_presence_set_idle(gaim_buddy_get_presence(buddy), idle, idle_time);
239 }
240
241 void
242 gaim_prpl_got_user_login_time(GaimAccount *account, const char *name,
243 time_t login_time)
244 {
245 GaimBuddy *buddy;
246 GaimPresence *presence;
247
248 g_return_if_fail(account != NULL);
249 g_return_if_fail(name != NULL);
250
251 if ((buddy = gaim_find_buddy(account, name)) == NULL)
252 return;
253
254 if (login_time == 0)
255 login_time = time(NULL);
256
257 presence = gaim_buddy_get_presence(buddy);
258
259 /*
260 * TODO: Set a presence's sign-on time. We don't support this yet.
261 */
262 gaim_debug_warning("prpl",
263 "Attempting to set a user's sign-on time, but we "
264 "don't support this yet! FIX IT!\n");
265 }
266
267 void
268 gaim_prpl_got_user_status(GaimAccount *account, const char *name,
269 const char *status_id, const char *attr_id, ...)
270 {
271 GaimBuddy *buddy;
272 GaimPresence *presence;
273 GaimStatus *status;
274
275 g_return_if_fail(account != NULL);
276 g_return_if_fail(name != NULL);
277 g_return_if_fail(status_id != NULL);
278 g_return_if_fail(gaim_account_is_connected(account));
279
280 if ((buddy = gaim_find_buddy(account, name)) == NULL)
281 return;
282
283 presence = gaim_buddy_get_presence(buddy);
284 status = gaim_presence_get_status(presence, status_id);
285
286 g_return_if_fail(status != NULL);
287
288 if (attr_id != NULL)
289 {
290 va_list args;
291
292 va_start(args, attr_id);
293
294 while (attr_id != NULL)
295 {
296 set_value_from_arg(status, attr_id, &args);
297
298 attr_id = va_arg(args, char *);
299 }
300
301 va_end(args);
302 }
303
304 gaim_presence_set_status_active(presence, status_id, TRUE);
305 }
306
307 void
308 gaim_prpl_got_user_warning_level(GaimAccount *account, const char *name,
309 unsigned int level)
310 {
311 GaimBuddy *buddy;
312
313 g_return_if_fail(account != NULL);
314 g_return_if_fail(name != NULL);
315
316 if ((buddy = gaim_find_buddy(account, name)) == NULL)
317 return;
318
319 gaim_presence_set_warning_level(gaim_buddy_get_presence(buddy), level);
320 }
321
322 void
323 gaim_prpl_set_account_status(GaimAccount *account, GaimStatus *status)
324 {
325 GaimPlugin *prpl;
326 GaimPluginProtocolInfo *prpl_info;
327
328 g_return_if_fail(account != NULL);
329 g_return_if_fail(status != NULL);
330
331 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));
332
333 if (prpl == NULL)
334 return;
335
336 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
337
338 if (prpl_info->set_status != NULL)
339 prpl_info->set_status(account, status);
340 }
341
342
343 /**************************************************************************
344 * Protocol Plugin Subsystem API
345 **************************************************************************/
346
31 GaimPlugin * 347 GaimPlugin *
32 gaim_find_prpl(const char *id) 348 gaim_find_prpl(const char *id)
33 { 349 {
34 GList *l; 350 GList *l;
35 GaimPlugin *plugin; 351 GaimPlugin *plugin;