diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 269697d04..0927f0c7d 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -186,6 +186,7 @@ list(APPEND libSources CountryUtils.cpp FuncTimeout.cpp Playlist.cpp + PlaylistEntry.cpp PlaylistPlaylistInterface.cpp MetaPlaylistInterface.cpp Query.cpp diff --git a/src/libtomahawk/Playlist.cpp b/src/libtomahawk/Playlist.cpp index 121fd1d55..ef4bcc382 100644 --- a/src/libtomahawk/Playlist.cpp +++ b/src/libtomahawk/Playlist.cpp @@ -44,109 +44,6 @@ using namespace Tomahawk; -PlaylistEntry::PlaylistEntry() -{ -} - - -PlaylistEntry::~PlaylistEntry() -{ - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << m_query->toString(); -} - - -void -PlaylistEntry::setQueryVariant( const QVariant& v ) -{ - QVariantMap m = v.toMap(); - - QString artist = m.value( "artist" ).toString(); - QString album = m.value( "album" ).toString(); - QString track = m.value( "track" ).toString(); - - setQuery( Tomahawk::Query::get( artist, track, album ) ); -} - - -QVariant -PlaylistEntry::queryVariant() const -{ - return m_query->toVariant(); -} - - -void -PlaylistEntry::setQuery( const Tomahawk::query_ptr& q ) -{ - m_query = q; - - connect( q.data(), SIGNAL( resolvingFinished( bool ) ), SLOT( onQueryResolved( bool ) ) ); -} - - -const Tomahawk::query_ptr& -PlaylistEntry::query() const -{ - return m_query; -} - - -source_ptr -PlaylistEntry::lastSource() const -{ - return m_lastsource; -} - - -void -PlaylistEntry::setLastSource( source_ptr s ) -{ - m_lastsource = s; -} - - -void -PlaylistEntry::onQueryResolved( bool hasResults ) -{ - if ( !hasResults ) - return; - - if ( resultHint().isEmpty() ) - setResultHint( hintFromQuery() ); -} - - -void -PlaylistEntry::setResultHint( const QString& s ) -{ - if ( m_resulthint == s ) - return; - - m_resulthint = s; - emit resultChanged(); -} - - -QString -PlaylistEntry::hintFromQuery() const -{ - QString resultHint, foundResult; - if ( !m_query->results().isEmpty() ) - foundResult = m_query->results().first()->url(); - else if ( !m_query->resultHint().isEmpty() ) - foundResult = m_query->resultHint(); - - if ( foundResult.startsWith( "file://" ) || - foundResult.startsWith( "servent://" ) || // Save resulthints for local files and peers automatically - ( TomahawkUtils::whitelistedHttpResultHint( foundResult ) && m_query->saveHTTPResultHint() ) ) - { - resultHint = foundResult; - } - - return resultHint; -} - - Playlist::Playlist( const source_ptr& author ) : m_source( author ) , m_lastmodified( 0 ) diff --git a/src/libtomahawk/Playlist.h b/src/libtomahawk/Playlist.h index 043a6dbff..b6dd44d4e 100644 --- a/src/libtomahawk/Playlist.h +++ b/src/libtomahawk/Playlist.h @@ -29,6 +29,7 @@ #include "Typedefs.h" #include "Result.h" +#include "PlaylistEntry.h" #include "PlaylistInterface.h" #include "playlist/PlaylistUpdaterInterface.h" #include "Query.h" @@ -48,64 +49,6 @@ namespace Tomahawk class PlaylistUpdaterInterface; -class DLLEXPORT PlaylistEntry : public QObject -{ -Q_OBJECT -Q_PROPERTY( QString guid READ guid WRITE setGuid ) -Q_PROPERTY( QString annotation READ annotation WRITE setAnnotation ) -Q_PROPERTY( unsigned int duration READ duration WRITE setDuration ) -Q_PROPERTY( unsigned int lastmodified READ lastmodified WRITE setLastmodified ) -Q_PROPERTY( QVariant query READ queryVariant WRITE setQueryVariant ) - -public: - PlaylistEntry(); - virtual ~PlaylistEntry(); - - bool isValid() const { return !m_query.isNull(); } - - void setQuery( const Tomahawk::query_ptr& q ); - const Tomahawk::query_ptr& query() const; - - void setQueryVariant( const QVariant& v ); - QVariant queryVariant() const; - - QString guid() const { return m_guid; } - void setGuid( const QString& s ) { m_guid = s; } - - QString annotation() const { return m_annotation; } - void setAnnotation( const QString& s ) { m_annotation = s; } - - QString resultHint() const { return m_resulthint; } - void setResultHint( const QString& s ); - - unsigned int duration() const { return m_duration; } - void setDuration( unsigned int i ) { m_duration = i; } - - unsigned int lastmodified() const { return m_lastmodified; } - void setLastmodified( unsigned int i ) { m_lastmodified = i; } - - source_ptr lastSource() const; - void setLastSource( source_ptr s ); - -signals: - void resultChanged(); - -private slots: - void onQueryResolved( bool hasResults ); - -private: - QString hintFromQuery() const; - - QString m_guid; - Tomahawk::query_ptr m_query; - QString m_annotation; - unsigned int m_duration; - unsigned int m_lastmodified; - source_ptr m_lastsource; - QString m_resulthint; -}; - - struct PlaylistRevision { QString revisionguid; @@ -343,7 +286,6 @@ private: } Q_DECLARE_METATYPE( QSharedPointer< Tomahawk::Playlist > ) -Q_DECLARE_METATYPE( QList< QSharedPointer< Tomahawk::PlaylistEntry > > ) Q_DECLARE_METATYPE( QList< QSharedPointer< Tomahawk::Query > > ) #endif // PLAYLIST_H diff --git a/src/libtomahawk/PlaylistEntry.cpp b/src/libtomahawk/PlaylistEntry.cpp new file mode 100644 index 000000000..47877d177 --- /dev/null +++ b/src/libtomahawk/PlaylistEntry.cpp @@ -0,0 +1,129 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2010-2011, Leo Franchi + * Copyright 2010-2012, Jeff Mitchell + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "PlaylistEntry.h" + +#include "Source.h" +#include "utils/Logger.h" + +using namespace Tomahawk; + + +PlaylistEntry::PlaylistEntry() +{ +} + + +PlaylistEntry::~PlaylistEntry() +{ + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << m_query->toString(); +} + + +void +PlaylistEntry::setQueryVariant( const QVariant& v ) +{ + QVariantMap m = v.toMap(); + + QString artist = m.value( "artist" ).toString(); + QString album = m.value( "album" ).toString(); + QString track = m.value( "track" ).toString(); + + setQuery( Tomahawk::Query::get( artist, track, album ) ); +} + + +QVariant +PlaylistEntry::queryVariant() const +{ + return m_query->toVariant(); +} + + +void +PlaylistEntry::setQuery( const Tomahawk::query_ptr& q ) +{ + m_query = q; + + connect( q.data(), SIGNAL( resolvingFinished( bool ) ), SLOT( onQueryResolved( bool ) ) ); +} + + +const Tomahawk::query_ptr& +PlaylistEntry::query() const +{ + return m_query; +} + + +source_ptr +PlaylistEntry::lastSource() const +{ + return m_lastsource; +} + + +void +PlaylistEntry::setLastSource( source_ptr s ) +{ + m_lastsource = s; +} + + +void +PlaylistEntry::onQueryResolved( bool hasResults ) +{ + if ( !hasResults ) + return; + + if ( resultHint().isEmpty() ) + setResultHint( hintFromQuery() ); +} + + +void +PlaylistEntry::setResultHint( const QString& s ) +{ + if ( m_resulthint == s ) + return; + + m_resulthint = s; + emit resultChanged(); +} + + +QString +PlaylistEntry::hintFromQuery() const +{ + QString resultHint, foundResult; + if ( !m_query->results().isEmpty() ) + foundResult = m_query->results().first()->url(); + else if ( !m_query->resultHint().isEmpty() ) + foundResult = m_query->resultHint(); + + if ( foundResult.startsWith( "file://" ) || + foundResult.startsWith( "servent://" ) || // Save resulthints for local files and peers automatically + ( TomahawkUtils::whitelistedHttpResultHint( foundResult ) && m_query->saveHTTPResultHint() ) ) + { + resultHint = foundResult; + } + + return resultHint; +} diff --git a/src/libtomahawk/PlaylistEntry.h b/src/libtomahawk/PlaylistEntry.h new file mode 100644 index 000000000..76a255218 --- /dev/null +++ b/src/libtomahawk/PlaylistEntry.h @@ -0,0 +1,98 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2010-2011, Leo Franchi + * Copyright 2010-2012, Jeff Mitchell + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef PLAYLISTENTRY_H +#define PLAYLISTENTRY_H + +#include +#include +#include +#include + +#include "Typedefs.h" +#include "Query.h" + +#include "DllMacro.h" + +namespace Tomahawk +{ + +class DLLEXPORT PlaylistEntry : public QObject +{ +Q_OBJECT +Q_PROPERTY( QString guid READ guid WRITE setGuid ) +Q_PROPERTY( QString annotation READ annotation WRITE setAnnotation ) +Q_PROPERTY( unsigned int duration READ duration WRITE setDuration ) +Q_PROPERTY( unsigned int lastmodified READ lastmodified WRITE setLastmodified ) +Q_PROPERTY( QVariant query READ queryVariant WRITE setQueryVariant ) + +public: + PlaylistEntry(); + virtual ~PlaylistEntry(); + + bool isValid() const { return !m_query.isNull(); } + + void setQuery( const Tomahawk::query_ptr& q ); + const Tomahawk::query_ptr& query() const; + + void setQueryVariant( const QVariant& v ); + QVariant queryVariant() const; + + QString guid() const { return m_guid; } + void setGuid( const QString& s ) { m_guid = s; } + + QString annotation() const { return m_annotation; } + void setAnnotation( const QString& s ) { m_annotation = s; } + + QString resultHint() const { return m_resulthint; } + void setResultHint( const QString& s ); + + unsigned int duration() const { return m_duration; } + void setDuration( unsigned int i ) { m_duration = i; } + + unsigned int lastmodified() const { return m_lastmodified; } + void setLastmodified( unsigned int i ) { m_lastmodified = i; } + + source_ptr lastSource() const; + void setLastSource( source_ptr s ); + +signals: + void resultChanged(); + +private slots: + void onQueryResolved( bool hasResults ); + +private: + QString hintFromQuery() const; + + QString m_guid; + Tomahawk::query_ptr m_query; + QString m_annotation; + unsigned int m_duration; + unsigned int m_lastmodified; + source_ptr m_lastsource; + QString m_resulthint; +}; + +} + +Q_DECLARE_METATYPE( QList< QSharedPointer< Tomahawk::PlaylistEntry > > ) + +#endif // PLAYLISTENTRY_H