Merge pull request #5027 from nextcloud/bugfix/modernise-accountsettings-code

Modernise and improve code in AccountSettings
This commit is contained in:
Claudio Cambra 2022-10-29 14:37:29 +02:00 committed by GitHub
commit bbfe9ca411
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -126,11 +126,11 @@ protected:
{ {
if (event->type() == QEvent::HoverMove) { if (event->type() == QEvent::HoverMove) {
Qt::CursorShape shape = Qt::ArrowCursor; Qt::CursorShape shape = Qt::ArrowCursor;
auto pos = folderList->mapFromGlobal(QCursor::pos()); const auto pos = folderList->mapFromGlobal(QCursor::pos());
auto index = folderList->indexAt(pos); const auto index = folderList->indexAt(pos);
if (model->classify(index) == FolderStatusModel::RootFolder if (model->classify(index) == FolderStatusModel::RootFolder &&
&& (FolderStatusDelegate::errorsListRect(folderList->visualRect(index)).contains(pos) (FolderStatusDelegate::errorsListRect(folderList->visualRect(index)).contains(pos) ||
|| FolderStatusDelegate::optionsButtonRect(folderList->visualRect(index),folderList->layoutDirection()).contains(pos))) { FolderStatusDelegate::optionsButtonRect(folderList->visualRect(index),folderList->layoutDirection()).contains(pos))) {
shape = Qt::PointingHandCursor; shape = Qt::PointingHandCursor;
} }
folderList->setCursor(shape); folderList->setCursor(shape);
@ -152,7 +152,7 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent)
_model = new FolderStatusModel; _model = new FolderStatusModel;
_model->setAccountState(_accountState); _model->setAccountState(_accountState);
_model->setParent(this); _model->setParent(this);
auto *delegate = new FolderStatusDelegate; const auto delegate = new FolderStatusDelegate;
delegate->setParent(this); delegate->setParent(this);
// Connect styleChanged events to our widgets, so they can adapt (Dark-/Light-Mode switching) // Connect styleChanged events to our widgets, so they can adapt (Dark-/Light-Mode switching)
@ -168,7 +168,7 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent)
#endif #endif
new ToolTipUpdater(_ui->_folderList); new ToolTipUpdater(_ui->_folderList);
auto mouseCursorChanger = new MouseCursorChanger(this); const auto mouseCursorChanger = new MouseCursorChanger(this);
mouseCursorChanger->folderList = _ui->_folderList; mouseCursorChanger->folderList = _ui->_folderList;
mouseCursorChanger->model = _model; mouseCursorChanger->model = _model;
_ui->_folderList->setMouseTracking(true); _ui->_folderList->setMouseTracking(true);
@ -272,7 +272,7 @@ void AccountSettings::slotEncryptFolderFinished(int status)
const auto folder = job->property(propertyFolder).value<Folder *>(); const auto folder = job->property(propertyFolder).value<Folder *>();
Q_ASSERT(folder); Q_ASSERT(folder);
const auto path = job->property(propertyPath).value<QString>(); const auto path = job->property(propertyPath).toString();
const auto index = _model->indexForPath(folder, path); const auto index = _model->indexForPath(folder, path);
Q_ASSERT(index.isValid()); Q_ASSERT(index.isValid());
_model->resetAndFetch(index.parent()); _model->resetAndFetch(index.parent());
@ -282,9 +282,10 @@ void AccountSettings::slotEncryptFolderFinished(int status)
QString AccountSettings::selectedFolderAlias() const QString AccountSettings::selectedFolderAlias() const
{ {
QModelIndex selected = _ui->_folderList->selectionModel()->currentIndex(); const auto selected = _ui->_folderList->selectionModel()->currentIndex();
if (!selected.isValid()) if (!selected.isValid()) {
return ""; return "";
}
return _model->data(selected, FolderStatusDelegate::FolderAliasRole).toString(); return _model->data(selected, FolderStatusDelegate::FolderAliasRole).toString();
} }
@ -302,11 +303,12 @@ void AccountSettings::doExpand()
{ {
// Make sure at least the root items are expanded // Make sure at least the root items are expanded
for (int i = 0; i < _model->rowCount(); ++i) { for (int i = 0; i < _model->rowCount(); ++i) {
auto idx = _model->index(i); const auto idx = _model->index(i);
if (!_ui->_folderList->isExpanded(idx)) if (!_ui->_folderList->isExpanded(idx)) {
_ui->_folderList->setExpanded(idx, true); _ui->_folderList->setExpanded(idx, true);
} }
} }
}
void AccountSettings::slotShowMnemonic(const QString &mnemonic) void AccountSettings::slotShowMnemonic(const QString &mnemonic)
{ {
@ -366,8 +368,7 @@ void AccountSettings::slotMarkSubfolderEncrypted(FolderStatusModel::SubFolderInf
job->start(); job->start();
}; };
if (folder->virtualFilesEnabled() if (folder->virtualFilesEnabled() && folder->vfs().mode() == Vfs::WindowsCfApi) {
&& folder->vfs().mode() == Vfs::WindowsCfApi) {
showEnableE2eeWithVirtualFilesWarningDialog(encryptFolder); showEnableE2eeWithVirtualFilesWarningDialog(encryptFolder);
return; return;
} }
@ -376,10 +377,11 @@ void AccountSettings::slotMarkSubfolderEncrypted(FolderStatusModel::SubFolderInf
void AccountSettings::slotEditCurrentIgnoredFiles() void AccountSettings::slotEditCurrentIgnoredFiles()
{ {
Folder *f = FolderMan::instance()->folder(selectedFolderAlias()); const auto folder = FolderMan::instance()->folder(selectedFolderAlias());
if (!f) if (!folder) {
return; return;
openIgnoredFilesDialog(f->path()); }
openIgnoredFilesDialog(folder->path());
} }
void AccountSettings::slotOpenMakeFolderDialog() void AccountSettings::slotOpenMakeFolderDialog()
@ -397,7 +399,7 @@ void AccountSettings::slotOpenMakeFolderDialog()
return; return;
} }
const QString fileName = [this, &selected, &classification] { const auto fileName = [this, &selected, &classification] {
QString result; QString result;
if (classification == FolderStatusModel::RootFolder) { if (classification == FolderStatusModel::RootFolder) {
const auto alias = _model->data(selected, FolderStatusDelegate::FolderAliasRole).toString(); const auto alias = _model->data(selected, FolderStatusDelegate::FolderAliasRole).toString();
@ -424,10 +426,11 @@ void AccountSettings::slotOpenMakeFolderDialog()
void AccountSettings::slotEditCurrentLocalIgnoredFiles() void AccountSettings::slotEditCurrentLocalIgnoredFiles()
{ {
QModelIndex selected = _ui->_folderList->selectionModel()->currentIndex(); const auto selected = _ui->_folderList->selectionModel()->currentIndex();
if (!selected.isValid() || _model->classify(selected) != FolderStatusModel::SubFolder) if (!selected.isValid() || _model->classify(selected) != FolderStatusModel::SubFolder) {
return; return;
QString fileName = _model->data(selected, FolderStatusDelegate::FolderPathRole).toString(); }
const auto fileName = _model->data(selected, FolderStatusDelegate::FolderPathRole).toString();
openIgnoredFilesDialog(fileName); openIgnoredFilesDialog(fileName);
} }
@ -435,25 +438,25 @@ void AccountSettings::openIgnoredFilesDialog(const QString & absFolderPath)
{ {
Q_ASSERT(QFileInfo(absFolderPath).isAbsolute()); Q_ASSERT(QFileInfo(absFolderPath).isAbsolute());
const QString ignoreFile = absFolderPath + ".sync-exclude.lst"; const QString ignoreFile{absFolderPath + ".sync-exclude.lst"};
auto layout = new QVBoxLayout(); const auto layout = new QVBoxLayout();
auto ignoreListWidget = new IgnoreListTableWidget(this); const auto ignoreListWidget = new IgnoreListTableWidget(this);
ignoreListWidget->readIgnoreFile(ignoreFile); ignoreListWidget->readIgnoreFile(ignoreFile);
layout->addWidget(ignoreListWidget); layout->addWidget(ignoreListWidget);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); const auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
layout->addWidget(buttonBox); layout->addWidget(buttonBox);
auto dialog = new QDialog(); const auto dialog = new QDialog();
dialog->setLayout(layout); dialog->setLayout(layout);
connect(buttonBox, &QDialogButtonBox::clicked, [=](QAbstractButton * button) { connect(buttonBox, &QDialogButtonBox::clicked, [=](QAbstractButton * button) {
if (buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) if (buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) {
ignoreListWidget->slotWriteIgnoreFile(ignoreFile); ignoreListWidget->slotWriteIgnoreFile(ignoreFile);
}
dialog->close(); dialog->close();
}); });
connect(buttonBox, &QDialogButtonBox::rejected, connect(buttonBox, &QDialogButtonBox::rejected, dialog, &QDialog::close);
dialog, &QDialog::close);
dialog->open(); dialog->open();
} }
@ -466,18 +469,18 @@ void AccountSettings::slotSubfolderContextMenuRequested(const QModelIndex& index
auto ac = menu.addAction(tr("Open folder")); auto ac = menu.addAction(tr("Open folder"));
connect(ac, &QAction::triggered, this, &AccountSettings::slotOpenCurrentLocalSubFolder); connect(ac, &QAction::triggered, this, &AccountSettings::slotOpenCurrentLocalSubFolder);
auto fileName = _model->data(index, FolderStatusDelegate::FolderPathRole).toString(); const auto fileName = _model->data(index, FolderStatusDelegate::FolderPathRole).toString();
if (!QFile::exists(fileName)) { if (!QFile::exists(fileName)) {
ac->setEnabled(false); ac->setEnabled(false);
} }
auto info = _model->infoForIndex(index); const auto info = _model->infoForIndex(index);
auto acc = _accountState->account(); const auto acc = _accountState->account();
if (acc->capabilities().clientSideEncryptionAvailable()) { if (acc->capabilities().clientSideEncryptionAvailable()) {
// Verify if the folder is empty before attempting to encrypt. // Verify if the folder is empty before attempting to encrypt.
bool isEncrypted = info->_isEncrypted; const auto isEncrypted = info->_isEncrypted;
bool isParentEncrypted = _model->isAnyAncestorEncrypted(index); const auto isParentEncrypted = _model->isAnyAncestorEncrypted(index);
if (!isEncrypted && !isParentEncrypted) { if (!isEncrypted && !isParentEncrypted) {
ac = menu.addAction(tr("Encrypt")); ac = menu.addAction(tr("Encrypt"));
@ -525,8 +528,8 @@ void AccountSettings::slotSubfolderContextMenuRequested(const QModelIndex& index
void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos) void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
{ {
QTreeView *tv = _ui->_folderList; const auto treeView = _ui->_folderList;
QModelIndex index = tv->indexAt(pos); const auto index = treeView->indexAt(pos);
if (!index.isValid()) { if (!index.isValid()) {
return; return;
} }
@ -540,20 +543,22 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
return; return;
} }
tv->setCurrentIndex(index); treeView->setCurrentIndex(index);
QString alias = _model->data(index, FolderStatusDelegate::FolderAliasRole).toString(); const auto alias = _model->data(index, FolderStatusDelegate::FolderAliasRole).toString();
bool folderPaused = _model->data(index, FolderStatusDelegate::FolderSyncPaused).toBool(); const auto folderPaused = _model->data(index, FolderStatusDelegate::FolderSyncPaused).toBool();
bool folderConnected = _model->data(index, FolderStatusDelegate::FolderAccountConnected).toBool(); const auto folderConnected = _model->data(index, FolderStatusDelegate::FolderAccountConnected).toBool();
auto folderMan = FolderMan::instance(); const auto folderMan = FolderMan::instance();
QPointer<Folder> folder = folderMan->folder(alias); const auto folder = folderMan->folder(alias);
if (!folder)
return;
auto *menu = new QMenu(tv); if (!folder) {
return;
}
const auto menu = new QMenu(treeView);
menu->setAttribute(Qt::WA_DeleteOnClose); menu->setAttribute(Qt::WA_DeleteOnClose);
QAction *ac = menu->addAction(tr("Open folder")); auto ac = menu->addAction(tr("Open folder"));
connect(ac, &QAction::triggered, this, &AccountSettings::slotOpenCurrentFolder); connect(ac, &QAction::triggered, this, &AccountSettings::slotOpenCurrentFolder);
ac = menu->addAction(tr("Edit Ignored Files")); ac = menu->addAction(tr("Edit Ignored Files"));
@ -599,8 +604,7 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
ac->setDisabled(Theme::instance()->enforceVirtualFilesSyncFolder()); ac->setDisabled(Theme::instance()->enforceVirtualFilesSyncFolder());
} }
if (Theme::instance()->showVirtualFilesOption() if (Theme::instance()->showVirtualFilesOption() && !folder->virtualFilesEnabled() && Vfs::checkAvailability(folder->path())) {
&& !folder->virtualFilesEnabled() && Vfs::checkAvailability(folder->path())) {
const auto mode = bestAvailableVfsMode(); const auto mode = bestAvailableVfsMode();
if (mode == Vfs::WindowsCfApi || ConfigFile().showExperimentalOptions()) { if (mode == Vfs::WindowsCfApi || ConfigFile().showExperimentalOptions()) {
ac = menu->addAction(tr("Enable virtual file support %1 …").arg(mode == Vfs::WindowsCfApi ? QString() : tr("(experimental)"))); ac = menu->addAction(tr("Enable virtual file support %1 …").arg(mode == Vfs::WindowsCfApi ? QString() : tr("(experimental)")));
@ -612,22 +616,23 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
} }
menu->popup(tv->mapToGlobal(pos)); menu->popup(treeView->mapToGlobal(pos));
} }
void AccountSettings::slotFolderListClicked(const QModelIndex &indx) void AccountSettings::slotFolderListClicked(const QModelIndex &indx)
{ {
if (indx.data(FolderStatusDelegate::AddButton).toBool()) { if (indx.data(FolderStatusDelegate::AddButton).toBool()) {
// "Add Folder Sync Connection" // "Add Folder Sync Connection"
QTreeView *tv = _ui->_folderList; const auto treeView = _ui->_folderList;
auto pos = tv->mapFromGlobal(QCursor::pos()); const auto pos = treeView->mapFromGlobal(QCursor::pos());
QStyleOptionViewItem opt; QStyleOptionViewItem opt;
opt.initFrom(tv); opt.initFrom(treeView);
auto btnRect = tv->visualRect(indx); const auto btnRect = treeView->visualRect(indx);
auto btnSize = tv->itemDelegate(indx)->sizeHint(opt, indx); const auto btnSize = treeView->itemDelegate(indx)->sizeHint(opt, indx);
auto actual = QStyle::visualRect(opt.direction, btnRect, QRect(btnRect.topLeft(), btnSize)); const auto actual = QStyle::visualRect(opt.direction, btnRect, QRect(btnRect.topLeft(), btnSize));
if (!actual.contains(pos)) if (!actual.contains(pos)) {
return; return;
}
if (indx.flags() & Qt::ItemIsEnabled) { if (indx.flags() & Qt::ItemIsEnabled) {
slotAddFolder(); slotAddFolder();
@ -641,20 +646,20 @@ void AccountSettings::slotFolderListClicked(const QModelIndex &indx)
} }
if (_model->classify(indx) == FolderStatusModel::RootFolder) { if (_model->classify(indx) == FolderStatusModel::RootFolder) {
// tries to find if we clicked on the '...' button. // tries to find if we clicked on the '...' button.
QTreeView *tv = _ui->_folderList; const auto treeView = _ui->_folderList;
auto pos = tv->mapFromGlobal(QCursor::pos()); const auto pos = treeView->mapFromGlobal(QCursor::pos());
if (FolderStatusDelegate::optionsButtonRect(tv->visualRect(indx), layoutDirection()).contains(pos)) { if (FolderStatusDelegate::optionsButtonRect(treeView->visualRect(indx), layoutDirection()).contains(pos)) {
slotCustomContextMenuRequested(pos); slotCustomContextMenuRequested(pos);
return; return;
} }
if (FolderStatusDelegate::errorsListRect(tv->visualRect(indx)).contains(pos)) { if (FolderStatusDelegate::errorsListRect(treeView->visualRect(indx)).contains(pos)) {
emit showIssuesList(_accountState); emit showIssuesList(_accountState);
return; return;
} }
// Expand root items on single click // Expand root items on single click
if (_accountState && _accountState->state() == AccountState::Connected) { if (_accountState && _accountState->state() == AccountState::Connected) {
bool expanded = !(_ui->_folderList->isExpanded(indx)); const auto expanded = !(_ui->_folderList->isExpanded(indx));
_ui->_folderList->setExpanded(indx, expanded); _ui->_folderList->setExpanded(indx, expanded);
} }
} }
@ -662,10 +667,10 @@ void AccountSettings::slotFolderListClicked(const QModelIndex &indx)
void AccountSettings::slotAddFolder() void AccountSettings::slotAddFolder()
{ {
FolderMan *folderMan = FolderMan::instance(); const auto folderMan = FolderMan::instance();
folderMan->setSyncEnabled(false); // do not start more syncs. folderMan->setSyncEnabled(false); // do not start more syncs.
auto *folderWizard = new FolderWizard(_accountState->account(), this); const auto folderWizard = new FolderWizard(_accountState->account(), this);
folderWizard->setAttribute(Qt::WA_DeleteOnClose); folderWizard->setAttribute(Qt::WA_DeleteOnClose);
connect(folderWizard, &QDialog::accepted, this, &AccountSettings::slotFolderWizardAccepted); connect(folderWizard, &QDialog::accepted, this, &AccountSettings::slotFolderWizardAccepted);
@ -676,8 +681,8 @@ void AccountSettings::slotAddFolder()
void AccountSettings::slotFolderWizardAccepted() void AccountSettings::slotFolderWizardAccepted()
{ {
auto *folderWizard = qobject_cast<FolderWizard *>(sender()); const auto folderWizard = qobject_cast<FolderWizard *>(sender());
FolderMan *folderMan = FolderMan::instance(); const auto folderMan = FolderMan::instance();
qCInfo(lcAccountSettings) << "Folder wizard completed"; qCInfo(lcAccountSettings) << "Folder wizard completed";
@ -712,22 +717,24 @@ void AccountSettings::slotFolderWizardAccepted()
*/ */
definition.ignoreHiddenFiles = folderMan->ignoreHiddenFiles(); definition.ignoreHiddenFiles = folderMan->ignoreHiddenFiles();
if (folderMan->navigationPaneHelper().showInExplorerNavigationPane()) if (folderMan->navigationPaneHelper().showInExplorerNavigationPane()) {
definition.navigationPaneClsid = QUuid::createUuid(); definition.navigationPaneClsid = QUuid::createUuid();
}
auto selectiveSyncBlackList = folderWizard->property("selectiveSyncBlackList").toStringList(); const auto selectiveSyncBlackList = folderWizard->property("selectiveSyncBlackList").toStringList();
folderMan->setSyncEnabled(true); folderMan->setSyncEnabled(true);
Folder *f = folderMan->addFolder(_accountState, definition); const auto folder = folderMan->addFolder(_accountState, definition);
if (f) { if (folder) {
if (definition.virtualFilesMode != Vfs::Off && folderWizard->property("useVirtualFiles").toBool()) if (definition.virtualFilesMode != Vfs::Off && folderWizard->property("useVirtualFiles").toBool()) {
f->setRootPinState(PinState::OnlineOnly); folder->setRootPinState(PinState::OnlineOnly);
}
f->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, selectiveSyncBlackList); folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, selectiveSyncBlackList);
// The user already accepted the selective sync dialog. everything is in the white list // The user already accepted the selective sync dialog. everything is in the white list
f->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList, folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList,
QStringList() << QLatin1String("/")); QStringList() << QLatin1String("/"));
folderMan->scheduleAllFolders(); folderMan->scheduleAllFolders();
emit folderChanged(); emit folderChanged();
@ -737,19 +744,19 @@ void AccountSettings::slotFolderWizardAccepted()
void AccountSettings::slotFolderWizardRejected() void AccountSettings::slotFolderWizardRejected()
{ {
qCInfo(lcAccountSettings) << "Folder wizard cancelled"; qCInfo(lcAccountSettings) << "Folder wizard cancelled";
FolderMan *folderMan = FolderMan::instance(); const auto folderMan = FolderMan::instance();
folderMan->setSyncEnabled(true); folderMan->setSyncEnabled(true);
} }
void AccountSettings::slotRemoveCurrentFolder() void AccountSettings::slotRemoveCurrentFolder()
{ {
auto folder = FolderMan::instance()->folder(selectedFolderAlias()); const auto folder = FolderMan::instance()->folder(selectedFolderAlias());
QModelIndex selected = _ui->_folderList->selectionModel()->currentIndex(); const auto selected = _ui->_folderList->selectionModel()->currentIndex();
if (selected.isValid() && folder) { if (selected.isValid() && folder) {
int row = selected.row(); const auto row = selected.row();
qCInfo(lcAccountSettings) << "Remove Folder alias " << folder->alias(); qCInfo(lcAccountSettings) << "Remove Folder alias " << folder->alias();
QString shortGuiLocalPath = folder->shortGuiLocalPath(); const auto shortGuiLocalPath = folder->shortGuiLocalPath();
auto messageBox = new QMessageBox(QMessageBox::Question, auto messageBox = new QMessageBox(QMessageBox::Question,
tr("Confirm Folder Sync Connection Removal"), tr("Confirm Folder Sync Connection Removal"),
@ -759,8 +766,7 @@ void AccountSettings::slotRemoveCurrentFolder()
QMessageBox::NoButton, QMessageBox::NoButton,
this); this);
messageBox->setAttribute(Qt::WA_DeleteOnClose); messageBox->setAttribute(Qt::WA_DeleteOnClose);
QPushButton *yesButton = const auto yesButton = messageBox->addButton(tr("Remove Folder Sync Connection"), QMessageBox::YesRole);
messageBox->addButton(tr("Remove Folder Sync Connection"), QMessageBox::YesRole);
messageBox->addButton(tr("Cancel"), QMessageBox::NoRole); messageBox->addButton(tr("Cancel"), QMessageBox::NoRole);
connect(messageBox, &QMessageBox::finished, this, [messageBox, yesButton, folder, row, this]{ connect(messageBox, &QMessageBox::finished, this, [messageBox, yesButton, folder, row, this]{
if (messageBox->clickedButton() == yesButton) { if (messageBox->clickedButton() == yesButton) {
@ -778,7 +784,7 @@ void AccountSettings::slotRemoveCurrentFolder()
void AccountSettings::slotOpenCurrentFolder() void AccountSettings::slotOpenCurrentFolder()
{ {
auto alias = selectedFolderAlias(); const auto alias = selectedFolderAlias();
if (!alias.isEmpty()) { if (!alias.isEmpty()) {
emit openFolderAlias(alias); emit openFolderAlias(alias);
} }
@ -786,39 +792,44 @@ void AccountSettings::slotOpenCurrentFolder()
void AccountSettings::slotOpenCurrentLocalSubFolder() void AccountSettings::slotOpenCurrentLocalSubFolder()
{ {
QModelIndex selected = _ui->_folderList->selectionModel()->currentIndex(); const auto selected = _ui->_folderList->selectionModel()->currentIndex();
if (!selected.isValid() || _model->classify(selected) != FolderStatusModel::SubFolder) if (!selected.isValid() || _model->classify(selected) != FolderStatusModel::SubFolder) {
return; return;
QString fileName = _model->data(selected, FolderStatusDelegate::FolderPathRole).toString(); }
QUrl url = QUrl::fromLocalFile(fileName); const auto fileName = _model->data(selected, FolderStatusDelegate::FolderPathRole).toString();
const auto url = QUrl::fromLocalFile(fileName);
QDesktopServices::openUrl(url); QDesktopServices::openUrl(url);
} }
void AccountSettings::slotEnableVfsCurrentFolder() void AccountSettings::slotEnableVfsCurrentFolder()
{ {
FolderMan *folderMan = FolderMan::instance(); const auto folderMan = FolderMan::instance();
QPointer<Folder> folder = folderMan->folder(selectedFolderAlias()); const auto folder = folderMan->folder(selectedFolderAlias());
QModelIndex selected = _ui->_folderList->selectionModel()->currentIndex(); const auto selected = _ui->_folderList->selectionModel()->currentIndex();
if (!selected.isValid() || !folder)
if (!selected.isValid() || !folder) {
return; return;
}
OwncloudWizard::askExperimentalVirtualFilesFeature(this, [folder, this](bool enable) { OwncloudWizard::askExperimentalVirtualFilesFeature(this, [folder, this](bool enable) {
if (!enable || !folder) if (!enable || !folder) {
return; return;
}
// we might need to add or remove the panel entry as cfapi brings this feature out of the box // we might need to add or remove the panel entry as cfapi brings this feature out of the box
FolderMan::instance()->navigationPaneHelper().scheduleUpdateCloudStorageRegistry(); FolderMan::instance()->navigationPaneHelper().scheduleUpdateCloudStorageRegistry();
// It is unsafe to switch on vfs while a sync is running - wait if necessary. // It is unsafe to switch on vfs while a sync is running - wait if necessary.
auto connection = std::make_shared<QMetaObject::Connection>(); const auto connection = std::make_shared<QMetaObject::Connection>();
auto switchVfsOn = [folder, connection, this]() { const auto switchVfsOn = [folder, connection, this]() {
if (*connection) if (*connection) {
QObject::disconnect(*connection); QObject::disconnect(*connection);
}
qCInfo(lcAccountSettings) << "Enabling vfs support for folder" << folder->path(); qCInfo(lcAccountSettings) << "Enabling vfs support for folder" << folder->path();
// Wipe selective sync blacklist // Wipe selective sync blacklist
bool ok = false; auto ok = false;
const auto oldBlacklist = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, &ok); const auto oldBlacklist = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, &ok);
folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, {}); folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, {});
@ -856,13 +867,15 @@ void AccountSettings::slotEnableVfsCurrentFolder()
void AccountSettings::slotDisableVfsCurrentFolder() void AccountSettings::slotDisableVfsCurrentFolder()
{ {
FolderMan *folderMan = FolderMan::instance(); const auto folderMan = FolderMan::instance();
QPointer<Folder> folder = folderMan->folder(selectedFolderAlias()); const auto folder = folderMan->folder(selectedFolderAlias());
QModelIndex selected = _ui->_folderList->selectionModel()->currentIndex(); const auto selected = _ui->_folderList->selectionModel()->currentIndex();
if (!selected.isValid() || !folder)
return;
auto msgBox = new QMessageBox( if (!selected.isValid() || !folder) {
return;
}
const auto msgBox = new QMessageBox(
QMessageBox::Question, QMessageBox::Question,
tr("Disable virtual file support?"), tr("Disable virtual file support?"),
tr("This action will disable virtual file support. As a consequence contents of folders that " tr("This action will disable virtual file support. As a consequence contents of folders that "
@ -872,21 +885,23 @@ void AccountSettings::slotDisableVfsCurrentFolder()
"will become available again." "will become available again."
"\n\n" "\n\n"
"This action will abort any currently running synchronization.")); "This action will abort any currently running synchronization."));
auto acceptButton = msgBox->addButton(tr("Disable support"), QMessageBox::AcceptRole); const auto acceptButton = msgBox->addButton(tr("Disable support"), QMessageBox::AcceptRole);
msgBox->addButton(tr("Cancel"), QMessageBox::RejectRole); msgBox->addButton(tr("Cancel"), QMessageBox::RejectRole);
connect(msgBox, &QMessageBox::finished, msgBox, [this, msgBox, folder, acceptButton] { connect(msgBox, &QMessageBox::finished, msgBox, [this, msgBox, folder, acceptButton] {
msgBox->deleteLater(); msgBox->deleteLater();
if (msgBox->clickedButton() != acceptButton|| !folder) if (msgBox->clickedButton() != acceptButton|| !folder) {
return; return;
}
// we might need to add or remove the panel entry as cfapi brings this feature out of the box // we might need to add or remove the panel entry as cfapi brings this feature out of the box
FolderMan::instance()->navigationPaneHelper().scheduleUpdateCloudStorageRegistry(); FolderMan::instance()->navigationPaneHelper().scheduleUpdateCloudStorageRegistry();
// It is unsafe to switch off vfs while a sync is running - wait if necessary. // It is unsafe to switch off vfs while a sync is running - wait if necessary.
auto connection = std::make_shared<QMetaObject::Connection>(); const auto connection = std::make_shared<QMetaObject::Connection>();
auto switchVfsOff = [folder, connection, this]() { const auto switchVfsOff = [folder, connection, this]() {
if (*connection) if (*connection) {
QObject::disconnect(*connection); QObject::disconnect(*connection);
}
qCInfo(lcAccountSettings) << "Disabling vfs support for folder" << folder->path(); qCInfo(lcAccountSettings) << "Disabling vfs support for folder" << folder->path();
@ -922,11 +937,13 @@ void AccountSettings::slotSetCurrentFolderAvailability(PinState state)
{ {
ASSERT(state == PinState::OnlineOnly || state == PinState::AlwaysLocal); ASSERT(state == PinState::OnlineOnly || state == PinState::AlwaysLocal);
FolderMan *folderMan = FolderMan::instance(); const auto folderMan = FolderMan::instance();
QPointer<Folder> folder = folderMan->folder(selectedFolderAlias()); const auto folder = folderMan->folder(selectedFolderAlias());
QModelIndex selected = _ui->_folderList->selectionModel()->currentIndex(); const auto selected = _ui->_folderList->selectionModel()->currentIndex();
if (!selected.isValid() || !folder)
if (!selected.isValid() || !folder) {
return; return;
}
// similar to socket api: sets pin state recursively and sync // similar to socket api: sets pin state recursively and sync
folder->setRootPinState(state); folder->setRootPinState(state);
@ -950,22 +967,22 @@ void AccountSettings::slotSetSubFolderAvailability(Folder *folder, const QString
void AccountSettings::showConnectionLabel(const QString &message, QStringList errors) void AccountSettings::showConnectionLabel(const QString &message, QStringList errors)
{ {
const QString errStyle = QLatin1String("color:#ffffff; background-color:#bb4d4d;padding:5px;" const auto errStyle = QLatin1String("color:#ffffff; background-color:#bb4d4d;padding:5px;"
"border-width: 1px; border-style: solid; border-color: #aaaaaa;" "border-width: 1px; border-style: solid; border-color: #aaaaaa;"
"border-radius:5px;"); "border-radius:5px;");
if (errors.isEmpty()) { if (errors.isEmpty()) {
QString msg = message; auto msg = message;
Theme::replaceLinkColorStringBackgroundAware(msg); Theme::replaceLinkColorStringBackgroundAware(msg);
_ui->connectLabel->setText(msg); _ui->connectLabel->setText(msg);
_ui->connectLabel->setToolTip(QString()); _ui->connectLabel->setToolTip({});
_ui->connectLabel->setStyleSheet(QString()); _ui->connectLabel->setStyleSheet({});
} else { } else {
errors.prepend(message); errors.prepend(message);
QString msg = errors.join(QLatin1String("\n")); auto msg = errors.join(QLatin1String("\n"));
qCDebug(lcAccountSettings) << msg; qCDebug(lcAccountSettings) << msg;
Theme::replaceLinkColorString(msg, QColor("#c1c8e6")); Theme::replaceLinkColorString(msg, QColor("#c1c8e6"));
_ui->connectLabel->setText(msg); _ui->connectLabel->setText(msg);
_ui->connectLabel->setToolTip(QString()); _ui->connectLabel->setToolTip({});
_ui->connectLabel->setStyleSheet(errStyle); _ui->connectLabel->setStyleSheet(errStyle);
} }
_ui->accountStatus->setVisible(!message.isEmpty()); _ui->accountStatus->setVisible(!message.isEmpty());
@ -973,24 +990,24 @@ void AccountSettings::showConnectionLabel(const QString &message, QStringList er
void AccountSettings::slotEnableCurrentFolder(bool terminate) void AccountSettings::slotEnableCurrentFolder(bool terminate)
{ {
auto alias = selectedFolderAlias(); const auto alias = selectedFolderAlias();
if (!alias.isEmpty()) { if (!alias.isEmpty()) {
FolderMan *folderMan = FolderMan::instance(); const auto folderMan = FolderMan::instance();
qCInfo(lcAccountSettings) << "Application: enable folder with alias " << alias; qCInfo(lcAccountSettings) << "Application: enable folder with alias " << alias;
bool currentlyPaused = false; auto currentlyPaused = false;
// this sets the folder status to disabled but does not interrupt it. // this sets the folder status to disabled but does not interrupt it.
Folder *f = folderMan->folder(alias); const auto folder = folderMan->folder(alias);
if (!f) { if (!folder) {
return; return;
} }
currentlyPaused = f->syncPaused(); currentlyPaused = folder->syncPaused();
if (!currentlyPaused && !terminate) { if (!currentlyPaused && !terminate) {
// check if a sync is still running and if so, ask if we should terminate. // check if a sync is still running and if so, ask if we should terminate.
if (f->isBusy()) { // its still running if (folder->isBusy()) { // its still running
auto msgbox = new QMessageBox(QMessageBox::Question, tr("Sync Running"), const auto msgbox = new QMessageBox(QMessageBox::Question, tr("Sync Running"),
tr("The syncing operation is running.<br/>Do you want to terminate it?"), tr("The syncing operation is running.<br/>Do you want to terminate it?"),
QMessageBox::Yes | QMessageBox::No, this); QMessageBox::Yes | QMessageBox::No, this);
msgbox->setAttribute(Qt::WA_DeleteOnClose); msgbox->setAttribute(Qt::WA_DeleteOnClose);
@ -1005,22 +1022,23 @@ void AccountSettings::slotEnableCurrentFolder(bool terminate)
// message box can return at any time while the thread keeps running, // message box can return at any time while the thread keeps running,
// so better check again after the user has responded. // so better check again after the user has responded.
if (f->isBusy() && terminate) { if (folder->isBusy() && terminate) {
f->slotTerminateSync(); folder->slotTerminateSync();
} }
f->setSyncPaused(!currentlyPaused); folder->setSyncPaused(!currentlyPaused);
// keep state for the icon setting. // keep state for the icon setting.
if (currentlyPaused) if (currentlyPaused) {
_wasDisabledBefore = true; _wasDisabledBefore = true;
}
_model->slotUpdateFolderState(f); _model->slotUpdateFolderState(folder);
} }
} }
void AccountSettings::slotScheduleCurrentFolder() void AccountSettings::slotScheduleCurrentFolder()
{ {
FolderMan *folderMan = FolderMan::instance(); const auto folderMan = FolderMan::instance();
if (auto folder = folderMan->folder(selectedFolderAlias())) { if (auto folder = folderMan->folder(selectedFolderAlias())) {
folderMan->scheduleFolder(folder); folderMan->scheduleFolder(folder);
} }
@ -1028,7 +1046,7 @@ void AccountSettings::slotScheduleCurrentFolder()
void AccountSettings::slotScheduleCurrentFolderForceRemoteDiscovery() void AccountSettings::slotScheduleCurrentFolderForceRemoteDiscovery()
{ {
FolderMan *folderMan = FolderMan::instance(); const auto folderMan = FolderMan::instance();
if (auto folder = folderMan->folder(selectedFolderAlias())) { if (auto folder = folderMan->folder(selectedFolderAlias())) {
folder->slotWipeErrorBlacklist(); folder->slotWipeErrorBlacklist();
folder->journalDb()->forceRemoteDiscoveryNextSync(); folder->journalDb()->forceRemoteDiscoveryNextSync();
@ -1056,25 +1074,25 @@ void AccountSettings::slotUpdateQuota(qint64 total, qint64 used)
_ui->quotaProgressBar->setVisible(true); _ui->quotaProgressBar->setVisible(true);
_ui->quotaProgressBar->setEnabled(true); _ui->quotaProgressBar->setEnabled(true);
// workaround the label only accepting ints (which may be only 32 bit wide) // workaround the label only accepting ints (which may be only 32 bit wide)
const double percent = used / (double)total * 100; const auto percent = used / (double)total * 100;
const int percentInt = qMin(qRound(percent), 100); const auto percentInt = qMin(qRound(percent), 100);
_ui->quotaProgressBar->setValue(percentInt); _ui->quotaProgressBar->setValue(percentInt);
QString usedStr = Utility::octetsToString(used); const auto usedStr = Utility::octetsToString(used);
QString totalStr = Utility::octetsToString(total); const auto totalStr = Utility::octetsToString(total);
QString percentStr = Utility::compactFormatDouble(percent, 1); const auto percentStr = Utility::compactFormatDouble(percent, 1);
QString toolTip = tr("%1 (%3%) of %2 in use. Some folders, including network mounted or shared folders, might have different limits.").arg(usedStr, totalStr, percentStr); const auto toolTip = tr("%1 (%3%) of %2 in use. Some folders, including network mounted or shared folders, might have different limits.").arg(usedStr, totalStr, percentStr);
_ui->quotaInfoLabel->setText(tr("%1 of %2 in use").arg(usedStr, totalStr)); _ui->quotaInfoLabel->setText(tr("%1 of %2 in use").arg(usedStr, totalStr));
_ui->quotaInfoLabel->setToolTip(toolTip); _ui->quotaInfoLabel->setToolTip(toolTip);
_ui->quotaProgressBar->setToolTip(toolTip); _ui->quotaProgressBar->setToolTip(toolTip);
} else { } else {
_ui->quotaProgressBar->setVisible(false); _ui->quotaProgressBar->setVisible(false);
_ui->quotaInfoLabel->setToolTip(QString()); _ui->quotaInfoLabel->setToolTip({});
/* -1 means not computed; -2 means unknown; -3 means unlimited (#owncloud/client/issues/3940)*/ /* -1 means not computed; -2 means unknown; -3 means unlimited (#owncloud/client/issues/3940)*/
if (total == 0 || total == -1) { if (total == 0 || total == -1) {
_ui->quotaInfoLabel->setText(tr("Currently there is no storage usage information available.")); _ui->quotaInfoLabel->setText(tr("Currently there is no storage usage information available."));
} else { } else {
QString usedStr = Utility::octetsToString(used); const auto usedStr = Utility::octetsToString(used);
_ui->quotaInfoLabel->setText(tr("%1 in use").arg(usedStr)); _ui->quotaInfoLabel->setText(tr("%1 in use").arg(usedStr));
} }
} }
@ -1082,23 +1100,23 @@ void AccountSettings::slotUpdateQuota(qint64 total, qint64 used)
void AccountSettings::slotAccountStateChanged() void AccountSettings::slotAccountStateChanged()
{ {
const AccountState::State state = _accountState ? _accountState->state() : AccountState::Disconnected; const auto state = _accountState ? _accountState->state() : AccountState::Disconnected;
if (state != AccountState::Disconnected) { if (state != AccountState::Disconnected) {
_ui->sslButton->updateAccountState(_accountState); _ui->sslButton->updateAccountState(_accountState);
AccountPtr account = _accountState->account(); const auto account = _accountState->account();
QUrl safeUrl(account->url()); auto safeUrl = account->url();
safeUrl.setPassword(QString()); // Remove the password from the URL to avoid showing it in the UI safeUrl.setPassword({}); // Remove the password from the URL to avoid showing it in the UI
const auto folders = FolderMan::instance()->map().values(); const auto folders = FolderMan::instance()->map().values();
for (Folder *folder : folders) { for (const auto folder : folders) {
_model->slotUpdateFolderState(folder); _model->slotUpdateFolderState(folder);
} }
const QString server = QString::fromLatin1("<a href=\"%1\">%2</a>") const auto server = QString::fromLatin1("<a href=\"%1\">%2</a>")
.arg(Utility::escape(account->url().toString()), .arg(Utility::escape(account->url().toString()),
Utility::escape(safeUrl.toString())); Utility::escape(safeUrl.toString()));
QString serverWithUser = server; auto serverWithUser = server;
if (AbstractCredentials *cred = account->credentials()) { if (const auto cred = account->credentials()) {
QString user = account->davDisplayName(); auto user = account->davDisplayName();
if (user.isEmpty()) { if (user.isEmpty()) {
user = cred->user(); user = cred->user();
} }
@ -1125,7 +1143,7 @@ void AccountSettings::slotAccountStateChanged()
break; break;
case AccountState::AskingCredentials: { case AccountState::AskingCredentials: {
QUrl url; QUrl url;
if (auto cred = qobject_cast<HttpCredentialsGui *>(account->credentials())) { if (const auto cred = qobject_cast<HttpCredentialsGui *>(account->credentials())) {
connect(cred, &HttpCredentialsGui::authorisationLinkChanged, connect(cred, &HttpCredentialsGui::authorisationLinkChanged,
this, &AccountSettings::slotAccountStateChanged, Qt::UniqueConnection); this, &AccountSettings::slotAccountStateChanged, Qt::UniqueConnection);
url = cred->authorisationLink(); url = cred->authorisationLink();
@ -1165,11 +1183,11 @@ void AccountSettings::slotAccountStateChanged()
if (state != AccountState::Connected) { if (state != AccountState::Connected) {
/* check if there are expanded root items, if so, close them */ /* check if there are expanded root items, if so, close them */
int i = 0; for (auto i = 0; i < _model->rowCount(); ++i) {
for (i = 0; i < _model->rowCount(); ++i) { if (_ui->_folderList->isExpanded(_model->index(i))) {
if (_ui->_folderList->isExpanded(_model->index(i)))
_ui->_folderList->setExpanded(_model->index(i), false); _ui->_folderList->setExpanded(_model->index(i), false);
} }
}
} else if (_model->isDirty()) { } else if (_model->isDirty()) {
// If we connect and have pending changes, show the list. // If we connect and have pending changes, show the list.
doExpand(); doExpand();
@ -1197,21 +1215,22 @@ void AccountSettings::slotLinkActivated(const QString &link)
{ {
// Parse folder alias and filename from the link, calculate the index // Parse folder alias and filename from the link, calculate the index
// and select it if it exists. // and select it if it exists.
const QStringList li = link.split(QLatin1String("?folder=")); const auto li = link.split(QLatin1String("?folder="));
if (li.count() > 1) { if (li.count() > 1) {
QString myFolder = li[0]; auto myFolder = li[0];
const QString alias = li[1]; const auto alias = li[1];
if (myFolder.endsWith(QLatin1Char('/'))) if (myFolder.endsWith(QLatin1Char('/'))) {
myFolder.chop(1); myFolder.chop(1);
}
// Make sure the folder itself is expanded // Make sure the folder itself is expanded
Folder *f = FolderMan::instance()->folder(alias); const auto folder = FolderMan::instance()->folder(alias);
QModelIndex folderIndx = _model->indexForPath(f, QString()); const auto folderIndx = _model->indexForPath(folder, {});
if (!_ui->_folderList->isExpanded(folderIndx)) { if (!_ui->_folderList->isExpanded(folderIndx)) {
_ui->_folderList->setExpanded(folderIndx, true); _ui->_folderList->setExpanded(folderIndx, true);
} }
QModelIndex indx = _model->indexForPath(f, myFolder); const auto indx = _model->indexForPath(folder, myFolder);
if (indx.isValid()) { if (indx.isValid()) {
// make sure all the parents are expanded // make sure all the parents are expanded
for (auto i = indx.parent(); i.isValid(); i = i.parent()) { for (auto i = indx.parent(); i.isValid(); i = i.parent()) {
@ -1255,7 +1274,7 @@ void AccountSettings::slotSelectiveSyncChanged(const QModelIndex &topLeft,
return; return;
} }
const bool showWarning = _model->isDirty() && _accountState->isConnected() && info->_checked == Qt::Unchecked; const auto showWarning = _model->isDirty() && _accountState->isConnected() && info->_checked == Qt::Unchecked;
// FIXME: the model is not precise enough to handle extra cases // 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. // e.g. the user clicked on the same checkbox 2x without applying the change in between.
@ -1264,8 +1283,8 @@ void AccountSettings::slotSelectiveSyncChanged(const QModelIndex &topLeft,
_ui->selectiveSyncLabel->show(); _ui->selectiveSyncLabel->show();
} }
const bool shouldBeVisible = _model->isDirty(); const auto shouldBeVisible = _model->isDirty();
const bool wasVisible = _ui->selectiveSyncStatus->isVisible(); const auto wasVisible = _ui->selectiveSyncStatus->isVisible();
if (shouldBeVisible) { if (shouldBeVisible) {
_ui->selectiveSyncStatus->setVisible(true); _ui->selectiveSyncStatus->setVisible(true);
} }
@ -1295,15 +1314,15 @@ void AccountSettings::slotSelectiveSyncChanged(const QModelIndex &topLeft,
void AccountSettings::refreshSelectiveSyncStatus() void AccountSettings::refreshSelectiveSyncStatus()
{ {
QString msg; QString msg;
int cnt = 0; auto cnt = 0;
const auto folders = FolderMan::instance()->map().values(); const auto folders = FolderMan::instance()->map().values();
_ui->bigFolderUi->setVisible(false); _ui->bigFolderUi->setVisible(false);
for (Folder *folder : folders) { for (const auto folder : folders) {
if (folder->accountState() != _accountState) { if (folder->accountState() != _accountState) {
continue; continue;
} }
bool ok = false; auto ok = false;
const auto undecidedList = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncUndecidedList, &ok); const auto undecidedList = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncUndecidedList, &ok);
for (const auto &it : undecidedList) { for (const auto &it : undecidedList) {
// FIXME: add the folder alias in a hoover hint. // FIXME: add the folder alias in a hoover hint.
@ -1311,11 +1330,11 @@ void AccountSettings::refreshSelectiveSyncStatus()
if (cnt++) { if (cnt++) {
msg += QLatin1String(", "); msg += QLatin1String(", ");
} }
QString myFolder = (it); auto myFolder = (it);
if (myFolder.endsWith('/')) { if (myFolder.endsWith('/')) {
myFolder.chop(1); myFolder.chop(1);
} }
QModelIndex theIndx = _model->indexForPath(folder, myFolder); const auto theIndx = _model->indexForPath(folder, myFolder);
if (theIndx.isValid()) { if (theIndx.isValid()) {
msg += QString::fromLatin1("<a href=\"%1?folder=%2\">%1</a>") msg += QString::fromLatin1("<a href=\"%1?folder=%2\">%1</a>")
.arg(Utility::escape(myFolder), Utility::escape(folder->alias())); .arg(Utility::escape(myFolder), Utility::escape(folder->alias()));
@ -1327,11 +1346,11 @@ void AccountSettings::refreshSelectiveSyncStatus()
if (!msg.isEmpty()) { if (!msg.isEmpty()) {
ConfigFile cfg; ConfigFile cfg;
QString info = !cfg.confirmExternalStorage() const auto 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->bigFolderUi->setVisible(true); _ui->bigFolderUi->setVisible(true);
@ -1342,14 +1361,14 @@ void AccountSettings::slotDeleteAccount()
{ {
// Deleting the account potentially deletes 'this', so // Deleting the account potentially deletes 'this', so
// the QMessageBox should be destroyed before that happens. // the QMessageBox should be destroyed before that happens.
auto messageBox = new QMessageBox(QMessageBox::Question, const auto messageBox = new QMessageBox(QMessageBox::Question,
tr("Confirm Account Removal"), tr("Confirm Account Removal"),
tr("<p>Do you really want to remove the connection to the account <i>%1</i>?</p>" tr("<p>Do you really want to remove the connection to the account <i>%1</i>?</p>"
"<p><b>Note:</b> This will <b>not</b> delete any files.</p>") "<p><b>Note:</b> This will <b>not</b> delete any files.</p>")
.arg(_accountState->account()->displayName()), .arg(_accountState->account()->displayName()),
QMessageBox::NoButton, QMessageBox::NoButton,
this); this);
auto yesButton = messageBox->addButton(tr("Remove connection"), QMessageBox::YesRole); const auto yesButton = messageBox->addButton(tr("Remove connection"), QMessageBox::YesRole);
messageBox->addButton(tr("Cancel"), QMessageBox::NoRole); messageBox->addButton(tr("Cancel"), QMessageBox::NoRole);
messageBox->setAttribute(Qt::WA_DeleteOnClose); messageBox->setAttribute(Qt::WA_DeleteOnClose);
connect(messageBox, &QMessageBox::finished, this, [this, messageBox, yesButton]{ connect(messageBox, &QMessageBox::finished, this, [this, messageBox, yesButton]{
@ -1357,7 +1376,7 @@ void AccountSettings::slotDeleteAccount()
// Else it might access during destruction. This should be better handled by it having a QSharedPointer // Else it might access during destruction. This should be better handled by it having a QSharedPointer
_model->setAccountState(nullptr); _model->setAccountState(nullptr);
auto manager = AccountManager::instance(); const auto manager = AccountManager::instance();
manager->deleteAccount(_accountState); manager->deleteAccount(_accountState);
manager->save(); manager->save();
} }
@ -1390,11 +1409,11 @@ void AccountSettings::slotStyleChanged()
void AccountSettings::customizeStyle() void AccountSettings::customizeStyle()
{ {
QString msg = _ui->connectLabel->text(); auto msg = _ui->connectLabel->text();
Theme::replaceLinkColorStringBackgroundAware(msg); Theme::replaceLinkColorStringBackgroundAware(msg);
_ui->connectLabel->setText(msg); _ui->connectLabel->setText(msg);
QColor color = palette().highlight().color(); const auto color = palette().highlight().color();
_ui->quotaProgressBar->setStyleSheet(QString::fromLatin1(progressBarStyleC).arg(color.name())); _ui->quotaProgressBar->setStyleSheet(QString::fromLatin1(progressBarStyleC).arg(color.name()));
} }