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 );
136 /* A Spacer and the search possibilities */
137 QSpacerItem *spacer = new QSpacerItem( 10, 20 );
138 buttons->addItem( spacer );
140 QLabel *filter = new QLabel( qtr(I_PL_SEARCH) + " " );
141 buttons->addWidget( filter );
143 searchLine = new ClickLineEdit( qtr(I_PL_FILTER), 0 );
144 searchLine->setMinimumWidth( 80 );
145 CONNECT( searchLine, textChanged(QString), this, search(QString));
146 buttons->addWidget( searchLine ); filter->setBuddy( searchLine );
148 QPushButton *clear = new QPushButton;
149 clear->setText( qfu( "CL") );
150 clear->setMaximumWidth( 30 );
151 clear->setToolTip( qtr( "Clear" ));
152 BUTTONACT( clear, clearFilter() );
153 buttons->addWidget( clear );
155 /* Finish the layout */
156 layout->addWidget( view );
157 layout->addLayout( buttons );
158 // layout->addWidget( bar );
162 /* Function to toggle between the Repeat states */
163 void StandardPLPanel::toggleRepeat()
165 if( model->hasRepeat() )
167 model->setRepeat( false ); model->setLoop( true );
168 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_all.png" ) );
169 repeatButton->setToolTip( qtr( I_PL_LOOP ));
171 else if( model->hasLoop() )
173 model->setRepeat( false ) ; model->setLoop( false );
174 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_off.png" ) );
175 repeatButton->setToolTip( qtr( I_PL_NOREPEAT ));
179 model->setRepeat( true );
180 repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_one.png" ) );
181 repeatButton->setToolTip( qtr( I_PL_REPEAT ));
185 /* Function to toggle between the Random states */
186 void StandardPLPanel::toggleRandom()
188 bool prev = model->hasRandom();
189 model->setRandom( !prev );
190 randomButton->setIcon( prev ?
191 QIcon( ":/pixmaps/playlist_shuffle_off.png" ) :
192 QIcon( ":/pixmaps/playlist_shuffle_on.png" ) );
193 randomButton->setToolTip( prev ? qtr( I_PL_NORANDOM ) : qtr(I_PL_RANDOM ) );
196 void StandardPLPanel::handleExpansion( const QModelIndex &index )
198 if( model->isCurrent( index ) )
199 view->scrollTo( index, QAbstractItemView::EnsureVisible );
202 void StandardPLPanel::setCurrentRootId( int _new )
204 currentRootId = _new;
205 if( currentRootId == THEPL->p_local_category->i_id ||
206 currentRootId == THEPL->p_local_onelevel->i_id )
208 addButton->setEnabled( true );
209 addButton->setToolTip( qtr(I_PL_ADDPL) );
211 else if( ( THEPL->p_ml_category &&
212 currentRootId == THEPL->p_ml_category->i_id ) ||
213 ( THEPL->p_ml_onelevel &&
214 currentRootId == THEPL->p_ml_onelevel->i_id ) )
216 addButton->setEnabled( true );
217 addButton->setToolTip( qtr(I_PL_ADDML) );
220 addButton->setEnabled( false );
223 /* PopupAdd Menu for the Add Menu */
224 void StandardPLPanel::popupAdd()
227 if( currentRootId == THEPL->p_local_category->i_id ||
228 currentRootId == THEPL->p_local_onelevel->i_id )
230 popup.addAction( qtr(I_PL_ADDF), THEDP, SLOT(simplePLAppendDialog()));
231 popup.addAction( qtr(I_PL_ADVADD), THEDP, SLOT(PLAppendDialog()) );
232 popup.addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) );
234 else if( ( THEPL->p_ml_category &&
235 currentRootId == THEPL->p_ml_category->i_id ) ||
236 ( THEPL->p_ml_onelevel &&
237 currentRootId == THEPL->p_ml_onelevel->i_id ) )
239 popup.addAction( qtr(I_PL_ADDF), THEDP, SLOT(simpleMLAppendDialog()));
240 popup.addAction( qtr(I_PL_ADVADD), THEDP, SLOT( MLAppendDialog() ) );
241 popup.addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
243 popup.exec( QCursor::pos() - addButton->mapFromGlobal( QCursor::pos() )
244 + QPoint( 0, addButton->height() ) );
247 void StandardPLPanel::popupSelectColumn( QPoint pos )
249 ContextUpdateMapper = new QSignalMapper(this);
253 #define ADD_META_ACTION( meta ) { \
254 QAction* option = selectColMenu.addAction( qfu(VLC_META_##meta) ); \
255 option->setCheckable( true ); \
256 option->setChecked( model->shownFlags() & VLC_META_ENGINE_##meta ); \
257 ContextUpdateMapper->setMapping( option, VLC_META_ENGINE_##meta ); \
258 CONNECT( option, triggered(), ContextUpdateMapper, map() ); \
261 CONNECT( ContextUpdateMapper, mapped( int ), model, viewchanged( int ) );
263 ADD_META_ACTION( TITLE );
264 ADD_META_ACTION( ARTIST );
265 ADD_META_ACTION( DURATION );
266 ADD_META_ACTION( COLLECTION );
267 ADD_META_ACTION( GENRE );
268 ADD_META_ACTION( SEQ_NUM );
269 ADD_META_ACTION( RATING );
270 ADD_META_ACTION( DESCRIPTION );
272 #undef ADD_META_ACTION
274 selectColMenu.exec( QCursor::pos() );
277 /* ClearFilter LineEdit */
278 void StandardPLPanel::clearFilter()
280 searchLine->setText( "" );
283 /* Search in the playlist */
284 void StandardPLPanel::search( QString searchText )
286 model->search( searchText );
289 void StandardPLPanel::doPopup( QModelIndex index, QPoint point )
291 if( !index.isValid() ) return;
292 QItemSelectionModel *selection = view->selectionModel();
293 QModelIndexList list = selection->selectedIndexes();
294 model->popup( index, point, list );
297 /* Set the root of the new Playlist */
298 /* This activated by the selector selection */
299 void StandardPLPanel::setRoot( int i_root_id )
301 playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id,
304 p_item = playlist_GetPreferredNode( THEPL, p_item );
306 model->rebuild( p_item );
309 void StandardPLPanel::removeItem( int i_id )
311 model->removeItem( i_id );
314 /* Delete and Suppr key remove the selection
315 FilterKey function and code function */
316 void StandardPLPanel::keyPressEvent( QKeyEvent *e )
327 void StandardPLPanel::deleteSelection()
329 QItemSelectionModel *selection = view->selectionModel();
330 QModelIndexList list = selection->selectedIndexes();
331 model->doDelete( list );
334 StandardPLPanel::~StandardPLPanel()