From fb4bb95b91c7b27d1d9fe47db17fca8909e510b8 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Sat, 1 Oct 2022 15:52:53 +0200 Subject: [PATCH] Perform inactive qquickwindow garbage collection when generating new file detail dialogs, raise existing dialog instead of always deleting Signed-off-by: Claudio Cambra --- src/gui/systray.cpp | 46 +++++++++++++++++++++++++++++---------------- src/gui/systray.h | 4 +++- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index 38ef32dbf..d4e44efd4 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -287,38 +287,52 @@ void Systray::destroyEditFileLocallyLoadingDialog() bool Systray::raiseDialogs() { - if(_dialogs.empty()) { + return raiseFileDetailDialogs(); +} + +bool Systray::raiseFileDetailDialogs(const QString &localPath) +{ + if(_fileDetailDialogs.empty()) { return false; } - QVector liveDialogs; + auto it = _fileDetailDialogs.begin(); + while (it != _fileDetailDialogs.end()) { + const auto dialog = *it; + auto liveDialog = dialog != nullptr; - for(const auto dialog : _dialogs) { - if(!dialog) { - continue; - } else if(!dialog->isVisible()) { + if (liveDialog && !dialog->isVisible()) { destroyDialog(dialog); - continue; + liveDialog = false; } - liveDialogs.append(dialog); + if (liveDialog && (localPath.isEmpty() || dialog->property("localPath").toString() == localPath)) { + dialog->show(); + dialog->raise(); + dialog->requestActivate(); - dialog->show(); - dialog->raise(); - dialog->requestActivate(); - } + ++it; + continue; + } - _dialogs = liveDialogs; + it = _fileDetailDialogs.erase(it); + continue; + } // If it is empty then we have raised no dialogs, so return false (and viceversa) - return !liveDialogs.empty(); + return !_fileDetailDialogs.empty(); } void Systray::createFileDetailsDialog(const QString &localPath) { + if (raiseFileDetailDialogs(localPath)) { + qCDebug(lcSystray) << "Reopening an existing file details dialog for " << localPath; + return; + } + qCDebug(lcSystray) << "Opening new file details dialog for " << localPath; - if(!_trayEngine) { + if (!_trayEngine) { qCWarning(lcSystray) << "Could not open file details dialog for" << localPath << "as no tray engine was available"; return; } @@ -345,7 +359,7 @@ void Systray::createFileDetailsDialog(const QString &localPath) return; } - _dialogs.append(dialog); + _fileDetailDialogs.append(dialog); dialog->show(); dialog->raise(); diff --git a/src/gui/systray.h b/src/gui/systray.h index 7522d9177..d28b66290 100644 --- a/src/gui/systray.h +++ b/src/gui/systray.h @@ -144,6 +144,8 @@ private slots: void slotPauseAllFolders(); private: + // Argument allows user to specify a specific dialog to be raised + bool raiseFileDetailDialogs(const QString &localPath = {}); void setPauseOnAllFoldersHelper(bool pause); static Systray *_instance; @@ -173,7 +175,7 @@ private: QSet _callsAlreadyNotified; QPointer _editFileLocallyLoadingDialog; - QVector _dialogs; + QVector _fileDetailDialogs; }; } // namespace OCC -- 2.30.2