From c3d4bfaf92abbc01cfcb6c709395c7b95a874b8d Mon Sep 17 00:00:00 2001 From: rumtid Date: Fri, 26 Jan 2024 11:43:13 +0800 Subject: [PATCH] Improve code structures --- src/ui/create-repo-dialog.cpp | 23 ++++++++++---------- src/ui/download-repo-dialog.cpp | 37 +++++++++++++-------------------- 2 files changed, 25 insertions(+), 35 deletions(-) diff --git a/src/ui/create-repo-dialog.cpp b/src/ui/create-repo-dialog.cpp index fe5ee32cc..0f94c2ddd 100644 --- a/src/ui/create-repo-dialog.cpp +++ b/src/ui/create-repo-dialog.cpp @@ -92,6 +92,17 @@ void CreateRepoDialog::createAction() if (!validateInputs()) { return; } +#ifdef Q_OS_WIN32 + if (utils::win::isNetworkDevice(path_)) { + bool ok = seafApplet->yesOrCancelBox( + tr("File changes on network drives may not be synced automatically. You can set sync intervals to enable periodic sync. Do you want to sync with this folder?"), + this, true); + if (!ok) { + return; + } + } +#endif // Q_OS_WIN32 + mStatusText->setText(tr("Creating...")); setAllInputsEnabled(false); @@ -187,18 +198,6 @@ bool CreateRepoDialog::validateInputs() name_ = mName->text().trimmed(); path_ = mDirectory->text(); - -#ifdef Q_OS_WIN32 - if (utils::win::isNetworkDevice(path_)) { - bool ok = seafApplet->detailedYesOrNoBox( - tr("File changes on network drives may not be synced automatically. Do you want to sync with this folder?"), - tr("You can set sync intervals to enable periodic sync."), this); - if (!ok) { - return false; - } - } -#endif // Q_OS_WIN32 - return true; } diff --git a/src/ui/download-repo-dialog.cpp b/src/ui/download-repo-dialog.cpp index cfdc04639..ac89c733d 100644 --- a/src/ui/download-repo-dialog.cpp +++ b/src/ui/download-repo-dialog.cpp @@ -234,6 +234,19 @@ void DownloadRepoDialog::onOkBtnClicked() if (!validateInputs()) { return; } +#ifdef Q_OS_WIN32 + QString worktree = alternative_path_.isEmpty() ? + QDir(mDirectory->text()).absoluteFilePath(repo_.name) : + alternative_path_; + if (utils::win::isNetworkDevice(worktree)) { + bool ok = seafApplet->yesOrCancelBox( + tr("File changes on network drives may not be synced automatically. You can set sync intervals to enable periodic sync. Do you want to sync with this folder?"), + this, true); + if (!ok) { + return; + } + } +#endif // Q_OS_WIN32 setAllInputsEnabled(false); @@ -280,25 +293,14 @@ bool DownloadRepoDialog::validateInputs() return false; } - QString path = QDir(mDirectory->text()).absoluteFilePath(repo_.name); - if (manual_merge_mode_) { -#ifdef Q_OS_WIN32 - if (utils::win::isNetworkDevice(path)) { - bool ok = seafApplet->detailedYesOrNoBox( - tr("File changes on network drives may not be synced automatically. Do you want to sync with this folder?"), - tr("You can set sync intervals to enable periodic sync."), this); - if (!ok) { - return false; - } - } -#endif // Q_OS_WIN32 return true; } sync_with_existing_ = false; alternative_path_ = ""; + QString path = QDir(mDirectory->text()).absoluteFilePath(repo_.name); QFileInfo fileinfo = QFileInfo(path); if (fileinfo.exists()) { sync_with_existing_ = true; @@ -333,17 +335,6 @@ bool DownloadRepoDialog::validateInputs() } } -#ifdef Q_OS_WIN32 - if (utils::win::isNetworkDevice(path)) { - bool ok = seafApplet->detailedYesOrNoBox( - tr("File changes on network drives may not be synced automatically. Do you want to sync with this folder?"), - tr("You can set sync intervals to enable periodic sync."), this); - if (!ok) { - return false; - } - } -#endif // Q_OS_WIN32 - return true; }