]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/playlist/standardpanel.cpp
Qt4: remove proto combo from open net tab
[vlc] / modules / gui / qt4 / components / playlist / standardpanel.cpp
index 767169bbf4716dc1968f1651b1c7d83c61eaecd9..aac73277d429ca4b2653e952bb5bc70f48bb31f7 100644 (file)
 
 #include "qt4.hpp"
 #include "dialogs_provider.hpp"
+
 #include "components/playlist/playlist_model.hpp"
 #include "components/playlist/panels.hpp"
 #include "util/customwidgets.hpp"
 
 #include <vlc_intf_strings.h>
 
-#include <QTreeView>
 #include <QPushButton>
 #include <QHBoxLayout>
 #include <QVBoxLayout>
 #include <QHeaderView>
 #include <QKeyEvent>
 #include <QModelIndexList>
-#include <QToolBar>
 #include <QLabel>
 #include <QSpacerItem>
 #include <QMenu>
 #include <QSignalMapper>
-
 #include <assert.h>
 
 #include "sorting.h"
@@ -56,24 +54,25 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
                                   playlist_item_t *p_root ):
                                   PLPanel( _parent, _p_intf )
 {
-    model = new PLModel( p_playlist, p_intf, p_root, -1, this );
+    model = new PLModel( p_playlist, p_intf, p_root, this );
 
     QVBoxLayout *layout = new QVBoxLayout();
     layout->setSpacing( 0 ); layout->setMargin( 0 );
 
     /* Create and configure the QTreeView */
-    view = new QVLCTreeView( 0 );
-    view->header()->setSortIndicator( 0 , Qt::AscendingOrder );
-    view->setSortingEnabled( true );
+    view = new QVLCTreeView;
     view->setModel( model );
     view->setIconSize( QSize( 20, 20 ) );
     view->setAlternatingRowColors( true );
     view->setAnimated( true );
+    view->setSelectionBehavior( QAbstractItemView::SelectRows );
     view->setSelectionMode( QAbstractItemView::ExtendedSelection );
     view->setDragEnabled( true );
     view->setAcceptDrops( true );
     view->setDropIndicatorShown( true );
-    view->setAutoScroll( true );
+    view->header()->setSortIndicator( -1 , Qt::AscendingOrder );
+    view->setUniformRowHeights( true );
+    view->setSortingEnabled( true );
 
 
     getSettings()->beginGroup("Playlist");
@@ -84,9 +83,13 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
     }
     else
     {
-        /* Configure the size of the header */
-        view->header()->resizeSection( 0, 200 );
-        view->header()->resizeSection( 1, 80 );
+        int m, c;
+        for( m = 1, c = 0; m != COLUMN_END; m <<= 1, c++ )
+        {
+            view->setColumnHidden( c, !( m & COLUMN_DEFAULT ) );
+            if( m == COLUMN_TITLE ) view->header()->resizeSection( c, 200 );
+            else if( m == COLUMN_DURATION ) view->header()->resizeSection( c, 80 );
+        }
     }
     view->header()->setSortIndicatorShown( true );
     view->header()->setClickable( true );
@@ -98,62 +101,58 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
              model,activateItem( const QModelIndex& ) );
     CONNECT( view, rightClicked( QModelIndex , QPoint ),
              this, doPopup( QModelIndex, QPoint ) );
-    CONNECT( model, dataChanged( const QModelIndex&, const QModelIndex& ),
-             this, handleExpansion( const QModelIndex& ) );
     CONNECT( view->header(), customContextMenuRequested( const QPoint & ),
              this, popupSelectColumn( QPoint ) );
+    CONNECT( model, currentChanged( const QModelIndex& ),
+             this, handleExpansion( const QModelIndex& ) );
 
     currentRootId = -1;
-    CONNECT( parent, rootChanged( int ), this, setCurrentRootId( int ) );
 
     /* Buttons configuration */
     QHBoxLayout *buttons = new QHBoxLayout;
 
     /* Add item to the playlist button */
     addButton = new QPushButton;
-    addButton->setIcon( QIcon( ":/playlist_add" ) );
+    addButton->setIcon( QIcon( ":/buttons/playlist/playlist_add" ) );
     addButton->setMaximumWidth( 30 );
     BUTTONACT( addButton, popupAdd() );
     buttons->addWidget( addButton );
 
     /* Random 2-state button */
     randomButton = new QPushButton( this );
-    if( model->hasRandom() )
-    {
-        randomButton->setIcon( QIcon( ":/shuffle_on" ));
-        randomButton->setToolTip( qtr( I_PL_RANDOM ));
-    }
-    else
-    {
-         randomButton->setIcon( QIcon( ":/shuffle_off" ) );
-         randomButton->setToolTip( qtr( I_PL_NORANDOM ));
-    }
+    randomButton->setIcon( QIcon( ":/buttons/playlist/shuffle_on" ));
+    randomButton->setToolTip( qtr( I_PL_RANDOM ));
+    randomButton->setCheckable( true );
+    randomButton->setChecked( model->hasRandom() );
     BUTTONACT( randomButton, toggleRandom() );
     buttons->addWidget( randomButton );
 
     /* Repeat 3-state button */
     repeatButton = new QPushButton( this );
+    repeatButton->setToolTip( qtr( "Click to toggle between loop one, loop all" ) );
+    repeatButton->setCheckable( true );
+
     if( model->hasRepeat() )
     {
-        repeatButton->setIcon( QIcon( ":/repeat_one" ) );
-        repeatButton->setToolTip( qtr( I_PL_REPEAT ));
+        repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_one" ) );
+        repeatButton->setChecked( true );
     }
     else if( model->hasLoop() )
     {
-        repeatButton->setIcon( QIcon( ":/repeat_all" ) );
-        repeatButton->setToolTip( qtr( I_PL_LOOP ));
+        repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_all" ) );
+        repeatButton->setChecked( true );
     }
     else
     {
-        repeatButton->setIcon( QIcon( ":/repeat_off" ) );
-        repeatButton->setToolTip( qtr( I_PL_NOREPEAT ));
+        repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_one" ) );
+        repeatButton->setChecked( false );
     }
     BUTTONACT( repeatButton, toggleRepeat() );
     buttons->addWidget( repeatButton );
 
     /* Goto */
     gotoPlayingButton = new QPushButton;
-    BUTTON_SET_ACT_I( gotoPlayingButton, "", jump_to,
+    BUTTON_SET_ACT_I( gotoPlayingButton, "", buttons/playlist/jump_to,
             qtr( "Show the current item" ), gotoPlayingItem() );
     buttons->addWidget( gotoPlayingButton );
 
@@ -164,21 +163,27 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
     QLabel *filter = new QLabel( qtr(I_PL_SEARCH) + " " );
     buttons->addWidget( filter );
 
-    searchLine = new  ClickLineEdit( qtr(I_PL_FILTER), 0 );
-    searchLine->setMinimumWidth( 80 );
-    CONNECT( searchLine, textChanged(QString), this, search(QString));
-    buttons->addWidget( searchLine ); filter->setBuddy( searchLine );
+    SearchLineEdit *search = new SearchLineEdit( this );
+    buttons->addWidget( search );
+    filter->setBuddy( search );
+    CONNECT( search, textChanged( const QString& ), this, search( const QString& ) );
 
-    QPushButton *clear = new QPushButton;
-    clear->setMaximumWidth( 30 );
-    BUTTON_SET_ACT_I( clear, "", clear, qtr( "Clear" ), clearFilter() );
-    buttons->addWidget( clear );
+    /* Title label */
+    title = new QLabel;
+    QFont titleFont;
+    titleFont.setPointSize( titleFont.pointSize() + 6 );
+    titleFont.setFamily( "Verdana" );
+    title->setFont( titleFont );
 
     /* Finish the layout */
+    layout->addWidget( title );
     layout->addWidget( view );
     layout->addLayout( buttons );
 //    layout->addWidget( bar );
     setLayout( layout );
+
+    selectColumnsSigMapper = new QSignalMapper( this );
+    CONNECT( selectColumnsSigMapper, mapped( int ), this, toggleColumnShown( int ) );
 }
 
 /* Function to toggle between the Repeat states */
@@ -187,20 +192,20 @@ void StandardPLPanel::toggleRepeat()
     if( model->hasRepeat() )
     {
         model->setRepeat( false ); model->setLoop( true );
-        repeatButton->setIcon( QIcon( ":/repeat_all" ) );
-        repeatButton->setToolTip( qtr( I_PL_LOOP ));
+        repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_all" ) );
+        repeatButton->setChecked( true );
     }
     else if( model->hasLoop() )
     {
         model->setRepeat( false ) ; model->setLoop( false );
-        repeatButton->setIcon( QIcon( ":/repeat_off" ) );
-        repeatButton->setToolTip( qtr( I_PL_NOREPEAT ));
+        repeatButton->setChecked( false );
+        repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_one" ) );
     }
     else
     {
-        model->setRepeat( true );
-        repeatButton->setIcon( QIcon( ":/repeat_one" ) );
-        repeatButton->setToolTip( qtr( I_PL_REPEAT ));
+        model->setRepeat( true ); model->setLoop( false );
+        repeatButton->setChecked( true );
+        repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_one" ) );
     }
 }
 
@@ -209,42 +214,16 @@ void StandardPLPanel::toggleRandom()
 {
     bool prev = model->hasRandom();
     model->setRandom( !prev );
-    randomButton->setIcon( prev ?
-                QIcon( ":/shuffle_off" ) :
-                QIcon( ":/shuffle_on" ) );
-    randomButton->setToolTip( prev ? qtr( I_PL_NORANDOM ) : qtr(I_PL_RANDOM ) );
 }
 
 void StandardPLPanel::gotoPlayingItem()
 {
-    view->scrollTo( view->currentIndex() );
+    view->scrollTo( model->currentIndex() );
 }
 
-void StandardPLPanel::handleExpansion( const QModelIndex &index )
+void StandardPLPanel::handleExpansion( const QModelIndexindex )
 {
-    if( model->isCurrent( index ) )
-        view->scrollTo( index, QAbstractItemView::EnsureVisible );
-}
-
-void StandardPLPanel::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(I_PL_ADDPL) );
-    }
-    else if( ( THEPL->p_ml_category &&
-                        currentRootId == THEPL->p_ml_category->i_id ) ||
-             ( THEPL->p_ml_onelevel &&
-                        currentRootId == THEPL->p_ml_onelevel->i_id ) )
-    {
-        addButton->setEnabled( true );
-        addButton->setToolTip( qtr(I_PL_ADDML) );
-    }
-    else
-        addButton->setEnabled( false );
+    view->scrollTo( index );
 }
 
 /* PopupAdd Menu for the Add Menu */
@@ -254,58 +233,56 @@ void StandardPLPanel::popupAdd()
     if( currentRootId == THEPL->p_local_category->i_id ||
         currentRootId == THEPL->p_local_onelevel->i_id )
     {
-        popup.addAction( qtr(I_PL_ADDF), THEDP, SLOT(PLAppendDialog()) );
+        popup.addAction( qtr(I_PL_ADDF), THEDP, SLOT( simplePLAppendDialog()) );
         popup.addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) );
+        popup.addAction( qtr(I_OP_ADVOP), THEDP, SLOT( PLAppendDialog()) );
     }
     else if( ( THEPL->p_ml_category &&
                 currentRootId == THEPL->p_ml_category->i_id ) ||
              ( THEPL->p_ml_onelevel &&
                 currentRootId == THEPL->p_ml_onelevel->i_id ) )
     {
-        popup.addAction( qtr(I_PL_ADDF), THEDP, SLOT( MLAppendDialog() ) );
+        popup.addAction( qtr(I_PL_ADDF), THEDP, SLOT( simpleMLAppendDialog()) );
         popup.addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
+        popup.addAction( qtr(I_OP_ADVOP), THEDP, SLOT( MLAppendDialog() ) );
     }
+
     popup.exec( QCursor::pos() - addButton->mapFromGlobal( QCursor::pos() )
                         + QPoint( 0, addButton->height() ) );
 }
 
 void StandardPLPanel::popupSelectColumn( QPoint pos )
 {
-    ContextUpdateMapper = new QSignalMapper(this);
-
-    QMenu selectColMenu;
-
-    CONNECT( ContextUpdateMapper, mapped( int ),  model, viewchanged( int ) );
+    QMenu menu;
 
-    int i_column = 1;
-    for( i_column = 1; i_column != COLUMN_END; i_column<<=1 )
+    /* We do not offer the option to hide index 0 column, or
+    * QTreeView will behave weird */
+    int i, j;
+    for( i = 1 << 1, j = 1; i < COLUMN_END; i <<= 1, j++ )
     {
-        QAction* option = selectColMenu.addAction(
-            qfu( psz_column_title( i_column ) ) );
+        QAction* option = menu.addAction(
+            qfu( psz_column_title( i ) ) );
         option->setCheckable( true );
-        option->setChecked( model->shownFlags() & i_column );
-        ContextUpdateMapper->setMapping( option, i_column );
-        CONNECT( option, triggered(), ContextUpdateMapper, map() );
+        option->setChecked( !view->isColumnHidden( j ) );
+        selectColumnsSigMapper->setMapping( option, j );
+        CONNECT( option, triggered(), selectColumnsSigMapper, map() );
     }
-
-    selectColMenu.exec( QCursor::pos() );
+    menu.exec( QCursor::pos() );
 }
 
-/* ClearFilter LineEdit */
-void StandardPLPanel::clearFilter()
+void StandardPLPanel::toggleColumnShown( int i )
 {
-    searchLine->setText( "" );
+    view->setColumnHidden( i, !view->isColumnHidden( i ) );
 }
 
 /* Search in the playlist */
-void StandardPLPanel::search( QString searchText )
+void StandardPLPanel::search( const QString& searchText )
 {
     model->search( searchText );
 }
 
 void StandardPLPanel::doPopup( QModelIndex index, QPoint point )
 {
-    if( !index.isValid() ) return;
     QItemSelectionModel *selection = view->selectionModel();
     QModelIndexList list = selection->selectedIndexes();
     model->popup( index, point, list );
@@ -313,17 +290,42 @@ void StandardPLPanel::doPopup( QModelIndex index, QPoint point )
 
 /* Set the root of the new Playlist */
 /* This activated by the selector selection */
-void StandardPLPanel::setRoot( int i_root_id )
+void StandardPLPanel::setRoot( playlist_item_t *p_item )
 {
     QPL_LOCK;
-    playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id,
-                                                    pl_Locked );
-    assert( p_item );
-    p_item = playlist_GetPreferredNode( THEPL, p_item );
     assert( p_item );
+
+    playlist_item_t *p_pref_item = playlist_GetPreferredNode( THEPL, p_item );
+    if( p_pref_item ) p_item = p_pref_item;
+
+    /* needed for popupAdd() */
+    currentRootId = p_item->i_id;
+
+    /* cosmetics, ..still need playlist locking.. */
+    char *psz_title = input_item_GetName( p_item->p_input );
+    title->setText( qfu(psz_title) );
+    free( psz_title );
+
     QPL_UNLOCK;
 
+    /* do THE job */
     model->rebuild( p_item );
+
+    /* enable/disable adding */
+    if( p_item == THEPL->p_local_category ||
+        p_item == THEPL->p_local_onelevel )
+    {
+        addButton->setEnabled( true );
+        addButton->setToolTip( qtr(I_PL_ADDPL) );
+    }
+    else if( ( THEPL->p_ml_category && p_item == THEPL->p_ml_category) ||
+              ( THEPL->p_ml_onelevel && p_item == THEPL->p_ml_onelevel ) )
+    {
+        addButton->setEnabled( true );
+        addButton->setToolTip( qtr(I_PL_ADDML) );
+    }
+    else
+        addButton->setEnabled( false );
 }
 
 void StandardPLPanel::removeItem( int i_id )
@@ -358,4 +360,3 @@ StandardPLPanel::~StandardPLPanel()
     getSettings()->endGroup();
 }
 
-