* src/modest-ui-actions.c:
[modest] / src / modest-tny-account-store.c
index 2b82794..46516ac 100644 (file)
@@ -60,7 +60,7 @@
 
 #ifdef MODEST_PLATFORM_MAEMO
 #include <tny-maemo-conic-device.h>
-#ifdef MODEST_HILDON_VERSION_0
+#ifdef MODEST_HAVE_HILDON0_WIDGETS
 #include <hildon-widgets/hildon-note.h>
 #include <hildon-widgets/hildon-banner.h>
 #else
@@ -381,9 +381,11 @@ get_account_store_for_account (TnyAccount *account)
 
 /* This callback will be called by Tinymail when it needs the password
  * from the user, for instance if the password was not remembered.
+ * It also calls forget_password() before calling this,
+ * so that we clear wrong passwords out of our account settings.
  * Note that TnyAccount here will be the server account. */
 static gchar*
-get_password (TnyAccount *account, const gchar *prompt, gboolean *cancel)
+get_password (TnyAccount *account, const gchar * prompt_not_used, gboolean *cancel)
 {
        /* Initialize the output parameter: */
        if (cancel)
@@ -431,18 +433,25 @@ get_password (TnyAccount *account, const gchar *prompt, gboolean *cancel)
                gboolean remember = FALSE;
                pwd = NULL;
                
-               /* Note that we ignore the returned username here,
-                * because it is enough that it will be stored in gconf 
-                * by the signal handler. */
                g_signal_emit (G_OBJECT(self), signals[PASSWORD_REQUESTED_SIGNAL], 0,
                               account_id, /* server_account_name */
                               &username, &pwd, cancel, &remember);
                
                if (!*cancel) {
-                       if (remember)
+                       /* The password will be returned as the result,
+                        * but we need to tell tinymail about the username too: */
+                       tny_account_set_user (account, username);
+                       
+                       if (remember) {
+                               printf ("%s: Storing username=%s, password=%s\n", 
+                                       __FUNCTION__, username, pwd);
+                               modest_account_mgr_set_string (priv->account_mgr,key,
+                                                              MODEST_ACCOUNT_USERNAME,
+                                                              username, TRUE);
                                modest_account_mgr_set_string (priv->account_mgr,key,
                                                               MODEST_ACCOUNT_PASSWORD,
                                                               pwd, TRUE);
+                       }
                        /* We need to dup the string even knowing that
                           it's already a dup of the contents of an
                           entry, because it if it's wrong, then camel
@@ -624,8 +633,9 @@ create_per_account_local_outbox_folders (TnyAccountStore *self)
                                
                accounts = g_slist_append (accounts, tny_account_outbox); /* cache it */
        };
-       
-       g_slist_free (account_names);
+
+       modest_account_mgr_free_account_names (account_names);
+       account_names = NULL;
        
        priv->store_accounts_outboxes = accounts;
 }
@@ -638,8 +648,6 @@ static void
 get_server_accounts  (TnyAccountStore *self, TnyList *list, TnyAccountType type)
 {
        g_return_if_fail (self);
-       
-       /* printf ("DEBUG: %s: list=%p, type=%d\n", __FUNCTION__, list, type); */
                
        ModestTnyAccountStorePrivate *priv = 
                MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
@@ -766,13 +774,11 @@ get_server_accounts  (TnyAccountStore *self, TnyList *list, TnyAccountType type)
                        iter_account_names = g_slist_next (iter_account_names);
                }               
        }
-       
-       g_slist_free (account_names);
+
+       /* free the account_names */
+       modest_account_mgr_free_account_names (account_names);
        account_names = NULL;
-       
-       /* TODO: Delete the strings in the GSList */
-       
-       
+
        /* We also create a per-account local outbox folder (a _store_ account) 
         * for each _transport_ account. */
        if (type == TNY_ACCOUNT_TYPE_TRANSPORT) {
@@ -1099,7 +1105,7 @@ modest_tny_account_store_get_tny_account_by (ModestTnyAccountStore *self,
        TnyAccount *account = NULL;
        ModestTnyAccountStorePrivate *priv;     
        GSList *cursor;
-       const gchar *val;
+       const gchar *val = NULL;
 
        g_return_val_if_fail (self, NULL);
        g_return_val_if_fail (str, NULL);
@@ -1119,8 +1125,9 @@ modest_tny_account_store_get_tny_account_by (ModestTnyAccountStore *self,
                        val = tny_account_get_url_string (TNY_ACCOUNT(cursor->data));
                        break;
                }
+               
                if (type == MODEST_TNY_ACCOUNT_STORE_QUERY_URL && 
-                   tny_account_matches_url_string (TNY_ACCOUNT(cursor->data), val)) {
+                   tny_account_matches_url_string (TNY_ACCOUNT(cursor->data), str)) {
                        account = TNY_ACCOUNT (cursor->data);
                        goto end;
                } else {
@@ -1144,6 +1151,7 @@ modest_tny_account_store_get_tny_account_by (ModestTnyAccountStore *self,
                        val = tny_account_get_url_string (TNY_ACCOUNT(cursor->data));
                        break;
                }
+               
                if (type == MODEST_TNY_ACCOUNT_STORE_QUERY_URL && 
                    tny_account_matches_url_string (TNY_ACCOUNT(cursor->data), val)) {
                        account = TNY_ACCOUNT (cursor->data);