From 9fe40f06829784fc1ec293d94b160be2517e4d8c Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Fri, 30 Dec 2011 16:31:19 -0500 Subject: [PATCH] Separate out Playlist's interface. PlaylistPlaylistInterface isn't a great name, someone come up with something better. --- src/libtomahawk/CMakeLists.txt | 2 + src/libtomahawk/albumplaylistinterface.cpp | 9 +- src/libtomahawk/albumplaylistinterface.h | 4 +- src/libtomahawk/artistplaylistinterface.cpp | 1 + src/libtomahawk/artistplaylistinterface.h | 6 +- src/libtomahawk/playlist.cpp | 28 +++--- src/libtomahawk/playlist.h | 34 ++------ src/libtomahawk/playlistinterface.h | 2 +- src/libtomahawk/playlistplaylistinterface.cpp | 64 ++++++++++++++ src/libtomahawk/playlistplaylistinterface.h | 85 +++++++++++++++++++ src/libtomahawk/sourceplaylistinterface.cpp | 4 +- src/libtomahawk/sourceplaylistinterface.h | 2 + 12 files changed, 193 insertions(+), 48 deletions(-) create mode 100644 src/libtomahawk/playlistplaylistinterface.cpp create mode 100644 src/libtomahawk/playlistplaylistinterface.h diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index e029dd17b..36efed296 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -286,6 +286,7 @@ set( libSources albumplaylistinterface.cpp collection.cpp playlist.cpp + playlistplaylistinterface.cpp resolver.cpp ExternalResolver.cpp query.cpp @@ -419,6 +420,7 @@ set( libHeaders album.h albumplaylistinterface.h playlist.h + playlistplaylistinterface.h EchonestCatalogSynchronizer.h diff --git a/src/libtomahawk/albumplaylistinterface.cpp b/src/libtomahawk/albumplaylistinterface.cpp index 3f9b4c131..a72723653 100644 --- a/src/libtomahawk/albumplaylistinterface.cpp +++ b/src/libtomahawk/albumplaylistinterface.cpp @@ -29,7 +29,6 @@ using namespace Tomahawk; AlbumPlaylistInterface::AlbumPlaylistInterface() {} -AlbumPlaylistInterface::~AlbumPlaylistInterface() {} AlbumPlaylistInterface::AlbumPlaylistInterface( Tomahawk::Album *album ) : Tomahawk::PlaylistInterface( this ) @@ -40,6 +39,12 @@ AlbumPlaylistInterface::AlbumPlaylistInterface( Tomahawk::Album *album ) } +AlbumPlaylistInterface::~AlbumPlaylistInterface() +{ + m_album.clear(); +} + + Tomahawk::result_ptr AlbumPlaylistInterface::siblingItem( int itemsAway ) { @@ -100,4 +105,4 @@ void AlbumPlaylistInterface::addQueries( const QList< query_ptr >& tracks ) { m_queries << tracks; -} \ No newline at end of file +} diff --git a/src/libtomahawk/albumplaylistinterface.h b/src/libtomahawk/albumplaylistinterface.h index 4ddb58d06..9fd9eaa48 100644 --- a/src/libtomahawk/albumplaylistinterface.h +++ b/src/libtomahawk/albumplaylistinterface.h @@ -59,7 +59,9 @@ public: virtual void setFilter( const QString& /*pattern*/ ) {} virtual void addQueries( const QList& tracks ); - + + virtual void findMoreIfaces() {} + signals: void repeatModeChanged( PlaylistInterface::RepeatMode mode ); void shuffleModeChanged( bool enabled ); diff --git a/src/libtomahawk/artistplaylistinterface.cpp b/src/libtomahawk/artistplaylistinterface.cpp index 11972cb71..6f22397ad 100644 --- a/src/libtomahawk/artistplaylistinterface.cpp +++ b/src/libtomahawk/artistplaylistinterface.cpp @@ -40,6 +40,7 @@ ArtistPlaylistInterface::ArtistPlaylistInterface( Tomahawk::Artist *artist ) ArtistPlaylistInterface::~ArtistPlaylistInterface() { + m_artist.clear(); } diff --git a/src/libtomahawk/artistplaylistinterface.h b/src/libtomahawk/artistplaylistinterface.h index eed599886..04e75e908 100644 --- a/src/libtomahawk/artistplaylistinterface.h +++ b/src/libtomahawk/artistplaylistinterface.h @@ -30,7 +30,7 @@ namespace Tomahawk { class Artist; - + class DLLEXPORT ArtistPlaylistInterface : public QObject, public Tomahawk::PlaylistInterface { Q_OBJECT @@ -58,7 +58,9 @@ public: virtual void setFilter( const QString& /*pattern*/ ) {} virtual void addQueries( const QList& tracks ); - + + virtual void findMoreIfaces() {} + signals: void repeatModeChanged( PlaylistInterface::RepeatMode mode ); void shuffleModeChanged( bool enabled ); diff --git a/src/libtomahawk/playlist.cpp b/src/libtomahawk/playlist.cpp index bd07027a8..fcf0f3cc3 100644 --- a/src/libtomahawk/playlist.cpp +++ b/src/libtomahawk/playlist.cpp @@ -18,8 +18,8 @@ #include "playlist.h" -#include -#include +#include +#include #include "database/database.h" #include "database/databasecommand_loadplaylistentries.h" @@ -32,6 +32,7 @@ #include "pipeline.h" #include "source.h" #include "sourcelist.h" +#include "playlistplaylistinterface.h" #include "utils/logger.h" #include "PlaylistUpdaterInterface.h" @@ -562,17 +563,6 @@ Playlist::newEntries( const QList< plentry_ptr >& entries ) } -QList -Playlist::tracks() -{ - QList queries; - foreach( const plentry_ptr& p, m_entries ) - queries << p->query(); - - return queries; -} - - void Playlist::setBusy( bool b ) { @@ -602,3 +592,15 @@ Playlist::checkRevisionQueue() createNewRevision( item.newRev, item.oldRev, item.entries ); } } + + +Tomahawk::playlistinterface_ptr +Playlist::getPlaylistInterface() +{ + if ( m_playlistInterface.isNull() ) + { + m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::PlaylistPlaylistInterface( this ) ); + } + + return m_playlistInterface; +} diff --git a/src/libtomahawk/playlist.h b/src/libtomahawk/playlist.h index 6c56eeb6e..5a6e04568 100644 --- a/src/libtomahawk/playlist.h +++ b/src/libtomahawk/playlist.h @@ -114,7 +114,7 @@ public: }; -class DLLEXPORT Playlist : public QObject, public Tomahawk::PlaylistInterface +class DLLEXPORT Playlist : public QObject { Q_OBJECT Q_PROPERTY( QString guid READ guid WRITE setGuid ) @@ -180,28 +180,13 @@ public: void setCreatedOn( uint createdOn ) { m_createdOn = createdOn; } // - virtual QList tracks(); - - virtual int unfilteredTrackCount() const { return m_entries.count(); } - virtual int trackCount() const { return m_entries.count(); } - - virtual bool hasNextItem() { return false; } - virtual Tomahawk::result_ptr currentItem() const { return m_currentItem; } - - virtual Tomahawk::result_ptr siblingItem( int /*itemsAway*/ ) { return result_ptr(); } - - virtual PlaylistInterface::RepeatMode repeatMode() const { return PlaylistInterface::NoRepeat; } - virtual bool shuffled() const { return false; } - - virtual void setRepeatMode( PlaylistInterface::RepeatMode ) {} - virtual void setShuffled( bool ) {} - - virtual void setFilter( const QString& /*pattern*/ ) {} QList entriesFromQueries( const QList& queries, bool clearFirst = false ); void setUpdater( PlaylistUpdaterInterface* interface ) { m_updater = interface; } PlaylistUpdaterInterface* updater() const { return m_updater; } + Tomahawk::playlistinterface_ptr getPlaylistInterface(); + signals: /// emitted when the playlist revision changes (whenever the playlist changes) void revisionLoaded( Tomahawk::PlaylistRevision ); @@ -221,13 +206,6 @@ signals: /// was deleted, eh? void deleted( const Tomahawk::playlist_ptr& pl ); - void repeatModeChanged( PlaylistInterface::RepeatMode mode ); - void shuffleModeChanged( bool enabled ); - - void trackCountChanged( unsigned int tracks ); - 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: @@ -291,8 +269,6 @@ private: unsigned int m_createdOn; bool m_shared; - result_ptr m_currentItem; - QList< plentry_ptr > m_initEntries; QList< plentry_ptr > m_entries; @@ -303,9 +279,11 @@ private: bool m_locallyChanged; bool m_deleted; bool m_busy; + + Tomahawk::playlistinterface_ptr m_playlistInterface; }; -}; +} Q_DECLARE_METATYPE( QSharedPointer< Tomahawk::Playlist > ) diff --git a/src/libtomahawk/playlistinterface.h b/src/libtomahawk/playlistinterface.h index aeb8d9dc0..88b7058e8 100644 --- a/src/libtomahawk/playlistinterface.h +++ b/src/libtomahawk/playlistinterface.h @@ -84,7 +84,7 @@ public: } //virtual void findMoreIfaces() = 0; - + public slots: virtual void setRepeatMode( RepeatMode mode ) = 0; virtual void setShuffled( bool enabled ) = 0; diff --git a/src/libtomahawk/playlistplaylistinterface.cpp b/src/libtomahawk/playlistplaylistinterface.cpp new file mode 100644 index 000000000..3f7984e44 --- /dev/null +++ b/src/libtomahawk/playlistplaylistinterface.cpp @@ -0,0 +1,64 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 "playlistplaylistinterface.h" + +#include "playlist.h" +#include "sourcelist.h" + +#include "utils/logger.h" + +using namespace Tomahawk; + + +PlaylistPlaylistInterface::PlaylistPlaylistInterface( Tomahawk::Playlist* playlist ) + : QObject() + , m_playlist( playlist ) +{ +} + + +PlaylistPlaylistInterface::~PlaylistPlaylistInterface() +{ + m_playlist.clear(); +} + + +int +PlaylistPlaylistInterface::unfilteredTrackCount() const +{ + return ( m_playlist.isNull() ? 0 : m_playlist.data()->entries().count() ); +} + + +int +PlaylistPlaylistInterface::trackCount() const +{ + return ( m_playlist.isNull() ? 0 : m_playlist.data()->entries().count() ); +} + + +QList< Tomahawk::query_ptr > +PlaylistPlaylistInterface::tracks() +{ + QList queries; + foreach( const plentry_ptr& p, ( m_playlist.isNull() ? QList< Tomahawk::plentry_ptr >() : m_playlist.data()->entries() ) ) + queries << p->query(); + + return queries; +} diff --git a/src/libtomahawk/playlistplaylistinterface.h b/src/libtomahawk/playlistplaylistinterface.h new file mode 100644 index 000000000..6beae26bb --- /dev/null +++ b/src/libtomahawk/playlistplaylistinterface.h @@ -0,0 +1,85 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 PLAYLISTPLAYLISTINTERFACE_H +#define PLAYLISTPLAYLISTINTERFACE_H + +#include +#include +#include + +#include "typedefs.h" +#include "result.h" +#include "playlistinterface.h" +#include "query.h" + +#include "dllmacro.h" + +namespace Tomahawk +{ + +class DLLEXPORT PlaylistPlaylistInterface : public QObject, public Tomahawk::PlaylistInterface +{ +Q_OBJECT + +public: + PlaylistPlaylistInterface( Tomahawk::Playlist* playlist ); + virtual ~PlaylistPlaylistInterface(); + + virtual QList tracks(); + + virtual int unfilteredTrackCount() const; + virtual int trackCount() const; + + virtual bool hasNextItem() { return false; } + virtual Tomahawk::result_ptr currentItem() const { return m_currentItem; } + + virtual Tomahawk::result_ptr siblingItem( int /*itemsAway*/ ) { return result_ptr(); } + + virtual PlaylistInterface::RepeatMode repeatMode() const { return PlaylistInterface::NoRepeat; } + virtual bool shuffled() const { return false; } + + virtual void setFilter( const QString& /*pattern*/ ) {} + + virtual void findMoreIfaces() {} + +signals: + void repeatModeChanged( PlaylistInterface::RepeatMode mode ); + void shuffleModeChanged( bool enabled ); + + void trackCountChanged( unsigned int tracks ); + void sourceTrackCountChanged( unsigned int tracks ); + + void nextTrackReady(); + +public slots: + virtual void setRepeatMode( PlaylistInterface::RepeatMode ) {} + virtual void setShuffled( bool ) {} + +private: + PlaylistPlaylistInterface(); + Q_DISABLE_COPY( PlaylistPlaylistInterface ) + + QWeakPointer< Tomahawk::Playlist > m_playlist; + + result_ptr m_currentItem; +}; + +} + +#endif // PLAYLISTPLAYLISTINTERFACE_H diff --git a/src/libtomahawk/sourceplaylistinterface.cpp b/src/libtomahawk/sourceplaylistinterface.cpp index d73beb15a..9dcce89e4 100644 --- a/src/libtomahawk/sourceplaylistinterface.cpp +++ b/src/libtomahawk/sourceplaylistinterface.cpp @@ -37,7 +37,9 @@ SourcePlaylistInterface::SourcePlaylistInterface( Tomahawk::source_ptr& source ) SourcePlaylistInterface::~SourcePlaylistInterface() -{} +{ + m_source.clear(); +} Tomahawk::result_ptr diff --git a/src/libtomahawk/sourceplaylistinterface.h b/src/libtomahawk/sourceplaylistinterface.h index cdc0d2945..7e4e5c73e 100644 --- a/src/libtomahawk/sourceplaylistinterface.h +++ b/src/libtomahawk/sourceplaylistinterface.h @@ -61,6 +61,8 @@ public: virtual void reset(); + virtual void findMoreIfaces() {} + public slots: virtual void setRepeatMode( PlaylistInterface::RepeatMode ) {} virtual void setShuffled( bool ) {}