AccountWizard: Don't crash when sync is running #4221
authorChristian Kamm <mail@ckamm.de>
Tue, 8 Dec 2015 13:37:37 +0000 (14:37 +0100)
committerChristian Kamm <mail@ckamm.de>
Wed, 9 Dec 2015 08:08:21 +0000 (09:08 +0100)
Running FolderMan::setupFolders() is redundant and just a leftover
from before multiaccount.

src/gui/accountsettings.cpp
src/gui/application.cpp
src/gui/folderman.cpp
src/gui/folderman.h

index 128494002bea91ca685294f51f8abcf321adc207..ee1d73cf681a3a12f7d9892e2859312331f7eb2b 100644 (file)
@@ -118,7 +118,7 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) :
 
     connect(ui->selectiveSyncApply, SIGNAL(clicked()), _model, SLOT(slotApplySelectiveSync()));
     connect(ui->selectiveSyncCancel, SIGNAL(clicked()), _model, SLOT(resetFolders()));
-    connect(FolderMan::instance(), SIGNAL(folderListLoaded(Folder::Map)), _model, SLOT(resetFolders()));
+    connect(FolderMan::instance(), SIGNAL(folderListChanged(Folder::Map)), _model, SLOT(resetFolders()));
     connect(this, SIGNAL(folderChanged()), _model, SLOT(resetFolders()));
 
 
index 2d4622bf357e09147843584cad3e6f84c78c3420..1182ecdd48eeafe256d283894debc7ef9a248955 100644 (file)
@@ -286,23 +286,39 @@ void Application::slotCrash()
 
 void Application::slotownCloudWizardDone( int res )
 {
+    AccountManager *accountMan = AccountManager::instance();
     FolderMan *folderMan = FolderMan::instance();
+
+    // During the wizard, scheduling of new syncs is disabled
+    folderMan->setSyncEnabled(true);
+
     if( res == QDialog::Accepted ) {
-        int cnt = folderMan->setupFolders();
-        qDebug() << "Set up " << cnt << " folders.";
-        // We have some sort of configuration. Enable autostart
-        Utility::setLaunchOnStartup(_theme->appName(), _theme->appNameGUI(), true);
-        if (cnt == 0) {
-            // The folder configuration was skipped
-            _gui->slotShowSettings();
+        // Open the settings page for the new account if no folders
+        // were configured. Using the last account for this check is
+        // not exactly correct, but good enough.
+        if (!accountMan->accounts().isEmpty()) {
+            AccountStatePtr newAccount = accountMan->accounts().last();
+            bool hasFolder = false;
+            foreach (Folder* folder, folderMan->map()) {
+                if (folder->accountState() == newAccount.data()) {
+                    hasFolder = true;
+                    break;
+                }
+            }
+
+            if (!hasFolder) {
+                _gui->slotShowSettings();
+            }
         }
-    }
-    folderMan->setSyncEnabled( true );
-    if( res == QDialog::Accepted ) {
+
+        // Check connectivity of the newly created account
         _checkConnectionTimer.start();
         slotCheckConnection();
-    }
 
+        // The very first time an account is configured: enabled autostart
+        // TODO: Doing this every time the account wizard finishes will annoy users.
+        Utility::setLaunchOnStartup(_theme->appName(), _theme->appNameGUI(), true);
+    }
 }
 
 void Application::setupLogging()
index 18759a6f31d690133746544579554093178b067a..6ad1fa07b48600a48c77aceac17bf2bf363b27d8 100644 (file)
@@ -216,7 +216,7 @@ int FolderMan::setupFolders()
         settings->endGroup(); // <account>
     }
 
-    emit folderListLoaded(_folderMap);
+    emit folderListChanged(_folderMap);
 
     return _folderMap.size();
 }
@@ -245,7 +245,7 @@ int FolderMan::setupFoldersMigration()
         }
     }
 
-    emit folderListLoaded(_folderMap);
+    emit folderListChanged(_folderMap);
 
     // return the number of valid folders.
     return _folderMap.size();
@@ -775,6 +775,8 @@ Folder* FolderMan::addFolder(AccountState* accountState, const FolderDefinition&
     if(folder && accountState) {
         folder->setAccountState(accountState);
         folder->saveToSettings();
+        emit folderSyncStateChange(folder);
+        emit folderListChanged(_folderMap);
     }
     return folder;
 }
index b63e750d886d2fdd94ee6052b019d7eb4e84e6e9..b120ea5b328c54eee41b26ccaf41433e965ef280 100644 (file)
@@ -139,7 +139,7 @@ signals:
      */
     void scheduleQueueChanged();
 
-    void folderListLoaded(const Folder::Map &);
+    void folderListChanged(const Folder::Map &);
 
 public slots:
     void slotRemoveFolder( Folder* );