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"
30 #include <vlc_intf_strings.h>
33 #include <QPushButton>
34 #include <QHBoxLayout>
35 #include <QVBoxLayout>
36 #include <QHeaderView>
38 #include <QModelIndexList>
41 #include <QSpacerItem>
46 StandardPLPanel::StandardPLPanel( BasePlaylistWidget *_parent,
47 intf_thread_t *_p_intf,
48 playlist_t *p_playlist,
49 playlist_item_t *p_root ):
50 PLPanel( _parent, _p_intf )
52 model = new PLModel( p_playlist, p_intf, p_root, -1, this );
53 view = new QVLCTreeView( 0 );
54 view->setModel(model);
55 view->setIconSize( QSize(20,20) );
56 view->setAlternatingRowColors( true );
57 view->header()->resizeSection( 0, 230 );
58 view->header()->resizeSection( 1, 170 );
59 view->header()->setSortIndicatorShown( true );
60 view->header()->setClickable( true );
62 view->setSelectionMode( QAbstractItemView::ExtendedSelection );
63 view->setDragEnabled( true );
64 view->setAcceptDrops( true );
65 view->setDropIndicatorShown( true );
66 view->setAutoScroll( true );
68 CONNECT( view, activated( const QModelIndex& ) ,
69 model,activateItem( const QModelIndex& ) );
70 CONNECT( view, rightClicked( QModelIndex , QPoint ),
71 this, doPopup( QModelIndex, QPoint ) );
72 CONNECT( model, dataChanged( const QModelIndex&, const QModelIndex& ),
73 this, handleExpansion( const QModelIndex& ) );
76 CONNECT( parent, rootChanged(int), this, setCurrentRootId( int ) );
78 QVBoxLayout *layout = new QVBoxLayout();
79 layout->setSpacing( 0 ); layout->setMargin( 0 );
81 QHBoxLayout *buttons = new QHBoxLayout();
83 addButton = new QPushButton( "+", this );
84 addButton->setMaximumWidth( 25 );
85 BUTTONACT( addButton, add() );
86 buttons->addWidget( addButton );
88 repeatButton = new QPushButton( 0 ); buttons->addWidget( repeatButton );
89 if( model->hasRepeat() ) repeatButton->setText( qtr( "R1" ) );
90 else if( model->hasLoop() ) repeatButton->setText( qtr( "RA" ) );
91 else repeatButton->setText( qtr( "NR" ) );
92 BUTTONACT( repeatButton, toggleRepeat() );
94 randomButton = new QPushButton( 0 ); buttons->addWidget( randomButton );
95 if( model->hasRandom() ) randomButton->setText( qtr( " RND" ) );
96 else randomButton->setText( qtr( "NRND" ) );
97 BUTTONACT( randomButton, toggleRandom() );
99 QSpacerItem *spacer = new QSpacerItem( 10, 20 );buttons->addItem( spacer );
101 QLabel *filter = new QLabel( qtr(I_PL_SEARCH) + " " );
102 buttons->addWidget( filter );
103 searchLine = new ClickLineEdit( qtr(I_PL_FILTER), 0 );
104 CONNECT( searchLine, textChanged(QString), this, search(QString));
105 buttons->addWidget( searchLine ); filter->setBuddy( searchLine );
107 QPushButton *clear = new QPushButton( qfu( "CL") );
108 clear->setMaximumWidth( 30 );
109 buttons->addWidget( clear );
110 BUTTONACT( clear, clearFilter() );
112 layout->addWidget( view );
113 layout->addLayout( buttons );
114 // layout->addWidget( bar );
118 void StandardPLPanel::toggleRepeat()
120 if( model->hasRepeat() )
122 model->setRepeat( false ); model->setLoop( true );
123 repeatButton->setText( qtr(I_PL_LOOP) );
125 else if( model->hasLoop() )
127 model->setRepeat( false ) ; model->setLoop( false );
128 repeatButton->setText( qtr(I_PL_NOREPEAT) );
132 model->setRepeat( true );
133 repeatButton->setText( qtr(I_PL_REPEAT) );
137 void StandardPLPanel::toggleRandom()
139 bool prev = model->hasRandom();
140 model->setRandom( !prev );
141 randomButton->setText( prev ? qtr(I_PL_NORANDOM) : qtr(I_PL_RANDOM) );
144 void StandardPLPanel::handleExpansion( const QModelIndex &index )
147 if( model->isCurrent( index ) )
150 while( parent.isValid() )
152 view->setExpanded( parent, true );
153 parent = model->parent( parent );
158 void StandardPLPanel::setCurrentRootId( int _new )
160 currentRootId = _new;
161 if( currentRootId == THEPL->p_local_category->i_id ||
162 currentRootId == THEPL->p_local_onelevel->i_id )
164 addButton->setEnabled( true );
165 addButton->setToolTip( qtr(I_PL_ADDPL) );
167 else if( currentRootId == THEPL->p_ml_category->i_id ||
168 currentRootId == THEPL->p_ml_onelevel->i_id )
170 addButton->setEnabled( true );
171 addButton->setToolTip( qtr(I_PL_ADDML) );
174 addButton->setEnabled( false );
177 void StandardPLPanel::add()
179 QMenu *popup = new QMenu();
180 if( currentRootId == THEPL->p_local_category->i_id ||
181 currentRootId == THEPL->p_local_onelevel->i_id )
183 popup->addAction( qtr(I_PL_ADDF), THEDP, SLOT(simplePLAppendDialog()));
184 popup->addAction( qtr(I_PL_ADVADD), THEDP, SLOT(PLAppendDialog()) );
185 popup->addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) );
187 else if( currentRootId == THEPL->p_ml_category->i_id ||
188 currentRootId == THEPL->p_ml_onelevel->i_id )
190 popup->addAction( qtr(I_PL_ADDF), THEDP, SLOT(simpleMLAppendDialog()));
191 popup->addAction( qtr(I_PL_ADVADD), THEDP, SLOT( MLAppendDialog() ) );
192 popup->addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
194 popup->popup( QCursor::pos() );
197 void StandardPLPanel::clearFilter()
199 searchLine->setText( "" );
202 void StandardPLPanel::search( QString searchText )
204 model->search( searchText );
207 void StandardPLPanel::doPopup( QModelIndex index, QPoint point )
209 if( !index.isValid() ) return;
210 QItemSelectionModel *selection = view->selectionModel();
211 QModelIndexList list = selection->selectedIndexes();
212 model->popup( index, point, list );
215 void StandardPLPanel::setRoot( int i_root_id )
217 playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id,
220 p_item = playlist_GetPreferredNode( THEPL, p_item );
222 model->rebuild( p_item );
225 void StandardPLPanel::removeItem( int i_id )
227 model->removeItem( i_id );
230 void StandardPLPanel::keyPressEvent( QKeyEvent *e )
241 void StandardPLPanel::deleteSelection()
243 QItemSelectionModel *selection = view->selectionModel();
244 QModelIndexList list = selection->selectedIndexes();
245 model->doDelete( list );
248 StandardPLPanel::~StandardPLPanel()