Skip to content

Commit

Permalink
Modernize FolderWizardRemotePath::isComplete().
Browse files Browse the repository at this point in the history
Signed-off-by: Camila Ayres <[email protected]>
  • Loading branch information
camilasan committed Dec 4, 2024
1 parent 0633f3f commit 1db1c48
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/gui/folderwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Folder *>(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;
}
}
Expand Down

0 comments on commit 1db1c48

Please sign in to comment.