Changeset 581

Show
Ignore:
Timestamp:
07/26/06 15:32:35
Author:
pvanhoof
Message:

Replaced the implementation with the GKeyFile stuff

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libtinymail-olpc/tny-account-store.c

    r579 r581  
    180180{ 
    181181        TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
    182         gint i=0, count; 
    183182        const gchar *filen; 
    184183        gchar *configd; 
    185         gchar *key = NULL; 
    186184        GDir *dir ; 
    187185 
    188186        configd = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir(),  
    189                 ".tinymail", "accounts"); 
     187                ".tinymail", "accounts", NULL); 
    190188        dir = g_dir_open (configd, 0, NULL); 
    191189        g_free (configd); 
     
    196194        for (filen = g_dir_read_name (dir); filen; filen = g_dir_read_name (dir)) 
    197195        { 
    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; 
    203198                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); 
    206206 
    207207                if (type && G_LIKELY (!g_ascii_strncasecmp (type, "transport", 9))) 
     
    223223                } 
    224224 
     225                if (type) 
     226                        g_free (type); 
    225227 
    226228                if (account) 
    227229                { 
     230                        gsize options_len; gint i; 
     231                        gchar **options; 
     232 
    228233                        tny_account_iface_set_account_store (account, self); 
    229234 
    230                         fscanf (file, "proto=%s", &proto); 
     235                        proto = g_key_file_get_value (keyfile, "tinymail", "proto", NULL); 
    231236                        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); 
    234240                        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) 
    241245                        { 
    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); 
    244249                        } 
    245250 
     
    252257 
    253258                                /* 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); 
    255260                                tny_account_iface_set_user (TNY_ACCOUNT_IFACE (account), user); 
    256261 
    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); 
    261264                                 
     265                                g_free (hostname); g_free (user); 
    262266                        } else { 
    263267                                gchar *url_string; 
     
    265269                                /* Un officially supported provider */ 
    266270                                /* 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); 
    269272                                tny_account_iface_set_url_string (TNY_ACCOUNT_IFACE (account), url_string); 
     273                                g_free (url_string); 
    270274                        } 
    271275 
     
    279283                        tny_account_iface_set_forget_pass_func (TNY_ACCOUNT_IFACE (account), 
    280284                                per_account_forget_pass_func); 
    281  
     285         
    282286                        tny_account_iface_set_pass_func (TNY_ACCOUNT_IFACE (account), 
    283287                                per_account_get_pass_func); 
    284288 
     289 
    285290                        tny_list_iface_prepend (list, account); 
    286291                } 
    287  
    288                 fclose (file); 
    289           } 
    290          
    291292        }        
    292293        g_dir_close (dir); 
     
    303304tny_account_store_add_account (TnyAccountStoreIface *self, TnyAccountIface *account, const gchar *type) 
    304305{ 
    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"); 
    324307 
    325308        return;