From 15ae4ea18b5832bbe82da40c41af1c3778e0a41f Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Wed, 4 Dec 2024 22:18:55 +0100 Subject: [PATCH] Modernize FolderWizardRemotePath::isComplete(). Signed-off-by: Camila Ayres --- src/gui/folderwizard.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/gui/folderwizard.cpp b/src/gui/folderwizard.cpp index 4ec85eea192ee..43f4da5e4800a 100644 --- a/src/gui/folderwizard.cpp +++ b/src/gui/folderwizard.cpp @@ -488,33 +488,30 @@ bool FolderWizardRemotePath::isComplete() const return false; } - auto dir = _ui.folderTreeWidget->currentItem()->data(0, Qt::UserRole).toString(); - if (!dir.startsWith(QLatin1Char('/'))) { - dir.prepend(QLatin1Char('/')); + auto targetPath = _ui.folderTreeWidget->currentItem()->data(0, Qt::UserRole).toString(); + if (!targetPath.startsWith(QLatin1Char('/'))) { + targetPath.prepend(QLatin1Char('/')); } - wizard()->setProperty("targetPath", dir); + wizard()->setProperty("targetPath", targetPath); - Folder::Map map = FolderMan::instance()->map(); - Folder::Map::const_iterator i = map.constBegin(); - for (i = map.constBegin(); i != map.constEnd(); i++) { - auto *f = static_cast(i.value()); - if (f->accountState()->account() != _account) { + for (const auto folder : qAsConst(FolderMan::instance()->map())) { + if (folder->accountState()->account() != _account) { continue; } - QString curDir = f->remotePathTrailingSlash(); - if (QDir::cleanPath(dir) == QDir::cleanPath(curDir)) { - showWarn(tr("Please choose a different location. %1 is already being used as a sync folder.").arg(Utility::escape(curDir))); + const auto currentDir = folder->remotePathTrailingSlash(); + if (QDir::cleanPath(targetPath) == QDir::cleanPath(currentDir)) { + showWarn(tr("Please choose a different location. %1 is already being used as a sync folder.").arg(Utility::escape(currentDir))); break; } - if (dir.startsWith(curDir)) { - showWarn(tr("Please choose a different location. %1 is already being synced in %2.").arg(Utility::escape(dir), Utility::escape(curDir))); + if (targetPath.startsWith(currentDir)) { + showWarn(tr("Please choose a different location. %1 is already being synced in %2.").arg(Utility::escape(targetPath), Utility::escape(currentDir))); break; } - if (curDir.startsWith(dir)) { - showWarn(tr("Please choose a different location. %1 is already being synced in %2.").arg(Utility::escape(curDir), Utility::escape(dir))); + if (currentDir.startsWith(targetPath)) { + showWarn(tr("Please choose a different location. %1 is already being synced in %2.").arg(Utility::escape(currentDir), Utility::escape(targetPath))); break; } }