mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-02-24 11:53:09 +01:00
Don't crash if user rapidly regenerates automatic playlists
This commit is contained in:
parent
5e4b5fa0d0
commit
326b75aefe
@ -101,12 +101,13 @@ struct PlaylistRevision
|
||||
|
||||
struct RevisionQueueItem
|
||||
{
|
||||
public:
|
||||
QString newRev;
|
||||
QString oldRev;
|
||||
QList< plentry_ptr > entries;
|
||||
bool applyToTip;
|
||||
|
||||
RevisionQueueItem( const QString& nRev, const QString& oRev, QList< plentry_ptr > e, bool latest ) :
|
||||
RevisionQueueItem( const QString& nRev, const QString& oRev, const QList< plentry_ptr >& e, bool latest ) :
|
||||
newRev( nRev ), oldRev( oRev), entries( e ), applyToTip( latest ) {}
|
||||
};
|
||||
|
||||
|
@ -161,7 +161,12 @@ DynamicPlaylist::createNewRevision( const QString& newrev,
|
||||
const QList< dyncontrol_ptr>& controls,
|
||||
const QList< plentry_ptr >& entries )
|
||||
{
|
||||
Q_ASSERT( !busy() );
|
||||
if ( busy() )
|
||||
{
|
||||
m_revisionQueue.enqueue( DynQueueItem( newrev, oldrev, type, controls, (int)Static, entries, oldrev == currentrevision() ) );
|
||||
return;
|
||||
}
|
||||
|
||||
setBusy( true );
|
||||
|
||||
// get the newly added tracks
|
||||
@ -198,6 +203,12 @@ DynamicPlaylist::createNewRevision( const QString& newrev,
|
||||
const QString& type,
|
||||
const QList< dyncontrol_ptr>& controls )
|
||||
{
|
||||
if ( busy() )
|
||||
{
|
||||
m_revisionQueue.enqueue( DynQueueItem( newrev, oldrev, type, controls, (int)OnDemand, QList< plentry_ptr >(), oldrev == currentrevision() ) );
|
||||
return;
|
||||
}
|
||||
|
||||
setBusy( true );
|
||||
|
||||
// can skip the entry stuff. just overwrite with new info
|
||||
@ -484,3 +495,20 @@ DynamicPlaylist::variantsToControl( const QList< QVariantMap >& controlsV )
|
||||
return realControls;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DynamicPlaylist::checkRevisionQueue()
|
||||
{
|
||||
if ( !m_revisionQueue.isEmpty() )
|
||||
{
|
||||
DynQueueItem item = m_revisionQueue.dequeue();
|
||||
if ( item.oldRev != currentrevision() && item.applyToTip ) // this was applied to the then-latest, but the already-running operation changed it so it's out of date now. fix it
|
||||
{
|
||||
item.oldRev = currentrevision();
|
||||
}
|
||||
if( item.mode == Static )
|
||||
createNewRevision( item.newRev, item.oldRev, item.type, item.controls, item.entries );
|
||||
else
|
||||
createNewRevision( item.newRev, item.oldRev, item.type, item.controls );
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,8 @@ namespace Tomahawk {
|
||||
|
||||
struct DLLEXPORT DynamicPlaylistRevision : PlaylistRevision
|
||||
{
|
||||
public:
|
||||
|
||||
QList< dyncontrol_ptr > controls;
|
||||
Tomahawk::GeneratorMode mode;
|
||||
QString type;
|
||||
@ -60,6 +62,16 @@ struct DLLEXPORT DynamicPlaylistRevision : PlaylistRevision
|
||||
DynamicPlaylistRevision() {}
|
||||
};
|
||||
|
||||
struct DynQueueItem : RevisionQueueItem
|
||||
{
|
||||
QString type;
|
||||
QList <dyncontrol_ptr> controls;
|
||||
int mode;
|
||||
|
||||
DynQueueItem( const QString& nRev, const QString& oRev, const QString& typ, const QList< dyncontrol_ptr >& ctrls, int m, const QList< plentry_ptr >& e, bool latest ) :
|
||||
RevisionQueueItem( nRev, oRev, e, latest ), type( typ ), controls( ctrls ), mode( m ) {}
|
||||
};
|
||||
|
||||
class DLLEXPORT DynamicPlaylist : public Playlist
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -185,8 +197,12 @@ private:
|
||||
GeneratorMode mode,
|
||||
bool shared );
|
||||
|
||||
void checkRevisionQueue();
|
||||
|
||||
QList< dyncontrol_ptr > variantsToControl( const QList< QVariantMap >& controlsV );
|
||||
geninterface_ptr m_generator;
|
||||
|
||||
QQueue<DynQueueItem> m_revisionQueue;
|
||||
};
|
||||
|
||||
}; // namespace
|
||||
|
Loading…
x
Reference in New Issue
Block a user