[vlc-commits] [Git][videolan/vlc][master] qt: show the playlist recovery dialog asynchronously

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Tue Oct 27 15:55:38 UTC 2026



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
868ec374 by Gabriel Lafond-Thenaille at 2026-10-27T16:23:48+01:00
qt: show the playlist recovery dialog asynchronously

Show the question with show() instead of exec() and start monitoring
the model once it is answered. The agent is now owned by MainCtx.

- - - - -


4 changed files:

- modules/gui/qt/maininterface/mainctx.cpp
- modules/gui/qt/maininterface/mainctx.hpp
- modules/gui/qt/qt.cpp
- modules/gui/qt/util/model_recovery_agent.hpp


Changes:

=====================================
modules/gui/qt/maininterface/mainctx.cpp
=====================================
@@ -43,6 +43,7 @@
 #include "util/qt_dirs.hpp"                     // toNativeSeparators
 
 #include "util/color_scheme_model.hpp"
+#include "util/model_recovery_agent.hpp"
 
 #include "widgets/native/interface_widgets.hpp"     // bgWidget, videoWidget
 
@@ -304,6 +305,15 @@ MainCtx::MainCtx(qt_intf_t *_p_intf)
 
     m_threadRunner = new ThreadRunner();
 
+    try {
+        m_playlistRecoveryAgent = std::make_unique<ModelRecoveryAgent>(settings,
+                                                                       QStringLiteral("Playlist"),
+                                                                       p_intf->p_mainPlaylistController);
+        QMetaObject::invokeMethod(this, [this]() {
+            m_playlistRecoveryAgent->prompt(p_intf);
+        }, Qt::QueuedConnection);
+    } catch (...) { }
+
     m_initialEffectiveMainInterfaceMode = getEffectiveMainInterfaceMode();
 }
 


=====================================
modules/gui/qt/maininterface/mainctx.hpp
=====================================
@@ -73,6 +73,7 @@ class UpdateModel;
 #endif
 struct vlc_preparser_t;
 class ThreadRunner;
+class ModelRecoveryAgent;
 
 namespace vlc {
 namespace playlist {
@@ -515,6 +516,8 @@ protected:
 
     ThreadRunner* m_threadRunner = nullptr;
 
+    std::unique_ptr<ModelRecoveryAgent> m_playlistRecoveryAgent;
+
 public slots:
     void toggleToolbarMenu();
     void toggleInterfaceFullScreen();


=====================================
modules/gui/qt/qt.cpp
=====================================
@@ -102,7 +102,6 @@ extern "C" char **environ;
 #include "maininterface/compositor.hpp"
 #include "util/vlctick.hpp"
 #include "util/shared_input_item.hpp"
-#include "util/model_recovery_agent.hpp"
 #include "util/vlcqtmessagehandler.hpp"
 #include "network/networkmediamodel.hpp"
 #include "network/devicesourceprovider.hpp"
@@ -1291,19 +1290,6 @@ static void *Thread( void *obj )
     p_intf->p_mainPlayerController = new PlayerController(p_intf);
     p_intf->p_mainPlaylistController = new vlc::playlist::PlaylistController(p_intf->p_playlist);
 
-    std::optional playlistModelRecoveryAgent = std::unique_ptr<ModelRecoveryAgent>();
-    QMetaObject::invokeMethod(&app, [&playlistModelRecoveryAgent, settings = QPointer(p_intf->mainSettings), mpc = QPointer(p_intf->p_mainPlaylistController)]() {
-        if (Q_UNLIKELY(!playlistModelRecoveryAgent)) // std::optional is nullopt, reset() was already called
-            return;
-        if (Q_UNLIKELY(!settings || !mpc))
-            return;
-        try {
-            playlistModelRecoveryAgent = std::make_unique<ModelRecoveryAgent>(settings.get(),
-                                                                              QStringLiteral("Playlist"),
-                                                                              mpc.get());
-        } catch (...){ }
-    }, Qt::QueuedConnection);
-
     /* Create the normal interface in non-DP mode */
 #ifdef _WIN32
     p_intf->p_mi = new MainCtxWin32(p_intf);
@@ -1468,7 +1454,6 @@ static void *Thread( void *obj )
 
     msg_Dbg( p_intf, "QApp exec() finished" );
 
-    playlistModelRecoveryAgent.reset();
     return ThreadCleanup( p_intf, CLEANUP_APP_TERMINATED );
 }
 


=====================================
modules/gui/qt/util/model_recovery_agent.hpp
=====================================
@@ -33,7 +33,7 @@
 
 #include "qt.hpp"
 
-#include "dialogs/dialogs_provider.hpp"
+#include "widgets/native/qvlcframe.hpp"
 
 class ModelRecoveryAgent
 {
@@ -43,6 +43,7 @@ class ModelRecoveryAgent
     QTimer m_timer;
     bool m_conditionDismissInitialDirtiness = false;
     std::unique_ptr<QLockFile> m_lockFile;
+    std::unique_ptr<QMessageBox> m_question;
 
 public:
     // NOTE: settings and model must outlive the instance of this class.
@@ -69,16 +70,23 @@ public:
                 const QFileInfo fileInfo(m_recoveryFileName);
                 if (fileInfo.size() > 0)
                 {
-                    if (DialogsProvider::getInstance()->messageDialog(qtr("Do you want to restore the %1 model from %2?").arg(modelIdentifier.toLower(),
-                                                                                                                              fileInfo.lastModified().toString()),
-                                                                      qtr("The application closed abruptly."),
-                                                                      (QMessageBox::Yes | QMessageBox::No),
-                                                                      QMessageBox::Yes,
-                                                                      QMessageBox::Question) == QMessageBox::Yes)
-                    {
-                        model->append(m_recoveryFileName);
-                        m_conditionDismissInitialDirtiness = true;
-                    }
+                    m_question = std::make_unique<QMessageBox>();
+                    m_question->setText(qtr("Do you want to restore the %1 model from %2?").arg(modelIdentifier.toLower(), fileInfo.lastModified().toString()));
+                    m_question->setWindowTitle(qtr("The application closed abruptly."));
+                    m_question->setIcon(QMessageBox::Question);
+                    m_question->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+                    m_question->setDefaultButton(QMessageBox::Yes);
+                    m_question->setWindowModality(Qt::ApplicationModal);
+
+                    QObject::connect(m_question.get(), &QDialog::finished, m_question.get(), [this, model]() {
+                        if (m_question->standardButton(m_question->clickedButton()) == QMessageBox::Yes)
+                        {
+                            model->append(m_recoveryFileName);
+                            m_conditionDismissInitialDirtiness = true;
+                        }
+                        m_question.release()->deleteLater();
+                        startMonitoring(model);
+                    });
                 }
             }
         }
@@ -102,6 +110,43 @@ public:
             settings->sync();
         }
 
+        if (!m_question)
+            startMonitoring(model);
+    }
+
+    void prompt(qt_intf_t *p_intf)
+    {
+        if (!m_question)
+            return;
+        QVLCDialog::setWindowTransientParent(m_question.get(), nullptr, p_intf);
+        m_question->show();
+    }
+
+    ~ModelRecoveryAgent()
+    {
+        if (m_question)
+            return;
+
+        if (!m_recoveryFileName.isEmpty())
+        {
+            QFile::remove(m_recoveryFileName);
+        }
+
+        assert(m_settings);
+
+        m_settings->sync();
+
+        if (m_settings->value(m_key) == m_recoveryFileName)
+        {
+            m_settings->remove(m_key);
+            m_settings->sync();
+        }
+    }
+
+private:
+    template<class T>
+    void startMonitoring(T* model)
+    {
         m_timer.setInterval(10000); // 10 seconds
         m_timer.setSingleShot(true);
 
@@ -150,24 +195,6 @@ public:
         QObject::connect(model, &T::itemsRemoved, &m_timer, QOverload<>::of(&QTimer::start));
         QObject::connect(model, &T::itemsUpdated, &m_timer, QOverload<>::of(&QTimer::start));
     }
-
-    ~ModelRecoveryAgent()
-    {
-        if (!m_recoveryFileName.isEmpty())
-        {
-            QFile::remove(m_recoveryFileName);
-        }
-
-        assert(m_settings);
-
-        m_settings->sync();
-
-        if (m_settings->value(m_key) == m_recoveryFileName)
-        {
-            m_settings->remove(m_key);
-            m_settings->sync();
-        }
-    }
 };
 
 #endif // MODEL_RECOVERY_AGENT_HPP



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/868ec3740d253aca955f11f09631540adc06d4e1

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/868ec3740d253aca955f11f09631540adc06d4e1
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list