extragear/multimedia/amarok/src

Leo Franchi lfranchi at gmail.com
Fri Sep 5 23:58:44 CEST 2008


SVN commit 857631 by lfranchi:

playlist support during collection scans.
amarok will now load found playlists during a scan.
howerver, still have not implemented duplicate checking---so if you rescan, they will show up again.
also, removed the reload-db call every time a playlist was added, because it seemed to stress some part of the playlistbrowser or db code and would make amarok crash. you might need to jiggle amarok a little to get it to show them right after a collection scan is finished.
CCMAIL: amarok-devel at kde.org


 M  +5 -2      collection/sqlcollection/ScanManager.cpp  
 M  +44 -3     playlistmanager/PlaylistManager.cpp  
 M  +11 -0     playlistmanager/PlaylistManager.h  


--- trunk/extragear/multimedia/amarok/src/collection/sqlcollection/ScanManager.cpp #857630:857631
@@ -2,6 +2,7 @@
  *  Copyright (c) 2003-2005 Mark Kretschmann <kretschmann at kde.org>
  *  Copyright (c) 2007 Maximilian Kossick <maximilian.kossick at googlemail.com>
  *  Copyright (c) 2007 Casey Link <unnamedrambler at gmail.com>
+ *  Copyright (c) 2008 Leo Franchi <lfranchi at kde.org>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -27,6 +28,7 @@
 #include "meta/MetaConstants.h"
 #include "meta/MetaUtility.h"
 #include "mountpointmanager.h"
+#include "playlistmanager/PlaylistManager.h"
 #include "ScanResultProcessor.h"
 #include "SqlCollection.h"
 
@@ -72,7 +74,7 @@
     }
     cleanTables();
     m_scanner = new AmarokProcess( this );
-    *m_scanner << "amarokcollectionscanner" << "--nocrashhandler";
+    *m_scanner << "amarokcollectionscanner" << "--nocrashhandler" << "-p";
     if( AmarokConfig::scanRecursively() ) *m_scanner << "-r";
     *m_scanner << MountPointManager::instance()->collectionFolders();
     m_scanner->setOutputChannelMode( KProcess::OnlyStdoutChannel );
@@ -559,7 +561,8 @@
                 }
                 else if( localname == "playlist" )
                 {
-                    //TODO handle playlist
+                    //TODO check for duplicates
+                    The::playlistManager()->save( m_reader.attributes().value( "path" ).toString() );
                 }
                 else if( localname == "image" )
                 {
--- trunk/extragear/multimedia/amarok/src/playlistmanager/PlaylistManager.cpp #857630:857631
@@ -213,7 +213,8 @@
         return QString("!!!Invalid Playlist Category!!!\nPlease Report this at bugs.kde.org.");
 }
 
-bool PlaylistManager::save( Meta::TrackList tracks, const QString & name)
+bool
+PlaylistManager::save( Meta::TrackList tracks, const QString & name)
 {
     Meta::SqlPlaylist* playlist = new Meta::SqlPlaylist( name, tracks, SqlPlaylistGroupPtr() );
     int newId = playlist->id();
@@ -221,15 +222,55 @@
 
     //jolt the playlist browser model to reload....
     //talk about over-coupling... :|
-    PlaylistBrowserNS::UserModel::instance()->reloadFromDb();
+    //PlaylistBrowserNS::UserModel::instance()->reloadFromDb();
     
     //we should really enter edit mode for the new playlist, but how...
-    PlaylistBrowserNS::UserModel::instance()->editPlaylist( newId );
+    // NOTE this doesn't really make sense, especially when batch adding
+    //      during a collection scan ---lfranchi 9/5/08
+    //PlaylistBrowserNS::UserModel::instance()->editPlaylist( newId );
 
     return true; //FIXME what's this supposed to return?
 }
 
 bool
+PlaylistManager::save( const QString& fromLocation )
+{
+    DEBUG_BLOCK
+    KUrl url( fromLocation );
+    Meta::Playlist* playlist = 0;
+    Meta::Format format = Meta::getFormat( fromLocation );
+    switch( format )
+    {
+        case Meta::PLS:
+            playlist = new Meta::PLSPlaylist( url );
+            break;
+        case Meta::M3U:
+            playlist = new Meta::M3UPlaylist( url );
+            break;
+        case Meta::XSPF:
+            playlist = new Meta::XSPFPlaylist( url );
+            break;
+
+        default:
+            debug() << "unknown type!";
+            break;
+    }
+    Meta::TrackList tracks = playlist->tracks();
+    QString name = playlist->name().split(".")[0];
+
+    foreach( Meta::TrackPtr track, tracks )
+    {
+        debug() << "playlist got track:" << track->prettyName();
+    }
+    
+    if( tracks.isEmpty() )
+        return false;
+
+    save( tracks, name );
+    return true;
+}
+    
+bool
 PlaylistManager::exportPlaylist( Meta::TrackList tracks,
                         const QString &location )
 {
--- trunk/extragear/multimedia/amarok/src/playlistmanager/PlaylistManager.h #857630:857631
@@ -111,8 +111,19 @@
 
         void downloadPlaylist( const KUrl & path, const Meta::PlaylistPtr playlist );
 
+        /**
+        *   Saves a list of tracks to a new SQL playlist. Used in the Playlist save button.
+        *   @arg tracks list of tracks to save
+        *   @arg name name of playlist to save
+        */
         bool save( Meta::TrackList tracks, const QString &name );
 
+        /**
+         *  Saves a playlist from a file to the database.
+         *  @arg fromLocation Saved playlist file to load
+         */
+        AMAROK_EXPORT bool save( const QString& fromLocation );
+        
         bool exportPlaylist( Meta::TrackList tracks, const QString &location );
 
 


More information about the Amarok-devel mailing list