* another g_return_... stomped
[modest] / src / modest-tny-account-store.c
index 2da76db..549a7c6 100644 (file)
@@ -9,6 +9,7 @@
 #include <tny-store-account-iface.h>
 #include <tny-transport-account-iface.h>
 #include <tny-device-iface.h>
+#include <tny-device.h>
 #include <tny-account-store.h>
 
 #include <tny-store-account.h>
@@ -46,6 +47,7 @@ struct _ModestTnyAccountStorePrivate {
        gchar *cache_dir;
 
        TnySessionCamel *tny_session_camel;
+       TnyDeviceIface  *device;
 
        ModestAccountMgr *modest_acc_mgr;
 };
@@ -83,7 +85,7 @@ modest_tny_account_store_get_type (void)
                my_type = g_type_register_static (TNY_TYPE_ACCOUNT_STORE,
                                                  "ModestTnyAccountStore", &my_info, 0);
 
-                g_type_add_interface_static (my_type, TNY_TYPE_ACCOUNT_STORE_IFACE,
+               g_type_add_interface_static (my_type, TNY_TYPE_ACCOUNT_STORE_IFACE,
                                             &iface_info);
        }
        return my_type;
@@ -118,6 +120,7 @@ modest_tny_account_store_init (ModestTnyAccountStore *obj)
                MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(obj);
 
        priv->modest_acc_mgr         = NULL;
+       priv->device                 = NULL;
 
        priv->store_accounts         = NULL;
        priv->transport_accounts     = NULL;
@@ -163,6 +166,11 @@ modest_tny_account_store_finalize (GObject *obj)
                priv->tny_session_camel = NULL;
        }
 
+       if (priv->device) {
+               g_object_unref (G_OBJECT(priv->device));
+               priv->device = NULL;
+       }
+
        priv->store_accounts     = free_gobject_list (priv->store_accounts);
        priv->transport_accounts = free_gobject_list (priv->store_accounts);
 
@@ -186,10 +194,16 @@ modest_tny_account_store_new (ModestAccountMgr *modest_acc_mgr)
        priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(obj);
        g_object_ref(G_OBJECT(priv->modest_acc_mgr = modest_acc_mgr));
 
+       priv->device = (TnyDeviceIface*)tny_device_new();
+       if (!priv->device) {
+               g_warning ("Cannot create Device instance");
+               g_object_unref (obj);
+               return NULL;
+       }
        priv->tny_session_camel = tny_session_camel_new
                (TNY_ACCOUNT_STORE_IFACE(obj));
        if (!priv->tny_session_camel) {
-               g_warning ("cannot create TnySessionCamel instance");
+               g_warning ("Cannot create TnySessionCamel instance");
                g_object_unref (obj);
                return NULL;
        }
@@ -199,7 +213,7 @@ modest_tny_account_store_new (ModestAccountMgr *modest_acc_mgr)
 
 
 static gchar*
-get_password (TnyAccountIface *account, const gchar *prompt)
+get_password (TnyAccountIface *account, const gchar *prompt, gboolean *cancel)
 {
        const gchar *key;
        const TnyAccountStoreIface *account_store;
@@ -207,8 +221,6 @@ get_password (TnyAccountIface *account, const gchar *prompt)
        ModestTnyAccountStorePrivate *priv;
        gchar *val;
 
-        g_message (__FUNCTION__);
-
        g_return_val_if_fail (account, NULL);
 
        key = tny_account_iface_get_id (account);
@@ -218,20 +230,16 @@ get_password (TnyAccountIface *account, const gchar *prompt)
        priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
 
        val = modest_account_mgr_get_server_account_string (priv->modest_acc_mgr, key,
-                                                           MODEST_ACCOUNT_PASSWORD,
-                                                           NULL);
-       if (!val || strlen(val)==0)
-        {
-                /* FIXME:
-                 * append the prompt to the emitted signal,
-                 * so the password dialog shows the prompt supplied by the caller of this function.
-                 */
-                g_signal_emit (G_OBJECT(self), signals[PASSWORD_REQUESTED_SIGNAL], 0,
-                               key);
-
+                                                                                               MODEST_ACCOUNT_PASSWORD, NULL);
+       if (!val) {
+               /* FIXME:
+                * append the prompt to the emitted signal,
+                * so the password dialog shows the prompt supplied by the caller of this function.
+                */
+               g_signal_emit (G_OBJECT(self), signals[PASSWORD_REQUESTED_SIGNAL], 0, key);
        }
 
-        return val;
+       return val;
 }
 
 
@@ -277,7 +285,6 @@ add_account  (TnyAccountStoreIface *self, TnyAccountIface *account)
 }
 
 
-
 static void
 modest_tny_account_store_add_store_account  (TnyAccountStoreIface *self,
                                             TnyStoreAccountIface *account)
@@ -287,7 +294,6 @@ modest_tny_account_store_add_store_account  (TnyAccountStoreIface *self,
 }
 
 
-
 static void
 modest_tny_account_store_add_transport_account  (TnyAccountStoreIface *self,
                                                 TnyTransportAccountIface *account)
@@ -297,7 +303,6 @@ modest_tny_account_store_add_transport_account  (TnyAccountStoreIface *self,
 }
 
 
-
 static TnyAccountIface*
 tny_account_from_key (ModestTnyAccountStore *self, const gchar *key,
                      gboolean is_store)
@@ -327,7 +332,8 @@ tny_account_from_key (ModestTnyAccountStore *self, const gchar *key,
                                             TNY_ACCOUNT_STORE_IFACE(self));
        /* id */
        tny_account_iface_set_id (tny_account, key);
-
+       tny_account_iface_set_name (tny_account, key);
+       
        /* proto */
        val = modest_account_mgr_get_server_account_string (priv->modest_acc_mgr, key,
                                                            MODEST_ACCOUNT_PROTO, NULL);
@@ -340,7 +346,6 @@ tny_account_from_key (ModestTnyAccountStore *self, const gchar *key,
                return NULL;
        }
 
-
        /* hostname */
        val = modest_account_mgr_get_server_account_string (priv->modest_acc_mgr, key,
                                                            MODEST_ACCOUNT_HOSTNAME,
@@ -378,7 +383,6 @@ tny_accounts_from_server_accounts (ModestTnyAccountStore *self, GSList *accounts
 
        while (cursor) {
                TnyAccountIface *tny_account;
-               gchar *key = cursor->data;
                tny_account = tny_account_from_key (self, (gchar*)cursor->data,
                                                    is_store);
                if (!tny_account) {
@@ -395,13 +399,12 @@ tny_accounts_from_server_accounts (ModestTnyAccountStore *self, GSList *accounts
 }
 
 
-
 static const GList*
 modest_tny_account_store_get_store_accounts  (TnyAccountStoreIface *iface)
 {
        ModestTnyAccountStore        *self;
        ModestTnyAccountStorePrivate *priv;
-       GSList                       *accounts, *cursor;
+       GSList                       *accounts;
        GList                        *tny_accounts;
 
        g_return_val_if_fail (iface, NULL);
@@ -415,12 +418,9 @@ modest_tny_account_store_get_store_accounts  (TnyAccountStoreIface *iface)
                                                         MODEST_PROTO_TYPE_STORE,
                                                         NULL, FALSE);
 
-       g_message ("accounts: %d", g_slist_length (accounts));
        tny_accounts = tny_accounts_from_server_accounts (self, accounts, TRUE);
        g_slist_free (accounts);
-       g_message ("store accounts: %d", g_list_length (tny_accounts));
-
-
+       
        /*
         * FIXME: after gconf notification support is added,
         * we can simply return priv->store_account
@@ -432,13 +432,12 @@ modest_tny_account_store_get_store_accounts  (TnyAccountStoreIface *iface)
 }
 
 
-
 static const GList*
 modest_tny_account_store_get_transport_accounts (TnyAccountStoreIface *iface)
 {
        ModestTnyAccountStore        *self;
        ModestTnyAccountStorePrivate *priv;
-       GSList                       *accounts, *cursor;
+       GSList                       *accounts;
        GList                        *tny_accounts;
 
        g_return_val_if_fail (iface, NULL);
@@ -479,7 +478,6 @@ ModestAccountMgr
 }
 
 
-
 TnySessionCamel*
 tny_account_store_get_session (TnyAccountStore *self)
 {
@@ -488,14 +486,10 @@ tny_account_store_get_session (TnyAccountStore *self)
 
        priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
 
-       g_message ("returning tny session camel %p",
-                  priv->tny_session_camel);
-
        return priv->tny_session_camel;
 }
 
 
-
 /**
  * modest_tny_account_store_get_cache_dir:
  * @self: self a TnyAccountStoreIface instance
@@ -512,8 +506,6 @@ modest_tny_account_store_get_cache_dir (TnyAccountStoreIface *self)
        ModestTnyAccountStorePrivate *priv;
        priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
 
-       gchar *cache_dir;
-
        if (!priv->cache_dir) {
                if (g_getenv("HOME") != NULL)
                        priv->cache_dir = g_strconcat(g_getenv("HOME"),
@@ -523,13 +515,15 @@ modest_tny_account_store_get_cache_dir (TnyAccountStoreIface *self)
 }
 
 
-
 static const TnyDeviceIface*
 modest_tny_account_store_get_device (TnyAccountStoreIface *self)
 {
-       return NULL; /* FIXME */
-}
+       ModestTnyAccountStorePrivate *priv;
 
+       priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (self);
+
+       return priv->device;
+}
 
 
 static void
@@ -541,17 +535,16 @@ modest_tny_account_store_iface_init (gpointer g_iface, gpointer iface_data)
 
        klass = (TnyAccountStoreIfaceClass *)g_iface;
 
-        klass->add_store_account_func      =
+       klass->add_store_account_func      =
                modest_tny_account_store_add_store_account;
-        klass->get_store_accounts_func     =
+       klass->get_store_accounts_func     =
                modest_tny_account_store_get_store_accounts;
-        klass->add_transport_account_func  =
+       klass->add_transport_account_func  =
                modest_tny_account_store_add_transport_account;
-        klass->get_transport_accounts_func =
+       klass->get_transport_accounts_func =
                modest_tny_account_store_get_transport_accounts;
        klass->get_cache_dir_func =
                modest_tny_account_store_get_cache_dir;
        klass->get_device_func =
                modest_tny_account_store_get_device;
-
 }