From 6431d66aeb9f31b2760c553a96d79b738e20231a Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 7 Apr 2023 15:23:43 +0800 Subject: [PATCH 1/4] Remove unnecessary signalling response to start edit locally, just start it within the job Signed-off-by: Claudio Cambra --- src/gui/editlocallyjob.cpp | 1 + src/gui/editlocallymanager.cpp | 9 ++------- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/gui/editlocallyjob.cpp b/src/gui/editlocallyjob.cpp index cb652ba94..1f15e4ded 100644 --- a/src/gui/editlocallyjob.cpp +++ b/src/gui/editlocallyjob.cpp @@ -153,6 +153,7 @@ void EditLocallyJob::proceedWithSetup() Systray::instance()->destroyEditFileLocallyLoadingDialog(); Q_EMIT setupFinished(); + startEditLocally(); } void EditLocallyJob::findAfolderAndConstructPaths() diff --git a/src/gui/editlocallymanager.cpp b/src/gui/editlocallymanager.cpp index c301d4b42..cd6ade7d3 100644 --- a/src/gui/editlocallymanager.cpp +++ b/src/gui/editlocallymanager.cpp @@ -79,14 +79,9 @@ void EditLocallyManager::createJob(const QString &userId, _jobs.insert(token, job); const auto removeJob = [this, token] { _jobs.remove(token); }; - const auto setupJob = [job] { job->startEditLocally(); }; - connect(job.data(), &EditLocallyJob::error, - this, removeJob); - connect(job.data(), &EditLocallyJob::finished, - this, removeJob); - connect(job.data(), &EditLocallyJob::setupFinished, - job.data(), setupJob); + connect(job.data(), &EditLocallyJob::error, this, removeJob); + connect(job.data(), &EditLocallyJob::finished, this, removeJob); job->startSetup(); } From e836ff4a124594dd650c62c7f64512caa6bb0e51 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 7 Apr 2023 16:11:55 +0800 Subject: [PATCH 2/4] Provide error when erasing the blacklist error for an item fails during edit locally Signed-off-by: Claudio Cambra --- src/gui/editlocallyjob.cpp | 17 +++++++++++++---- src/gui/editlocallyjob.h | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/gui/editlocallyjob.cpp b/src/gui/editlocallyjob.cpp index 1f15e4ded..de8f980af 100644 --- a/src/gui/editlocallyjob.cpp +++ b/src/gui/editlocallyjob.cpp @@ -252,7 +252,12 @@ bool EditLocallyJob::checkIfFileParentSyncIsNeeded() void EditLocallyJob::startSyncBeforeOpening() { - eraseBlacklistRecordForItem(); + if (!eraseBlacklistRecordForItem()) { + showError(tr("Could not start editing locally."), + tr("An error occurred trying to synchronise the file to edit locally.")); + return; + } + if (!checkIfFileParentSyncIsNeeded()) { processLocalItem(); return; @@ -264,20 +269,24 @@ void EditLocallyJob::startSyncBeforeOpening() FolderMan::instance()->forceSyncForFolder(_folderForFile); } -void EditLocallyJob::eraseBlacklistRecordForItem() +bool EditLocallyJob::eraseBlacklistRecordForItem() { if (!_folderForFile || !_fileParentItem) { qCWarning(lcEditLocallyJob) << "_folderForFile or _fileParentItem is invalid!"; - return; + return false; } + Q_ASSERT(!_folderForFile->isSyncRunning()); if (_folderForFile->isSyncRunning()) { qCWarning(lcEditLocallyJob) << "_folderForFile is syncing"; - return; + return false; } + if (_folderForFile->journalDb()->errorBlacklistEntry(_fileParentItem->_file).isValid()) { _folderForFile->journalDb()->wipeErrorBlacklistEntry(_fileParentItem->_file); } + + return true; } const QString EditLocallyJob::getRelativePathToRemoteRootForFile() const diff --git a/src/gui/editlocallyjob.h b/src/gui/editlocallyjob.h index 9b06aedbc..3f215f90e 100644 --- a/src/gui/editlocallyjob.h +++ b/src/gui/editlocallyjob.h @@ -54,7 +54,6 @@ public slots: private slots: void fetchRemoteFileParentInfo(); void startSyncBeforeOpening(); - void eraseBlacklistRecordForItem(); void startTokenRemoteCheck(); void proceedWithSetup(); @@ -85,6 +84,7 @@ private slots: private: [[nodiscard]] bool checkIfFileParentSyncIsNeeded(); // returns true if sync will be needed, false otherwise + [[nodiscard]] bool eraseBlacklistRecordForItem(); [[nodiscard]] const QString getRelativePathToRemoteRootForFile() const; // returns either '/' or a (relative path - Folder::remotePath()) for folders pointing to a non-root remote path e.g. '/subfolder' instead of '/' [[nodiscard]] const QString getRelativePathParent() const; From 401ecd8e3cef69f7451293cc8cbd4c689f203e51 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 7 Apr 2023 16:29:15 +0800 Subject: [PATCH 3/4] Ensure errors are emitted and loading dialog destroyed when fatal errors are met during edit locally Signed-off-by: Claudio Cambra --- src/gui/editlocallyjob.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/gui/editlocallyjob.cpp b/src/gui/editlocallyjob.cpp index de8f980af..62a4fb8be 100644 --- a/src/gui/editlocallyjob.cpp +++ b/src/gui/editlocallyjob.cpp @@ -89,6 +89,9 @@ void EditLocallyJob::startTokenRemoteCheck() << "accountState:" << _accountState << "relPath:" << _relPath << "token:" << _token; + + showError(tr("Could not start editing locally."), + tr("An error occurred trying to verify the request to edit locally.")); return; } @@ -199,6 +202,8 @@ void EditLocallyJob::fetchRemoteFileParentInfo() if (_relPathParent == QStringLiteral("/")) { qCWarning(lcEditLocallyJob) << "LsColJob must only be used for nested folders."; + showError(tr("Could not start editing locally."), + tr("An error occurred during data retrieval.")); return; } @@ -448,6 +453,8 @@ void EditLocallyJob::startEditLocally() << "fileName:" << _fileName << "localFilePath:" << _localFilePath << "folderForFile:" << _folderForFile; + + showError(tr("Could not start editing locally."), tr("An error occurred during setup.")); return; } @@ -504,6 +511,8 @@ void EditLocallyJob::slotDirectoryListingIterated(const QString &name, const QMa if (_relPathParent == QStringLiteral("/")) { qCWarning(lcEditLocallyJob) << "LsColJob must only be used for nested folders."; + showError(tr("Could not start editing locally."), + tr("An error occurred during data retrieval.")); return; } @@ -511,6 +520,8 @@ void EditLocallyJob::slotDirectoryListingIterated(const QString &name, const QMa Q_ASSERT(job); if (!job) { qCWarning(lcEditLocallyJob) << "Must call slotDirectoryListingIterated from a signal."; + showError(tr("Could not start editing locally."), + tr("An error occurred during data retrieval.")); return; } @@ -534,8 +545,9 @@ void EditLocallyJob::slotItemDiscovered(const OCC::SyncFileItemPtr &item) Q_ASSERT(item && !item->isEmpty()); if (!item || item->isEmpty()) { qCWarning(lcEditLocallyJob) << "invalid item"; - } - if (item->_file == _relativePathToRemoteRoot) { + showError(tr("Could not start editing locally."), + tr("An error occurred trying to synchronise the file to edit locally.")); + } else if (item->_file == _relativePathToRemoteRoot) { disconnect(&_folderForFile->syncEngine(), &SyncEngine::itemDiscovered, this, &EditLocallyJob::slotItemDiscovered); if (item->_instruction == CSYNC_INSTRUCTION_NONE) { // return early if the file is already in sync @@ -553,6 +565,8 @@ void EditLocallyJob::openFile() if(_localFilePath.isEmpty()) { qCWarning(lcEditLocallyJob) << "Could not edit locally. Invalid local file path."; + showError(tr("Could not start editing locally."), + tr("Invalid local file path.")); return; } From 348c2536ce0da9dc778bc2d92fed8a6e1955c925 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 12 Apr 2023 17:06:07 +0800 Subject: [PATCH 4/4] Remove unneeded setupFinished signal from EditLocallyJob Signed-off-by: Claudio Cambra --- src/gui/editlocallyjob.cpp | 1 - src/gui/editlocallyjob.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gui/editlocallyjob.cpp b/src/gui/editlocallyjob.cpp index 62a4fb8be..cf2c10822 100644 --- a/src/gui/editlocallyjob.cpp +++ b/src/gui/editlocallyjob.cpp @@ -155,7 +155,6 @@ void EditLocallyJob::proceedWithSetup() _localFilePath = _folderForFile->path() + _relativePathToRemoteRoot; Systray::instance()->destroyEditFileLocallyLoadingDialog(); - Q_EMIT setupFinished(); startEditLocally(); } diff --git a/src/gui/editlocallyjob.h b/src/gui/editlocallyjob.h index 3f215f90e..8eeaa4afb 100644 --- a/src/gui/editlocallyjob.h +++ b/src/gui/editlocallyjob.h @@ -43,10 +43,10 @@ public: [[nodiscard]] static QString prefixSlashToPath(const QString &path); signals: - void setupFinished(); void error(const QString &message, const QString &informativeText); void finished(); void callShowError(const QString &message, const QString &informativeText); + public slots: void startSetup(); void startEditLocally();