* Fixed some compilation warnings
[modest] / src / modest-tny-account-store.c
index 8f9dfda..ca0d113 100644 (file)
@@ -28,6 +28,7 @@
  */
 
 #include <string.h>
+#include <glib/gi18n.h>
 
 #include <tny-account.h>
 #include <tny-account-store.h>
 #include <tny-device.h>
 #include <tny-account-store.h>
 #include <tny-camel-transport-account.h>
-#include <tny-camel-store-account.h>
+#include <tny-camel-imap-store-account.h>
+#include <tny-camel-pop-store-account.h>
 #include <modest-marshal.h>
-#include <glib/gi18n.h>
+#include <modest-protocol-info.h>
 #include "modest-account-mgr.h"
 #include "modest-tny-account-store.h"
 #include "modest-tny-platform-factory.h"
-
+#include <tny-gtk-lockable.h>
 #include <camel/camel.h>
 
 /* 'private'/'protected' functions */
@@ -219,8 +221,6 @@ get_password (TnyAccount *account, const gchar *prompt, gboolean *cancel)
        gchar *pwd = NULL;
        gboolean already_asked;
        
-       gdk_threads_enter ();
-
        key           = tny_account_get_id (account);
        account_store = TNY_ACCOUNT_STORE(get_account_store_for_account (account));
 
@@ -269,8 +269,6 @@ get_password (TnyAccount *account, const gchar *prompt, gboolean *cancel)
        } else
                *cancel = FALSE;
 
-       gdk_threads_leave ();
-
        return pwd;
 }
 
@@ -303,6 +301,39 @@ forget_password (TnyAccount *account) {
                                  TRUE, NULL);
 }
 
+
+
+/* instantiate the correct tny account subclass */
+static TnyAccount*
+tny_account_for_proto (const gchar* proto /* ugly */, ModestProtocolType modest_type) 
+{
+       TnyAccount *tny_account = NULL;
+       
+       /* is it a store or a transport? */
+       if  (modest_type == MODEST_PROTOCOL_TYPE_STORE) {
+               if (strcmp (proto, "pop") == 0) 
+                       tny_account = TNY_ACCOUNT(tny_camel_pop_store_account_new ());
+               else if (strcmp (proto, "imap") == 0)
+                       tny_account = TNY_ACCOUNT(tny_camel_imap_store_account_new ());
+
+       }  else if (modest_type == MODEST_PROTOCOL_TYPE_TRANSPORT) {
+               if (strcmp (proto, "sendmail") == 0) 
+                       tny_account = TNY_ACCOUNT(tny_camel_transport_account_new ());
+               else if (strcmp (proto, "smtp") == 0)
+                       tny_account = TNY_ACCOUNT(tny_camel_transport_account_new ());
+       }
+       
+       if (tny_account) {
+               tny_account_set_proto (tny_account, proto);
+       } else
+               g_printerr ("modest: could not get tny %s account (%d)\n",
+                           proto, modest_type);
+       
+       return tny_account;
+}
+
+
+
 /* create a tnyaccount for the server account connected to the account with name 'key'
  */
 static TnyAccount*
@@ -320,17 +351,19 @@ tny_account_from_name (ModestTnyAccountStore *self, const gchar *account,
        g_return_val_if_fail (server_account, NULL);
 
        priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+       
+       /* proto */
+       val = modest_account_mgr_get_string (priv->account_mgr, server_account,
+                                            MODEST_ACCOUNT_PROTO, TRUE, NULL);
+       if (!val) {
+               g_printerr ("modest: protocol not defined for '%s:%s'\n", 
+                           account, server_account);
+               return NULL;
+       }
 
-       /* is it a store or a transport? */
-       if  (modest_type == MODEST_PROTOCOL_TYPE_STORE) 
-               tny_account = TNY_ACCOUNT(tny_camel_store_account_new ());
-       else if (modest_type == MODEST_PROTOCOL_TYPE_TRANSPORT)
-               tny_account = TNY_ACCOUNT(tny_camel_transport_account_new ());
-       else
-               g_assert_not_reached ();
-
+       tny_account = tny_account_for_proto (val, modest_type);
        if (!tny_account) {
-               g_printerr ("modest: failed to create new tny account for '%s:%s'\n",
+               g_printerr ("modest: could not create account for '%s:%s'\n",
                            account, server_account);
                return NULL;
        }
@@ -357,19 +390,6 @@ tny_account_from_name (ModestTnyAccountStore *self, const gchar *account,
                return NULL;
        }
 
-       /* proto */
-       val = modest_account_mgr_get_string (priv->account_mgr, server_account,
-                                            MODEST_ACCOUNT_PROTO, TRUE, NULL);
-       if (val) {
-               tny_account_set_proto (tny_account, val);
-               g_free (val);
-       } else {
-               g_printerr ("modest: protocol not defined for '%s:%s'\n", 
-                           account, server_account);
-               g_object_unref (G_OBJECT(tny_account));
-               return NULL;
-       }
-
        /* Options */
        options = modest_account_mgr_get_list (priv->account_mgr,
                                               tny_account_get_id (tny_account),
@@ -495,7 +515,6 @@ modest_tny_account_store_new (ModestAccountMgr *account_mgr) {
                g_object_unref (obj);
                return NULL;
        }
-/*     tny_device_force_online (priv->device); */
        
        priv->tny_session_camel = tny_session_camel_new (TNY_ACCOUNT_STORE(obj));
 
@@ -505,6 +524,8 @@ modest_tny_account_store_new (ModestAccountMgr *account_mgr) {
                return NULL;
        }
 
+       tny_session_camel_set_ui_locker (priv->tny_session_camel, tny_gtk_lockable_new ());
+
        return MODEST_TNY_ACCOUNT_STORE(obj);
 }
 
@@ -537,7 +558,7 @@ add_account  (TnyAccountStore *self, TnyAccount *account) {
        return modest_account_mgr_add_server_account (priv->account_mgr,
                                                      account_name,
                                                      hostname, username, NULL,
-                                                     proto);
+                                                     modest_protocol_info_get_protocol(proto));
 }
 
 
@@ -625,7 +646,7 @@ modest_tny_account_store_get_accounts  (TnyAccountStore *iface,
                modest_type = MODEST_PROTOCOL_TYPE_STORE;
                break;
        case TNY_ACCOUNT_STORE_BOTH:
-               modest_type = MODEST_PROTOCOL_TYPE_ANY;
+               modest_type = MODEST_PROTOCOL_TYPE_UNKNOWN;
                break;
        default:
                g_assert_not_reached ();
@@ -649,7 +670,7 @@ modest_tny_account_store_get_accounts  (TnyAccountStore *iface,
                        continue;
                } 
                
-               if (modest_type == MODEST_PROTOCOL_TYPE_TRANSPORT || modest_type == MODEST_PROTOCOL_TYPE_ANY) {
+               if (modest_type == MODEST_PROTOCOL_TYPE_TRANSPORT || modest_type == MODEST_PROTOCOL_TYPE_UNKNOWN) {
                        server_account = get_server_account_for_account (self, account_name,
                                                                         MODEST_PROTOCOL_TYPE_TRANSPORT);
                        if (server_account) {
@@ -668,7 +689,7 @@ modest_tny_account_store_get_accounts  (TnyAccountStore *iface,
                        g_free (server_account);
                }
                
-               if (modest_type == MODEST_PROTOCOL_TYPE_STORE || modest_type == MODEST_PROTOCOL_TYPE_ANY) {
+               if (modest_type == MODEST_PROTOCOL_TYPE_STORE || modest_type == MODEST_PROTOCOL_TYPE_UNKNOWN) {
                        server_account = get_server_account_for_account (self, account_name,
                                                                         MODEST_PROTOCOL_TYPE_STORE);
                        if (server_account) {