1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-09 07:36:48 +02:00

Separate album playlist interface

This commit is contained in:
Jeff Mitchell
2011-12-28 12:27:25 -05:00
parent 9bc38282e9
commit 424ac7a1d5
8 changed files with 215 additions and 86 deletions

View File

@@ -283,6 +283,7 @@ set( libSources
artist.cpp artist.cpp
artistplaylistinterface.cpp artistplaylistinterface.cpp
album.cpp album.cpp
albumplaylistinterface.cpp
collection.cpp collection.cpp
playlist.cpp playlist.cpp
resolver.cpp resolver.cpp
@@ -416,6 +417,7 @@ set( libHeaders
artist.h artist.h
artistplaylistinterface.h artistplaylistinterface.h
album.h album.h
albumplaylistinterface.h
playlist.h playlist.h
EchonestCatalogSynchronizer.h EchonestCatalogSynchronizer.h

View File

@@ -19,6 +19,7 @@
#include "album.h" #include "album.h"
#include "artist.h" #include "artist.h"
#include "albumplaylistinterface.h"
#include "database/database.h" #include "database/database.h"
#include "database/databaseimpl.h" #include "database/databaseimpl.h"
#include "database/databasecommand_alltracks.h" #include "database/databasecommand_alltracks.h"
@@ -63,12 +64,10 @@ Album::get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& ar
Album::Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist ) Album::Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist )
: PlaylistInterface( this ) : QObject()
, m_id( id ) , m_id( id )
, m_name( name ) , m_name( name )
, m_artist( artist ) , m_artist( artist )
, m_currentItem( 0 )
, m_currentTrack( 0 )
{ {
} }
@@ -78,65 +77,28 @@ Album::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
m_queries << tracks; Tomahawk::AlbumPlaylistInterface* api = dynamic_cast< Tomahawk::AlbumPlaylistInterface* >( getPlaylistInterface().data() );
if ( api )
api->addQueries( tracks );
emit tracksAdded( tracks ); emit tracksAdded( tracks );
} }
Tomahawk::result_ptr
Album::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;
}
result_ptr
Album::currentItem() const
{
return m_currentItem;
}
bool
Album::hasNextItem()
{
int p = m_currentTrack;
p++;
if ( p < 0 || p >= m_queries.count() )
return false;
return true;
}
artist_ptr artist_ptr
Album::artist() const Album::artist() const
{ {
return m_artist; return m_artist;
} }
QList<Tomahawk::query_ptr>
Album::tracks()
{
if ( m_queries.isEmpty() )
{
DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks();
cmd->setAlbum( this );
cmd->setSortOrder( DatabaseCommand_AllTracks::AlbumPosition );
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, QVariant ) ), Tomahawk::playlistinterface_ptr
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) ); Album::getPlaylistInterface()
{
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) ); if ( m_playlistInterface.isNull() )
{
m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::AlbumPlaylistInterface( this ) );
} }
return m_queries; return m_playlistInterface;
} }

View File

@@ -19,8 +19,8 @@
#ifndef TOMAHAWKALBUM_H #ifndef TOMAHAWKALBUM_H
#define TOMAHAWKALBUM_H #define TOMAHAWKALBUM_H
#include <QObject> #include <QtCore/QObject>
#include <QSharedPointer> #include <QtCore/QSharedPointer>
#include "typedefs.h" #include "typedefs.h"
#include "playlistinterface.h" #include "playlistinterface.h"
@@ -29,7 +29,7 @@
namespace Tomahawk namespace Tomahawk
{ {
class DLLEXPORT Album : public QObject, public Tomahawk::PlaylistInterface class DLLEXPORT Album : public QObject
{ {
Q_OBJECT Q_OBJECT
@@ -44,47 +44,24 @@ public:
QString name() const { return m_name; } QString name() const { return m_name; }
artist_ptr artist() const; artist_ptr artist() const;
QList<Tomahawk::query_ptr> tracks(); Tomahawk::playlistinterface_ptr getPlaylistInterface();
virtual int trackCount() const { return m_queries.count(); }
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 );
private: private:
Q_DISABLE_COPY( Album )
Album(); Album();
unsigned int m_id; unsigned int m_id;
QString m_name; QString m_name;
artist_ptr m_artist; artist_ptr m_artist;
QList<Tomahawk::query_ptr> m_queries;
result_ptr m_currentItem; Tomahawk::playlistinterface_ptr m_playlistInterface;
unsigned int m_currentTrack;
}; };
}; // ns }; // ns

View File

@@ -0,0 +1,103 @@
/* === 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 "albumplaylistinterface.h"
#include "artist.h"
#include "database/database.h"
#include "database/databaseimpl.h"
#include "database/databasecommand_alltracks.h"
#include "query.h"
#include "utils/logger.h"
using namespace Tomahawk;
AlbumPlaylistInterface::AlbumPlaylistInterface() {}
AlbumPlaylistInterface::~AlbumPlaylistInterface() {}
AlbumPlaylistInterface::AlbumPlaylistInterface( Tomahawk::Album *album )
: Tomahawk::PlaylistInterface( this )
, m_currentItem( 0 )
, m_currentTrack( 0 )
, m_album( QWeakPointer< Tomahawk::Album >( album ) )
{
}
Tomahawk::result_ptr
AlbumPlaylistInterface::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;
}
result_ptr
AlbumPlaylistInterface::currentItem() const
{
return m_currentItem;
}
bool
AlbumPlaylistInterface::hasNextItem()
{
int p = m_currentTrack;
p++;
if ( p < 0 || p >= m_queries.count() )
return false;
return true;
}
QList< Tomahawk::query_ptr >
AlbumPlaylistInterface::tracks()
{
if ( m_queries.isEmpty() && m_album )
{
DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks();
cmd->setAlbum( m_album.data() );
cmd->setSortOrder( DatabaseCommand_AllTracks::AlbumPosition );
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
AlbumPlaylistInterface::addQueries( const QList< query_ptr >& tracks )
{
m_queries << tracks;
}

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 TOMAHAWKALBUMPLAYLISTINTERFACE_H
#define TOMAHAWKALBUMPLAYLISTINTERFACE_H
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
#include "typedefs.h"
#include "playlistinterface.h"
#include "dllmacro.h"
namespace Tomahawk
{
class Album;
class DLLEXPORT AlbumPlaylistInterface : public QObject, public Tomahawk::PlaylistInterface
{
Q_OBJECT
public:
AlbumPlaylistInterface( Tomahawk::Album *album );
virtual ~AlbumPlaylistInterface();
QList<Tomahawk::query_ptr> tracks();
virtual int trackCount() const { return m_queries.count(); }
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( AlbumPlaylistInterface )
AlbumPlaylistInterface();
QList< Tomahawk::query_ptr > m_queries;
result_ptr m_currentItem;
unsigned int m_currentTrack;
QWeakPointer< Tomahawk::Album > m_album;
};
}; // ns
#endif

View File

@@ -785,7 +785,7 @@ DropJob::getAlbum(const QString &artist, const QString &album)
if ( albumPtr.isNull() ) if ( albumPtr.isNull() )
return QList< query_ptr >(); return QList< query_ptr >();
if ( albumPtr->tracks().isEmpty() ) if ( albumPtr->getPlaylistInterface()->tracks().isEmpty() )
{ {
m_dropJob = new DropJobNotifier( QPixmap( RESPATH "images/album-icon.png" ), Album ); m_dropJob = new DropJobNotifier( QPixmap( RESPATH "images/album-icon.png" ), Album );
connect( albumPtr.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ), connect( albumPtr.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ),
@@ -796,7 +796,7 @@ DropJob::getAlbum(const QString &artist, const QString &album)
return QList< query_ptr >(); return QList< query_ptr >();
} }
else else
return albumPtr->tracks(); return albumPtr->getPlaylistInterface()->tracks();
} }

View File

@@ -152,7 +152,7 @@ PlaylistModel::append( const Tomahawk::album_ptr& album )
m_isTemporary = true; m_isTemporary = true;
} }
append( album->tracks() ); append( album->getPlaylistInterface()->tracks() );
} }

View File

@@ -19,7 +19,7 @@
#ifndef PLAYLISTINTERFACE_H #ifndef PLAYLISTINTERFACE_H
#define PLAYLISTINTERFACE_H #define PLAYLISTINTERFACE_H
#include <QModelIndex> #include <QtCore/QModelIndex>
#include "typedefs.h" #include "typedefs.h"
#include "dllmacro.h" #include "dllmacro.h"