1 /*****************************************************************************
2 * standardpanel.cpp : The "standard" playlist panel : just a treeview
3 ****************************************************************************
4 * Copyright (C) 2000-2005 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
25 #include "dialogs_provider.hpp"
26 #include "playlist_model.hpp"
27 #include "components/playlist/panels.hpp"
28 #include "util/customwidgets.hpp"
31 #include <QPushButton>
32 #include <QHBoxLayout>
33 #include <QVBoxLayout>
34 #include <QHeaderView>
36 #include <QModelIndexList>
39 #include <QSpacerItem>
44 StandardPLPanel::StandardPLPanel( BasePlaylistWidget *_parent,
45 intf_thread_t *_p_intf,
46 playlist_t *p_playlist,
47 playlist_item_t *p_root ):
48 PLPanel( _parent, _p_intf )
50 model = new PLModel( p_playlist, p_root, -1, this );
51 view = new QVLCTreeView( 0 );
52 view->setModel(model);
53 view->setIconSize( QSize(20,20) );
54 view->setAlternatingRowColors( true );
55 view->header()->resizeSection( 0, 230 );
56 view->header()->resizeSection( 2, 60 );
57 view->header()->setSortIndicatorShown( true );
58 view->header()->setClickable( true );
60 view->setSelectionMode( QAbstractItemView::ExtendedSelection );
61 view->setDragEnabled(true);
62 view->setAcceptDrops(true);
63 view->setDropIndicatorShown(true);
65 CONNECT( view, activated( const QModelIndex& ) ,
66 model,activateItem( const QModelIndex& ) );
67 CONNECT( view, rightClicked( QModelIndex , QPoint ),
68 this, doPopup( QModelIndex, QPoint ) );
69 CONNECT( model, dataChanged( const QModelIndex&, const QModelIndex& ),
70 this, handleExpansion( const QModelIndex& ) );
73 CONNECT( parent, rootChanged(int), this, setCurrentRootId( int ) );
75 QVBoxLayout *layout = new QVBoxLayout();
76 layout->setSpacing( 0 ); layout->setMargin( 0 );
78 QHBoxLayout *buttons = new QHBoxLayout();
80 addButton = new QPushButton( "+", this );
81 addButton->setMaximumWidth( 25 );
82 BUTTONACT( addButton, add() );
83 buttons->addWidget( addButton );
85 repeatButton = new QPushButton( 0 ); buttons->addWidget( repeatButton );
86 if( model->hasRepeat() ) repeatButton->setText( qtr( "R1" ) );
87 else if( model->hasLoop() ) repeatButton->setText( qtr( "RA" ) );
88 else repeatButton->setText( qtr( "NR" ) );
89 BUTTONACT( repeatButton, toggleRepeat() );
91 randomButton = new QPushButton( 0 ); buttons->addWidget( randomButton );
92 if( model->hasRandom() ) randomButton->setText( qtr( " RND" ) );
93 else randomButton->setText( qtr( "NRND" ) );
94 BUTTONACT( randomButton, toggleRandom() );
96 QSpacerItem *spacer = new QSpacerItem( 10, 20 );buttons->addItem( spacer );
98 QLabel *filter = new QLabel( qfu( "&Search:" ) + " " );
99 buttons->addWidget( filter );
100 searchLine = new ClickLineEdit( qfu( "Playlist filter" ), 0 );
101 CONNECT( searchLine, textChanged(QString), this, search(QString));
102 buttons->addWidget( searchLine ); filter->setBuddy( searchLine );
104 QPushButton *clear = new QPushButton( qfu( "CL") );
105 clear->setMaximumWidth( 30 );
106 buttons->addWidget( clear );
107 BUTTONACT( clear, clearFilter() );
109 layout->addWidget( view );
110 layout->addLayout( buttons );
111 // layout->addWidget( bar );
115 void StandardPLPanel::toggleRepeat()
117 if( model->hasRepeat() )
119 model->setRepeat( false ); model->setLoop( true );
120 repeatButton->setText( qtr( "Repeat All" ) );
122 else if( model->hasLoop() )
124 model->setRepeat( false ) ; model->setLoop( false );
125 repeatButton->setText( qtr( "No Repeat" ) );
129 model->setRepeat( true );
130 repeatButton->setText( qtr( "Repeat One" ) );
134 void StandardPLPanel::toggleRandom()
136 bool prev = model->hasRandom();
137 model->setRandom( !prev );
138 randomButton->setText( prev ? qtr( "No Random" ) : qtr( "Random" ) );
141 void StandardPLPanel::handleExpansion( const QModelIndex &index )
144 if( model->isCurrent( index ) )
147 while( parent.isValid() )
149 view->setExpanded( parent, true );
150 parent = model->parent( parent );
155 void StandardPLPanel::setCurrentRootId( int _new )
157 currentRootId = _new;
158 if( currentRootId == THEPL->p_local_category->i_id ||
159 currentRootId == THEPL->p_local_onelevel->i_id )
161 addButton->setEnabled( true );
162 addButton->setToolTip( qtr("Add to playlist" ) );
164 else if( currentRootId == THEPL->p_ml_category->i_id ||
165 currentRootId == THEPL->p_ml_onelevel->i_id )
167 addButton->setEnabled( true );
168 addButton->setToolTip( qtr("Add to media library" ) );
171 addButton->setEnabled( false );
174 void StandardPLPanel::add()
176 QMenu *popup = new QMenu();
177 if( currentRootId == THEPL->p_local_category->i_id ||
178 currentRootId == THEPL->p_local_onelevel->i_id )
180 popup->addAction( "Add file", THEDP, SLOT( simplePLAppendDialog() ) );
181 popup->addAction( "Advanced add", THEDP, SLOT( PLAppendDialog() ) );
183 else if( currentRootId == THEPL->p_ml_category->i_id ||
184 currentRootId == THEPL->p_ml_onelevel->i_id )
186 popup->addAction( "Add file", THEDP, SLOT( simpleMLAppendDialog() ) );
187 popup->addAction( "Advanced add", THEDP, SLOT( MLAppendDialog() ) );
188 popup->addAction( "Directory", THEDP, SLOT( openMLDirectory() ) );
190 popup->popup( QCursor::pos() );
193 void StandardPLPanel::clearFilter()
195 searchLine->setText( "" );
198 void StandardPLPanel::search( QString searchText )
200 model->search( searchText );
203 void StandardPLPanel::doPopup( QModelIndex index, QPoint point )
205 if( !index.isValid() ) return;
206 QItemSelectionModel *selection = view->selectionModel();
207 QModelIndexList list = selection->selectedIndexes();
208 model->popup( index, point, list );
211 void StandardPLPanel::setRoot( int i_root_id )
213 playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id );
215 p_item = playlist_GetPreferredNode( THEPL, p_item );
217 model->rebuild( p_item );
220 void StandardPLPanel::keyPressEvent( QKeyEvent *e )
231 void StandardPLPanel::deleteSelection()
233 QItemSelectionModel *selection = view->selectionModel();
234 QModelIndexList list = selection->selectedIndexes();
235 model->doDelete( list );
238 StandardPLPanel::~StandardPLPanel()