Mercurial > pidgin.yaz
annotate libgaim/account.c @ 15000:82d1a2fc6d25
[gaim-migrate @ 17778]
SF Patch #1598994 from lexande
Fixes SF Bug #1581999
Original Description:
"The gaim 2.0.0beta5 log reader plugin uses the "Date" XML field in MSN logs, the format of which varies between locales, leading to logs being displayed on incorrect/future dates in locales that do not use the MM/DD/YYYY format. This patch fixes the plugin to use the "DateTime" field which has YYYY-MM-DD date in all locales."
I totally Warmenhovened this patch. My approach:
"I'm using the Date, Time, and DateTime fields. If I can determine that the log matches the current timezone, it'll display 100% properly in the log viewer. If it has a reasonable offset, it'll display as the original time, sort in the right place, but not have a timezone abbreviation. If the offset is bogus or I can't parse the Date or Time field, it'll display in UTC, but still sort properly. I think this is as ideal as is possible, given the data we have to work with."
You don't have to understand this. ;)
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sun, 19 Nov 2006 06:54:38 +0000 |
parents | 633d4c25e82c |
children | 577ddea3ab82 |
rev | line source |
---|---|
14192 | 1 /** |
2 * @file account.c Account API | |
3 * @ingroup core | |
4 * | |
5 * gaim | |
6 * | |
7 * Gaim is the legal property of its developers, whose names are too numerous | |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
25 #include "internal.h" | |
26 #include "account.h" | |
27 #include "core.h" | |
28 #include "dbus-maybe.h" | |
29 #include "debug.h" | |
14696 | 30 #include "network.h" |
14192 | 31 #include "notify.h" |
32 #include "pounce.h" | |
33 #include "prefs.h" | |
34 #include "privacy.h" | |
35 #include "prpl.h" | |
36 #include "request.h" | |
37 #include "server.h" | |
38 #include "signals.h" | |
39 #include "status.h" | |
40 #include "util.h" | |
41 #include "xmlnode.h" | |
42 | |
43 /* TODO: Should use GaimValue instead of this? What about "ui"? */ | |
44 typedef struct | |
45 { | |
46 GaimPrefType type; | |
47 | |
48 char *ui; | |
49 | |
50 union | |
51 { | |
52 int integer; | |
53 char *string; | |
54 gboolean bool; | |
55 | |
56 } value; | |
57 | |
58 } GaimAccountSetting; | |
59 | |
60 | |
61 static GaimAccountUiOps *account_ui_ops = NULL; | |
62 | |
63 static GList *accounts = NULL; | |
64 static guint save_timer = 0; | |
65 static gboolean accounts_loaded = FALSE; | |
66 | |
67 | |
68 /********************************************************************* | |
69 * Writing to disk * | |
70 *********************************************************************/ | |
71 | |
72 static void | |
73 setting_to_xmlnode(gpointer key, gpointer value, gpointer user_data) | |
74 { | |
75 const char *name; | |
76 GaimAccountSetting *setting; | |
77 xmlnode *node, *child; | |
78 char buf[20]; | |
79 | |
80 name = (const char *)key; | |
81 setting = (GaimAccountSetting *)value; | |
82 node = (xmlnode *)user_data; | |
83 | |
84 child = xmlnode_new_child(node, "setting"); | |
85 xmlnode_set_attrib(child, "name", name); | |
86 | |
87 if (setting->type == GAIM_PREF_INT) { | |
88 xmlnode_set_attrib(child, "type", "int"); | |
89 snprintf(buf, sizeof(buf), "%d", setting->value.integer); | |
90 xmlnode_insert_data(child, buf, -1); | |
91 } | |
92 else if (setting->type == GAIM_PREF_STRING && setting->value.string != NULL) { | |
93 xmlnode_set_attrib(child, "type", "string"); | |
94 xmlnode_insert_data(child, setting->value.string, -1); | |
95 } | |
96 else if (setting->type == GAIM_PREF_BOOLEAN) { | |
97 xmlnode_set_attrib(child, "type", "bool"); | |
98 snprintf(buf, sizeof(buf), "%d", setting->value.bool); | |
99 xmlnode_insert_data(child, buf, -1); | |
100 } | |
101 } | |
102 | |
103 static void | |
104 ui_setting_to_xmlnode(gpointer key, gpointer value, gpointer user_data) | |
105 { | |
106 const char *ui; | |
107 GHashTable *table; | |
108 xmlnode *node, *child; | |
109 | |
110 ui = (const char *)key; | |
111 table = (GHashTable *)value; | |
112 node = (xmlnode *)user_data; | |
113 | |
114 if (g_hash_table_size(table) > 0) | |
115 { | |
116 child = xmlnode_new_child(node, "settings"); | |
117 xmlnode_set_attrib(child, "ui", ui); | |
118 g_hash_table_foreach(table, setting_to_xmlnode, child); | |
119 } | |
120 } | |
121 | |
122 static xmlnode * | |
123 status_attr_to_xmlnode(const GaimStatus *status, const GaimStatusType *type, const GaimStatusAttr *attr) | |
124 { | |
125 xmlnode *node; | |
126 const char *id; | |
127 char *value = NULL; | |
128 GaimStatusAttr *default_attr; | |
129 GaimValue *default_value; | |
130 GaimType attr_type; | |
131 GaimValue *attr_value; | |
132 | |
133 id = gaim_status_attr_get_id(attr); | |
134 g_return_val_if_fail(id, NULL); | |
135 | |
136 attr_value = gaim_status_get_attr_value(status, id); | |
137 g_return_val_if_fail(attr_value, NULL); | |
138 attr_type = gaim_value_get_type(attr_value); | |
139 | |
140 /* | |
141 * If attr_value is a different type than it should be | |
142 * then don't write it to the file. | |
143 */ | |
144 default_attr = gaim_status_type_get_attr(type, id); | |
145 default_value = gaim_status_attr_get_value(default_attr); | |
146 if (attr_type != gaim_value_get_type(default_value)) | |
147 return NULL; | |
148 | |
149 /* | |
150 * If attr_value is the same as the default for this status | |
151 * then there is no need to write it to the file. | |
152 */ | |
153 if (attr_type == GAIM_TYPE_STRING) | |
154 { | |
155 const char *string_value = gaim_value_get_string(attr_value); | |
156 const char *default_string_value = gaim_value_get_string(default_value); | |
157 if (((string_value == NULL) && (default_string_value == NULL)) || | |
158 ((string_value != NULL) && (default_string_value != NULL) && | |
159 !strcmp(string_value, default_string_value))) | |
160 return NULL; | |
161 value = g_strdup(gaim_value_get_string(attr_value)); | |
162 } | |
163 else if (attr_type == GAIM_TYPE_INT) | |
164 { | |
165 int int_value = gaim_value_get_int(attr_value); | |
166 if (int_value == gaim_value_get_int(default_value)) | |
167 return NULL; | |
168 value = g_strdup_printf("%d", int_value); | |
169 } | |
170 else if (attr_type == GAIM_TYPE_BOOLEAN) | |
171 { | |
172 gboolean boolean_value = gaim_value_get_boolean(attr_value); | |
173 if (boolean_value == gaim_value_get_boolean(default_value)) | |
174 return NULL; | |
175 value = g_strdup(boolean_value ? | |
176 "true" : "false"); | |
177 } | |
178 else | |
179 { | |
180 return NULL; | |
181 } | |
182 | |
183 g_return_val_if_fail(value, NULL); | |
184 | |
185 node = xmlnode_new("attribute"); | |
186 | |
187 xmlnode_set_attrib(node, "id", id); | |
188 xmlnode_set_attrib(node, "value", value); | |
189 | |
190 g_free(value); | |
191 | |
192 return node; | |
193 } | |
194 | |
195 static xmlnode * | |
196 status_attrs_to_xmlnode(const GaimStatus *status) | |
197 { | |
198 GaimStatusType *type = gaim_status_get_type(status); | |
199 xmlnode *node, *child; | |
200 const GList *attrs, *attr; | |
201 | |
202 node = xmlnode_new("attributes"); | |
203 | |
204 attrs = gaim_status_type_get_attrs(type); | |
205 for (attr = attrs; attr != NULL; attr = attr->next) | |
206 { | |
207 child = status_attr_to_xmlnode(status, type, (const GaimStatusAttr *)attr->data); | |
208 if (child) | |
209 xmlnode_insert_child(node, child); | |
210 } | |
211 | |
212 return node; | |
213 } | |
214 | |
215 static xmlnode * | |
216 status_to_xmlnode(const GaimStatus *status) | |
217 { | |
218 xmlnode *node, *child; | |
219 | |
220 node = xmlnode_new("status"); | |
221 xmlnode_set_attrib(node, "type", gaim_status_get_id(status)); | |
222 if (gaim_status_get_name(status) != NULL) | |
223 xmlnode_set_attrib(node, "name", gaim_status_get_name(status)); | |
224 xmlnode_set_attrib(node, "active", gaim_status_is_active(status) ? "true" : "false"); | |
225 | |
226 child = status_attrs_to_xmlnode(status); | |
227 xmlnode_insert_child(node, child); | |
228 | |
229 return node; | |
230 } | |
231 | |
232 static xmlnode * | |
233 statuses_to_xmlnode(const GaimPresence *presence) | |
234 { | |
235 xmlnode *node, *child; | |
236 const GList *statuses, *status; | |
237 | |
238 node = xmlnode_new("statuses"); | |
239 | |
240 statuses = gaim_presence_get_statuses(presence); | |
241 for (status = statuses; status != NULL; status = status->next) | |
242 { | |
243 child = status_to_xmlnode((GaimStatus *)status->data); | |
244 xmlnode_insert_child(node, child); | |
245 } | |
246 | |
247 return node; | |
248 } | |
249 | |
250 static xmlnode * | |
251 proxy_settings_to_xmlnode(GaimProxyInfo *proxy_info) | |
252 { | |
253 xmlnode *node, *child; | |
254 GaimProxyType proxy_type; | |
255 const char *value; | |
256 int int_value; | |
257 char buf[20]; | |
258 | |
259 proxy_type = gaim_proxy_info_get_type(proxy_info); | |
260 | |
261 node = xmlnode_new("proxy"); | |
262 | |
263 child = xmlnode_new_child(node, "type"); | |
264 xmlnode_insert_data(child, | |
265 (proxy_type == GAIM_PROXY_USE_GLOBAL ? "global" : | |
266 proxy_type == GAIM_PROXY_NONE ? "none" : | |
267 proxy_type == GAIM_PROXY_HTTP ? "http" : | |
268 proxy_type == GAIM_PROXY_SOCKS4 ? "socks4" : | |
269 proxy_type == GAIM_PROXY_SOCKS5 ? "socks5" : | |
270 proxy_type == GAIM_PROXY_USE_ENVVAR ? "envvar" : "unknown"), -1); | |
271 | |
14980
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
272 if ((value = gaim_proxy_info_get_host(proxy_info)) != NULL) |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
273 { |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
274 child = xmlnode_new_child(node, "host"); |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
275 xmlnode_insert_data(child, value, -1); |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
276 } |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
277 |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
278 if ((int_value = gaim_proxy_info_get_port(proxy_info)) != 0) |
14192 | 279 { |
14980
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
280 snprintf(buf, sizeof(buf), "%d", int_value); |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
281 child = xmlnode_new_child(node, "port"); |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
282 xmlnode_insert_data(child, buf, -1); |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
283 } |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
284 |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
285 if ((value = gaim_proxy_info_get_username(proxy_info)) != NULL) |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
286 { |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
287 child = xmlnode_new_child(node, "username"); |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
288 xmlnode_insert_data(child, value, -1); |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
289 } |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
290 |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
291 if ((value = gaim_proxy_info_get_password(proxy_info)) != NULL) |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
292 { |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
293 child = xmlnode_new_child(node, "password"); |
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
294 xmlnode_insert_data(child, value, -1); |
14192 | 295 } |
296 | |
297 return node; | |
298 } | |
299 | |
300 static xmlnode * | |
301 account_to_xmlnode(GaimAccount *account) | |
302 { | |
303 xmlnode *node, *child; | |
304 const char *tmp; | |
305 GaimPresence *presence; | |
306 GaimProxyInfo *proxy_info; | |
307 | |
308 node = xmlnode_new("account"); | |
309 | |
310 child = xmlnode_new_child(node, "protocol"); | |
311 xmlnode_insert_data(child, gaim_account_get_protocol_id(account), -1); | |
312 | |
313 child = xmlnode_new_child(node, "name"); | |
314 xmlnode_insert_data(child, gaim_account_get_username(account), -1); | |
315 | |
316 if (gaim_account_get_remember_password(account) && | |
317 ((tmp = gaim_account_get_password(account)) != NULL)) | |
318 { | |
319 child = xmlnode_new_child(node, "password"); | |
320 xmlnode_insert_data(child, tmp, -1); | |
321 } | |
322 | |
323 if ((tmp = gaim_account_get_alias(account)) != NULL) | |
324 { | |
325 child = xmlnode_new_child(node, "alias"); | |
326 xmlnode_insert_data(child, tmp, -1); | |
327 } | |
328 | |
329 if ((presence = gaim_account_get_presence(account)) != NULL) | |
330 { | |
331 child = statuses_to_xmlnode(presence); | |
332 xmlnode_insert_child(node, child); | |
333 } | |
334 | |
335 if ((tmp = gaim_account_get_user_info(account)) != NULL) | |
336 { | |
337 /* TODO: Do we need to call gaim_str_strip_char(tmp, '\r') here? */ | |
338 child = xmlnode_new_child(node, "userinfo"); | |
339 xmlnode_insert_data(child, tmp, -1); | |
340 } | |
341 | |
342 if ((tmp = gaim_account_get_buddy_icon(account)) != NULL) | |
343 { | |
344 child = xmlnode_new_child(node, "buddyicon"); | |
345 xmlnode_insert_data(child, tmp, -1); | |
346 } | |
347 | |
348 if (g_hash_table_size(account->settings) > 0) | |
349 { | |
350 child = xmlnode_new_child(node, "settings"); | |
351 g_hash_table_foreach(account->settings, setting_to_xmlnode, child); | |
352 } | |
353 | |
354 if (g_hash_table_size(account->ui_settings) > 0) | |
355 { | |
356 g_hash_table_foreach(account->ui_settings, ui_setting_to_xmlnode, node); | |
357 } | |
358 | |
359 if ((proxy_info = gaim_account_get_proxy_info(account)) != NULL) | |
360 { | |
361 child = proxy_settings_to_xmlnode(proxy_info); | |
362 xmlnode_insert_child(node, child); | |
363 } | |
364 | |
365 return node; | |
366 } | |
367 | |
368 static xmlnode * | |
369 accounts_to_xmlnode(void) | |
370 { | |
371 xmlnode *node, *child; | |
372 GList *cur; | |
373 | |
374 node = xmlnode_new("account"); | |
375 xmlnode_set_attrib(node, "version", "1.0"); | |
376 | |
377 for (cur = gaim_accounts_get_all(); cur != NULL; cur = cur->next) | |
378 { | |
379 child = account_to_xmlnode(cur->data); | |
380 xmlnode_insert_child(node, child); | |
381 } | |
382 | |
383 return node; | |
384 } | |
385 | |
386 static void | |
387 sync_accounts(void) | |
388 { | |
389 xmlnode *node; | |
390 char *data; | |
391 | |
392 if (!accounts_loaded) | |
393 { | |
394 gaim_debug_error("account", "Attempted to save accounts before " | |
395 "they were read!\n"); | |
396 return; | |
397 } | |
398 | |
399 node = accounts_to_xmlnode(); | |
400 data = xmlnode_to_formatted_str(node, NULL); | |
401 gaim_util_write_data_to_file("accounts.xml", data, -1); | |
402 g_free(data); | |
403 xmlnode_free(node); | |
404 } | |
405 | |
406 static gboolean | |
407 save_cb(gpointer data) | |
408 { | |
409 sync_accounts(); | |
410 save_timer = 0; | |
411 return FALSE; | |
412 } | |
413 | |
414 static void | |
415 schedule_accounts_save() | |
416 { | |
417 if (save_timer == 0) | |
418 save_timer = gaim_timeout_add(5000, save_cb, NULL); | |
419 } | |
420 | |
421 | |
422 /********************************************************************* | |
423 * Reading from disk * | |
424 *********************************************************************/ | |
425 | |
426 static void | |
427 parse_settings(xmlnode *node, GaimAccount *account) | |
428 { | |
429 const char *ui; | |
430 xmlnode *child; | |
431 | |
432 /* Get the UI string, if these are UI settings */ | |
433 ui = xmlnode_get_attrib(node, "ui"); | |
434 | |
435 /* Read settings, one by one */ | |
436 for (child = xmlnode_get_child(node, "setting"); child != NULL; | |
437 child = xmlnode_get_next_twin(child)) | |
438 { | |
439 const char *name, *str_type; | |
440 GaimPrefType type; | |
441 char *data; | |
442 | |
443 name = xmlnode_get_attrib(child, "name"); | |
444 if (name == NULL) | |
445 /* Ignore this setting */ | |
446 continue; | |
447 | |
448 str_type = xmlnode_get_attrib(child, "type"); | |
449 if (str_type == NULL) | |
450 /* Ignore this setting */ | |
451 continue; | |
452 | |
453 if (!strcmp(str_type, "string")) | |
454 type = GAIM_PREF_STRING; | |
455 else if (!strcmp(str_type, "int")) | |
456 type = GAIM_PREF_INT; | |
457 else if (!strcmp(str_type, "bool")) | |
458 type = GAIM_PREF_BOOLEAN; | |
459 else | |
460 /* Ignore this setting */ | |
461 continue; | |
462 | |
463 data = xmlnode_get_data(child); | |
464 if (data == NULL) | |
465 /* Ignore this setting */ | |
466 continue; | |
467 | |
468 if (ui == NULL) | |
469 { | |
470 if (type == GAIM_PREF_STRING) | |
471 gaim_account_set_string(account, name, data); | |
472 else if (type == GAIM_PREF_INT) | |
473 gaim_account_set_int(account, name, atoi(data)); | |
474 else if (type == GAIM_PREF_BOOLEAN) | |
475 gaim_account_set_bool(account, name, | |
476 (*data == '0' ? FALSE : TRUE)); | |
477 } else { | |
478 if (type == GAIM_PREF_STRING) | |
479 gaim_account_set_ui_string(account, ui, name, data); | |
480 else if (type == GAIM_PREF_INT) | |
481 gaim_account_set_ui_int(account, ui, name, atoi(data)); | |
482 else if (type == GAIM_PREF_BOOLEAN) | |
483 gaim_account_set_ui_bool(account, ui, name, | |
484 (*data == '0' ? FALSE : TRUE)); | |
485 } | |
486 | |
487 g_free(data); | |
488 } | |
489 } | |
490 | |
491 static GList * | |
492 parse_status_attrs(xmlnode *node, GaimStatus *status) | |
493 { | |
494 GList *list = NULL; | |
495 xmlnode *child; | |
496 GaimValue *attr_value; | |
497 | |
498 for (child = xmlnode_get_child(node, "attribute"); child != NULL; | |
499 child = xmlnode_get_next_twin(child)) | |
500 { | |
501 const char *id = xmlnode_get_attrib(child, "id"); | |
502 const char *value = xmlnode_get_attrib(child, "value"); | |
503 | |
504 if (!id || !*id || !value || !*value) | |
505 continue; | |
506 | |
507 attr_value = gaim_status_get_attr_value(status, id); | |
508 if (!attr_value) | |
509 continue; | |
510 | |
511 list = g_list_append(list, (char *)id); | |
512 | |
513 switch (gaim_value_get_type(attr_value)) | |
514 { | |
515 case GAIM_TYPE_STRING: | |
516 list = g_list_append(list, (char *)value); | |
517 break; | |
518 case GAIM_TYPE_INT: | |
519 case GAIM_TYPE_BOOLEAN: | |
520 { | |
521 int v; | |
522 if (sscanf(value, "%d", &v) == 1) | |
523 list = g_list_append(list, GINT_TO_POINTER(v)); | |
524 else | |
525 list = g_list_remove(list, id); | |
526 break; | |
527 } | |
528 default: | |
529 break; | |
530 } | |
531 } | |
532 | |
533 return list; | |
534 } | |
535 | |
536 static void | |
537 parse_status(xmlnode *node, GaimAccount *account) | |
538 { | |
539 gboolean active = FALSE; | |
540 const char *data; | |
541 const char *type; | |
542 xmlnode *child; | |
543 GList *attrs = NULL; | |
544 | |
545 /* Get the active/inactive state */ | |
546 data = xmlnode_get_attrib(node, "active"); | |
547 if (data == NULL) | |
548 return; | |
549 if (strcasecmp(data, "true") == 0) | |
550 active = TRUE; | |
551 else if (strcasecmp(data, "false") == 0) | |
552 active = FALSE; | |
553 else | |
554 return; | |
555 | |
556 /* Get the type of the status */ | |
557 type = xmlnode_get_attrib(node, "type"); | |
558 if (type == NULL) | |
559 return; | |
560 | |
561 /* Read attributes into a GList */ | |
562 child = xmlnode_get_child(node, "attributes"); | |
563 if (child != NULL) | |
564 { | |
565 attrs = parse_status_attrs(child, | |
566 gaim_account_get_status(account, type)); | |
567 } | |
568 | |
569 gaim_account_set_status_list(account, type, active, attrs); | |
570 | |
571 g_list_free(attrs); | |
572 } | |
573 | |
574 static void | |
575 parse_statuses(xmlnode *node, GaimAccount *account) | |
576 { | |
577 xmlnode *child; | |
578 | |
579 for (child = xmlnode_get_child(node, "status"); child != NULL; | |
580 child = xmlnode_get_next_twin(child)) | |
581 { | |
582 parse_status(child, account); | |
583 } | |
584 } | |
585 | |
586 static void | |
587 parse_proxy_info(xmlnode *node, GaimAccount *account) | |
588 { | |
589 GaimProxyInfo *proxy_info; | |
590 xmlnode *child; | |
591 char *data; | |
592 | |
593 proxy_info = gaim_proxy_info_new(); | |
594 | |
595 /* Use the global proxy settings, by default */ | |
596 gaim_proxy_info_set_type(proxy_info, GAIM_PROXY_USE_GLOBAL); | |
597 | |
598 /* Read proxy type */ | |
599 child = xmlnode_get_child(node, "type"); | |
600 if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) | |
601 { | |
602 if (!strcmp(data, "global")) | |
603 gaim_proxy_info_set_type(proxy_info, GAIM_PROXY_USE_GLOBAL); | |
604 else if (!strcmp(data, "none")) | |
605 gaim_proxy_info_set_type(proxy_info, GAIM_PROXY_NONE); | |
606 else if (!strcmp(data, "http")) | |
607 gaim_proxy_info_set_type(proxy_info, GAIM_PROXY_HTTP); | |
608 else if (!strcmp(data, "socks4")) | |
609 gaim_proxy_info_set_type(proxy_info, GAIM_PROXY_SOCKS4); | |
610 else if (!strcmp(data, "socks5")) | |
611 gaim_proxy_info_set_type(proxy_info, GAIM_PROXY_SOCKS5); | |
612 else if (!strcmp(data, "envvar")) | |
613 gaim_proxy_info_set_type(proxy_info, GAIM_PROXY_USE_ENVVAR); | |
614 else | |
615 { | |
616 gaim_debug_error("account", "Invalid proxy type found when " | |
617 "loading account information for %s\n", | |
618 gaim_account_get_username(account)); | |
619 } | |
620 g_free(data); | |
621 } | |
622 | |
623 /* Read proxy host */ | |
624 child = xmlnode_get_child(node, "host"); | |
625 if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) | |
626 { | |
627 gaim_proxy_info_set_host(proxy_info, data); | |
628 g_free(data); | |
629 } | |
630 | |
631 /* Read proxy port */ | |
632 child = xmlnode_get_child(node, "port"); | |
633 if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) | |
634 { | |
635 gaim_proxy_info_set_port(proxy_info, atoi(data)); | |
636 g_free(data); | |
637 } | |
638 | |
639 /* Read proxy username */ | |
640 child = xmlnode_get_child(node, "username"); | |
641 if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) | |
642 { | |
643 gaim_proxy_info_set_username(proxy_info, data); | |
644 g_free(data); | |
645 } | |
646 | |
647 /* Read proxy password */ | |
648 child = xmlnode_get_child(node, "password"); | |
649 if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) | |
650 { | |
651 gaim_proxy_info_set_password(proxy_info, data); | |
652 g_free(data); | |
653 } | |
654 | |
14980
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
655 /* If there are no values set then proxy_info NULL */ |
14192 | 656 if ((gaim_proxy_info_get_type(proxy_info) == GAIM_PROXY_USE_GLOBAL) && |
657 (gaim_proxy_info_get_host(proxy_info) == NULL) && | |
658 (gaim_proxy_info_get_port(proxy_info) == 0) && | |
659 (gaim_proxy_info_get_username(proxy_info) == NULL) && | |
660 (gaim_proxy_info_get_password(proxy_info) == NULL)) | |
661 { | |
662 gaim_proxy_info_destroy(proxy_info); | |
663 return; | |
664 } | |
665 | |
666 gaim_account_set_proxy_info(account, proxy_info); | |
667 } | |
668 | |
669 static GaimAccount * | |
670 parse_account(xmlnode *node) | |
671 { | |
672 GaimAccount *ret; | |
673 xmlnode *child; | |
674 char *protocol_id = NULL; | |
675 char *name = NULL; | |
676 char *data; | |
677 | |
678 child = xmlnode_get_child(node, "protocol"); | |
679 if (child != NULL) | |
680 protocol_id = xmlnode_get_data(child); | |
681 | |
682 child = xmlnode_get_child(node, "name"); | |
683 if (child != NULL) | |
684 name = xmlnode_get_data(child); | |
685 if (name == NULL) | |
686 { | |
687 /* Do we really need to do this? */ | |
688 child = xmlnode_get_child(node, "username"); | |
689 if (child != NULL) | |
690 name = xmlnode_get_data(child); | |
691 } | |
692 | |
693 if ((protocol_id == NULL) || (name == NULL)) | |
694 { | |
695 g_free(protocol_id); | |
696 g_free(name); | |
697 return NULL; | |
698 } | |
699 | |
700 ret = gaim_account_new(name, protocol_id); | |
701 g_free(name); | |
702 g_free(protocol_id); | |
703 | |
704 /* Read the password */ | |
705 child = xmlnode_get_child(node, "password"); | |
706 if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) | |
707 { | |
708 gaim_account_set_remember_password(ret, TRUE); | |
709 gaim_account_set_password(ret, data); | |
710 g_free(data); | |
711 } | |
712 | |
713 /* Read the alias */ | |
714 child = xmlnode_get_child(node, "alias"); | |
715 if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) | |
716 { | |
717 if (*data != '\0') | |
718 gaim_account_set_alias(ret, data); | |
719 g_free(data); | |
720 } | |
721 | |
722 /* Read the statuses */ | |
723 child = xmlnode_get_child(node, "statuses"); | |
724 if (child != NULL) | |
725 { | |
726 parse_statuses(child, ret); | |
727 } | |
728 | |
729 /* Read the userinfo */ | |
730 child = xmlnode_get_child(node, "userinfo"); | |
731 if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) | |
732 { | |
733 gaim_account_set_user_info(ret, data); | |
734 g_free(data); | |
735 } | |
736 | |
737 /* Read the buddyicon */ | |
738 child = xmlnode_get_child(node, "buddyicon"); | |
739 if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) | |
740 { | |
741 gaim_account_set_buddy_icon(ret, data); | |
742 g_free(data); | |
743 } | |
744 | |
745 /* Read settings (both core and UI) */ | |
746 for (child = xmlnode_get_child(node, "settings"); child != NULL; | |
747 child = xmlnode_get_next_twin(child)) | |
748 { | |
749 parse_settings(child, ret); | |
750 } | |
751 | |
752 /* Read proxy */ | |
753 child = xmlnode_get_child(node, "proxy"); | |
754 if (child != NULL) | |
755 { | |
756 parse_proxy_info(child, ret); | |
757 } | |
758 | |
759 return ret; | |
760 } | |
761 | |
762 static void | |
763 load_accounts(void) | |
764 { | |
765 xmlnode *node, *child; | |
766 | |
767 accounts_loaded = TRUE; | |
768 | |
769 node = gaim_util_read_xml_from_file("accounts.xml", _("accounts")); | |
770 | |
771 if (node == NULL) | |
772 return; | |
773 | |
774 for (child = xmlnode_get_child(node, "account"); child != NULL; | |
775 child = xmlnode_get_next_twin(child)) | |
776 { | |
777 GaimAccount *new_acct; | |
778 new_acct = parse_account(child); | |
779 gaim_accounts_add(new_acct); | |
780 } | |
781 | |
782 xmlnode_free(node); | |
783 } | |
784 | |
785 | |
786 static void | |
787 delete_setting(void *data) | |
788 { | |
789 GaimAccountSetting *setting = (GaimAccountSetting *)data; | |
790 | |
791 g_free(setting->ui); | |
792 | |
793 if (setting->type == GAIM_PREF_STRING) | |
794 g_free(setting->value.string); | |
795 | |
796 g_free(setting); | |
797 } | |
798 | |
799 GaimAccount * | |
800 gaim_account_new(const char *username, const char *protocol_id) | |
801 { | |
802 GaimAccount *account = NULL; | |
803 GaimPlugin *prpl = NULL; | |
804 GaimPluginProtocolInfo *prpl_info = NULL; | |
805 GaimStatusType *status_type; | |
806 | |
807 g_return_val_if_fail(username != NULL, NULL); | |
808 g_return_val_if_fail(protocol_id != NULL, NULL); | |
809 | |
810 account = gaim_accounts_find(username, protocol_id); | |
811 | |
812 if (account != NULL) | |
813 return account; | |
814 | |
815 account = g_new0(GaimAccount, 1); | |
816 GAIM_DBUS_REGISTER_POINTER(account, GaimAccount); | |
817 | |
818 gaim_account_set_username(account, username); | |
819 | |
820 gaim_account_set_protocol_id(account, protocol_id); | |
821 | |
822 account->settings = g_hash_table_new_full(g_str_hash, g_str_equal, | |
823 g_free, delete_setting); | |
824 account->ui_settings = g_hash_table_new_full(g_str_hash, g_str_equal, | |
825 g_free, (GDestroyNotify)g_hash_table_destroy); | |
826 account->system_log = NULL; | |
827 /* 0 is not a valid privacy setting */ | |
828 account->perm_deny = GAIM_PRIVACY_ALLOW_ALL; | |
829 | |
830 account->presence = gaim_presence_new_for_account(account); | |
831 | |
832 prpl = gaim_find_prpl(protocol_id); | |
833 | |
834 if (prpl == NULL) | |
835 return account; | |
836 | |
837 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
838 if (prpl_info != NULL && prpl_info->status_types != NULL) | |
839 gaim_account_set_status_types(account, prpl_info->status_types(account)); | |
840 | |
841 status_type = gaim_account_get_status_type_with_primitive(account, GAIM_STATUS_AVAILABLE); | |
842 if (status_type != NULL) | |
843 gaim_presence_set_status_active(account->presence, | |
844 gaim_status_type_get_id(status_type), | |
845 TRUE); | |
846 else | |
847 gaim_presence_set_status_active(account->presence, | |
848 "offline", | |
849 TRUE); | |
850 | |
851 return account; | |
852 } | |
853 | |
854 void | |
855 gaim_account_destroy(GaimAccount *account) | |
856 { | |
857 GList *l; | |
858 | |
859 g_return_if_fail(account != NULL); | |
860 | |
861 gaim_debug_info("account", "Destroying account %p\n", account); | |
862 | |
863 for (l = gaim_get_conversations(); l != NULL; l = l->next) | |
864 { | |
865 GaimConversation *conv = (GaimConversation *)l->data; | |
866 | |
867 if (gaim_conversation_get_account(conv) == account) | |
868 gaim_conversation_set_account(conv, NULL); | |
869 } | |
870 | |
871 g_free(account->username); | |
872 g_free(account->alias); | |
873 g_free(account->password); | |
874 g_free(account->user_info); | |
875 g_free(account->protocol_id); | |
876 | |
877 g_hash_table_destroy(account->settings); | |
878 g_hash_table_destroy(account->ui_settings); | |
879 | |
880 gaim_account_set_status_types(account, NULL); | |
881 | |
882 gaim_presence_destroy(account->presence); | |
883 | |
884 if(account->system_log) | |
885 gaim_log_free(account->system_log); | |
886 | |
887 GAIM_DBUS_UNREGISTER_POINTER(account); | |
888 g_free(account); | |
889 } | |
890 | |
891 void | |
892 gaim_account_register(GaimAccount *account) | |
893 { | |
894 g_return_if_fail(account != NULL); | |
895 | |
896 gaim_debug_info("account", "Registering account %s\n", | |
897 gaim_account_get_username(account)); | |
898 | |
899 gaim_connection_new(account, TRUE, NULL); | |
900 } | |
901 | |
902 static void | |
903 request_password_ok_cb(GaimAccount *account, GaimRequestFields *fields) | |
904 { | |
905 const char *entry; | |
906 gboolean remember; | |
907 | |
908 entry = gaim_request_fields_get_string(fields, "password"); | |
909 remember = gaim_request_fields_get_bool(fields, "remember"); | |
910 | |
911 if (!entry || !*entry) | |
912 { | |
913 gaim_notify_error(account, NULL, _("Password is required to sign on."), NULL); | |
914 return; | |
915 } | |
916 | |
917 if(remember) | |
918 gaim_account_set_remember_password(account, TRUE); | |
919 | |
920 gaim_account_set_password(account, entry); | |
921 | |
922 gaim_connection_new(account, FALSE, entry); | |
923 } | |
924 | |
925 static void | |
926 request_password(GaimAccount *account) | |
927 { | |
928 gchar *primary; | |
929 const gchar *username; | |
930 GaimRequestFieldGroup *group; | |
931 GaimRequestField *field; | |
932 GaimRequestFields *fields; | |
933 | |
934 /* Close any previous password request windows */ | |
935 gaim_request_close_with_handle(account); | |
936 | |
937 username = gaim_account_get_username(account); | |
938 primary = g_strdup_printf(_("Enter password for %s (%s)"), username, | |
939 gaim_account_get_protocol_name(account)); | |
940 | |
941 fields = gaim_request_fields_new(); | |
942 group = gaim_request_field_group_new(NULL); | |
943 gaim_request_fields_add_group(fields, group); | |
944 | |
945 field = gaim_request_field_string_new("password", _("Enter Password"), NULL, FALSE); | |
946 gaim_request_field_string_set_masked(field, TRUE); | |
947 gaim_request_field_set_required(field, TRUE); | |
948 gaim_request_field_group_add_field(group, field); | |
949 | |
950 field = gaim_request_field_bool_new("remember", _("Save password"), FALSE); | |
951 gaim_request_field_group_add_field(group, field); | |
952 | |
953 gaim_request_fields(account, | |
954 NULL, | |
955 primary, | |
956 NULL, | |
957 fields, | |
958 _("OK"), G_CALLBACK(request_password_ok_cb), | |
959 _("Cancel"), NULL, | |
960 account); | |
961 g_free(primary); | |
962 } | |
963 | |
964 void | |
965 gaim_account_connect(GaimAccount *account) | |
966 { | |
967 GaimPlugin *prpl; | |
968 GaimPluginProtocolInfo *prpl_info; | |
969 const char *password; | |
970 | |
971 g_return_if_fail(account != NULL); | |
972 | |
973 gaim_debug_info("account", "Connecting to account %s\n", | |
974 gaim_account_get_username(account)); | |
975 | |
976 if (!gaim_account_get_enabled(account, gaim_core_get_ui())) | |
977 return; | |
978 | |
979 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); | |
980 if (prpl == NULL) | |
981 { | |
982 gchar *message; | |
983 | |
984 message = g_strdup_printf(_("Missing protocol plugin for %s"), | |
985 gaim_account_get_username(account)); | |
986 gaim_notify_error(account, _("Connection Error"), message, NULL); | |
987 g_free(message); | |
988 return; | |
989 } | |
990 | |
991 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
992 password = gaim_account_get_password(account); | |
993 if ((password == NULL) && | |
994 !(prpl_info->options & OPT_PROTO_NO_PASSWORD) && | |
995 !(prpl_info->options & OPT_PROTO_PASSWORD_OPTIONAL)) | |
996 request_password(account); | |
997 else | |
998 gaim_connection_new(account, FALSE, password); | |
999 } | |
1000 | |
1001 void | |
1002 gaim_account_disconnect(GaimAccount *account) | |
1003 { | |
1004 GaimConnection *gc; | |
1005 | |
1006 g_return_if_fail(account != NULL); | |
1007 g_return_if_fail(!gaim_account_is_disconnected(account)); | |
1008 | |
1009 gaim_debug_info("account", "Disconnecting account %p\n", account); | |
1010 | |
1011 account->disconnecting = TRUE; | |
1012 | |
1013 gc = gaim_account_get_connection(account); | |
1014 gaim_connection_destroy(gc); | |
1015 if (!gaim_account_get_remember_password(account)) | |
14980
c157efddc62a
[gaim-migrate @ 17758]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14969
diff
changeset
|
1016 gaim_account_set_password(account, NULL); |
14192 | 1017 gaim_account_set_connection(account, NULL); |
1018 | |
1019 account->disconnecting = FALSE; | |
1020 } | |
1021 | |
1022 void | |
1023 gaim_account_notify_added(GaimAccount *account, const char *remote_user, | |
1024 const char *id, const char *alias, | |
1025 const char *message) | |
1026 { | |
1027 GaimAccountUiOps *ui_ops; | |
1028 | |
1029 g_return_if_fail(account != NULL); | |
1030 g_return_if_fail(remote_user != NULL); | |
1031 | |
1032 ui_ops = gaim_accounts_get_ui_ops(); | |
1033 | |
1034 if (ui_ops != NULL && ui_ops->notify_added != NULL) | |
1035 ui_ops->notify_added(account, remote_user, id, alias, message); | |
1036 } | |
1037 | |
1038 void | |
1039 gaim_account_request_add(GaimAccount *account, const char *remote_user, | |
1040 const char *id, const char *alias, | |
1041 const char *message) | |
1042 { | |
1043 GaimAccountUiOps *ui_ops; | |
1044 | |
1045 g_return_if_fail(account != NULL); | |
1046 g_return_if_fail(remote_user != NULL); | |
1047 | |
1048 ui_ops = gaim_accounts_get_ui_ops(); | |
1049 | |
1050 if (ui_ops != NULL && ui_ops->request_add != NULL) | |
1051 ui_ops->request_add(account, remote_user, id, alias, message); | |
1052 } | |
1053 | |
1054 static void | |
1055 change_password_cb(GaimAccount *account, GaimRequestFields *fields) | |
1056 { | |
1057 const char *orig_pass, *new_pass_1, *new_pass_2; | |
1058 | |
1059 orig_pass = gaim_request_fields_get_string(fields, "password"); | |
1060 new_pass_1 = gaim_request_fields_get_string(fields, "new_password_1"); | |
1061 new_pass_2 = gaim_request_fields_get_string(fields, "new_password_2"); | |
1062 | |
1063 if (g_utf8_collate(new_pass_1, new_pass_2)) | |
1064 { | |
1065 gaim_notify_error(account, NULL, | |
1066 _("New passwords do not match."), NULL); | |
1067 | |
1068 return; | |
1069 } | |
1070 | |
1071 if (orig_pass == NULL || new_pass_1 == NULL || new_pass_2 == NULL || | |
1072 *orig_pass == '\0' || *new_pass_1 == '\0' || *new_pass_2 == '\0') | |
1073 { | |
1074 gaim_notify_error(account, NULL, | |
1075 _("Fill out all fields completely."), NULL); | |
1076 return; | |
1077 } | |
1078 | |
1079 gaim_account_change_password(account, orig_pass, new_pass_1); | |
1080 } | |
1081 | |
1082 void | |
1083 gaim_account_request_change_password(GaimAccount *account) | |
1084 { | |
1085 GaimRequestFields *fields; | |
1086 GaimRequestFieldGroup *group; | |
1087 GaimRequestField *field; | |
1088 char primary[256]; | |
1089 | |
1090 g_return_if_fail(account != NULL); | |
1091 g_return_if_fail(gaim_account_is_connected(account)); | |
1092 | |
1093 fields = gaim_request_fields_new(); | |
1094 | |
1095 group = gaim_request_field_group_new(NULL); | |
1096 gaim_request_fields_add_group(fields, group); | |
1097 | |
1098 field = gaim_request_field_string_new("password", _("Original password"), | |
1099 NULL, FALSE); | |
1100 gaim_request_field_string_set_masked(field, TRUE); | |
1101 gaim_request_field_set_required(field, TRUE); | |
1102 gaim_request_field_group_add_field(group, field); | |
1103 | |
1104 field = gaim_request_field_string_new("new_password_1", | |
1105 _("New password"), | |
1106 NULL, FALSE); | |
1107 gaim_request_field_string_set_masked(field, TRUE); | |
1108 gaim_request_field_set_required(field, TRUE); | |
1109 gaim_request_field_group_add_field(group, field); | |
1110 | |
1111 field = gaim_request_field_string_new("new_password_2", | |
1112 _("New password (again)"), | |
1113 NULL, FALSE); | |
1114 gaim_request_field_string_set_masked(field, TRUE); | |
1115 gaim_request_field_set_required(field, TRUE); | |
1116 gaim_request_field_group_add_field(group, field); | |
1117 | |
1118 g_snprintf(primary, sizeof(primary), _("Change password for %s"), | |
1119 gaim_account_get_username(account)); | |
1120 | |
1121 /* I'm sticking this somewhere in the code: bologna */ | |
1122 | |
1123 gaim_request_fields(gaim_account_get_connection(account), | |
1124 NULL, | |
1125 primary, | |
1126 _("Please enter your current password and your " | |
1127 "new password."), | |
1128 fields, | |
1129 _("OK"), G_CALLBACK(change_password_cb), | |
1130 _("Cancel"), NULL, | |
1131 account); | |
1132 } | |
1133 | |
1134 static void | |
1135 set_user_info_cb(GaimAccount *account, const char *user_info) | |
1136 { | |
1137 GaimConnection *gc; | |
1138 | |
1139 gaim_account_set_user_info(account, user_info); | |
1140 gc = gaim_account_get_connection(account); | |
14607 | 1141 serv_set_info(gc, user_info); |
14192 | 1142 } |
1143 | |
1144 void | |
1145 gaim_account_request_change_user_info(GaimAccount *account) | |
1146 { | |
1147 GaimConnection *gc; | |
1148 char primary[256]; | |
1149 | |
1150 g_return_if_fail(account != NULL); | |
1151 g_return_if_fail(gaim_account_is_connected(account)); | |
1152 | |
1153 gc = gaim_account_get_connection(account); | |
1154 | |
1155 g_snprintf(primary, sizeof(primary), | |
1156 _("Change user information for %s"), | |
1157 gaim_account_get_username(account)); | |
1158 | |
1159 gaim_request_input(gc, _("Set User Info"), primary, NULL, | |
1160 gaim_account_get_user_info(account), | |
1161 TRUE, FALSE, ((gc != NULL) && | |
1162 (gc->flags & GAIM_CONNECTION_HTML) ? "html" : NULL), | |
1163 _("Save"), G_CALLBACK(set_user_info_cb), | |
1164 _("Cancel"), NULL, account); | |
1165 } | |
1166 | |
1167 void | |
1168 gaim_account_set_username(GaimAccount *account, const char *username) | |
1169 { | |
1170 g_return_if_fail(account != NULL); | |
1171 | |
1172 g_free(account->username); | |
1173 account->username = g_strdup(username); | |
1174 | |
1175 schedule_accounts_save(); | |
1176 } | |
1177 | |
1178 void | |
1179 gaim_account_set_password(GaimAccount *account, const char *password) | |
1180 { | |
1181 g_return_if_fail(account != NULL); | |
1182 | |
1183 g_free(account->password); | |
1184 account->password = g_strdup(password); | |
1185 | |
1186 schedule_accounts_save(); | |
1187 } | |
1188 | |
1189 void | |
1190 gaim_account_set_alias(GaimAccount *account, const char *alias) | |
1191 { | |
1192 g_return_if_fail(account != NULL); | |
1193 | |
1194 /* | |
1195 * Do nothing if alias and account->alias are both NULL. Or if | |
1196 * they're the exact same string. | |
1197 */ | |
1198 if (alias == account->alias) | |
1199 return; | |
1200 | |
1201 if ((!alias && account->alias) || (alias && !account->alias) || | |
1202 g_utf8_collate(account->alias, alias)) | |
1203 { | |
1204 char *old = account->alias; | |
1205 | |
1206 account->alias = g_strdup(alias); | |
1207 gaim_signal_emit(gaim_accounts_get_handle(), "account-alias-changed", | |
1208 account, old); | |
1209 g_free(old); | |
1210 | |
1211 schedule_accounts_save(); | |
1212 } | |
1213 } | |
1214 | |
1215 void | |
1216 gaim_account_set_user_info(GaimAccount *account, const char *user_info) | |
1217 { | |
1218 g_return_if_fail(account != NULL); | |
1219 | |
1220 g_free(account->user_info); | |
1221 account->user_info = g_strdup(user_info); | |
1222 | |
1223 schedule_accounts_save(); | |
1224 } | |
1225 | |
1226 void | |
1227 gaim_account_set_buddy_icon(GaimAccount *account, const char *icon) | |
1228 { | |
1229 g_return_if_fail(account != NULL); | |
1230 | |
1231 /* Delete an existing icon from the cache. */ | |
1232 if (account->buddy_icon != NULL && (icon == NULL || strcmp(account->buddy_icon, icon))) | |
1233 { | |
1234 const char *dirname = gaim_buddy_icons_get_cache_dir(); | |
1235 struct stat st; | |
1236 | |
1237 if (g_stat(account->buddy_icon, &st) == 0) | |
1238 { | |
1239 /* The file exists. This is a full path. */ | |
1240 | |
1241 /* XXX: This is a hack so we only delete the file if it's | |
1242 * in the cache dir. Otherwise, people who upgrade (who | |
1243 * may have buddy icon filenames set outside of the cache | |
1244 * dir) could lose files. */ | |
1245 if (!strncmp(dirname, account->buddy_icon, strlen(dirname))) | |
1246 g_unlink(account->buddy_icon); | |
1247 } | |
1248 else | |
1249 { | |
1250 char *filename = g_build_filename(dirname, account->buddy_icon, NULL); | |
1251 g_unlink(filename); | |
1252 g_free(filename); | |
1253 } | |
1254 } | |
1255 | |
1256 g_free(account->buddy_icon); | |
1257 account->buddy_icon = g_strdup(icon); | |
1258 if (gaim_account_is_connected(account)) | |
1259 { | |
14982 | 1260 GaimConnection *gc; |
1261 GaimPluginProtocolInfo *prpl_info; | |
1262 | |
1263 gc = gaim_account_get_connection(account); | |
1264 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
1265 | |
1266 if (prpl_info && prpl_info->set_buddy_icon) | |
1267 { | |
1268 char *filename = gaim_buddy_icons_get_full_path(icon); | |
1269 prpl_info->set_buddy_icon(gc, filename); | |
1270 g_free(filename); | |
1271 } | |
14192 | 1272 } |
1273 | |
1274 schedule_accounts_save(); | |
1275 } | |
1276 | |
1277 void | |
1278 gaim_account_set_protocol_id(GaimAccount *account, const char *protocol_id) | |
1279 { | |
1280 g_return_if_fail(account != NULL); | |
1281 g_return_if_fail(protocol_id != NULL); | |
1282 | |
1283 g_free(account->protocol_id); | |
1284 account->protocol_id = g_strdup(protocol_id); | |
1285 | |
1286 schedule_accounts_save(); | |
1287 } | |
1288 | |
1289 void | |
1290 gaim_account_set_connection(GaimAccount *account, GaimConnection *gc) | |
1291 { | |
1292 g_return_if_fail(account != NULL); | |
1293 | |
1294 account->gc = gc; | |
1295 } | |
1296 | |
1297 void | |
1298 gaim_account_set_remember_password(GaimAccount *account, gboolean value) | |
1299 { | |
1300 g_return_if_fail(account != NULL); | |
1301 | |
1302 account->remember_pass = value; | |
1303 | |
1304 schedule_accounts_save(); | |
1305 } | |
1306 | |
1307 void | |
1308 gaim_account_set_check_mail(GaimAccount *account, gboolean value) | |
1309 { | |
1310 g_return_if_fail(account != NULL); | |
1311 | |
1312 gaim_account_set_bool(account, "check-mail", value); | |
1313 } | |
1314 | |
1315 void | |
1316 gaim_account_set_enabled(GaimAccount *account, const char *ui, | |
1317 gboolean value) | |
1318 { | |
1319 GaimConnection *gc; | |
1320 gboolean was_enabled = FALSE; | |
1321 | |
1322 g_return_if_fail(account != NULL); | |
1323 g_return_if_fail(ui != NULL); | |
1324 | |
1325 was_enabled = gaim_account_get_enabled(account, ui); | |
1326 | |
1327 gaim_account_set_ui_bool(account, ui, "auto-login", value); | |
1328 gc = gaim_account_get_connection(account); | |
1329 | |
1330 if(was_enabled && !value) | |
1331 gaim_signal_emit(gaim_accounts_get_handle(), "account-disabled", account); | |
1332 else if(!was_enabled && value) | |
1333 gaim_signal_emit(gaim_accounts_get_handle(), "account-enabled", account); | |
1334 | |
1335 if ((gc != NULL) && (gc->wants_to_die == TRUE)) | |
1336 return; | |
1337 | |
1338 if (value && gaim_presence_is_online(account->presence)) | |
1339 gaim_account_connect(account); | |
1340 else if (!value && !gaim_account_is_disconnected(account)) | |
1341 gaim_account_disconnect(account); | |
1342 } | |
1343 | |
1344 void | |
1345 gaim_account_set_proxy_info(GaimAccount *account, GaimProxyInfo *info) | |
1346 { | |
1347 g_return_if_fail(account != NULL); | |
1348 | |
1349 if (account->proxy_info != NULL) | |
1350 gaim_proxy_info_destroy(account->proxy_info); | |
1351 | |
1352 account->proxy_info = info; | |
1353 | |
1354 schedule_accounts_save(); | |
1355 } | |
1356 | |
1357 void | |
1358 gaim_account_set_status_types(GaimAccount *account, GList *status_types) | |
1359 { | |
1360 g_return_if_fail(account != NULL); | |
1361 | |
14662
61a4a2dc491e
[gaim-migrate @ 17408]
Etan Reisner <pidgin@unreliablesource.net>
parents:
14643
diff
changeset
|
1362 /* Out with the old... */ |
14192 | 1363 if (account->status_types != NULL) |
1364 { | |
1365 g_list_foreach(account->status_types, (GFunc)gaim_status_type_destroy, NULL); | |
1366 g_list_free(account->status_types); | |
1367 } | |
1368 | |
1369 /* In with the new... */ | |
1370 account->status_types = status_types; | |
1371 } | |
1372 | |
1373 void | |
1374 gaim_account_set_status(GaimAccount *account, const char *status_id, | |
1375 gboolean active, ...) | |
1376 { | |
14643 | 1377 GList *attrs = NULL; |
1378 const gchar *id; | |
1379 gpointer data; | |
14192 | 1380 va_list args; |
1381 | |
1382 va_start(args, active); | |
14643 | 1383 while ((id = va_arg(args, const char *)) != NULL) |
14192 | 1384 { |
14643 | 1385 attrs = g_list_append(attrs, (char *)id); |
1386 data = va_arg(args, void *); | |
1387 attrs = g_list_append(attrs, data); | |
14192 | 1388 } |
1389 gaim_account_set_status_list(account, status_id, active, attrs); | |
1390 g_list_free(attrs); | |
14643 | 1391 va_end(args); |
14192 | 1392 } |
1393 | |
1394 void | |
1395 gaim_account_set_status_list(GaimAccount *account, const char *status_id, | |
1396 gboolean active, GList *attrs) | |
1397 { | |
1398 GaimStatus *status; | |
1399 | |
1400 g_return_if_fail(account != NULL); | |
1401 g_return_if_fail(status_id != NULL); | |
1402 | |
1403 status = gaim_account_get_status(account, status_id); | |
1404 if (status == NULL) | |
1405 { | |
1406 gaim_debug_error("account", | |
1407 "Invalid status ID %s for account %s (%s)\n", | |
1408 status_id, gaim_account_get_username(account), | |
1409 gaim_account_get_protocol_id(account)); | |
1410 return; | |
1411 } | |
1412 | |
1413 if (active || gaim_status_is_independent(status)) | |
1414 gaim_status_set_active_with_attrs_list(status, active, attrs); | |
1415 | |
1416 /* | |
1417 * Our current statuses are saved to accounts.xml (so that when we | |
1418 * reconnect, we go back to the previous status). | |
1419 */ | |
1420 schedule_accounts_save(); | |
1421 } | |
1422 | |
1423 void | |
1424 gaim_account_clear_settings(GaimAccount *account) | |
1425 { | |
1426 g_return_if_fail(account != NULL); | |
1427 | |
1428 g_hash_table_destroy(account->settings); | |
1429 | |
1430 account->settings = g_hash_table_new_full(g_str_hash, g_str_equal, | |
1431 g_free, delete_setting); | |
1432 } | |
1433 | |
1434 void | |
1435 gaim_account_set_int(GaimAccount *account, const char *name, int value) | |
1436 { | |
1437 GaimAccountSetting *setting; | |
1438 | |
1439 g_return_if_fail(account != NULL); | |
1440 g_return_if_fail(name != NULL); | |
1441 | |
1442 setting = g_new0(GaimAccountSetting, 1); | |
1443 | |
1444 setting->type = GAIM_PREF_INT; | |
1445 setting->value.integer = value; | |
1446 | |
1447 g_hash_table_insert(account->settings, g_strdup(name), setting); | |
1448 | |
1449 schedule_accounts_save(); | |
1450 } | |
1451 | |
1452 void | |
1453 gaim_account_set_string(GaimAccount *account, const char *name, | |
1454 const char *value) | |
1455 { | |
1456 GaimAccountSetting *setting; | |
1457 | |
1458 g_return_if_fail(account != NULL); | |
1459 g_return_if_fail(name != NULL); | |
1460 | |
1461 setting = g_new0(GaimAccountSetting, 1); | |
1462 | |
1463 setting->type = GAIM_PREF_STRING; | |
1464 setting->value.string = g_strdup(value); | |
1465 | |
1466 g_hash_table_insert(account->settings, g_strdup(name), setting); | |
1467 | |
1468 schedule_accounts_save(); | |
1469 } | |
1470 | |
1471 void | |
1472 gaim_account_set_bool(GaimAccount *account, const char *name, gboolean value) | |
1473 { | |
1474 GaimAccountSetting *setting; | |
1475 | |
1476 g_return_if_fail(account != NULL); | |
1477 g_return_if_fail(name != NULL); | |
1478 | |
1479 setting = g_new0(GaimAccountSetting, 1); | |
1480 | |
1481 setting->type = GAIM_PREF_BOOLEAN; | |
1482 setting->value.bool = value; | |
1483 | |
1484 g_hash_table_insert(account->settings, g_strdup(name), setting); | |
1485 | |
1486 schedule_accounts_save(); | |
1487 } | |
1488 | |
1489 static GHashTable * | |
1490 get_ui_settings_table(GaimAccount *account, const char *ui) | |
1491 { | |
1492 GHashTable *table; | |
1493 | |
1494 table = g_hash_table_lookup(account->ui_settings, ui); | |
1495 | |
1496 if (table == NULL) { | |
1497 table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, | |
1498 delete_setting); | |
1499 g_hash_table_insert(account->ui_settings, g_strdup(ui), table); | |
1500 } | |
1501 | |
1502 return table; | |
1503 } | |
1504 | |
1505 void | |
1506 gaim_account_set_ui_int(GaimAccount *account, const char *ui, | |
1507 const char *name, int value) | |
1508 { | |
1509 GaimAccountSetting *setting; | |
1510 GHashTable *table; | |
1511 | |
1512 g_return_if_fail(account != NULL); | |
1513 g_return_if_fail(ui != NULL); | |
1514 g_return_if_fail(name != NULL); | |
1515 | |
1516 setting = g_new0(GaimAccountSetting, 1); | |
1517 | |
1518 setting->type = GAIM_PREF_INT; | |
1519 setting->ui = g_strdup(ui); | |
1520 setting->value.integer = value; | |
1521 | |
1522 table = get_ui_settings_table(account, ui); | |
1523 | |
1524 g_hash_table_insert(table, g_strdup(name), setting); | |
1525 | |
1526 schedule_accounts_save(); | |
1527 } | |
1528 | |
1529 void | |
1530 gaim_account_set_ui_string(GaimAccount *account, const char *ui, | |
1531 const char *name, const char *value) | |
1532 { | |
1533 GaimAccountSetting *setting; | |
1534 GHashTable *table; | |
1535 | |
1536 g_return_if_fail(account != NULL); | |
1537 g_return_if_fail(ui != NULL); | |
1538 g_return_if_fail(name != NULL); | |
1539 | |
1540 setting = g_new0(GaimAccountSetting, 1); | |
1541 | |
1542 setting->type = GAIM_PREF_STRING; | |
1543 setting->ui = g_strdup(ui); | |
1544 setting->value.string = g_strdup(value); | |
1545 | |
1546 table = get_ui_settings_table(account, ui); | |
1547 | |
1548 g_hash_table_insert(table, g_strdup(name), setting); | |
1549 | |
1550 schedule_accounts_save(); | |
1551 } | |
1552 | |
1553 void | |
1554 gaim_account_set_ui_bool(GaimAccount *account, const char *ui, | |
1555 const char *name, gboolean value) | |
1556 { | |
1557 GaimAccountSetting *setting; | |
1558 GHashTable *table; | |
1559 | |
1560 g_return_if_fail(account != NULL); | |
1561 g_return_if_fail(ui != NULL); | |
1562 g_return_if_fail(name != NULL); | |
1563 | |
1564 setting = g_new0(GaimAccountSetting, 1); | |
1565 | |
1566 setting->type = GAIM_PREF_BOOLEAN; | |
1567 setting->ui = g_strdup(ui); | |
1568 setting->value.bool = value; | |
1569 | |
1570 table = get_ui_settings_table(account, ui); | |
1571 | |
1572 g_hash_table_insert(table, g_strdup(name), setting); | |
1573 | |
1574 schedule_accounts_save(); | |
1575 } | |
1576 | |
1577 static GaimConnectionState | |
1578 gaim_account_get_state(const GaimAccount *account) | |
1579 { | |
1580 GaimConnection *gc; | |
1581 | |
1582 g_return_val_if_fail(account != NULL, GAIM_DISCONNECTED); | |
1583 | |
1584 gc = gaim_account_get_connection(account); | |
1585 if (!gc) | |
1586 return GAIM_DISCONNECTED; | |
1587 | |
1588 return gaim_connection_get_state(gc); | |
1589 } | |
1590 | |
1591 gboolean | |
1592 gaim_account_is_connected(const GaimAccount *account) | |
1593 { | |
1594 return (gaim_account_get_state(account) == GAIM_CONNECTED); | |
1595 } | |
1596 | |
1597 gboolean | |
1598 gaim_account_is_connecting(const GaimAccount *account) | |
1599 { | |
1600 return (gaim_account_get_state(account) == GAIM_CONNECTING); | |
1601 } | |
1602 | |
1603 gboolean | |
1604 gaim_account_is_disconnected(const GaimAccount *account) | |
1605 { | |
1606 return (gaim_account_get_state(account) == GAIM_DISCONNECTED); | |
1607 } | |
1608 | |
1609 const char * | |
1610 gaim_account_get_username(const GaimAccount *account) | |
1611 { | |
1612 g_return_val_if_fail(account != NULL, NULL); | |
1613 | |
1614 return account->username; | |
1615 } | |
1616 | |
1617 const char * | |
1618 gaim_account_get_password(const GaimAccount *account) | |
1619 { | |
1620 g_return_val_if_fail(account != NULL, NULL); | |
1621 | |
1622 return account->password; | |
1623 } | |
1624 | |
1625 const char * | |
1626 gaim_account_get_alias(const GaimAccount *account) | |
1627 { | |
1628 g_return_val_if_fail(account != NULL, NULL); | |
1629 | |
1630 return account->alias; | |
1631 } | |
1632 | |
1633 const char * | |
1634 gaim_account_get_user_info(const GaimAccount *account) | |
1635 { | |
1636 g_return_val_if_fail(account != NULL, NULL); | |
1637 | |
1638 return account->user_info; | |
1639 } | |
1640 | |
1641 const char * | |
1642 gaim_account_get_buddy_icon(const GaimAccount *account) | |
1643 { | |
1644 g_return_val_if_fail(account != NULL, NULL); | |
1645 | |
1646 return account->buddy_icon; | |
1647 } | |
1648 | |
1649 const char * | |
1650 gaim_account_get_protocol_id(const GaimAccount *account) | |
1651 { | |
1652 g_return_val_if_fail(account != NULL, NULL); | |
14991 | 1653 /* |
1654 * HACK by Seanegan | |
1655 */ | |
1656 if (!strcmp(account->protocol_id, "prpl-oscar")) { | |
1657 if (isdigit(account->username[0])) | |
1658 return "prpl-icq"; | |
1659 else | |
1660 return "prpl-aim"; | |
1661 } | |
14192 | 1662 return account->protocol_id; |
1663 } | |
1664 | |
1665 const char * | |
1666 gaim_account_get_protocol_name(const GaimAccount *account) | |
1667 { | |
1668 GaimPlugin *p; | |
1669 | |
1670 g_return_val_if_fail(account != NULL, NULL); | |
1671 | |
1672 p = gaim_find_prpl(gaim_account_get_protocol_id(account)); | |
1673 | |
1674 return ((p && p->info->name) ? _(p->info->name) : _("Unknown")); | |
1675 } | |
1676 | |
1677 GaimConnection * | |
1678 gaim_account_get_connection(const GaimAccount *account) | |
1679 { | |
1680 g_return_val_if_fail(account != NULL, NULL); | |
1681 | |
1682 return account->gc; | |
1683 } | |
1684 | |
1685 gboolean | |
1686 gaim_account_get_remember_password(const GaimAccount *account) | |
1687 { | |
1688 g_return_val_if_fail(account != NULL, FALSE); | |
1689 | |
1690 return account->remember_pass; | |
1691 } | |
1692 | |
1693 gboolean | |
1694 gaim_account_get_check_mail(const GaimAccount *account) | |
1695 { | |
1696 g_return_val_if_fail(account != NULL, FALSE); | |
1697 | |
1698 return gaim_account_get_bool(account, "check-mail", FALSE); | |
1699 } | |
1700 | |
1701 gboolean | |
1702 gaim_account_get_enabled(const GaimAccount *account, const char *ui) | |
1703 { | |
1704 g_return_val_if_fail(account != NULL, FALSE); | |
1705 g_return_val_if_fail(ui != NULL, FALSE); | |
1706 | |
1707 return gaim_account_get_ui_bool(account, ui, "auto-login", FALSE); | |
1708 } | |
1709 | |
1710 GaimProxyInfo * | |
1711 gaim_account_get_proxy_info(const GaimAccount *account) | |
1712 { | |
1713 g_return_val_if_fail(account != NULL, NULL); | |
1714 | |
1715 return account->proxy_info; | |
1716 } | |
1717 | |
1718 GaimStatus * | |
1719 gaim_account_get_active_status(const GaimAccount *account) | |
1720 { | |
1721 g_return_val_if_fail(account != NULL, NULL); | |
1722 | |
1723 return gaim_presence_get_active_status(account->presence); | |
1724 } | |
1725 | |
1726 GaimStatus * | |
1727 gaim_account_get_status(const GaimAccount *account, const char *status_id) | |
1728 { | |
1729 g_return_val_if_fail(account != NULL, NULL); | |
1730 g_return_val_if_fail(status_id != NULL, NULL); | |
1731 | |
1732 return gaim_presence_get_status(account->presence, status_id); | |
1733 } | |
1734 | |
1735 GaimStatusType * | |
1736 gaim_account_get_status_type(const GaimAccount *account, const char *id) | |
1737 { | |
1738 const GList *l; | |
1739 | |
1740 g_return_val_if_fail(account != NULL, NULL); | |
1741 g_return_val_if_fail(id != NULL, NULL); | |
1742 | |
1743 for (l = gaim_account_get_status_types(account); l != NULL; l = l->next) | |
1744 { | |
1745 GaimStatusType *status_type = (GaimStatusType *)l->data; | |
1746 | |
1747 if (!strcmp(gaim_status_type_get_id(status_type), id)) | |
1748 return status_type; | |
1749 } | |
1750 | |
1751 return NULL; | |
1752 } | |
1753 | |
1754 GaimStatusType * | |
1755 gaim_account_get_status_type_with_primitive(const GaimAccount *account, GaimStatusPrimitive primitive) | |
1756 { | |
1757 const GList *l; | |
1758 | |
1759 g_return_val_if_fail(account != NULL, NULL); | |
1760 | |
1761 for (l = gaim_account_get_status_types(account); l != NULL; l = l->next) | |
1762 { | |
1763 GaimStatusType *status_type = (GaimStatusType *)l->data; | |
1764 | |
1765 if (gaim_status_type_get_primitive(status_type) == primitive) | |
1766 return status_type; | |
1767 } | |
1768 | |
1769 return NULL; | |
1770 } | |
1771 | |
1772 GaimPresence * | |
1773 gaim_account_get_presence(const GaimAccount *account) | |
1774 { | |
1775 g_return_val_if_fail(account != NULL, NULL); | |
1776 | |
1777 return account->presence; | |
1778 } | |
1779 | |
1780 gboolean | |
1781 gaim_account_is_status_active(const GaimAccount *account, | |
1782 const char *status_id) | |
1783 { | |
1784 g_return_val_if_fail(account != NULL, FALSE); | |
1785 g_return_val_if_fail(status_id != NULL, FALSE); | |
1786 | |
1787 return gaim_presence_is_status_active(account->presence, status_id); | |
1788 } | |
1789 | |
1790 const GList * | |
1791 gaim_account_get_status_types(const GaimAccount *account) | |
1792 { | |
1793 g_return_val_if_fail(account != NULL, NULL); | |
1794 | |
1795 return account->status_types; | |
1796 } | |
1797 | |
1798 int | |
1799 gaim_account_get_int(const GaimAccount *account, const char *name, | |
1800 int default_value) | |
1801 { | |
1802 GaimAccountSetting *setting; | |
1803 | |
1804 g_return_val_if_fail(account != NULL, default_value); | |
1805 g_return_val_if_fail(name != NULL, default_value); | |
1806 | |
1807 setting = g_hash_table_lookup(account->settings, name); | |
1808 | |
1809 if (setting == NULL) | |
1810 return default_value; | |
1811 | |
1812 g_return_val_if_fail(setting->type == GAIM_PREF_INT, default_value); | |
1813 | |
1814 return setting->value.integer; | |
1815 } | |
1816 | |
1817 const char * | |
1818 gaim_account_get_string(const GaimAccount *account, const char *name, | |
1819 const char *default_value) | |
1820 { | |
1821 GaimAccountSetting *setting; | |
1822 | |
1823 g_return_val_if_fail(account != NULL, default_value); | |
1824 g_return_val_if_fail(name != NULL, default_value); | |
1825 | |
1826 setting = g_hash_table_lookup(account->settings, name); | |
1827 | |
1828 if (setting == NULL) | |
1829 return default_value; | |
1830 | |
1831 g_return_val_if_fail(setting->type == GAIM_PREF_STRING, default_value); | |
1832 | |
1833 return setting->value.string; | |
1834 } | |
1835 | |
1836 gboolean | |
1837 gaim_account_get_bool(const GaimAccount *account, const char *name, | |
1838 gboolean default_value) | |
1839 { | |
1840 GaimAccountSetting *setting; | |
1841 | |
1842 g_return_val_if_fail(account != NULL, default_value); | |
1843 g_return_val_if_fail(name != NULL, default_value); | |
1844 | |
1845 setting = g_hash_table_lookup(account->settings, name); | |
1846 | |
1847 if (setting == NULL) | |
1848 return default_value; | |
1849 | |
1850 g_return_val_if_fail(setting->type == GAIM_PREF_BOOLEAN, default_value); | |
1851 | |
1852 return setting->value.bool; | |
1853 } | |
1854 | |
1855 int | |
1856 gaim_account_get_ui_int(const GaimAccount *account, const char *ui, | |
1857 const char *name, int default_value) | |
1858 { | |
1859 GaimAccountSetting *setting; | |
1860 GHashTable *table; | |
1861 | |
1862 g_return_val_if_fail(account != NULL, default_value); | |
1863 g_return_val_if_fail(ui != NULL, default_value); | |
1864 g_return_val_if_fail(name != NULL, default_value); | |
1865 | |
1866 if ((table = g_hash_table_lookup(account->ui_settings, ui)) == NULL) | |
1867 return default_value; | |
1868 | |
1869 if ((setting = g_hash_table_lookup(table, name)) == NULL) | |
1870 return default_value; | |
1871 | |
1872 g_return_val_if_fail(setting->type == GAIM_PREF_INT, default_value); | |
1873 | |
1874 return setting->value.integer; | |
1875 } | |
1876 | |
1877 const char * | |
1878 gaim_account_get_ui_string(const GaimAccount *account, const char *ui, | |
1879 const char *name, const char *default_value) | |
1880 { | |
1881 GaimAccountSetting *setting; | |
1882 GHashTable *table; | |
1883 | |
1884 g_return_val_if_fail(account != NULL, default_value); | |
1885 g_return_val_if_fail(ui != NULL, default_value); | |
1886 g_return_val_if_fail(name != NULL, default_value); | |
1887 | |
1888 if ((table = g_hash_table_lookup(account->ui_settings, ui)) == NULL) | |
1889 return default_value; | |
1890 | |
1891 if ((setting = g_hash_table_lookup(table, name)) == NULL) | |
1892 return default_value; | |
1893 | |
1894 g_return_val_if_fail(setting->type == GAIM_PREF_STRING, default_value); | |
1895 | |
1896 return setting->value.string; | |
1897 } | |
1898 | |
1899 gboolean | |
1900 gaim_account_get_ui_bool(const GaimAccount *account, const char *ui, | |
1901 const char *name, gboolean default_value) | |
1902 { | |
1903 GaimAccountSetting *setting; | |
1904 GHashTable *table; | |
1905 | |
1906 g_return_val_if_fail(account != NULL, default_value); | |
1907 g_return_val_if_fail(ui != NULL, default_value); | |
1908 g_return_val_if_fail(name != NULL, default_value); | |
1909 | |
1910 if ((table = g_hash_table_lookup(account->ui_settings, ui)) == NULL) | |
1911 return default_value; | |
1912 | |
1913 if ((setting = g_hash_table_lookup(table, name)) == NULL) | |
1914 return default_value; | |
1915 | |
1916 g_return_val_if_fail(setting->type == GAIM_PREF_BOOLEAN, default_value); | |
1917 | |
1918 return setting->value.bool; | |
1919 } | |
1920 | |
1921 GaimLog * | |
1922 gaim_account_get_log(GaimAccount *account, gboolean create) | |
1923 { | |
1924 g_return_val_if_fail(account != NULL, NULL); | |
1925 | |
1926 if(!account->system_log && create){ | |
1927 GaimPresence *presence; | |
1928 int login_time; | |
1929 | |
1930 presence = gaim_account_get_presence(account); | |
1931 login_time = gaim_presence_get_login_time(presence); | |
1932 | |
1933 account->system_log = gaim_log_new(GAIM_LOG_SYSTEM, | |
1934 gaim_account_get_username(account), account, NULL, | |
1935 (login_time != 0) ? login_time : time(NULL), NULL); | |
1936 } | |
1937 | |
1938 return account->system_log; | |
1939 } | |
1940 | |
1941 void | |
1942 gaim_account_destroy_log(GaimAccount *account) | |
1943 { | |
1944 g_return_if_fail(account != NULL); | |
1945 | |
1946 if(account->system_log){ | |
1947 gaim_log_free(account->system_log); | |
1948 account->system_log = NULL; | |
1949 } | |
1950 } | |
1951 | |
1952 void | |
1953 gaim_account_add_buddy(GaimAccount *account, GaimBuddy *buddy) | |
1954 { | |
1955 GaimPluginProtocolInfo *prpl_info = NULL; | |
1956 GaimConnection *gc = gaim_account_get_connection(account); | |
1957 | |
1958 if (gc != NULL && gc->prpl != NULL) | |
1959 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
1960 | |
14607 | 1961 if (prpl_info != NULL && prpl_info->add_buddy != NULL) |
14192 | 1962 prpl_info->add_buddy(gc, buddy, gaim_buddy_get_group(buddy)); |
1963 } | |
1964 | |
1965 void | |
1966 gaim_account_add_buddies(GaimAccount *account, GList *buddies) | |
1967 { | |
1968 GaimPluginProtocolInfo *prpl_info = NULL; | |
1969 GaimConnection *gc = gaim_account_get_connection(account); | |
1970 | |
1971 if (gc != NULL && gc->prpl != NULL) | |
1972 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
1973 | |
14607 | 1974 if (prpl_info) { |
14192 | 1975 GList *cur, *groups = NULL; |
1976 | |
1977 /* Make a list of what group each buddy is in */ | |
1978 for (cur = buddies; cur != NULL; cur = cur->next) { | |
1979 GaimBlistNode *node = cur->data; | |
1980 groups = g_list_append(groups, node->parent->parent); | |
1981 } | |
1982 | |
1983 if (prpl_info->add_buddies != NULL) | |
1984 prpl_info->add_buddies(gc, buddies, groups); | |
1985 else if (prpl_info->add_buddy != NULL) { | |
1986 GList *curb = buddies, *curg = groups; | |
1987 | |
1988 while ((curb != NULL) && (curg != NULL)) { | |
1989 prpl_info->add_buddy(gc, curb->data, curg->data); | |
1990 curb = curb->next; | |
1991 curg = curg->next; | |
1992 } | |
1993 } | |
1994 | |
1995 g_list_free(groups); | |
1996 } | |
1997 } | |
1998 | |
1999 void | |
2000 gaim_account_remove_buddy(GaimAccount *account, GaimBuddy *buddy, | |
2001 GaimGroup *group) | |
2002 { | |
2003 GaimPluginProtocolInfo *prpl_info = NULL; | |
2004 GaimConnection *gc = gaim_account_get_connection(account); | |
2005 | |
2006 if (gc != NULL && gc->prpl != NULL) | |
2007 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
2008 | |
14607 | 2009 if (prpl_info && prpl_info->remove_buddy) |
14192 | 2010 prpl_info->remove_buddy(gc, buddy, group); |
2011 } | |
2012 | |
2013 void | |
2014 gaim_account_remove_buddies(GaimAccount *account, GList *buddies, GList *groups) | |
2015 { | |
2016 GaimPluginProtocolInfo *prpl_info = NULL; | |
2017 GaimConnection *gc = gaim_account_get_connection(account); | |
2018 | |
2019 if (gc != NULL && gc->prpl != NULL) | |
2020 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
2021 | |
14607 | 2022 if (prpl_info) { |
14192 | 2023 if (prpl_info->remove_buddies) |
2024 prpl_info->remove_buddies(gc, buddies, groups); | |
2025 else { | |
2026 GList *curb = buddies; | |
2027 GList *curg = groups; | |
2028 while ((curb != NULL) && (curg != NULL)) { | |
2029 gaim_account_remove_buddy(account, curb->data, curg->data); | |
2030 curb = curb->next; | |
2031 curg = curg->next; | |
2032 } | |
2033 } | |
2034 } | |
2035 } | |
2036 | |
2037 void | |
2038 gaim_account_remove_group(GaimAccount *account, GaimGroup *group) | |
2039 { | |
2040 GaimPluginProtocolInfo *prpl_info = NULL; | |
2041 GaimConnection *gc = gaim_account_get_connection(account); | |
2042 | |
2043 if (gc != NULL && gc->prpl != NULL) | |
2044 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
2045 | |
14607 | 2046 if (prpl_info && prpl_info->remove_group) |
14192 | 2047 prpl_info->remove_group(gc, group); |
2048 } | |
2049 | |
2050 void | |
2051 gaim_account_change_password(GaimAccount *account, const char *orig_pw, | |
2052 const char *new_pw) | |
2053 { | |
2054 GaimPluginProtocolInfo *prpl_info = NULL; | |
2055 GaimConnection *gc = gaim_account_get_connection(account); | |
2056 | |
2057 gaim_account_set_password(account, new_pw); | |
2058 | |
2059 if (gc != NULL && gc->prpl != NULL) | |
2060 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
2061 | |
14607 | 2062 if (prpl_info && prpl_info->change_passwd) |
14192 | 2063 prpl_info->change_passwd(gc, orig_pw, new_pw); |
2064 } | |
2065 | |
2066 gboolean gaim_account_supports_offline_message(GaimAccount *account, GaimBuddy *buddy) | |
2067 { | |
2068 GaimConnection *gc; | |
2069 GaimPluginProtocolInfo *prpl_info; | |
2070 | |
2071 g_return_val_if_fail(account, FALSE); | |
2072 g_return_val_if_fail(buddy, FALSE); | |
2073 | |
2074 gc = gaim_account_get_connection(account); | |
2075 if (gc == NULL) | |
2076 return FALSE; | |
2077 | |
2078 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
2079 | |
2080 if (!prpl_info || !prpl_info->offline_message) | |
2081 return FALSE; | |
2082 return prpl_info->offline_message(buddy); | |
2083 } | |
2084 | |
2085 void | |
2086 gaim_accounts_add(GaimAccount *account) | |
2087 { | |
2088 g_return_if_fail(account != NULL); | |
2089 | |
2090 if (g_list_find(accounts, account) != NULL) | |
2091 return; | |
2092 | |
2093 accounts = g_list_append(accounts, account); | |
2094 | |
2095 schedule_accounts_save(); | |
2096 | |
2097 gaim_signal_emit(gaim_accounts_get_handle(), "account-added", account); | |
2098 } | |
2099 | |
2100 void | |
2101 gaim_accounts_remove(GaimAccount *account) | |
2102 { | |
2103 g_return_if_fail(account != NULL); | |
2104 | |
2105 accounts = g_list_remove(accounts, account); | |
2106 | |
2107 schedule_accounts_save(); | |
2108 | |
2109 gaim_signal_emit(gaim_accounts_get_handle(), "account-removed", account); | |
2110 } | |
2111 | |
2112 void | |
2113 gaim_accounts_delete(GaimAccount *account) | |
2114 { | |
2115 GaimBlistNode *gnode, *cnode, *bnode; | |
2116 | |
2117 g_return_if_fail(account != NULL); | |
2118 | |
14909 | 2119 /* |
2120 * Disable the account before blowing it out of the water. | |
2121 * Conceptually it probably makes more sense to disable the | |
2122 * account for all UIs rather than the just the current UI, | |
2123 * but it doesn't really matter. | |
2124 */ | |
2125 gaim_account_set_enabled(account, gaim_core_get_ui(), FALSE); | |
2126 | |
14192 | 2127 gaim_notify_close_with_handle(account); |
2128 gaim_request_close_with_handle(account); | |
2129 | |
2130 gaim_accounts_remove(account); | |
2131 | |
2132 /* Remove this account's buddies */ | |
2133 for (gnode = gaim_get_blist()->root; gnode != NULL; gnode = gnode->next) { | |
2134 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
2135 continue; | |
2136 | |
2137 cnode = gnode->child; | |
2138 while (cnode) { | |
2139 GaimBlistNode *cnode_next = cnode->next; | |
2140 | |
2141 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
2142 bnode = cnode->child; | |
2143 while (bnode) { | |
2144 GaimBlistNode *bnode_next = bnode->next; | |
2145 | |
2146 if (GAIM_BLIST_NODE_IS_BUDDY(bnode)) { | |
2147 GaimBuddy *b = (GaimBuddy *)bnode; | |
2148 | |
2149 if (b->account == account) | |
2150 gaim_blist_remove_buddy(b); | |
2151 } | |
2152 bnode = bnode_next; | |
2153 } | |
2154 } else if (GAIM_BLIST_NODE_IS_CHAT(cnode)) { | |
2155 GaimChat *c = (GaimChat *)cnode; | |
2156 | |
2157 if (c->account == account) | |
2158 gaim_blist_remove_chat(c); | |
2159 } | |
2160 cnode = cnode_next; | |
2161 } | |
2162 } | |
2163 | |
2164 /* Remove this account's pounces */ | |
2165 gaim_pounce_destroy_all_by_account(account); | |
2166 | |
2167 /* This will cause the deletion of an old buddy icon. */ | |
2168 gaim_account_set_buddy_icon(account, NULL); | |
2169 | |
2170 gaim_account_destroy(account); | |
2171 } | |
2172 | |
2173 void | |
2174 gaim_accounts_reorder(GaimAccount *account, gint new_index) | |
2175 { | |
2176 gint index; | |
2177 GList *l; | |
2178 | |
2179 g_return_if_fail(account != NULL); | |
2180 g_return_if_fail(new_index <= g_list_length(accounts)); | |
2181 | |
2182 index = g_list_index(accounts, account); | |
2183 | |
2184 if (index == -1) { | |
2185 gaim_debug_error("account", | |
2186 "Unregistered account (%s) discovered during reorder!\n", | |
2187 gaim_account_get_username(account)); | |
2188 return; | |
2189 } | |
2190 | |
2191 l = g_list_nth(accounts, index); | |
2192 | |
2193 if (new_index > index) | |
2194 new_index--; | |
2195 | |
2196 /* Remove the old one. */ | |
2197 accounts = g_list_delete_link(accounts, l); | |
2198 | |
2199 /* Insert it where it should go. */ | |
2200 accounts = g_list_insert(accounts, account, new_index); | |
2201 | |
2202 schedule_accounts_save(); | |
2203 } | |
2204 | |
2205 GList * | |
2206 gaim_accounts_get_all(void) | |
2207 { | |
2208 return accounts; | |
2209 } | |
2210 | |
2211 GList * | |
2212 gaim_accounts_get_all_active(void) | |
2213 { | |
2214 GList *list = NULL; | |
2215 GList *all = gaim_accounts_get_all(); | |
2216 | |
2217 while (all != NULL) { | |
2218 GaimAccount *account = all->data; | |
2219 | |
2220 if (gaim_account_get_enabled(account, gaim_core_get_ui())) | |
2221 list = g_list_append(list, account); | |
2222 | |
2223 all = all->next; | |
2224 } | |
2225 | |
2226 return list; | |
2227 } | |
2228 | |
2229 GaimAccount * | |
2230 gaim_accounts_find(const char *name, const char *protocol_id) | |
2231 { | |
2232 GaimAccount *account = NULL; | |
2233 GList *l; | |
2234 char *who; | |
2235 | |
2236 g_return_val_if_fail(name != NULL, NULL); | |
2237 | |
2238 who = g_strdup(gaim_normalize(NULL, name)); | |
2239 | |
2240 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) { | |
2241 account = (GaimAccount *)l->data; | |
2242 | |
2243 if (!strcmp(gaim_normalize(NULL, gaim_account_get_username(account)), who) && | |
2244 (!protocol_id || !strcmp(account->protocol_id, protocol_id))) { | |
2245 | |
2246 break; | |
2247 } | |
2248 | |
2249 account = NULL; | |
2250 } | |
2251 | |
2252 g_free(who); | |
2253 | |
2254 return account; | |
2255 } | |
2256 | |
2257 void | |
2258 gaim_accounts_restore_current_statuses() | |
2259 { | |
2260 GList *l; | |
2261 GaimAccount *account; | |
2262 | |
14696 | 2263 /* If we're not connected to the Internet right now, we bail on this */ |
2264 if (!gaim_network_is_available()) | |
2265 { | |
14705 | 2266 gaim_debug_info("account", "Network not connected; skipping reconnect\n"); |
14696 | 2267 return; |
2268 } | |
2269 | |
14192 | 2270 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) |
2271 { | |
2272 account = (GaimAccount *)l->data; | |
2273 if (gaim_account_get_enabled(account, gaim_core_get_ui()) && | |
2274 (gaim_presence_is_online(account->presence))) | |
2275 { | |
2276 gaim_account_connect(account); | |
2277 } | |
2278 } | |
2279 } | |
2280 | |
2281 void | |
2282 gaim_accounts_set_ui_ops(GaimAccountUiOps *ops) | |
2283 { | |
2284 account_ui_ops = ops; | |
2285 } | |
2286 | |
2287 GaimAccountUiOps * | |
2288 gaim_accounts_get_ui_ops(void) | |
2289 { | |
2290 return account_ui_ops; | |
2291 } | |
2292 | |
2293 void * | |
2294 gaim_accounts_get_handle(void) | |
2295 { | |
2296 static int handle; | |
2297 | |
2298 return &handle; | |
2299 } | |
2300 | |
2301 void | |
2302 gaim_accounts_init(void) | |
2303 { | |
2304 void *handle = gaim_accounts_get_handle(); | |
2305 | |
2306 gaim_signal_register(handle, "account-connecting", | |
2307 gaim_marshal_VOID__POINTER, NULL, 1, | |
2308 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
2309 GAIM_SUBTYPE_ACCOUNT)); | |
2310 | |
2311 gaim_signal_register(handle, "account-disabled", | |
2312 gaim_marshal_VOID__POINTER, NULL, 1, | |
2313 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
2314 GAIM_SUBTYPE_ACCOUNT)); | |
2315 | |
2316 gaim_signal_register(handle, "account-enabled", | |
2317 gaim_marshal_VOID__POINTER, NULL, 1, | |
2318 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
2319 GAIM_SUBTYPE_ACCOUNT)); | |
2320 | |
2321 gaim_signal_register(handle, "account-setting-info", | |
2322 gaim_marshal_VOID__POINTER_POINTER, NULL, 2, | |
2323 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
2324 GAIM_SUBTYPE_ACCOUNT), | |
2325 gaim_value_new(GAIM_TYPE_STRING)); | |
2326 | |
2327 gaim_signal_register(handle, "account-set-info", | |
2328 gaim_marshal_VOID__POINTER_POINTER, NULL, 2, | |
2329 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
2330 GAIM_SUBTYPE_ACCOUNT), | |
2331 gaim_value_new(GAIM_TYPE_STRING)); | |
2332 | |
2333 gaim_signal_register(handle, "account-added", | |
2334 gaim_marshal_VOID__POINTER, NULL, 1, | |
2335 gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_ACCOUNT)); | |
2336 | |
2337 gaim_signal_register(handle, "account-removed", | |
2338 gaim_marshal_VOID__POINTER, NULL, 1, | |
2339 gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_ACCOUNT)); | |
2340 | |
2341 gaim_signal_register(handle, "account-status-changed", | |
2342 gaim_marshal_VOID__POINTER_POINTER_POINTER, NULL, 3, | |
2343 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
2344 GAIM_SUBTYPE_ACCOUNT), | |
2345 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
2346 GAIM_SUBTYPE_STATUS), | |
2347 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
2348 GAIM_SUBTYPE_STATUS)); | |
2349 | |
2350 gaim_signal_register(handle, "account-alias-changed", | |
2351 gaim_marshal_VOID__POINTER_POINTER, NULL, 2, | |
2352 gaim_value_new(GAIM_TYPE_SUBTYPE, | |
2353 GAIM_SUBTYPE_ACCOUNT), | |
2354 gaim_value_new(GAIM_TYPE_STRING)); | |
2355 | |
2356 load_accounts(); | |
2357 | |
2358 } | |
2359 | |
2360 void | |
2361 gaim_accounts_uninit(void) | |
2362 { | |
2363 if (save_timer != 0) | |
2364 { | |
2365 gaim_timeout_remove(save_timer); | |
2366 save_timer = 0; | |
2367 sync_accounts(); | |
2368 } | |
2369 | |
2370 gaim_signals_unregister_by_instance(gaim_accounts_get_handle()); | |
2371 } |