]> git.sesse.net Git - vlc/commitdiff
Fix SD support
authorClément Stenac <zorglub@videolan.org>
Sun, 10 Sep 2006 19:00:21 +0000 (19:00 +0000)
committerClément Stenac <zorglub@videolan.org>
Sun, 10 Sep 2006 19:00:21 +0000 (19:00 +0000)
modules/gui/qt4/dialogs/playlist.cpp
modules/gui/qt4/dialogs/playlist.hpp
modules/gui/qt4/dialogs_provider.cpp
modules/gui/qt4/dialogs_provider.hpp
modules/gui/qt4/menus.cpp

index a20469802e9df2b4eb934331fab581463d467a37..4a0b57ee51bc42647b63c3d5e4fb55f07a17cb53 100644 (file)
 #include "components/playlist/panels.hpp"
 #include "components/playlist/selector.hpp"
 #include <QHBoxLayout>
-#include "menus.hpp"
+#include <QSignalMapper>
+#include <QMenu>
+#include <QAction>
+#include <QMenuBar>
+#include "dialogs_provider.hpp"
 
 PlaylistDialog *PlaylistDialog::instance = NULL;
 
@@ -36,7 +40,11 @@ PlaylistDialog::PlaylistDialog( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     QWidget *main = new QWidget( this );
     setCentralWidget( main );
     setWindowTitle( qtr( "Playlist" ) );
-    QVLCMenu::createPlMenuBar( menuBar(), p_intf );
+
+    SDMapper = new QSignalMapper();
+    connect( SDMapper, SIGNAL( mapped (QString)), this,
+             SLOT( SDMenuAction( QString ) ) );
+    createPlMenuBar( menuBar(), p_intf );
 
     selector = new PLSelector( centralWidget(), p_intf, THEPL );
     selector->setMaximumWidth( 130 );
@@ -60,3 +68,79 @@ PlaylistDialog::~PlaylistDialog()
 {
     writeSettings( "playlist" );
 }
+
+void PlaylistDialog::createPlMenuBar( QMenuBar *bar, intf_thread_t *p_intf )
+{
+    QMenu *manageMenu = new QMenu();
+    manageMenu->setTitle( qtr("Add") );
+
+    QMenu *subPlaylist = new QMenu();
+    subPlaylist->setTitle( qtr("Add to current playlist") );
+    subPlaylist->addAction( "&File...", THEDP,
+                           SLOT( simplePLAppendDialog() ) );
+    subPlaylist->addAction( "&Advanced add...", THEDP,
+                           SLOT( PLAppendDialog() ) );
+    manageMenu->addMenu( subPlaylist );
+    manageMenu->addSeparator();
+
+    QMenu *subML = new QMenu();
+    subML->setTitle( qtr("Add to Media library") );
+    subML->addAction( "&File...", THEDP,
+                           SLOT( simpleMLAppendDialog() ) );
+    subML->addAction( "Directory", THEDP, SLOT( openMLDirectory() ));
+    subML->addAction( "&Advanced add...", THEDP,
+                           SLOT( MLAppendDialog() ) );
+    manageMenu->addMenu( subML );
+    manageMenu->addAction( "Open playlist file", THEDP, SLOT( openPlaylist() ));
+
+    bar->addMenu( manageMenu );
+    bar->addMenu( SDMenu() );
+}
+
+QMenu *PlaylistDialog::SDMenu()
+{
+    QMenu *menu = new QMenu();
+    menu->setTitle( qtr( "Additional sources" ) );
+    vlc_list_t *p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,
+                                        FIND_ANYWHERE );
+    int i_num = 0;
+    for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
+    {
+        module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
+        if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
+            i_num++;
+    }
+    for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
+    {
+        module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object;
+        if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
+        {
+            QAction *a = new QAction( qfu( p_parser->psz_longname ), menu );
+            a->setCheckable( true );
+            /* hack to handle submodules properly */
+            int i = -1;
+            while( p_parser->pp_shortcuts[++i] != NULL );
+            i--;
+            if( playlist_IsServicesDiscoveryLoaded( THEPL,
+                 i>=0?p_parser->pp_shortcuts[i] : p_parser->psz_object_name ) )
+            {
+                a->setChecked( true );
+            }
+            connect( a , SIGNAL( triggered() ), SDMapper, SLOT( map() ) );
+            SDMapper->setMapping( a, i>=0? p_parser->pp_shortcuts[i] :
+                                            p_parser->psz_object_name );
+            menu->addAction( a );
+        }
+    }
+    vlc_list_release( p_list );
+    return menu;
+}
+
+void PlaylistDialog::SDMenuAction( QString data )
+{
+    char *psz_sd = data.toUtf8().data();
+    if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
+        playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
+    else
+        playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
+}
index 11de34f8cc036773a37824742bf26bfb83e22988..d3ce6e26d5e1b48c4699af885616404b265a6962 100644 (file)
@@ -26,6 +26,7 @@
 #include <QModelIndex>
 #include "util/qvlcframe.hpp"
 
+class QSignalMapper;
 class PLSelector;
 class PLPanel;
 
@@ -40,11 +41,17 @@ public:
     }
     virtual ~PlaylistDialog();
 private:
+
+    void createPlMenuBar( QMenuBar *bar, intf_thread_t *p_intf );
+    QMenu * SDMenu();
     PlaylistDialog( intf_thread_t * );
     static PlaylistDialog *instance;
 
+    QSignalMapper *SDMapper;
     PLSelector *selector;
     PLPanel *rightPanel;
+private slots:
+    void SDMenuAction( QString );
 };
 
 
index a63e2d736207bbfddff00928c4fd48e0274060e5..8bf4d46e06b1b43055a91d8e3f36a58727148918 100644 (file)
@@ -37,9 +37,6 @@ DialogsProvider* DialogsProvider::instance = NULL;
 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
                                       QObject( NULL ), p_intf( _p_intf )
 {
-//    idle_timer = new QTimer( this );
-//    idle_timer->start( 0 );
-
     fixed_timer = new QTimer( this );
     fixed_timer->start( 150 /* milliseconds */ );
 
@@ -52,9 +49,6 @@ DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
             SLOT(menuUpdateAction( QObject *)) );
 }
 
-DialogsProvider::~DialogsProvider()
-{
-}
 void DialogsProvider::customEvent( QEvent *event )
 {
     if( event->type() == DialogEvent_Type )
index 6018313f9c55d3cb626ddce0c532a8a5682d8548..73b7e7752709fd1d539c52bf9668f4f42c661d66 100644 (file)
@@ -50,8 +50,7 @@ public:
             instance = new DialogsProvider( p_intf );
         return instance;
     }
-    virtual ~DialogsProvider();
-    QTimer *idle_timer;
+    virtual ~DialogsProvider() {};
     QTimer *fixed_timer;
 protected:
     friend class QVLCMenu;
index 793ce81295fdd7a0655f2fbfe07d279d148260c2..163696bb089c6d6fbc4afabc0a7dcac0224787ab 100644 (file)
@@ -38,7 +38,6 @@ enum
 };
 
 static QActionGroup *currentGroup;
-static char ** pp_sds;
 
 // Add static entries to menus
 #define DP_SADD( text, help, icon, slot ) { if( strlen(icon) > 0 ) { QAction *action = menu->addAction( text, THEDP, SLOT( slot ) ); action->setIcon(QIcon(icon));} else { menu->addAction( text, THEDP, SLOT( slot ) ); } }
@@ -128,85 +127,6 @@ void QVLCMenu::createMenuBar( QMenuBar *bar, intf_thread_t *p_intf )
 
     //    BAR_ADD( HelpMenu(), qtr("Help" ) );
 }
-
-void QVLCMenu::createPlMenuBar( QMenuBar *bar, intf_thread_t *p_intf )
-{
-    QMenu *manageMenu = new QMenu();
-    manageMenu->setTitle( qtr("Operations") );
-
-    QMenu *subPlaylist = new QMenu();
-    subPlaylist->setTitle( qtr("Add to current playlist") );
-    subPlaylist->addAction( "&File...", THEDP,
-                           SLOT( simplePLAppendDialog() ) );
-    subPlaylist->addAction( "&Advanced add...", THEDP,
-                           SLOT( PLAppendDialog() ) );
-    manageMenu->addMenu( subPlaylist );
-    manageMenu->addSeparator();
-
-    QMenu *subML = new QMenu();
-    subML->setTitle( qtr("Add to Media library") );
-    subML->addAction( "&File...", THEDP,
-                           SLOT( simpleMLAppendDialog() ) );
-    subML->addAction( "Directory", THEDP, SLOT( openMLDirectory() ));
-    subML->addAction( "&Advanced add...", THEDP,
-                           SLOT( MLAppendDialog() ) );
-    manageMenu->addMenu( subML );
-    manageMenu->addAction( "Open playlist file", THEDP, SLOT( openPlaylist() ));
-    manageMenu->addSeparator();
-
-//    manageMenu->addMenu( SDMenu( p_intf ) );
-
-    bar->addMenu( manageMenu );
-}
-
-QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
-{
-    QMenu *menu = new QMenu();
-    menu->setTitle( qtr( "Services Discovery" ) );
-    playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
-                                            VLC_OBJECT_PLAYLIST,
-                                            FIND_ANYWHERE );
-    assert( p_playlist );
-    vlc_list_t *p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,
-                                        FIND_ANYWHERE );
-    int i_num = 0;
-    for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
-    {
-        module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
-        if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
-            i_num++;
-    }
-    if( i_num )  pp_sds = (char **)calloc( i_num, sizeof(void *) );
-    for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
-    {
-        module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object;
-        if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
-        {
-            QAction *a = menu->addAction(
-                            qfu( p_parser->psz_longname ?
-                                   p_parser->psz_longname :
-                                   ( p_parser->psz_shortname ?
-                                       p_parser->psz_shortname :
-                                       p_parser->psz_object_name ) ) );
-            a->setCheckable( true );
-            /* hack to handle submodules properly */
-            int i = -1;
-            while( p_parser->pp_shortcuts[++i] != NULL );
-            i--;
-            if( playlist_IsServicesDiscoveryLoaded( p_playlist,
-                 i>=0?p_parser->pp_shortcuts[i] : p_parser->psz_object_name ) )
-            {
-                a->setChecked( true );
-            }
-            pp_sds[i_num++] = i>=0? p_parser->pp_shortcuts[i] :
-                                    p_parser->psz_object_name;
-        }
-    }
-    vlc_list_release( p_list );
-    vlc_object_release( p_playlist );
-    return menu;
-}
-
 QMenu *QVLCMenu::FileMenu()
 {
     QMenu *menu = new QMenu();