]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/playlist/playlist.cpp
Qt: rename playlist root* functions and getters for clarity
[vlc] / modules / gui / qt4 / components / playlist / playlist.cpp
index 79fb57f9e483a3eed17a83bc004db327d808ae4b..382a7efc7d15d50d399ed0c86aaa0984198c644f 100644 (file)
@@ -30,6 +30,7 @@
 #include "components/playlist/standardpanel.hpp"  /* MainView */
 #include "components/playlist/selector.hpp"       /* PLSelector */
 #include "components/playlist/playlist_model.hpp" /* PLModel */
+#include "components/playlist/ml_model.hpp"       /* MLModel */
 #include "components/interface_widgets.hpp"       /* CoverArtLabel */
 
 #include "util/searchlineedit.hpp"
@@ -39,6 +40,8 @@
 
 #include <QMenu>
 #include <QSignalMapper>
+#include <QSlider>
+#include <QStackedWidget>
 
 /**********************************************************************
  * Playlist Widget. The embedded playlist
@@ -51,6 +54,7 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par )
     setContentsMargins( 0, 3, 0, 3 );
 
     QGridLayout *layout = new QGridLayout( this );
+    layout->setMargin( 0 ); layout->setSpacing( 0 );
 
     /*******************
      * Left            *
@@ -64,16 +68,13 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par )
 
     /* Create a Container for the Art Label
        in order to have a beautiful resizing for the selector above it */
-    QWidget *artContainer = new QWidget;
-    QHBoxLayout *artContLay = new QHBoxLayout( artContainer );
-    artContLay->setMargin( 0 );
-    artContLay->setSpacing( 0 );
+    artContainer = new QStackedWidget;
     artContainer->setMaximumHeight( 128 );
 
     /* Art label */
     CoverArtLabel *art = new CoverArtLabel( artContainer, p_intf );
     art->setToolTip( qtr( "Double click to get media information" ) );
-    artContLay->addWidget( art, 1 );
+    artContainer->addWidget( art );
 
     CONNECT( THEMIM->getIM(), artChanged( QString ),
              art, showArtUpdate( const QString& ) );
@@ -86,13 +87,18 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par )
     /* Initialisation of the playlist */
     playlist_t * p_playlist = THEPL;
     PL_LOCK;
-    playlist_item_t *p_root = THEPL->p_playing;
+    playlist_item_t *p_root = p_playlist->p_playing;
     PL_UNLOCK;
 
-    setMinimumWidth( 350 );
+    setMinimumWidth( 400 );
 
-    PLModel *model = new PLModel( p_playlist, p_intf, p_root, this );
-    mainView = new StandardPLPanel( this, p_intf, p_root, selector, model );
+    PLModel *model = PLModel::getPLModel( p_intf );
+#ifdef MEDIA_LIBRARY
+    MLModel *mlmodel = new MLModel( p_intf, this );
+    mainView = new StandardPLPanel( this, p_intf, p_root, selector, model, mlmodel );
+#else
+    mainView = new StandardPLPanel( this, p_intf, p_root, selector, model, NULL );
+#endif
 
     /* Location Bar */
     locationBar = new LocationBar( model );
@@ -102,11 +108,15 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par )
     CONNECT( locationBar, invoked( const QModelIndex & ),
              mainView, browseInto( const QModelIndex & ) );
 
+    QHBoxLayout *topbarLayout = new QHBoxLayout();
+    layout->addLayout( topbarLayout, 0, 1 );
+    topbarLayout->setSpacing( 10 );
+
     /* Button to switch views */
     QToolButton *viewButton = new QToolButton( this );
     viewButton->setIcon( style()->standardIcon( QStyle::SP_FileDialogDetailedView ) );
     viewButton->setToolTip( qtr("Change playlistview") );
-    layout->addWidget( viewButton, 0, 2 );
+    topbarLayout->addWidget( viewButton );
 
     /* View selection menu */
     QSignalMapper *viewSelectionMapper = new QSignalMapper( this );
@@ -114,7 +124,12 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par )
 
     QActionGroup *actionGroup = new QActionGroup( this );
 
-    for( int i = 0; i < StandardPLPanel::VIEW_COUNT; i++ )
+#ifndef NDEBUG
+# define MAX_VIEW StandardPLPanel::VIEW_COUNT
+#else
+# define MAX_VIEW StandardPLPanel::VIEW_COUNT - 1
+#endif
+    for( int i = 0; i < MAX_VIEW; i++ )
     {
         viewActions[i] = actionGroup->addAction( viewNames[i] );
         viewActions[i]->setCheckable( true );
@@ -132,21 +147,23 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par )
     searchEdit = new SearchLineEdit( this );
     searchEdit->setMaximumWidth( 250 );
     searchEdit->setMinimumWidth( 80 );
-    layout->addWidget( searchEdit, 0, 3 );
-    CONNECT( searchEdit, textEdited( const QString& ),
+    searchEdit->setToolTip( qtr("Search the playlist") );
+    topbarLayout->addWidget( searchEdit );
+    CONNECT( searchEdit, textChanged( const QString& ),
              mainView, search( const QString& ) );
     CONNECT( searchEdit, searchDelayedChanged( const QString& ),
              mainView, searchDelayed( const QString & ) );
+
     CONNECT( mainView, viewChanged( const QModelIndex& ),
              this, changeView( const QModelIndex &) );
-    layout->setColumnStretch( 3, 3 );
 
     /* Connect the activation of the selector to a redefining of the PL */
-    DCONNECT( selector, activated( playlist_item_t * ),
-              mainView, setRoot( playlist_item_t * ) );
+    DCONNECT( selector, categoryActivated( playlist_item_t *, bool ),
+              mainView, setRootItem( playlist_item_t *, bool ) );
+    mainView->setRootItem( p_root, false );
 
-
-    split = new QSplitter(this);
+    /* */
+    split = new PlaylistSplitter( this );
 
     /* Add the two sides of the QSplitter */
     split->addWidget( leftSplitter );
@@ -169,6 +186,7 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par )
     getSettings()->endGroup();
 
     layout->addWidget( split, 1, 0, 1, -1 );
+
     setAcceptDrops( true );
     setWindowTitle( qtr( "Playlist" ) );
     setWindowRole( "vlc-playlist" );
@@ -227,7 +245,7 @@ void PlaylistWidget::changeView( const QModelIndex& index )
 {
     searchEdit->clear();
     locationBar->setIndex( index );
-    int i = mainView->getViewNumber();
+    int i = mainView->currentViewIndex();
     viewActions[i]->setChecked(true);
 }
 
@@ -258,9 +276,15 @@ void LocationBar::setIndex( const QModelIndex &index )
     while( true )
     {
         PLItem *item = model->getItem( i );
+        QString text;
 
-        char *fb_name = input_item_GetTitleFbName( item->inputItem() );
-        QString text = qfu(fb_name);
+        char *fb_name = input_item_GetTitle( item->inputItem() );
+        if( EMPTY_STR( fb_name ) )
+        {
+            free( fb_name );
+            fb_name = input_item_GetName( item->inputItem() );
+        }
+        text = qfu(fb_name);
         free(fb_name);
 
         QAbstractButton *btn = new LocationButton( text, first, !first, this );
@@ -361,7 +385,7 @@ QSize LocationBar::sizeHint() const
 
 LocationButton::LocationButton( const QString &text, bool bold,
                                 bool arrow, QWidget * parent )
-  : b_arrow( arrow ), QPushButton( parent )
+  : QPushButton( parent ), b_arrow( arrow )
 {
     QFont font;
     font.setBold( bold );
@@ -371,7 +395,7 @@ LocationButton::LocationButton( const QString &text, bool bold,
 
 #define PADDING 4
 
-void LocationButton::paintEvent ( QPaintEvent * event )
+void LocationButton::paintEvent ( QPaintEvent * )
 {
     QStyleOptionButton option;
     option.initFrom( this );
@@ -420,7 +444,7 @@ QSize LocationButton::sizeHint() const
 #undef PADDING
 
 #ifdef Q_WS_MAC
-QSplitterHandle *PlaylistWidget::createHandle()
+QSplitterHandle *PlaylistSplitter::createHandle()
 {
     return new SplitterHandle( orientation(), this );
 }