diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 6d64c0d0b..92651881c 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -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 diff --git a/src/libtomahawk/playlist.cpp b/src/libtomahawk/playlist.cpp index f600af761..7c8ec7de7 100644 --- a/src/libtomahawk/playlist.cpp +++ b/src/libtomahawk/playlist.cpp @@ -503,7 +503,7 @@ Playlist::addEntry( const query_ptr& query, const QString& oldrev ) void Playlist::addEntries( const QList& queries, const QString& oldrev ) { - QList el = addEntriesInternal( queries ); + QList el = entriesFromQueries( queries ); QString newrev = uuid(); createNewRevision( newrev, oldrev, el ); @@ -511,7 +511,7 @@ Playlist::addEntries( const QList& queries, const QString& oldrev ) QList -Playlist::addEntriesInternal( const QList& queries ) +Playlist::entriesFromQueries( const QList& queries ) { QList el = entries(); foreach( const query_ptr& query, queries ) diff --git a/src/libtomahawk/playlist.h b/src/libtomahawk/playlist.h index bbb1390b5..2302554cc 100644 --- a/src/libtomahawk/playlist.h +++ b/src/libtomahawk/playlist.h @@ -196,6 +196,7 @@ public: virtual void setFilter( const QString& /*pattern*/ ) {} + QList entriesFromQueries( const QList& 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 addEntriesInternal( const QList& queries ); private slots: void onResultsFound( const QList& results ); diff --git a/src/libtomahawk/playlist/PlaylistUpdaterInterface.h b/src/libtomahawk/playlist/PlaylistUpdaterInterface.h new file mode 100644 index 000000000..e31a5c425 --- /dev/null +++ b/src/libtomahawk/playlist/PlaylistUpdaterInterface.h @@ -0,0 +1,59 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Leo Franchi + * + * 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 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 diff --git a/src/libtomahawk/playlist/XspfUpdater.cpp b/src/libtomahawk/playlist/XspfUpdater.cpp new file mode 100644 index 000000000..949d5a943 --- /dev/null +++ b/src/libtomahawk/playlist/XspfUpdater.cpp @@ -0,0 +1,67 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Leo Franchi + * + * 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 "XspfUpdater.h" + +#include "playlist.h" +#include "utils/xspfloader.h" + +#include + +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( sender() ); + Q_ASSERT( loader ); + + QList< query_ptr > queries = loader->entries(); + QList 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() ) +// } +// } +} diff --git a/src/libtomahawk/playlist/XspfUpdater.h b/src/libtomahawk/playlist/XspfUpdater.h new file mode 100644 index 000000000..59d7d5cd1 --- /dev/null +++ b/src/libtomahawk/playlist/XspfUpdater.h @@ -0,0 +1,47 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Leo Franchi + * + * 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 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 diff --git a/src/libtomahawk/playlist/dynamic/DynamicPlaylist.cpp b/src/libtomahawk/playlist/dynamic/DynamicPlaylist.cpp index fb6fd18a1..9358d2a88 100644 --- a/src/libtomahawk/playlist/dynamic/DynamicPlaylist.cpp +++ b/src/libtomahawk/playlist/dynamic/DynamicPlaylist.cpp @@ -1,6 +1,6 @@ /* === This file is part of Tomahawk Player - === * - * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2010-2011, Leo Franchi * * 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 el = addEntriesInternal( queries ); + QList el = entriesFromQueries( queries ); QString newrev = uuid(); createNewRevision( newrev, oldrev, m_generator->type(), m_generator->controls(), el ); diff --git a/src/libtomahawk/playlist/dynamic/DynamicPlaylist.h b/src/libtomahawk/playlist/dynamic/DynamicPlaylist.h index 6ee85049c..6860926c6 100644 --- a/src/libtomahawk/playlist/dynamic/DynamicPlaylist.h +++ b/src/libtomahawk/playlist/dynamic/DynamicPlaylist.h @@ -1,6 +1,6 @@ /* === This file is part of Tomahawk Player - === * - * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2010-2011, Leo Franchi * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by