Mercurial > pidgin.yaz
annotate src/prpl.c @ 10040:81059dce3aed
[gaim-migrate @ 10999]
" Post all three of these to the sf patch tracker as
three separate patches and assign the buddy list
changes and oscar changes to me, and the
gaim_status_is_online() changes to Luke. And in the
one assigned to Luke, ask him if he could pretty please
with sugar on top check through it quickly and
commit it if it looks sensible?
--KingAnt
This adds gaim_status_is_online so that we can check
statuses as well as presences for online status. It
also changes gaim_presence_is_online to use the new
function." --Dave West
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sat, 18 Sep 2004 23:17:38 +0000 |
parents | 0ddc38f8db4a |
children | dcdda2857ca8 |
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 | |
10007 | 60 gaim_presence_set_login_time(presence, login_time); |
9949 | 61 } |
62 | |
63 static gboolean | |
64 set_value_from_arg(GaimStatus *status, const char *id, va_list *args) | |
65 { | |
66 GaimValue *value; | |
67 | |
68 value = gaim_status_get_attr_value(status, id); | |
69 | |
70 if (value == NULL) | |
71 { | |
72 gaim_debug_error("prpl", | |
73 "Attempted to set an unknown attribute %s on " | |
74 "status %s\n", | |
75 id, gaim_status_get_id(status)); | |
76 return FALSE; | |
77 } | |
78 | |
79 switch (gaim_value_get_type(value)) | |
80 { | |
81 case GAIM_TYPE_CHAR: | |
82 gaim_value_set_char(value, (char)va_arg(*args, int)); | |
83 break; | |
84 | |
85 case GAIM_TYPE_UCHAR: | |
86 gaim_value_set_uchar(value, | |
87 (unsigned char)va_arg(*args, unsigned int)); | |
88 break; | |
89 | |
90 case GAIM_TYPE_BOOLEAN: | |
91 gaim_value_set_boolean(value, va_arg(*args, gboolean)); | |
92 break; | |
93 | |
94 case GAIM_TYPE_SHORT: | |
95 gaim_value_set_short(value, (short)va_arg(*args, int)); | |
96 break; | |
97 | |
98 case GAIM_TYPE_USHORT: | |
99 gaim_value_set_ushort(value, | |
100 (unsigned short)va_arg(*args, unsigned int)); | |
101 break; | |
102 | |
103 case GAIM_TYPE_INT: | |
104 gaim_value_set_int(value, va_arg(*args, int)); | |
105 break; | |
106 | |
107 case GAIM_TYPE_UINT: | |
108 gaim_value_set_uint(value, va_arg(*args, unsigned int)); | |
109 break; | |
110 | |
111 case GAIM_TYPE_LONG: | |
112 gaim_value_set_long(value, va_arg(*args, long)); | |
113 break; | |
114 | |
115 case GAIM_TYPE_ULONG: | |
116 gaim_value_set_ulong(value, va_arg(*args, unsigned long)); | |
117 break; | |
118 | |
119 case GAIM_TYPE_INT64: | |
120 gaim_value_set_int64(value, va_arg(*args, gint64)); | |
121 break; | |
122 | |
123 case GAIM_TYPE_UINT64: | |
124 gaim_value_set_uint64(value, va_arg(*args, guint64)); | |
125 break; | |
126 | |
127 case GAIM_TYPE_STRING: | |
128 gaim_value_set_string(value, va_arg(*args, char *)); | |
129 break; | |
130 | |
131 case GAIM_TYPE_OBJECT: | |
132 gaim_value_set_object(value, va_arg(*args, void *)); | |
133 break; | |
134 | |
135 case GAIM_TYPE_POINTER: | |
136 gaim_value_set_pointer(value, va_arg(*args, void *)); | |
137 break; | |
138 | |
139 case GAIM_TYPE_ENUM: | |
140 gaim_value_set_enum(value, va_arg(*args, int)); | |
141 break; | |
142 | |
143 case GAIM_TYPE_BOXED: | |
144 gaim_value_set_boxed(value, va_arg(*args, void *)); | |
145 break; | |
146 | |
147 default: | |
148 return FALSE; | |
149 } | |
150 | |
151 return TRUE; | |
152 } | |
153 | |
154 void | |
155 gaim_prpl_got_account_status(GaimAccount *account, const char *status_id, | |
156 const char *attr_id, ...) | |
157 { | |
158 GaimPresence *presence; | |
159 GaimStatus *status; | |
160 | |
161 g_return_if_fail(account != NULL); | |
162 g_return_if_fail(status_id != NULL); | |
163 g_return_if_fail(gaim_account_is_connected(account)); | |
164 | |
165 presence = gaim_account_get_presence(account); | |
166 status = gaim_presence_get_status(presence, status_id); | |
167 | |
168 g_return_if_fail(status != NULL); | |
169 | |
170 if (attr_id != NULL) | |
171 { | |
172 va_list args; | |
173 | |
174 va_start(args, attr_id); | |
175 | |
176 while (attr_id != NULL) | |
177 { | |
178 set_value_from_arg(status, attr_id, &args); | |
179 | |
180 attr_id = va_arg(args, char *); | |
181 } | |
182 | |
183 va_end(args); | |
184 } | |
185 | |
186 gaim_presence_set_status_active(presence, status_id, TRUE); | |
187 } | |
188 | |
189 void | |
190 gaim_prpl_got_account_warning_level(GaimAccount *account, const char *username, | |
191 unsigned int level) | |
192 { | |
193 GaimPresence *presence; | |
194 unsigned int old_level; | |
10007 | 195 gchar *buf; |
9949 | 196 |
197 g_return_if_fail(account != NULL); | |
198 | |
199 presence = gaim_account_get_presence(account); | |
200 | |
201 gaim_signal_emit(gaim_accounts_get_handle(), "account-warned", | |
202 account, username, level); | |
203 | |
204 old_level = gaim_presence_get_warning_level(presence); | |
205 gaim_presence_set_warning_level(presence, level); | |
206 | |
207 if (old_level >= level) | |
208 return; | |
209 | |
10007 | 210 if (username == NULL) |
211 buf = g_strdup_printf(_("%s has just been warned by an anonymous " | |
212 "person.\nYour new warning level is %d%%"), | |
213 gaim_account_get_username(account), | |
214 level); | |
215 else | |
216 buf = g_strdup_printf(_("%s has just been warned by %s.\n" | |
217 "Your new warning level is %d%%"), | |
218 gaim_account_get_username(account), | |
219 username, level); | |
9949 | 220 |
10007 | 221 gaim_notify_info(NULL, NULL, buf, NULL); |
222 | |
223 g_free(buf); | |
9949 | 224 } |
225 | |
226 void | |
227 gaim_prpl_got_user_idle(GaimAccount *account, const char *name, | |
228 gboolean idle, time_t idle_time) | |
229 { | |
230 GaimBuddy *buddy; | |
10007 | 231 GaimPresence *presence; |
9949 | 232 |
233 g_return_if_fail(account != NULL); | |
234 g_return_if_fail(name != NULL); | |
235 g_return_if_fail(gaim_account_is_connected(account)); | |
236 | |
237 if ((buddy = gaim_find_buddy(account, name)) == NULL) | |
238 return; | |
239 | |
10007 | 240 presence = gaim_buddy_get_presence(buddy); |
241 | |
242 gaim_presence_set_idle(presence, idle, idle_time); | |
9949 | 243 } |
244 | |
245 void | |
246 gaim_prpl_got_user_login_time(GaimAccount *account, const char *name, | |
247 time_t login_time) | |
248 { | |
249 GaimBuddy *buddy; | |
250 GaimPresence *presence; | |
251 | |
252 g_return_if_fail(account != NULL); | |
253 g_return_if_fail(name != NULL); | |
254 | |
255 if ((buddy = gaim_find_buddy(account, name)) == NULL) | |
256 return; | |
257 | |
258 if (login_time == 0) | |
259 login_time = time(NULL); | |
260 | |
261 presence = gaim_buddy_get_presence(buddy); | |
262 | |
10006 | 263 gaim_presence_set_login_time(presence, login_time); |
9949 | 264 } |
265 | |
266 void | |
267 gaim_prpl_got_user_status(GaimAccount *account, const char *name, | |
268 const char *status_id, const char *attr_id, ...) | |
269 { | |
270 GaimBuddy *buddy; | |
271 GaimPresence *presence; | |
272 GaimStatus *status; | |
273 | |
274 g_return_if_fail(account != NULL); | |
275 g_return_if_fail(name != NULL); | |
276 g_return_if_fail(status_id != NULL); | |
277 g_return_if_fail(gaim_account_is_connected(account)); | |
278 | |
279 if ((buddy = gaim_find_buddy(account, name)) == NULL) | |
280 return; | |
281 | |
282 presence = gaim_buddy_get_presence(buddy); | |
283 status = gaim_presence_get_status(presence, status_id); | |
284 | |
285 g_return_if_fail(status != NULL); | |
286 | |
287 if (attr_id != NULL) | |
288 { | |
289 va_list args; | |
290 | |
291 va_start(args, attr_id); | |
292 | |
293 while (attr_id != NULL) | |
294 { | |
295 set_value_from_arg(status, attr_id, &args); | |
296 | |
297 attr_id = va_arg(args, char *); | |
298 } | |
299 | |
300 va_end(args); | |
301 } | |
302 | |
303 gaim_presence_set_status_active(presence, status_id, TRUE); | |
10012 | 304 |
305 gaim_blist_update_buddy_presence(buddy, GAIM_BUDDY_IS_ONLINE(buddy)); | |
306 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); | |
9949 | 307 } |
308 | |
309 void | |
310 gaim_prpl_got_user_warning_level(GaimAccount *account, const char *name, | |
311 unsigned int level) | |
312 { | |
313 GaimBuddy *buddy; | |
10007 | 314 GaimPresence *presence; |
9949 | 315 |
316 g_return_if_fail(account != NULL); | |
317 g_return_if_fail(name != NULL); | |
318 | |
319 if ((buddy = gaim_find_buddy(account, name)) == NULL) | |
320 return; | |
321 | |
10007 | 322 presence = gaim_buddy_get_presence(buddy); |
323 | |
324 gaim_presence_set_warning_level(presence, level); | |
9949 | 325 } |
326 | |
327 void | |
328 gaim_prpl_set_account_status(GaimAccount *account, GaimStatus *status) | |
329 { | |
330 GaimPlugin *prpl; | |
331 GaimPluginProtocolInfo *prpl_info; | |
332 | |
333 g_return_if_fail(account != NULL); | |
334 g_return_if_fail(status != NULL); | |
335 | |
336 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); | |
337 | |
338 if (prpl == NULL) | |
339 return; | |
340 | |
341 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
342 | |
343 if (prpl_info->set_status != NULL) | |
344 prpl_info->set_status(account, status); | |
345 } | |
346 | |
10006 | 347 GList * |
348 gaim_prpl_get_statuses(GaimAccount *account, GaimPresence *presence) | |
349 { | |
350 GaimPlugin *prpl; | |
351 GaimPluginProtocolInfo *prpl_info; | |
352 GList *statuses = NULL; | |
353 GList *l; | |
354 GaimStatus *status; | |
355 | |
356 g_return_val_if_fail(account != NULL, NULL); | |
357 g_return_val_if_fail(presence != NULL, NULL); | |
358 | |
359 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); | |
360 | |
361 if (prpl == NULL) | |
362 return NULL; | |
363 | |
364 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
365 if (prpl_info == NULL || prpl_info->status_types == NULL) | |
366 return NULL; | |
367 | |
368 for (l = prpl_info->status_types(account); l != NULL; l = l->next) | |
369 { | |
370 status = gaim_status_new((GaimStatusType *)l->data, presence); | |
371 statuses = g_list_append(statuses, status); | |
372 } | |
373 | |
374 return statuses; | |
375 } | |
376 | |
9949 | 377 |
378 /************************************************************************** | |
379 * Protocol Plugin Subsystem API | |
380 **************************************************************************/ | |
381 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
382 GaimPlugin * |
7956 | 383 gaim_find_prpl(const char *id) |
981 | 384 { |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
385 GList *l; |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
386 GaimPlugin *plugin; |
981 | 387 |
10036
0ddc38f8db4a
[gaim-migrate @ 10995]
Luke Schierer <lschiere@pidgin.im>
parents:
10023
diff
changeset
|
388 g_return_val_if_fail(id != NULL, NULL); |
0ddc38f8db4a
[gaim-migrate @ 10995]
Luke Schierer <lschiere@pidgin.im>
parents:
10023
diff
changeset
|
389 |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
390 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
|
391 plugin = (GaimPlugin *)l->data; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
392 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
393 /* Just In Case (TM) */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
394 if (GAIM_IS_PROTOCOL_PLUGIN(plugin)) { |
7956 | 395 if (!strcmp(plugin->info->id, id)) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
396 return plugin; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
397 } |
981 | 398 } |
399 | |
400 return NULL; | |
401 } |