mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
* Moved PlaylistEntry class into separate files.
This commit is contained in:
@@ -186,6 +186,7 @@ list(APPEND libSources
|
|||||||
CountryUtils.cpp
|
CountryUtils.cpp
|
||||||
FuncTimeout.cpp
|
FuncTimeout.cpp
|
||||||
Playlist.cpp
|
Playlist.cpp
|
||||||
|
PlaylistEntry.cpp
|
||||||
PlaylistPlaylistInterface.cpp
|
PlaylistPlaylistInterface.cpp
|
||||||
MetaPlaylistInterface.cpp
|
MetaPlaylistInterface.cpp
|
||||||
Query.cpp
|
Query.cpp
|
||||||
|
@@ -44,109 +44,6 @@
|
|||||||
using namespace Tomahawk;
|
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 )
|
Playlist::Playlist( const source_ptr& author )
|
||||||
: m_source( author )
|
: m_source( author )
|
||||||
, m_lastmodified( 0 )
|
, m_lastmodified( 0 )
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
#include "Result.h"
|
#include "Result.h"
|
||||||
|
#include "PlaylistEntry.h"
|
||||||
#include "PlaylistInterface.h"
|
#include "PlaylistInterface.h"
|
||||||
#include "playlist/PlaylistUpdaterInterface.h"
|
#include "playlist/PlaylistUpdaterInterface.h"
|
||||||
#include "Query.h"
|
#include "Query.h"
|
||||||
@@ -48,64 +49,6 @@ namespace Tomahawk
|
|||||||
|
|
||||||
class PlaylistUpdaterInterface;
|
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
|
struct PlaylistRevision
|
||||||
{
|
{
|
||||||
QString revisionguid;
|
QString revisionguid;
|
||||||
@@ -343,7 +286,6 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
Q_DECLARE_METATYPE( QSharedPointer< Tomahawk::Playlist > )
|
Q_DECLARE_METATYPE( QSharedPointer< Tomahawk::Playlist > )
|
||||||
Q_DECLARE_METATYPE( QList< QSharedPointer< Tomahawk::PlaylistEntry > > )
|
|
||||||
Q_DECLARE_METATYPE( QList< QSharedPointer< Tomahawk::Query > > )
|
Q_DECLARE_METATYPE( QList< QSharedPointer< Tomahawk::Query > > )
|
||||||
|
|
||||||
#endif // PLAYLIST_H
|
#endif // PLAYLIST_H
|
||||||
|
129
src/libtomahawk/PlaylistEntry.cpp
Normal file
129
src/libtomahawk/PlaylistEntry.cpp
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
|
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||||
|
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
98
src/libtomahawk/PlaylistEntry.h
Normal file
98
src/libtomahawk/PlaylistEntry.h
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
|
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||||
|
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PLAYLISTENTRY_H
|
||||||
|
#define PLAYLISTENTRY_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QList>
|
||||||
|
#include <QVariant>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
|
||||||
|
#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
|
Reference in New Issue
Block a user