1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 03:10:12 +02:00

Separate Artist playlist interface

This commit is contained in:
Jeff Mitchell
2011-12-26 13:19:24 -05:00
parent a4f65cbcc2
commit 1a240911f5
9 changed files with 209 additions and 87 deletions

View File

@@ -281,6 +281,7 @@ set( libSources
aclsystem.cpp
artist.cpp
artistplaylistinterface.cpp
album.cpp
collection.cpp
playlist.cpp
@@ -413,6 +414,7 @@ set( libHeaders
sourceplaylistinterface.h
artist.h
artistplaylistinterface.h
album.h
playlist.h

View File

@@ -18,10 +18,10 @@
#include "artist.h"
#include "artistplaylistinterface.h"
#include "collection.h"
#include "database/database.h"
#include "database/databaseimpl.h"
#include "database/databasecommand_alltracks.h"
#include "query.h"
#include "utils/logger.h"
@@ -71,11 +71,9 @@ Artist::get( unsigned int id, const QString& name )
Artist::Artist( unsigned int id, const QString& name )
: PlaylistInterface( this )
: QObject()
, m_id( id )
, m_name( name )
, m_currentItem( 0 )
, m_currentTrack( 0 )
{
m_sortname = DatabaseImpl::sortname( name, true );
}
@@ -86,61 +84,19 @@ Artist::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks )
{
qDebug() << Q_FUNC_INFO;
m_queries << tracks;
Tomahawk::ArtistPlaylistInterface* api = dynamic_cast< Tomahawk::ArtistPlaylistInterface* >( getPlaylistInterface().data() );
if ( api )
api->addQueries( tracks );
emit tracksAdded( tracks );
}
Tomahawk::result_ptr
Artist::siblingItem( int itemsAway )
Tomahawk::playlistinterface_ptr
Artist::getPlaylistInterface()
{
int p = m_currentTrack;
p += itemsAway;
if ( p < 0 )
return Tomahawk::result_ptr();
if ( p >= m_queries.count() )
return Tomahawk::result_ptr();
m_currentTrack = p;
m_currentItem = m_queries.at( p )->results().first();
return m_currentItem;
}
bool
Artist::hasNextItem()
{
int p = m_currentTrack;
p++;
if ( p < 0 || p >= m_queries.count() )
return false;
return true;
}
result_ptr
Artist::currentItem() const
{
return m_currentItem;
}
QList<Tomahawk::query_ptr>
Artist::tracks()
{
if ( m_queries.isEmpty() )
if ( m_playlistInterface.isNull() )
{
DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks();
cmd->setArtist( this );
cmd->setSortOrder( DatabaseCommand_AllTracks::Album );
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, QVariant ) ),
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::ArtistPlaylistInterface( this ) );
}
return m_queries;
return m_playlistInterface;
}

View File

@@ -23,13 +23,12 @@
#include <QSharedPointer>
#include "typedefs.h"
#include "playlistinterface.h"
#include "dllmacro.h"
namespace Tomahawk
{
class DLLEXPORT Artist : public QObject, public Tomahawk::PlaylistInterface
class DLLEXPORT Artist : public QObject
{
Q_OBJECT
@@ -45,33 +44,10 @@ public:
QString name() const { return m_name; }
QString sortname() const { return m_sortname; }
virtual QList<Tomahawk::query_ptr> tracks();
virtual int trackCount() const { return 0; }
virtual int unfilteredTrackCount() const { return m_queries.count(); }
virtual Tomahawk::result_ptr siblingItem( int itemsAway );
virtual bool hasNextItem();
virtual Tomahawk::result_ptr currentItem() const;
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*/ ) {}
Tomahawk::playlistinterface_ptr getPlaylistInterface();
signals:
void repeatModeChanged( PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled );
void tracksAdded( const QList<Tomahawk::query_ptr>& tracks );
void trackCountChanged( unsigned int tracks );
void sourceTrackCountChanged( unsigned int tracks );
void nextTrackReady();
private slots:
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks );
@@ -83,9 +59,7 @@ private:
QString m_name;
QString m_sortname;
QList<Tomahawk::query_ptr> m_queries;
result_ptr m_currentItem;
unsigned int m_currentTrack;
Tomahawk::playlistinterface_ptr m_playlistInterface;
};
}; // ns

View File

@@ -0,0 +1,105 @@
/* === 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 "artistplaylistinterface.h"
#include "artist.h"
#include "collection.h"
#include "query.h"
#include "database/database.h"
#include "database/databasecommand_alltracks.h"
#include "utils/logger.h"
using namespace Tomahawk;
ArtistPlaylistInterface::ArtistPlaylistInterface( Tomahawk::Artist *artist )
: Tomahawk::PlaylistInterface()
, m_currentItem( 0 )
, m_currentTrack( 0 )
, m_artist( QWeakPointer< Tomahawk::Artist >( artist ) )
{
}
ArtistPlaylistInterface::~ArtistPlaylistInterface()
{
}
Tomahawk::result_ptr
ArtistPlaylistInterface::siblingItem( int itemsAway )
{
int p = m_currentTrack;
p += itemsAway;
if ( p < 0 )
return Tomahawk::result_ptr();
if ( p >= m_queries.count() )
return Tomahawk::result_ptr();
m_currentTrack = p;
m_currentItem = m_queries.at( p )->results().first();
return m_currentItem;
}
bool
ArtistPlaylistInterface::hasNextItem()
{
int p = m_currentTrack;
p++;
if ( p < 0 || p >= m_queries.count() )
return false;
return true;
}
result_ptr
ArtistPlaylistInterface::currentItem() const
{
return m_currentItem;
}
QList<Tomahawk::query_ptr>
ArtistPlaylistInterface::tracks()
{
if ( m_queries.isEmpty() && m_artist )
{
DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks();
cmd->setArtist( m_artist.data() );
cmd->setSortOrder( DatabaseCommand_AllTracks::Album );
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, QVariant ) ),
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
}
return m_queries;
}
void
ArtistPlaylistInterface::addQueries( const QList< query_ptr >& tracks )
{
m_queries << tracks;
}

View File

@@ -0,0 +1,83 @@
/* === 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 TOMAHAWKARTISTPLAYLISTINTERFACE_H
#define TOMAHAWKARTISTPLAYLISTINTERFACE_H
#include <QObject>
#include <QSharedPointer>
#include "typedefs.h"
#include "playlistinterface.h"
#include "dllmacro.h"
namespace Tomahawk
{
class Artist;
class DLLEXPORT ArtistPlaylistInterface : public QObject, public Tomahawk::PlaylistInterface
{
Q_OBJECT
public:
ArtistPlaylistInterface( Tomahawk::Artist *artist );
virtual ~ArtistPlaylistInterface();
virtual QList<Tomahawk::query_ptr> tracks();
virtual int trackCount() const { return 0; }
virtual int unfilteredTrackCount() const { return m_queries.count(); }
virtual Tomahawk::result_ptr siblingItem( int itemsAway );
virtual bool hasNextItem();
virtual Tomahawk::result_ptr currentItem() const;
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*/ ) {}
virtual void addQueries( const QList<Tomahawk::query_ptr>& tracks );
signals:
void repeatModeChanged( PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled );
void trackCountChanged( unsigned int tracks );
void sourceTrackCountChanged( unsigned int tracks );
void nextTrackReady();
private:
Q_DISABLE_COPY( ArtistPlaylistInterface )
QList< Tomahawk::query_ptr > m_queries;
result_ptr m_currentItem;
unsigned int m_currentTrack;
QWeakPointer< Tomahawk::Artist > m_artist;
};
}; // ns
#endif

View File

@@ -764,7 +764,7 @@ QList< query_ptr >
DropJob::getArtist( const QString &artist )
{
artist_ptr artistPtr = Artist::get( artist );
if ( artistPtr->tracks().isEmpty() )
if ( artistPtr->getPlaylistInterface()->tracks().isEmpty() )
{
connect( artistPtr.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ),
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
@@ -772,7 +772,7 @@ DropJob::getArtist( const QString &artist )
return QList< query_ptr >();
}
else
return artistPtr->tracks();
return artistPtr->getPlaylistInterface()->tracks();
}

View File

@@ -172,7 +172,7 @@ PlaylistModel::append( const Tomahawk::artist_ptr& artist )
m_isTemporary = true;
}
append( artist->tracks() );
append( artist->getPlaylistInterface()->tracks() );
}

View File

@@ -83,6 +83,8 @@ public:
return m_sharedPtr;
}
//virtual void findMoreIfaces() = 0;
public slots:
virtual void setRepeatMode( RepeatMode mode ) = 0;
virtual void setShuffled( bool enabled ) = 0;

View File

@@ -188,7 +188,7 @@ Source::setOffline()
m_cc = 0;
DatabaseCommand_SourceOffline* cmd = new DatabaseCommand_SourceOffline( id() );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
}