2007-05-10 Murray Cumming <murrayc@murrayc.com>
authorMurray Cumming <murrayc@murrayc.com>
Thu, 10 May 2007 16:08:53 +0000 (16:08 +0000)
committerMurray Cumming <murrayc@murrayc.com>
Thu, 10 May 2007 16:08:53 +0000 (16:08 +0000)
* src/modest-account-mgr-helpers.c:
        (modest_account_mgr_get_server_account_data),
        (modest_account_mgr_free_server_account_data):
        * src/modest-account-mgr-helpers.h:
        * src/modest-account-mgr.c:
        (modest_account_mgr_add_server_account):
        * src/modest-defs.h:
        * src/modest-tny-account.c:
        (modest_tny_account_new_from_server_account):
        Determine the options for tny_camel_account_add_option() here,
        based on the settings, rather than storing them directly in gconf.

pmo-trunk-r1828

ChangeLog2
src/modest-account-mgr-helpers.c
src/modest-account-mgr-helpers.h
src/modest-account-mgr.c
src/modest-defs.h
src/modest-tny-account.c

index 24e266f..e5e1a42 100644 (file)
@@ -1,5 +1,19 @@
 2007-05-10  Murray Cumming  <murrayc@murrayc.com>
 
 2007-05-10  Murray Cumming  <murrayc@murrayc.com>
 
+       * src/modest-account-mgr-helpers.c:
+       (modest_account_mgr_get_server_account_data),
+       (modest_account_mgr_free_server_account_data):
+       * src/modest-account-mgr-helpers.h:
+       * src/modest-account-mgr.c:
+       (modest_account_mgr_add_server_account):
+       * src/modest-defs.h:
+       * src/modest-tny-account.c:
+       (modest_tny_account_new_from_server_account):
+       Determine the options for tny_camel_account_add_option() here, 
+       based on the settings, rather than storing them directly in gconf.
+
+2007-05-10  Murray Cumming  <murrayc@murrayc.com>
+
        * src/modest-tny-account-store.c: (modest_tny_account_store_alert):
        Show a more friendly error dialog now that we expect (from the tinymail 
        documentation) to get the UNKNOWN_ALERT error. Add explanatory comments.
        * src/modest-tny-account-store.c: (modest_tny_account_store_alert):
        Show a more friendly error dialog now that we expect (from the tinymail 
        documentation) to get the UNKNOWN_ALERT error. Add explanatory comments.
index 927105e..5f9de4c 100644 (file)
@@ -76,82 +76,6 @@ gchar* modest_account_mgr_get_signature (ModestAccountMgr *self, const gchar* na
        return modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_SIGNATURE, FALSE);
 }
        
        return modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_SIGNATURE, FALSE);
 }
        
-       
-
-#if 0 /* Not needed, but works. */
-static gint
-compare_option_strings_for_name (const gchar* a, const gchar* b)
-{
-       /* printf("  debug: compare_option_strings_for_name():a=%s, b=%s\n", a, b); */
-       const gchar* sep = strchr(a, '=');
-       if (!sep)
-               return -1;
-               
-       gint len = sep - a;
-       if(len <= 0)
-               return -1;
-               
-       /* Get the part of the string before the =.
-        * Note that this allocation is inefficient just so we can do a strcmp. */
-       gchar* name = g_malloc (len+1);
-       memcpy(name, a, len);
-       name[len] = 0; /* Null-termination. */
-       
-       /* printf("    debug: name=%s\n", name); */
-
-       gint result = strcmp (name, b);
-       
-       g_free (name);
-       
-       return result;
-}
-           
-gchar*
-modest_server_account_data_get_option_string (GSList* options_list, const gchar* option_name)
-{
-       if (!options_list)
-               return NULL;
-       
-       gchar *result = NULL;
-       GSList* option = g_slist_find_custom(options_list, option_name, (GCompareFunc)compare_option_strings_for_name);
-       if(option) {
-               /* Get the value part of the key=value pair: */
-               const gchar* pair = (const gchar*)option->data;
-               
-               const gchar* sep = strchr(pair, '=');
-               if (sep) {
-                       gint len = sep - pair;
-                       if(len > 0) {
-                               result = g_strdup(sep+1);
-                               
-                               /* Avoid returning an empty string instead of NULL. */
-                               if(result && strlen(result) == 0) {
-                                       g_free(result);
-                                       result = NULL;
-                               }
-                       }
-               }
-       }
-               
-       return result;
-}
-
-gboolean
-modest_server_account_data_get_option_bool (GSList* options_list, const gchar* option_name)
-{
-       if (!options_list)
-               return FALSE;
-       
-       gboolean result = FALSE;
-       GSList* option = g_slist_find_custom(options_list, option_name, (GCompareFunc)strcmp);
-       if(option) {
-               return TRUE;
-       }
-               
-       return result;
-}
-#endif
-
 
 gboolean modest_account_mgr_set_connection_specific_smtp (ModestAccountMgr *self, 
        const gchar* account_name,
 
 gboolean modest_account_mgr_set_connection_specific_smtp (ModestAccountMgr *self, 
        const gchar* account_name,
@@ -407,25 +331,6 @@ modest_server_account_set_security (ModestAccountMgr *self,
        /* Set it in the configuration: */
        modest_account_mgr_set_string (self, account_name, MODEST_ACCOUNT_SECURITY, str_value, TRUE);
 }
        /* Set it in the configuration: */
        modest_account_mgr_set_string (self, account_name, MODEST_ACCOUNT_SECURITY, str_value, TRUE);
 }
-                    
-#if 0                     
-gchar*
-modest_account_mgr_get_server_account_option (ModestAccountMgr *self, 
-       const gchar* account_name, const gchar* option_name)
-{
-       GSList *option_list = modest_account_mgr_get_list (self, account_name, MODEST_ACCOUNT_OPTIONS,
-                                                    MODEST_CONF_VALUE_STRING, TRUE);
-       if (!option_list)
-               return NULL;
-               
-       gchar *result = modest_server_account_data_get_option_value (option_list, option_name);
-       
-       /* TODO: Should we free the items too, or just the list? */
-       g_slist_free (option_list);
-               
-       return result;
-}
-#endif
 
 ModestServerAccountData*
 modest_account_mgr_get_server_account_data (ModestAccountMgr *self, const gchar* name)
 
 ModestServerAccountData*
 modest_account_mgr_get_server_account_data (ModestAccountMgr *self, const gchar* name)
@@ -456,10 +361,7 @@ modest_account_mgr_get_server_account_data (ModestAccountMgr *self, const gchar*
        data->last_updated = modest_account_mgr_get_int    (self, name, MODEST_ACCOUNT_LAST_UPDATED,TRUE);
        
        data->password     = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_PASSWORD, TRUE);
        data->last_updated = modest_account_mgr_get_int    (self, name, MODEST_ACCOUNT_LAST_UPDATED,TRUE);
        
        data->password     = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_PASSWORD, TRUE);
-       data->uri          = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_URI,TRUE);
-       data->options = modest_account_mgr_get_list (self, name, MODEST_ACCOUNT_OPTIONS,
-                                                    MODEST_CONF_VALUE_STRING, TRUE);
-                                                  
+       data->uri          = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_URI,TRUE);                          
        
        return data;
 }
        
        return data;
 }
@@ -485,15 +387,6 @@ modest_account_mgr_free_server_account_data (ModestAccountMgr *self,
 
        g_free (data->password);
        data->password = NULL;
 
        g_free (data->password);
        data->password = NULL;
-       
-       if (data->options) {
-               GSList *tmp = data->options;
-               while (tmp) {
-                       g_free (tmp->data);
-                       tmp = g_slist_next (tmp);
-               }
-               g_slist_free (data->options);
-       }
 
        g_slice_free (ModestServerAccountData, data);
 }
 
        g_slice_free (ModestServerAccountData, data);
 }
index 0b6873c..45ad0e0 100644 (file)
@@ -51,7 +51,6 @@ typedef struct {
        gint             port; /* Or 0, if the default should be used. */
        ModestProtocol   secure_auth;
        ModestProtocol   security;
        gint             port; /* Or 0, if the default should be used. */
        ModestProtocol   secure_auth;
        ModestProtocol   security;
-       GSList           *options;
 } ModestServerAccountData;
 
 typedef struct {
 } ModestServerAccountData;
 
 typedef struct {
@@ -371,37 +370,6 @@ modest_account_mgr_get_server_account_data (ModestAccountMgr *self, const gchar*
 void
 modest_account_mgr_free_server_account_data (ModestAccountMgr *self,
                                             ModestServerAccountData* data);
 void
 modest_account_mgr_free_server_account_data (ModestAccountMgr *self,
                                             ModestServerAccountData* data);
-       
-#if 0
-/**
- * modest_account_mgr_get_account_option:
- * @self: a ModestAccountMgr instance
- * @account_name: the account name to check
- * @account_name: the option name to check
- *
- * Returns: The account option value. This must be freed with g_free().
- */
-gchar* modest_account_mgr_get_server_account_option (ModestAccountMgr *self, 
-       const gchar* account_name, const gchar* option_name);
-
-/**
- * modest_server_account_data_get_option_value:
- * @options_list: a ModestServerAccountData::options list.
- * @option_name: the option name to check
- *
- * Returns: The account option value. This must be freed with g_free().
- */
-gchar* modest_server_account_data_get_option_string (GSList* options_list, const gchar* option_name);
-
-/**
- * modest_server_account_data_get_option_bool:
- * @options_list: a ModestServerAccountData::options list.
- * @option_name: the option name to check
- *
- * Returns: Whether the account option is present.
- */
-gboolean modest_server_account_data_get_option_bool (GSList* options_list, const gchar* option_name);
-#endif
 
 /**
  * modest_account_mgr_get_from_string
 
 /**
  * modest_account_mgr_get_from_string
index 99d40ef..b051201 100644 (file)
@@ -398,47 +398,6 @@ modest_account_mgr_add_server_account (ModestAccountMgr * self,
                goto cleanup;
 
        if (proto_type == MODEST_PROTOCOL_TYPE_STORE) {
                goto cleanup;
 
        if (proto_type == MODEST_PROTOCOL_TYPE_STORE) {
-
-               GSList *option_list = NULL;
-
-               /* Connection options. Some options are only valid for IMAP
-                  accounts but it's OK for just now since POP is still not
-                  supported */
-               key = _modest_account_mgr_get_account_keyname (name, MODEST_ACCOUNT_OPTIONS, TRUE);
-               /* Enable subscriptions and check the mails in all folders */
-               option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_USE_LSUB);
-               option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_CHECK_ALL);
-
-               /* TODO: Remove this hack. These are hard-coded camel options to make the connection work.
-                * The regular connection options (set later here) should be interpreted instead 
-                * because in future these camel options will not be in gconf. murrayc.
-                */
-               /* Security options */
-               switch (security) {
-               case MODEST_PROTOCOL_SECURITY_NONE:
-                       option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_NEVER);
-                       break;
-               case MODEST_PROTOCOL_SECURITY_SSL:
-               case MODEST_PROTOCOL_SECURITY_TLS:
-                       option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_ALWAYS);
-                       break;
-               case MODEST_PROTOCOL_SECURITY_TLS_OP:
-                       option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE);
-                       break;
-               default:
-                       g_warning ("Invalid security option");
-               }
-               ok = modest_conf_set_list (priv->modest_conf, key, 
-                                          option_list, MODEST_CONF_VALUE_STRING, &err);
-               if (err) {
-                       g_printerr ("modest: failed to set %s: %s\n", key, err->message);
-                       g_error_free (err);
-                       ok = FALSE;
-               }
-               g_slist_free (option_list);
-               g_free (key);
-               
-               
                /* Add the security settings: */
                modest_server_account_set_security (self, name, security);
        }
                /* Add the security settings: */
                modest_server_account_set_security (self, name, security);
        }
index 12c1041..5f55181 100644 (file)
 #define MODEST_ACCOUNT_LEAVE_ON_SERVER   "leave_on_server"   /* boolean */
 #define MODEST_ACCOUNT_PREFERRED_CNX     "preferred_cnx"     /* string */
 #define MODEST_ACCOUNT_PORT                     "port"              /* int */
 #define MODEST_ACCOUNT_LEAVE_ON_SERVER   "leave_on_server"   /* boolean */
 #define MODEST_ACCOUNT_PREFERRED_CNX     "preferred_cnx"     /* string */
 #define MODEST_ACCOUNT_PORT                     "port"              /* int */
-#define MODEST_ACCOUNT_OPTIONS          "options"           /* list */
 
 #define MODEST_ACCOUNT_AUTH_MECH        "auth_mech"         /* string */
 #define MODEST_ACCOUNT_AUTH_MECH_VALUE_NONE "none"
 
 #define MODEST_ACCOUNT_AUTH_MECH        "auth_mech"         /* string */
 #define MODEST_ACCOUNT_AUTH_MECH_VALUE_NONE "none"
 #define MODEST_ACCOUNT_SECURITY_VALUE_NORMAL "normal"
 #define MODEST_ACCOUNT_SECURITY_VALUE_SSL "ssl"
 
 #define MODEST_ACCOUNT_SECURITY_VALUE_NORMAL "normal"
 #define MODEST_ACCOUNT_SECURITY_VALUE_SSL "ssl"
 
-
-/* Options keys that correspond directly to camel options.
- * These probably should not be written to user configuration, 
- * because they are specific API implementation details. */
-/* Keys and values used in the text items in the options GSList: */
-#define MODEST_ACCOUNT_OPTION_SSL "use_ssl"
-#define MODEST_ACCOUNT_OPTION_SSL_NEVER "never"
-#define MODEST_ACCOUNT_OPTION_SSL_ALWAYS "always"
-#define MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE "when-possible"
-
-#define MODEST_ACCOUNT_OPTION_USE_LSUB "use_lsub"
-#define MODEST_ACCOUNT_OPTION_CHECK_ALL "check_all"
-
 /* Macros for different text formats in mail editor */
 #define MODEST_FILE_FORMAT_PLAIN_TEXT 0
 #define MODEST_FILE_FORMAT_FORMATTED_TEXT 1
 /* Macros for different text formats in mail editor */
 #define MODEST_FILE_FORMAT_PLAIN_TEXT 0
 #define MODEST_FILE_FORMAT_FORMATTED_TEXT 1
index eee8fa1..be7cc11 100644 (file)
@@ -87,6 +87,13 @@ modest_tny_account_get_special_folder (TnyAccount *account,
        return special_folder;
 }
 
        return special_folder;
 }
 
+/* Camel options: */
+#define MODEST_ACCOUNT_OPTION_SSL "use_ssl"
+#define MODEST_ACCOUNT_OPTION_SSL_NEVER "never"
+#define MODEST_ACCOUNT_OPTION_SSL_ALWAYS "always"
+#define MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE "when-possible"
+#define MODEST_ACCOUNT_OPTION_USE_LSUB "use_lsub"
+#define MODEST_ACCOUNT_OPTION_CHECK_ALL "check_all"
 
 /**
  * modest_tny_account_new_from_server_account:
 
 /**
  * modest_tny_account_new_from_server_account:
@@ -142,14 +149,37 @@ modest_tny_account_new_from_server_account (ModestAccountMgr *account_mgr,
        if (account_data->uri) 
                tny_account_set_url_string (TNY_ACCOUNT(tny_account), account_data->uri);
        else {
        if (account_data->uri) 
                tny_account_set_url_string (TNY_ACCOUNT(tny_account), account_data->uri);
        else {
-               if (account_data->options) {
-                       GSList *options = account_data->options;
-                       while (options) {
-                               tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (tny_account),
-                                                             options->data);
-                               options = g_slist_next (options);
-                       }
+               const gchar* option_security = NULL;
+               switch (account_data->security) {
+               case MODEST_PROTOCOL_SECURITY_NONE:
+                       option_security = MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_NEVER;
+                       break;
+               case MODEST_PROTOCOL_SECURITY_SSL:
+               case MODEST_PROTOCOL_SECURITY_TLS:
+                       option_security = MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_ALWAYS;;
+                       break;
+               case MODEST_PROTOCOL_SECURITY_TLS_OP:
+                       option_security = MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE;
+                       break;
+               default:
+                       break;
                }
                }
+               
+               if(option_security) {
+                       tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (tny_account),
+                                                     option_security);
+               }
+               
+               if (account_data->proto == MODEST_PROTOCOL_TYPE_STORE) {
+                       /* Connection options. Some options are only valid for IMAP
+                          accounts but it's OK for just now since POP is still not
+                          supported */
+                       tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (tny_account),
+                                                                     MODEST_ACCOUNT_OPTION_USE_LSUB);
+                       tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (tny_account),
+                                                                     MODEST_ACCOUNT_OPTION_CHECK_ALL);
+               }
+               
                if (account_data->username) 
                        tny_account_set_user (tny_account, account_data->username);
                if (account_data->hostname)
                if (account_data->username) 
                        tny_account_set_user (tny_account, account_data->username);
                if (account_data->hostname)