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 "components/playlist/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>
43 #include <QSignalMapper>
47 StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
48 intf_thread_t *_p_intf,
49 playlist_t *p_playlist,
50 playlist_item_t *p_root ):
51 PLPanel( _parent, _p_intf )
53 model = new PLModel( p_playlist, p_intf, p_root, -1, this );
55 QVBoxLayout *layout = new QVBoxLayout();
56 layout->setSpacing( 0 ); layout->setMargin( 0 );
58 /* Create and configure the QTreeView */
59 view = new QVLCTreeView( 0 );
60 view->setModel(model);
61 view->setIconSize( QSize( 20, 20 ) );
62 view->setAlternatingRowColors( true );
63 view->setAnimated( true );
64 view->setSortingEnabled( true );
65 view->setSelectionMode( QAbstractItemView::ExtendedSelection );
66 view->setDragEnabled( true );
67 view->setAcceptDrops( true );
68 view->setDropIndicatorShown( true );
69 view->setAutoScroll( true );
71 /* Configure the size of the header */
72 view->header()->resizeSection( 0, 200 );
73 view->header()->resizeSection( 1, 80 );
74 view->header()->setSortIndicatorShown( true );
75 view->header()->setClickable( true );
76 view->header()->setContextMenuPolicy( Qt::CustomContextMenu );
78 /* Connections for the TreeView */
79 CONNECT( view, activated( const QModelIndex& ) ,
80 model,activateItem( const QModelIndex& ) );
81 CONNECT( view, rightClicked( QModelIndex , QPoint ),
82 this, doPopup( QModelIndex, QPoint ) );
83 CONNECT( model, dataChanged( const QModelIndex&, const QModelIndex& ),
84 this, handleExpansion( const QModelIndex& ) );
85 CONNECT( view->header(), customContextMenuRequested( const QPoint & ),
86 this, popupSelectColumn( QPoint ) );
89 CONNECT( parent, rootChanged( int ), this, setCurrentRootId( int ) );
91 /* Buttons configuration */
92 QHBoxLayout *buttons = new QHBoxLayout;
94 /* Add item to the playlist button */
95 addButton = new QPushButton;
96 addButton->setIcon( QIcon( ":/pixmaps/playlist_add.png" ) );
97 addButton->setMaximumWidth( 30 );
98 BUTTONACT( addButton, popupAdd() );
99 buttons->addWidget( addButton );
101 /* Random 2-state button */
102 randomButton = new QPushButton( this );
103 if( model->hasRandom() )
105 randomButton->setIcon( QIcon( ":/pixmaps/playlist_shuffle_on.png" ));
106 randomButton->setToolTip( qtr( I_PL_RANDOM ));
110 randomButton->setIcon( QIcon( ":/pixmaps/playlist_shuffle_off.png" ) );
111 randomButton->setToolTip( qtr( I_PL_NORANDOM ));
113 BUTTONACT( randomButton, toggleRandom() );
114 buttons->addWidget( randomButton );
116 /* Repeat 3-state button */
117 repeatButton = new QPushButton( this );
118 if( model->hasRepeat() )
120 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_one.png" ) );
121 repeatButton->setToolTip( qtr( I_PL_REPEAT ));
123 else if( model->hasLoop() )
125 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_all.png" ) );
126 repeatButton->setToolTip( qtr( I_PL_LOOP ));
130 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_off.png" ) );
131 repeatButton->setToolTip( qtr( I_PL_NOREPEAT ));
133 BUTTONACT( repeatButton, toggleRepeat() );
134 buttons->addWidget( repeatButton );
137 gotoPlayingButton = new QPushButton( qtr( "X" ), this );
138 BUTTONACT( gotoPlayingButton, gotoPlayingItem() );
139 buttons->addWidget( gotoPlayingButton );
141 /* A Spacer and the search possibilities */
142 QSpacerItem *spacer = new QSpacerItem( 10, 20 );
143 buttons->addItem( spacer );
145 QLabel *filter = new QLabel( qtr(I_PL_SEARCH) + " " );
146 buttons->addWidget( filter );
148 searchLine = new ClickLineEdit( qtr(I_PL_FILTER), 0 );
149 searchLine->setMinimumWidth( 80 );
150 CONNECT( searchLine, textChanged(QString), this, search(QString));
151 buttons->addWidget( searchLine ); filter->setBuddy( searchLine );
153 QPushButton *clear = new QPushButton;
154 clear->setText( qfu( "CL") );
155 clear->setMaximumWidth( 30 );
156 clear->setToolTip( qtr( "Clear" ));
157 BUTTONACT( clear, clearFilter() );
158 buttons->addWidget( clear );
160 /* Finish the layout */
161 layout->addWidget( view );
162 layout->addLayout( buttons );
163 // layout->addWidget( bar );
167 /* Function to toggle between the Repeat states */
168 void StandardPLPanel::toggleRepeat()
170 if( model->hasRepeat() )
172 model->setRepeat( false ); model->setLoop( true );
173 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_all.png" ) );
174 repeatButton->setToolTip( qtr( I_PL_LOOP ));
176 else if( model->hasLoop() )
178 model->setRepeat( false ) ; model->setLoop( false );
179 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_off.png" ) );
180 repeatButton->setToolTip( qtr( I_PL_NOREPEAT ));
184 model->setRepeat( true );
185 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_one.png" ) );
186 repeatButton->setToolTip( qtr( I_PL_REPEAT ));
190 /* Function to toggle between the Random states */
191 void StandardPLPanel::toggleRandom()
193 bool prev = model->hasRandom();
194 model->setRandom( !prev );
195 randomButton->setIcon( prev ?
196 QIcon( ":/pixmaps/playlist_shuffle_off.png" ) :
197 QIcon( ":/pixmaps/playlist_shuffle_on.png" ) );
198 randomButton->setToolTip( prev ? qtr( I_PL_NORANDOM ) : qtr(I_PL_RANDOM ) );
201 void StandardPLPanel::gotoPlayingItem()
203 view->scrollTo( view->currentIndex() );
206 void StandardPLPanel::handleExpansion( const QModelIndex &index )
208 if( model->isCurrent( index ) )
209 view->scrollTo( index, QAbstractItemView::EnsureVisible );
212 void StandardPLPanel::setCurrentRootId( int _new )
214 currentRootId = _new;
215 if( currentRootId == THEPL->p_local_category->i_id ||
216 currentRootId == THEPL->p_local_onelevel->i_id )
218 addButton->setEnabled( true );
219 addButton->setToolTip( qtr(I_PL_ADDPL) );
221 else if( ( THEPL->p_ml_category &&
222 currentRootId == THEPL->p_ml_category->i_id ) ||
223 ( THEPL->p_ml_onelevel &&
224 currentRootId == THEPL->p_ml_onelevel->i_id ) )
226 addButton->setEnabled( true );
227 addButton->setToolTip( qtr(I_PL_ADDML) );
230 addButton->setEnabled( false );
233 /* PopupAdd Menu for the Add Menu */
234 void StandardPLPanel::popupAdd()
237 if( currentRootId == THEPL->p_local_category->i_id ||
238 currentRootId == THEPL->p_local_onelevel->i_id )
240 popup.addAction( qtr(I_PL_ADDF), THEDP, SLOT(simplePLAppendDialog()));
241 popup.addAction( qtr(I_PL_ADVADD), THEDP, SLOT(PLAppendDialog()) );
242 popup.addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) );
244 else if( ( THEPL->p_ml_category &&
245 currentRootId == THEPL->p_ml_category->i_id ) ||
246 ( THEPL->p_ml_onelevel &&
247 currentRootId == THEPL->p_ml_onelevel->i_id ) )
249 popup.addAction( qtr(I_PL_ADDF), THEDP, SLOT(simpleMLAppendDialog()));
250 popup.addAction( qtr(I_PL_ADVADD), THEDP, SLOT( MLAppendDialog() ) );
251 popup.addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
253 popup.exec( QCursor::pos() - addButton->mapFromGlobal( QCursor::pos() )
254 + QPoint( 0, addButton->height() ) );
257 void StandardPLPanel::popupSelectColumn( QPoint pos )
259 ContextUpdateMapper = new QSignalMapper(this);
263 #define ADD_META_ACTION( meta ) { \
264 QAction* option = selectColMenu.addAction( qfu(VLC_META_##meta) ); \
265 option->setCheckable( true ); \
266 option->setChecked( model->shownFlags() & VLC_META_ENGINE_##meta ); \
267 ContextUpdateMapper->setMapping( option, VLC_META_ENGINE_##meta ); \
268 CONNECT( option, triggered(), ContextUpdateMapper, map() ); \
271 CONNECT( ContextUpdateMapper, mapped( int ), model, viewchanged( int ) );
273 ADD_META_ACTION( TITLE );
274 ADD_META_ACTION( ARTIST );
275 ADD_META_ACTION( DURATION );
276 ADD_META_ACTION( COLLECTION );
277 ADD_META_ACTION( GENRE );
278 ADD_META_ACTION( SEQ_NUM );
279 ADD_META_ACTION( RATING );
280 ADD_META_ACTION( DESCRIPTION );
282 #undef ADD_META_ACTION
284 selectColMenu.exec( QCursor::pos() );
287 /* ClearFilter LineEdit */
288 void StandardPLPanel::clearFilter()
290 searchLine->setText( "" );
293 /* Search in the playlist */
294 void StandardPLPanel::search( QString searchText )
296 model->search( searchText );
299 void StandardPLPanel::doPopup( QModelIndex index, QPoint point )
301 if( !index.isValid() ) return;
302 QItemSelectionModel *selection = view->selectionModel();
303 QModelIndexList list = selection->selectedIndexes();
304 model->popup( index, point, list );
307 /* Set the root of the new Playlist */
308 /* This activated by the selector selection */
309 void StandardPLPanel::setRoot( int i_root_id )
311 playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id,
314 p_item = playlist_GetPreferredNode( THEPL, p_item );
316 model->rebuild( p_item );
319 void StandardPLPanel::removeItem( int i_id )
321 model->removeItem( i_id );
324 /* Delete and Suppr key remove the selection
325 FilterKey function and code function */
326 void StandardPLPanel::keyPressEvent( QKeyEvent *e )
337 void StandardPLPanel::deleteSelection()
339 QItemSelectionModel *selection = view->selectionModel();
340 QModelIndexList list = selection->selectedIndexes();
341 model->doDelete( list );
344 StandardPLPanel::~StandardPLPanel()