* Deleted unused code
authorSergio Villar Senin <svillar@igalia.com>
Fri, 29 Feb 2008 17:08:59 +0000 (17:08 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Fri, 29 Feb 2008 17:08:59 +0000 (17:08 +0000)
* Added some documentation
* Added optimizations when refreshing accounts, do not recurse folders if we don't want to poke status
* Issue send&receive only after a succesful connect
* Added a poke_status parametter to do_send_receive
* Do not update the "Last updated" when refreshing folders, only when send&receive
* Fixes  NB#80728, username no longer gets dimmed when an invalid username is given

pmo-trunk-r4259

src/dbus_api/modest-dbus-callbacks.c
src/maemo/modest-main-window.c
src/modest-account-mgr-helpers.c
src/modest-mail-operation.c
src/modest-tny-account-store.c
src/modest-tny-account.h
src/modest-ui-actions.c
src/modest-ui-actions.h

index 7530237..fa4b30a 100644 (file)
@@ -794,7 +794,7 @@ on_idle_send_receive(gpointer user_data)
 
        if (auto_update)
                /* Do send receive */
-               modest_ui_actions_do_send_receive_all (main_win, FALSE);
+               modest_ui_actions_do_send_receive_all (main_win, FALSE, FALSE);
        else
                /* Disable auto update */
                modest_platform_set_update_interval (0);
index 1fa7410..70c4cad 100644 (file)
@@ -1581,27 +1581,6 @@ modest_main_window_show_toolbar (ModestWindow *self,
                                                            show_toolbar);
 }
 
-/* 
- * Counts the number of remote accounts in a list
- */
-static guint
-num_remote_accounts (TnyList *accounts)
-{
-       TnyIterator *iter;
-       guint num = 0;
-
-       iter = tny_list_create_iterator (accounts);
-       while (!tny_iterator_is_done (iter)) {
-               TnyAccount *account = (TnyAccount *) tny_iterator_get_current (iter);
-               if (modest_tny_folder_store_is_remote (TNY_FOLDER_STORE (account)))
-                       num++;
-               tny_iterator_next (iter);
-       }
-       g_object_unref (iter);
-       return num;
-}
-
-
 static void
 on_account_inserted (TnyAccountStore *accoust_store,
                      TnyAccount *account,
@@ -1611,24 +1590,8 @@ on_account_inserted (TnyAccountStore *accoust_store,
           folders account do now cause menu changes */
        if (TNY_IS_STORE_ACCOUNT (account) && 
            modest_tny_folder_store_is_remote (TNY_FOLDER_STORE (account))) {
-               TnyList *list = tny_simple_list_new ();
-
                /* Update menus */
                update_menus (MODEST_MAIN_WINDOW (user_data));
-
-               /* Perform a send&receive if there are more than 1
-                  remote account , if this is the first remote
-                  account the folder view will automatically select
-                  and update it */
-               tny_account_store_get_accounts (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()), 
-                                               list, TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
-               if (num_remote_accounts (list) > 1) {
-                       const gchar *account_name = 
-                               modest_tny_account_get_parent_modest_account_name_for_server_account (account);
-                       modest_ui_actions_do_send_receive (account_name, FALSE, MODEST_WINDOW (user_data));
-               }
-
-               g_object_unref (list);
        }
 }
 
@@ -2584,9 +2547,9 @@ refresh_account (const gchar *account_name)
        
        /* If account_name == NULL, we must update all (option All) */
        if (!account_name)
-               modest_ui_actions_do_send_receive_all (win, TRUE);
+               modest_ui_actions_do_send_receive_all (win, TRUE, TRUE);
        else
-               modest_ui_actions_do_send_receive (account_name, TRUE, win);
+               modest_ui_actions_do_send_receive (account_name, TRUE, TRUE, win);
        
 }
 
index 33f88fe..dd203f4 100644 (file)
@@ -284,8 +284,7 @@ modest_account_mgr_set_server_account_username (ModestAccountMgr *self, const gc
                
        /* We don't know anything about new usernames: */
        if (strcmp (existing_username, username) != 0)
-               modest_account_mgr_set_server_account_username_has_succeeded (self, account_name,
-                                                                             TRUE);
+               modest_account_mgr_set_server_account_username_has_succeeded (self, account_name, FALSE);
                
        g_free (existing_username);
 }
@@ -306,15 +305,6 @@ modest_account_mgr_set_server_account_username_has_succeeded (ModestAccountMgr *
                                     succeeded, TRUE /* server account */);
 }
 
-void
-modest_account_mgr_set_server_account_password (ModestAccountMgr *self, const gchar* account_name, 
-                                   const gchar* password)
-{
-       modest_account_mgr_set_string (self, account_name, MODEST_ACCOUNT_PASSWORD, 
-                                      password, TRUE /* server account */);
-}
-
-       
 gchar*
 modest_account_mgr_get_server_account_password (ModestAccountMgr *self, const gchar* account_name)
 {
index b441d2a..44fdc7a 100644 (file)
@@ -1222,7 +1222,7 @@ inbox_refreshed_cb (TnyFolder *inbox,
        ModestAccountMgr *mgr;
        ModestAccountRetrieveType retrieve_type;
        TnyList *new_headers = NULL;
-       gboolean headers_only, ignore_limit;
+       gboolean headers_only, ignore_limit, succeeded;
        TnyTransportAccount *transport_account = NULL;
 
        info = (UpdateAccountInfo *) user_data;
@@ -1335,6 +1335,13 @@ inbox_refreshed_cb (TnyFolder *inbox,
        g_ptr_array_foreach (new_headers_array, (GFunc) g_object_unref, NULL);
        g_ptr_array_free (new_headers_array, FALSE);
 
+       if (priv->error)
+               succeeded = FALSE;
+       else
+               succeeded = TRUE;
+       modest_account_mgr_set_server_account_username_has_succeeded (modest_runtime_get_account_mgr (), 
+                                                                     tny_account_get_name (priv->account), 
+                                                                     succeeded);
  send_mail:
        /* Get the transport account */
        transport_account = (TnyTransportAccount *)
@@ -1406,7 +1413,8 @@ recurse_folders_async_cb (TnyFolderStore *folder_store,
 
        if (err || canceled) {
                /* Try to continue anyway */
-       } else {
+       } else if (info->poke_all) {
+               /* We're not getting INBOX children if we don't want to poke all */
                TnyIterator *iter = tny_list_create_iterator (list);
                while (!tny_iterator_is_done (iter)) {
                        TnyFolderStore *folder = (TnyFolderStore*) tny_iterator_get_current (iter);
@@ -2828,19 +2836,6 @@ on_refresh_folder (TnyFolder   *folder,
 
        g_return_if_fail(priv!=NULL);
 
-       /* If the folder is remote, set the "Last updated" value */
-       if (modest_tny_folder_is_remote_folder (folder)) {
-               TnyAccount *account = modest_tny_folder_get_account (folder);
-               ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
-               const gchar *name;
-               name = modest_tny_account_get_parent_modest_account_name_for_server_account (account);
-               modest_account_mgr_set_last_updated (mgr, tny_account_get_id (account), time (NULL));
-               if (!cancelled && !error)
-                       modest_account_mgr_set_server_account_username_has_succeeded (mgr, tny_account_get_id (account), TRUE);
-               modest_account_mgr_set_account_busy (mgr, name, FALSE);
-               g_object_unref (account);
-       }
-
        if (error) {
                priv->error = g_error_copy (error);
                priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
@@ -2930,15 +2925,6 @@ modest_mail_operation_refresh_folder  (ModestMailOperation *self,
        helper->user_callback = user_callback;
        helper->user_data = user_data;
 
-       /* Refresh the folder. TODO: tinymail could issue a status
-          updates before the callback call then this could happen. We
-          must review the design */
-       if (modest_tny_folder_is_remote_folder (folder)) {
-               /* If the folder is remote, mark its account as busy */
-               const gchar *name;
-               name = modest_tny_account_get_parent_modest_account_name_for_server_account (priv->account);
-               modest_account_mgr_set_account_busy (modest_runtime_get_account_mgr (), name, TRUE);
-       }
        modest_mail_operation_notify_start (self);
        
        /* notify that the operation was started */
index f3108d5..ab4091b 100644 (file)
@@ -58,6 +58,7 @@
 #include <tny-gtk-lockable.h>
 #include <camel/camel.h>
 #include <modest-platform.h>
+#include "modest-ui-actions.h"
 
 #ifdef MODEST_PLATFORM_MAEMO
 #include <tny-maemo-conic-device.h>
@@ -107,6 +108,10 @@ static void    modest_tny_account_store_forget_password_in_memory (ModestTnyAcco
 
 static void    add_connection_specific_transport_accounts         (ModestTnyAccountStore *self);
 
+static void    connection_status_changed   (TnyAccount *account, 
+                                           TnyConnectionStatus status, 
+                                           gpointer data);
+
 /* list my signals */
 enum {
        ACCOUNT_CHANGED_SIGNAL,
@@ -1483,6 +1488,35 @@ add_existing_accounts (ModestTnyAccountStore *self)
        modest_account_mgr_free_account_names (account_names);
 }
 
+static void 
+connection_status_changed (TnyAccount *account, 
+                          TnyConnectionStatus status, 
+                          gpointer data)
+{
+       if (status == TNY_CONNECTION_STATUS_CONNECTED) {
+               const gchar *account_name;
+               ModestWindow *main_window;
+               ModestTnyAccountStorePrivate *priv = NULL;
+               
+               priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (data);
+
+               /* Remove this handler */
+               priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers, 
+                                                                 G_OBJECT (account),
+                                                                 "connection_status_changed");
+
+               /* Set the username as succedded */
+               modest_account_mgr_set_server_account_username_has_succeeded (modest_runtime_get_account_mgr (), 
+                                                                             tny_account_get_id (account), 
+                                                                             TRUE);
+
+               /* Perform a send receive */
+               account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (account);
+               main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (), FALSE);
+               modest_ui_actions_do_send_receive (account_name, FALSE, FALSE, main_window);
+       }
+}
+
 static TnyAccount*
 create_tny_account (ModestTnyAccountStore *self,
                    const gchar *name,
@@ -1504,6 +1538,15 @@ create_tny_account (ModestTnyAccountStore *self,
                   we use a new account if any */
                modest_tny_account_store_forget_password_in_memory (self, 
                                                                    tny_account_get_id (account));
+
+               /* Install a signal handler that will refresh the
+                  account the first time it becomes online */
+               priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers, 
+                                                              G_OBJECT (account), 
+                                                              "connection_status_changed",
+                                                              G_CALLBACK (connection_status_changed),
+                                                              self);
+
                /* Set the account store */                             
                g_object_set_data (G_OBJECT(account), "account_store", self);
        } else {
@@ -1645,6 +1688,15 @@ on_account_disconnect_when_removing (TnyCamelAccount *account,
        self = MODEST_TNY_ACCOUNT_STORE (user_data);
        priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (self);
 
+       /* Remove the connection-status-changed handler if it's still there */
+       if (modest_signal_mgr_is_connected (priv->sighandlers, 
+                                           G_OBJECT (account),
+                                           "connection_status_changed")) {
+               priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers, 
+                                                                 G_OBJECT (account),
+                                                                 "connection_status_changed");
+       }
+
        /* Remove it from the list of accounts */
        if (TNY_IS_STORE_ACCOUNT (account))
                tny_list_remove (priv->store_accounts, (GObject *) account);
index 1cb0533..1816541 100644 (file)
@@ -124,22 +124,6 @@ modest_tny_account_new_from_server_account_name (ModestAccountMgr *account_mgr,
                                                 TnyGetPassFunc get_pass_func,
                                                 TnyForgetPassFunc forget_pass_func);
 
-#if 0
-/**
- * modest_tny_account_new_from_server_account_name:
- * @tny_account: a valid tny account
- * @account_mgr: a valid account mgr instance
- * @server_account_name: the name of a server account in the configuration system.
- *
- * update the given tny account; note that you cannot change the protocol type
- * 
- * Returns: a new TnyAccount or NULL in case of error.
- */
-gboolean modest_tny_account_update_from_server_account_name (TnyAccount *tny_account,
-                                                            ModestAccountMgr *account_mgr,
-                                                            const gchar *server_account_name);
-#endif
-
 /**
  * modest_tny_account_get_special_folder:
  * @self: a TnyAccount
index 885370e..e8ddc50 100644 (file)
@@ -1732,6 +1732,7 @@ typedef struct {
        TnyAccount *account;
        ModestWindow *win;
        gchar *account_name;
+       gboolean poke_status;
 } SendReceiveInfo;
 
 static void
@@ -1766,7 +1767,7 @@ do_send_receive_performer (gboolean canceled,
 
        /* Send & receive. */
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
-       modest_mail_operation_update_account (mail_op, info->account_name, (info->win) ? FALSE : TRUE,
+       modest_mail_operation_update_account (mail_op, info->account_name, info->poke_status,
                                              (info->win) ? retrieve_all_messages_cb : NULL, 
                                              new_messages_arrived, info->win);
        g_object_unref (G_OBJECT (mail_op));
@@ -1791,6 +1792,7 @@ do_send_receive_performer (gboolean canceled,
 void
 modest_ui_actions_do_send_receive (const gchar *account_name, 
                                   gboolean force_connection,
+                                  gboolean poke_status,
                                   ModestWindow *win)
 {
        gchar *acc_name = NULL;
@@ -1818,6 +1820,7 @@ modest_ui_actions_do_send_receive (const gchar *account_name,
        info = g_slice_new (SendReceiveInfo);
        info->account_name = acc_name;
        info->win = (win) ? g_object_ref (win) : NULL;
+       info->poke_status = poke_status;
        info->account = modest_tny_account_store_get_server_account (acc_store, acc_name,
                                                                     TNY_ACCOUNT_TYPE_STORE);
 
@@ -1906,7 +1909,8 @@ modest_ui_actions_cancel_send (GtkAction *action,  ModestWindow *win)
  */
 void
 modest_ui_actions_do_send_receive_all (ModestWindow *win, 
-                                      gboolean force_connection)
+                                      gboolean force_connection,
+                                      gboolean poke_status)
 {
        GSList *account_names, *iter;
 
@@ -1915,7 +1919,9 @@ modest_ui_actions_do_send_receive_all (ModestWindow *win,
 
        iter = account_names;
        while (iter) {                  
-               modest_ui_actions_do_send_receive ((const char*) iter->data, force_connection, win);
+               modest_ui_actions_do_send_receive ((const char*) iter->data, 
+                                                  force_connection, 
+                                                  poke_status, win);
                iter = g_slist_next (iter);
        }
 
@@ -1956,8 +1962,9 @@ modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
                        g_object_unref (folder_store);
        }       
        
-       /* Refresh the active account. Force the connection if needed */
-       modest_ui_actions_do_send_receive (NULL, TRUE, win);
+       /* Refresh the active account. Force the connection if needed
+          and poke the status of all folders */
+       modest_ui_actions_do_send_receive (NULL, TRUE, TRUE, win);
 }
 
 
index 5f731b2..efea199 100644 (file)
@@ -198,15 +198,20 @@ void     modest_ui_actions_cancel_send (GtkAction *action,  ModestWindow *win);
 /**
  * modest_ui_actions_do_send_receive_all:
  * @win: the window that will be used as source of the refresh mail operation
+ * @force_connection: whether or not the code should try to force a new connection if we're offline
+ * @poke_status: wheter ot not we want to poke the status of all mail folders
  * 
  * Refreshes all the accounts
  **/
 void    modest_ui_actions_do_send_receive_all          (ModestWindow *win,
-                                                       gboolean force_connection);
+                                                       gboolean force_connection,
+                                                       gboolean poke_status);
 
 /**
  * modest_ui_actions_do_send_receive:
  * @account_name: the name of the Modest account or NULL
+ * @force_connection: whether or not the code should try to force a new connection if we're offline
+ * @poke_status: wheter ot not we want to poke the status of all mail folders
  * @win: the window that will be used as source of the refresh mail operation
  * 
  * Refreshes the Modest account whose name is passed as argument. If
@@ -216,6 +221,7 @@ void    modest_ui_actions_do_send_receive_all          (ModestWindow *win,
  **/
 void    modest_ui_actions_do_send_receive              (const gchar *account_name,
                                                        gboolean force_connection,
+                                                       gboolean poke_status,
                                                        ModestWindow *win);
 
 /**