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);
67 CONNECT( view, activated( const QModelIndex& ) ,
68 model,activateItem( const QModelIndex& ) );
69 CONNECT( view, rightClicked( QModelIndex , QPoint ),
70 this, doPopup( QModelIndex, QPoint ) );
71 CONNECT( model, dataChanged( const QModelIndex&, const QModelIndex& ),
72 this, handleExpansion( const QModelIndex& ) );
75 CONNECT( parent, rootChanged(int), this, setCurrentRootId( int ) );
77 QVBoxLayout *layout = new QVBoxLayout();
78 layout->setSpacing( 0 ); layout->setMargin( 0 );
80 QHBoxLayout *buttons = new QHBoxLayout();
82 addButton = new QPushButton( "+", this );
83 addButton->setMaximumWidth( 25 );
84 BUTTONACT( addButton, add() );
85 buttons->addWidget( addButton );
87 repeatButton = new QPushButton( 0 ); buttons->addWidget( repeatButton );
88 if( model->hasRepeat() ) repeatButton->setText( qtr( "R1" ) );
89 else if( model->hasLoop() ) repeatButton->setText( qtr( "RA" ) );
90 else repeatButton->setText( qtr( "NR" ) );
91 BUTTONACT( repeatButton, toggleRepeat() );
93 randomButton = new QPushButton( 0 ); buttons->addWidget( randomButton );
94 if( model->hasRandom() ) randomButton->setText( qtr( " RND" ) );
95 else randomButton->setText( qtr( "NRND" ) );
96 BUTTONACT( randomButton, toggleRandom() );
98 QSpacerItem *spacer = new QSpacerItem( 10, 20 );buttons->addItem( spacer );
100 QLabel *filter = new QLabel( qtr(I_PL_SEARCH) + " " );
101 buttons->addWidget( filter );
102 searchLine = new ClickLineEdit( qtr(I_PL_FILTER), 0 );
103 CONNECT( searchLine, textChanged(QString), this, search(QString));
104 buttons->addWidget( searchLine ); filter->setBuddy( searchLine );
106 QPushButton *clear = new QPushButton( qfu( "CL") );
107 clear->setMaximumWidth( 30 );
108 buttons->addWidget( clear );
109 BUTTONACT( clear, clearFilter() );
111 layout->addWidget( view );
112 layout->addLayout( buttons );
113 // layout->addWidget( bar );
117 void StandardPLPanel::toggleRepeat()
119 if( model->hasRepeat() )
121 model->setRepeat( false ); model->setLoop( true );
122 repeatButton->setText( qtr(I_PL_LOOP) );
124 else if( model->hasLoop() )
126 model->setRepeat( false ) ; model->setLoop( false );
127 repeatButton->setText( qtr(I_PL_NOREPEAT) );
131 model->setRepeat( true );
132 repeatButton->setText( qtr(I_PL_REPEAT) );
136 void StandardPLPanel::toggleRandom()
138 bool prev = model->hasRandom();
139 model->setRandom( !prev );
140 randomButton->setText( prev ? qtr(I_PL_NORANDOM) : qtr(I_PL_RANDOM) );
143 void StandardPLPanel::handleExpansion( const QModelIndex &index )
146 if( model->isCurrent( index ) )
149 while( parent.isValid() )
151 view->setExpanded( parent, true );
152 parent = model->parent( parent );
157 void StandardPLPanel::setCurrentRootId( int _new )
159 currentRootId = _new;
160 if( currentRootId == THEPL->p_local_category->i_id ||
161 currentRootId == THEPL->p_local_onelevel->i_id )
163 addButton->setEnabled( true );
164 addButton->setToolTip( qtr(I_PL_ADDPL) );
166 else if( currentRootId == THEPL->p_ml_category->i_id ||
167 currentRootId == THEPL->p_ml_onelevel->i_id )
169 addButton->setEnabled( true );
170 addButton->setToolTip( qtr(I_PL_ADDML) );
173 addButton->setEnabled( false );
176 void StandardPLPanel::add()
178 QMenu *popup = new QMenu();
179 if( currentRootId == THEPL->p_local_category->i_id ||
180 currentRootId == THEPL->p_local_onelevel->i_id )
182 popup->addAction( qtr(I_PL_ADDF), THEDP, SLOT(simplePLAppendDialog()));
183 popup->addAction( qtr(I_PL_ADVADD), THEDP, SLOT(PLAppendDialog()) );
184 popup->addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) );
186 else if( currentRootId == THEPL->p_ml_category->i_id ||
187 currentRootId == THEPL->p_ml_onelevel->i_id )
189 popup->addAction( qtr(I_PL_ADDF), THEDP, SLOT(simpleMLAppendDialog()));
190 popup->addAction( qtr(I_PL_ADVADD), THEDP, SLOT( MLAppendDialog() ) );
191 popup->addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
193 popup->popup( QCursor::pos() );
196 void StandardPLPanel::clearFilter()
198 searchLine->setText( "" );
201 void StandardPLPanel::search( QString searchText )
203 model->search( searchText );
206 void StandardPLPanel::doPopup( QModelIndex index, QPoint point )
208 if( !index.isValid() ) return;
209 QItemSelectionModel *selection = view->selectionModel();
210 QModelIndexList list = selection->selectedIndexes();
211 model->popup( index, point, list );
214 void StandardPLPanel::setRoot( int i_root_id )
216 playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id,
219 p_item = playlist_GetPreferredNode( THEPL, p_item );
221 model->rebuild( p_item );
224 void StandardPLPanel::removeItem( int i_id )
226 model->removeItem( i_id );
229 void StandardPLPanel::keyPressEvent( QKeyEvent *e )
240 void StandardPLPanel::deleteSelection()
242 QItemSelectionModel *selection = view->selectionModel();
243 QModelIndexList list = selection->selectedIndexes();
244 model->doDelete( list );
247 StandardPLPanel::~StandardPLPanel()