Wizards: Add placeholder option and warning to account wizard
authorChristian Kamm <mail@ckamm.de>
Tue, 3 Apr 2018 15:30:17 +0000 (17:30 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:57:50 +0000 (10:57 +0100)
Also add the warning dialog to the option in the folder wizard.

src/gui/folderwizard.cpp
src/gui/folderwizard.h
src/gui/owncloudsetupwizard.cpp
src/gui/wizard/owncloudadvancedsetuppage.cpp
src/gui/wizard/owncloudadvancedsetuppage.h
src/gui/wizard/owncloudadvancedsetuppage.ui
src/gui/wizard/owncloudwizard.cpp
src/gui/wizard/owncloudwizard.h

index 8fc46aaade7f50750d08057994e09bb824b2534b..4abf28afae9263f3e695180970130a78ef87162d 100644 (file)
@@ -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);
+        });
+    }
+}
+
 
 // ====================================================================================
 
index 42cdfce18c90f456203e2bd74b36d1277a0091e3..7255e699519adb2e34c5e976b6ed06e4f3ce88ba 100644 (file)
@@ -130,6 +130,9 @@ public:
     void initializePage() override;
     void cleanupPage() override;
 
+private slots:
+    void placeholderCheckboxClicked();
+
 private:
     SelectiveSyncWidget *_selectiveSync;
     QCheckBox *_placeholderCheckBox;
index 1a8762e04c821a66898a5c1957f444d0c663f2be..1d8ff440df6855e4e212de016c2a637fb0fb8ca8 100644 (file)
@@ -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();
 
index 4fb0f424a3d15dd13dd5cea4c1314e8b4706d234..794d095bd0ccaed03b0f16160488a69cbc4c47c4 100644 (file)
@@ -18,6 +18,7 @@
 #include <QUrl>
 #include <QTimer>
 #include <QStorageInfo>
+#include <QMessageBox>
 
 #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<OwncloudWizard *>(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
index f49fc8f1d76e1e8bd778b762c7517c786c156652..b4a24681c0639bdb4930026ac6f76ea43edd2e8e 100644 (file)
@@ -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();
index 7f223ed8907d54528eff023a0cd08d4ea361b13d..6883094a54aba3973689cd492507bbf92ea92971 100644 (file)
             <property name="text">
              <string/>
             </property>
+            <property name="checkable">
+             <bool>false</bool>
+            </property>
            </widget>
           </item>
           <item>
           </item>
          </layout>
         </item>
+        <item>
+         <layout class="QHBoxLayout" name="horizontalLayout_4">
+          <item>
+           <widget class="QRadioButton" name="rPlaceholderSync">
+            <property name="sizePolicy">
+             <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+              <horstretch>0</horstretch>
+              <verstretch>0</verstretch>
+             </sizepolicy>
+            </property>
+            <property name="text">
+             <string>Create placeholders instead of downloading files (experimental)</string>
+            </property>
+            <property name="checkable">
+             <bool>false</bool>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <spacer name="horizontalSpacer_5">
+            <property name="orientation">
+             <enum>Qt::Horizontal</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>40</width>
+              <height>20</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+         </layout>
+        </item>
        </layout>
       </widget>
      </item>
index 912222dca764776dcb7c808f73c6be1e5daef3d3..d9adb828e78b21fba9d9d7487134db9202fc41f4 100644 (file)
@@ -14,6 +14,7 @@
  */
 
 #include "account.h"
+#include "config.h"
 #include "configfile.h"
 #include "theme.h"
 #include "owncloudgui.h"
@@ -34,6 +35,7 @@
 
 #include <QtCore>
 #include <QtGui>
+#include <QMessageBox>
 
 #include <cstdlib>
 
@@ -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<void(bool enable)> &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
index ee6161ca55d9de0a08a927b4427dbeee2cdad374..b81c2cd9f6ac0d9fcc0b44485e7a92c1f398800a 100644 (file)
@@ -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<void(bool enable)> &callback);
+
     // FIXME: Can those be local variables?
     // Set from the OwncloudSetupPage, later used from OwncloudHttpCredsPage
     QSslKey _clientSslKey;