mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-01 14:42:25 +02:00
* Adjust inheriting models to new PlayableModel API.
This commit is contained in:
parent
0c00cccc1f
commit
d907a9fbc8
@ -93,10 +93,10 @@ PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist, bool loadEn
|
||||
}
|
||||
|
||||
QList<plentry_ptr> entries = playlist->entries();
|
||||
foreach( const plentry_ptr& p, entries )
|
||||
qDebug() << p->guid() << p->query()->track() << p->query()->artist();
|
||||
/* foreach ( const plentry_ptr& p, entries )
|
||||
qDebug() << p->guid() << p->query()->track() << p->query()->artist();*/
|
||||
|
||||
append( entries );
|
||||
appendEntries( entries );
|
||||
|
||||
m_isLoading = false;
|
||||
}
|
||||
@ -112,78 +112,67 @@ PlaylistModel::clear()
|
||||
|
||||
|
||||
void
|
||||
PlaylistModel::append( const QList< plentry_ptr >& entries )
|
||||
PlaylistModel::appendEntries( const QList< plentry_ptr >& entries )
|
||||
{
|
||||
insert( entries, rowCount( QModelIndex() ) );
|
||||
insertEntries( entries, rowCount( QModelIndex() ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistModel::append( const QList< query_ptr >& queries )
|
||||
PlaylistModel::insertAlbums( const QList< Tomahawk::album_ptr >& albums, int row )
|
||||
{
|
||||
insert( queries, rowCount( QModelIndex() ) );
|
||||
}
|
||||
// FIXME: This currently appends, not inserts!
|
||||
|
||||
|
||||
void
|
||||
PlaylistModel::append( const Tomahawk::query_ptr& query )
|
||||
{
|
||||
insert( query, rowCount( QModelIndex() ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistModel::append( const Tomahawk::album_ptr& album )
|
||||
{
|
||||
if ( album.isNull() )
|
||||
return;
|
||||
|
||||
connect( album.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ),
|
||||
SLOT( append( QList<Tomahawk::query_ptr> ) ) );
|
||||
|
||||
if ( rowCount( QModelIndex() ) == 0 )
|
||||
foreach ( const album_ptr& album, albums )
|
||||
{
|
||||
setTitle( album->name() );
|
||||
setDescription( tr( "All tracks by %1 on album %2" ).arg( album->artist()->name() ).arg( album->name() ) );
|
||||
m_isTemporary = true;
|
||||
if ( album.isNull() )
|
||||
return;
|
||||
|
||||
connect( album.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ),
|
||||
SLOT( appendQueries( QList<Tomahawk::query_ptr> ) ) );
|
||||
|
||||
appendQueries( album->playlistInterface( Mixed )->tracks() );
|
||||
}
|
||||
|
||||
append( album->playlistInterface( Mixed )->tracks() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistModel::append( const Tomahawk::artist_ptr& artist )
|
||||
{
|
||||
if ( artist.isNull() )
|
||||
return;
|
||||
|
||||
connect( artist.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ),
|
||||
SLOT( append( QList<Tomahawk::query_ptr> ) ) );
|
||||
|
||||
if ( rowCount( QModelIndex() ) == 0 )
|
||||
if ( rowCount( QModelIndex() ) == 0 && albums.count() == 1 )
|
||||
{
|
||||
setTitle( artist->name() );
|
||||
setDescription( tr( "All tracks by %1" ).arg( artist->name() ) );
|
||||
setTitle( albums.first()->name() );
|
||||
setDescription( tr( "All tracks by %1 on album %2" ).arg( albums.first()->artist()->name() ).arg( albums.first()->name() ) );
|
||||
m_isTemporary = true;
|
||||
}
|
||||
|
||||
append( artist->playlistInterface( Mixed )->tracks() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistModel::insert( const Tomahawk::query_ptr& query, int row )
|
||||
PlaylistModel::insertArtists( const QList< Tomahawk::artist_ptr >& artists, int row )
|
||||
{
|
||||
PlayableModel::insert( query, row );
|
||||
// FIXME: This currently appends, not inserts!
|
||||
|
||||
foreach ( const artist_ptr& artist, artists )
|
||||
{
|
||||
if ( artist.isNull() )
|
||||
return;
|
||||
|
||||
connect( artist.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ),
|
||||
SLOT( appendQueries( QList<Tomahawk::query_ptr> ) ) );
|
||||
|
||||
appendQueries( artist->playlistInterface( Mixed )->tracks() );
|
||||
}
|
||||
|
||||
if ( rowCount( QModelIndex() ) == 0 && artists.count() == 1 )
|
||||
{
|
||||
setTitle( artists.first()->name() );
|
||||
setDescription( tr( "All tracks by %1" ).arg( artists.first()->name() ) );
|
||||
m_isTemporary = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistModel::insert( const QList< Tomahawk::query_ptr >& queries, int row )
|
||||
PlaylistModel::insertQueries( const QList< Tomahawk::query_ptr >& queries, int row )
|
||||
{
|
||||
QList< Tomahawk::plentry_ptr > entries;
|
||||
foreach( const query_ptr& query, queries )
|
||||
foreach ( const query_ptr& query, queries )
|
||||
{
|
||||
plentry_ptr entry = plentry_ptr( new PlaylistEntry() );
|
||||
|
||||
@ -200,12 +189,12 @@ PlaylistModel::insert( const QList< Tomahawk::query_ptr >& queries, int row )
|
||||
entries << entry;
|
||||
}
|
||||
|
||||
insert( entries, row );
|
||||
insertEntries( entries, row );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistModel::insert( const QList< Tomahawk::plentry_ptr >& entries, int row )
|
||||
PlaylistModel::insertEntries( const QList< Tomahawk::plentry_ptr >& entries, int row )
|
||||
{
|
||||
if ( !entries.count() )
|
||||
{
|
||||
@ -368,7 +357,7 @@ PlaylistModel::parsedDroppedTracks( QList< query_ptr > tracks )
|
||||
if ( update )
|
||||
beginPlaylistChanges();
|
||||
|
||||
insert( tracks, beginRow );
|
||||
insertQueries( tracks, beginRow );
|
||||
|
||||
if ( update && m_dropStorage.action & Qt::CopyAction )
|
||||
endPlaylistChanges();
|
||||
|
@ -58,15 +58,12 @@ public:
|
||||
public slots:
|
||||
virtual void clear();
|
||||
|
||||
virtual void append( const Tomahawk::query_ptr& query );
|
||||
virtual void append( const Tomahawk::album_ptr& album );
|
||||
virtual void append( const Tomahawk::artist_ptr& artist );
|
||||
virtual void append( const QList< Tomahawk::query_ptr >& queries );
|
||||
virtual void append( const QList< Tomahawk::plentry_ptr >& entries );
|
||||
virtual void appendEntries( const QList< Tomahawk::plentry_ptr >& entries );
|
||||
|
||||
virtual void insert( const Tomahawk::query_ptr& query, int row = 0 );
|
||||
virtual void insert( const QList< Tomahawk::query_ptr >& queries, int row = 0 );
|
||||
virtual void insert( const QList< Tomahawk::plentry_ptr >& entries, int row = 0 );
|
||||
virtual void insertAlbums( const QList< Tomahawk::album_ptr >& album, int row = 0 );
|
||||
virtual void insertArtists( const QList< Tomahawk::artist_ptr >& artist, int row = 0 );
|
||||
virtual void insertQueries( const QList< Tomahawk::query_ptr >& queries, int row = 0 );
|
||||
virtual void insertEntries( const QList< Tomahawk::plentry_ptr >& entries, int row = 0 );
|
||||
|
||||
virtual void removeIndex( const QModelIndex& index, bool moreToCome = false );
|
||||
|
||||
|
@ -60,7 +60,7 @@ RecentlyAddedModel::loadHistory()
|
||||
cmd->setSortDescending( true );
|
||||
|
||||
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, QVariant ) ),
|
||||
SLOT( append( QList<Tomahawk::query_ptr> ) ), Qt::QueuedConnection );
|
||||
SLOT( appendQueries( QList<Tomahawk::query_ptr> ) ), Qt::QueuedConnection );
|
||||
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ RecentlyPlayedModel::loadHistory()
|
||||
cmd->setLimit( m_limit );
|
||||
|
||||
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ),
|
||||
SLOT( append( QList<Tomahawk::query_ptr> ) ), Qt::QueuedConnection );
|
||||
SLOT( appendQueries( QList<Tomahawk::query_ptr> ) ), Qt::QueuedConnection );
|
||||
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
}
|
||||
@ -119,7 +119,7 @@ RecentlyPlayedModel::onPlaybackFinished( const Tomahawk::query_ptr& query )
|
||||
|
||||
PlayableItem* youngestItem = itemFromIndex( index( 0, 0, QModelIndex() ) );
|
||||
if ( youngestItem->query()->playedBy().second <= playtime )
|
||||
insert( query, 0 );
|
||||
insertQuery( query, 0 );
|
||||
else
|
||||
{
|
||||
for ( int i = 0; i < count - 1; i++ )
|
||||
@ -129,14 +129,14 @@ RecentlyPlayedModel::onPlaybackFinished( const Tomahawk::query_ptr& query )
|
||||
|
||||
if ( item1->query()->playedBy().second >= playtime && item2->query()->playedBy().second <= playtime )
|
||||
{
|
||||
insert( query, i + 1 );
|
||||
insertQuery( query, i + 1 );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
insert( query, 0 );
|
||||
insertQuery( query, 0 );
|
||||
|
||||
if ( trackCount() > (int)m_limit )
|
||||
remove( m_limit );
|
||||
|
@ -121,7 +121,7 @@ DynamicModel::newTrackGenerated( const Tomahawk::query_ptr& query )
|
||||
connect( query.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( trackResolveFinished( bool ) ) );
|
||||
|
||||
m_waitingFor << query.data();
|
||||
append( query );
|
||||
appendQuery( query );
|
||||
}
|
||||
}
|
||||
|
||||
@ -316,11 +316,9 @@ DynamicModel::addToPlaylist( const QList< query_ptr >& entries, bool clearFirst
|
||||
m_playlist->addEntries( entries, m_playlist->currentrevision() );
|
||||
}
|
||||
else
|
||||
{ // read-only, so add tracks only in the GUI, not to the playlist itself
|
||||
foreach ( const query_ptr& query, entries )
|
||||
{
|
||||
append( query );
|
||||
}
|
||||
{
|
||||
// read-only, so add tracks only in the GUI, not to the playlist itself
|
||||
appendQueries( entries );
|
||||
}
|
||||
|
||||
emit tracksAdded();
|
||||
|
Loading…
x
Reference in New Issue
Block a user