mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-19 15:29:42 +01:00
* Playlist now queues addEntries/insertEntries calls if it's not loaded yet.
This commit is contained in:
parent
729291c589
commit
01e3c3b5b3
@ -163,6 +163,8 @@ Playlist::init()
|
||||
m_busy = false;
|
||||
m_deleted = false;
|
||||
m_locallyChanged = false;
|
||||
m_loaded = false;
|
||||
|
||||
connect( Pipeline::instance(), SIGNAL( idle() ), SLOT( onResolvingFinished() ) );
|
||||
}
|
||||
|
||||
@ -536,6 +538,7 @@ Playlist::setRevision( const QString& rev,
|
||||
}
|
||||
|
||||
setBusy( false );
|
||||
m_loaded = true;
|
||||
|
||||
if ( m_initEntries.count() && currentrevision().isEmpty() )
|
||||
{
|
||||
@ -656,8 +659,15 @@ Playlist::addEntry( const query_ptr& query, const QString& oldrev )
|
||||
void
|
||||
Playlist::addEntries( const QList<query_ptr>& queries, const QString& oldrev )
|
||||
{
|
||||
QList<plentry_ptr> el = entriesFromQueries( queries );
|
||||
if ( !m_loaded )
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << "Queueing addEntries call!";
|
||||
loadRevision( oldrev );
|
||||
m_queuedOps << NewClosure( 0, "", this, SLOT( addEntries( QList<Tomahawk::query_ptr>, QString ) ), queries, oldrev );
|
||||
return;
|
||||
}
|
||||
|
||||
const QList<plentry_ptr> el = entriesFromQueries( queries );
|
||||
const int prevSize = m_entries.size();
|
||||
|
||||
QString newrev = uuid();
|
||||
@ -667,7 +677,7 @@ Playlist::addEntries( const QList<query_ptr>& queries, const QString& oldrev )
|
||||
// PlaylistModel also emits during appends, but since we call
|
||||
// createNewRevision, it reloads instead of appends.
|
||||
const QList<plentry_ptr> added = el.mid( prevSize );
|
||||
qDebug() << "Playlist got" << queries.size() << "tracks added, emitting tracksInserted with:" << added.size() << "at pos:" << prevSize - 1;
|
||||
tDebug( LOGVERBOSE ) << "Playlist got" << queries.size() << "tracks added, emitting tracksInserted with:" << added.size() << "at pos:" << prevSize - 1;
|
||||
emit tracksInserted( added, prevSize );
|
||||
}
|
||||
|
||||
@ -675,13 +685,21 @@ Playlist::addEntries( const QList<query_ptr>& queries, const QString& oldrev )
|
||||
void
|
||||
Playlist::insertEntries( const QList< query_ptr >& queries, const int position, const QString& oldrev )
|
||||
{
|
||||
if ( !m_loaded )
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << "Queueing insertEntries call!";
|
||||
loadRevision( oldrev );
|
||||
m_queuedOps << NewClosure( 0, "", this, SLOT( insertEntries( QList<Tomahawk::query_ptr>, int, QString ) ), queries, position, oldrev );
|
||||
return;
|
||||
}
|
||||
|
||||
QList<plentry_ptr> toInsert = entriesFromQueries( queries, true );
|
||||
QList<plentry_ptr> entries = m_entries;
|
||||
|
||||
Q_ASSERT( position <= m_entries.size() );
|
||||
if ( position > m_entries.size() )
|
||||
{
|
||||
qWarning() << "ERROR trying to insert tracks past end of playlist! Appending!!";
|
||||
tDebug() << "ERROR trying to insert tracks past end of playlist! Appending!";
|
||||
addEntries( queries, oldrev );
|
||||
return;
|
||||
}
|
||||
@ -788,6 +806,12 @@ Playlist::checkRevisionQueue()
|
||||
}
|
||||
updateEntries( item.newRev, item.oldRev, item.entries );
|
||||
}
|
||||
|
||||
if ( !m_queuedOps.isEmpty() )
|
||||
{
|
||||
_detail::Closure* next = m_queuedOps.dequeue();
|
||||
next->forceInvoke();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "PlaylistInterface.h"
|
||||
#include "playlist/PlaylistUpdaterInterface.h"
|
||||
#include "Query.h"
|
||||
#include "utils/Closure.h"
|
||||
|
||||
#include "DllMacro.h"
|
||||
|
||||
@ -168,11 +169,9 @@ public:
|
||||
uint createdOn() const { return m_createdOn; }
|
||||
|
||||
bool busy() const { return m_busy; }
|
||||
bool loaded() const { return m_loaded; }
|
||||
|
||||
const QList< plentry_ptr >& entries() { return m_entries; }
|
||||
virtual void addEntry( const Tomahawk::query_ptr& query, const QString& oldrev );
|
||||
virtual void addEntries( const QList<Tomahawk::query_ptr>& queries, const QString& oldrev );
|
||||
virtual void insertEntries( const QList<Tomahawk::query_ptr>& queries, const int position, const QString& oldrev );
|
||||
|
||||
// <IGNORE hack="true">
|
||||
// these need to exist and be public for the json serialization stuff
|
||||
@ -248,6 +247,10 @@ public slots:
|
||||
// entries should be <= entries(), with changed metadata.
|
||||
void updateEntries( const QString& newrev, const QString& oldrev, const QList< plentry_ptr >& entries );
|
||||
|
||||
virtual void addEntry( const Tomahawk::query_ptr& query, const QString& oldrev );
|
||||
virtual void addEntries( const QList<Tomahawk::query_ptr>& queries, const QString& oldrev );
|
||||
virtual void insertEntries( const QList<Tomahawk::query_ptr>& queries, const int position, const QString& oldrev );
|
||||
|
||||
void reportCreated( const Tomahawk::playlist_ptr& self );
|
||||
void reportDeleted( const Tomahawk::playlist_ptr& self );
|
||||
|
||||
@ -310,7 +313,9 @@ private:
|
||||
unsigned int m_lastmodified;
|
||||
unsigned int m_createdOn;
|
||||
bool m_shared;
|
||||
bool m_loaded;
|
||||
|
||||
QQueue<_detail::Closure*> m_queuedOps;
|
||||
QList< plentry_ptr > m_initEntries;
|
||||
QList< plentry_ptr > m_entries;
|
||||
|
||||
@ -330,5 +335,6 @@ private:
|
||||
|
||||
Q_DECLARE_METATYPE( QSharedPointer< Tomahawk::Playlist > )
|
||||
Q_DECLARE_METATYPE( QList< QSharedPointer< Tomahawk::PlaylistEntry > > )
|
||||
Q_DECLARE_METATYPE( QList< QSharedPointer< Tomahawk::Query > > )
|
||||
|
||||
#endif // PLAYLIST_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user