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