1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-19 15:29:42 +01:00

skeleton auto-updating for xspf playlists

This commit is contained in:
Leo Franchi 2011-09-24 15:40:32 -04:00
parent f58ba2926e
commit 3b861983e6
8 changed files with 182 additions and 7 deletions

View File

@ -140,6 +140,7 @@ set( libSources
playlist/artistview.cpp
playlist/customplaylistview.cpp
playlist/ViewHeader.cpp
playlist/XspfUpdater.cpp
playlist/topbar/topbar.cpp
playlist/topbar/clearbutton.cpp
@ -375,6 +376,8 @@ set( libHeaders
playlist/artistview.h
playlist/customplaylistview.h
playlist/ViewHeader.h
playlist/PlaylistUpdaterInterface.h
playlist/XspfUpdater.h
playlist/topbar/topbar.h
playlist/topbar/clearbutton.h

View File

@ -503,7 +503,7 @@ Playlist::addEntry( const query_ptr& query, const QString& oldrev )
void
Playlist::addEntries( const QList<query_ptr>& queries, const QString& oldrev )
{
QList<plentry_ptr> el = addEntriesInternal( queries );
QList<plentry_ptr> el = entriesFromQueries( queries );
QString newrev = uuid();
createNewRevision( newrev, oldrev, el );
@ -511,7 +511,7 @@ Playlist::addEntries( const QList<query_ptr>& queries, const QString& oldrev )
QList<plentry_ptr>
Playlist::addEntriesInternal( const QList<Tomahawk::query_ptr>& queries )
Playlist::entriesFromQueries( const QList<Tomahawk::query_ptr>& queries )
{
QList<plentry_ptr> el = entries();
foreach( const query_ptr& query, queries )

View File

@ -196,6 +196,7 @@ public:
virtual void setFilter( const QString& /*pattern*/ ) {}
QList<plentry_ptr> entriesFromQueries( const QList<Tomahawk::query_ptr>& queries );
signals:
/// emitted when the playlist revision changes (whenever the playlist changes)
void revisionLoaded( Tomahawk::PlaylistRevision );
@ -222,7 +223,6 @@ signals:
void sourceTrackCountChanged( unsigned int tracks );
void nextTrackReady();
public slots:
// want to update the playlist from the model?
// generate a newrev using uuid() and call this:
@ -267,7 +267,6 @@ protected:
bool is_newest_rev,
const QMap< QString, Tomahawk::plentry_ptr >& addedmap );
QList<plentry_ptr> addEntriesInternal( const QList<Tomahawk::query_ptr>& queries );
private slots:
void onResultsFound( const QList<Tomahawk::result_ptr>& results );

View File

@ -0,0 +1,59 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.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 PLAYLISTUPDATERINTERFACE_H
#define PLAYLISTUPDATERINTERFACE_H
#include "dllmacro.h"
#include "typedefs.h"
#include "playlist.h"
namespace Tomahawk
{
/**
* If a playlist needs periodic updating, implement a updater interface.
*
* Default is auto-updating.
*/
class DLLEXPORT PlaylistUpdaterInterface : public QObject
{
Q_OBJECT
public:
PlaylistUpdaterInterface( const playlist_ptr& pl, QObject* parent )
: QObject( parent )
, m_autoUpdate( true )
, m_playlist( pl )
{}
virtual ~PlaylistUpdaterInterface() {}
void setAutoUpdate( bool autoUpdate ) { m_autoUpdate = autoUpdate; }
bool autoUpdate() const { return m_autoUpdate; }
playlist_ptr playlist() const { return m_playlist; }
signals:
private:
bool m_autoUpdate;
playlist_ptr m_playlist;
};
}
#endif // PLAYLISTUPDATERINTERFACE_H

View File

@ -0,0 +1,67 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.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 "XspfUpdater.h"
#include "playlist.h"
#include "utils/xspfloader.h"
#include <QTimer>
using namespace Tomahawk;
XspfUpdater::XspfUpdater( const playlist_ptr& pl, const QString& xUrl, QObject *parent )
: PlaylistUpdaterInterface( pl, parent )
, m_url( xUrl )
, m_timer( new QTimer( this ) )
{
// for now refresh every 60min
m_timer->setInterval( 60 * 60 * 1000);
connect( m_timer, SIGNAL( timeout() ), this, SLOT( update() ) );
}
XspfUpdater::~XspfUpdater()
{}
void
XspfUpdater::update()
{
XSPFLoader* l = new XSPFLoader( false );
connect( l, SIGNAL( ok ( Tomahawk::playlist_ptr ) ), this, SLOT( playlistLoaded() ) );
}
void
XspfUpdater::playlistLoaded()
{
XSPFLoader* loader = qobject_cast<XSPFLoader*>( sender() );
Q_ASSERT( loader );
QList< query_ptr > queries = loader->entries();
QList<plentry_ptr> el = playlist()->entriesFromQueries( queries );
playlist()->createNewRevision( uuid(), playlist()->currentrevision(), el );
// // if there are any different from the current playlist, clear and use the new one, update
// bool changed = ( queries.size() == playlist()->entries().count() );
// if ( !changed )
// {
// foreach( const query_ptr& newSong, queries )
// {
// if ( !playlist()->entries.contains() )
// }
// }
}

View File

@ -0,0 +1,47 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.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 XSPFUPDATER_H
#define XSPFUPDATER_H
#include "PlaylistUpdaterInterface.h"
class QTimer;
namespace Tomahawk
{
class XspfUpdater : public PlaylistUpdaterInterface
{
Q_OBJECT
public:
explicit XspfUpdater( const playlist_ptr& pl, const QString& xspfUrl, QObject *parent = 0 );
virtual ~XspfUpdater();
private slots:
void update();
void playlistLoaded();
private:
QString m_url;
QTimer* m_timer;
};
}
#endif // XSPFUPDATER_H

View File

@ -1,6 +1,6 @@
/* === 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>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -347,7 +347,7 @@ DynamicPlaylist::addEntries(const QList< query_ptr >& queries, const QString& ol
{
Q_ASSERT( m_generator->mode() == Static );
QList<plentry_ptr> el = addEntriesInternal( queries );
QList<plentry_ptr> el = entriesFromQueries( queries );
QString newrev = uuid();
createNewRevision( newrev, oldrev, m_generator->type(), m_generator->controls(), el );

View File

@ -1,6 +1,6 @@
/* === 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>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by