]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/playlist/standardpanel.cpp
The playlist have to be locked when calling playlist_ItemGetById (not tested for...
[vlc] / modules / gui / qt4 / components / playlist / standardpanel.cpp
index d420ac0e518e54bcbbba5be13bb679347784da5b..6b57047e85bbf1533958bc7b98e96d60f01ae121 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
+
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
 
 #include "qt4.hpp"
 #include "dialogs_provider.hpp"
+
 #include "components/playlist/playlist_model.hpp"
 #include "components/playlist/panels.hpp"
 #include "util/customwidgets.hpp"
@@ -44,7 +46,6 @@
 #include <QSpacerItem>
 #include <QMenu>
 #include <QSignalMapper>
-
 #include <assert.h>
 
 #include "sorting.h"
@@ -61,10 +62,10 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
     layout->setSpacing( 0 ); layout->setMargin( 0 );
 
     /* Create and configure the QTreeView */
-    view = new QVLCTreeView( 0 );
+    view = new QVLCTreeView;
+    view->header()->setSortIndicator( 0 , Qt::AscendingOrder );
     view->setSortingEnabled( true );
-    view->sortByColumn( -1, Qt::AscendingOrder );
-    view->setModel(model);
+    view->setModel( model );
     view->setIconSize( QSize( 20, 20 ) );
     view->setAlternatingRowColors( true );
     view->setAnimated( true );
@@ -74,12 +75,23 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
     view->setDropIndicatorShown( true );
     view->setAutoScroll( true );
 
-    /* Configure the size of the header */
-    view->header()->resizeSection( 0, 200 );
-    view->header()->resizeSection( 1, 80 );
+
+    getSettings()->beginGroup("Playlist");
+    if( getSettings()->contains( "headerState" ) )
+    {
+        view->header()->restoreState(
+                getSettings()->value( "headerState" ).toByteArray() );
+    }
+    else
+    {
+        /* Configure the size of the header */
+        view->header()->resizeSection( 0, 200 );
+        view->header()->resizeSection( 1, 80 );
+    }
     view->header()->setSortIndicatorShown( true );
     view->header()->setClickable( true );
     view->header()->setContextMenuPolicy( Qt::CustomContextMenu );
+    getSettings()->endGroup();
 
     /* Connections for the TreeView */
     CONNECT( view, activated( const QModelIndex& ) ,
@@ -99,7 +111,7 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
 
     /* Add item to the playlist button */
     addButton = new QPushButton;
-    addButton->setIcon( QIcon( ":/pixmaps/playlist_add.png" ) );
+    addButton->setIcon( QIcon( ":/playlist_add" ) );
     addButton->setMaximumWidth( 30 );
     BUTTONACT( addButton, popupAdd() );
     buttons->addWidget( addButton );
@@ -108,12 +120,12 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
     randomButton = new QPushButton( this );
     if( model->hasRandom() )
     {
-        randomButton->setIcon( QIcon( ":/pixmaps/playlist_shuffle_on.png" ));
+        randomButton->setIcon( QIcon( ":/shuffle_on" ));
         randomButton->setToolTip( qtr( I_PL_RANDOM ));
     }
     else
     {
-         randomButton->setIcon( QIcon( ":/pixmaps/playlist_shuffle_off.png" ) );
+         randomButton->setIcon( QIcon( ":/shuffle_off" ) );
          randomButton->setToolTip( qtr( I_PL_NORANDOM ));
     }
     BUTTONACT( randomButton, toggleRandom() );
@@ -123,26 +135,26 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
     repeatButton = new QPushButton( this );
     if( model->hasRepeat() )
     {
-        repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_one.png" ) );
+        repeatButton->setIcon( QIcon( ":/repeat_one" ) );
         repeatButton->setToolTip( qtr( I_PL_REPEAT ));
     }
     else if( model->hasLoop() )
     {
-        repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_all.png" ) );
+        repeatButton->setIcon( QIcon( ":/repeat_all" ) );
         repeatButton->setToolTip( qtr( I_PL_LOOP ));
     }
     else
     {
-        repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_off.png" ) );
+        repeatButton->setIcon( QIcon( ":/repeat_off" ) );
         repeatButton->setToolTip( qtr( I_PL_NOREPEAT ));
     }
     BUTTONACT( repeatButton, toggleRepeat() );
     buttons->addWidget( repeatButton );
 
     /* Goto */
-    gotoPlayingButton = new QPushButton( "X" , this );
-    gotoPlayingButton->setToolTip( qtr( "Show the current item" ));
-    BUTTONACT( gotoPlayingButton, gotoPlayingItem() );
+    gotoPlayingButton = new QPushButton;
+    BUTTON_SET_ACT_I( gotoPlayingButton, "", jump_to,
+            qtr( "Show the current item" ), gotoPlayingItem() );
     buttons->addWidget( gotoPlayingButton );
 
     /* A Spacer and the search possibilities */
@@ -152,17 +164,10 @@ 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 );
-
-    QPushButton *clear = new QPushButton;
-    clear->setText( qfu( "CL") );
-    clear->setMaximumWidth( 30 );
-    clear->setToolTip( qtr( "Clear" ));
-    BUTTONACT( clear, clearFilter() );
-    buttons->addWidget( clear );
+    SearchLineEdit *search = new SearchLineEdit( this );
+    buttons->addWidget( search );
+    filter->setBuddy( search );
+    CONNECT( search, textChanged( QString ), this, search( QString ) );
 
     /* Finish the layout */
     layout->addWidget( view );
@@ -177,19 +182,19 @@ void StandardPLPanel::toggleRepeat()
     if( model->hasRepeat() )
     {
         model->setRepeat( false ); model->setLoop( true );
-        repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_all.png" ) );
+        repeatButton->setIcon( QIcon( ":/repeat_all" ) );
         repeatButton->setToolTip( qtr( I_PL_LOOP ));
     }
     else if( model->hasLoop() )
     {
         model->setRepeat( false ) ; model->setLoop( false );
-        repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_off.png" ) );
+        repeatButton->setIcon( QIcon( ":/repeat_off" ) );
         repeatButton->setToolTip( qtr( I_PL_NOREPEAT ));
     }
     else
     {
         model->setRepeat( true );
-        repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_one.png" ) );
+        repeatButton->setIcon( QIcon( ":/repeat_one" ) );
         repeatButton->setToolTip( qtr( I_PL_REPEAT ));
     }
 }
@@ -200,8 +205,8 @@ void StandardPLPanel::toggleRandom()
     bool prev = model->hasRandom();
     model->setRandom( !prev );
     randomButton->setIcon( prev ?
-                QIcon( ":/pixmaps/playlist_shuffle_off.png" ) :
-                QIcon( ":/pixmaps/playlist_shuffle_on.png" ) );
+                QIcon( ":/shuffle_off" ) :
+                QIcon( ":/shuffle_on" ) );
     randomButton->setToolTip( prev ? qtr( I_PL_NORANDOM ) : qtr(I_PL_RANDOM ) );
 }
 
@@ -244,8 +249,7 @@ 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(simplePLAppendDialog()));
-        popup.addAction( qtr(I_PL_ADVADD), THEDP, SLOT(PLAppendDialog()) );
+        popup.addAction( qtr(I_PL_ADDF), THEDP, SLOT(PLAppendDialog()) );
         popup.addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) );
     }
     else if( ( THEPL->p_ml_category &&
@@ -253,8 +257,7 @@ void StandardPLPanel::popupAdd()
              ( THEPL->p_ml_onelevel &&
                 currentRootId == THEPL->p_ml_onelevel->i_id ) )
     {
-        popup.addAction( qtr(I_PL_ADDF), THEDP, SLOT(simpleMLAppendDialog()));
-        popup.addAction( qtr(I_PL_ADVADD), THEDP, SLOT( MLAppendDialog() ) );
+        popup.addAction( qtr(I_PL_ADDF), THEDP, SLOT( MLAppendDialog() ) );
         popup.addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
     }
     popup.exec( QCursor::pos() - addButton->mapFromGlobal( QCursor::pos() )
@@ -267,37 +270,22 @@ void StandardPLPanel::popupSelectColumn( QPoint pos )
 
     QMenu selectColMenu;
 
-    char *psz_title;
-#define ADD_META_ACTION( meta ) {                                              \
-    QAction* option = selectColMenu.addAction( psz_column_title( meta ) );     \
-    option->setCheckable( true );                                              \
-    option->setChecked( model->shownFlags() & meta );                          \
-    ContextUpdateMapper->setMapping( option, meta );                           \
-    CONNECT( option, triggered(), ContextUpdateMapper, map() );                \
-}
-
     CONNECT( ContextUpdateMapper, mapped( int ),  model, viewchanged( int ) );
 
-    ADD_META_ACTION( COLUMN_NUMBER );
-    ADD_META_ACTION( COLUMN_TITLE );
-    ADD_META_ACTION( COLUMN_DURATION );
-    ADD_META_ACTION( COLUMN_ARTIST );
-    ADD_META_ACTION( COLUMN_GENRE );
-    ADD_META_ACTION( COLUMN_ALBUM );
-    ADD_META_ACTION( COLUMN_TRACK_NUMBER );
-    ADD_META_ACTION( COLUMN_DESCRIPTION );
-
-#undef ADD_META_ACTION
+    int i_column = 1;
+    for( i_column = 1; i_column != COLUMN_END; i_column<<=1 )
+    {
+        QAction* option = selectColMenu.addAction(
+            qfu( psz_column_title( i_column ) ) );
+        option->setCheckable( true );
+        option->setChecked( model->shownFlags() & i_column );
+        ContextUpdateMapper->setMapping( option, i_column );
+        CONNECT( option, triggered(), ContextUpdateMapper, map() );
+    }
 
     selectColMenu.exec( QCursor::pos() );
 }
 
-/* ClearFilter LineEdit */
-void StandardPLPanel::clearFilter()
-{
-    searchLine->setText( "" );
-}
-
 /* Search in the playlist */
 void StandardPLPanel::search( QString searchText )
 {
@@ -316,11 +304,13 @@ void StandardPLPanel::doPopup( QModelIndex index, QPoint point )
 /* This activated by the selector selection */
 void StandardPLPanel::setRoot( int i_root_id )
 {
-    playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id,
-                                                    true );
+    QPL_LOCK;
+    playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id );
     assert( p_item );
     p_item = playlist_GetPreferredNode( THEPL, p_item );
     assert( p_item );
+    QPL_UNLOCK;
+
     model->rebuild( p_item );
 }
 
@@ -350,4 +340,10 @@ void StandardPLPanel::deleteSelection()
 }
 
 StandardPLPanel::~StandardPLPanel()
-{}
+{
+    getSettings()->beginGroup("Playlist");
+    getSettings()->setValue( "headerState", view->header()->saveState() );
+    getSettings()->endGroup();
+}
+
+