Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wizard: show an error message if there is no enough free space in the local folder #1006

Merged
merged 1 commit into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion src/gui/wizard/owncloudadvancedsetuppage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <QFileDialog>
#include <QUrl>
#include <QTimer>
#include <QStorageInfo>

#include "QProgressIndicator.h"

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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());
}
Expand All @@ -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
4 changes: 4 additions & 0 deletions src/gui/wizard/owncloudadvancedsetuppage.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ private slots:
void startSpinner();
void stopSpinner();
QUrl serverUrl() const;
qint64 availableLocalSpace() const;
QString checkLocalSpace(qint64 remoteSize) const;

Ui_OwncloudAdvancedSetupPage _ui;
bool _checking;
Expand All @@ -73,6 +75,8 @@ private slots:
QProgressIndicator *_progressIndi;
QString _remoteFolder;
QStringList _selectiveSyncBlacklist;
qint64 _rSize;
qint64 _rSelectedSize;
};

} // namespace OCC
Expand Down
Loading