Mercurial > pidgin
annotate src/prpl.c @ 10749:3839df4f7074
[gaim-migrate @ 12351]
This fixes the auto-reconnect plugin bug. The whole "wants_to_die"
thing feels a little dirty. Eh, it's fine for now.
Also, the gtkstatusbox starts off in the "available" state instead
of using the GaimStatus of whatever account is online. This negates
the effect of saving the GaimStatuses for an account.
More tomorrow...
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 27 Mar 2005 05:17:18 +0000 |
parents | 0ad82505bde8 |
children | b75ce371c812 |
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 { | |
10554 | 230 GSList *l; |
9949 | 231 |
232 g_return_if_fail(account != NULL); | |
233 g_return_if_fail(name != NULL); | |
234 g_return_if_fail(gaim_account_is_connected(account)); | |
235 | |
10554 | 236 for (l = gaim_find_buddies(account, name); l != NULL; l = l->next) |
237 { | |
238 GaimBuddy *buddy; | |
239 GaimPresence *presence; | |
9949 | 240 |
10554 | 241 buddy = (GaimBuddy *)l->data; |
10007 | 242 |
10554 | 243 presence = gaim_buddy_get_presence(buddy); |
244 | |
245 gaim_presence_set_idle(presence, idle, idle_time); | |
246 } | |
9949 | 247 } |
248 | |
249 void | |
250 gaim_prpl_got_user_login_time(GaimAccount *account, const char *name, | |
251 time_t login_time) | |
252 { | |
10554 | 253 GSList *l; |
9949 | 254 |
255 g_return_if_fail(account != NULL); | |
256 g_return_if_fail(name != NULL); | |
257 | |
10554 | 258 for (l = gaim_find_buddies(account, name); l != NULL; l = l->next) |
259 { | |
260 GaimBuddy *buddy; | |
261 GaimPresence *presence; | |
262 | |
263 buddy = (GaimBuddy *)l->data; | |
9949 | 264 |
10554 | 265 if (login_time == 0) |
266 login_time = time(NULL); | |
9949 | 267 |
10554 | 268 presence = gaim_buddy_get_presence(buddy); |
9949 | 269 |
10554 | 270 gaim_presence_set_login_time(presence, login_time); |
271 } | |
9949 | 272 } |
273 | |
274 void | |
275 gaim_prpl_got_user_status(GaimAccount *account, const char *name, | |
276 const char *status_id, const char *attr_id, ...) | |
277 { | |
10554 | 278 GSList *l; |
9949 | 279 |
280 g_return_if_fail(account != NULL); | |
281 g_return_if_fail(name != NULL); | |
282 g_return_if_fail(status_id != NULL); | |
283 g_return_if_fail(gaim_account_is_connected(account)); | |
284 | |
10554 | 285 for (l = gaim_find_buddies(account, name); l != NULL; l = l->next) |
286 { | |
287 GaimBuddy *buddy; | |
288 GaimPresence *presence; | |
289 GaimStatus *status; | |
290 GaimStatus *old_status; | |
9949 | 291 |
10554 | 292 buddy = (GaimBuddy *)l->data; |
293 presence = gaim_buddy_get_presence(buddy); | |
294 status = gaim_presence_get_status(presence, status_id); | |
9949 | 295 |
10554 | 296 g_return_if_fail(status != NULL); |
9949 | 297 |
10554 | 298 if (attr_id != NULL) |
299 { | |
300 va_list args; | |
9949 | 301 |
10554 | 302 va_start(args, attr_id); |
9949 | 303 |
10554 | 304 while (attr_id != NULL) |
305 { | |
306 set_value_from_arg(status, attr_id, &args); | |
9949 | 307 |
10554 | 308 attr_id = va_arg(args, char *); |
309 } | |
310 | |
311 va_end(args); | |
9949 | 312 } |
313 | |
10554 | 314 old_status = gaim_presence_get_active_status(presence); |
315 gaim_presence_set_status_active(presence, status_id, TRUE); | |
316 gaim_blist_update_buddy_status(buddy, old_status); | |
9949 | 317 } |
318 } | |
319 | |
320 void | |
321 gaim_prpl_got_user_warning_level(GaimAccount *account, const char *name, | |
322 unsigned int level) | |
323 { | |
10554 | 324 GSList *l; |
9949 | 325 |
326 g_return_if_fail(account != NULL); | |
327 g_return_if_fail(name != NULL); | |
328 | |
10554 | 329 for (l = gaim_find_buddies(account, name); l != NULL; l = l->next) |
330 { | |
331 GaimBuddy *buddy; | |
332 GaimPresence *presence; | |
9949 | 333 |
10554 | 334 buddy = (GaimBuddy *)l->data; |
10007 | 335 |
10554 | 336 presence = gaim_buddy_get_presence(buddy); |
337 | |
338 gaim_presence_set_warning_level(presence, level); | |
339 } | |
9949 | 340 } |
341 | |
342 void | |
10447 | 343 gaim_prpl_change_account_status(GaimAccount *account, |
344 GaimStatus *old_status, GaimStatus *new_status) | |
9949 | 345 { |
346 GaimPlugin *prpl; | |
347 GaimPluginProtocolInfo *prpl_info; | |
348 | |
10447 | 349 g_return_if_fail(account != NULL); |
350 g_return_if_fail(old_status != NULL); | |
351 g_return_if_fail(new_status != NULL); | |
9949 | 352 |
353 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); | |
354 | |
355 if (prpl == NULL) | |
356 return; | |
357 | |
358 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
359 | |
360 if (prpl_info->set_status != NULL) | |
10447 | 361 prpl_info->set_status(account, new_status); |
9949 | 362 } |
363 | |
10006 | 364 GList * |
365 gaim_prpl_get_statuses(GaimAccount *account, GaimPresence *presence) | |
366 { | |
367 GaimPlugin *prpl; | |
368 GaimPluginProtocolInfo *prpl_info; | |
369 GList *statuses = NULL; | |
370 GList *l; | |
371 GaimStatus *status; | |
372 | |
10447 | 373 g_return_val_if_fail(account != NULL, NULL); |
10006 | 374 g_return_val_if_fail(presence != NULL, NULL); |
375 | |
376 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); | |
10046 | 377 |
10006 | 378 if (prpl == NULL) |
379 return NULL; | |
10046 | 380 |
10006 | 381 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
382 if (prpl_info == NULL || prpl_info->status_types == NULL) | |
383 return NULL; | |
384 | |
385 for (l = prpl_info->status_types(account); l != NULL; l = l->next) | |
386 { | |
387 status = gaim_status_new((GaimStatusType *)l->data, presence); | |
388 statuses = g_list_append(statuses, status); | |
389 } | |
390 | |
391 return statuses; | |
392 } | |
393 | |
9949 | 394 |
395 /************************************************************************** | |
396 * Protocol Plugin Subsystem API | |
397 **************************************************************************/ | |
398 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
399 GaimPlugin * |
7956 | 400 gaim_find_prpl(const char *id) |
981 | 401 { |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
402 GList *l; |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
403 GaimPlugin *plugin; |
981 | 404 |
10036
0ddc38f8db4a
[gaim-migrate @ 10995]
Luke Schierer <lschiere@pidgin.im>
parents:
10023
diff
changeset
|
405 g_return_val_if_fail(id != NULL, NULL); |
0ddc38f8db4a
[gaim-migrate @ 10995]
Luke Schierer <lschiere@pidgin.im>
parents:
10023
diff
changeset
|
406 |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
407 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
|
408 plugin = (GaimPlugin *)l->data; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
409 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
410 /* Just In Case (TM) */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
411 if (GAIM_IS_PROTOCOL_PLUGIN(plugin)) { |
7956 | 412 if (!strcmp(plugin->info->id, id)) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
413 return plugin; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
414 } |
981 | 415 } |
416 | |
417 return NULL; | |
418 } |