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->setModel(model);
64 view->setIconSize( QSize( 20, 20 ) );
65 view->setAlternatingRowColors( true );
66 view->setAnimated( true );
67 view->setSortingEnabled( true );
68 view->setSelectionMode( QAbstractItemView::ExtendedSelection );
69 view->setDragEnabled( true );
70 view->setAcceptDrops( true );
71 view->setDropIndicatorShown( true );
72 view->setAutoScroll( true );
74 /* Configure the size of the header */
75 view->header()->resizeSection( 0, 200 );
76 view->header()->resizeSection( 1, 80 );
77 view->header()->setSortIndicatorShown( true );
78 view->header()->setClickable( true );
79 view->header()->setContextMenuPolicy( Qt::CustomContextMenu );
81 /* Connections for the TreeView */
82 CONNECT( view, activated( const QModelIndex& ) ,
83 model,activateItem( const QModelIndex& ) );
84 CONNECT( view, rightClicked( QModelIndex , QPoint ),
85 this, doPopup( QModelIndex, QPoint ) );
86 CONNECT( model, dataChanged( const QModelIndex&, const QModelIndex& ),
87 this, handleExpansion( const QModelIndex& ) );
88 CONNECT( view->header(), customContextMenuRequested( const QPoint & ),
89 this, popupSelectColumn( QPoint ) );
92 CONNECT( parent, rootChanged( int ), this, setCurrentRootId( int ) );
94 /* Buttons configuration */
95 QHBoxLayout *buttons = new QHBoxLayout;
97 /* Add item to the playlist button */
98 addButton = new QPushButton;
99 addButton->setIcon( QIcon( ":/pixmaps/playlist_add.png" ) );
100 addButton->setMaximumWidth( 30 );
101 BUTTONACT( addButton, popupAdd() );
102 buttons->addWidget( addButton );
104 /* Random 2-state button */
105 randomButton = new QPushButton( this );
106 if( model->hasRandom() )
108 randomButton->setIcon( QIcon( ":/pixmaps/playlist_shuffle_on.png" ));
109 randomButton->setToolTip( qtr( I_PL_RANDOM ));
113 randomButton->setIcon( QIcon( ":/pixmaps/playlist_shuffle_off.png" ) );
114 randomButton->setToolTip( qtr( I_PL_NORANDOM ));
116 BUTTONACT( randomButton, toggleRandom() );
117 buttons->addWidget( randomButton );
119 /* Repeat 3-state button */
120 repeatButton = new QPushButton( this );
121 if( model->hasRepeat() )
123 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_one.png" ) );
124 repeatButton->setToolTip( qtr( I_PL_REPEAT ));
126 else if( model->hasLoop() )
128 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_all.png" ) );
129 repeatButton->setToolTip( qtr( I_PL_LOOP ));
133 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_off.png" ) );
134 repeatButton->setToolTip( qtr( I_PL_NOREPEAT ));
136 BUTTONACT( repeatButton, toggleRepeat() );
137 buttons->addWidget( repeatButton );
140 gotoPlayingButton = new QPushButton( "X" , this );
141 gotoPlayingButton->setToolTip( qtr( "Show the current item" ));
142 BUTTONACT( gotoPlayingButton, gotoPlayingItem() );
143 buttons->addWidget( gotoPlayingButton );
145 /* A Spacer and the search possibilities */
146 QSpacerItem *spacer = new QSpacerItem( 10, 20 );
147 buttons->addItem( spacer );
149 QLabel *filter = new QLabel( qtr(I_PL_SEARCH) + " " );
150 buttons->addWidget( filter );
152 searchLine = new ClickLineEdit( qtr(I_PL_FILTER), 0 );
153 searchLine->setMinimumWidth( 80 );
154 CONNECT( searchLine, textChanged(QString), this, search(QString));
155 buttons->addWidget( searchLine ); filter->setBuddy( searchLine );
157 QPushButton *clear = new QPushButton;
158 clear->setText( qfu( "CL") );
159 clear->setMaximumWidth( 30 );
160 clear->setToolTip( qtr( "Clear" ));
161 BUTTONACT( clear, clearFilter() );
162 buttons->addWidget( clear );
164 /* Finish the layout */
165 layout->addWidget( view );
166 layout->addLayout( buttons );
167 // layout->addWidget( bar );
171 /* Function to toggle between the Repeat states */
172 void StandardPLPanel::toggleRepeat()
174 if( model->hasRepeat() )
176 model->setRepeat( false ); model->setLoop( true );
177 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_all.png" ) );
178 repeatButton->setToolTip( qtr( I_PL_LOOP ));
180 else if( model->hasLoop() )
182 model->setRepeat( false ) ; model->setLoop( false );
183 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_off.png" ) );
184 repeatButton->setToolTip( qtr( I_PL_NOREPEAT ));
188 model->setRepeat( true );
189 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_one.png" ) );
190 repeatButton->setToolTip( qtr( I_PL_REPEAT ));
194 /* Function to toggle between the Random states */
195 void StandardPLPanel::toggleRandom()
197 bool prev = model->hasRandom();
198 model->setRandom( !prev );
199 randomButton->setIcon( prev ?
200 QIcon( ":/pixmaps/playlist_shuffle_off.png" ) :
201 QIcon( ":/pixmaps/playlist_shuffle_on.png" ) );
202 randomButton->setToolTip( prev ? qtr( I_PL_NORANDOM ) : qtr(I_PL_RANDOM ) );
205 void StandardPLPanel::gotoPlayingItem()
207 view->scrollTo( view->currentIndex() );
210 void StandardPLPanel::handleExpansion( const QModelIndex &index )
212 if( model->isCurrent( index ) )
213 view->scrollTo( index, QAbstractItemView::EnsureVisible );
216 void StandardPLPanel::setCurrentRootId( int _new )
218 currentRootId = _new;
219 if( currentRootId == THEPL->p_local_category->i_id ||
220 currentRootId == THEPL->p_local_onelevel->i_id )
222 addButton->setEnabled( true );
223 addButton->setToolTip( qtr(I_PL_ADDPL) );
225 else if( ( THEPL->p_ml_category &&
226 currentRootId == THEPL->p_ml_category->i_id ) ||
227 ( THEPL->p_ml_onelevel &&
228 currentRootId == THEPL->p_ml_onelevel->i_id ) )
230 addButton->setEnabled( true );
231 addButton->setToolTip( qtr(I_PL_ADDML) );
234 addButton->setEnabled( false );
237 /* PopupAdd Menu for the Add Menu */
238 void StandardPLPanel::popupAdd()
241 if( currentRootId == THEPL->p_local_category->i_id ||
242 currentRootId == THEPL->p_local_onelevel->i_id )
244 popup.addAction( qtr(I_PL_ADDF), THEDP, SLOT(simplePLAppendDialog()));
245 popup.addAction( qtr(I_PL_ADVADD), THEDP, SLOT(PLAppendDialog()) );
246 popup.addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) );
248 else if( ( THEPL->p_ml_category &&
249 currentRootId == THEPL->p_ml_category->i_id ) ||
250 ( THEPL->p_ml_onelevel &&
251 currentRootId == THEPL->p_ml_onelevel->i_id ) )
253 popup.addAction( qtr(I_PL_ADDF), THEDP, SLOT(simpleMLAppendDialog()));
254 popup.addAction( qtr(I_PL_ADVADD), THEDP, SLOT( MLAppendDialog() ) );
255 popup.addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
257 popup.exec( QCursor::pos() - addButton->mapFromGlobal( QCursor::pos() )
258 + QPoint( 0, addButton->height() ) );
261 void StandardPLPanel::popupSelectColumn( QPoint pos )
263 ContextUpdateMapper = new QSignalMapper(this);
267 #define ADD_META_ACTION( meta ) { \
268 QAction* option = selectColMenu.addAction( qfu(VLC_META_##meta) ); \
269 option->setCheckable( true ); \
270 option->setChecked( model->shownFlags() & VLC_META_ENGINE_##meta ); \
271 ContextUpdateMapper->setMapping( option, VLC_META_ENGINE_##meta ); \
272 CONNECT( option, triggered(), ContextUpdateMapper, map() ); \
275 CONNECT( ContextUpdateMapper, mapped( int ), model, viewchanged( int ) );
277 ADD_META_ACTION( TITLE );
278 ADD_META_ACTION( DURATION );
279 ADD_META_ACTION( ARTIST );
280 ADD_META_ACTION( GENRE );
281 ADD_META_ACTION( COLLECTION );
282 ADD_META_ACTION( SEQ_NUM );
283 ADD_META_ACTION( DESCRIPTION );
284 ADD_META_ACTION( RATING );
285 ADD_META_ACTION( TRACKID );
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()