Changeset 84

Show
Ignore:
Timestamp:
04/22/08 13:38:28
Author:
pvanhoof
Message:
        • Added editing account options
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r82 r84  
    33        * Updated tny_camel_account_add_option to reflect recent API changes 
    44        on Tinymail's trunk 
     5        * Added editing account options 
    56 
    672008-04-17  Philip Van Hoof  <pvanhoof@gnome.org> 
  • trunk/src/tmut-account-editor.c

    r76 r84  
    2828#include "tmut-shell-child.h" 
    2929 
     30#include <tny-camel-account.h> 
     31#include <tny-simple-list.h> 
     32#include <tny-list.h> 
     33#include <tny-iterator.h> 
     34 
     35 
    3036static GObjectClass *parent_class = NULL; 
    3137 
     
    116122 
    117123        if (account) { 
     124                TnyList *options = tny_simple_list_new (); 
     125                gboolean first = TRUE; 
     126                TnyIterator *iter; 
     127                GString *options_string = g_string_new (""); 
     128 
    118129                gtk_entry_set_text (GTK_ENTRY (priv->name_entry),  
    119130                        tny_account_get_name (account)?tny_account_get_name (account):""); 
     
    125136                gtk_entry_set_text (GTK_ENTRY (priv->user_entry),  
    126137                        tny_account_get_user (account)?tny_account_get_user (account):""); 
     138 
     139                tny_camel_account_get_options (TNY_CAMEL_ACCOUNT (account), options); 
     140                iter = tny_list_create_iterator (options); 
     141 
     142                while (!tny_iterator_is_done (iter)) { 
     143                        TnyPair *pair = TNY_PAIR (tny_iterator_get_current (iter)); 
     144                        const gchar *value = tny_pair_get_value (pair); 
     145 
     146                        g_string_append (options_string,  
     147                                tny_pair_get_name (pair)); 
     148 
     149                        if (value) { 
     150                                g_string_append_c (options_string, '='); 
     151                                g_string_append (options_string, value); 
     152                        } 
     153 
     154                        if (!first) 
     155                                g_string_append (options_string, ", "); 
     156 
     157                        first = FALSE; 
     158 
     159                        tny_iterator_next (iter); 
     160                } 
     161 
     162                g_object_unref (iter); 
     163                g_object_unref (options); 
     164 
     165                gtk_entry_set_text (GTK_ENTRY (priv->options_entry),  
     166                        options_string->str); 
     167 
     168                g_string_free (options_string, TRUE); 
     169 
    127170        } else { 
    128171                gtk_entry_set_text (GTK_ENTRY (priv->name_entry), _("Account name")); 
  • trunk/src/tmut-account-store.c

    r83 r84  
    282282{ 
    283283        TMutAccountStorePriv *priv = TMUT_ACCOUNT_STORE_GET_PRIVATE (self); 
    284         GList *found = g_list_find (priv->accounts, account); 
    285  
    286         if (found) { 
    287                 TnyAccount *account = found->data; 
    288                 const gchar *filen = tny_account_get_id (account); 
    289                 FILE *file; 
    290                 GKeyFile *keyfile = g_key_file_new (); 
    291  
    292                 g_key_file_load_from_file (keyfile, filen, G_KEY_FILE_NONE, NULL); 
    293  
    294                 if (name) { 
    295                         tny_account_set_name (account, name); 
    296                         g_key_file_set_value (keyfile, "tmut", "name", name); 
     284        const gchar *filen = tny_account_get_id (account); 
     285        FILE *file; 
     286        GKeyFile *keyfile = g_key_file_new (); 
     287 
     288        g_key_file_load_from_file (keyfile, filen, G_KEY_FILE_NONE, NULL); 
     289 
     290        if (name) { 
     291                tny_account_set_name (account, name); 
     292                g_key_file_set_value (keyfile, "tmut", "name", name); 
     293        } 
     294 
     295        if (hostname) { 
     296                tny_account_set_hostname (account, hostname); 
     297                g_key_file_set_value (keyfile, "tmut", "hostname", hostname); 
     298        } 
     299 
     300        if (proto) { 
     301                tny_account_set_proto (account, proto); 
     302                g_key_file_set_value (keyfile, "tmut", "proto", proto); 
     303        } 
     304 
     305        if (user) { 
     306                tny_account_set_user (account, user); 
     307                g_key_file_set_value (keyfile, "tmut", "user", user); 
     308        } 
     309 
     310        if (port != -1) { 
     311                tny_account_set_port (account, port); 
     312                g_key_file_set_integer (keyfile, "tmut", "port", port); 
     313        } 
     314 
     315        if (mech) { 
     316                tny_account_set_secure_auth_mech (account, mech); 
     317                g_key_file_set_value (keyfile, "tmut", "mech", mech); 
     318        } 
     319 
     320        tny_camel_account_clear_options (TNY_CAMEL_ACCOUNT (account)); 
     321 
     322        if (options) { 
     323                gint i = 0; 
     324                while (options[i] != NULL) { 
     325                        gchar *str = g_strdup (options [i]); 
     326                        gchar *key = str; 
     327                        gchar *value = strchr (str, '='); 
     328 
     329                        if (value) { 
     330                                *value = '\0'; 
     331                                value++; 
     332                        } else 
     333                                value = ""; 
     334 
     335                        tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (account),  
     336                                tny_pair_new (key, value)); 
     337                        i++; 
     338                        g_free (str); 
    297339                } 
    298340 
    299                 if (hostname) { 
    300                         tny_account_set_hostname (account, hostname); 
    301                         g_key_file_set_value (keyfile, "tmut", "hostname", hostname); 
    302                 } 
    303  
    304                 if (proto) { 
    305                         tny_account_set_proto (account, proto); 
    306                         g_key_file_set_value (keyfile, "tmut", "proto", proto); 
    307                 } 
    308  
    309                 if (user) { 
    310                         tny_account_set_user (account, user); 
    311                         g_key_file_set_value (keyfile, "tmut", "user", user); 
    312                 } 
    313  
    314                 if (port != -1) { 
    315                         tny_account_set_port (account, port); 
    316                         g_key_file_set_integer (keyfile, "tmut", "port", port); 
    317                 } 
    318  
    319                 if (mech) { 
    320                         tny_account_set_secure_auth_mech (account, mech); 
    321                         g_key_file_set_value (keyfile, "tmut", "mech", mech); 
    322                 } 
    323  
    324                 if (options) { 
    325                         /* todo: sync account instance's options with new ones */ 
    326                         gint options_len = 0; 
    327                         while (options[options_len] != NULL) 
    328                                 options_len++; 
    329                         g_key_file_set_string_list (keyfile, "tmut", "options",  
    330                                 options, options_len); 
    331                 } 
    332  
    333                 file = fopen (filen, "w"); 
    334  
    335                 if (file) { 
    336                         gsize len; 
    337                         char *str = g_key_file_to_data (keyfile, &len, NULL); 
    338                         fputs (str, file); 
    339                         fclose (file); 
    340                 } 
    341  
    342                 if (account) { 
    343                         g_signal_emit (self,  
    344                                 tmut_account_store_signals [TMUT_ACCOUNT_STORE_ACCOUNT_EDITED],  
    345                                 0, account); 
    346                 } 
    347  
    348                 g_key_file_free (keyfile); 
    349                 g_list_free (found); 
    350         } 
     341                g_key_file_set_string_list (keyfile, "tmut", "options",  
     342                        options, i); 
     343        } else { 
     344                g_key_file_remove_key (keyfile, "tmut", "options", NULL); 
     345        } 
     346 
     347        file = fopen (filen, "w"); 
     348 
     349        if (file) { 
     350                gsize len; 
     351                char *str = g_key_file_to_data (keyfile, &len, NULL); 
     352                fputs (str, file); 
     353                fclose (file); 
     354        } 
     355 
     356        g_signal_emit (self,  
     357                tmut_account_store_signals [TMUT_ACCOUNT_STORE_ACCOUNT_EDITED],  
     358                0, account); 
     359 
     360        g_key_file_free (keyfile); 
    351361} 
    352362