From 0c4db907b326fc4ebfed58e3f00479a055d6ed72 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Tue, 31 Jul 2012 17:48:41 -0400 Subject: [PATCH] UI tweaks for synchronizing last.fm loved tracks --- src/libtomahawk/accounts/lastfm/LastFmConfig.cpp | 13 +++++++++++-- src/libtomahawk/accounts/lastfm/LastFmConfig.h | 2 +- .../database/DatabaseCommand_LoadSocialActions.h | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/libtomahawk/accounts/lastfm/LastFmConfig.cpp b/src/libtomahawk/accounts/lastfm/LastFmConfig.cpp index f6151d2c4..efc2ea1f5 100644 --- a/src/libtomahawk/accounts/lastfm/LastFmConfig.cpp +++ b/src/libtomahawk/accounts/lastfm/LastFmConfig.cpp @@ -43,6 +43,7 @@ LastFmConfig::LastFmConfig( LastFmAccount* account ) , m_lastTimeStamp( 0 ) , m_totalLovedPages( -1 ) , m_doneFetchingLoved( false ) + , m_doneFetchingLocal( false ) { m_ui = new Ui_LastFmConfig; m_ui->setupUi( this ); @@ -252,6 +253,8 @@ LastFmConfig::syncLovedTracks( uint page ) { QNetworkReply* reply = lastfm::User( username() ).getLovedTracks( 200, page ); + m_ui->syncLovedTracks->setEnabled( false ); + m_ui->syncLovedTracks->setText( tr( "Synchronizing..." ) ); m_ui->progressBar->show(); NewClosure( reply, SIGNAL( finished() ), this, SLOT( onLovedFinished( QNetworkReply* ) ), reply ); @@ -283,7 +286,7 @@ LastFmConfig::onLovedFinished( QNetworkReply* reply ) if ( m_totalLovedPages < 0 ) { m_totalLovedPages = loved.attribute( "totalPages" ).toInt(); - m_ui->progressBar->setMaximum( m_totalLovedPages ); + m_ui->progressBar->setMaximum( m_totalLovedPages + 2 ); } m_ui->progressBar->setValue( thisPage ); @@ -302,7 +305,7 @@ LastFmConfig::onLovedFinished( QNetworkReply* reply ) { m_doneFetchingLoved = true; - if ( !m_localLoved.isEmpty() ) + if ( m_doneFetchingLocal ) syncLoved(); return; @@ -330,6 +333,7 @@ void LastFmConfig::localLovedLoaded( DatabaseCommand_LoadSocialActions::TrackActions tracks ) { m_localLoved = tracks; + m_doneFetchingLocal = true; if ( m_doneFetchingLoved ) syncLoved(); @@ -343,6 +347,8 @@ LastFmConfig::syncLoved() const QSet< Tomahawk::query_ptr > myLoved = m_localLoved.keys().toSet(); + m_ui->progressBar->setValue( m_ui->progressBar->value() + 1 ); + foreach ( const Tomahawk::query_ptr& lastfmLoved, m_lastfmLoved ) { QSet< Tomahawk::query_ptr >::const_iterator iter = std::find_if( myLoved.begin(), myLoved.end(), boost::bind( &trackEquality, _1, boost::ref( lastfmLoved ) ) ); @@ -389,5 +395,8 @@ LastFmConfig::syncLoved() else lfmTrack.love(); } + + m_ui->progressBar->setValue( m_ui->progressBar->value() + 1 ); + m_ui->syncLovedTracks->setText( tr( "Synchronization Finished" ) ); } diff --git a/src/libtomahawk/accounts/lastfm/LastFmConfig.h b/src/libtomahawk/accounts/lastfm/LastFmConfig.h index 704eb58ad..b443b85a5 100644 --- a/src/libtomahawk/accounts/lastfm/LastFmConfig.h +++ b/src/libtomahawk/accounts/lastfm/LastFmConfig.h @@ -72,7 +72,7 @@ private: unsigned int m_lastTimeStamp; int m_totalLovedPages; - bool m_doneFetchingLoved; + bool m_doneFetchingLoved, m_doneFetchingLocal; QSet< Tomahawk::query_ptr > m_lastfmLoved; DatabaseCommand_LoadSocialActions::TrackActions m_localLoved; }; diff --git a/src/libtomahawk/database/DatabaseCommand_LoadSocialActions.h b/src/libtomahawk/database/DatabaseCommand_LoadSocialActions.h index 2eca2c3a8..fdc987bd5 100644 --- a/src/libtomahawk/database/DatabaseCommand_LoadSocialActions.h +++ b/src/libtomahawk/database/DatabaseCommand_LoadSocialActions.h @@ -126,6 +126,7 @@ public: */ void setTrack( const QString& s ) { m_track = s; } + virtual bool doesMutates() const { return false; } signals: /** * All loaded social actions for each track found, for queries that generate all tracks