From 4e508d0276c80f8ba52e2fe0dc97d4ad86762ec7 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 7 Dec 2022 12:40:48 +0100 Subject: [PATCH] Run locking procedure on main thread, open file after file has been locked remotely Signed-off-by: Claudio Cambra --- src/gui/editlocallyjob.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/gui/editlocallyjob.cpp b/src/gui/editlocallyjob.cpp index a6230d8754e98..b4607d579eb70 100644 --- a/src/gui/editlocallyjob.cpp +++ b/src/gui/editlocallyjob.cpp @@ -252,7 +252,7 @@ void EditLocallyJob::startSyncBeforeOpening() { eraseBlacklistRecordForItem(); if (!checkIfFileParentSyncIsNeeded()) { - openFile(); + lockFile(); return; } @@ -465,7 +465,7 @@ void EditLocallyJob::slotItemCompleted(const OCC::SyncFileItemPtr &item) if (item->_file == _relativePathToRemoteRoot) { disconnect(&_folderForFile->syncEngine(), &SyncEngine::itemCompleted, this, &EditLocallyJob::slotItemCompleted); disconnect(&_folderForFile->syncEngine(), &SyncEngine::itemDiscovered, this, &EditLocallyJob::slotItemDiscovered); - openFile(); + lockFile(); } } @@ -546,10 +546,13 @@ void EditLocallyJob::openFile() // from a separate thread, or, there will be a freeze. To avoid searching for a specific folder and checking // if the VFS is enabled - we just always call it from a separate thread. QtConcurrent::run([localFilePathUrl, this]() { - if(QDesktopServices::openUrl(localFilePathUrl)) { - lockFile(); + const auto fileOpened = QDesktopServices::openUrl(localFilePathUrl); + if (!fileOpened) { + showError(tr("Could not open %1").arg(_fileName), tr("Please try again.")); } + Systray::instance()->destroyEditFileLocallyLoadingDialog(); + emit finished(); }); } @@ -570,22 +573,26 @@ void EditLocallyJob::lockFile() } }; + const auto runSingleFileDiscovery = [this] { + const SyncEngine::SingleItemDiscoveryOptions singleItemDiscoveryOptions = {(_relPathParent == QStringLiteral("/") ? QString{} : _relPathParent), + _relativePathToRemoteRoot, + _fileParentItem}; + _folderForFile->syncEngine().setSingleItemDiscoveryOptions(singleItemDiscoveryOptions); + FolderMan::instance()->forceSyncForFolder(_folderForFile); + }; + _folderConnections.append(connect(&_folderForFile->syncEngine(), &SyncEngine::itemCompleted, this, syncEngineFileSlot)); _folderConnections.append(connect(&_folderForFile->syncEngine(), &SyncEngine::itemDiscovered, this, syncEngineFileSlot)); + _folderConnections.append(connect(_accountState->account().data(), &Account::lockFileSuccess, + this, runSingleFileDiscovery)); _folderConnections.append(connect(_accountState->account().data(), &Account::lockFileError, this, &EditLocallyJob::fileLockError)); _folderForFile->accountState()->account()->setLockFileState(_relPath, _folderForFile->journalDb(), SyncFileItem::LockStatus::LockedItem); - - const SyncEngine::SingleItemDiscoveryOptions singleItemDiscoveryOptions = {(_relPathParent == QStringLiteral("/") ? QString{} : _relPathParent), - _relativePathToRemoteRoot, - _fileParentItem}; - _folderForFile->syncEngine().setSingleItemDiscoveryOptions(singleItemDiscoveryOptions); - FolderMan::instance()->forceSyncForFolder(_folderForFile); } void EditLocallyJob::disconnectFolderSignals() @@ -635,7 +642,7 @@ void EditLocallyJob::fileLockProcedureComplete(const QString ¬ificationTitle, success ? QSystemTrayIcon::Information : QSystemTrayIcon::Warning); disconnectFolderSignals(); - Q_EMIT finished(); + openFile(); } int EditLocallyJob::fileLockTimeRemainingMinutes(const int lockTime, const int lockTimeOut)