* added licensing boilerplate to source files
[modest] / src / modest-tny-account-store.c
index e9fba72..f8e967f 100644 (file)
@@ -1,6 +1,34 @@
-/* modest-tny-account-store.c */
+/* Copyright (c) 2006, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
 
-/* insert (c)/licensing information) */
+/* modest-tny-account-store.c */
 
 #include <string.h>
 
@@ -42,7 +70,7 @@ enum {
 /* Password Status */
 enum {
         PW_NOT_INVALID,
-        PW_INVALID,
+        PW_INVALID
 };
 
 static const gchar *transport_protocols[] = { "smtp", NULL };
@@ -61,6 +89,7 @@ struct _ModestTnyAccountStorePrivate {
 
         ModestAccountMgr *modest_acc_mgr;
         gint pw_invalid;
+        ModestTnyGetPassFunc get_pass_func;
 };
 #define MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                       MODEST_TYPE_TNY_ACCOUNT_STORE, \
@@ -142,6 +171,7 @@ modest_tny_account_store_init (ModestTnyAccountStore *obj)
         priv->tny_session_camel      = NULL;
         /* Meaning: if not indicated otherwise, we have valid password data */
         priv->pw_invalid             = PW_NOT_INVALID;
+        priv->get_pass_func          = NULL;
 }
 
 
@@ -180,7 +210,7 @@ get_password (TnyAccountIface *account,
        account_store = tny_account_iface_get_account_store(account);
 
        self = MODEST_TNY_ACCOUNT_STORE (account_store);
-       priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+        priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
 
         if (priv->pw_invalid==PW_NOT_INVALID) {
                 retval = modest_account_mgr_get_server_account_string (priv->modest_acc_mgr,
@@ -188,9 +218,16 @@ get_password (TnyAccountIface *account,
                                                                        MODEST_ACCOUNT_PASSWORD,
                                                                        NULL);
         } else {
-                g_signal_emit(G_OBJECT(self), signals[PASSWORD_REQUESTED_SIGNAL], 0, key);
-                priv->pw_invalid=PW_NOT_INVALID;
-                retval=NULL;
+                retval = priv->get_pass_func(account, prompt, cancel);
+                if (!*cancel)
+                {
+                        priv->pw_invalid=PW_NOT_INVALID;
+                        modest_account_mgr_set_server_account_string(priv->modest_acc_mgr,
+                                                                     key,
+                                                                     MODEST_ACCOUNT_PASSWORD,
+                                                                     retval,
+                                                                     NULL);
+                }
         }
         return retval;
 }
@@ -274,7 +311,7 @@ tny_account_from_key (ModestTnyAccountStore *self, const gchar *key,
        }
 
        tny_account_iface_set_pass_func (tny_account, get_password);
-       tny_account_iface_set_forget_pass_func (tny_account, forget_password);
+        tny_account_iface_set_forget_pass_func (tny_account, forget_password);
 
        return tny_account;
 }
@@ -703,3 +740,12 @@ modest_tny_account_store_iface_init (gpointer g_iface, gpointer iface_data)
        klass->get_device_func =
                modest_tny_account_store_get_device;
 }
+
+void
+modest_tny_account_store_set_get_pass_func (ModestTnyAccountStore *self, ModestTnyGetPassFunc func) {
+
+        ModestTnyAccountStorePrivate *priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+
+        priv->get_pass_func=func;
+}
+