Merge pull request #2692 from nextcloud/fix-issue-1029

Handle the warning message when unchecking folders for syncing.
This commit is contained in:
Camila 2020-12-14 12:54:05 +01:00 committed by GitHub
commit be1fb77488
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 147 additions and 92 deletions

View file

@ -170,6 +170,12 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent)
addAction(syncNowWithRemoteDiscovery); 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->selectiveSyncApply, &QAbstractButton::clicked, _model, &FolderStatusModel::slotApplySelectiveSync);
connect(_ui->selectiveSyncCancel, &QAbstractButton::clicked, _model, &FolderStatusModel::resetFolders); connect(_ui->selectiveSyncCancel, &QAbstractButton::clicked, _model, &FolderStatusModel::resetFolders);
connect(_ui->bigFolderApply, &QAbstractButton::clicked, _model, &FolderStatusModel::slotApplySelectiveSync); connect(_ui->bigFolderApply, &QAbstractButton::clicked, _model, &FolderStatusModel::slotApplySelectiveSync);
@ -214,7 +220,6 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent)
customizeStyle(); customizeStyle();
} }
void AccountSettings::slotNewMnemonicGenerated() void AccountSettings::slotNewMnemonicGenerated()
{ {
_ui->encryptionMessage->setText(tr("This account supports end-to-end encryption")); _ui->encryptionMessage->setText(tr("This account supports end-to-end encryption"));
@ -888,13 +893,71 @@ AccountSettings::~AccountSettings()
delete _ui; delete _ui;
} }
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)
{
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() void AccountSettings::refreshSelectiveSyncStatus()
{ {
bool shouldBeVisible = _model->isDirty() && _accountState->isConnected();
QString msg; QString msg;
int cnt = 0; int cnt = 0;
const auto folders = FolderMan::instance()->map().values(); const auto folders = FolderMan::instance()->map().values();
_ui->bigFolderUi->setVisible(false);
for (Folder *folder : folders) { for (Folder *folder : folders) {
if (folder->accountState() != _accountState) { if (folder->accountState() != _accountState) {
continue; continue;
@ -923,40 +986,16 @@ void AccountSettings::refreshSelectiveSyncStatus()
} }
} }
if (msg.isEmpty()) { if (!msg.isEmpty()) {
_ui->selectiveSyncButtons->setVisible(true);
_ui->bigFolderUi->setVisible(false);
} else {
ConfigFile cfg; ConfigFile cfg;
QString info = !cfg.confirmExternalStorage() QString info = !cfg.confirmExternalStorage()
? tr("There are folders that were not synchronized because they are too big: ") ? tr("There are folders that were not synchronized because they are too big: ")
: !cfg.newBigFolderSizeLimit().first : !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 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 or external storages: ");
_ui->selectiveSyncNotification->setText(info + msg); _ui->selectiveSyncNotification->setText(info + msg);
_ui->selectiveSyncButtons->setVisible(false);
_ui->bigFolderUi->setVisible(true); _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();
}
});
} }
} }

View file

@ -71,8 +71,8 @@ public slots:
void slotUpdateQuota(qint64 total, qint64 used); void slotUpdateQuota(qint64 total, qint64 used);
void slotAccountStateChanged(); void slotAccountStateChanged();
void slotStyleChanged(); void slotStyleChanged();
AccountState *accountsState() { return _accountState; } AccountState *accountsState() { return _accountState; }
void slotHideSelectiveSyncWidget();
protected slots: protected slots:
void slotAddFolder(); void slotAddFolder();
@ -103,6 +103,9 @@ protected slots:
void slotNewMnemonicGenerated(); void slotNewMnemonicGenerated();
void slotEncryptFolderFinished(int status); void slotEncryptFolderFinished(int status);
void slotSelectiveSyncChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
const QVector<int> &roles);
private: private:
void showConnectionLabel(const QString &message, void showConnectionLabel(const QString &message,
QStringList errors = QStringList()); QStringList errors = QStringList());

View file

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>581</width> <width>588</width>
<height>557</height> <height>557</height>
</rect> </rect>
</property> </property>
@ -41,62 +41,6 @@
</property> </property>
</widget> </widget>
</item> </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> </layout>
</item> </item>
<item> <item>
@ -241,6 +185,9 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="1" column="0">
<widget class="KMessageWidget" name="encryptionMessage" native="true"/>
</item>
<item row="3" column="0"> <item row="3" column="0">
<widget class="OCC::FolderStatusView" name="_folderList"> <widget class="OCC::FolderStatusView" name="_folderList">
<property name="sizePolicy"> <property name="sizePolicy">
@ -260,8 +207,74 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="5" column="0">
<widget class="KMessageWidget" name="encryptionMessage" native="true"/> <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> </item>
</layout> </layout>
</widget> </widget>