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 );
59 view->setSelectionMode( QAbstractItemView::ExtendedSelection );
61 CONNECT( view, activated( const QModelIndex& ) ,
62 model,activateItem( const QModelIndex& ) );
63 CONNECT( view, rightClicked( QModelIndex , QPoint ),
64 this, doPopup( QModelIndex, QPoint ) );
65 CONNECT( model, dataChanged( const QModelIndex&, const QModelIndex& ),
66 this, handleExpansion( const QModelIndex& ) );
69 CONNECT( parent, rootChanged(int), this, setCurrentRootId( int ) );
71 QVBoxLayout *layout = new QVBoxLayout();
72 layout->setSpacing( 0 ); layout->setMargin( 0 );
74 QHBoxLayout *buttons = new QHBoxLayout();
76 addButton = new QPushButton( "+", this );
77 addButton->setMaximumWidth( 25 );
78 BUTTONACT( addButton, add() );
79 buttons->addWidget( addButton );
81 repeatButton = new QPushButton( 0 ); buttons->addWidget( repeatButton );
82 if( model->hasRepeat() ) repeatButton->setText( qtr( "R1" ) );
83 else if( model->hasLoop() ) repeatButton->setText( qtr( "RA" ) );
84 else repeatButton->setText( qtr( "NR" ) );
85 BUTTONACT( repeatButton, toggleRepeat() );
87 randomButton = new QPushButton( 0 ); buttons->addWidget( randomButton );
88 if( model->hasRandom() ) randomButton->setText( qtr( " RND" ) );
89 else randomButton->setText( qtr( "NRND" ) );
90 BUTTONACT( randomButton, toggleRandom() );
92 QSpacerItem *spacer = new QSpacerItem( 10, 20 );buttons->addItem( spacer );
94 QLabel *filter = new QLabel( qfu( "&Search:" ) + " " );
95 buttons->addWidget( filter );
96 searchLine = new ClickLineEdit( qfu( "Playlist filter" ), 0 );
97 CONNECT( searchLine, textChanged(QString), this, search(QString));
98 buttons->addWidget( searchLine ); filter->setBuddy( searchLine );
100 QPushButton *clear = new QPushButton( qfu( "CL") );
101 clear->setMaximumWidth( 30 );
102 buttons->addWidget( clear );
103 BUTTONACT( clear, clearFilter() );
105 layout->addWidget( view );
106 layout->addLayout( buttons );
107 // layout->addWidget( bar );
111 void StandardPLPanel::toggleRepeat()
113 if( model->hasRepeat() )
115 model->setRepeat( false ); model->setLoop( true );
116 repeatButton->setText( qtr( "Repeat All" ) );
118 else if( model->hasLoop() )
120 model->setRepeat( false ) ; model->setLoop( false );
121 repeatButton->setText( qtr( "No Repeat" ) );
125 model->setRepeat( true );
126 repeatButton->setText( qtr( "Repeat One" ) );
130 void StandardPLPanel::toggleRandom()
132 bool prev = model->hasRandom();
133 model->setRandom( !prev );
134 randomButton->setText( prev ? qtr( "No Random" ) : qtr( "Random" ) );
137 void StandardPLPanel::handleExpansion( const QModelIndex &index )
140 if( model->isCurrent( index ) )
143 while( parent.isValid() )
145 view->setExpanded( parent, true );
146 parent = model->parent( parent );
151 void StandardPLPanel::setCurrentRootId( int _new )
153 currentRootId = _new;
154 if( currentRootId == THEPL->p_local_category->i_id ||
155 currentRootId == THEPL->p_local_onelevel->i_id )
157 addButton->setEnabled( true );
158 addButton->setToolTip( qtr("Add to playlist" ) );
160 else if( currentRootId == THEPL->p_ml_category->i_id ||
161 currentRootId == THEPL->p_ml_onelevel->i_id )
163 addButton->setEnabled( true );
164 addButton->setToolTip( qtr("Add to media library" ) );
167 addButton->setEnabled( false );
170 void StandardPLPanel::add()
172 QMenu *popup = new QMenu();
173 if( currentRootId == THEPL->p_local_category->i_id ||
174 currentRootId == THEPL->p_local_onelevel->i_id )
176 popup->addAction( "Add file", THEDP, SLOT( simplePLAppendDialog() ) );
177 popup->addAction( "Advanced add", THEDP, SLOT( PLAppendDialog() ) );
179 else if( currentRootId == THEPL->p_ml_category->i_id ||
180 currentRootId == THEPL->p_ml_onelevel->i_id )
182 popup->addAction( "Add file", THEDP, SLOT( simpleMLAppendDialog() ) );
183 popup->addAction( "Advanced add", THEDP, SLOT( MLAppendDialog() ) );
184 popup->addAction( "Directory", THEDP, SLOT( openMLDirectory() ) );
186 popup->popup( QCursor::pos() );
189 void StandardPLPanel::clearFilter()
191 searchLine->setText( "" );
194 void StandardPLPanel::search( QString searchText )
196 model->search( searchText );
199 void StandardPLPanel::doPopup( QModelIndex index, QPoint point )
201 if( !index.isValid() ) return;
202 QItemSelectionModel *selection = view->selectionModel();
203 QModelIndexList list = selection->selectedIndexes();
204 model->popup( index, point, list );
207 void StandardPLPanel::setRoot( int i_root_id )
209 playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id );
211 p_item = playlist_GetPreferredNode( THEPL, p_item );
213 model->rebuild( p_item );
216 void StandardPLPanel::keyPressEvent( QKeyEvent *e )
227 void StandardPLPanel::deleteSelection()
229 QItemSelectionModel *selection = view->selectionModel();
230 QModelIndexList list = selection->selectedIndexes();
231 model->doDelete( list );
234 StandardPLPanel::~StandardPLPanel()