diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index fe99e54a39211..e84e11f927adf 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -42,10 +42,6 @@ static const char versionC[] = "version"; static const int maxFoldersVersion = 1; -namespace { -static constexpr auto editFileLocallyName = "editFileLocallyName"; -} - namespace OCC { Q_LOGGING_CATEGORY(lcFolderMan, "nextcloud.gui.folder.manager", QtInfoMsg) @@ -1492,9 +1488,23 @@ void FolderMan::editFileLocally(const QString &accountDisplayName, const QString showError(accountFound, tr("Could not find a file for local editing. Make sure its path is valid and it is synced locally."), relPath); return; } - folderForFile->setProperty(editFileLocallyName, localFilePath); folderForFile->startSync(); - QObject::connect(folderForFile, &Folder::syncFinished, this, &FolderMan::slotSyncFinishedBeforeOpeningForLocalEditing); + _localFileEditingSyncFinishedConnections.insert(localFilePath, QObject::connect(folderForFile, &Folder::syncFinished, this, + [this, localFilePath](const OCC::SyncResult &result) { + Q_UNUSED(result); + const auto foundConnectionIt = _localFileEditingSyncFinishedConnections.find(localFilePath); + if (foundConnectionIt.value()) { + QObject::disconnect(foundConnectionIt.value()); + _localFileEditingSyncFinishedConnections.erase(foundConnectionIt); + } + // 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]() { + QDesktopServices::openUrl(QUrl::fromLocalFile(localFilePath)); + Systray::instance()->destroyEditFileLocallyLoadingDialog(); + }); + })); } void FolderMan::trayOverallStatus(const QList &folders, @@ -1859,20 +1869,4 @@ void FolderMan::slotConnectToPushNotifications(Account *account) } } -void FolderMan::slotSyncFinishedBeforeOpeningForLocalEditing(const OCC::SyncResult &result) -{ - Q_UNUSED(result); - const auto folderForFile = qobject_cast(sender()); - QObject::disconnect(folderForFile, &Folder::syncFinished, this, &FolderMan::slotSyncFinishedBeforeOpeningForLocalEditing); - const auto localFilePath = folderForFile->property(editFileLocallyName).toString(); - folderForFile->setProperty(editFileLocallyName, {}); - // 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]() { - QDesktopServices::openUrl(QUrl::fromLocalFile(localFilePath)); - Systray::instance()->destroyEditFileLocallyLoadingDialog(); - }); -} - } // namespace OCC diff --git a/src/gui/folderman.h b/src/gui/folderman.h index 858c675b9da32..77a6b6682b0dc 100644 --- a/src/gui/folderman.h +++ b/src/gui/folderman.h @@ -309,8 +309,6 @@ private slots: void slotProcessFilesPushNotification(Account *account); void slotConnectToPushNotifications(Account *account); - void slotSyncFinishedBeforeOpeningForLocalEditing(const OCC::SyncResult &result); - private: /** Adds a new folder, does not add it to the account settings and * does not set an account on the new folder. @@ -377,6 +375,8 @@ private slots: bool _appRestartRequired = false; + QMap _localFileEditingSyncFinishedConnections; + static FolderMan *_instance; explicit FolderMan(QObject *parent = nullptr); friend class OCC::Application; diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index 059b9a3817f44..e52f62bc81b54 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -281,7 +281,7 @@ void Systray::destroyEditFileLocallyLoadingDialog() return; } qCDebug(lcSystray) << "Closing a file local editing dialog..."; - QMetaObject::invokeMethod(_editFileLocallyLoadingDialog, "closeDialog"); + _editFileLocallyLoadingDialog->deleteLater(); _editFileLocallyLoadingDialog = nullptr; } diff --git a/src/gui/tray/EditFileLocallyLoadingDialog.qml b/src/gui/tray/EditFileLocallyLoadingDialog.qml index d7b9209349ffb..f7fbe965b3a49 100644 --- a/src/gui/tray/EditFileLocallyLoadingDialog.qml +++ b/src/gui/tray/EditFileLocallyLoadingDialog.qml @@ -19,11 +19,6 @@ Window { readonly property real fontPixelSize: Style.topLinePixelSize * 1.5 readonly property real iconWidth: fontPixelSize * 2 - function closeDialog() { - root.close(); - Systray.destroyDialog(root); - } - Component.onCompleted: { Systray.forceWindowInit(root); x = Screen.width / 2 - width / 2