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

Separate out Playlist's interface. PlaylistPlaylistInterface isn't a great name, someone come up with something better.

This commit is contained in:
Jeff Mitchell 2011-12-30 16:31:19 -05:00
parent f81db381be
commit 9fe40f0682
12 changed files with 193 additions and 48 deletions

View File

@ -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

View File

@ -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;
}
}

View File

@ -59,7 +59,9 @@ public:
virtual void setFilter( const QString& /*pattern*/ ) {}
virtual void addQueries( const QList<Tomahawk::query_ptr>& tracks );
virtual void findMoreIfaces() {}
signals:
void repeatModeChanged( PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled );

View File

@ -40,6 +40,7 @@ ArtistPlaylistInterface::ArtistPlaylistInterface( Tomahawk::Artist *artist )
ArtistPlaylistInterface::~ArtistPlaylistInterface()
{
m_artist.clear();
}

View File

@ -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<Tomahawk::query_ptr>& tracks );
virtual void findMoreIfaces() {}
signals:
void repeatModeChanged( PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled );

View File

@ -18,8 +18,8 @@
#include "playlist.h"
#include <QDomDocument>
#include <QDomElement>
#include <QtXml/QDomDocument>
#include <QtXml/QDomElement>
#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<Tomahawk::query_ptr>
Playlist::tracks()
{
QList<Tomahawk::query_ptr> 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;
}

View File

@ -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; }
// </IGNORE>
virtual QList<Tomahawk::query_ptr> 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<plentry_ptr> entriesFromQueries( const QList<Tomahawk::query_ptr>& 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 > )

View File

@ -84,7 +84,7 @@ public:
}
//virtual void findMoreIfaces() = 0;
public slots:
virtual void setRepeatMode( RepeatMode mode ) = 0;
virtual void setShuffled( bool enabled ) = 0;

View File

@ -0,0 +1,64 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@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 "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<Tomahawk::query_ptr> queries;
foreach( const plentry_ptr& p, ( m_playlist.isNull() ? QList< Tomahawk::plentry_ptr >() : m_playlist.data()->entries() ) )
queries << p->query();
return queries;
}

View File

@ -0,0 +1,85 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@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 PLAYLISTPLAYLISTINTERFACE_H
#define PLAYLISTPLAYLISTINTERFACE_H
#include <QObject>
#include <QList>
#include <QSharedPointer>
#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<Tomahawk::query_ptr> 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

View File

@ -37,7 +37,9 @@ SourcePlaylistInterface::SourcePlaylistInterface( Tomahawk::source_ptr& source )
SourcePlaylistInterface::~SourcePlaylistInterface()
{}
{
m_source.clear();
}
Tomahawk::result_ptr

View File

@ -61,6 +61,8 @@ public:
virtual void reset();
virtual void findMoreIfaces() {}
public slots:
virtual void setRepeatMode( PlaylistInterface::RepeatMode ) {}
virtual void setShuffled( bool ) {}