Perform inactive qquickwindow garbage collection when generating new file detail...
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Sat, 1 Oct 2022 13:52:53 +0000 (15:52 +0200)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 31 Oct 2022 17:06:08 +0000 (18:06 +0100)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/systray.cpp
src/gui/systray.h

index 38ef32dbf92d718bfb77e28b603b9f15a6b502d1..d4e44efd430b761ca18c591045cef1d5712a7773 100644 (file)
@@ -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<QQuickWindow*> 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();
index 7522d9177363c26716e314a69defa8c35c4188d1..d28b6629083c7244354102e97f9ada7962f679c3 100644 (file)
@@ -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<qlonglong> _callsAlreadyNotified;
     QPointer<QObject> _editFileLocallyLoadingDialog;
-    QVector<QQuickWindow*> _dialogs;
+    QVector<QQuickWindow*> _fileDetailDialogs;
 };
 
 } // namespace OCC