From aee8b9f3c59610b8ec82f9a3563d0bc45d762c48 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Tue, 3 Apr 2018 17:30:17 +0200 Subject: [PATCH] Wizards: Add placeholder option and warning to account wizard Also add the warning dialog to the option in the folder wizard. --- src/gui/folderwizard.cpp | 15 ++++++- src/gui/folderwizard.h | 3 ++ src/gui/owncloudsetupwizard.cpp | 1 + src/gui/wizard/owncloudadvancedsetuppage.cpp | 42 +++++++++++++++++--- src/gui/wizard/owncloudadvancedsetuppage.h | 4 ++ src/gui/wizard/owncloudadvancedsetuppage.ui | 36 +++++++++++++++++ src/gui/wizard/owncloudwizard.cpp | 28 +++++++++++++ src/gui/wizard/owncloudwizard.h | 8 ++++ 8 files changed, 130 insertions(+), 7 deletions(-) diff --git a/src/gui/folderwizard.cpp b/src/gui/folderwizard.cpp index 8fc46aaad..4abf28afa 100644 --- a/src/gui/folderwizard.cpp +++ b/src/gui/folderwizard.cpp @@ -493,7 +493,8 @@ FolderWizardSelectiveSync::FolderWizardSelectiveSync(const AccountPtr &account) auto *layout = new QVBoxLayout(this); _selectiveSync = new SelectiveSyncWidget(account, this); layout->addWidget(_selectiveSync); - _placeholderCheckBox = new QCheckBox(tr("Download placeholders instead of downloading the files (Experimental)")); + _placeholderCheckBox = new QCheckBox(tr("Create placeholders instead of downloading files (experimental)")); + connect(_placeholderCheckBox, &QCheckBox::clicked, this, &FolderWizardSelectiveSync::placeholderCheckboxClicked); layout->addWidget(_placeholderCheckBox); } @@ -534,6 +535,18 @@ void FolderWizardSelectiveSync::cleanupPage() QWizardPage::cleanupPage(); } +void FolderWizardSelectiveSync::placeholderCheckboxClicked() +{ + // The click has already had an effect on the box, so if it's + // checked it was newly activated. + if (_placeholderCheckBox->isChecked()) { + OwncloudWizard::askExperimentalPlaceholderFeature([this](bool enable) { + if (!enable) + _placeholderCheckBox->setChecked(false); + }); + } +} + // ==================================================================================== diff --git a/src/gui/folderwizard.h b/src/gui/folderwizard.h index 42cdfce18..7255e6995 100644 --- a/src/gui/folderwizard.h +++ b/src/gui/folderwizard.h @@ -130,6 +130,9 @@ public: void initializePage() override; void cleanupPage() override; +private slots: + void placeholderCheckboxClicked(); + private: SelectiveSyncWidget *_selectiveSync; QCheckBox *_placeholderCheckBox; diff --git a/src/gui/owncloudsetupwizard.cpp b/src/gui/owncloudsetupwizard.cpp index 1a8762e04..1d8ff440d 100644 --- a/src/gui/owncloudsetupwizard.cpp +++ b/src/gui/owncloudsetupwizard.cpp @@ -633,6 +633,7 @@ void OwncloudSetupWizard::slotAssistantFinished(int result) folderDefinition.localPath = localFolder; folderDefinition.targetPath = FolderDefinition::prepareTargetPath(_remoteFolder); folderDefinition.ignoreHiddenFiles = folderMan->ignoreHiddenFiles(); + folderDefinition.usePlaceholders = _ocWizard->usePlaceholderSync(); if (folderMan->navigationPaneHelper().showInExplorerNavigationPane()) folderDefinition.navigationPaneClsid = QUuid::createUuid(); diff --git a/src/gui/wizard/owncloudadvancedsetuppage.cpp b/src/gui/wizard/owncloudadvancedsetuppage.cpp index 4fb0f424a..794d095bd 100644 --- a/src/gui/wizard/owncloudadvancedsetuppage.cpp +++ b/src/gui/wizard/owncloudadvancedsetuppage.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "QProgressIndicator.h" @@ -55,6 +56,7 @@ OwncloudAdvancedSetupPage::OwncloudAdvancedSetupPage() connect(_ui.rSyncEverything, &QAbstractButton::clicked, this, &OwncloudAdvancedSetupPage::slotSyncEverythingClicked); connect(_ui.rSelectiveSync, &QAbstractButton::clicked, this, &OwncloudAdvancedSetupPage::slotSelectiveSyncClicked); + connect(_ui.rPlaceholderSync, &QAbstractButton::clicked, this, &OwncloudAdvancedSetupPage::slotPlaceholderSyncClicked); connect(_ui.bSelectiveSync, &QAbstractButton::clicked, this, &OwncloudAdvancedSetupPage::slotSelectiveSyncClicked); QIcon appIcon = theme->applicationIcon(); @@ -231,6 +233,11 @@ QStringList OwncloudAdvancedSetupPage::selectiveSyncBlacklist() const return _selectiveSyncBlacklist; } +bool OwncloudAdvancedSetupPage::usePlaceholderSync() const +{ + return _ui.rPlaceholderSync->isChecked(); +} + bool OwncloudAdvancedSetupPage::isConfirmBigFolderChecked() const { return _ui.rSyncEverything->isChecked() && _ui.confCheckBoxSize->isChecked(); @@ -305,9 +312,6 @@ void OwncloudAdvancedSetupPage::slotSelectFolder() void OwncloudAdvancedSetupPage::slotSelectiveSyncClicked() { - // Because clicking on it also changes it, restore it to the previous state in case the user cancelled the dialog - _ui.rSyncEverything->setChecked(_selectiveSyncBlacklist.isEmpty()); - AccountPtr acc = static_cast(wizard())->account(); auto *dlg = new SelectiveSyncDialog(acc, _remoteFolder, _selectiveSyncBlacklist, this); @@ -330,7 +334,7 @@ void OwncloudAdvancedSetupPage::slotSelectiveSyncClicked() if (updateBlacklist) { if (!_selectiveSyncBlacklist.isEmpty()) { _ui.rSelectiveSync->blockSignals(true); - _ui.rSelectiveSync->setChecked(true); + setRadioChecked(_ui.rSelectiveSync); _ui.rSelectiveSync->blockSignals(false); auto s = dlg->estimatedSize(); if (s > 0) { @@ -344,17 +348,29 @@ void OwncloudAdvancedSetupPage::slotSelectiveSyncClicked() _ui.lSelectiveSyncSizeLabel->setText(QString()); } } else { - _ui.rSyncEverything->setChecked(true); + setRadioChecked(_ui.rSyncEverything); _ui.lSelectiveSyncSizeLabel->setText(QString()); } wizard()->setProperty("blacklist", _selectiveSyncBlacklist); } } +void OwncloudAdvancedSetupPage::slotPlaceholderSyncClicked() +{ + OwncloudWizard::askExperimentalPlaceholderFeature([this](bool enable) { + if (!enable) + return; + + _ui.lSelectiveSyncSizeLabel->setText(QString()); + _selectiveSyncBlacklist.clear(); + setRadioChecked(_ui.rPlaceholderSync); + }); +} + void OwncloudAdvancedSetupPage::slotSyncEverythingClicked() { _ui.lSelectiveSyncSizeLabel->setText(QString()); - _ui.rSyncEverything->setChecked(true); + setRadioChecked(_ui.rSyncEverything); _selectiveSyncBlacklist.clear(); QString errorStr = checkLocalSpace(_rSize); @@ -395,4 +411,18 @@ void OwncloudAdvancedSetupPage::customizeStyle() _progressIndi->setColor(QGuiApplication::palette().color(QPalette::Text)); } +void OwncloudAdvancedSetupPage::setRadioChecked(QRadioButton *radio) +{ + // We don't want clicking the radio buttons to immediately adjust the checked state + // for selective sync and placeholder sync, so we keep them uncheckable until + // they should be checked. + radio->setCheckable(true); + radio->setChecked(true); + + if (radio != _ui.rSelectiveSync) + _ui.rSelectiveSync->setCheckable(false); + if (radio != _ui.rPlaceholderSync) + _ui.rPlaceholderSync->setCheckable(false); +} + } // namespace OCC diff --git a/src/gui/wizard/owncloudadvancedsetuppage.h b/src/gui/wizard/owncloudadvancedsetuppage.h index f49fc8f1d..b4a24681c 100644 --- a/src/gui/wizard/owncloudadvancedsetuppage.h +++ b/src/gui/wizard/owncloudadvancedsetuppage.h @@ -41,6 +41,7 @@ public: bool validatePage() override; QString localFolder() const; QStringList selectiveSyncBlacklist() const; + bool usePlaceholderSync() const; bool isConfirmBigFolderChecked() const; void setRemoteFolder(const QString &remoteFolder); void setMultipleFoldersExist(bool exist); @@ -57,9 +58,12 @@ private slots: void slotSelectFolder(); void slotSyncEverythingClicked(); void slotSelectiveSyncClicked(); + void slotPlaceholderSyncClicked(); void slotQuotaRetrieved(const QVariantMap &result); private: + void setRadioChecked(QRadioButton *radio); + void setupCustomization(); void updateStatus(); bool dataChanged(); diff --git a/src/gui/wizard/owncloudadvancedsetuppage.ui b/src/gui/wizard/owncloudadvancedsetuppage.ui index 7f223ed89..6883094a5 100644 --- a/src/gui/wizard/owncloudadvancedsetuppage.ui +++ b/src/gui/wizard/owncloudadvancedsetuppage.ui @@ -190,6 +190,9 @@ + + false + @@ -224,6 +227,39 @@ + + + + + + + 0 + 0 + + + + Create placeholders instead of downloading files (experimental) + + + false + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + diff --git a/src/gui/wizard/owncloudwizard.cpp b/src/gui/wizard/owncloudwizard.cpp index 912222dca..d9adb828e 100644 --- a/src/gui/wizard/owncloudwizard.cpp +++ b/src/gui/wizard/owncloudwizard.cpp @@ -14,6 +14,7 @@ */ #include "account.h" +#include "config.h" #include "configfile.h" #include "theme.h" #include "owncloudgui.h" @@ -34,6 +35,7 @@ #include #include +#include #include @@ -131,6 +133,11 @@ QStringList OwncloudWizard::selectiveSyncBlacklist() const return _advancedSetupPage->selectiveSyncBlacklist(); } +bool OwncloudWizard::usePlaceholderSync() const +{ + return _advancedSetupPage->usePlaceholderSync(); +} + bool OwncloudWizard::isConfirmBigFolderChecked() const { return _advancedSetupPage->isConfirmBigFolderChecked(); @@ -319,4 +326,25 @@ void OwncloudWizard::bringToTop() ownCloudGui::raiseDialog(this); } +void OwncloudWizard::askExperimentalPlaceholderFeature(const std::function &callback) +{ + auto msgBox = new QMessageBox( + QMessageBox::Warning, + tr("Enable experimental feature?"), + tr("When the \"synchronize placeholders\" mode is enabled no files will be downloaded initially. " + "Instead, a tiny \"%1\" file will be created for each file on the server. " + "The contents can be downloaded by running these files or by using their context menu." + "\n\n" + "This is a new, experimental mode. If you decide to use it, please report any " + "issues that come up.") + .arg(APPLICATION_DOTPLACEHOLDER_SUFFIX)); + msgBox->addButton(tr("Enable experimental mode"), QMessageBox::AcceptRole); + msgBox->addButton(tr("Stay safe"), QMessageBox::RejectRole); + connect(msgBox, &QMessageBox::finished, msgBox, [callback, msgBox](int result) { + callback(result == QMessageBox::AcceptRole); + msgBox->deleteLater(); + }); + msgBox->open(); +} + } // end namespace diff --git a/src/gui/wizard/owncloudwizard.h b/src/gui/wizard/owncloudwizard.h index ee6161ca5..b81c2cd9f 100644 --- a/src/gui/wizard/owncloudwizard.h +++ b/src/gui/wizard/owncloudwizard.h @@ -67,6 +67,7 @@ public: QString ocUrl() const; QString localFolder() const; QStringList selectiveSyncBlacklist() const; + bool usePlaceholderSync() const; bool isConfirmBigFolderChecked() const; void enableFinishOnResultWidget(bool enable); @@ -76,6 +77,13 @@ public: void bringToTop(); + /** + * Shows a dialog explaining the placeholder mode and warning about it + * being experimental. Calles the callback with true if enabling was + * chosen. + */ + static void askExperimentalPlaceholderFeature(const std::function &callback); + // FIXME: Can those be local variables? // Set from the OwncloudSetupPage, later used from OwncloudHttpCredsPage QSslKey _clientSslKey;