mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-10 16:14:40 +02:00
Separate Artist playlist interface
This commit is contained in:
@@ -281,6 +281,7 @@ set( libSources
|
|||||||
|
|
||||||
aclsystem.cpp
|
aclsystem.cpp
|
||||||
artist.cpp
|
artist.cpp
|
||||||
|
artistplaylistinterface.cpp
|
||||||
album.cpp
|
album.cpp
|
||||||
collection.cpp
|
collection.cpp
|
||||||
playlist.cpp
|
playlist.cpp
|
||||||
@@ -413,6 +414,7 @@ set( libHeaders
|
|||||||
sourceplaylistinterface.h
|
sourceplaylistinterface.h
|
||||||
|
|
||||||
artist.h
|
artist.h
|
||||||
|
artistplaylistinterface.h
|
||||||
album.h
|
album.h
|
||||||
playlist.h
|
playlist.h
|
||||||
|
|
||||||
|
@@ -18,10 +18,10 @@
|
|||||||
|
|
||||||
#include "artist.h"
|
#include "artist.h"
|
||||||
|
|
||||||
|
#include "artistplaylistinterface.h"
|
||||||
#include "collection.h"
|
#include "collection.h"
|
||||||
#include "database/database.h"
|
#include "database/database.h"
|
||||||
#include "database/databaseimpl.h"
|
#include "database/databaseimpl.h"
|
||||||
#include "database/databasecommand_alltracks.h"
|
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
|
|
||||||
#include "utils/logger.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 )
|
Artist::Artist( unsigned int id, const QString& name )
|
||||||
: PlaylistInterface( this )
|
: QObject()
|
||||||
, m_id( id )
|
, m_id( id )
|
||||||
, m_name( name )
|
, m_name( name )
|
||||||
, m_currentItem( 0 )
|
|
||||||
, m_currentTrack( 0 )
|
|
||||||
{
|
{
|
||||||
m_sortname = DatabaseImpl::sortname( name, true );
|
m_sortname = DatabaseImpl::sortname( name, true );
|
||||||
}
|
}
|
||||||
@@ -86,61 +84,19 @@ Artist::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks )
|
|||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
m_queries << tracks;
|
Tomahawk::ArtistPlaylistInterface* api = dynamic_cast< Tomahawk::ArtistPlaylistInterface* >( getPlaylistInterface().data() );
|
||||||
|
if ( api )
|
||||||
|
api->addQueries( tracks );
|
||||||
emit tracksAdded( tracks );
|
emit tracksAdded( tracks );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Tomahawk::playlistinterface_ptr
|
||||||
Tomahawk::result_ptr
|
Artist::getPlaylistInterface()
|
||||||
Artist::siblingItem( int itemsAway )
|
|
||||||
{
|
{
|
||||||
int p = m_currentTrack;
|
if ( m_playlistInterface.isNull() )
|
||||||
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() )
|
|
||||||
{
|
{
|
||||||
DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks();
|
m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::ArtistPlaylistInterface( this ) );
|
||||||
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 ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_queries;
|
return m_playlistInterface;
|
||||||
}
|
}
|
||||||
|
@@ -23,13 +23,12 @@
|
|||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
|
|
||||||
#include "typedefs.h"
|
#include "typedefs.h"
|
||||||
#include "playlistinterface.h"
|
|
||||||
#include "dllmacro.h"
|
#include "dllmacro.h"
|
||||||
|
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
{
|
{
|
||||||
|
|
||||||
class DLLEXPORT Artist : public QObject, public Tomahawk::PlaylistInterface
|
class DLLEXPORT Artist : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -45,33 +44,10 @@ public:
|
|||||||
QString name() const { return m_name; }
|
QString name() const { return m_name; }
|
||||||
QString sortname() const { return m_sortname; }
|
QString sortname() const { return m_sortname; }
|
||||||
|
|
||||||
virtual QList<Tomahawk::query_ptr> tracks();
|
Tomahawk::playlistinterface_ptr getPlaylistInterface();
|
||||||
|
|
||||||
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*/ ) {}
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void repeatModeChanged( PlaylistInterface::RepeatMode mode );
|
|
||||||
void shuffleModeChanged( bool enabled );
|
|
||||||
|
|
||||||
void tracksAdded( const QList<Tomahawk::query_ptr>& tracks );
|
void tracksAdded( const QList<Tomahawk::query_ptr>& tracks );
|
||||||
void trackCountChanged( unsigned int tracks );
|
|
||||||
void sourceTrackCountChanged( unsigned int tracks );
|
|
||||||
|
|
||||||
void nextTrackReady();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks );
|
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks );
|
||||||
@@ -83,9 +59,7 @@ private:
|
|||||||
QString m_name;
|
QString m_name;
|
||||||
QString m_sortname;
|
QString m_sortname;
|
||||||
|
|
||||||
QList<Tomahawk::query_ptr> m_queries;
|
Tomahawk::playlistinterface_ptr m_playlistInterface;
|
||||||
result_ptr m_currentItem;
|
|
||||||
unsigned int m_currentTrack;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}; // ns
|
}; // ns
|
||||||
|
105
src/libtomahawk/artistplaylistinterface.cpp
Normal file
105
src/libtomahawk/artistplaylistinterface.cpp
Normal 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;
|
||||||
|
}
|
83
src/libtomahawk/artistplaylistinterface.h
Normal file
83
src/libtomahawk/artistplaylistinterface.h
Normal 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
|
@@ -764,7 +764,7 @@ QList< query_ptr >
|
|||||||
DropJob::getArtist( const QString &artist )
|
DropJob::getArtist( const QString &artist )
|
||||||
{
|
{
|
||||||
artist_ptr artistPtr = Artist::get( 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> ) ),
|
connect( artistPtr.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ),
|
||||||
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
|
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
|
||||||
@@ -772,7 +772,7 @@ DropJob::getArtist( const QString &artist )
|
|||||||
return QList< query_ptr >();
|
return QList< query_ptr >();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return artistPtr->tracks();
|
return artistPtr->getPlaylistInterface()->tracks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -172,7 +172,7 @@ PlaylistModel::append( const Tomahawk::artist_ptr& artist )
|
|||||||
m_isTemporary = true;
|
m_isTemporary = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
append( artist->tracks() );
|
append( artist->getPlaylistInterface()->tracks() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -83,6 +83,8 @@ public:
|
|||||||
return m_sharedPtr;
|
return m_sharedPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//virtual void findMoreIfaces() = 0;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void setRepeatMode( RepeatMode mode ) = 0;
|
virtual void setRepeatMode( RepeatMode mode ) = 0;
|
||||||
virtual void setShuffled( bool enabled ) = 0;
|
virtual void setShuffled( bool enabled ) = 0;
|
||||||
|
@@ -188,7 +188,7 @@ Source::setOffline()
|
|||||||
|
|
||||||
m_cc = 0;
|
m_cc = 0;
|
||||||
DatabaseCommand_SourceOffline* cmd = new DatabaseCommand_SourceOffline( id() );
|
DatabaseCommand_SourceOffline* cmd = new DatabaseCommand_SourceOffline( id() );
|
||||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user