* small cleanups in icon-factory
[modest] / src / modest-tny-account-store.c
index 1bcbf7e..f7e73cc 100644 (file)
 #include <tny-store-account.h>
 #include <tny-transport-account.h>
 #include <tny-device.h>
-#include <tny-gnome-device.h>
 #include <tny-account-store.h>
 #include <tny-camel-transport-account.h>
 #include <tny-camel-store-account.h>
 #include <modest-marshal.h>
+#include <glib/gi18n.h>
 #include "modest-account-mgr.h"
 #include "modest-tny-account-store.h"
 #include "modest-tny-platform-factory.h"
@@ -227,24 +227,17 @@ get_password (TnyAccount *account, const gchar *prompt, gboolean *cancel)
         priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
 
        /* is it in the hash? if it's already there, it must be wrong... */
-//     already_asked = g_hash_table_lookup (priv->password_hash, key) != NULL;
-/*     if (already_asked) */
-/*             g_warning ("password already asked for or in config (%s)", */
-/*                        key); */
-/*     else */
-/*             g_warning ("password not yet asked for or in config (%s)", */
-/*                        key); */
+       already_asked = g_hash_table_lookup (priv->password_hash, key) != NULL;
 
        /* if the password is not already there, try ModestConf */
-//     if (!already_asked) 
+/*     if (!already_asked)  */
                pwd  = modest_account_mgr_get_string (priv->account_mgr,
                                                      key, MODEST_ACCOUNT_PASSWORD,
                                                      TRUE, NULL);
 
-       /* if it was already asked, it must have been wrong, so ask again */
-/*     if (!already_asked ||  !pwd || strlen(pwd) == 0) { */
-/*             g_warning ("emit signal to get pass for %s", key); */
-               
+/*     /\* if it was already asked, it must have been wrong, so ask again *\/ */
+/*     if (!already_asked || !pwd || strlen(pwd) == 0) { */
+
 /*             /\* we don't have it yet. we emit a signal to get the password somewhere *\/ */
 /*             const gchar* name = tny_account_get_name (account); */
 /*             *cancel = TRUE; */
@@ -258,7 +251,7 @@ get_password (TnyAccount *account, const gchar *prompt, gboolean *cancel)
 /*     } else */
 /*             *cancel = FALSE; */
 
-//     g_hash_table_insert (priv->password_hash, (gpointer)key, (gpointer)pwd);
+/*     g_hash_table_insert (priv->password_hash, key, pwd); */
        
        return pwd; 
 }
@@ -287,7 +280,9 @@ tny_account_from_name (ModestTnyAccountStore *self, const gchar *account,
        TnyAccount *tny_account;
        ModestTnyAccountStorePrivate *priv;
        gchar *val;
-
+       GSList *options = NULL;
+       GError *error = NULL;
+       
        g_return_val_if_fail (self, NULL);
        g_return_val_if_fail (account, NULL);
        g_return_val_if_fail (server_account, NULL);
@@ -331,6 +326,28 @@ tny_account_from_name (ModestTnyAccountStore *self, const gchar *account,
                return NULL;
        }
 
+       /* Options */
+       options = modest_account_mgr_get_list (priv->account_mgr,
+                                              tny_account_get_id (tny_account),
+                                              MODEST_ACCOUNT_OPTIONS,
+                                              MODEST_CONF_VALUE_STRING,
+                                              TRUE,
+                                              &error);
+       
+       if (error) {
+               g_warning ("Error retrieving account %s options: %s",
+                          tny_account_get_id (tny_account), error->message);
+               g_error_free (error);
+       } else {
+               GSList *tmp = options;
+               while (options) {
+                       tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (tny_account), options->data);
+                       g_free (options->data);
+                       options = g_slist_next (options);
+               }
+               g_slist_free (tmp);
+       }
+
        /* hostname */
        val = modest_account_mgr_get_string (priv->account_mgr, server_account,
                                             MODEST_ACCOUNT_HOSTNAME, TRUE,
@@ -421,7 +438,6 @@ modest_tny_account_store_new (ModestAccountMgr *account_mgr) {
        
        priv->store_lock = g_mutex_new ();
 
-       /* FIXME: don't use GNOME */
        pfact = TNY_PLATFORM_FACTORY (modest_tny_platform_factory_get_instance());
        if (!pfact) {
                g_printerr ("modest: cannot create platform factory\n");
@@ -574,12 +590,14 @@ modest_tny_account_store_get_accounts  (TnyAccountStore *iface,
        cursor = accounts = modest_account_mgr_account_names (priv->account_mgr, NULL); 
 
        while (cursor) {
-               gchar           *account_name;
-               gchar           *server_account;
-               TnyAccount *account;
-
-               account_name  =  (gchar*)cursor->data;
-               account =  NULL;
+               gchar       *account_name;
+               gchar       *server_account;
+               TnyAccount  *account;
+               gboolean     is_server_account;
+
+               account_name      = (gchar*)cursor->data;
+               account           = NULL;
+               is_server_account = FALSE;
                
                if (!modest_account_mgr_account_get_enabled (priv->account_mgr, account_name)) { 
                        g_free (account_name); 
@@ -590,10 +608,13 @@ modest_tny_account_store_get_accounts  (TnyAccountStore *iface,
                if (modest_type == MODEST_PROTOCOL_TYPE_TRANSPORT || modest_type == MODEST_PROTOCOL_TYPE_ANY) {
                        server_account = get_server_account_for_account (self, account_name,
                                                                         MODEST_PROTOCOL_TYPE_TRANSPORT);
-                       if (server_account)
+                       if (server_account) {
                                account = tny_account_from_name (self, account_name, 
                                                                       server_account,
                                                                       MODEST_PROTOCOL_TYPE_TRANSPORT);
+                               is_server_account = TRUE;
+                       }
+
                        if (!account)
                                g_printerr ("modest: no transport account for '%s'\n",
                                            account_name);
@@ -606,10 +627,13 @@ modest_tny_account_store_get_accounts  (TnyAccountStore *iface,
                if (modest_type == MODEST_PROTOCOL_TYPE_STORE || modest_type == MODEST_PROTOCOL_TYPE_ANY) {
                        server_account = get_server_account_for_account (self, account_name,
                                                                         MODEST_PROTOCOL_TYPE_STORE);
-                       if (server_account)
+                       if (server_account) {
                                account = tny_account_from_name (self, account_name, 
                                                                       server_account,
                                                                       MODEST_PROTOCOL_TYPE_STORE);
+                               is_server_account = TRUE;
+                       }
+
                        if (!account)
                                g_printerr ("modest: no store account for '%s'\n",
                                            account_name);
@@ -625,8 +649,6 @@ modest_tny_account_store_get_accounts  (TnyAccountStore *iface,
        g_slist_free (accounts);
 
        tny_session_camel_set_account_store (priv->tny_session_camel, iface);
-/*     tny_session_camel_set_current_accounts (priv->tny_session_camel, */
-/*                                             list); */
 }