1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-08 23:26:40 +02:00

more fixes

This commit is contained in:
Leo Franchi
2012-03-28 18:23:41 -04:00
parent f414e92b74
commit 704c736046
6 changed files with 48 additions and 5 deletions

View File

@@ -185,7 +185,11 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
return; return;
SpotifyPlaylistUpdater* updater = m_updaters[ plid ]; SpotifyPlaylistUpdater* updater = m_updaters[ plid ];
Q_ASSERT( updater->sync() );
// If we're not syncing with this, the resolver is quite misinformed.
Q_ASSERT( updater && updater->sync() );
if ( !updater || !updater->sync() )
return;
const QVariantList tracksList = msg.value( "trackPositions" ).toList(); const QVariantList tracksList = msg.value( "trackPositions" ).toList();
const QString newRev = msg.value( "revid" ).toString(); const QString newRev = msg.value( "revid" ).toString();

View File

@@ -142,6 +142,12 @@ SpotifyPlaylistUpdater::sync() const
void void
SpotifyPlaylistUpdater::spotifyTracksAdded( const QVariantList& tracks, const QString& startPosId, const QString& newRev, const QString& oldRev ) SpotifyPlaylistUpdater::spotifyTracksAdded( const QVariantList& tracks, const QString& startPosId, const QString& newRev, const QString& oldRev )
{ {
if ( m_plRevisionBeforeSpotifyUpdate == playlist()->currentrevision() )
{
m_plRevisionBeforeSpotifyUpdate.clear();
return;
}
const QList< query_ptr > queries = variantToQueries( tracks ); const QList< query_ptr > queries = variantToQueries( tracks );
qDebug() << Q_FUNC_INFO << "inserting tracks in middle of tomahawk playlist, from spotify command!" << tracks << startPosId << newRev << oldRev; qDebug() << Q_FUNC_INFO << "inserting tracks in middle of tomahawk playlist, from spotify command!" << tracks << startPosId << newRev << oldRev;
@@ -164,7 +170,7 @@ SpotifyPlaylistUpdater::spotifyTracksAdded( const QVariantList& tracks, const QS
pos = entries.size(); pos = entries.size();
qDebug() << Q_FUNC_INFO << "inserting tracks at position:" << pos; qDebug() << Q_FUNC_INFO << "inserting tracks at position:" << pos;
m_plRevisionBeforeUpdate = playlist()->currentrevision(); m_plRevisionBeforeTomahawkUpdate = playlist()->currentrevision();
playlist()->insertEntries( queries, pos, playlist()->currentrevision() ); playlist()->insertEntries( queries, pos, playlist()->currentrevision() );
} }
@@ -173,6 +179,12 @@ SpotifyPlaylistUpdater::spotifyTracksAdded( const QVariantList& tracks, const QS
void void
SpotifyPlaylistUpdater::spotifyTracksRemoved( const QVariantList& trackIds, const QString& newRev, const QString& oldRev ) SpotifyPlaylistUpdater::spotifyTracksRemoved( const QVariantList& trackIds, const QString& newRev, const QString& oldRev )
{ {
if ( m_plRevisionBeforeSpotifyUpdate == playlist()->currentrevision() )
{
m_plRevisionBeforeSpotifyUpdate.clear();
return;
}
qDebug() << Q_FUNC_INFO << "remove tracks in middle of tomahawk playlist, from spotify command!" << trackIds << newRev << oldRev; qDebug() << Q_FUNC_INFO << "remove tracks in middle of tomahawk playlist, from spotify command!" << trackIds << newRev << oldRev;
// Uh oh, dont' want to get out of sync!! // Uh oh, dont' want to get out of sync!!
// Q_ASSERT( m_latestRev == oldRev ); // Q_ASSERT( m_latestRev == oldRev );
@@ -207,7 +219,7 @@ SpotifyPlaylistUpdater::spotifyTracksRemoved( const QVariantList& trackIds, cons
entries.removeAll( torm ); entries.removeAll( torm );
m_plRevisionBeforeUpdate = playlist()->currentrevision(); m_plRevisionBeforeTomahawkUpdate = playlist()->currentrevision();
const int sizeDiff = playlist()->entries().size() - entries.size(); const int sizeDiff = playlist()->entries().size() - entries.size();
qDebug() << "We were asked to delete:" << trackIds.size() << "tracks from the playlist, and we deleted:" << sizeDiff; qDebug() << "We were asked to delete:" << trackIds.size() << "tracks from the playlist, and we deleted:" << sizeDiff;
@@ -229,9 +241,10 @@ SpotifyPlaylistUpdater::spotifyTracksMoved( const QVariantList& tracks, const QS
void void
SpotifyPlaylistUpdater::tomahawkTracksInserted( const QList< plentry_ptr >& tracks, int pos ) SpotifyPlaylistUpdater::tomahawkTracksInserted( const QList< plentry_ptr >& tracks, int pos )
{ {
if ( playlist()->currentrevision() == m_plRevisionBeforeUpdate ) if ( playlist()->currentrevision() == m_plRevisionBeforeTomahawkUpdate )
{ {
// We did the insert. Don't get in an infinite loop! // We did the insert. Don't get in an infinite loop!
m_plRevisionBeforeTomahawkUpdate.clear();
return; return;
} }
@@ -270,6 +283,7 @@ SpotifyPlaylistUpdater::tomahawkTracksInserted( const QList< plentry_ptr >& trac
} }
msg[ "tracks" ] = tracksJson; msg[ "tracks" ] = tracksJson;
m_plRevisionBeforeSpotifyUpdate = playlist()->currentrevision();
m_spotify->sendMessage( msg, this, "onTracksInsertedReturn" ); m_spotify->sendMessage( msg, this, "onTracksInsertedReturn" );
} }
@@ -287,6 +301,14 @@ SpotifyPlaylistUpdater::onTracksInsertedReturn( const QString& msgType, const QV
void void
SpotifyPlaylistUpdater::tomahawkTracksRemoved( const QList< query_ptr >& tracks ) SpotifyPlaylistUpdater::tomahawkTracksRemoved( const QList< query_ptr >& tracks )
{ {
if ( playlist()->currentrevision() == m_plRevisionBeforeTomahawkUpdate )
{
// We did the insert. Don't get in an infinite loop!
m_plRevisionBeforeTomahawkUpdate.clear();
return;
}
qDebug() << Q_FUNC_INFO << "updating spotify resolver with removed tracks:" << tracks; qDebug() << Q_FUNC_INFO << "updating spotify resolver with removed tracks:" << tracks;
QVariantMap msg; QVariantMap msg;
msg[ "_msgtype" ] = "removeTracksFromPlaylist"; msg[ "_msgtype" ] = "removeTracksFromPlaylist";
@@ -294,6 +316,7 @@ SpotifyPlaylistUpdater::tomahawkTracksRemoved( const QList< query_ptr >& tracks
msg[ "oldrev" ] = m_latestRev; msg[ "oldrev" ] = m_latestRev;
msg[ "tracks" ] = queriesToVariant( tracks ); msg[ "tracks" ] = queriesToVariant( tracks );
m_plRevisionBeforeSpotifyUpdate = playlist()->currentrevision();
m_spotify->sendMessage( msg, this, "onTracksRemovedReturn" ); m_spotify->sendMessage( msg, this, "onTracksRemovedReturn" );
} }

View File

@@ -75,7 +75,7 @@ private:
Tomahawk::Accounts::SpotifyAccount* m_spotify; Tomahawk::Accounts::SpotifyAccount* m_spotify;
QString m_latestRev, m_spotifyId; QString m_latestRev, m_spotifyId;
QString m_plRevisionBeforeUpdate; QString m_plRevisionBeforeTomahawkUpdate, m_plRevisionBeforeSpotifyUpdate;
bool m_sync; bool m_sync;
}; };

View File

@@ -134,6 +134,18 @@ DatabaseCommand_SetPlaylistRevision::exec( DatabaseImpl* lib )
} }
else else
{ {
// DEBUG only
qDebug() << "Current entries in the playlist_item table for this playlist:" << m_playlistguid;
TomahawkSqlQuery q = lib->newquery();
q.prepare( "SELECT guid, playlist, trackname, artistname, annotation FROM playlist_item WHERE playlist = ?" );
q.addBindValue( m_playlistguid );
if ( q.exec() )
{
while ( q.next() )
{
qDebug() << "====" << q.value( 0 ).toString() << q.value( 1 ).toString() << q.value( 2 ).toString() << q.value( 3 ).toString() << q.value( 4 ).toString() << "====";
}
}
QString sql = "INSERT INTO playlist_item( guid, playlist, trackname, artistname, albumname, " QString sql = "INSERT INTO playlist_item( guid, playlist, trackname, artistname, albumname, "
"annotation, duration, addedon, addedby, result_hint ) " "annotation, duration, addedon, addedby, result_hint ) "
"VALUES( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"; "VALUES( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
@@ -142,6 +154,8 @@ DatabaseCommand_SetPlaylistRevision::exec( DatabaseImpl* lib )
qDebug() << "Num new playlist_items to add:" << m_addedentries.length(); qDebug() << "Num new playlist_items to add:" << m_addedentries.length();
foreach( const plentry_ptr& e, m_addedentries ) foreach( const plentry_ptr& e, m_addedentries )
{ {
qDebug() << "Adding:" << e->guid() << e->query()->track() << e->query()->artist();
m_addedmap.insert( e->guid(), e ); // needed in postcommithook m_addedmap.insert( e->guid(), e ); // needed in postcommithook
QString resultHint; QString resultHint;

View File

@@ -2,6 +2,7 @@
* *
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org> * Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by