From ff6ab388267c275a6b21a174d61fc37e7175d3d5 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 28 Nov 2022 18:29:37 +0100 Subject: [PATCH 1/9] Lock file when editing locally Signed-off-by: Claudio Cambra --- src/gui/editlocallyjob.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/editlocallyjob.cpp b/src/gui/editlocallyjob.cpp index 93ca4762800b8..67c8cbdc05a72 100644 --- a/src/gui/editlocallyjob.cpp +++ b/src/gui/editlocallyjob.cpp @@ -546,7 +546,8 @@ void EditLocallyJob::openFile() // In case the VFS mode is enabled and a file is not yet hydrated, we must call QDesktopServices::openUrl // 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([localFilePath]() { + QtConcurrent::run([localFilePath, this]() { + _accountState->account()->setLockFileState(_relPath, _folderForFile->journalDb(), SyncFileItem::LockStatus::LockedItem); QDesktopServices::openUrl(QUrl::fromLocalFile(localFilePath)); Systray::instance()->destroyEditFileLocallyLoadingDialog(); }); From 10746d84412d16633a8cb50c73e61ccd7924e2ed Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 29 Nov 2022 19:07:00 +0100 Subject: [PATCH 2/9] Notify user when file is locked when local editing begins Signed-off-by: Claudio Cambra --- src/gui/editlocallyjob.cpp | 85 ++++++++++++++++++++++++++++++++-- src/gui/editlocallyjob.h | 9 +++- src/gui/editlocallymanager.cpp | 2 +- 3 files changed, 89 insertions(+), 7 deletions(-) diff --git a/src/gui/editlocallyjob.cpp b/src/gui/editlocallyjob.cpp index 67c8cbdc05a72..489b027edfb73 100644 --- a/src/gui/editlocallyjob.cpp +++ b/src/gui/editlocallyjob.cpp @@ -136,6 +136,7 @@ void EditLocallyJob::proceedWithSetup() } _fileName = relPathSplit.last(); + _folderRelativePath = _localFilePath.mid(_folderForFile->cleanPath().length() + 1); _folderForFile = findFolderForFile(_relPath, _userId); @@ -542,17 +543,91 @@ void EditLocallyJob::openFile() return; } - const auto localFilePath = _localFilePath; + const auto localFilePathUrl = QUrl::fromLocalFile(_localFilePath); // In case the VFS mode is enabled and a file is not yet hydrated, we must call QDesktopServices::openUrl // 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([localFilePath, this]() { - _accountState->account()->setLockFileState(_relPath, _folderForFile->journalDb(), SyncFileItem::LockStatus::LockedItem); - QDesktopServices::openUrl(QUrl::fromLocalFile(localFilePath)); + QtConcurrent::run([localFilePathUrl, this]() { + if(QDesktopServices::openUrl(localFilePathUrl)) { + lockFile(); + } Systray::instance()->destroyEditFileLocallyLoadingDialog(); }); +} + +void EditLocallyJob::lockFile() +{ + Q_ASSERT(_accountState); + Q_ASSERT(_accountState->account()); + Q_ASSERT(_folderForFile); + + if (_accountState->account()->fileLockStatus(_folderForFile->journalDb(), _folderRelativePath) == SyncFileItem::LockStatus::LockedItem) { + fileLockSuccess(true); + return; + } + + _folderConnections.append(connect(_accountState->account().data(), &Account::lockFileSuccess, + this, [this] { + _folderForFile->journalDb()->schedulePathForRemoteDiscovery(_relPath); + _folderForFile->scheduleThisFolderSoon(); + })); + _folderConnections.append(connect(_folderForFile, &Folder::syncFinished, + this, [this](const OCC::SyncResult &result) { + Q_UNUSED(result) + fileLockSuccess(); + })); + _folderConnections.append(connect(_accountState->account().data(), &Account::lockFileError, + this, &EditLocallyJob::fileLockError)); + + _folderForFile->accountState()->account()->setLockFileState(_relPath, + _folderForFile->journalDb(), + SyncFileItem::LockStatus::LockedItem); +} + +void EditLocallyJob::disconnectFolderSignals() +{ + for (const auto &connection : qAsConst(_folderConnections)) { + disconnect(connection); + } +} + +void EditLocallyJob::fileLockSuccess(const bool existingLock) +{ + qCDebug(lcEditLocallyJob()) << "File lock succeeded, showing notification" << _relPath; + + SyncJournalFileRecord rec; + Q_ASSERT(_folderForFile->journalDb()->getFileRecord(_folderRelativePath, &rec)); + Q_ASSERT(rec.isValid()); + Q_ASSERT(rec._lockstate._locked); + + const auto lockExpirationTime = rec._lockstate._lockTime + rec._lockstate._lockTimeout; + const auto remainingTime = QDateTime::currentDateTime().secsTo(QDateTime::fromSecsSinceEpoch(lockExpirationTime)); + + static constexpr auto SECONDS_PER_MINUTE = 60; + const auto remainingTimeInMinutes = static_cast(remainingTime > 0 ? remainingTime / SECONDS_PER_MINUTE : 0); + + const auto notificationTitle = existingLock ? tr("File %1 already locked.") : + tr("File %1 now locked."); + + Systray::instance()->showMessage(notificationTitle.arg(_fileName), + tr("Lock will last for %1 minutes. " + "You can also unlock this file manually once you are finished editing.").arg(remainingTimeInMinutes), + QSystemTrayIcon::Information); + + disconnectFolderSignals(); + Q_EMIT finished(); +} + +void EditLocallyJob::fileLockError(const QString &errorMessage) +{ + qCWarning(lcEditLocallyJob()) << "File lock failed, showing notification" << _relPath << errorMessage; + + Systray::instance()->showMessage(tr("File %1 could not be locked."), + errorMessage, + QSystemTrayIcon::Warning); - Q_EMIT fileOpened(); + disconnectFolderSignals(); + Q_EMIT finished(); } } diff --git a/src/gui/editlocallyjob.h b/src/gui/editlocallyjob.h index a2293bffcd7b3..9099804ad6b50 100644 --- a/src/gui/editlocallyjob.h +++ b/src/gui/editlocallyjob.h @@ -45,7 +45,7 @@ class EditLocallyJob : public QObject signals: void setupFinished(); void error(const QString &message, const QString &informativeText); - void fileOpened(); + void finished(); public slots: void startSetup(); @@ -72,6 +72,11 @@ private slots: void slotDirectoryListingIterated(const QString &name, const QMap &properties); void openFile(); + void lockFile(); + + void fileLockSuccess(const bool existingLock = false); + void fileLockError(const QString &errorMessage); + void disconnectFolderSignals(); private: [[nodiscard]] bool checkIfFileParentSyncIsNeeded(); // returns true if sync will be needed, false otherwise @@ -90,9 +95,11 @@ private slots: QString _fileName; QString _localFilePath; + QString _folderRelativePath; Folder *_folderForFile = nullptr; std::unique_ptr _checkTokenJob; QMetaObject::Connection _syncTerminatedConnection = {}; + QVector _folderConnections; }; } diff --git a/src/gui/editlocallymanager.cpp b/src/gui/editlocallymanager.cpp index 09776b31af89d..c301d4b42f011 100644 --- a/src/gui/editlocallymanager.cpp +++ b/src/gui/editlocallymanager.cpp @@ -83,7 +83,7 @@ void EditLocallyManager::createJob(const QString &userId, connect(job.data(), &EditLocallyJob::error, this, removeJob); - connect(job.data(), &EditLocallyJob::fileOpened, + connect(job.data(), &EditLocallyJob::finished, this, removeJob); connect(job.data(), &EditLocallyJob::setupFinished, job.data(), setupJob); From 3f20f192e9d7cbc202f2b35dc60cef53f3f99ce5 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 5 Dec 2022 21:22:08 +0100 Subject: [PATCH 3/9] Ensure we are checking lock state once file has been synced after setting lock Signed-off-by: Claudio Cambra --- src/gui/editlocallyjob.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/gui/editlocallyjob.cpp b/src/gui/editlocallyjob.cpp index 489b027edfb73..a248c6b50873b 100644 --- a/src/gui/editlocallyjob.cpp +++ b/src/gui/editlocallyjob.cpp @@ -566,22 +566,23 @@ void EditLocallyJob::lockFile() return; } - _folderConnections.append(connect(_accountState->account().data(), &Account::lockFileSuccess, - this, [this] { - _folderForFile->journalDb()->schedulePathForRemoteDiscovery(_relPath); - _folderForFile->scheduleThisFolderSoon(); - })); - _folderConnections.append(connect(_folderForFile, &Folder::syncFinished, - this, [this](const OCC::SyncResult &result) { - Q_UNUSED(result) - fileLockSuccess(); + _folderForFile->setSyncPaused(true); + + _folderConnections.append(connect(&_folderForFile->syncEngine(), &SyncEngine::itemCompleted, + this, [this](const SyncFileItemPtr &item) { + if (item->_file == _relPath && item->_locked == SyncFileItem::LockStatus::LockedItem) { + fileLockSuccess(); + } })); + _folderConnections.append(connect(_accountState->account().data(), &Account::lockFileError, this, &EditLocallyJob::fileLockError)); _folderForFile->accountState()->account()->setLockFileState(_relPath, _folderForFile->journalDb(), SyncFileItem::LockStatus::LockedItem); + _folderForFile->journalDb()->schedulePathForRemoteDiscovery(_relPath); + FolderMan::instance()->forceSyncForFolder(_folderForFile); } void EditLocallyJob::disconnectFolderSignals() From 6dbdcccb0fef80a884a47f98421e1cdbf8f18c76 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 6 Dec 2022 12:34:33 +0100 Subject: [PATCH 4/9] Ensure we are using folder relative paths for synced folders that are not root to work correctly Signed-off-by: Claudio Cambra --- src/gui/editlocallyjob.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/gui/editlocallyjob.cpp b/src/gui/editlocallyjob.cpp index a248c6b50873b..2340a07000a71 100644 --- a/src/gui/editlocallyjob.cpp +++ b/src/gui/editlocallyjob.cpp @@ -136,8 +136,6 @@ void EditLocallyJob::proceedWithSetup() } _fileName = relPathSplit.last(); - _folderRelativePath = _localFilePath.mid(_folderForFile->cleanPath().length() + 1); - _folderForFile = findFolderForFile(_relPath, _userId); if (!_folderForFile) { @@ -561,16 +559,14 @@ void EditLocallyJob::lockFile() Q_ASSERT(_accountState->account()); Q_ASSERT(_folderForFile); - if (_accountState->account()->fileLockStatus(_folderForFile->journalDb(), _folderRelativePath) == SyncFileItem::LockStatus::LockedItem) { + if (_accountState->account()->fileLockStatus(_folderForFile->journalDb(), _relativePathToRemoteRoot) == SyncFileItem::LockStatus::LockedItem) { fileLockSuccess(true); return; } - _folderForFile->setSyncPaused(true); - _folderConnections.append(connect(&_folderForFile->syncEngine(), &SyncEngine::itemCompleted, this, [this](const SyncFileItemPtr &item) { - if (item->_file == _relPath && item->_locked == SyncFileItem::LockStatus::LockedItem) { + if (item->_file == _relativePathToRemoteRoot && item->_locked == SyncFileItem::LockStatus::LockedItem) { fileLockSuccess(); } })); @@ -581,7 +577,8 @@ void EditLocallyJob::lockFile() _folderForFile->accountState()->account()->setLockFileState(_relPath, _folderForFile->journalDb(), SyncFileItem::LockStatus::LockedItem); - _folderForFile->journalDb()->schedulePathForRemoteDiscovery(_relPath); + + _folderForFile->syncEngine().setSingleItemDiscoveryOptions({_relPathParent == QStringLiteral("/") ? QString{} : _relPathParent, _relativePathToRemoteRoot, _fileParentItem}); FolderMan::instance()->forceSyncForFolder(_folderForFile); } @@ -597,7 +594,7 @@ void EditLocallyJob::fileLockSuccess(const bool existingLock) qCDebug(lcEditLocallyJob()) << "File lock succeeded, showing notification" << _relPath; SyncJournalFileRecord rec; - Q_ASSERT(_folderForFile->journalDb()->getFileRecord(_folderRelativePath, &rec)); + Q_ASSERT(_folderForFile->journalDb()->getFileRecord(_relativePathToRemoteRoot, &rec)); Q_ASSERT(rec.isValid()); Q_ASSERT(rec._lockstate._locked); From d3fa0066d07f8ff77790cad25a427bf45e6c5ea5 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 6 Dec 2022 13:52:36 +0100 Subject: [PATCH 5/9] Ensure we are using up-to-date item ptr instead of potentially un-update file record when checking lock state in fileLockSuccess, separate case with lock already pre-existing Signed-off-by: Claudio Cambra --- src/gui/editlocallyjob.cpp | 73 ++++++++++++++++++++++++-------------- src/gui/editlocallyjob.h | 8 ++++- 2 files changed, 54 insertions(+), 27 deletions(-) diff --git a/src/gui/editlocallyjob.cpp b/src/gui/editlocallyjob.cpp index 2340a07000a71..a6230d8754e98 100644 --- a/src/gui/editlocallyjob.cpp +++ b/src/gui/editlocallyjob.cpp @@ -560,17 +560,20 @@ void EditLocallyJob::lockFile() Q_ASSERT(_folderForFile); if (_accountState->account()->fileLockStatus(_folderForFile->journalDb(), _relativePathToRemoteRoot) == SyncFileItem::LockStatus::LockedItem) { - fileLockSuccess(true); + fileAlreadyLocked(); return; } - _folderConnections.append(connect(&_folderForFile->syncEngine(), &SyncEngine::itemCompleted, - this, [this](const SyncFileItemPtr &item) { + const auto syncEngineFileSlot = [this](const SyncFileItemPtr &item) { if (item->_file == _relativePathToRemoteRoot && item->_locked == SyncFileItem::LockStatus::LockedItem) { - fileLockSuccess(); + fileLockSuccess(item); } - })); + }; + _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::lockFileError, this, &EditLocallyJob::fileLockError)); @@ -578,7 +581,10 @@ void EditLocallyJob::lockFile() _folderForFile->journalDb(), SyncFileItem::LockStatus::LockedItem); - _folderForFile->syncEngine().setSingleItemDiscoveryOptions({_relPathParent == QStringLiteral("/") ? QString{} : _relPathParent, _relativePathToRemoteRoot, _fileParentItem}); + const SyncEngine::SingleItemDiscoveryOptions singleItemDiscoveryOptions = {(_relPathParent == QStringLiteral("/") ? QString{} : _relPathParent), + _relativePathToRemoteRoot, + _fileParentItem}; + _folderForFile->syncEngine().setSingleItemDiscoveryOptions(singleItemDiscoveryOptions); FolderMan::instance()->forceSyncForFolder(_folderForFile); } @@ -589,43 +595,58 @@ void EditLocallyJob::disconnectFolderSignals() } } -void EditLocallyJob::fileLockSuccess(const bool existingLock) +void EditLocallyJob::fileAlreadyLocked() { - qCDebug(lcEditLocallyJob()) << "File lock succeeded, showing notification" << _relPath; - SyncJournalFileRecord rec; Q_ASSERT(_folderForFile->journalDb()->getFileRecord(_relativePathToRemoteRoot, &rec)); Q_ASSERT(rec.isValid()); Q_ASSERT(rec._lockstate._locked); - const auto lockExpirationTime = rec._lockstate._lockTime + rec._lockstate._lockTimeout; - const auto remainingTime = QDateTime::currentDateTime().secsTo(QDateTime::fromSecsSinceEpoch(lockExpirationTime)); - - static constexpr auto SECONDS_PER_MINUTE = 60; - const auto remainingTimeInMinutes = static_cast(remainingTime > 0 ? remainingTime / SECONDS_PER_MINUTE : 0); - - const auto notificationTitle = existingLock ? tr("File %1 already locked.") : - tr("File %1 now locked."); + const auto remainingTimeInMinutes = fileLockTimeRemainingMinutes(rec._lockstate._lockTime, rec._lockstate._lockTimeout); + fileLockProcedureComplete(tr("File %1 already locked.").arg(_fileName), + tr("Lock will last for %1 minutes. " + "You can also unlock this file manually once you are finished editing.").arg(remainingTimeInMinutes), + true); +} - Systray::instance()->showMessage(notificationTitle.arg(_fileName), - tr("Lock will last for %1 minutes. " - "You can also unlock this file manually once you are finished editing.").arg(remainingTimeInMinutes), - QSystemTrayIcon::Information); +void EditLocallyJob::fileLockSuccess(const SyncFileItemPtr &item) +{ + qCDebug(lcEditLocallyJob()) << "File lock succeeded, showing notification" << _relPath; - disconnectFolderSignals(); - Q_EMIT finished(); + const auto remainingTimeInMinutes = fileLockTimeRemainingMinutes(item->_lockTime, item->_lockTimeout); + fileLockProcedureComplete(tr("File %1 now locked.").arg(_fileName), + tr("Lock will last for %1 minutes. " + "You can also unlock this file manually once you are finished editing.").arg(remainingTimeInMinutes), + true); } void EditLocallyJob::fileLockError(const QString &errorMessage) { qCWarning(lcEditLocallyJob()) << "File lock failed, showing notification" << _relPath << errorMessage; + fileLockProcedureComplete(tr("File %1 could not be locked."), errorMessage, false); +} - Systray::instance()->showMessage(tr("File %1 could not be locked."), - errorMessage, - QSystemTrayIcon::Warning); +void EditLocallyJob::fileLockProcedureComplete(const QString ¬ificationTitle, + const QString ¬ificationMessage, + const bool success) +{ + Systray::instance()->showMessage(notificationTitle, + notificationMessage, + success ? QSystemTrayIcon::Information : QSystemTrayIcon::Warning); disconnectFolderSignals(); Q_EMIT finished(); } +int EditLocallyJob::fileLockTimeRemainingMinutes(const int lockTime, const int lockTimeOut) +{ + const auto lockExpirationTime = lockTime + lockTimeOut; + const auto remainingTime = QDateTime::currentDateTime().secsTo(QDateTime::fromSecsSinceEpoch(lockExpirationTime)); + + static constexpr auto SECONDS_PER_MINUTE = 60; + const auto remainingTimeInMinutes = static_cast(remainingTime > 0 ? remainingTime / SECONDS_PER_MINUTE : 0); + + return remainingTimeInMinutes; +} + } diff --git a/src/gui/editlocallyjob.h b/src/gui/editlocallyjob.h index 9099804ad6b50..4bc4d071bcfe3 100644 --- a/src/gui/editlocallyjob.h +++ b/src/gui/editlocallyjob.h @@ -74,8 +74,12 @@ private slots: void openFile(); void lockFile(); - void fileLockSuccess(const bool existingLock = false); + void fileAlreadyLocked(); + void fileLockSuccess(const SyncFileItemPtr &item); void fileLockError(const QString &errorMessage); + void fileLockProcedureComplete(const QString ¬ificationTitle, + const QString ¬ificationMessage, + const bool success); void disconnectFolderSignals(); private: @@ -83,6 +87,8 @@ private slots: [[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; + [[nodiscard]] int fileLockTimeRemainingMinutes(const int lockTime, const int lockTimeOut); + bool _tokenVerified = false; AccountStatePtr _accountState; From 4e508d0276c80f8ba52e2fe0dc97d4ad86762ec7 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 7 Dec 2022 12:40:48 +0100 Subject: [PATCH 6/9] 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) From 1b5b30d222154ad9b9639b44808b5b71f505bf01 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 7 Dec 2022 13:46:21 +0100 Subject: [PATCH 7/9] Make fileLockTimeRemainingMinutes a static method Signed-off-by: Claudio Cambra --- src/gui/editlocallyjob.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/editlocallyjob.h b/src/gui/editlocallyjob.h index 4bc4d071bcfe3..60637889e6c46 100644 --- a/src/gui/editlocallyjob.h +++ b/src/gui/editlocallyjob.h @@ -87,7 +87,7 @@ private slots: [[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; - [[nodiscard]] int fileLockTimeRemainingMinutes(const int lockTime, const int lockTimeOut); + [[nodiscard]] static int fileLockTimeRemainingMinutes(const int lockTime, const int lockTimeOut); bool _tokenVerified = false; From 7eb31c31e5e30b187f92b0fcc39191a6f46f8ca0 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 7 Dec 2022 13:47:48 +0100 Subject: [PATCH 8/9] Fix loss of integer precision in parameters for fileLockTimeRemainingMinutes Signed-off-by: Claudio Cambra --- src/gui/editlocallyjob.cpp | 2 +- src/gui/editlocallyjob.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/editlocallyjob.cpp b/src/gui/editlocallyjob.cpp index b4607d579eb70..de01a2cc2a9b9 100644 --- a/src/gui/editlocallyjob.cpp +++ b/src/gui/editlocallyjob.cpp @@ -645,7 +645,7 @@ void EditLocallyJob::fileLockProcedureComplete(const QString ¬ificationTitle, openFile(); } -int EditLocallyJob::fileLockTimeRemainingMinutes(const int lockTime, const int lockTimeOut) +int EditLocallyJob::fileLockTimeRemainingMinutes(const qint64 lockTime, const qint64 lockTimeOut) { const auto lockExpirationTime = lockTime + lockTimeOut; const auto remainingTime = QDateTime::currentDateTime().secsTo(QDateTime::fromSecsSinceEpoch(lockExpirationTime)); diff --git a/src/gui/editlocallyjob.h b/src/gui/editlocallyjob.h index 60637889e6c46..158e0fc5d2e73 100644 --- a/src/gui/editlocallyjob.h +++ b/src/gui/editlocallyjob.h @@ -87,7 +87,7 @@ private slots: [[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; - [[nodiscard]] static int fileLockTimeRemainingMinutes(const int lockTime, const int lockTimeOut); + [[nodiscard]] static int fileLockTimeRemainingMinutes(const qint64 lockTime, const qint64 lockTimeOut); bool _tokenVerified = false; From 58f91072a5eaa1ddfef321b8ec8f2b34ef2cb5ce Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 7 Dec 2022 13:48:51 +0100 Subject: [PATCH 9/9] Remove redundant openUrl variable Signed-off-by: Claudio Cambra --- src/gui/editlocallyjob.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gui/editlocallyjob.cpp b/src/gui/editlocallyjob.cpp index de01a2cc2a9b9..1027243e38214 100644 --- a/src/gui/editlocallyjob.cpp +++ b/src/gui/editlocallyjob.cpp @@ -546,8 +546,7 @@ 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]() { - const auto fileOpened = QDesktopServices::openUrl(localFilePathUrl); - if (!fileOpened) { + if (QDesktopServices::openUrl(localFilePathUrl)) { showError(tr("Could not open %1").arg(_fileName), tr("Please try again.")); }