Show an error message if there is no enough free space in the local
authorJavier Llorente <javier@opensuse.org>
Wed, 9 Jan 2019 22:15:45 +0000 (23:15 +0100)
committerJavier Llorente <javier@opensuse.org>
Sun, 13 Jan 2019 22:35:06 +0000 (23:35 +0100)
folder

src/gui/wizard/owncloudadvancedsetuppage.cpp
src/gui/wizard/owncloudadvancedsetuppage.h
src/gui/wizard/owncloudadvancedsetuppage.ui

index 981f7efae83cad93283a004c594812107d465839..a340d89bfcc2ca9826a07afec6b9342305100ef1 100644 (file)
@@ -17,6 +17,7 @@
 #include <QFileDialog>
 #include <QUrl>
 #include <QTimer>
+#include <QStorageInfo>
 
 #include "QProgressIndicator.h"
 
@@ -169,10 +170,21 @@ void OwncloudAdvancedSetupPage::updateStatus()
         _ui.resolutionWidget->setVisible(false);
     }
 
+    QString lfreeSpaceStr = Utility::octetsToString(availableLocalSpace());
+    _ui.lFreeSpace->setText(QString(tr("Free space: %1")).arg(lfreeSpaceStr));
+
     _ui.syncModeLabel->setText(t);
     _ui.syncModeLabel->setFixedHeight(_ui.syncModeLabel->sizeHint().height());
     wizard()->resize(wizard()->sizeHint());
+
+    qint64 rSpace = _ui.rSyncEverything->isChecked() ? _rSize : _rSelectedSize;
+
+    QString spaceError = checkLocalSpace(rSpace);
+    if (!spaceError.isEmpty()) {
+        errorStr = spaceError;
+    }
     setErrorString(errorStr);
+
     emit completeChanged();
 }
 
@@ -288,6 +300,10 @@ void OwncloudAdvancedSetupPage::slotSelectFolder()
         wizard()->setProperty("localFolder", dir);
         updateStatus();
     }
+
+    qint64 rSpace = _ui.rSyncEverything->isChecked() ? _rSize : _rSelectedSize;
+    QString errorStr = checkLocalSpace(rSpace);
+    setErrorString(errorStr);
 }
 
 void OwncloudAdvancedSetupPage::slotSelectiveSyncClicked()
@@ -322,6 +338,11 @@ void OwncloudAdvancedSetupPage::slotSelectiveSyncClicked()
             auto s = dlg->estimatedSize();
             if (s > 0) {
                 _ui.lSelectiveSyncSizeLabel->setText(tr("(%1)").arg(Utility::octetsToString(s)));
+
+                _rSelectedSize = s;
+                QString errorStr = checkLocalSpace(_rSelectedSize);
+                setErrorString(errorStr);
+
             } else {
                 _ui.lSelectiveSyncSizeLabel->setText(QString());
             }
@@ -338,11 +359,30 @@ void OwncloudAdvancedSetupPage::slotSyncEverythingClicked()
     _ui.lSelectiveSyncSizeLabel->setText(QString());
     _ui.rSyncEverything->setChecked(true);
     _selectiveSyncBlacklist.clear();
+
+    QString errorStr = checkLocalSpace(_rSize);
+    setErrorString(errorStr);
 }
 
 void OwncloudAdvancedSetupPage::slotQuotaRetrieved(const QVariantMap &result)
 {
-    _ui.lSyncEverythingSizeLabel->setText(tr("(%1)").arg(Utility::octetsToString(result["size"].toDouble())));
+    _rSize = result["size"].toDouble();
+    _ui.lSyncEverythingSizeLabel->setText(tr("(%1)").arg(Utility::octetsToString(_rSize)));
+}
+
+qint64 OwncloudAdvancedSetupPage::availableLocalSpace() const
+{
+    QString localDir = localFolder();
+    QString path = !QDir(localDir).exists() && localDir.contains(QDir::homePath()) ?
+                QDir::homePath() : localDir;
+    QStorageInfo storage(QDir::toNativeSeparators(path));
+
+    return storage.bytesAvailable();
+}
+
+QString OwncloudAdvancedSetupPage::checkLocalSpace(qint64 remoteSize) const
+{
+    return (availableLocalSpace()>remoteSize) ? QString() : tr("There is no enough free space in the local folder!");
 }
 
 } // namespace OCC
index 593f9e0539c45500147ca9e147340e35c29fe188..9ebf9fc70f149490d16f9d664b354423fa96733f 100644 (file)
@@ -65,6 +65,8 @@ private:
     void startSpinner();
     void stopSpinner();
     QUrl serverUrl() const;
+    qint64 availableLocalSpace() const;
+    QString checkLocalSpace(qint64 remoteSize) const;
 
     Ui_OwncloudAdvancedSetupPage _ui;
     bool _checking;
@@ -73,6 +75,8 @@ private:
     QProgressIndicator *_progressIndi;
     QString _remoteFolder;
     QStringList _selectiveSyncBlacklist;
+    qint64 _rSize;
+    qint64 _rSelectedSize;
 };
 
 } // namespace OCC
index a36704c389cfd9e4635953945b0e0e87982fdc63..d949d50ba1e3e55da401250ca4cca2556c7cad48 100644 (file)
        </property>
       </spacer>
      </item>
-     <item row="0" column="0">
-      <layout class="QVBoxLayout" name="verticalLayout_2">
-       <item>
-        <widget class="QLabel" name="lServerIcon">
-         <property name="text">
-          <string>TextLabel</string>
-         </property>
-         <property name="alignment">
-          <set>Qt::AlignCenter</set>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="QLabel" name="lServer">
-         <property name="text">
-          <string>Server</string>
-         </property>
-         <property name="alignment">
-          <set>Qt::AlignCenter</set>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <spacer name="verticalSpacer_3">
-         <property name="orientation">
-          <enum>Qt::Vertical</enum>
-         </property>
-         <property name="sizeHint" stdset="0">
-          <size>
-           <width>20</width>
-           <height>40</height>
-          </size>
-         </property>
-        </spacer>
-       </item>
-      </layout>
-     </item>
-     <item row="1" column="1">
-      <spacer name="verticalSpacer">
-       <property name="orientation">
-        <enum>Qt::Vertical</enum>
-       </property>
-       <property name="sizeType">
-        <enum>QSizePolicy::MinimumExpanding</enum>
-       </property>
-       <property name="sizeHint" stdset="0">
-        <size>
-         <width>20</width>
-         <height>40</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-     <item row="2" column="0" rowspan="3">
-      <layout class="QVBoxLayout" name="verticalLayout_3">
-       <item>
-        <widget class="QLabel" name="lLocalIcon">
-         <property name="text">
-          <string>TextLabel</string>
-         </property>
-         <property name="alignment">
-          <set>Qt::AlignCenter</set>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="QLabel" name="lLocal">
-         <property name="sizePolicy">
-          <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
-           <horstretch>0</horstretch>
-           <verstretch>0</verstretch>
-          </sizepolicy>
-         </property>
-         <property name="text">
-          <string>&amp;Local Folder</string>
-         </property>
-         <property name="alignment">
-          <set>Qt::AlignCenter</set>
-         </property>
-         <property name="buddy">
-          <cstring>pbSelectLocalFolder</cstring>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <spacer name="verticalSpacer_4">
-         <property name="orientation">
-          <enum>Qt::Vertical</enum>
-         </property>
-         <property name="sizeHint" stdset="0">
-          <size>
-           <width>20</width>
-           <height>40</height>
-          </size>
-         </property>
-        </spacer>
-       </item>
-      </layout>
-     </item>
-     <item row="4" column="1" colspan="2">
-      <widget class="QWidget" name="resolutionWidget" native="true">
-       <property name="sizePolicy">
-        <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
-         <horstretch>0</horstretch>
-         <verstretch>0</verstretch>
-        </sizepolicy>
-       </property>
-       <layout class="QFormLayout" name="formLayout_2">
-        <property name="sizeConstraint">
-         <enum>QLayout::SetMinimumSize</enum>
-        </property>
-        <property name="fieldGrowthPolicy">
-         <enum>QFormLayout::ExpandingFieldsGrow</enum>
-        </property>
-        <item row="1" column="0" colspan="2">
-         <widget class="QRadioButton" name="radioButton">
-          <property name="text">
-           <string>&amp;Keep local data</string>
-          </property>
-          <property name="checked">
-           <bool>true</bool>
-          </property>
-         </widget>
-        </item>
-        <item row="2" column="0" colspan="2">
-         <widget class="QRadioButton" name="cbSyncFromScratch">
-          <property name="toolTip">
-           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If this box is checked, existing content in the local folder will be erased to start a clean sync from the server.&lt;/p&gt;&lt;p&gt;Do not check this if the local content should be uploaded to the servers folder.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
-          </property>
-          <property name="text">
-           <string>Start a &amp;clean sync (Erases the local folder!)</string>
-          </property>
-          <property name="checkable">
-           <bool>true</bool>
-          </property>
-         </widget>
-        </item>
-       </layout>
-      </widget>
-     </item>
-     <item row="2" column="1" rowspan="2">
-      <widget class="QPushButton" name="pbSelectLocalFolder">
-       <property name="sizePolicy">
-        <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
-         <horstretch>0</horstretch>
-         <verstretch>0</verstretch>
-        </sizepolicy>
-       </property>
-       <property name="text">
-        <string>pbSelectLocalFolder</string>
-       </property>
-      </widget>
-     </item>
      <item row="0" column="1" colspan="2">
       <widget class="QWidget" name="widget" native="true">
        <layout class="QVBoxLayout" name="verticalLayout">
        </layout>
       </widget>
      </item>
+     <item row="2" column="0" rowspan="4">
+      <layout class="QVBoxLayout" name="verticalLayout_3">
+       <item>
+        <widget class="QLabel" name="lLocalIcon">
+         <property name="text">
+          <string>TextLabel</string>
+         </property>
+         <property name="alignment">
+          <set>Qt::AlignCenter</set>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLabel" name="lLocal">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="text">
+          <string>&amp;Local Folder</string>
+         </property>
+         <property name="alignment">
+          <set>Qt::AlignCenter</set>
+         </property>
+         <property name="buddy">
+          <cstring>pbSelectLocalFolder</cstring>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <spacer name="verticalSpacer_4">
+         <property name="orientation">
+          <enum>Qt::Vertical</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>20</width>
+           <height>40</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+      </layout>
+     </item>
+     <item row="2" column="1" rowspan="2">
+      <widget class="QPushButton" name="pbSelectLocalFolder">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="text">
+        <string>pbSelectLocalFolder</string>
+       </property>
+      </widget>
+     </item>
+     <item row="0" column="0">
+      <layout class="QVBoxLayout" name="verticalLayout_2">
+       <item>
+        <widget class="QLabel" name="lServerIcon">
+         <property name="text">
+          <string>TextLabel</string>
+         </property>
+         <property name="alignment">
+          <set>Qt::AlignCenter</set>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLabel" name="lServer">
+         <property name="text">
+          <string>Server</string>
+         </property>
+         <property name="alignment">
+          <set>Qt::AlignCenter</set>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <spacer name="verticalSpacer_3">
+         <property name="orientation">
+          <enum>Qt::Vertical</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>20</width>
+           <height>40</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+      </layout>
+     </item>
+     <item row="5" column="1" colspan="2">
+      <widget class="QWidget" name="resolutionWidget" native="true">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <layout class="QFormLayout" name="formLayout_2">
+        <property name="sizeConstraint">
+         <enum>QLayout::SetMinimumSize</enum>
+        </property>
+        <property name="fieldGrowthPolicy">
+         <enum>QFormLayout::ExpandingFieldsGrow</enum>
+        </property>
+        <item row="1" column="0" colspan="2">
+         <widget class="QRadioButton" name="radioButton">
+          <property name="text">
+           <string>&amp;Keep local data</string>
+          </property>
+          <property name="checked">
+           <bool>true</bool>
+          </property>
+         </widget>
+        </item>
+        <item row="2" column="0" colspan="2">
+         <widget class="QRadioButton" name="cbSyncFromScratch">
+          <property name="toolTip">
+           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If this box is checked, existing content in the local folder will be erased to start a clean sync from the server.&lt;/p&gt;&lt;p&gt;Do not check this if the local content should be uploaded to the servers folder.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+          </property>
+          <property name="text">
+           <string>Start a &amp;clean sync (Erases the local folder!)</string>
+          </property>
+          <property name="checkable">
+           <bool>true</bool>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </widget>
+     </item>
+     <item row="1" column="1">
+      <spacer name="verticalSpacer">
+       <property name="orientation">
+        <enum>Qt::Vertical</enum>
+       </property>
+       <property name="sizeType">
+        <enum>QSizePolicy::MinimumExpanding</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>20</width>
+         <height>40</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item row="4" column="1">
+      <widget class="QLabel" name="lFreeSpace">
+       <property name="text">
+        <string>TextLabel</string>
+       </property>
+      </widget>
+     </item>
     </layout>
    </item>
    <item>