diff options
author | Fabian Müller <fmueller@owncloud.com> | 2022-04-21 04:59:31 +0300 |
---|---|---|
committer | Hannah von Reth <vonreth@kde.org> | 2022-04-26 18:32:09 +0300 |
commit | d2d3cae83b8956d2b020e440beb17ae6d9af565d (patch) | |
tree | 076d2ec49bcdb509893bef434bf0ea31460f7119 /src/gui/owncloudgui.cpp | |
parent | 8f1083da6ee709e59f6c715cc2c0097797e72fd5 (diff) |
Use folder wizard for manual sync config
This approach gives the user a lot more freedom.
The commit further moves the dialog logic out of the folder manager code, which allows us to clean up some API weirdness.
Diffstat (limited to 'src/gui/owncloudgui.cpp')
-rw-r--r-- | src/gui/owncloudgui.cpp | 170 |
1 files changed, 117 insertions, 53 deletions
diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 935279582..bb3429b8a 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -22,7 +22,9 @@ #include "configfile.h" #include "creds/abstractcredentials.h" #include "folderman.h" +#include "folderwizard/folderwizard.h" #include "graphapi/drives.h" +#include "gui/accountsettings.h" #include "guiutility.h" #include "logbrowser.h" #include "logger.h" @@ -51,61 +53,46 @@ namespace { using namespace OCC; -void setUpInitialSyncFolder(AccountStatePtr accountStatePtr, const QString &localFolder, Wizard::SyncMode syncMode) +void setUpInitialSyncFolder(AccountStatePtr accountStatePtr, const QString &localFolder, bool useVfs) { - auto account = accountStatePtr->account(); - - // ensure we are connected and fetch the capabilities - auto validator = new ConnectionValidator(account, account.data()); - - QObject::connect(validator, &ConnectionValidator::connectionResult, account.data(), [accountStatePtr, localFolder, syncMode](ConnectionValidator::Status status, const QStringList &errors) { - if (OC_ENSURE(status == ConnectionValidator::Connected)) { - // saving once after adding makes sure the account is stored in the config in a working state - // this is needed to ensure a consistent state in the config file upon unexpected terminations of the client - // (for instance, when running from a debugger and stopping the process from there) - AccountManager::instance()->save(true); - auto folderMan = FolderMan::instance(); - - // saves a bit of duplicate code - auto addFolder = [folderMan, accountStatePtr, syncMode](const QString &localFolder, const QString &remotePath, const QUrl &webDavUrl, const QString &displayName = {}) { - folderMan->addFolderFromWizard(accountStatePtr, localFolder, remotePath, webDavUrl, displayName, syncMode); - }; - - auto finalize = [accountStatePtr] { - accountStatePtr->checkConnectivity(); - FolderMan::instance()->scheduleAllFolders(); - }; - - if (accountStatePtr->account()->capabilities().spacesSupport().enabled) { - auto *drive = new OCC::GraphApi::Drives(accountStatePtr->account()); - - QObject::connect(drive, &OCC::GraphApi::Drives::finishedSignal, [accountStatePtr, localFolder, drive, addFolder, finalize] { - if (drive->parseError().error == QJsonParseError::NoError) { - const auto &drives = drive->drives(); - if (!drives.isEmpty()) { - const QDir localDir(localFolder); - localDir.mkdir("."); - for (const auto &d : drives) { - const QDir driveLocalFolder = localDir.filePath(d.getName()); - driveLocalFolder.mkdir("."); - addFolder(driveLocalFolder.absolutePath(), {}, QUrl::fromEncoded(d.getRoot().getWebDavUrl().toUtf8()), d.getName()); - } - finalize(); - } - } - }); + auto folderMan = FolderMan::instance(); - drive->start(); + // saves a bit of duplicate code + auto addFolder = [folderMan, accountStatePtr, useVfs](const QString &localFolder, const QString &remotePath, const QUrl &webDavUrl, const QString &displayName = {}) { + folderMan->addFolderFromWizard(accountStatePtr, localFolder, remotePath, webDavUrl, displayName, useVfs); + }; - return; - } else { - addFolder(localFolder, Theme::instance()->defaultServerFolder(), accountStatePtr->account()->davUrl()); - finalize(); + auto finalize = [accountStatePtr] { + accountStatePtr->checkConnectivity(); + FolderMan::instance()->scheduleAllFolders(); + }; + + if (accountStatePtr->account()->capabilities().spacesSupport().enabled) { + auto *drive = new OCC::GraphApi::Drives(accountStatePtr->account()); + + QObject::connect(drive, &OCC::GraphApi::Drives::finishedSignal, [accountStatePtr, localFolder, drive, addFolder, finalize] { + if (drive->parseError().error == QJsonParseError::NoError) { + const auto &drives = drive->drives(); + if (!drives.isEmpty()) { + const QDir localDir(localFolder); + localDir.mkdir("."); + for (const auto &d : drives) { + const QDir driveLocalFolder = localDir.filePath(d.getName()); + driveLocalFolder.mkdir("."); + addFolder(driveLocalFolder.absolutePath(), {}, QUrl::fromEncoded(d.getRoot().getWebDavUrl().toUtf8()), d.getName()); + } + finalize(); + } } - } - }); + }); - validator->checkServerAndUpdate(); + drive->start(); + + return; + } else { + addFolder(localFolder, Theme::instance()->defaultServerFolder(), accountStatePtr->account()->davUrl()); + finalize(); + } } } @@ -1015,8 +1002,9 @@ void ownCloudGui::runNewAccountWizard() connect(_wizardController, &Wizard::SetupWizardController::finished, ocApp(), [this](AccountPtr newAccount, const QString &localFolder, Wizard::SyncMode syncMode) { - // reenable sync, which is disabled while the wizard is shown - FolderMan::instance()->setSyncEnabled(true); + // note: while the wizard is shown, we disable the folder synchronization + // previously we could perform this just here, but now we have to postpone this depending on whether selective sync was chosen + // see also #9497 // when the dialog is closed before it has finished, there won't be a new account to set up // the wizard controller signalizes this by passing a null pointer @@ -1024,7 +1012,83 @@ void ownCloudGui::runNewAccountWizard() // finally, call the slot that finalizes the setup auto accountStatePtr = ocApp()->addNewAccount(newAccount); - setUpInitialSyncFolder(accountStatePtr, localFolder, syncMode); + auto account = accountStatePtr->account(); + + // ensure we are connected and fetch the capabilities + auto validator = new ConnectionValidator(account, account.data()); + + QObject::connect(validator, &ConnectionValidator::connectionResult, account.data(), [accountStatePtr, localFolder, syncMode](ConnectionValidator::Status status, const QStringList &errors) { + if (OC_ENSURE(status == ConnectionValidator::Connected)) { + // saving once after adding makes sure the account is stored in the config in a working state + // this is needed to ensure a consistent state in the config file upon unexpected terminations of the client + // (for instance, when running from a debugger and stopping the process from there) + AccountManager::instance()->save(true); + + switch (syncMode) { + case Wizard::SyncMode::SyncEverything: + case Wizard::SyncMode::UseVfs: { + bool useVfs = syncMode == Wizard::SyncMode::UseVfs; + setUpInitialSyncFolder(accountStatePtr, localFolder, useVfs); + FolderMan::instance()->setSyncEnabled(true); + + break; + } + case Wizard::SyncMode::ConfigureUsingFolderWizard: { + // localFolder is ignored in this scenario + // we want the caller to make sure it's not set to a value, though + Q_ASSERT(localFolder.isEmpty()); + + auto *folderWizard = new FolderWizard(accountStatePtr->account(), ocApp()->gui()->settingsDialog()); + folderWizard->setAttribute(Qt::WA_DeleteOnClose); + + // adapted from AccountSettings::slotFolderWizardAccepted() + connect(folderWizard, &QDialog::accepted, [accountStatePtr, folderWizard]() { + FolderMan *folderMan = FolderMan::instance(); + + qCInfo(lcApplication) << "Folder wizard completed"; + + bool useVfs = folderWizard->property("useVirtualFiles").toBool(); + + auto folder = folderMan->addFolderFromWizard(accountStatePtr, + folderWizard->field(QLatin1String("sourceFolder")).toString(), + folderWizard->property("targetPath").toString(), + folderWizard->davUrl(), + folderWizard->displayName(), + useVfs); + + const auto selectiveSyncBlackList = folderWizard->property("selectiveSyncBlackList").toStringList(); + + if (!selectiveSyncBlackList.isEmpty() && OC_ENSURE(folder && useVfs)) { + folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, selectiveSyncBlackList); + + // The user already accepted the selective sync dialog. everything is in the white list + folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList, + QStringList() << QLatin1String("/")); + } + + folderMan->setSyncEnabled(true); + folderMan->scheduleAllFolders(); + }); + + connect(folderWizard, &QDialog::rejected, []() { + qCInfo(lcApplication) << "Folder wizard cancelled"; + FolderMan::instance()->setSyncEnabled(true); + }); + + folderWizard->open(); + + break; + } + default: + Q_UNREACHABLE(); + } + } + }); + + + validator->checkServerAndUpdate(); + } else { + FolderMan::instance()->setSyncEnabled(true); } // make sure the wizard is cleaned up eventually |