Mercurial > pidgin
annotate src/account.c @ 5687:ae626f0b68ef
[gaim-migrate @ 6108]
The rest of the proxy options are added, and modifying the Proxy type box
shows or hides the detailed options, depending on the item chosen.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Tue, 03 Jun 2003 05:09:54 +0000 |
parents | 46d7ad0dfa26 |
children | 2d0d96c5a7a7 |
rev | line source |
---|---|
5574
a95e872e58dc
[gaim-migrate @ 5978]
Christian Hammond <chipx86@chipx86.com>
parents:
5573
diff
changeset
|
1 /* |
5563 | 2 * @file account.c Account API |
3 * @ingroup core | |
4 * | |
5 * gaim | |
6 * | |
7 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
8 * | |
9 * This program is free software; you can redistribute it and/or modify | |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
22 */ | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
23 #ifdef HAVE_CONFIG_H |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
24 #include <config.h> |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
25 #endif |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
26 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
27 #include <string.h> |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
28 #include <stdio.h> |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
29 #include <stdlib.h> |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
30 #include <sys/stat.h> |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
31 #include <sys/types.h> |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
32 #include <glib.h> |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
33 |
5563 | 34 #include "account.h" |
35 #include "prefs.h" | |
5665
132a30783c3d
[gaim-migrate @ 6081]
Christian Hammond <chipx86@chipx86.com>
parents:
5659
diff
changeset
|
36 #include "prpl.h" |
5563 | 37 |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
38 typedef enum |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
39 { |
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
40 TAG_NONE = 0, |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
41 TAG_PROTOCOL, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
42 TAG_NAME, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
43 TAG_PASSWORD, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
44 TAG_ALIAS, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
45 TAG_USERINFO, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
46 TAG_BUDDYICON, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
47 TAG_SETTING |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
48 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
49 } AccountParserTag; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
50 |
5563 | 51 typedef struct |
52 { | |
53 GaimPrefType type; | |
54 | |
55 union | |
56 { | |
57 int integer; | |
58 char *string; | |
59 gboolean bool; | |
60 | |
61 } value; | |
62 | |
63 } GaimAccountSetting; | |
64 | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
65 typedef struct |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
66 { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
67 AccountParserTag tag; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
68 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
69 GaimAccount *account; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
70 GaimProtocol protocol; |
5643
eb685809108b
[gaim-migrate @ 6057]
Christian Hammond <chipx86@chipx86.com>
parents:
5620
diff
changeset
|
71 char *protocol_id; |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
72 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
73 GString *buffer; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
74 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
75 GaimPrefType setting_type; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
76 char *setting_name; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
77 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
78 } AccountParserData; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
79 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
80 static GList *accounts = NULL; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
81 static guint accounts_save_timer = 0; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
82 static gboolean accounts_loaded = FALSE; |
5563 | 83 |
84 static void | |
85 __delete_setting(void *data) | |
86 { | |
87 GaimAccountSetting *setting = (GaimAccountSetting *)data; | |
88 | |
89 if (setting->type == GAIM_PREF_STRING) | |
90 g_free(setting->value.string); | |
91 | |
92 g_free(setting); | |
93 } | |
94 | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
95 static gboolean |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
96 __accounts_save_cb(gpointer unused) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
97 { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
98 gaim_accounts_sync(); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
99 accounts_save_timer = 0; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
100 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
101 return FALSE; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
102 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
103 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
104 static void |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
105 schedule_accounts_save() |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
106 { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
107 if (!accounts_save_timer) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
108 accounts_save_timer = g_timeout_add(5000, __accounts_save_cb, NULL); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
109 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
110 |
5563 | 111 GaimAccount * |
112 gaim_account_new(const char *username, GaimProtocol protocol) | |
113 { | |
114 GaimAccount *account; | |
115 | |
116 g_return_val_if_fail(username != NULL, NULL); | |
117 | |
118 account = g_new0(GaimAccount, 1); | |
119 | |
120 gaim_account_set_username(account, username); | |
121 gaim_account_set_protocol(account, protocol); | |
122 | |
123 account->settings = g_hash_table_new_full(g_str_hash, g_str_equal, | |
124 g_free, __delete_setting); | |
125 | |
126 accounts = g_list_append(accounts, account); | |
127 | |
128 return account; | |
129 } | |
130 | |
131 void | |
132 gaim_account_destroy(GaimAccount *account) | |
133 { | |
134 g_return_if_fail(account != NULL); | |
135 | |
136 if (account->gc != NULL) | |
137 gaim_connection_destroy(account->gc); | |
138 | |
5643
eb685809108b
[gaim-migrate @ 6057]
Christian Hammond <chipx86@chipx86.com>
parents:
5620
diff
changeset
|
139 if (account->username != NULL) g_free(account->username); |
eb685809108b
[gaim-migrate @ 6057]
Christian Hammond <chipx86@chipx86.com>
parents:
5620
diff
changeset
|
140 if (account->alias != NULL) g_free(account->alias); |
eb685809108b
[gaim-migrate @ 6057]
Christian Hammond <chipx86@chipx86.com>
parents:
5620
diff
changeset
|
141 if (account->password != NULL) g_free(account->password); |
eb685809108b
[gaim-migrate @ 6057]
Christian Hammond <chipx86@chipx86.com>
parents:
5620
diff
changeset
|
142 if (account->user_info != NULL) g_free(account->user_info); |
eb685809108b
[gaim-migrate @ 6057]
Christian Hammond <chipx86@chipx86.com>
parents:
5620
diff
changeset
|
143 if (account->protocol_id != NULL) g_free(account->protocol_id); |
5563 | 144 |
145 g_hash_table_destroy(account->settings); | |
146 | |
147 accounts = g_list_remove(accounts, account); | |
148 | |
149 g_free(account); | |
150 } | |
151 | |
152 GaimConnection * | |
153 gaim_account_connect(GaimAccount *account) | |
154 { | |
155 GaimConnection *gc; | |
156 | |
157 g_return_val_if_fail(account != NULL, NULL); | |
158 g_return_val_if_fail(!gaim_account_is_connected(account), NULL); | |
159 | |
160 gc = gaim_connection_new(account); | |
161 | |
162 gaim_connection_connect(gc); | |
163 | |
164 return gc; | |
165 } | |
166 | |
167 void | |
168 gaim_account_disconnect(GaimAccount *account) | |
169 { | |
170 g_return_if_fail(account != NULL); | |
171 g_return_if_fail(gaim_account_is_connected(account)); | |
172 | |
173 gaim_connection_disconnect(account->gc); | |
174 | |
175 account->gc = NULL; | |
176 } | |
177 | |
178 void | |
179 gaim_account_set_username(GaimAccount *account, const char *username) | |
180 { | |
181 g_return_if_fail(account != NULL); | |
182 g_return_if_fail(username != NULL); | |
183 | |
184 if (account->username != NULL) | |
185 g_free(account->username); | |
186 | |
187 account->username = (username == NULL ? NULL : g_strdup(username)); | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
188 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
189 schedule_accounts_save(); |
5563 | 190 } |
191 | |
192 void | |
193 gaim_account_set_password(GaimAccount *account, const char *password) | |
194 { | |
195 g_return_if_fail(account != NULL); | |
196 g_return_if_fail(password != NULL); | |
197 | |
198 if (account->password != NULL) | |
199 g_free(account->password); | |
200 | |
201 account->password = (password == NULL ? NULL : g_strdup(password)); | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
202 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
203 schedule_accounts_save(); |
5563 | 204 } |
205 | |
206 void | |
207 gaim_account_set_alias(GaimAccount *account, const char *alias) | |
208 { | |
209 g_return_if_fail(account != NULL); | |
210 g_return_if_fail(alias != NULL); | |
211 | |
212 if (account->alias != NULL) | |
213 g_free(account->alias); | |
214 | |
215 account->alias = (alias == NULL ? NULL : g_strdup(alias)); | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
216 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
217 schedule_accounts_save(); |
5563 | 218 } |
219 | |
220 void | |
221 gaim_account_set_user_info(GaimAccount *account, const char *user_info) | |
222 { | |
223 g_return_if_fail(account != NULL); | |
224 g_return_if_fail(user_info != NULL); | |
225 | |
226 if (account->user_info != NULL) | |
227 g_free(account->user_info); | |
228 | |
229 account->user_info = (user_info == NULL ? NULL : g_strdup(user_info)); | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
230 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
231 schedule_accounts_save(); |
5563 | 232 } |
233 | |
234 void | |
235 gaim_account_set_buddy_icon(GaimAccount *account, const char *icon) | |
236 { | |
237 g_return_if_fail(account != NULL); | |
238 g_return_if_fail(icon != NULL); | |
239 | |
240 if (account->buddy_icon != NULL) | |
241 g_free(account->buddy_icon); | |
242 | |
243 account->buddy_icon = (icon == NULL ? NULL : g_strdup(icon)); | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
244 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
245 schedule_accounts_save(); |
5563 | 246 } |
247 | |
248 void | |
249 gaim_account_set_protocol(GaimAccount *account, GaimProtocol protocol) | |
250 { | |
5665
132a30783c3d
[gaim-migrate @ 6081]
Christian Hammond <chipx86@chipx86.com>
parents:
5659
diff
changeset
|
251 GaimPlugin *plugin; |
132a30783c3d
[gaim-migrate @ 6081]
Christian Hammond <chipx86@chipx86.com>
parents:
5659
diff
changeset
|
252 |
5563 | 253 g_return_if_fail(account != NULL); |
254 | |
5665
132a30783c3d
[gaim-migrate @ 6081]
Christian Hammond <chipx86@chipx86.com>
parents:
5659
diff
changeset
|
255 plugin = gaim_find_prpl(protocol); |
132a30783c3d
[gaim-migrate @ 6081]
Christian Hammond <chipx86@chipx86.com>
parents:
5659
diff
changeset
|
256 |
132a30783c3d
[gaim-migrate @ 6081]
Christian Hammond <chipx86@chipx86.com>
parents:
5659
diff
changeset
|
257 g_return_if_fail(plugin != NULL); |
132a30783c3d
[gaim-migrate @ 6081]
Christian Hammond <chipx86@chipx86.com>
parents:
5659
diff
changeset
|
258 |
5563 | 259 account->protocol = protocol; |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
260 |
5665
132a30783c3d
[gaim-migrate @ 6081]
Christian Hammond <chipx86@chipx86.com>
parents:
5659
diff
changeset
|
261 if (account->protocol_id != NULL) |
132a30783c3d
[gaim-migrate @ 6081]
Christian Hammond <chipx86@chipx86.com>
parents:
5659
diff
changeset
|
262 g_free(account->protocol_id); |
132a30783c3d
[gaim-migrate @ 6081]
Christian Hammond <chipx86@chipx86.com>
parents:
5659
diff
changeset
|
263 |
132a30783c3d
[gaim-migrate @ 6081]
Christian Hammond <chipx86@chipx86.com>
parents:
5659
diff
changeset
|
264 account->protocol_id = g_strdup(plugin->info->id); |
132a30783c3d
[gaim-migrate @ 6081]
Christian Hammond <chipx86@chipx86.com>
parents:
5659
diff
changeset
|
265 |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
266 schedule_accounts_save(); |
5563 | 267 } |
268 | |
269 void | |
270 gaim_account_set_connection(GaimAccount *account, GaimConnection *gc) | |
271 { | |
272 g_return_if_fail(account != NULL); | |
273 g_return_if_fail(gc != NULL); | |
274 | |
275 account->gc = gc; | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
276 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
277 schedule_accounts_save(); |
5563 | 278 } |
279 | |
280 void | |
281 gaim_account_set_remember_password(GaimAccount *account, gboolean value) | |
282 { | |
283 g_return_if_fail(account != NULL); | |
284 | |
285 account->remember_pass = value; | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
286 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
287 schedule_accounts_save(); |
5563 | 288 } |
289 | |
290 void | |
5659
6b3214ab8632
[gaim-migrate @ 6073]
Christian Hammond <chipx86@chipx86.com>
parents:
5643
diff
changeset
|
291 gaim_account_set_check_mail(GaimAccount *account, gboolean value) |
6b3214ab8632
[gaim-migrate @ 6073]
Christian Hammond <chipx86@chipx86.com>
parents:
5643
diff
changeset
|
292 { |
6b3214ab8632
[gaim-migrate @ 6073]
Christian Hammond <chipx86@chipx86.com>
parents:
5643
diff
changeset
|
293 g_return_if_fail(account != NULL); |
6b3214ab8632
[gaim-migrate @ 6073]
Christian Hammond <chipx86@chipx86.com>
parents:
5643
diff
changeset
|
294 |
6b3214ab8632
[gaim-migrate @ 6073]
Christian Hammond <chipx86@chipx86.com>
parents:
5643
diff
changeset
|
295 account->check_mail = value; |
6b3214ab8632
[gaim-migrate @ 6073]
Christian Hammond <chipx86@chipx86.com>
parents:
5643
diff
changeset
|
296 |
6b3214ab8632
[gaim-migrate @ 6073]
Christian Hammond <chipx86@chipx86.com>
parents:
5643
diff
changeset
|
297 schedule_accounts_save(); |
6b3214ab8632
[gaim-migrate @ 6073]
Christian Hammond <chipx86@chipx86.com>
parents:
5643
diff
changeset
|
298 } |
6b3214ab8632
[gaim-migrate @ 6073]
Christian Hammond <chipx86@chipx86.com>
parents:
5643
diff
changeset
|
299 |
6b3214ab8632
[gaim-migrate @ 6073]
Christian Hammond <chipx86@chipx86.com>
parents:
5643
diff
changeset
|
300 void |
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5666
diff
changeset
|
301 gaim_account_set_proxy_info(GaimAccount *account, GaimProxyInfo *info) |
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5666
diff
changeset
|
302 { |
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5666
diff
changeset
|
303 g_return_if_fail(account != NULL); |
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5666
diff
changeset
|
304 |
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5666
diff
changeset
|
305 account->proxy_info = info; |
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5666
diff
changeset
|
306 |
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5666
diff
changeset
|
307 schedule_accounts_save(); |
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5666
diff
changeset
|
308 } |
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5666
diff
changeset
|
309 |
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5666
diff
changeset
|
310 void |
5563 | 311 gaim_account_set_int(GaimAccount *account, const char *name, int value) |
312 { | |
313 GaimAccountSetting *setting; | |
314 | |
315 g_return_if_fail(account != NULL); | |
316 g_return_if_fail(name != NULL); | |
317 | |
318 setting = g_new0(GaimAccountSetting, 1); | |
319 | |
320 setting->type = GAIM_PREF_INT; | |
321 setting->value.integer = value; | |
322 | |
323 g_hash_table_insert(account->settings, g_strdup(name), setting); | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
324 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
325 schedule_accounts_save(); |
5563 | 326 } |
327 | |
328 void | |
329 gaim_account_set_string(GaimAccount *account, const char *name, | |
330 const char *value) | |
331 { | |
332 GaimAccountSetting *setting; | |
333 | |
334 g_return_if_fail(account != NULL); | |
335 g_return_if_fail(name != NULL); | |
336 | |
337 setting = g_new0(GaimAccountSetting, 1); | |
338 | |
339 setting->type = GAIM_PREF_STRING; | |
340 setting->value.string = g_strdup(value); | |
341 | |
342 g_hash_table_insert(account->settings, g_strdup(name), setting); | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
343 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
344 schedule_accounts_save(); |
5563 | 345 } |
346 | |
347 void | |
348 gaim_account_set_bool(GaimAccount *account, const char *name, gboolean value) | |
349 { | |
350 GaimAccountSetting *setting; | |
351 | |
352 g_return_if_fail(account != NULL); | |
353 g_return_if_fail(name != NULL); | |
354 | |
355 setting = g_new0(GaimAccountSetting, 1); | |
356 | |
357 setting->type = GAIM_PREF_BOOLEAN; | |
358 setting->value.bool = value; | |
359 | |
360 g_hash_table_insert(account->settings, g_strdup(name), setting); | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
361 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
362 schedule_accounts_save(); |
5563 | 363 } |
364 | |
365 gboolean | |
366 gaim_account_is_connected(const GaimAccount *account) | |
367 { | |
368 g_return_val_if_fail(account != NULL, FALSE); | |
369 | |
370 return (account->gc != NULL && | |
371 gaim_connection_get_state(account->gc) == GAIM_CONNECTED); | |
372 } | |
373 | |
374 const char * | |
375 gaim_account_get_username(const GaimAccount *account) | |
376 { | |
377 g_return_val_if_fail(account != NULL, NULL); | |
378 | |
379 return account->username; | |
380 } | |
381 | |
382 const char * | |
383 gaim_account_get_password(const GaimAccount *account) | |
384 { | |
385 g_return_val_if_fail(account != NULL, NULL); | |
386 | |
387 return account->password; | |
388 } | |
389 | |
390 const char * | |
391 gaim_account_get_alias(const GaimAccount *account) | |
392 { | |
393 g_return_val_if_fail(account != NULL, NULL); | |
394 | |
395 return account->alias; | |
396 } | |
397 | |
398 const char * | |
399 gaim_account_get_user_info(const GaimAccount *account) | |
400 { | |
401 g_return_val_if_fail(account != NULL, NULL); | |
402 | |
403 return account->user_info; | |
404 } | |
405 | |
406 const char * | |
407 gaim_account_get_buddy_icon(const GaimAccount *account) | |
408 { | |
409 g_return_val_if_fail(account != NULL, NULL); | |
410 | |
411 return account->buddy_icon; | |
412 } | |
413 | |
414 GaimProtocol | |
415 gaim_account_get_protocol(const GaimAccount *account) | |
416 { | |
417 g_return_val_if_fail(account != NULL, -1); | |
418 | |
419 return account->protocol; | |
420 } | |
421 | |
422 GaimConnection * | |
423 gaim_account_get_connection(const GaimAccount *account) | |
424 { | |
425 g_return_val_if_fail(account != NULL, NULL); | |
426 | |
427 return account->gc; | |
428 } | |
429 | |
430 gboolean | |
431 gaim_account_get_remember_password(const GaimAccount *account) | |
432 { | |
433 g_return_val_if_fail(account != NULL, FALSE); | |
434 | |
435 return account->remember_pass; | |
436 } | |
437 | |
5565
c3c4aaf69f65
[gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
438 gboolean |
c3c4aaf69f65
[gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
439 gaim_account_get_check_mail(const GaimAccount *account) |
c3c4aaf69f65
[gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
440 { |
c3c4aaf69f65
[gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
441 g_return_val_if_fail(account != NULL, FALSE); |
c3c4aaf69f65
[gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
442 |
c3c4aaf69f65
[gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
443 return account->check_mail; |
c3c4aaf69f65
[gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
444 } |
c3c4aaf69f65
[gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
445 |
5681
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5666
diff
changeset
|
446 GaimProxyInfo * |
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5666
diff
changeset
|
447 gaim_account_get_proxy_info(const GaimAccount *account) |
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5666
diff
changeset
|
448 { |
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5666
diff
changeset
|
449 g_return_val_if_fail(account != NULL, NULL); |
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5666
diff
changeset
|
450 |
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5666
diff
changeset
|
451 return account->proxy_info; |
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5666
diff
changeset
|
452 } |
46d7ad0dfa26
[gaim-migrate @ 6100]
Christian Hammond <chipx86@chipx86.com>
parents:
5666
diff
changeset
|
453 |
5563 | 454 int |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
455 gaim_account_get_int(const GaimAccount *account, const char *name, |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
456 int default_value) |
5563 | 457 { |
458 GaimAccountSetting *setting; | |
459 | |
5565
c3c4aaf69f65
[gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
460 g_return_val_if_fail(account != NULL, default_value); |
c3c4aaf69f65
[gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
461 g_return_val_if_fail(name != NULL, default_value); |
5563 | 462 |
463 setting = g_hash_table_lookup(account->settings, name); | |
464 | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
465 if (setting == NULL) |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
466 return default_value; |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
467 |
5565
c3c4aaf69f65
[gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
468 g_return_val_if_fail(setting->type == GAIM_PREF_INT, default_value); |
5563 | 469 |
470 return setting->value.integer; | |
471 } | |
472 | |
473 const char * | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
474 gaim_account_get_string(const GaimAccount *account, const char *name, |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
475 const char *default_value) |
5563 | 476 { |
477 GaimAccountSetting *setting; | |
478 | |
5565
c3c4aaf69f65
[gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
479 g_return_val_if_fail(account != NULL, default_value); |
c3c4aaf69f65
[gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
480 g_return_val_if_fail(name != NULL, default_value); |
5563 | 481 |
482 setting = g_hash_table_lookup(account->settings, name); | |
483 | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
484 if (setting == NULL) |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
485 return default_value; |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
486 |
5565
c3c4aaf69f65
[gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
487 g_return_val_if_fail(setting->type == GAIM_PREF_STRING, default_value); |
5563 | 488 |
489 return setting->value.string; | |
490 } | |
491 | |
492 gboolean | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
493 gaim_account_get_bool(const GaimAccount *account, const char *name, |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
494 gboolean default_value) |
5563 | 495 { |
496 GaimAccountSetting *setting; | |
497 | |
5565
c3c4aaf69f65
[gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
498 g_return_val_if_fail(account != NULL, default_value); |
c3c4aaf69f65
[gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
499 g_return_val_if_fail(name != NULL, default_value); |
5563 | 500 |
501 setting = g_hash_table_lookup(account->settings, name); | |
502 | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
503 if (setting == NULL) |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
504 return default_value; |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
505 |
5565
c3c4aaf69f65
[gaim-migrate @ 5967]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
506 g_return_val_if_fail(setting->type == GAIM_PREF_BOOLEAN, default_value); |
5563 | 507 |
508 return setting->value.bool; | |
509 } | |
510 | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
511 /* XML Stuff */ |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
512 static void |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
513 __free_parser_data(gpointer user_data) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
514 { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
515 AccountParserData *data = user_data; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
516 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
517 if (data->buffer != NULL) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
518 g_free(data->buffer); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
519 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
520 if (data->setting_name != NULL) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
521 g_free(data->setting_name); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
522 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
523 g_free(data); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
524 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
525 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
526 static void |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
527 __start_element_handler(GMarkupParseContext *context, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
528 const gchar *element_name, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
529 const gchar **attribute_names, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
530 const gchar **attribute_values, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
531 gpointer user_data, GError **error) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
532 { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
533 AccountParserData *data = user_data; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
534 int i; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
535 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
536 if (data->buffer != NULL) { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
537 g_string_free(data->buffer, TRUE); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
538 data->buffer = NULL; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
539 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
540 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
541 if (!strcmp(element_name, "protocol")) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
542 data->tag = TAG_PROTOCOL; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
543 else if (!strcmp(element_name, "name")) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
544 data->tag = TAG_NAME; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
545 else if (!strcmp(element_name, "password")) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
546 data->tag = TAG_PASSWORD; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
547 else if (!strcmp(element_name, "alias")) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
548 data->tag = TAG_ALIAS; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
549 else if (!strcmp(element_name, "userinfo")) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
550 data->tag = TAG_USERINFO; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
551 else if (!strcmp(element_name, "buddyicon")) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
552 data->tag = TAG_BUDDYICON; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
553 else if (!strcmp(element_name, "setting")) { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
554 data->tag = TAG_SETTING; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
555 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
556 for (i = 0; attribute_names[i] != NULL; i++) { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
557 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
558 if (!strcmp(attribute_names[i], "name")) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
559 data->setting_name = g_strdup(attribute_values[i]); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
560 else if (!strcmp(attribute_names[i], "type")) { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
561 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
562 if (!strcmp(attribute_values[i], "string")) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
563 data->setting_type = GAIM_PREF_STRING; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
564 else if (!strcmp(attribute_values[i], "int")) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
565 data->setting_type = GAIM_PREF_INT; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
566 else if (!strcmp(attribute_values[i], "bool")) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
567 data->setting_type = GAIM_PREF_BOOLEAN; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
568 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
569 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
570 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
571 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
572 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
573 static void |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
574 __end_element_handler(GMarkupParseContext *context, const gchar *element_name, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
575 gpointer user_data, GError **error) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
576 { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
577 AccountParserData *data = user_data; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
578 gchar *buffer; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
579 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
580 if (data->buffer == NULL) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
581 return; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
582 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
583 buffer = g_string_free(data->buffer, FALSE); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
584 data->buffer = NULL; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
585 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
586 if (data->tag == TAG_PROTOCOL) { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
587 GList *l; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
588 GaimPlugin *plugin; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
589 |
5643
eb685809108b
[gaim-migrate @ 6057]
Christian Hammond <chipx86@chipx86.com>
parents:
5620
diff
changeset
|
590 data->protocol_id = g_strdup(buffer); |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
591 data->protocol = -1; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
592 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
593 for (l = gaim_plugins_get_protocols(); l != NULL; l = l->next) { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
594 plugin = (GaimPlugin *)l->data; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
595 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
596 if (GAIM_IS_PROTOCOL_PLUGIN(plugin)) { |
5581
3a9b54f260e3
[gaim-migrate @ 5985]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
597 if (!strcmp(plugin->info->id, buffer)) { |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
598 data->protocol = |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
599 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->protocol; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
600 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
601 break; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
602 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
603 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
604 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
605 } |
5643
eb685809108b
[gaim-migrate @ 6057]
Christian Hammond <chipx86@chipx86.com>
parents:
5620
diff
changeset
|
606 else if (data->tag == TAG_NAME) { |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
607 data->account = gaim_account_new(buffer, data->protocol); |
5643
eb685809108b
[gaim-migrate @ 6057]
Christian Hammond <chipx86@chipx86.com>
parents:
5620
diff
changeset
|
608 data->account->protocol_id = data->protocol_id; |
eb685809108b
[gaim-migrate @ 6057]
Christian Hammond <chipx86@chipx86.com>
parents:
5620
diff
changeset
|
609 |
eb685809108b
[gaim-migrate @ 6057]
Christian Hammond <chipx86@chipx86.com>
parents:
5620
diff
changeset
|
610 data->protocol_id = NULL; |
eb685809108b
[gaim-migrate @ 6057]
Christian Hammond <chipx86@chipx86.com>
parents:
5620
diff
changeset
|
611 } |
5581
3a9b54f260e3
[gaim-migrate @ 5985]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
612 else if (data->tag == TAG_PASSWORD) { |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
613 gaim_account_set_password(data->account, buffer); |
5581
3a9b54f260e3
[gaim-migrate @ 5985]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
614 gaim_account_set_remember_password(data->account, TRUE); |
3a9b54f260e3
[gaim-migrate @ 5985]
Christian Hammond <chipx86@chipx86.com>
parents:
5580
diff
changeset
|
615 } |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
616 else if (data->tag == TAG_ALIAS) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
617 gaim_account_set_alias(data->account, buffer); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
618 else if (data->tag == TAG_USERINFO) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
619 gaim_account_set_user_info(data->account, buffer); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
620 else if (data->tag == TAG_BUDDYICON) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
621 gaim_account_set_buddy_icon(data->account, buffer); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
622 else if (data->tag == TAG_SETTING) { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
623 if (data->setting_type == GAIM_PREF_STRING) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
624 gaim_account_set_string(data->account, data->setting_name, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
625 buffer); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
626 else if (data->setting_type == GAIM_PREF_INT) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
627 gaim_account_set_int(data->account, data->setting_name, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
628 atoi(buffer)); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
629 else if (data->setting_type == GAIM_PREF_BOOLEAN) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
630 gaim_account_set_bool(data->account, data->setting_name, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
631 (*buffer == '0' ? FALSE : TRUE)); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
632 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
633 g_free(data->setting_name); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
634 data->setting_name = NULL; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
635 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
636 |
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
637 data->tag = TAG_NONE; |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
638 |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
639 g_free(buffer); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
640 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
641 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
642 static void |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
643 __text_handler(GMarkupParseContext *context, const gchar *text, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
644 gsize text_len, gpointer user_data, GError **error) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
645 { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
646 AccountParserData *data = user_data; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
647 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
648 if (data->buffer == NULL) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
649 data->buffer = g_string_new_len(text, text_len); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
650 else |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
651 g_string_append_len(data->buffer, text, text_len); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
652 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
653 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
654 static GMarkupParser accounts_parser = |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
655 { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
656 __start_element_handler, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
657 __end_element_handler, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
658 __text_handler, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
659 NULL, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
660 NULL |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
661 }; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
662 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
663 gboolean |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
664 gaim_accounts_load() |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
665 { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
666 gchar *filename = g_build_filename(gaim_user_dir(), "accounts.xml", NULL); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
667 gchar *contents = NULL; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
668 gsize length; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
669 GMarkupParseContext *context; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
670 GError *error = NULL; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
671 AccountParserData *parser_data; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
672 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
673 if (filename == NULL) { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
674 accounts_loaded = TRUE; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
675 return FALSE; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
676 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
677 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
678 gaim_debug(GAIM_DEBUG_INFO, "accounts", "Reading %s\n", filename); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
679 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
680 if (!g_file_get_contents(filename, &contents, &length, &error)) { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
681 gaim_debug(GAIM_DEBUG_ERROR, "accounts", |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
682 "Error reading accounts: %s\n", error->message); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
683 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
684 g_error_free(error); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
685 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
686 accounts_loaded = TRUE; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
687 return FALSE; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
688 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
689 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
690 parser_data = g_new0(AccountParserData, 1); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
691 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
692 context = g_markup_parse_context_new(&accounts_parser, 0, |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
693 parser_data, __free_parser_data); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
694 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
695 if (!g_markup_parse_context_parse(context, contents, length, NULL)) { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
696 g_markup_parse_context_free(context); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
697 g_free(contents); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
698 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
699 accounts_loaded = TRUE; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
700 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
701 return FALSE; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
702 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
703 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
704 if (!g_markup_parse_context_end_parse(context, NULL)) { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
705 gaim_debug(GAIM_DEBUG_ERROR, "accounts", "Error parsing %s\n", |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
706 filename); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
707 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
708 g_markup_parse_context_free(context); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
709 g_free(contents); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
710 accounts_loaded = TRUE; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
711 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
712 return FALSE; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
713 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
714 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
715 g_markup_parse_context_free(context); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
716 g_free(contents); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
717 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
718 gaim_debug(GAIM_DEBUG_INFO, "accounts", "Finished reading %s\n", |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
719 filename); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
720 g_free(filename); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
721 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
722 accounts_loaded = TRUE; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
723 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
724 return TRUE; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
725 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
726 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
727 static void |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
728 __write_setting(gpointer key, gpointer value, gpointer user_data) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
729 { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
730 GaimAccountSetting *setting; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
731 const char *name; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
732 FILE *fp; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
733 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
734 setting = (GaimAccountSetting *)value; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
735 name = (const char *)key; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
736 fp = (FILE *)user_data; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
737 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
738 if (setting->type == GAIM_PREF_INT) { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
739 fprintf(fp, " <setting name='%s' type='int'>%d</setting>\n", |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
740 name, setting->value.integer); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
741 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
742 else if (setting->type == GAIM_PREF_STRING) { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
743 fprintf(fp, " <setting name='%s' type='string'>%s</setting>\n", |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
744 name, setting->value.string); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
745 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
746 else if (setting->type == GAIM_PREF_BOOLEAN) { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
747 fprintf(fp, " <setting name='%s' type='bool'>%d</setting>\n", |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
748 name, setting->value.bool); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
749 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
750 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
751 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
752 static void |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
753 gaim_accounts_write(FILE *fp, GaimAccount *account) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
754 { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
755 const char *password, *alias, *user_info, *buddy_icon; |
5610 | 756 char *esc; |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
757 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
758 fprintf(fp, " <account>\n"); |
5643
eb685809108b
[gaim-migrate @ 6057]
Christian Hammond <chipx86@chipx86.com>
parents:
5620
diff
changeset
|
759 fprintf(fp, " <protocol>%s</protocol>\n", account->protocol_id); |
5610 | 760 esc = g_markup_escape_text(gaim_account_get_username(account), -1); |
761 fprintf(fp, " <name>%s</name>\n", esc); | |
762 g_free(esc); | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
763 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
764 if (gaim_account_get_remember_password(account) && |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
765 (password = gaim_account_get_password(account)) != NULL) { |
5610 | 766 esc = g_markup_escape_text(password, -1); |
767 fprintf(fp, " <password>%s</password>\n", esc); | |
768 g_free(esc); | |
769 } | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
770 |
5610 | 771 if ((alias = gaim_account_get_alias(account)) != NULL) { |
772 esc = g_markup_escape_text(alias, -1); | |
773 fprintf(fp, " <alias>%s</alias>\n", esc); | |
774 g_free(esc); | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
775 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
776 |
5610 | 777 if ((user_info = gaim_account_get_user_info(account)) != NULL) { |
778 esc = g_markup_escape_text(user_info, -1); | |
779 fprintf(fp, " <userinfo>%s</userinfo>\n", esc); | |
780 g_free(esc); | |
781 } | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
782 |
5610 | 783 if ((buddy_icon = gaim_account_get_buddy_icon(account)) != NULL) { |
784 esc = g_markup_escape_text(buddy_icon, -1); | |
785 fprintf(fp, " <buddyicon>%s</buddyicon>\n", esc); | |
786 g_free(esc); | |
787 } | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
788 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
789 fprintf(fp, " <settings>\n"); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
790 g_hash_table_foreach(account->settings, __write_setting, fp); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
791 fprintf(fp, " </settings>\n"); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
792 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
793 fprintf(fp, " </account>\n"); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
794 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
795 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
796 void |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
797 gaim_accounts_sync(void) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
798 { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
799 FILE *fp; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
800 const char *user_dir = gaim_user_dir(); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
801 char *filename; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
802 char *filename_real; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
803 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
804 if (!accounts_loaded) { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
805 gaim_debug(GAIM_DEBUG_WARNING, "accounts", |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
806 "Writing accounts to disk.\n"); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
807 schedule_accounts_save(); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
808 return; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
809 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
810 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
811 if (user_dir == NULL) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
812 return; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
813 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
814 gaim_debug(GAIM_DEBUG_INFO, "accounts", "Writing accounts to disk.\n"); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
815 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
816 fp = fopen(user_dir, "r"); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
817 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
818 if (fp == NULL) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
819 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
820 else |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
821 fclose(fp); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
822 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
823 filename = g_build_filename(user_dir, "accounts.xml.save", NULL); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
824 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
825 if ((fp = fopen(filename, "w")) != NULL) { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
826 GList *l; |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
827 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
828 fprintf(fp, "<?xml version='1.0' encoding='UTF-8' ?>\n\n"); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
829 fprintf(fp, "<accounts>\n"); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
830 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
831 for (l = gaim_accounts_get_all(); l != NULL; l = l->next) |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
832 gaim_accounts_write(fp, l->data); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
833 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
834 fprintf(fp, "</accounts>\n"); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
835 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
836 fclose(fp); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
837 chmod(filename, S_IRUSR | S_IWUSR); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
838 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
839 else { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
840 gaim_debug(GAIM_DEBUG_ERROR, "accounts", "Unable to write %s\n", |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
841 filename); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
842 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
843 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
844 filename_real = g_build_filename(user_dir, "accounts.xml", NULL); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
845 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
846 if (rename(filename, filename_real) < 0) { |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
847 gaim_debug(GAIM_DEBUG_ERROR, "accounts", "Error renaming %s to %s\n", |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
848 filename, filename_real); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
849 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
850 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
851 g_free(filename); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
852 g_free(filename_real); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
853 } |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
854 |
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
855 void |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
856 gaim_accounts_reorder(GaimAccount *account, size_t new_index) |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
857 { |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
858 size_t index; |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
859 GList *l; |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
860 |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
861 g_return_if_fail(account != NULL); |
5620
c9724982ce45
[gaim-migrate @ 6027]
Christian Hammond <chipx86@chipx86.com>
parents:
5610
diff
changeset
|
862 g_return_if_fail(new_index >= 0 && new_index <= g_list_length(accounts)); |
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
863 |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
864 index = g_list_index(accounts, account); |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
865 |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
866 if (index == -1) { |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
867 gaim_debug(GAIM_DEBUG_ERROR, "accounts", |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
868 "Unregistered account (%s) discovered during reorder!\n", |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
869 gaim_account_get_username(account)); |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
870 return; |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
871 } |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
872 |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
873 l = g_list_nth(accounts, index); |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
874 |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
875 if (new_index > index) |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
876 new_index--; |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
877 |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
878 /* Remove the old one. */ |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
879 accounts = g_list_delete_link(accounts, l); |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
880 |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
881 /* Insert it where it should go. */ |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
882 accounts = g_list_insert(accounts, account, new_index); |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
883 |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
884 schedule_accounts_save(); |
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5574
diff
changeset
|
885 } |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5565
diff
changeset
|
886 |
5563 | 887 GList * |
888 gaim_accounts_get_all(void) | |
889 { | |
890 return accounts; | |
891 } |