[vlc-commits] qt: Start scanning for renderers when the menu gets displayed

Hugo Beauzée-Luyssen git at videolan.org
Thu Jan 18 17:27:41 CET 2018


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Thu Jan 18 16:18:24 2018 +0100| [f828a12e0e62ad2c2494487425427b321ef93d33] | committer: Hugo Beauzée-Luyssen

qt: Start scanning for renderers when the menu gets displayed

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f828a12e0e62ad2c2494487425427b321ef93d33
---

 modules/gui/qt/actions_manager.cpp | 93 ++++++++++++++++++++------------------
 modules/gui/qt/actions_manager.hpp |  7 ++-
 modules/gui/qt/menus.cpp           |  7 +--
 3 files changed, 60 insertions(+), 47 deletions(-)

diff --git a/modules/gui/qt/actions_manager.cpp b/modules/gui/qt/actions_manager.cpp
index 3555d4eda0..95a796690e 100644
--- a/modules/gui/qt/actions_manager.cpp
+++ b/modules/gui/qt/actions_manager.cpp
@@ -40,17 +40,19 @@
 
 ActionsManager::ActionsManager( intf_thread_t * _p_i )
     : p_intf( _p_i )
+    , m_scanning( false )
 {
     CONNECT( this, rendererItemAdded( vlc_renderer_item_t* ),
              this, onRendererItemAdded( vlc_renderer_item_t* ) );
     CONNECT( this, rendererItemRemoved( vlc_renderer_item_t* ),
              this, onRendererItemRemoved( vlc_renderer_item_t* ) );
+    m_stop_scan_timer.setSingleShot( true );
+    CONNECT( &m_stop_scan_timer, timeout(), this, StopRendererScan() );
 }
 
 ActionsManager::~ActionsManager()
 {
-    foreach ( vlc_renderer_discovery_t* p_rd, m_rds )
-        vlc_rd_release( p_rd );
+    StopRendererScan();
 }
 
 void ActionsManager::doAction( int id_action )
@@ -297,55 +299,60 @@ void ActionsManager::renderer_event_item_removed( vlc_renderer_discovery_t *p_rd
     self->emit rendererItemRemoved( p_item );
 }
 
-void ActionsManager::ScanRendererAction(bool checked)
+void ActionsManager::StartRendererScan()
 {
-    if (checked == !m_rds.empty())
-        return; /* nothing changed */
+    m_stop_scan_timer.stop();
+    if( m_scanning )
+        return;
 
-    if (checked)
+    /* SD subnodes */
+    char **ppsz_longnames;
+    char **ppsz_names;
+    if( vlc_rd_get_names( THEPL, &ppsz_names, &ppsz_longnames ) != VLC_SUCCESS )
+        return;
+
+    struct vlc_renderer_discovery_owner owner =
     {
-        /* reset the list of renderers */
-        foreach (QAction* action, VLCMenuBar::rendererMenu->actions())
-        {
-            QVariant data = action->data();
-            if (!data.canConvert<QVariantHash>())
-                continue;
-            VLCMenuBar::rendererMenu->removeAction(action);
-            VLCMenuBar::rendererGroup->removeAction(action);
-        }
+        this,
+        renderer_event_item_added,
+        renderer_event_item_removed,
+    };
 
-        /* SD subnodes */
-        char **ppsz_longnames;
-        char **ppsz_names;
-        if( vlc_rd_get_names( THEPL, &ppsz_names, &ppsz_longnames ) != VLC_SUCCESS )
-            return;
+    char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
+    for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
+    {
+        msg_Dbg( p_intf, "starting renderer discovery service %s", *ppsz_longname );
+        vlc_renderer_discovery_t* p_rd = vlc_rd_new( VLC_OBJECT(p_intf), *ppsz_name, &owner );
+        if( p_rd != NULL )
+            m_rds.push_back( p_rd );
+        free( *ppsz_name );
+        free( *ppsz_longname );
+    }
+    free( ppsz_names );
+    free( ppsz_longnames );
+    m_scanning = true;
+}
 
-        struct vlc_renderer_discovery_owner owner =
-        {
-            this,
-            renderer_event_item_added,
-            renderer_event_item_removed,
-        };
+void ActionsManager::RendererMenuCountdown()
+{
+    m_stop_scan_timer.start( 20000 );
+}
 
-        char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
-        for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
-        {
-            msg_Dbg( p_intf, "starting renderer discovery service %s", *ppsz_longname );
-            vlc_renderer_discovery_t* p_rd = vlc_rd_new( VLC_OBJECT(p_intf), *ppsz_name, &owner );
-            if( p_rd != NULL )
-                m_rds.push_back( p_rd );
-            free( *ppsz_name );
-            free( *ppsz_longname );
-        }
-        free( ppsz_names );
-        free( ppsz_longnames );
-    }
-    else
+void ActionsManager::StopRendererScan()
+{
+    /* reset the list of renderers */
+    foreach (QAction* action, VLCMenuBar::rendererMenu->actions())
     {
-        foreach ( vlc_renderer_discovery_t* p_rd, m_rds )
-            vlc_rd_release( p_rd );
-        m_rds.clear();
+        QVariant data = action->data();
+        if (!data.canConvert<QVariantHash>())
+            continue;
+        VLCMenuBar::rendererMenu->removeAction(action);
+        VLCMenuBar::rendererGroup->removeAction(action);
     }
+    foreach ( vlc_renderer_discovery_t* p_rd, m_rds )
+        vlc_rd_release( p_rd );
+    m_rds.clear();
+    m_scanning = false;
 }
 
 void ActionsManager::RendererSelected( QAction *selected )
diff --git a/modules/gui/qt/actions_manager.hpp b/modules/gui/qt/actions_manager.hpp
index f1581b0862..5592429aaf 100644
--- a/modules/gui/qt/actions_manager.hpp
+++ b/modules/gui/qt/actions_manager.hpp
@@ -33,6 +33,7 @@
 #include <QVector>
 
 #include <QObject>
+#include <QTimer>
 class QAction;
 
 typedef enum actionType_e
@@ -76,6 +77,8 @@ private:
 
     intf_thread_t* const p_intf;
     QVector<vlc_renderer_discovery_t*> m_rds;
+    QTimer m_stop_scan_timer;
+    bool m_scanning;
 
     static void renderer_event_item_added( vlc_renderer_discovery_t *,
                                            vlc_renderer_item_t * );
@@ -92,7 +95,9 @@ public slots:
     void record();
     void skipForward();
     void skipBackward();
-    void ScanRendererAction( bool );
+    void StartRendererScan();
+    void RendererMenuCountdown();
+    void StopRendererScan();
     void RendererSelected( QAction * );
 
 protected slots:
diff --git a/modules/gui/qt/menus.cpp b/modules/gui/qt/menus.cpp
index ef75eedc53..77392d611f 100644
--- a/modules/gui/qt/menus.cpp
+++ b/modules/gui/qt/menus.cpp
@@ -1651,11 +1651,12 @@ QMenu *VLCMenuBar::RendererMenu(intf_thread_t *p_intf, QMenu *menu )
 
     submenu->addSeparator();
 
-    action = new QAction( qtr("Scan"), submenu );
-    action->setCheckable(true);
+    action = new QAction( qtr("Scanning..."), submenu );
+    action->setEnabled( false );
     submenu->addAction( action );
 
-    CONNECT( action, triggered(bool), ActionsManager::getInstance( p_intf ), ScanRendererAction( bool ) );
+    CONNECT( submenu, aboutToShow(), ActionsManager::getInstance( p_intf ), StartRendererScan() );
+    CONNECT( submenu, aboutToHide(), ActionsManager::getInstance( p_intf ), RendererMenuCountdown() );
     CONNECT( rendererGroup, triggered(QAction*), ActionsManager::getInstance( p_intf ), RendererSelected( QAction* ) );
 
     return submenu;



More information about the vlc-commits mailing list