mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 15:59:42 +01:00
Clean up auto-updating xspf handling to make it actually usable
This commit is contained in:
parent
891692d914
commit
3873189d79
@ -66,6 +66,22 @@ PlaylistUpdaterInterface::PlaylistUpdaterInterface( const playlist_ptr& pl )
|
||||
QTimer::singleShot( 0, this, SLOT( doSave() ) );
|
||||
}
|
||||
|
||||
PlaylistUpdaterInterface::PlaylistUpdaterInterface( const playlist_ptr& pl, int interval, bool autoUpdate )
|
||||
: QObject( 0 )
|
||||
, m_timer( new QTimer( this ) )
|
||||
, m_autoUpdate( autoUpdate )
|
||||
, m_playlist( pl )
|
||||
{
|
||||
Q_ASSERT( !m_playlist.isNull() );
|
||||
|
||||
m_playlist->setUpdater( this );
|
||||
m_timer->setInterval( interval );
|
||||
connect( m_timer, SIGNAL( timeout() ), this, SLOT( updateNow() ) );
|
||||
|
||||
QTimer::singleShot( 0, this, SLOT( doSave() ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistUpdaterInterface::doSave()
|
||||
{
|
||||
@ -92,6 +108,8 @@ PlaylistUpdaterInterface::remove()
|
||||
s->remove( QString( "%1/type" ).arg( key ) );
|
||||
s->remove( QString( "%1/autoupdate" ).arg( key ) );
|
||||
s->remove( QString( "%1/interval" ).arg( key ) );
|
||||
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
|
||||
|
@ -37,6 +37,7 @@ class DLLEXPORT PlaylistUpdaterInterface : public QObject
|
||||
Q_OBJECT
|
||||
public:
|
||||
PlaylistUpdaterInterface( const playlist_ptr& pl );
|
||||
PlaylistUpdaterInterface( const playlist_ptr& pl, int interval, bool autoUpdate );
|
||||
|
||||
virtual ~PlaylistUpdaterInterface(){}
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include <QTimer>
|
||||
#include <tomahawksettings.h>
|
||||
#include <pipeline.h>
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
@ -32,6 +33,14 @@ XspfUpdater::XspfUpdater( const playlist_ptr& pl, const QString& xUrl )
|
||||
{
|
||||
}
|
||||
|
||||
XspfUpdater::XspfUpdater( const playlist_ptr& pl, int interval, bool autoUpdate, const QString& xspfUrl )
|
||||
: PlaylistUpdaterInterface( pl, interval, autoUpdate )
|
||||
, m_url( xspfUrl )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
XspfUpdater::XspfUpdater( const playlist_ptr& pl )
|
||||
: PlaylistUpdaterInterface( pl )
|
||||
{
|
||||
@ -46,6 +55,7 @@ void
|
||||
XspfUpdater::updateNow()
|
||||
{
|
||||
XSPFLoader* l = new XSPFLoader( false, false );
|
||||
l->setAutoResolveTracks( false );
|
||||
l->load( m_url );
|
||||
connect( l, SIGNAL( ok ( Tomahawk::playlist_ptr ) ), this, SLOT( playlistLoaded() ) );
|
||||
}
|
||||
@ -56,8 +66,35 @@ XspfUpdater::playlistLoaded()
|
||||
XSPFLoader* loader = qobject_cast<XSPFLoader*>( sender() );
|
||||
Q_ASSERT( loader );
|
||||
|
||||
QList< query_ptr > queries = loader->entries();
|
||||
QList<plentry_ptr> el = playlist()->entriesFromQueries( queries, true );
|
||||
QList< query_ptr> oldqueries;
|
||||
foreach ( const plentry_ptr& ple, playlist()->entries() )
|
||||
oldqueries << ple->query();
|
||||
|
||||
QList< query_ptr > newqueries = loader->entries();
|
||||
int sameCount = 0;
|
||||
QList< query_ptr > tosave = newqueries;
|
||||
foreach ( const query_ptr& newquery, newqueries )
|
||||
{
|
||||
foreach ( const query_ptr& oldq, oldqueries )
|
||||
{
|
||||
if ( newquery->track() == oldq->track() &&
|
||||
newquery->artist() == oldq->artist() &&
|
||||
newquery->album() == oldq->album() )
|
||||
{
|
||||
sameCount++;
|
||||
if ( tosave.contains( newquery ) )
|
||||
tosave.replace( tosave.indexOf( newquery ), oldq );
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No work to be done if all are the same
|
||||
if ( oldqueries.size() == newqueries.size() && sameCount == oldqueries.size() )
|
||||
return;
|
||||
|
||||
QList<plentry_ptr> el = playlist()->entriesFromQueries( tosave, true );
|
||||
playlist()->createNewRevision( uuid(), playlist()->currentrevision(), el );
|
||||
|
||||
// // if there are any different from the current playlist, clear and use the new one, update
|
||||
|
@ -31,6 +31,7 @@ class XspfUpdater : public PlaylistUpdaterInterface
|
||||
Q_OBJECT
|
||||
public:
|
||||
XspfUpdater( const playlist_ptr& pl, const QString& xspfUrl );
|
||||
XspfUpdater( const playlist_ptr& pl, int interval, bool autoUpdate, const QString& xspfUrl );
|
||||
explicit XspfUpdater( const playlist_ptr& pl ); // used by factory
|
||||
|
||||
virtual ~XspfUpdater();
|
||||
|
@ -34,6 +34,7 @@ XSPFLoader::XSPFLoader( bool autoCreate, bool autoUpdate, QObject *parent )
|
||||
: QObject( parent )
|
||||
, m_autoCreate( autoCreate )
|
||||
, m_autoUpdate( autoUpdate )
|
||||
, m_autoResolve( false )
|
||||
, m_NS("http://xspf.org/ns/0/")
|
||||
{
|
||||
qRegisterMetaType< XSPFErrorCode >("XSPFErrorCode");
|
||||
@ -102,6 +103,9 @@ void
|
||||
XSPFLoader::networkLoadFinished()
|
||||
{
|
||||
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
|
||||
if ( reply->error() != QNetworkReply::NoError )
|
||||
return;
|
||||
|
||||
m_body = reply->readAll();
|
||||
gotBody();
|
||||
}
|
||||
@ -196,7 +200,7 @@ XSPFLoader::gotBody()
|
||||
continue;
|
||||
}
|
||||
|
||||
query_ptr q = Tomahawk::Query::get( artist, track, album, uuid() );
|
||||
query_ptr q = Tomahawk::Query::get( artist, track, album, uuid(), m_autoResolve );
|
||||
q->setDuration( duration.toInt() / 1000 );
|
||||
if ( !url.isEmpty() )
|
||||
q->setResultHint( url );
|
||||
@ -222,9 +226,8 @@ XSPFLoader::gotBody()
|
||||
false,
|
||||
m_entries );
|
||||
|
||||
Tomahawk::XspfUpdater* updater = new Tomahawk::XspfUpdater( m_playlist, m_url.toString() );
|
||||
updater->setInterval( 1200000 ); // 20 minute default for now, no way to change it
|
||||
updater->setAutoUpdate( m_autoUpdate );
|
||||
// 10 minute default---for now, no way to change it
|
||||
new Tomahawk::XspfUpdater( m_playlist, 6000000, m_autoUpdate, m_url.toString() );
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
QList< Tomahawk::query_ptr > entries() const;
|
||||
|
||||
void setOverrideTitle( const QString& newTitle );
|
||||
void setAutoResolveTracks( bool autoResolve ) { m_autoResolve = autoResolve; }
|
||||
|
||||
signals:
|
||||
void error( XSPFLoader::XSPFErrorCode error );
|
||||
@ -63,7 +64,7 @@ private:
|
||||
void reportError();
|
||||
void gotBody();
|
||||
|
||||
bool m_autoCreate, m_autoUpdate;
|
||||
bool m_autoCreate, m_autoUpdate, m_autoResolve;
|
||||
QString m_NS,m_overrideTitle;
|
||||
QList< Tomahawk::query_ptr > m_entries;
|
||||
QString m_title, m_info, m_creator;
|
||||
|
Loading…
x
Reference in New Issue
Block a user