Mercurial > pidgin.yaz
annotate src/prpl.c @ 9988:d770673338f4
[gaim-migrate @ 10901]
(15:20:15) grim elite: ok.. i just got to make a big #if 0 because the
custom away messages aren't setup yet :/
(15:30:01) grim elite: ok i've got it compiling.. couple of warnings yet..
(15:34:24) grim elite:
www.reaperworld.com/code/gaim/gaim-2.0.0cvs-oscar_compiles.diff
Mark should look this over, but it seems fairly straight forward
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Wed, 08 Sep 2004 19:36:04 +0000 |
parents | ced29c7b396c |
children | 9baedaca25c7 |
rev | line source |
---|---|
981 | 1 /* |
2 * gaim | |
3 * | |
8046 | 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. | |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
7 * |
981 | 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 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
23 #include "internal.h" |
5945
2a18e7b5917e
[gaim-migrate @ 6386]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
24 #include "conversation.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
25 #include "debug.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
26 #include "notify.h" |
981 | 27 #include "prpl.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
28 #include "request.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
29 #include "util.h" |
3738 | 30 |
9949 | 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 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
347 GaimPlugin * |
7956 | 348 gaim_find_prpl(const char *id) |
981 | 349 { |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
350 GList *l; |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
351 GaimPlugin *plugin; |
981 | 352 |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
353 for (l = gaim_plugins_get_protocols(); l != NULL; l = l->next) { |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
354 plugin = (GaimPlugin *)l->data; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
355 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
356 /* Just In Case (TM) */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
357 if (GAIM_IS_PROTOCOL_PLUGIN(plugin)) { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
358 |
7956 | 359 if (!strcmp(plugin->info->id, id)) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
360 return plugin; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
361 } |
981 | 362 } |
363 | |
364 return NULL; | |
365 } |