]> git.sesse.net Git - vlc/commitdiff
Playlist menu
authorClément Stenac <zorglub@videolan.org>
Fri, 22 Sep 2006 18:31:31 +0000 (18:31 +0000)
committerClément Stenac <zorglub@videolan.org>
Fri, 22 Sep 2006 18:31:31 +0000 (18:31 +0000)
Add button in playlist widget

modules/gui/qt4/components/interface_widgets.cpp
modules/gui/qt4/components/interface_widgets.hpp
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/main_interface.cpp
modules/gui/qt4/menus.cpp
modules/gui/qt4/menus.hpp

index e25cf263c40803aa4c0a557b3f30938f82924696..0fafbb50b89af5b5cde88faf9978f09d2be7bad3 100644 (file)
 #include "pixmaps/art.xpm"
 #include <vlc/vout.h>
 
+#include <QCursor>
 #include <QPushButton>
 #include <QHBoxLayout>
+#include <QMenu>
 
 #define ICON_SIZE 128
 
@@ -48,7 +50,6 @@ VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
 {
     vlc_mutex_init( p_intf, &lock );
     p_vout = NULL;
-    setFrameStyle(QFrame::Panel | QFrame::Raised);
 
     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
 }
@@ -103,7 +104,6 @@ void VideoWidget::release( void *p_win )
 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
                                         QFrame( NULL ), p_intf( _p_i )
 {
-    setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
 
     setAutoFillBackground( true );
     plt =  palette();
@@ -148,7 +148,6 @@ void BackgroundWidget::resizeEvent( QResizeEvent *e )
 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
                                                 QFrame( NULL ), p_intf( _p_i )
 {
-    setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
     QHBoxLayout *layout = new QHBoxLayout( this );
     layout->setMargin( 0 );
     QPushButton *prevButton = new QPushButton( "Prev" );
@@ -175,20 +174,21 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) : QFrame(NULL),
     QVBoxLayout *left = new QVBoxLayout( );
     QHBoxLayout *middle = new QHBoxLayout;
 
-    setFrameStyle(QFrame::StyledPanel | QFrame::Sunken );
     selector = new PLSelector( this, p_intf, THEPL );
     selector->setMaximumWidth( 130 );
     left->addWidget( selector );
 
     QPushButton *undockButton = new QPushButton( "UN", this );
     undockButton->setMaximumWidth( 25 );
-    BUTTONACT( undockButton, undock() );
-
     undockButton->setToolTip( qtr( "Undock playlist for main interface" ) );
-    QPushButton *sourcesButton = new QPushButton( "Sources", this );
-    sourcesButton->setToolTip( qtr( "Select additional stream sources" ) );
+    BUTTONACT( undockButton, undock() );
     middle->addWidget( undockButton );
-    middle->addWidget( sourcesButton );
+
+    addButton = new QPushButton( "+", this );
+    addButton->setMaximumWidth( 25 );
+    BUTTONACT( addButton, add() );
+    middle->addWidget( addButton );
+
     left->addLayout( middle );
 
     QLabel *art = new QLabel( "" );
@@ -200,11 +200,13 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) : QFrame(NULL),
 
     playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
                                                 THEPL->p_local_category );
+    currentRootId = p_root->i_id;
 
     rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( this,
                               p_intf, THEPL, p_root ) );
 
     CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
+    CONNECT( selector, activated( int ), this, setCurrentRootId( int ) );
 
     QHBoxLayout *layout = new QHBoxLayout(this);
     layout->addLayout( left, 0 );
@@ -216,6 +218,25 @@ PlaylistWidget::~PlaylistWidget()
 {
 }
 
+void PlaylistWidget::setCurrentRootId( int _new )
+{
+    currentRootId = _new;
+    if( currentRootId == THEPL->p_local_category->i_id ||
+        currentRootId == THEPL->p_local_onelevel->i_id  )
+    {
+        addButton->setEnabled( true );
+        addButton->setToolTip( qtr("Add to playlist" ) );
+    }
+    else if( currentRootId == THEPL->p_ml_category->i_id ||
+             currentRootId == THEPL->p_ml_onelevel->i_id )
+    {
+        addButton->setEnabled( true );
+        addButton->setToolTip( qtr("Add to media library" ) );
+    }
+    else
+        addButton->setEnabled( false );
+}
+
 void PlaylistWidget::undock()
 {
     hide();
@@ -226,9 +247,27 @@ void PlaylistWidget::undock()
     QApplication::postEvent( p_intf->p_sys->p_mi, event );
 }
 
+void PlaylistWidget::add()
+{
+    QMenu *popup = new QMenu();
+    if( currentRootId == THEPL->p_local_category->i_id ||
+        currentRootId == THEPL->p_local_onelevel->i_id )
+    {
+        popup->addAction( "Add file", THEDP, SLOT( simplePLAppendDialog() ) );
+        popup->addAction( "Advanced add", THEDP, SLOT( PLAppendDialog() ) );
+    }
+    else if( currentRootId == THEPL->p_ml_category->i_id ||
+             currentRootId == THEPL->p_ml_onelevel->i_id )
+    {
+        popup->addAction( "Add file", THEDP, SLOT( simpleMLAppendDialog() ) );
+        popup->addAction( "Advanced add", THEDP, SLOT( MLAppendDialog() ) );
+        popup->addAction( "Directory", THEDP, SLOT( openMLDirectory() ) );
+    }
+    popup->popup( QCursor::pos() );
+}
+
 QSize PlaylistWidget::sizeHint() const
 {
-    fprintf( stderr, "PL Size %ix%i\n", widgetSize.width(), widgetSize.height() );
     return widgetSize;
 }
 
index c084807dc99d4b0614d3035acf709b33f0771bf1..6d467664551a5fb01522f9e7c2b40d385622ecd1 100644 (file)
@@ -93,6 +93,7 @@ private:
 class QSignalMapper;
 class PLSelector;
 class PLPanel;
+class QPushButton;
 
 class PlaylistWidget : public QFrame
 {
@@ -106,8 +107,12 @@ private:
     PLSelector *selector;
     PLPanel *rightPanel;
     intf_thread_t *p_intf;
+    int currentRootId;
+    QPushButton *addButton;
 private slots:
     void undock();
+    void add();
+    void setCurrentRootId( int );
 };
 
 #endif
index 718842be8f67de7bae5efc3c3774f915cd0692dc..5e55081fc71ae995c0828ae9b6282e996034f6e0 100644 (file)
@@ -29,6 +29,7 @@
 #include "components/playlist/panels.hpp"
 #include "components/playlist/selector.hpp"
 #include "dialogs_provider.hpp"
+#include "menus.hpp"
 
 #include <QHBoxLayout>
 #include <QSignalMapper>
@@ -44,9 +45,7 @@ PlaylistDialog::PlaylistDialog( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     setCentralWidget( main );
     setWindowTitle( qtr( "Playlist" ) );
 
-    SDMapper = new QSignalMapper();
-    CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
-    createPlMenuBar( menuBar(), p_intf );
+   createPlMenuBar( menuBar(), p_intf );
 
     selector = new PLSelector( centralWidget(), p_intf, THEPL );
     selector->setMaximumWidth( 130 );
@@ -96,46 +95,7 @@ void PlaylistDialog::createPlMenuBar( QMenuBar *bar, intf_thread_t *p_intf )
 
     manageMenu->addAction( "Dock playlist", this, SLOT( dock() ) );
     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 , triggered(), SDMapper, 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;
+    bar->addMenu( QVLCMenu::SDMenu( p_intf ) );
 }
 
 void PlaylistDialog::dock()
@@ -144,12 +104,3 @@ void PlaylistDialog::dock()
     QEvent *event = new QEvent( (QEvent::Type)(PLDockEvent_Type) );
     QApplication::postEvent( p_intf->p_sys->p_mi, event );
 }
-
-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 13e109afd0d5ee01f5782868265cce225a201ee5..c2ef45a2979f2e7b70787a459993b6888bb632bb 100644 (file)
@@ -48,16 +48,13 @@ public:
 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 dock();
-    void SDMenuAction( QString );
 };
 
 
index 609150dea0f5e5651556c36de98b17535e6114a2..96625c492b5de389c26e811b25d151304aac1b1b 100644 (file)
@@ -51,6 +51,9 @@ DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
     menusUpdateMapper = new QSignalMapper();
     CONNECT( menusUpdateMapper, mapped(QObject *),
              this, menuUpdateAction( QObject *) );
+
+    SDMapper = new QSignalMapper();
+    CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
 }
 
 DialogsProvider::~DialogsProvider()
@@ -187,6 +190,16 @@ void DialogsProvider::menuUpdateAction( QObject *data )
     f->doFunc( p_intf );
 }
 
+void DialogsProvider::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 );
+}
+
+
 void DialogsProvider::simplePLAppendDialog()
 {
     QStringList files = showSimpleOpen();
index 1da6baef43a3cebfa260a9650ff2ddce2b7741bf..d098fd34fe615fb1983a209a655c1ddf30bd149b 100644 (file)
@@ -59,6 +59,7 @@ protected:
     friend class QVLCMenu;
     QSignalMapper *menusMapper;
     QSignalMapper *menusUpdateMapper;
+    QSignalMapper *SDMapper;
     void customEvent( QEvent *);
 private:
     DialogsProvider( intf_thread_t *);
@@ -84,6 +85,7 @@ public slots:
     void doInteraction( intf_dialog_args_t * );
     void menuAction( QObject *);
     void menuUpdateAction( QObject *);
+    void SDMenuAction( QString );
     void streamingDialog();
     void openPlaylist();
     void openDirectory();
index 67d54c3d0660d7f08fdc5f9d516798676643d2c0..b34261bc491f229976d356ba7c1ebd5959120644 100644 (file)
@@ -30,6 +30,7 @@
 #include "dialogs/playlist.hpp"
 #include "menus.hpp"
 
+#include <QMenuBar>
 #include <QCloseEvent>
 #include <QPushButton>
 #include <QStatusBar>
@@ -92,7 +93,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     setWindowTitle( QString::fromUtf8( _("VLC media player") ) );
     handleMainUi( settings );
 
-    QVLCMenu::createMenuBar( menuBar(), p_intf );
+    QVLCMenu::createMenuBar( menuBar(), p_intf, playlistEmbeddedFlag );
 
     /* Status bar */
     timeLabel = new QLabel( 0 );
@@ -444,11 +445,15 @@ void MainInterface::customEvent( QEvent *event )
         playlistWidget = NULL;
         playlistEmbeddedFlag = false;
         doComponentsUpdate();
+        menuBar()->clear();
+        QVLCMenu::createMenuBar( menuBar(), p_intf, false );
     }
     else if( event->type() == PLDockEvent_Type )
     {
         PlaylistDialog::killInstance();
         playlistEmbeddedFlag = true;
+        menuBar()->clear();
+        QVLCMenu::createMenuBar( menuBar(), p_intf, true );
         playlist();
     }
 }
@@ -524,7 +529,7 @@ void MainInterface::play()
     if( !THEPL->i_size || !THEPL->i_enabled )
     {
         /* The playlist is empty, open a file requester */
-        THEDP->openDialog();
+        THEDP->simpleOpenDialog();
         setStatus( 0 );
         return;
     }
index f6424d75db8ebbc4f96a414e96b835cc1c8e3777..6f336ef0d6d802b12390fc34c39f1fa8adb151ba 100644 (file)
@@ -117,9 +117,14 @@ static int AudioAutoMenuBuilder( vlc_object_t *p_object,
     CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
     THEDP->menusUpdateMapper->setMapping( menu, f ); }
 
-void QVLCMenu::createMenuBar( QMenuBar *bar, intf_thread_t *p_intf )
+void QVLCMenu::createMenuBar( QMenuBar *bar, intf_thread_t *p_intf,
+                              bool playlist )
 {
     BAR_ADD( FileMenu(), qtr("File") );
+    if( playlist )
+    {
+        BAR_ADD( PlaylistMenu( p_intf ), qtr("Playlist" ) );
+    }
     BAR_ADD( ToolsMenu( p_intf ), qtr("Tools") );
     BAR_DADD( VideoMenu( p_intf, NULL ), qtr("Video"), 1 );
     BAR_DADD( AudioMenu( p_intf, NULL ), qtr("Audio"), 2 );
@@ -139,6 +144,17 @@ QMenu *QVLCMenu::FileMenu()
     return menu;
 }
 
+QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf )
+{
+    QMenu *menu = new QMenu();
+    menu->addMenu( SDMenu( p_intf ) );
+    menu->addSeparator();
+
+    DP_SADD( qtr( "Open playlist file"), "", "", openPlaylist() );
+//    DP_SADD( qtr( "Save playlist to file" ), "", "", savePlaylist() );
+    return menu;
+}
+
 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf, bool with_intf )
 {
     QMenu *menu = new QMenu();
@@ -242,6 +258,44 @@ QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *current )
     return Populate( p_intf, current, varnames, objects );
 }
 
+QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
+{
+    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 , triggered(), THEDP->SDMapper, map() );
+            THEDP->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;
+}
 
 /*****************************************************************************
  * Popup menus
index 0817abe05065072190769726d2dfb33010b8005c..7e27e62afad0f6003e0d917c45661b55cec1eb2a 100644 (file)
@@ -58,12 +58,12 @@ class QVLCMenu : public QObject
 {
     Q_OBJECT;
 public:
-    static void createMenuBar( QMenuBar *, intf_thread_t * );
-    static void createPlMenuBar( QMenuBar *, intf_thread_t * );
+    static void createMenuBar( QMenuBar *, intf_thread_t *, bool );
 
     /* Menus */
     static QMenu *FileMenu();
     static QMenu *SDMenu( intf_thread_t * );
+    static QMenu *PlaylistMenu( intf_thread_t *);
     static QMenu *ToolsMenu( intf_thread_t *, bool with_intf = true );
     static QMenu *NavigMenu( intf_thread_t * , QMenu * );
     static QMenu *VideoMenu( intf_thread_t * , QMenu * );
@@ -98,14 +98,10 @@ public:
     {
         switch( id )
         {
-        case 1:
-            QVLCMenu::VideoMenu( p_intf, menu ); break;
-        case 2:
-            QVLCMenu::AudioMenu( p_intf, menu ); break;
-        case 3:
-            QVLCMenu::NavigMenu( p_intf, menu ); break;
-        case 4:
-            QVLCMenu::InterfacesMenu( p_intf, menu ); break;
+        case 1: QVLCMenu::VideoMenu( p_intf, menu ); break;
+        case 2: QVLCMenu::AudioMenu( p_intf, menu ); break;
+        case 3: QVLCMenu::NavigMenu( p_intf, menu ); break;
+        case 4: QVLCMenu::InterfacesMenu( p_intf, menu ); break;
         }
     };
     int id; QMenu *menu;