Git commit 0638d9dfce905ef66cc28074810e3ed5c37479f0 by Bart Cerneels. Committed on 27/09/2010 at 11:26. Pushed by shanachie into branch 'master'.
Add rootnode action to create empty playlist. Required change to QtGroupingProxy to enable actions for the rootnode (empty area in the views). BUG:202725 GUI:Context menu action the empty saved playlist area to create new empty playlist. M +2 -0 ChangeLog M +9 -0 src/browsers/playlistbrowser/PlaylistBrowserFilterProxy.cpp M +1 -0 src/browsers/playlistbrowser/PlaylistBrowserFilterProxy.h M +20 -4 src/browsers/playlistbrowser/PlaylistBrowserModel.cpp M +2 -0 src/browsers/playlistbrowser/PlaylistBrowserModel.h M +9 -3 src/browsers/playlistbrowser/PlaylistBrowserView.cpp M +2 -0 src/browsers/playlistbrowser/PlaylistsByProviderProxy.cpp M +6 -0 src/browsers/playlistbrowser/PodcastModel.cpp M +2 -1 src/browsers/playlistbrowser/QtGroupingProxy.cpp http://commits.kde.org/amarok/0638d9dfce905ef66cc28074810e3ed5c37479f0 diff --git a/ChangeLog b/ChangeLog index c16a3b5..50c375b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ Amarok ChangeLog Version 2.5.0-Beta 1 FEATURES: + * Addded a "create new playlist" action in the empty space of the Saved + Playlists. (BR202725) * Add new type of optional tokens in format string (Collection Organizer) (BR 264874) * Compilations are properly marked as such when transferring music diff --git a/src/browsers/playlistbrowser/PlaylistBrowserFilterProxy.cpp b/src/browsers/playlistbrowser/PlaylistBrowserFilterProxy.cpp index 84439fa..36a05c8 100644 --- a/src/browsers/playlistbrowser/PlaylistBrowserFilterProxy.cpp +++ b/src/browsers/playlistbrowser/PlaylistBrowserFilterProxy.cpp @@ -34,6 +34,15 @@ PlaylistBrowserFilterProxy::setSourceModel( QAbstractItemModel *model ) SLOT(slotRenameIndex( const QModelIndex & )) ); } +QVariant +PlaylistBrowserFilterProxy::data(const QModelIndex &index, int role) const +{ + debug() << index << " role: " << role; + QVariant result = QSortFilterProxyModel::data( index, role ); + debug() << result; + return result; +} + void PlaylistBrowserFilterProxy::slotRenameIndex( const QModelIndex &sourceIdx ) { diff --git a/src/browsers/playlistbrowser/PlaylistBrowserFilterProxy.h b/src/browsers/playlistbrowser/PlaylistBrowserFilterProxy.h index f0e1a72..a6b80f2 100644 --- a/src/browsers/playlistbrowser/PlaylistBrowserFilterProxy.h +++ b/src/browsers/playlistbrowser/PlaylistBrowserFilterProxy.h @@ -32,6 +32,7 @@ class PlaylistBrowserFilterProxy : public QSortFilterProxyModel // QSortFilterProxyModel methods virtual void setSourceModel( QAbstractItemModel *sourceModel ); + virtual QVariant data(const QModelIndex &index, int role) const; signals: void renameIndex( const QModelIndex &index ); diff --git a/src/browsers/playlistbrowser/PlaylistBrowserModel.cpp b/src/browsers/playlistbrowser/PlaylistBrowserModel.cpp index a914b0b..ce87656 100644 --- a/src/browsers/playlistbrowser/PlaylistBrowserModel.cpp +++ b/src/browsers/playlistbrowser/PlaylistBrowserModel.cpp @@ -39,6 +39,11 @@ lessThanPlaylistTitles( const Playlists::PlaylistPtr &lhs, const Playlists::Play PlaylistBrowserModel::PlaylistBrowserModel( int playlistCategory ) : m_playlistCategory( playlistCategory ) { + m_createEmptyPlaylistAction = new QAction( KIcon( "media-track-add-amarok" ), + i18n( "Create empty playlist" ), + this ); + connect( m_createEmptyPlaylistAction, SIGNAL(triggered()), SLOT(slotCreateEmptyPlaylist()) ); + //common, unconditional actions m_appendAction = new QAction( KIcon( "media-track-add-amarok" ), i18n( "&Add to Playlist" ), this ); @@ -70,9 +75,6 @@ PlaylistBrowserModel::PlaylistBrowserModel( int playlistCategory ) QVariant PlaylistBrowserModel::data( const QModelIndex &index, int role ) const { - if( !index.isValid() ) - return QVariant(); - int row = REMOVE_TRACK_MASK(index.internalId()); Playlists::PlaylistPtr playlist = m_playlists.value( row ); @@ -168,7 +170,7 @@ PlaylistBrowserModel::data( const QModelIndex &index, int role ) const break; } - default: return QVariant(); + default: break; } @@ -400,6 +402,7 @@ PlaylistBrowserModel::flags( const QModelIndex &idx ) const return Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; } + QVariant PlaylistBrowserModel::headerData( int section, Qt::Orientation orientation, int role ) const { @@ -677,6 +680,13 @@ PlaylistBrowserModel::slotPlaylistUpdated( Playlists::PlaylistPtr playlist, int endInsertRows(); } +void +PlaylistBrowserModel::slotCreateEmptyPlaylist() +{ + The::playlistManager()->save( Meta::TrackList(), + Amarok::generatePlaylistName( Meta::TrackList() ) ); +} + Meta::TrackList PlaylistBrowserModel::tracksFromIndexes( const QModelIndexList &list ) const { @@ -742,6 +752,12 @@ PlaylistBrowserModel::providerForIndex( const QModelIndex &idx ) const QActionList PlaylistBrowserModel::actionsFor( const QModelIndex &idx ) const { + if( !idx.isValid() ) + { + QActionList emptyActions; + emptyActions << m_createEmptyPlaylistAction; + return emptyActions; + } //wheter we use the list from m_appendAction of m_loadAction does not matter they are the same QModelIndexList actionList = m_appendAction->data().value<QModelIndexList>(); diff --git a/src/browsers/playlistbrowser/PlaylistBrowserModel.h b/src/browsers/playlistbrowser/PlaylistBrowserModel.h index ae495ec..432c1b1 100644 --- a/src/browsers/playlistbrowser/PlaylistBrowserModel.h +++ b/src/browsers/playlistbrowser/PlaylistBrowserModel.h @@ -116,11 +116,13 @@ class PlaylistBrowserModel : public QAbstractItemModel, void slotPlaylistAdded( Playlists::PlaylistPtr playlist, int category ); void slotPlaylistRemoved( Playlists::PlaylistPtr playlist, int category ); void slotPlaylistUpdated( Playlists::PlaylistPtr playlist, int category ); + void slotCreateEmptyPlaylist(); private: int m_playlistCategory; QAction *m_appendAction; QAction *m_loadAction; + QAction *m_createEmptyPlaylistAction; }; } diff --git a/src/browsers/playlistbrowser/PlaylistBrowserView.cpp b/src/browsers/playlistbrowser/PlaylistBrowserView.cpp index 48465b2..9c4236d 100644 --- a/src/browsers/playlistbrowser/PlaylistBrowserView.cpp +++ b/src/browsers/playlistbrowser/PlaylistBrowserView.cpp @@ -286,7 +286,13 @@ PlaylistBrowserNS::PlaylistBrowserView::keyPressEvent( QKeyEvent *event ) void PlaylistBrowserNS::PlaylistBrowserView::contextMenuEvent( QContextMenuEvent *event ) { - QModelIndexList indices = selectedIndexes(); + QModelIndex clickedIdx = indexAt( event->pos() ); + + QModelIndexList indices; + if( selectedIndexes().contains( clickedIdx ) ) + indices << selectedIndexes(); + else + indices << clickedIdx; QActionList actions = actionsFor( indices ); @@ -338,8 +344,8 @@ PlaylistBrowserNS::PlaylistBrowserView::actionsFor( QModelIndexList indexes ) QActionList actions; foreach( QModelIndex idx, indexes ) { - QActionList idxActions = - idx.data( PlaylistBrowserNS::PlaylistBrowserModel::ActionRole ).value<QActionList>(); + QActionList idxActions = model()->data( idx, + PlaylistBrowserNS::PlaylistBrowserModel::ActionRole ).value<QActionList>(); //only add unique actions model is responsible for making them unique foreach( QAction *action, idxActions ) { diff --git a/src/browsers/playlistbrowser/PlaylistsByProviderProxy.cpp b/src/browsers/playlistbrowser/PlaylistsByProviderProxy.cpp index 8469639..1ce0c14 100644 --- a/src/browsers/playlistbrowser/PlaylistsByProviderProxy.cpp +++ b/src/browsers/playlistbrowser/PlaylistsByProviderProxy.cpp @@ -41,6 +41,8 @@ PlaylistsByProviderProxy::PlaylistsByProviderProxy( QAbstractItemModel *model, i QVariant PlaylistsByProviderProxy::data( const QModelIndex &idx, int role ) const { + //TODO: actions for empty providers + //TODO: filter out actions not from the provider, possibly using QAction separators marking // the source of the actions (makes sense in the UI as well. diff --git a/src/browsers/playlistbrowser/PodcastModel.cpp b/src/browsers/playlistbrowser/PodcastModel.cpp index 5923f2c..1cad82e 100644 --- a/src/browsers/playlistbrowser/PodcastModel.cpp +++ b/src/browsers/playlistbrowser/PodcastModel.cpp @@ -390,6 +390,12 @@ PlaylistBrowserNS::PodcastModel::refreshPodcasts() QActionList PlaylistBrowserNS::PodcastModel::actionsFor( const QModelIndex &idx ) const { + if( !idx.isValid() ) + { + //TODO: add podcast action + return QActionList(); + } + QActionList actions = PlaylistBrowserModel::actionsFor( idx ); /* by default a list of podcast episodes can only be changed to isNew = false, except diff --git a/src/browsers/playlistbrowser/QtGroupingProxy.cpp b/src/browsers/playlistbrowser/QtGroupingProxy.cpp index 635f740..c6bbf8f 100644 --- a/src/browsers/playlistbrowser/QtGroupingProxy.cpp +++ b/src/browsers/playlistbrowser/QtGroupingProxy.cpp @@ -358,7 +358,8 @@ QVariant QtGroupingProxy::data( const QModelIndex &index, int role ) const { if( !index.isValid() ) - return QVariant(); + return sourceModel()->data( m_rootNode, role ); //rootNode could have useful data + //qDebug() << __FUNCTION__ << index << " role: " << role; int row = index.row(); int column = index.column();
