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 *****************************************************************************/
28 #include "dialogs_provider.hpp"
29 #include "components/playlist/playlist_model.hpp"
30 #include "components/playlist/panels.hpp"
31 #include "util/customwidgets.hpp"
33 #include <vlc_intf_strings.h>
36 #include <QPushButton>
37 #include <QHBoxLayout>
38 #include <QVBoxLayout>
39 #include <QHeaderView>
41 #include <QModelIndexList>
44 #include <QSpacerItem>
46 #include <QSignalMapper>
50 StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
51 intf_thread_t *_p_intf,
52 playlist_t *p_playlist,
53 playlist_item_t *p_root ):
54 PLPanel( _parent, _p_intf )
56 model = new PLModel( p_playlist, p_intf, p_root, -1, this );
58 QVBoxLayout *layout = new QVBoxLayout();
59 layout->setSpacing( 0 ); layout->setMargin( 0 );
61 /* Create and configure the QTreeView */
62 view = new QVLCTreeView( 0 );
63 view->setSortingEnabled( true );
64 view->sortByColumn( -1, Qt::AscendingOrder );
65 view->setModel(model);
66 view->setIconSize( QSize( 20, 20 ) );
67 view->setAlternatingRowColors( true );
68 view->setAnimated( true );
69 view->setSelectionMode( QAbstractItemView::ExtendedSelection );
70 view->setDragEnabled( true );
71 view->setAcceptDrops( true );
72 view->setDropIndicatorShown( true );
73 view->setAutoScroll( true );
75 /* Configure the size of the header */
76 view->header()->resizeSection( 0, 200 );
77 view->header()->resizeSection( 1, 80 );
78 view->header()->setSortIndicatorShown( true );
79 view->header()->setClickable( true );
80 view->header()->setContextMenuPolicy( Qt::CustomContextMenu );
82 /* Connections for the TreeView */
83 CONNECT( view, activated( const QModelIndex& ) ,
84 model,activateItem( const QModelIndex& ) );
85 CONNECT( view, rightClicked( QModelIndex , QPoint ),
86 this, doPopup( QModelIndex, QPoint ) );
87 CONNECT( model, dataChanged( const QModelIndex&, const QModelIndex& ),
88 this, handleExpansion( const QModelIndex& ) );
89 CONNECT( view->header(), customContextMenuRequested( const QPoint & ),
90 this, popupSelectColumn( QPoint ) );
93 CONNECT( parent, rootChanged( int ), this, setCurrentRootId( int ) );
95 /* Buttons configuration */
96 QHBoxLayout *buttons = new QHBoxLayout;
98 /* Add item to the playlist button */
99 addButton = new QPushButton;
100 addButton->setIcon( QIcon( ":/pixmaps/playlist_add.png" ) );
101 addButton->setMaximumWidth( 30 );
102 BUTTONACT( addButton, popupAdd() );
103 buttons->addWidget( addButton );
105 /* Random 2-state button */
106 randomButton = new QPushButton( this );
107 if( model->hasRandom() )
109 randomButton->setIcon( QIcon( ":/pixmaps/playlist_shuffle_on.png" ));
110 randomButton->setToolTip( qtr( I_PL_RANDOM ));
114 randomButton->setIcon( QIcon( ":/pixmaps/playlist_shuffle_off.png" ) );
115 randomButton->setToolTip( qtr( I_PL_NORANDOM ));
117 BUTTONACT( randomButton, toggleRandom() );
118 buttons->addWidget( randomButton );
120 /* Repeat 3-state button */
121 repeatButton = new QPushButton( this );
122 if( model->hasRepeat() )
124 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_one.png" ) );
125 repeatButton->setToolTip( qtr( I_PL_REPEAT ));
127 else if( model->hasLoop() )
129 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_all.png" ) );
130 repeatButton->setToolTip( qtr( I_PL_LOOP ));
134 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_off.png" ) );
135 repeatButton->setToolTip( qtr( I_PL_NOREPEAT ));
137 BUTTONACT( repeatButton, toggleRepeat() );
138 buttons->addWidget( repeatButton );
141 gotoPlayingButton = new QPushButton( "X" , this );
142 gotoPlayingButton->setToolTip( qtr( "Show the current item" ));
143 BUTTONACT( gotoPlayingButton, gotoPlayingItem() );
144 buttons->addWidget( gotoPlayingButton );
146 /* A Spacer and the search possibilities */
147 QSpacerItem *spacer = new QSpacerItem( 10, 20 );
148 buttons->addItem( spacer );
150 QLabel *filter = new QLabel( qtr(I_PL_SEARCH) + " " );
151 buttons->addWidget( filter );
153 searchLine = new ClickLineEdit( qtr(I_PL_FILTER), 0 );
154 searchLine->setMinimumWidth( 80 );
155 CONNECT( searchLine, textChanged(QString), this, search(QString));
156 buttons->addWidget( searchLine ); filter->setBuddy( searchLine );
158 QPushButton *clear = new QPushButton;
159 clear->setText( qfu( "CL") );
160 clear->setMaximumWidth( 30 );
161 clear->setToolTip( qtr( "Clear" ));
162 BUTTONACT( clear, clearFilter() );
163 buttons->addWidget( clear );
165 /* Finish the layout */
166 layout->addWidget( view );
167 layout->addLayout( buttons );
168 // layout->addWidget( bar );
172 /* Function to toggle between the Repeat states */
173 void StandardPLPanel::toggleRepeat()
175 if( model->hasRepeat() )
177 model->setRepeat( false ); model->setLoop( true );
178 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_all.png" ) );
179 repeatButton->setToolTip( qtr( I_PL_LOOP ));
181 else if( model->hasLoop() )
183 model->setRepeat( false ) ; model->setLoop( false );
184 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_off.png" ) );
185 repeatButton->setToolTip( qtr( I_PL_NOREPEAT ));
189 model->setRepeat( true );
190 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_one.png" ) );
191 repeatButton->setToolTip( qtr( I_PL_REPEAT ));
195 /* Function to toggle between the Random states */
196 void StandardPLPanel::toggleRandom()
198 bool prev = model->hasRandom();
199 model->setRandom( !prev );
200 randomButton->setIcon( prev ?
201 QIcon( ":/pixmaps/playlist_shuffle_off.png" ) :
202 QIcon( ":/pixmaps/playlist_shuffle_on.png" ) );
203 randomButton->setToolTip( prev ? qtr( I_PL_NORANDOM ) : qtr(I_PL_RANDOM ) );
206 void StandardPLPanel::gotoPlayingItem()
208 view->scrollTo( view->currentIndex() );
211 void StandardPLPanel::handleExpansion( const QModelIndex &index )
213 if( model->isCurrent( index ) )
214 view->scrollTo( index, QAbstractItemView::EnsureVisible );
217 void StandardPLPanel::setCurrentRootId( int _new )
219 currentRootId = _new;
220 if( currentRootId == THEPL->p_local_category->i_id ||
221 currentRootId == THEPL->p_local_onelevel->i_id )
223 addButton->setEnabled( true );
224 addButton->setToolTip( qtr(I_PL_ADDPL) );
226 else if( ( THEPL->p_ml_category &&
227 currentRootId == THEPL->p_ml_category->i_id ) ||
228 ( THEPL->p_ml_onelevel &&
229 currentRootId == THEPL->p_ml_onelevel->i_id ) )
231 addButton->setEnabled( true );
232 addButton->setToolTip( qtr(I_PL_ADDML) );
235 addButton->setEnabled( false );
238 /* PopupAdd Menu for the Add Menu */
239 void StandardPLPanel::popupAdd()
242 if( currentRootId == THEPL->p_local_category->i_id ||
243 currentRootId == THEPL->p_local_onelevel->i_id )
245 popup.addAction( qtr(I_PL_ADDF), THEDP, SLOT(simplePLAppendDialog()));
246 popup.addAction( qtr(I_PL_ADVADD), THEDP, SLOT(PLAppendDialog()) );
247 popup.addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) );
249 else if( ( THEPL->p_ml_category &&
250 currentRootId == THEPL->p_ml_category->i_id ) ||
251 ( THEPL->p_ml_onelevel &&
252 currentRootId == THEPL->p_ml_onelevel->i_id ) )
254 popup.addAction( qtr(I_PL_ADDF), THEDP, SLOT(simpleMLAppendDialog()));
255 popup.addAction( qtr(I_PL_ADVADD), THEDP, SLOT( MLAppendDialog() ) );
256 popup.addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
258 popup.exec( QCursor::pos() - addButton->mapFromGlobal( QCursor::pos() )
259 + QPoint( 0, addButton->height() ) );
262 void StandardPLPanel::popupSelectColumn( QPoint pos )
264 ContextUpdateMapper = new QSignalMapper(this);
268 #define ADD_META_ACTION( meta ) { \
269 QAction* option = selectColMenu.addAction( qfu(VLC_META_##meta) ); \
270 option->setCheckable( true ); \
271 option->setChecked( model->shownFlags() & VLC_META_ENGINE_##meta ); \
272 ContextUpdateMapper->setMapping( option, VLC_META_ENGINE_##meta ); \
273 CONNECT( option, triggered(), ContextUpdateMapper, map() ); \
276 CONNECT( ContextUpdateMapper, mapped( int ), model, viewchanged( int ) );
278 ADD_META_ACTION( TRACKID );
279 ADD_META_ACTION( TITLE );
280 ADD_META_ACTION( DURATION );
281 ADD_META_ACTION( ARTIST );
282 ADD_META_ACTION( GENRE );
283 ADD_META_ACTION( COLLECTION );
284 ADD_META_ACTION( SEQ_NUM );
285 ADD_META_ACTION( DESCRIPTION );
287 #undef ADD_META_ACTION
289 selectColMenu.exec( QCursor::pos() );
292 /* ClearFilter LineEdit */
293 void StandardPLPanel::clearFilter()
295 searchLine->setText( "" );
298 /* Search in the playlist */
299 void StandardPLPanel::search( QString searchText )
301 model->search( searchText );
304 void StandardPLPanel::doPopup( QModelIndex index, QPoint point )
306 if( !index.isValid() ) return;
307 QItemSelectionModel *selection = view->selectionModel();
308 QModelIndexList list = selection->selectedIndexes();
309 model->popup( index, point, list );
312 /* Set the root of the new Playlist */
313 /* This activated by the selector selection */
314 void StandardPLPanel::setRoot( int i_root_id )
316 playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id,
319 p_item = playlist_GetPreferredNode( THEPL, p_item );
321 model->rebuild( p_item );
324 void StandardPLPanel::removeItem( int i_id )
326 model->removeItem( i_id );
329 /* Delete and Suppr key remove the selection
330 FilterKey function and code function */
331 void StandardPLPanel::keyPressEvent( QKeyEvent *e )
342 void StandardPLPanel::deleteSelection()
344 QItemSelectionModel *selection = view->selectionModel();
345 QModelIndexList list = selection->selectedIndexes();
346 model->doDelete( list );
349 StandardPLPanel::~StandardPLPanel()