[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [Amarok]  Make the playlist actions work for playlist files.
From:       Bart Cerneels <bart.cerneels () kde ! org>
Date:       2009-08-10 21:28:39
Message-ID: 200908110127.n7B1R3vx030847 () Wurst ! kollide ! net
[Download RAW message or body]

commit ea8212580e01c5d033e64425069e9cd454dd920d
Author:     Bart Cerneels <bart.cerneels@kde.org>
AuthorDate: Mon Aug 10 23:24:17 2009 +0200
Commit:     Bart Cerneels <bart.cerneels@kde.org>
CommitDate: Mon Aug 10 23:25:23 2009 +0200

    Make the playlist actions work for playlist files.
    
    2 methods were uninitialized and a cleanup of the write actions is needed.

diff --git a/src/browsers/playlistbrowser/UserPlaylistModel.cpp \
b/src/browsers/playlistbrowser/UserPlaylistModel.cpp index b1563b2..1afa6ab 100644
--- a/src/browsers/playlistbrowser/UserPlaylistModel.cpp
+++ b/src/browsers/playlistbrowser/UserPlaylistModel.cpp
@@ -68,6 +68,8 @@ PlaylistBrowserNS::UserModel::UserModel()
     : MetaPlaylistModel()
     , m_appendAction( 0 )
     , m_loadAction( 0 )
+    , m_renameAction( 0 )
+    , m_deleteAction( 0 )
 {
     s_instance = this;
     loadPlaylists();
@@ -458,13 +460,13 @@ PlaylistBrowserNS::UserModel::dropMimeData ( const QMimeData \
*data, Qt::DropActi  QList<QAction *>
 PlaylistBrowserNS::UserModel::actionsFor( const QModelIndexList &indices )
 {
-    QSet<QAction *> actions;
+    QList<QAction *> actions;
     m_selectedPlaylists.clear();
     m_selectedPlaylists << selectedPlaylists( indices );
     m_selectedTracks.clear();
     m_selectedTracks << selectedTracks( indices );
 
-    actions = QSet<QAction *>::fromList( createCommonActions( indices ) );
+    actions = createCommonActions( indices );
 
     // If a playlist is selected, we bring up playlist actions
     if( !m_selectedPlaylists.isEmpty() )
@@ -488,29 +490,23 @@ PlaylistBrowserNS::UserModel::actionsFor( const QModelIndexList \
&indices )  }
 
             if( writable )
-                actions += QSet<QAction *>::fromList(
-                        createWriteActions( indices ) );
+                actions << createWriteActions( indices );
 
         }
-        actions += QSet<QAction *>::fromList(
-                            The::playlistManager()->playlistActions( \
                m_selectedPlaylists )
-                        );
+        actions << The::playlistManager()->playlistActions( m_selectedPlaylists );
     }
     // Otherwise, tracks are selected, so we bring up track actions
     else
     {
         foreach( const QModelIndex &idx, indices )
         {
-            actions += QSet<QAction *>::fromList(
-                            The::playlistManager()->trackActions(
+            actions << The::playlistManager()->trackActions(
                                         m_playlists.value( idx.parent().internalId() \
                ),
-                                        idx.row()
-                                    )
-                        );
+                                        idx.row() );
         }
     }
 
-    return actions.toList();
+    return actions;
 }
 
 void
diff --git a/src/browsers/playlistbrowser/UserPlaylistTreeView.cpp \
b/src/browsers/playlistbrowser/UserPlaylistTreeView.cpp index f689880..1283b45 100644
--- a/src/browsers/playlistbrowser/UserPlaylistTreeView.cpp
+++ b/src/browsers/playlistbrowser/UserPlaylistTreeView.cpp
@@ -186,8 +186,11 @@ void PlaylistBrowserNS::UserPlaylistTreeView::contextMenuEvent( \
QContextMenuEven  if( actions.isEmpty() )
         return;
 
-    foreach( QAction * action, actions )
-        menu.addAction( action );
+    foreach( QAction *action, actions )
+    {
+        if( action )
+            menu.addAction( action );
+    }
 
     if( indices.count() == 0 )
         menu.addAction( m_addGroupAction );
diff --git a/src/playlistmanager/UserPlaylistProvider.h \
b/src/playlistmanager/UserPlaylistProvider.h index 20e930c..3d080c7 100644
--- a/src/playlistmanager/UserPlaylistProvider.h
+++ b/src/playlistmanager/UserPlaylistProvider.h
@@ -51,8 +51,8 @@ class AMAROK_EXPORT UserPlaylistProvider : public PlaylistProvider
 
         virtual bool supportsEmptyGroups();
 
-        QList<QAction *> playlistActions( Meta::PlaylistPtr playlist );
-        QList<QAction *> trackActions( Meta::PlaylistPtr playlist,
+        virtual QList<QAction *> playlistActions( Meta::PlaylistPtr playlist );
+        virtual QList<QAction *> trackActions( Meta::PlaylistPtr playlist,
                                                   int trackIndex );
 
         // UserPlaylistProvider-specific
diff --git a/src/playlistmanager/file/PlaylistFileProvider.cpp \
b/src/playlistmanager/file/PlaylistFileProvider.cpp index 261b233..09a8df2 100644
--- a/src/playlistmanager/file/PlaylistFileProvider.cpp
+++ b/src/playlistmanager/file/PlaylistFileProvider.cpp
@@ -99,6 +99,26 @@ PlaylistFileProvider::playlists()
     return m_playlists;
 }
 
+QList<QAction *>
+PlaylistFileProvider::playlistActions( Meta::PlaylistPtr playlist )
+{
+    Q_UNUSED( playlist );
+    QList<QAction *> actions;
+
+    return actions;
+}
+
+QList<QAction *>
+PlaylistFileProvider::trackActions( Meta::PlaylistPtr playlist, int trackIndex )
+{
+    Q_UNUSED( playlist );
+    Q_UNUSED( trackIndex );
+    QList<QAction *> actions;
+
+    return actions;
+}
+
+
 Meta::PlaylistPtr
 PlaylistFileProvider::save( const Meta::TrackList &tracks )
 {
@@ -163,6 +183,30 @@ PlaylistFileProvider::import( const KUrl &path )
     return true;
 }
 
+void
+PlaylistFileProvider::rename( Meta::PlaylistPtr playlist, const QString &newName )
+{
+    DEBUG_BLOCK
+    Q_UNUSED(playlist);
+    Q_UNUSED(newName);
+}
+
+void
+PlaylistFileProvider::deletePlaylists( Meta::PlaylistList playlistList )
+{
+    DEBUG_BLOCK
+    foreach( Meta::PlaylistPtr playlist, playlistList )
+    {
+        Meta::PlaylistFilePtr playlistFile = Meta::PlaylistFilePtr::dynamicCast( \
playlist ); +        if( playlistFile.isNull() )
+        {
+            error() << "Could not cast to playlistFilePtr at " << __FILE__ << ":" << \
__LINE__; +            continue;
+        }
+        QFile::remove( playlistFile->retrievableUrl().path() );
+    }
+}
+
 KConfigGroup
 PlaylistFileProvider::loadedPlaylistsConfig()
 {
diff --git a/src/playlistmanager/file/PlaylistFileProvider.h \
b/src/playlistmanager/file/PlaylistFileProvider.h index 97434dc..9a564ef 100644
--- a/src/playlistmanager/file/PlaylistFileProvider.h
+++ b/src/playlistmanager/file/PlaylistFileProvider.h
@@ -30,6 +30,8 @@ class KUrl;
 */
 class PlaylistFileProvider : public UserPlaylistProvider
 {
+    Q_OBJECT
+
     public:
         PlaylistFileProvider();
         ~PlaylistFileProvider();
@@ -41,6 +43,10 @@ class PlaylistFileProvider : public UserPlaylistProvider
 
         virtual Meta::PlaylistList playlists();
 
+        virtual QList<QAction *> playlistActions( Meta::PlaylistPtr playlist );
+        virtual QList<QAction *> trackActions( Meta::PlaylistPtr playlist,
+                                                  int trackIndex );
+
         virtual bool canSavePlaylists() { return true; }
 
         virtual Meta::PlaylistPtr save( const Meta::TrackList &tracks );
@@ -49,6 +55,10 @@ class PlaylistFileProvider : public UserPlaylistProvider
 
         bool import( const KUrl &path );
 
+        virtual bool isWritable() { return true; }
+        virtual void rename( Meta::PlaylistPtr playlist, const QString &newName );
+        virtual void deletePlaylists( Meta::PlaylistList playlistList );
+
     private:
         KConfigGroup loadedPlaylistsConfig();
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic