mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-07 06:36:55 +02:00
Don't crash if user rapidly regenerates automatic playlists
This commit is contained in:
@@ -101,12 +101,13 @@ struct PlaylistRevision
|
|||||||
|
|
||||||
struct RevisionQueueItem
|
struct RevisionQueueItem
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
QString newRev;
|
QString newRev;
|
||||||
QString oldRev;
|
QString oldRev;
|
||||||
QList< plentry_ptr > entries;
|
QList< plentry_ptr > entries;
|
||||||
bool applyToTip;
|
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 ) {}
|
newRev( nRev ), oldRev( oRev), entries( e ), applyToTip( latest ) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -161,7 +161,12 @@ DynamicPlaylist::createNewRevision( const QString& newrev,
|
|||||||
const QList< dyncontrol_ptr>& controls,
|
const QList< dyncontrol_ptr>& controls,
|
||||||
const QList< plentry_ptr >& entries )
|
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 );
|
setBusy( true );
|
||||||
|
|
||||||
// get the newly added tracks
|
// get the newly added tracks
|
||||||
@@ -198,6 +203,12 @@ DynamicPlaylist::createNewRevision( const QString& newrev,
|
|||||||
const QString& type,
|
const QString& type,
|
||||||
const QList< dyncontrol_ptr>& controls )
|
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 );
|
setBusy( true );
|
||||||
|
|
||||||
// can skip the entry stuff. just overwrite with new info
|
// can skip the entry stuff. just overwrite with new info
|
||||||
@@ -484,3 +495,20 @@ DynamicPlaylist::variantsToControl( const QList< QVariantMap >& controlsV )
|
|||||||
return realControls;
|
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
|
struct DLLEXPORT DynamicPlaylistRevision : PlaylistRevision
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
QList< dyncontrol_ptr > controls;
|
QList< dyncontrol_ptr > controls;
|
||||||
Tomahawk::GeneratorMode mode;
|
Tomahawk::GeneratorMode mode;
|
||||||
QString type;
|
QString type;
|
||||||
@@ -60,6 +62,16 @@ struct DLLEXPORT DynamicPlaylistRevision : PlaylistRevision
|
|||||||
DynamicPlaylistRevision() {}
|
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
|
class DLLEXPORT DynamicPlaylist : public Playlist
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -185,8 +197,12 @@ private:
|
|||||||
GeneratorMode mode,
|
GeneratorMode mode,
|
||||||
bool shared );
|
bool shared );
|
||||||
|
|
||||||
|
void checkRevisionQueue();
|
||||||
|
|
||||||
QList< dyncontrol_ptr > variantsToControl( const QList< QVariantMap >& controlsV );
|
QList< dyncontrol_ptr > variantsToControl( const QList< QVariantMap >& controlsV );
|
||||||
geninterface_ptr m_generator;
|
geninterface_ptr m_generator;
|
||||||
|
|
||||||
|
QQueue<DynQueueItem> m_revisionQueue;
|
||||||
};
|
};
|
||||||
|
|
||||||
}; // namespace
|
}; // namespace
|
||||||
|
Reference in New Issue
Block a user