extragear/multimedia/amarok/src

Bart Cerneels bart.cerneels at kde.org
Sat Jan 31 10:07:32 CET 2009


SVN commit 918988 by shanachie:

Add PlaylistsInGroupsProxy to allow grouping of all playlists.

This proxy model turns data from PlaylistBrowserNS::UserModel::GroupRole into folders. i.e. turns a flat model into a treemodel based on a certain role.

This can probably be resused but for now only used for playlist grouping by folder and soon also by provider.

CCMAIL:amarok-devel at kde.org

 M  +3 -2      CMakeLists.txt  
 M  +8 -5      browsers/playlistbrowser/PlaylistCategory.cpp  
 M  +3 -1      browsers/playlistbrowser/PlaylistCategory.h  
 A             browsers/playlistbrowser/PlaylistsInGroupsProxy.cpp   [License: GPL (v2+)]
 A             browsers/playlistbrowser/PlaylistsInGroupsProxy.h   [License: GPL (v2+)]
 M  +12 -16    browsers/playlistbrowser/UserPlaylistModel.cpp  
 M  +2 -2      browsers/playlistbrowser/UserPlaylistModel.h  
 M  +1 -1      playlistmanager/sql/SqlUserPlaylistProvider.cpp  


--- trunk/extragear/multimedia/amarok/src/CMakeLists.txt #918987:918988
@@ -265,9 +265,9 @@
     context/LyricsManager.cpp
 	context/ToolbarView.cpp
     context/layouts/ContextLayout.cpp
-    context/layouts/VerticalLayout.cpp	
+    context/layouts/VerticalLayout.cpp
 	context/toolbar/AppletItemOverlay.cpp
-	context/toolbar/AppletToolbar.cpp 
+	context/toolbar/AppletToolbar.cpp
 	context/toolbar/AppletToolbarAddItem.cpp
 	context/toolbar/AppletToolbarAppletItem.cpp
 	context/toolbar/AppletToolbarConfigItem.cpp
@@ -302,6 +302,7 @@
     browsers/playlistbrowser/UserPlaylistModel.cpp
     browsers/playlistbrowser/UserPlaylistTreeView.cpp
     browsers/playlistbrowser/PlaylistCategory.cpp
+    browsers/playlistbrowser/PlaylistsInGroupsProxy.cpp
     browsers/playlistbrowser/PodcastModel.cpp
     browsers/playlistbrowser/PodcastCategory.cpp
 )
--- trunk/extragear/multimedia/amarok/src/browsers/playlistbrowser/PlaylistCategory.cpp #918987:918988
@@ -22,6 +22,7 @@
 #include "CollectionManager.h"
 #include "PaletteHandler.h"
 #include "playlist/PlaylistModel.h"
+#include "PlaylistsInGroupsProxy.h"
 #include "context/popupdropper/libpud/PopupDropperAction.h"
 // #include "SqlPlaylist.h"
 // #include "SqlPlaylistGroup.h"
@@ -52,7 +53,6 @@
     m_playlistView = new UserPlaylistTreeView( this );
     m_playlistView->setFrameShape( QFrame::NoFrame );
     m_playlistView->setContentsMargins(0,0,0,0);
-    m_playlistView->setModel( PlaylistBrowserNS::UserModel::instance() );
     m_playlistView->header()->hide();
 
     //m_playlistView->setSelectionMode(QAbstractItemView::SingleSelection);
@@ -65,8 +65,11 @@
     //connect( m_playlistView, SIGNAL( activated( const QModelIndex & ) ), this, SLOT( itemActivated(  const QModelIndex & ) ) );
     //connect( m_playlistView, SIGNAL( customContextMenuRequested( const QPoint & ) ), this, SLOT( showContextMenu( const QPoint & ) ) );
 
-    connect( PlaylistBrowserNS::UserModel::instance(), SIGNAL( editIndex( const QModelIndex & ) ), m_playlistView, SLOT( edit( const QModelIndex & ) ) );
+    m_groupedProxy = new PlaylistsInGroupsProxy( PlaylistBrowserNS::UserModel::instance() );
+    m_playlistView->setModel( m_groupedProxy );
 
+    connect( m_groupedProxy, SIGNAL( editIndex( const QModelIndex & ) ), m_playlistView, SLOT( edit( const QModelIndex & ) ) );
+
     connect( The::paletteHandler(), SIGNAL( newPalette( const QPalette & ) ), SLOT( newPalette( const QPalette & ) ) );
 
     QVBoxLayout *vLayout = new QVBoxLayout( this );
@@ -78,7 +81,7 @@
 
     m_addGroupAction = new KAction( KIcon("media-track-add-amarok" ), i18n( "Add Folder" ), this  );
     m_toolBar->addAction( m_addGroupAction );
-    connect( m_addGroupAction, SIGNAL( triggered( bool ) ), PlaylistBrowserNS::UserModel::instance(), SLOT( createNewGroup() ) );
+//TODO:     connect( m_addGroupAction, SIGNAL( triggered( bool ) ), m_groupedProxy, SLOT( createNewGroup() ) );
 
     m_playlistView->setNewGroupAction( m_addGroupAction );
 
@@ -96,7 +99,7 @@
 void
 PlaylistBrowserNS::PlaylistCategory::showAddStreamDialog()
 {
-    KDialog *dialog = new PlaylistBrowserNS::StreamEditor( this );
+    KDialog *dialog = new PlaylistBrowserNS::treamEditor( this );
     connect( dialog, SIGNAL( okClicked() ), this, SLOT( streamDialogConfirmed() ) );
 }*/
 /*
@@ -109,7 +112,7 @@
     Meta::TrackPtr track = CollectionManager::instance()->trackForUrl(  dialog->streamUrl() );
     if( !track.isNull() )
     {
-        PlaylistBrowserNS::UserModel::instance()->createNewStream(  dialog->streamName(), track );
+        m_model->createNewStream(  dialog->streamName(), track );
     }
     else
     {
--- trunk/extragear/multimedia/amarok/src/browsers/playlistbrowser/PlaylistCategory.h #918987:918988
@@ -34,6 +34,8 @@
 class KAction;
 class KLineEdit;
 
+class PlaylistsInGroupsProxy;
+
 namespace PlaylistBrowserNS {
 
 /**
@@ -61,8 +63,8 @@
     UserPlaylistTreeView * m_playlistView;
 
     KAction * m_addGroupAction;
+    PlaylistsInGroupsProxy *m_groupedProxy;
 
-
 };
 
 class StreamEditor : public KDialog
--- trunk/extragear/multimedia/amarok/src/browsers/playlistbrowser/UserPlaylistModel.cpp #918987:918988
@@ -80,29 +80,25 @@
 QVariant
 PlaylistBrowserNS::UserModel::data(const QModelIndex & index, int role) const
 {
+    DEBUG_BLOCK
+
     if ( !index.isValid() )
         return QVariant();
 
     Meta::PlaylistPtr item = m_playlists.value( index.internalId() );
 
-    if ( role == 0xf00d )
-        return QVariant::fromValue( item );
-    else if ( role == Qt::DisplayRole || role == Qt::EditRole )
-        return item->name();
-    else if( role == DescriptionRole || role == Qt::ToolTipRole )
-        return item->description();
-    else if( role == OriginRole )
-        return QVariant(); //TODO return the provider name
-    else if (role == Qt::DecorationRole )
-        return QVariant( KIcon( "amarok_playlist" ) );
-    else if( role == GroupRole )
+    switch( role )
     {
-        QStringList groups = item->groups();
-
-        return groups.first();
+        case 0xf00d: return QVariant::fromValue( item );
+        case Qt::DisplayRole:
+        case Qt::EditRole: return item->name();
+        case DescriptionRole:
+        case Qt::ToolTipRole: return item->description();
+        case OriginRole: return QVariant(); //TODO return the provider name
+        case Qt::DecorationRole: return QVariant( KIcon( "amarok_playlist" ) );
+        case GroupRole: return item->groups();
+        default: return QVariant();
     }
-
-    return QVariant();
 }
 
 QModelIndex
--- trunk/extragear/multimedia/amarok/src/browsers/playlistbrowser/UserPlaylistModel.h #918987:918988
@@ -43,8 +43,8 @@
         enum {
             DescriptionRole = Qt::UserRole + 1,
             //Where is this Playlist from i.e. which PlaylistProvider
-            OriginRole = Qt::UserRole,
-            GroupRole = Qt::UserRole //What is the name of the group this Playlist is in.
+            OriginRole = Qt::UserRole + 2,
+            GroupRole = Qt::UserRole + 3 //What is the name of the group this Playlist is in.
         };
         static UserModel * instance();
 
--- trunk/extragear/multimedia/amarok/src/playlistmanager/sql/SqlUserPlaylistProvider.cpp #918987:918988
@@ -35,7 +35,7 @@
     : UserPlaylistProvider()
 {
     checkTables();
-    m_root = Meta::SqlPlaylistGroupPtr( new Meta::SqlPlaylistGroup( "root",
+    m_root = Meta::SqlPlaylistGroupPtr( new Meta::SqlPlaylistGroup( "",
             Meta::SqlPlaylistGroupPtr() ) );
 }
 


More information about the Amarok-devel mailing list