From ed306b00f07a5f075aed30a978337bf065fbbefa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Lindstr=C3=B6m?= Date: Thu, 24 Nov 2011 15:02:04 +0100 Subject: [PATCH] Create playlist from M3U --- src/libtomahawk/utils/m3uloader.cpp | 50 +++++++++++++++++++++-------- src/libtomahawk/utils/m3uloader.h | 10 ++++-- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/libtomahawk/utils/m3uloader.cpp b/src/libtomahawk/utils/m3uloader.cpp index 457f12d74..855ab8e92 100644 --- a/src/libtomahawk/utils/m3uloader.cpp +++ b/src/libtomahawk/utils/m3uloader.cpp @@ -21,11 +21,12 @@ #include "utils/tomahawkutils.h" #include "query.h" #include "sourcelist.h" -#include "jobview/JobStatusView.h" -#include "jobview/JobStatusModel.h" -#include "viewmanager.h" -#include + +//#include #include +#include "playlist.h" + +#include "dropjob.h" #include /* taglib */ #include @@ -57,7 +58,7 @@ M3uLoader::~M3uLoader() { } -Tomahawk::query_ptr +void M3uLoader::getTags( const QFileInfo& info ) { @@ -74,13 +75,13 @@ M3uLoader::getTags( const QFileInfo& info ) if ( artist.isEmpty() || track.isEmpty() ) { qDebug() << "Error parsing" << info.fileName(); - return Tomahawk::query_ptr(); + return; } else { qDebug() << Q_FUNC_INFO << artist << track << album; - Tomahawk::query_ptr q = Tomahawk::Query::get( artist, track, album, uuid(), true ); - return q; + Tomahawk::query_ptr q = Tomahawk::Query::get( artist, track, album, uuid(), !m_createNewPlaylist ); + m_tracks << q; } } @@ -97,6 +98,8 @@ M3uLoader::parseM3u( const QString& fileLink ) return; } + m_title = fileInfo.baseName(); + while ( !file.atEnd() ) { @@ -110,23 +113,44 @@ M3uLoader::parseM3u( const QString& fileLink ) QFileInfo tmpFile( QUrl::fromUserInput( QString( line.simplified() ) ).toLocalFile() ); if( tmpFile.exists() ) - m_tracks << getTags( tmpFile ); + getTags( tmpFile ); else { QFileInfo tmpFile( QUrl::fromUserInput( QString( fileInfo.canonicalPath() + "/" + line.simplified() ) ).toLocalFile() ); if( tmpFile.exists() ) - m_tracks << getTags( tmpFile ); + getTags( tmpFile ); } } - if( !m_tracks.isEmpty() ) + if( m_tracks.isEmpty() ) { - qDebug() << Q_FUNC_INFO << "Emitting tracks!"; - emit tracks( m_tracks ); + + qDebug() << Q_FUNC_INFO << "Coulnt parse M3U!"; + return; } + + if ( m_createNewPlaylist ) + { + m_playlist = Playlist::create( SourceList::instance()->getLocal(), + uuid(), + m_title, + m_info, + m_creator, + false, + m_tracks ); + + connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( playlistCreated() ) ); + + } + else + emit tracks( m_tracks ); + + + m_tracks.clear(); file.deleteLater(); + } diff --git a/src/libtomahawk/utils/m3uloader.h b/src/libtomahawk/utils/m3uloader.h index bae91ba5b..f10ad859e 100644 --- a/src/libtomahawk/utils/m3uloader.h +++ b/src/libtomahawk/utils/m3uloader.h @@ -19,11 +19,12 @@ #ifndef M3U_LOADER_H #define M3U_LOADER_H + +#include #include "dllmacro.h" #include "typedefs.h" #include "query.h" -#include "dropjobnotifier.h" -#include +#include "playlist.h" #include #include #include @@ -40,18 +41,21 @@ public: explicit M3uLoader( const QString& trackUrl, bool createNewPlaylist = false, QObject* parent = 0 ); explicit M3uLoader( const QStringList& trackUrls, bool createNewPlaylist = false, QObject* parent = 0 ); virtual ~M3uLoader(); + signals: void track( const Tomahawk::query_ptr& track ); void tracks( const QList< Tomahawk::query_ptr > tracks ); private: void parseM3u( const QString& track ); - Tomahawk::query_ptr getTags( const QFileInfo& info ); + void getTags( const QFileInfo& info ); QList< query_ptr > m_tracks; QString m_title, m_info, m_creator; bool m_single; bool m_trackMode; bool m_createNewPlaylist; + playlist_ptr m_playlist; + }; }