/*****************************************************************************
* standardpanel.cpp : The "standard" playlist panel : just a treeview
****************************************************************************
- * Copyright (C) 2000-2005 the VideoLAN team
+ * Copyright (C) 2000-2009 VideoLAN
* $Id$
*
* Authors: Clément Stenac <zorglub@videolan.org>
+ * JB Kempf <jb@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
-#include "qt4.hpp"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include "dialogs_provider.hpp"
-#include "playlist_model.hpp"
-#include "components/playlist/panels.hpp"
+
+#include "components/playlist/playlist_model.hpp"
+#include "components/playlist/standardpanel.hpp"
+#include "components/playlist/icon_view.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 <QWheelEvent>
#include <assert.h>
+#include "sorting.h"
+
StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
intf_thread_t *_p_intf,
playlist_t *p_playlist,
playlist_item_t *p_root ):
- PLPanel( _parent, _p_intf )
+ QWidget( _parent ), p_intf( _p_intf )
{
- model = new PLModel( p_playlist, p_intf, p_root, -1, this );
-
- /* Create and configure the QTreeView */
- view = new QVLCTreeView( 0 );
- view->setModel(model);
- view->setIconSize( QSize(20,20) );
- view->setAlternatingRowColors( true );
- view->setAnimated( true );
- view->setSortingEnabled( true );
- view->setSelectionMode( QAbstractItemView::ExtendedSelection );
- view->setDragEnabled( true );
- view->setAcceptDrops( true );
- view->setDropIndicatorShown( true );
- view->setAutoScroll( true );
-
- view->header()->resizeSection( 0, 230 );
- view->header()->resizeSection( 1, 170 );
- view->header()->setSortIndicatorShown( true );
- view->header()->setClickable( true );
- view->header()->setContextMenuPolicy( Qt::CustomContextMenu );
-
- CONNECT( view, activated( const QModelIndex& ) ,
- 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 ) );
+ layout = new QGridLayout( this );
+ layout->setSpacing( 0 ); layout->setMargin( 0 );
+ setMinimumWidth( 300 );
- currentRootId = -1;
- CONNECT( parent, rootChanged(int), this, setCurrentRootId( int ) );
+ model = new PLModel( p_playlist, p_intf, p_root, this );
- QVBoxLayout *layout = new QVBoxLayout();
- layout->setSpacing( 0 ); layout->setMargin( 0 );
+ iconView = NULL;
+ treeView = NULL;
- /* Buttons configuration */
- QHBoxLayout *buttons = new QHBoxLayout();
-
- addButton = new QPushButton( QIcon( ":/pixmaps/playlist_add.png" ), "", this );
- addButton->setMaximumWidth( 25 );
- BUTTONACT( addButton, popupAdd() );
- buttons->addWidget( addButton );
-
- randomButton = new QPushButton( this );
- randomButton->setIcon( model->hasRandom() ?
- QIcon( ":/pixmaps/playlist_shuffle_on.png" ) :
- QIcon( ":/pixmaps/playlist_shuffle_off.png" ) );
- BUTTONACT( randomButton, toggleRandom() );
- buttons->addWidget( randomButton );
-
- QSpacerItem *spacer = new QSpacerItem( 10, 20 );
- buttons->addItem( spacer );
-
- repeatButton = new QPushButton( this );
- if( model->hasRepeat() ) repeatButton->setIcon(
- QIcon( ":/pixmaps/playlist_repeat_one.png" ) );
- else if( model->hasLoop() ) repeatButton->setIcon(
- QIcon( ":/pixmaps/playlist_repeat_all.png" ) );
- else repeatButton->setIcon(
- QIcon( ":/pixmaps/playlist_repeat_off.png" ) );
- BUTTONACT( repeatButton, toggleRepeat() );
- buttons->addWidget( repeatButton );
-
-
- QLabel *filter = new QLabel( qtr(I_PL_SEARCH) + " " );
- buttons->addWidget( filter );
- searchLine = new ClickLineEdit( qtr(I_PL_FILTER), 0 );
- CONNECT( searchLine, textChanged(QString), this, search(QString));
- buttons->addWidget( searchLine ); filter->setBuddy( searchLine );
-
- QPushButton *clear = new QPushButton( qfu( "CL") );
- clear->setMaximumWidth( 30 );
- BUTTONACT( clear, clearFilter() );
- buttons->addWidget( clear );
-
- layout->addWidget( view );
- layout->addLayout( buttons );
-// layout->addWidget( bar );
- setLayout( layout );
-}
+ /* Saved Settings */
+ getSettings()->beginGroup("Playlist");
-void StandardPLPanel::toggleRepeat()
-{
- if( model->hasRepeat() )
- {
- model->setRepeat( false ); model->setLoop( true );
- repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_all.png" ) );
- }
- else if( model->hasLoop() )
- {
- model->setRepeat( false ) ; model->setLoop( false );
- repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_off.png" ) );
- }
+ int i_viewMode = getSettings()->value( "view-mode", TREE_VIEW ).toInt();
+ if( i_viewMode == ICON_VIEW )
+ iconView = new PlIconView( model, this );
else
- {
- model->setRepeat( true );
- repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_one.png" ) );
- }
+ createTreeView();
+
+ getSettings()->endGroup();
+
+ currentRootId = -1;
+
+ /* Title label */
+ title = new QLabel;
+ QFont titleFont;
+ titleFont.setPointSize( titleFont.pointSize() + 6 );
+ titleFont.setFamily( "Verdana" );
+ title->setFont( titleFont );
+ layout->addWidget( title, 0, 0 );
+
+ /* A Spacer and the search possibilities */
+ layout->setColumnStretch( 1, 10 );
+
+ SearchLineEdit *search = new SearchLineEdit( this );
+ search->setMaximumWidth( 200 );
+ layout->addWidget( search, 0, 4 );
+ CONNECT( search, textChanged( const QString& ),
+ this, search( const QString& ) );
+ layout->setColumnStretch( 4, 1 );
+
+ /* Add item to the playlist button */
+ addButton = new QPushButton;
+ addButton->setIcon( QIcon( ":/buttons/playlist/playlist_add" ) );
+ addButton->setMaximumWidth( 30 );
+ BUTTONACT( addButton, popupAdd() );
+ layout->addWidget( addButton, 0, 3 );
+
+ QPushButton *viewButton = new QPushButton( this );
+ viewButton->setIcon( QIcon( ":/buttons/playlist/playlist_add" ) );
+ layout->addWidget( viewButton, 0, 2 );
+ BUTTONACT( viewButton, toggleView() );
}
-void StandardPLPanel::toggleRandom()
+StandardPLPanel::~StandardPLPanel()
{
- bool prev = model->hasRandom();
- model->setRandom( !prev );
- randomButton->setIcon( prev ?
- QIcon( ":/pixmaps/playlist_shuffle_off.png" ) :
- QIcon( ":/pixmaps/playlist_shuffle_on.png" ) );
+ getSettings()->beginGroup("Playlist");
+ if( treeView )
+ getSettings()->setValue( "headerStateV2", treeView->header()->saveState() );
+ getSettings()->endGroup();
}
-void StandardPLPanel::handleExpansion( const QModelIndex &index )
+/* Unused anymore, but might be useful, like in right-click menu */
+void StandardPLPanel::gotoPlayingItem()
{
- QModelIndex parent;
- if( model->isCurrent( index ) )
- {
- view->scrollTo( index, QAbstractItemView::EnsureVisible );
- parent = index;
- while( parent.isValid() )
- {
- view->setExpanded( parent, true );
- parent = model->parent( parent );
- }
- }
+ if( treeView )
+ treeView->scrollTo( model->currentIndex() );
}
-void StandardPLPanel::setCurrentRootId( int _new )
+void StandardPLPanel::handleExpansion( const QModelIndex& index )
{
- 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( currentRootId == THEPL->p_ml_category->i_id ||
- currentRootId == THEPL->p_ml_onelevel->i_id )
- {
- addButton->setEnabled( true );
- addButton->setToolTip( qtr(I_PL_ADDML) );
- }
- else
- addButton->setEnabled( false );
+ assert( treeView );
+ treeView->scrollTo( index );
}
+/* PopupAdd Menu for the Add Menu */
void StandardPLPanel::popupAdd()
{
QMenu popup;
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( simplePLAppendDialog()) );
popup.addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) );
+ popup.addAction( qtr(I_OP_ADVOP), THEDP, SLOT( PLAppendDialog()) );
}
- else if( currentRootId == THEPL->p_ml_category->i_id ||
- currentRootId == THEPL->p_ml_onelevel->i_id )
+ 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(simpleMLAppendDialog()));
- popup.addAction( qtr(I_PL_ADVADD), 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() );
+
+ popup.exec( QCursor::pos() - addButton->mapFromGlobal( QCursor::pos() )
+ + QPoint( 0, addButton->height() ) );
}
-void StandardPLPanel::popupSelectColumn( QPoint )
+void StandardPLPanel::popupSelectColumn( QPoint pos )
{
- ContextUpdateMapper = new QSignalMapper(this);
-
- QMenu selectColMenu;
-
-#define ADD_META_ACTION( meta ) { \
- QAction* option = selectColMenu.addAction( qfu(VLC_META_##meta) ); \
- option->setCheckable( true ); \
- option->setChecked( model->shownFlags() & VLC_META_ENGINE_##meta ); \
- ContextUpdateMapper->setMapping( option, VLC_META_ENGINE_##meta ); \
- CONNECT( option, triggered(), ContextUpdateMapper, map() ); \
- }
- CONNECT( ContextUpdateMapper, mapped( int ), model, viewchanged( int ) );
-
- ADD_META_ACTION( TITLE );
- ADD_META_ACTION( ARTIST );
- ADD_META_ACTION( DURATION );
- ADD_META_ACTION( COLLECTION );
- ADD_META_ACTION( GENRE );
- ADD_META_ACTION( SEQ_NUM );
- ADD_META_ACTION( RATING );
- ADD_META_ACTION( DESCRIPTION );
-
-#undef ADD_META_ACTION
-
- selectColMenu.exec( QCursor::pos() );
- }
-
-void StandardPLPanel::clearFilter()
+ QMenu menu;
+ assert( treeView );
+
+ /* 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 = menu.addAction(
+ qfu( psz_column_title( i ) ) );
+ option->setCheckable( true );
+ option->setChecked( !treeView->isColumnHidden( j ) );
+ selectColumnsSigMapper->setMapping( option, j );
+ CONNECT( option, triggered(), selectColumnsSigMapper, map() );
+ }
+ menu.exec( QCursor::pos() );
+}
+
+void StandardPLPanel::popupPlView( const QPoint &point )
{
- searchLine->setText( "" );
+ QAbstractItemView *aView;
+ if ( treeView && treeView->isVisible() ) aView = treeView;
+ else if( iconView && iconView->isVisible() ) aView = iconView;
+ else return;
+
+ QModelIndex index = aView->indexAt( point );
+ QPoint globalPoint = aView->viewport()->mapToGlobal( point );
+ QItemSelectionModel *selection = aView->selectionModel();
+ QModelIndexList list = selection->selectedIndexes();
+ model->popup( index, globalPoint, list );
}
-void StandardPLPanel::search( QString searchText )
+void StandardPLPanel::toggleColumnShown( int i )
{
- model->search( searchText );
+ treeView->setColumnHidden( i, !treeView->isColumnHidden( i ) );
}
-void StandardPLPanel::doPopup( QModelIndex index, QPoint point )
+/* Search in the playlist */
+void StandardPLPanel::search( const QString& searchText )
{
- if( !index.isValid() ) return;
- QItemSelectionModel *selection = view->selectionModel();
- QModelIndexList list = selection->selectedIndexes();
- model->popup( index, point, list );
+ model->search( searchText );
}
-void StandardPLPanel::setRoot( int i_root_id )
+/* Set the root of the new Playlist */
+/* This activated by the selector selection */
+void StandardPLPanel::setRoot( playlist_item_t *p_item )
{
- playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id,
- VLC_TRUE );
- assert( p_item );
- p_item = playlist_GetPreferredNode( THEPL, p_item );
+ QPL_LOCK;
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 )
model->removeItem( i_id );
}
+/* Delete and Suppr key remove the selection
+ FilterKey function and code function */
void StandardPLPanel::keyPressEvent( QKeyEvent *e )
{
switch( e->key() )
void StandardPLPanel::deleteSelection()
{
- QItemSelectionModel *selection = view->selectionModel();
+ //FIXME
+ if( !treeView ) return;
+ QItemSelectionModel *selection = treeView->selectionModel();
QModelIndexList list = selection->selectedIndexes();
model->doDelete( list );
}
-StandardPLPanel::~StandardPLPanel()
-{}
+void StandardPLPanel::createIconView()
+{
+ iconView = new PlIconView( model, this );
+ iconView->setContextMenuPolicy( Qt::CustomContextMenu );
+ CONNECT( iconView, customContextMenuRequested( const QPoint & ),
+ this, popupPlView( const QPoint & ) );
+
+ layout->addWidget( iconView, 1, 0, 1, -1 );
+}
+
+void StandardPLPanel::createTreeView()
+{
+ /* Create and configure the QTreeView */
+ treeView = new QTreeView;
+ treeView->setModel( model );
+
+ treeView->setIconSize( QSize( 20, 20 ) );
+ treeView->setAlternatingRowColors( true );
+ treeView->setAnimated( true );
+ treeView->setUniformRowHeights( true );
+ treeView->setSortingEnabled( true );
+ treeView->header()->setSortIndicator( -1 , Qt::AscendingOrder );
+ treeView->header()->setSortIndicatorShown( true );
+ treeView->header()->setClickable( true );
+ treeView->header()->setContextMenuPolicy( Qt::CustomContextMenu );
+
+ treeView->setSelectionBehavior( QAbstractItemView::SelectRows );
+ treeView->setSelectionMode( QAbstractItemView::ExtendedSelection );
+ treeView->setDragEnabled( true );
+ treeView->setAcceptDrops( true );
+ treeView->setDropIndicatorShown( true );
+ treeView->setContextMenuPolicy( Qt::CustomContextMenu );
+
+ if( getSettings()->contains( "headerStateV2" ) )
+ {
+ treeView->header()->restoreState(
+ getSettings()->value( "headerStateV2" ).toByteArray() );
+ }
+ else
+ {
+ for( int m = 1, c = 0; m != COLUMN_END; m <<= 1, c++ )
+ {
+ treeView->setClumnHidden( c, !( m & COLUMN_DEFAULT ) );
+ if( m == COLUMN_TITLE ) treeView->header()->resizeSection( c, 200 );
+ else if( m == COLUMN_DURATION ) treeView->header()->resizeSection( c, 80 );
+ }
+ }
+
+ /* Connections for the TreeView */
+ CONNECT( treeView, activated( const QModelIndex& ),
+ model,activateItem( const QModelIndex& ) );
+ CONNECT( treeView->header(), customContextMenuRequested( const QPoint & ),
+ this, popupSelectColumn( QPoint ) );
+ CONNECT( treeView, customContextMenuRequested( const QPoint & ),
+ this, popupPlView( const QPoint & ) );
+ CONNECT( model, currentChanged( const QModelIndex& ),
+ this, handleExpansion( const QModelIndex& ) );
+
+ /* SignalMapper for columns */
+ selectColumnsSigMapper = new QSignalMapper( this );
+ CONNECT( selectColumnsSigMapper, mapped( int ),
+ this, toggleColumnShown( int ) );
+
+ /* Finish the layout */
+ layout->addWidget( treeView, 1, 0, 1, -1 );
+}
+
+void StandardPLPanel::toggleView()
+{
+ if( treeView && treeView->isVisible() )
+ {
+ if( iconView == NULL )
+ createIconView();
+
+ treeView->hide();
+ iconView->show();
+ }
+ else
+ {
+ iconView->hide();
+ treeView->show();
+ }
+}
+
+void StandardPLPanel::wheelEvent( QWheelEvent *e )
+{
+ // Accept this event in order to prevent unwanted volume up/down changes
+ e->accept();
+}