mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-19 04:11:46 +02:00
Queue too-fast revision changes and replay them in order to avoid crashes while fast editing
This commit is contained in:
@@ -296,7 +296,12 @@ Playlist::createNewRevision( const QString& newrev, const QString& oldrev, const
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << newrev << oldrev << entries.count();
|
||||
|
||||
Q_ASSERT( !busy() );
|
||||
if ( busy() )
|
||||
{
|
||||
m_revisionQueue.enqueue( RevisionQueueItem( newrev, oldrev, entries, oldrev == currentrevision() ) );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( newrev != oldrev )
|
||||
setBusy( true );
|
||||
|
||||
@@ -370,6 +375,8 @@ Playlist::setRevision( const QString& rev,
|
||||
}
|
||||
else
|
||||
emit revisionLoaded( pr );
|
||||
|
||||
checkRevisionQueue();
|
||||
}
|
||||
|
||||
|
||||
@@ -569,3 +576,17 @@ Playlist::setBusy( bool b )
|
||||
m_busy = b;
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void
|
||||
Playlist::checkRevisionQueue()
|
||||
{
|
||||
if ( !m_revisionQueue.isEmpty() )
|
||||
{
|
||||
RevisionQueueItem 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();
|
||||
}
|
||||
createNewRevision( item.newRev, item.oldRev, item.entries );
|
||||
}
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include "playlistinterface.h"
|
||||
|
||||
#include "dllmacro.h"
|
||||
#include <QQueue>
|
||||
|
||||
class DatabaseCommand_LoadAllPlaylists;
|
||||
class DatabaseCommand_SetPlaylistRevision;
|
||||
@@ -98,6 +99,17 @@ struct PlaylistRevision
|
||||
bool applied; // false if conflict
|
||||
};
|
||||
|
||||
struct RevisionQueueItem
|
||||
{
|
||||
QString newRev;
|
||||
QString oldRev;
|
||||
QList< plentry_ptr > entries;
|
||||
bool applyToTip;
|
||||
|
||||
RevisionQueueItem( const QString& nRev, const QString& oRev, QList< plentry_ptr > e, bool latest ) :
|
||||
newRev( nRev ), oldRev( oRev), entries( e ), applyToTip( latest ) {}
|
||||
};
|
||||
|
||||
|
||||
class DLLEXPORT Playlist : public QObject, public PlaylistInterface
|
||||
{
|
||||
@@ -264,6 +276,7 @@ private:
|
||||
void init();
|
||||
|
||||
void setBusy( bool b );
|
||||
void checkRevisionQueue();
|
||||
|
||||
source_ptr m_source;
|
||||
QString m_currentrevision;
|
||||
@@ -277,6 +290,8 @@ private:
|
||||
QList< plentry_ptr > m_initEntries;
|
||||
QList< plentry_ptr > m_entries;
|
||||
|
||||
QQueue<RevisionQueueItem> m_revisionQueue;
|
||||
|
||||
bool m_locallyChanged;
|
||||
bool m_busy;
|
||||
};
|
||||
|
Reference in New Issue
Block a user