Handle the warning message when unchecking folders for syncing.
authorCamila <hello@camila.codes>
Wed, 2 Dec 2020 15:09:43 +0000 (16:09 +0100)
committerCamila <hello@camila.codes>
Mon, 14 Dec 2020 11:36:51 +0000 (12:36 +0100)
Split widgets and slot to handle the refreshing of the view:
- refreshSelectiveSyncStatus is connected to signal dirtyChanged
and will handle big folder warning.
- slotSelectiveSyncChanged  which is connected to dataChanged signal
and will handle the selective sync warning. It fixes #1029 because
it looks for the checkbox state before showing the warning.

Signed-off-by: Camila <hello@camila.codes>
src/gui/accountsettings.cpp
src/gui/accountsettings.h
src/gui/accountsettings.ui

index 49e90e19b90430bd956a8eb94328f9105b89728e..b878aa58af2344d376ff1f7a3b4fb6376aada84f 100644 (file)
@@ -170,6 +170,12 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent)
     addAction(syncNowWithRemoteDiscovery);
 
 
+    slotHideSelectiveSyncWidget();
+    _ui->bigFolderUi->setVisible(false);
+    connect(_model, &QAbstractItemModel::dataChanged, this, &AccountSettings::slotSelectiveSyncChanged);
+    connect(_ui->selectiveSyncApply, &QAbstractButton::clicked, this, &AccountSettings::slotHideSelectiveSyncWidget);
+    connect(_ui->selectiveSyncCancel, &QAbstractButton::clicked, this, &AccountSettings::slotHideSelectiveSyncWidget);
+
     connect(_ui->selectiveSyncApply, &QAbstractButton::clicked, _model, &FolderStatusModel::slotApplySelectiveSync);
     connect(_ui->selectiveSyncCancel, &QAbstractButton::clicked, _model, &FolderStatusModel::resetFolders);
     connect(_ui->bigFolderApply, &QAbstractButton::clicked, _model, &FolderStatusModel::slotApplySelectiveSync);
@@ -214,7 +220,6 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent)
     customizeStyle();
 }
 
-
 void AccountSettings::slotNewMnemonicGenerated()
 {
     _ui->encryptionMessage->setText(tr("This account supports end-to-end encryption"));
@@ -888,13 +893,71 @@ AccountSettings::~AccountSettings()
     delete _ui;
 }
 
-void AccountSettings::refreshSelectiveSyncStatus()
+void AccountSettings::slotHideSelectiveSyncWidget()
+{
+    _ui->selectiveSyncApply->setEnabled(false);
+    _ui->selectiveSyncStatus->setVisible(false);
+    _ui->selectiveSyncButtons->setVisible(false);
+    _ui->selectiveSyncLabel->hide();
+}
+
+void AccountSettings::slotSelectiveSyncChanged(const QModelIndex &topLeft,
+                                               const QModelIndex &bottomRight,
+                                               const QVector<int> &roles)
 {
-    bool shouldBeVisible = _model->isDirty() && _accountState->isConnected();
+    Q_UNUSED(bottomRight);
+    if (!roles.contains(Qt::CheckStateRole)) {
+        return;
+    }
+
+    const auto info = _model->infoForIndex(topLeft);
+    if (!info) {
+        return;
+    }
+
+    const bool showWarning = _model->isDirty() && _accountState->isConnected() && info->_checked == Qt::Unchecked;
 
+    // FIXME: the model is not precise enough to handle extra cases
+    // e.g. the user clicked on the same checkbox 2x without applying the change in between.
+    // We don't know which checkbox changed to be able to toggle the selectiveSyncLabel display.
+    if (showWarning) {
+        _ui->selectiveSyncLabel->show();
+    }
+
+    const bool shouldBeVisible = _model->isDirty();
+    const bool wasVisible = _ui->selectiveSyncStatus->isVisible();
+    if (shouldBeVisible) {
+        _ui->selectiveSyncStatus->setVisible(true);
+    }
+
+    _ui->selectiveSyncApply->setEnabled(true);
+    _ui->selectiveSyncButtons->setVisible(true);
+
+    if (shouldBeVisible != wasVisible) {
+        const auto hint = _ui->selectiveSyncStatus->sizeHint();
+
+        if (shouldBeVisible) {
+            _ui->selectiveSyncStatus->setMaximumHeight(0);
+        }
+
+        const auto anim = new QPropertyAnimation(_ui->selectiveSyncStatus, "maximumHeight", _ui->selectiveSyncStatus);
+        anim->setEndValue(_model->isDirty() ? hint.height() : 0);
+        anim->start(QAbstractAnimation::DeleteWhenStopped);
+        connect(anim, &QPropertyAnimation::finished, [this, shouldBeVisible]() {
+            _ui->selectiveSyncStatus->setMaximumHeight(QWIDGETSIZE_MAX);
+            if (!shouldBeVisible) {
+                _ui->selectiveSyncStatus->hide();
+            }
+        });
+    }
+}
+
+void AccountSettings::refreshSelectiveSyncStatus()
+{
     QString msg;
     int cnt = 0;
     const auto folders = FolderMan::instance()->map().values();
+    _ui->bigFolderUi->setVisible(false);
     for (Folder *folder : folders) {
         if (folder->accountState() != _accountState) {
             continue;
@@ -923,40 +986,16 @@ void AccountSettings::refreshSelectiveSyncStatus()
         }
     }
 
-    if (msg.isEmpty()) {
-        _ui->selectiveSyncButtons->setVisible(true);
-        _ui->bigFolderUi->setVisible(false);
-    } else {
+    if (!msg.isEmpty()) {
         ConfigFile cfg;
         QString info = !cfg.confirmExternalStorage()
-            ? tr("There are folders that were not synchronized because they are too big: ")
-            : !cfg.newBigFolderSizeLimit().first
-                ? tr("There are folders that were not synchronized because they are external storages: ")
-                : tr("There are folders that were not synchronized because they are too big or external storages: ");
+                ? tr("There are folders that were not synchronized because they are too big: ")
+                : !cfg.newBigFolderSizeLimit().first
+                  ? tr("There are folders that were not synchronized because they are external storages: ")
+                  : tr("There are folders that were not synchronized because they are too big or external storages: ");
 
         _ui->selectiveSyncNotification->setText(info + msg);
-        _ui->selectiveSyncButtons->setVisible(false);
         _ui->bigFolderUi->setVisible(true);
-        shouldBeVisible = true;
-    }
-
-    _ui->selectiveSyncApply->setEnabled(_model->isDirty() || !msg.isEmpty());
-    bool wasVisible = !_ui->selectiveSyncStatus->isHidden();
-    if (wasVisible != shouldBeVisible) {
-        QSize hint = _ui->selectiveSyncStatus->sizeHint();
-        if (shouldBeVisible) {
-            _ui->selectiveSyncStatus->setMaximumHeight(0);
-            _ui->selectiveSyncStatus->setVisible(true);
-        }
-        auto anim = new QPropertyAnimation(_ui->selectiveSyncStatus, "maximumHeight", _ui->selectiveSyncStatus);
-        anim->setEndValue(shouldBeVisible ? hint.height() : 0);
-        anim->start(QAbstractAnimation::DeleteWhenStopped);
-        connect(anim, &QPropertyAnimation::finished, [this, shouldBeVisible]() {
-            _ui->selectiveSyncStatus->setMaximumHeight(QWIDGETSIZE_MAX);
-            if (!shouldBeVisible) {
-                _ui->selectiveSyncStatus->hide();
-            }
-        });
     }
 }
 
index 3dfa18fb9bfc7d9ac9b4c979e3e155f3ddf2122c..ade9d6c58b0583ba500d04dc1c02c497137129a7 100644 (file)
@@ -71,8 +71,8 @@ public slots:
     void slotUpdateQuota(qint64 total, qint64 used);
     void slotAccountStateChanged();
     void slotStyleChanged();
-
     AccountState *accountsState() { return _accountState; }
+    void slotHideSelectiveSyncWidget();
 
 protected slots:
     void slotAddFolder();
@@ -103,6 +103,9 @@ protected slots:
     void slotNewMnemonicGenerated();
     void slotEncryptFolderFinished(int status);
 
+    void slotSelectiveSyncChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
+                                  const QVector<int> &roles);
+
 private:
     void showConnectionLabel(const QString &message,
         QStringList errors = QStringList());
index af155b51777c8830772ca19bd57015e3f04c086e..77224160c7dc31a3e32a206887e60ce94430beb1 100644 (file)
@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>581</width>
+    <width>588</width>
     <height>557</height>
    </rect>
   </property>
           </property>
          </widget>
         </item>
-        <item>
-         <widget class="QWidget" name="bigFolderUi" native="true">
-          <layout class="QVBoxLayout" name="verticalLayout">
-           <property name="leftMargin">
-            <number>0</number>
-           </property>
-           <property name="topMargin">
-            <number>0</number>
-           </property>
-           <property name="rightMargin">
-            <number>0</number>
-           </property>
-           <property name="bottomMargin">
-            <number>0</number>
-           </property>
-           <item>
-            <widget class="QLabel" name="selectiveSyncNotification">
-             <property name="styleSheet">
-              <string notr="true">color: red</string>
-             </property>
-             <property name="text">
-              <string/>
-             </property>
-             <property name="wordWrap">
-              <bool>true</bool>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <layout class="QHBoxLayout" name="horizontalLayout_2">
-             <item>
-              <widget class="QPushButton" name="bigFolderSyncAll">
-               <property name="text">
-                <string>Synchronize all</string>
-               </property>
-              </widget>
-             </item>
-             <item>
-              <widget class="QPushButton" name="bigFolderSyncNone">
-               <property name="text">
-                <string>Synchronize none</string>
-               </property>
-              </widget>
-             </item>
-             <item>
-              <widget class="QPushButton" name="bigFolderApply">
-               <property name="text">
-                <string>Apply manual changes</string>
-               </property>
-              </widget>
-             </item>
-            </layout>
-           </item>
-          </layout>
-         </widget>
-        </item>
        </layout>
       </item>
       <item>
      </item>
     </layout>
    </item>
+   <item row="1" column="0">
+    <widget class="KMessageWidget" name="encryptionMessage" native="true"/>
+   </item>
    <item row="3" column="0">
     <widget class="OCC::FolderStatusView" name="_folderList">
      <property name="sizePolicy">
      </property>
     </widget>
    </item>
-   <item row="1" column="0">
-    <widget class="KMessageWidget" name="encryptionMessage" native="true"/>
+   <item row="5" column="0">
+    <widget class="QWidget" name="bigFolderUi" native="true">
+     <layout class="QVBoxLayout" name="verticalLayout">
+      <property name="leftMargin">
+       <number>0</number>
+      </property>
+      <property name="topMargin">
+       <number>0</number>
+      </property>
+      <property name="rightMargin">
+       <number>0</number>
+      </property>
+      <property name="bottomMargin">
+       <number>0</number>
+      </property>
+      <item>
+       <widget class="QLabel" name="selectiveSyncNotification">
+        <property name="styleSheet">
+         <string notr="true">color: red</string>
+        </property>
+        <property name="text">
+         <string/>
+        </property>
+        <property name="wordWrap">
+         <bool>true</bool>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <layout class="QHBoxLayout" name="horizontalLayout_2">
+        <item>
+         <spacer name="horizontalSpacer">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>40</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+        <item>
+         <widget class="QPushButton" name="bigFolderSyncAll">
+          <property name="text">
+           <string>Synchronize all</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QPushButton" name="bigFolderSyncNone">
+          <property name="text">
+           <string>Synchronize none</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QPushButton" name="bigFolderApply">
+          <property name="text">
+           <string>Apply manual changes</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+     </layout>
+    </widget>
    </item>
   </layout>
  </widget>