Changeset 581
- Timestamp:
- 07/26/06 15:32:35
- Files:
-
- trunk/libtinymail-olpc/tny-account-store.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libtinymail-olpc/tny-account-store.c
r579 r581 180 180 { 181 181 TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 182 gint i=0, count;183 182 const gchar *filen; 184 183 gchar *configd; 185 gchar *key = NULL;186 184 GDir *dir ; 187 185 188 186 configd = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir(), 189 ".tinymail", "accounts" );187 ".tinymail", "accounts", NULL); 190 188 dir = g_dir_open (configd, 0, NULL); 191 189 g_free (configd); … … 196 194 for (filen = g_dir_read_name (dir); filen; filen = g_dir_read_name (dir)) 197 195 { 198 FILE *file = fopen (filen, "r"); 199 200 if (file) 201 { 202 gchar *tok, proto[200], type[200], key[200], name[200], options[1000]; 196 GKeyFile *keyfile; 197 gchar *proto, *type, *key, *name; 203 198 TnyAccountIface *account = NULL; 204 205 fscanf (file, "type=%s", &type); 199 200 keyfile = g_key_file_new (); 201 202 if (!g_key_file_load_from_file (keyfile, filen, G_KEY_FILE_NONE, NULL)) 203 continue; 204 205 type = g_key_file_get_value (keyfile, "tinymail", "type", NULL); 206 206 207 207 if (type && G_LIKELY (!g_ascii_strncasecmp (type, "transport", 9))) … … 223 223 } 224 224 225 if (type) 226 g_free (type); 225 227 226 228 if (account) 227 229 { 230 gsize options_len; gint i; 231 gchar **options; 232 228 233 tny_account_iface_set_account_store (account, self); 229 234 230 fscanf (file, "proto=%s", &proto);235 proto = g_key_file_get_value (keyfile, "tinymail", "proto", NULL); 231 236 tny_account_iface_set_proto (TNY_ACCOUNT_IFACE (account), proto); 232 233 fscanf (file, "name=%s", &name); 237 g_free (proto); 238 239 name = g_key_file_get_value (keyfile, "tinymail", "name", NULL); 234 240 tny_account_iface_set_name (TNY_ACCOUNT_IFACE (account), name); 235 236 237 fscanf (file, "options=%s", &options); 238 tok = strtok (options, ","); 239 240 while (tok) 241 g_free (name); 242 243 options = g_key_file_get_string_list (keyfile, "tinymail", "options", &options_len, NULL); 244 if (options) 241 245 { 242 tny_account_add_option (TNY_ACCOUNT (account), tok); 243 tok = strtok (NULL, ","); 246 for (i=0; i<options_len; i++) 247 tny_account_add_option (TNY_ACCOUNT (account), options[i]); 248 g_strfreev (options); 244 249 } 245 250 … … 252 257 253 258 /* TODO: Add other supported and tested providers here */ 254 fscanf (file, "user=%s", &user);259 user = g_key_file_get_value (keyfile, "tinymail", "user", NULL); 255 260 tny_account_iface_set_user (TNY_ACCOUNT_IFACE (account), user); 256 261 257 258 fscanf (file, "hostname=%s", &hostname); 259 tny_account_iface_set_hostname (TNY_ACCOUNT_IFACE (account), 260 hostname); 262 hostname = g_key_file_get_value (keyfile, "tinymail", "hostname", NULL); 263 tny_account_iface_set_hostname (TNY_ACCOUNT_IFACE (account), hostname); 261 264 265 g_free (hostname); g_free (user); 262 266 } else { 263 267 gchar *url_string; … … 265 269 /* Un officially supported provider */ 266 270 /* Assuming there's a url_string in this case */ 267 268 fscanf (file, "url_string=%s", &url_string); 271 url_string = g_key_file_get_value (keyfile, "tinymail", "url_string", NULL); 269 272 tny_account_iface_set_url_string (TNY_ACCOUNT_IFACE (account), url_string); 273 g_free (url_string); 270 274 } 271 275 … … 279 283 tny_account_iface_set_forget_pass_func (TNY_ACCOUNT_IFACE (account), 280 284 per_account_forget_pass_func); 281 285 282 286 tny_account_iface_set_pass_func (TNY_ACCOUNT_IFACE (account), 283 287 per_account_get_pass_func); 284 288 289 285 290 tny_list_iface_prepend (list, account); 286 291 } 287 288 fclose (file);289 }290 291 292 } 292 293 g_dir_close (dir); … … 303 304 tny_account_store_add_account (TnyAccountStoreIface *self, TnyAccountIface *account, const gchar *type) 304 305 { 305 TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 306 gchar *filen = g_build_filename (g_get_home_dir(), ".tinymail", 307 tny_account_iface_get_name (account)); 308 309 FILE *file = fopen (filen, "w"); 310 311 if (file) 312 { 313 314 fprintf (file, "type=%s", type); 315 fprintf (file, "proto=%s", tny_account_iface_get_proto (account)); 316 fprintf (file, "name=%s", tny_account_iface_get_name (account)); 317 fprintf (file, "options="); 318 fprintf (file, "user=%s", tny_account_iface_get_user (account)); 319 fprintf (file, "hostname=%s", tny_account_iface_get_hostname (account)); 320 321 322 fclose (file); 323 } 306 g_warning ("Not implemented\n"); 324 307 325 308 return;
