mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-25 02:09:48 +01:00
* Fixed playlist issues which caused dupe playlist_items.
This commit is contained in:
parent
f32c1f1338
commit
9ec9fb9362
@ -26,6 +26,8 @@
|
||||
#include "network/servent.h"
|
||||
#include "utils/logger.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
|
||||
DatabaseCommand_SetPlaylistRevision::DatabaseCommand_SetPlaylistRevision(
|
||||
const source_ptr& s,
|
||||
@ -90,8 +92,6 @@ DatabaseCommand_SetPlaylistRevision::postCommitHook()
|
||||
void
|
||||
DatabaseCommand_SetPlaylistRevision::exec( DatabaseImpl* lib )
|
||||
{
|
||||
using namespace Tomahawk;
|
||||
|
||||
// get the current revision for this playlist
|
||||
// this also serves to check the playlist exists.
|
||||
TomahawkSqlQuery chkq = lib->newquery();
|
||||
@ -100,7 +100,7 @@ DatabaseCommand_SetPlaylistRevision::exec( DatabaseImpl* lib )
|
||||
if( chkq.exec() && chkq.next() )
|
||||
{
|
||||
m_currentRevision = chkq.value( 0 ).toString();
|
||||
qDebug() << Q_FUNC_INFO << "pl guid" << m_playlistguid << " curr rev" << m_currentRevision;
|
||||
qDebug() << Q_FUNC_INFO << "pl guid" << m_playlistguid << "- curr rev" << m_currentRevision;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -181,7 +181,7 @@ DatabaseCommand_SetPlaylistRevision::exec( DatabaseImpl* lib )
|
||||
// if optimistic locking is ok, update current revision to this new one
|
||||
if ( m_currentRevision == m_oldrev )
|
||||
{
|
||||
qDebug() << "updating current revision, optimistic locking ok";
|
||||
qDebug() << "Updating current revision, optimistic locking ok";
|
||||
|
||||
TomahawkSqlQuery query2 = lib->newquery();
|
||||
query2.prepare( "UPDATE playlist SET currentrevision = ? WHERE guid = ?" );
|
||||
@ -199,12 +199,11 @@ DatabaseCommand_SetPlaylistRevision::exec( DatabaseImpl* lib )
|
||||
"WHERE guid = :guid" );
|
||||
query_entries.bindValue( ":guid", m_oldrev );
|
||||
query_entries.exec();
|
||||
if( query_entries.next() )
|
||||
if ( query_entries.next() )
|
||||
{
|
||||
// entries should be a list of strings:
|
||||
bool ok;
|
||||
QJson::Parser parser;
|
||||
QVariant v = parser.parse( query_entries.value(0).toByteArray(), &ok );
|
||||
QVariant v = parser.parse( query_entries.value( 0 ).toByteArray(), &ok );
|
||||
Q_ASSERT( ok && v.type() == QVariant::List ); //TODO
|
||||
|
||||
m_previous_rev_orderedguids = v.toStringList();
|
||||
|
@ -41,6 +41,7 @@ using namespace Tomahawk;
|
||||
PlaylistEntry::PlaylistEntry() {}
|
||||
PlaylistEntry::~PlaylistEntry() {}
|
||||
|
||||
|
||||
void
|
||||
PlaylistEntry::setQueryVariant( const QVariant& v )
|
||||
{
|
||||
@ -92,7 +93,6 @@ Playlist::Playlist( const source_ptr& author )
|
||||
: m_source( author )
|
||||
, m_lastmodified( 0 )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "JSON";
|
||||
}
|
||||
|
||||
|
||||
@ -116,10 +116,7 @@ Playlist::Playlist( const source_ptr& src,
|
||||
, m_lastmodified( lastmod )
|
||||
, m_createdOn( createdOn )
|
||||
, m_shared( shared )
|
||||
, m_currentItem( 0 )
|
||||
, m_busy( false )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "1" << title;
|
||||
init();
|
||||
}
|
||||
|
||||
@ -140,11 +137,8 @@ Playlist::Playlist( const source_ptr& author,
|
||||
, m_lastmodified( 0 )
|
||||
, m_createdOn( 0 ) // will be set by db command
|
||||
, m_shared( shared )
|
||||
, m_currentItem ( 0 )
|
||||
, m_initEntries( entries )
|
||||
, m_busy( false )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "2" << title;
|
||||
init();
|
||||
}
|
||||
|
||||
@ -152,8 +146,9 @@ Playlist::Playlist( const source_ptr& author,
|
||||
void
|
||||
Playlist::init()
|
||||
{
|
||||
m_locallyChanged = false;
|
||||
connect( Pipeline::instance(), SIGNAL( idle() ), SLOT( onResolvingFinished() ) );
|
||||
m_busy = false;
|
||||
m_locallyChanged = false;
|
||||
connect( Pipeline::instance(), SIGNAL( idle() ), SLOT( onResolvingFinished() ) );
|
||||
}
|
||||
|
||||
|
||||
@ -185,7 +180,6 @@ Playlist::create( const source_ptr& author,
|
||||
playlist_ptr playlist( new Playlist( author, guid, title, info, creator, shared, entries ) );
|
||||
|
||||
// save to DB in the background
|
||||
// Hope this doesn't cause any problems..
|
||||
// Watch for the created() signal if you need to be sure it's written.
|
||||
//
|
||||
// When a playlist is created it will reportCreated(), adding it to the
|
||||
@ -221,7 +215,7 @@ Playlist::load( const QString& guid )
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
void
|
||||
Playlist::remove( const playlist_ptr& playlist )
|
||||
{
|
||||
playlist->aboutToBeDeleted( playlist );
|
||||
@ -231,18 +225,14 @@ Playlist::remove( const playlist_ptr& playlist )
|
||||
|
||||
DatabaseCommand_DeletePlaylist* cmd = new DatabaseCommand_DeletePlaylist( playlist->author(), playlist->guid() );
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
||||
|
||||
return true; // FIXME
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
void
|
||||
Playlist::rename( const QString& title )
|
||||
{
|
||||
DatabaseCommand_RenamePlaylist* cmd = new DatabaseCommand_RenamePlaylist( author(), guid(), title );
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
||||
|
||||
return true; // FIXME
|
||||
}
|
||||
|
||||
|
||||
@ -586,8 +576,9 @@ Playlist::checkRevisionQueue()
|
||||
{
|
||||
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
|
||||
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
|
||||
if ( item.oldRev == item.newRev )
|
||||
{
|
||||
checkRevisionQueue();
|
||||
|
@ -142,8 +142,8 @@ public:
|
||||
bool shared,
|
||||
const QList<Tomahawk::query_ptr>& queries = QList<Tomahawk::query_ptr>() );
|
||||
|
||||
static bool remove( const playlist_ptr& playlist );
|
||||
bool rename( const QString& title );
|
||||
static void remove( const playlist_ptr& playlist );
|
||||
void rename( const QString& title );
|
||||
|
||||
virtual void loadRevision( const QString& rev = "" );
|
||||
|
||||
|
@ -331,8 +331,10 @@ PlaylistModel::onDataChanged()
|
||||
void
|
||||
PlaylistModel::onRevisionLoaded( Tomahawk::PlaylistRevision revision )
|
||||
{
|
||||
if ( m_playlist->author() != SourceList::instance()->getLocal() )
|
||||
if ( !m_waitForRevision.contains( revision.revisionguid ) )
|
||||
loadPlaylist( m_playlist );
|
||||
else
|
||||
m_waitForRevision.removeAll( revision.revisionguid );
|
||||
}
|
||||
|
||||
|
||||
@ -432,25 +434,20 @@ PlaylistModel::parsedDroppedTracks( QList< query_ptr > tracks )
|
||||
void
|
||||
PlaylistModel::onPlaylistChanged()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
if ( m_playlist.isNull() )
|
||||
return;
|
||||
|
||||
QList<plentry_ptr> l = playlistEntries();
|
||||
foreach( const plentry_ptr& ple, l )
|
||||
{
|
||||
qDebug() << "updateinternal:" << ple->query()->toString();
|
||||
}
|
||||
|
||||
QString newrev = uuid();
|
||||
if( dynplaylist_ptr dynplaylist = m_playlist.dynamicCast<Tomahawk::DynamicPlaylist>() )
|
||||
m_waitForRevision << newrev;
|
||||
|
||||
if ( dynplaylist_ptr dynplaylist = m_playlist.dynamicCast<Tomahawk::DynamicPlaylist>() )
|
||||
{
|
||||
if( dynplaylist->mode() == OnDemand )
|
||||
if ( dynplaylist->mode() == OnDemand )
|
||||
{
|
||||
dynplaylist->createNewRevision( newrev );
|
||||
}
|
||||
else if( dynplaylist->mode() == Static )
|
||||
else if ( dynplaylist->mode() == Static )
|
||||
{
|
||||
dynplaylist->createNewRevision( newrev, dynplaylist->currentrevision(), dynplaylist->type(), dynplaylist->generator()->controls(), l );
|
||||
}
|
||||
|
@ -99,6 +99,7 @@ private:
|
||||
Tomahawk::playlist_ptr m_playlist;
|
||||
bool m_isTemporary;
|
||||
QList< Tomahawk::Query* > m_waitingForResolved;
|
||||
QStringList m_waitForRevision;
|
||||
|
||||
DropStorageData m_dropStorage;
|
||||
};
|
||||
|
@ -196,12 +196,13 @@ PlaylistItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
|
||||
else
|
||||
dj->tracksFromMimeData( data, false, false );
|
||||
|
||||
// TODO cant' know if it works or not yet...
|
||||
// TODO can't know if it works or not yet...
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistItem::parsedDroppedTracks( const QList< query_ptr >& tracks)
|
||||
PlaylistItem::parsedDroppedTracks( const QList< query_ptr >& tracks )
|
||||
{
|
||||
qDebug() << "adding" << tracks.count() << "tracks";
|
||||
if ( tracks.count() && !m_playlist.isNull() && m_playlist->author()->isLocal() )
|
||||
|
Loading…
x
Reference in New Issue
Block a user