[vlc-commits] Qt: adapt menus to new Audio Device list

Jean-Baptiste Kempf git at videolan.org
Mon Apr 22 17:35:53 CEST 2013


vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Mon Apr 22 17:35:23 2013 +0200| [26d72ccd4510866f8889ad5722459a9de6a1eaed] | committer: Jean-Baptiste Kempf

Qt: adapt menus to new Audio Device list

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

 modules/gui/qt4/input_manager.cpp |   14 ++++++++++++++
 modules/gui/qt4/input_manager.hpp |    6 ++++++
 modules/gui/qt4/menus.cpp         |   34 ++++++++++++++++++++++++++++++++--
 modules/gui/qt4/menus.hpp         |    4 +++-
 4 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/modules/gui/qt4/input_manager.cpp b/modules/gui/qt4/input_manager.cpp
index 1daf5b8..a078ee7 100644
--- a/modules/gui/qt4/input_manager.cpp
+++ b/modules/gui/qt4/input_manager.cpp
@@ -39,6 +39,7 @@
 #include <QApplication>
 #include <QFile>
 #include <QDir>
+#include <QSignalMapper>
 
 #include <assert.h>
 
@@ -999,6 +1000,10 @@ MainInputManager::MainInputManager( intf_thread_t *_p_intf )
     p_input = playlist_CurrentInput( pl_Get(p_intf) );
     if( p_input )
         emit inputChanged( p_input );
+
+    /* Audio Menu */
+    menusAudioMapper = new QSignalMapper();
+    CONNECT( menusAudioMapper, mapped(QString), this, menusUpdateAudio( QString ) );
 }
 
 MainInputManager::~MainInputManager()
@@ -1015,6 +1020,8 @@ MainInputManager::~MainInputManager()
 
     var_DelCallback( THEPL, "playlist-item-append", PLItemAppended, this );
     var_DelCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
+
+    delete menusAudioMapper;
 }
 
 vout_thread_t* MainInputManager::getVout()
@@ -1218,6 +1225,12 @@ void MainInputManager::notifyMute( bool mute )
     emit soundMuteChanged(mute);
 }
 
+
+void MainInputManager::menusUpdateAudio( const QString& data )
+{
+    aout_DeviceSet( getAout(), qtu(data) );
+}
+
 static int PLItemAppended
 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
 {
@@ -1231,6 +1244,7 @@ static int PLItemAppended
     QApplication::postEvent( mim, event );
     return VLC_SUCCESS;
 }
+
 static int PLItemRemoved
 ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
 {
diff --git a/modules/gui/qt4/input_manager.hpp b/modules/gui/qt4/input_manager.hpp
index dcf23ee..ff1a83d 100644
--- a/modules/gui/qt4/input_manager.hpp
+++ b/modules/gui/qt4/input_manager.hpp
@@ -37,6 +37,7 @@
 
 #include <QObject>
 #include <QEvent>
+class QSignalMapper;
 
 enum { NORMAL,    /* loop: 0, repeat: 0 */
        REPEAT_ONE,/* loop: 0, repeat: 1 */
@@ -253,6 +254,7 @@ class MainInputManager : public QObject, public Singleton<MainInputManager>
 {
     Q_OBJECT
     friend class Singleton<MainInputManager>;
+    friend class VLCMenuBar;
 
 public:
     input_thread_t *getInput() { return p_input; }
@@ -270,6 +272,9 @@ public:
 
     void requestVoutUpdate() { return im->UpdateVout(); }
 
+protected:
+    QSignalMapper *menusAudioMapper;
+
 private:
     MainInputManager( intf_thread_t * );
     virtual ~MainInputManager();
@@ -301,6 +306,7 @@ private slots:
     void notifyRepeatLoop( bool );
     void notifyVolume( float );
     void notifyMute( bool );
+    void menusUpdateAudio( const QString& );
 
 signals:
     void inputChanged( input_thread_t * );
diff --git a/modules/gui/qt4/menus.cpp b/modules/gui/qt4/menus.cpp
index f6626b8..65428a4 100644
--- a/modules/gui/qt4/menus.cpp
+++ b/modules/gui/qt4/menus.cpp
@@ -82,6 +82,7 @@ enum
 static QActionGroup *currentGroup;
 
 QMenu *VLCMenuBar::recentsMenu = NULL;
+QMenu *VLCMenuBar::audioDeviceMenu = NULL;
 
 /**
  * @brief Add static entries to DP in menus
@@ -255,7 +256,6 @@ static int AudioAutoMenuBuilder( audio_output_t *p_object,
 {
     PUSH_INPUTVAR( "audio-es" );
     PUSH_VAR( "stereo-mode" );
-    PUSH_VAR( "device" );
     PUSH_VAR( "visual" );
     return VLC_SUCCESS;
 }
@@ -593,8 +593,8 @@ QMenu *VLCMenuBar::AudioMenu( intf_thread_t *p_intf, QMenu * current )
     if( current->isEmpty() )
     {
         addActionWithSubmenu( current, "audio-es", qtr( "Audio &Track" ) );
+        audioDeviceMenu = current->addMenu( qtr( "Audio &Device" ) );
         addActionWithSubmenu( current, "stereo-mode", qtr( "&Stereo Mode" ) );
-        addActionWithSubmenu( current, "device", qtr( "Audio &Device" ) );
         current->addSeparator();
 
         addActionWithSubmenu( current, "visual", qtr( "&Visualizations" ) );
@@ -605,6 +605,7 @@ QMenu *VLCMenuBar::AudioMenu( intf_thread_t *p_intf, QMenu * current )
     p_aout = THEMIM->getAout();
     EnableStaticEntries( current, ( p_aout != NULL ) );
     AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
+    updateAudioDevice( p_intf, p_aout, audioDeviceMenu );
     if( p_aout )
     {
         vlc_object_release( p_aout );
@@ -1524,6 +1525,35 @@ void VLCMenuBar::DoAction( QObject *data )
         var_Set( p_object, var, val );
 }
 
+void VLCMenuBar::updateAudioDevice( intf_thread_t * p_intf, audio_output_t *p_aout, QMenu *current )
+{
+    char **ids, **names;
+    char *selected;
+
+    if( !p_aout )
+        return;
+
+    current->clear();
+    int i_result = aout_DevicesList( p_aout, &ids, &names);
+    selected = aout_DeviceGet( p_aout );
+
+    QActionGroup *actionGroup = new QActionGroup(current);
+    QAction *action;
+
+    for( int i = 0; i < i_result; i++ )
+    {
+        action = new QAction( qfu( names[i] ), NULL );
+        action->setData( ids[i] );
+        action->setCheckable( true );
+        if( selected && !strcmp( ids[i], selected ) )
+            action->setChecked( true );
+        actionGroup->addAction( action );
+        current->addAction( action );
+        CONNECT(action, changed(), THEMIM->menusAudioMapper, map());
+        THEMIM->menusAudioMapper->setMapping(action, ids[i]);
+    }
+}
+
 void VLCMenuBar::updateRecents( intf_thread_t *p_intf )
 {
     if( recentsMenu )
diff --git a/modules/gui/qt4/menus.hpp b/modules/gui/qt4/menus.hpp
index 969a7cb..883a46d 100644
--- a/modules/gui/qt4/menus.hpp
+++ b/modules/gui/qt4/menus.hpp
@@ -153,7 +153,9 @@ private:
     static void EnableStaticEntries( QMenu *, bool );
 
     /* recentMRL menu */
-    static QMenu *recentsMenu;
+    static QMenu *recentsMenu, *audioDeviceMenu;
+
+    static void updateAudioDevice( intf_thread_t *, audio_output_t *, QMenu* );
 
 public slots:
     static void updateRecents( intf_thread_t * );



More information about the vlc-commits mailing list