diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp index 43a0d1555..b33dbe272 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp @@ -30,10 +30,11 @@ #include QHash< QString, QStringList > Tomahawk::EchonestControl::s_suggestCache = QHash< QString, QStringList >(); +bool Tomahawk::EchonestControl::s_fetchingMoodsAndStyles = false; +int Tomahawk::EchonestControl::s_stylePollCount = 0; Tomahawk::EchonestControl::EchonestControl( const QString& selectedType, const QStringList& typeSelectors, QObject* parent ) : DynamicControl ( selectedType.isEmpty() ? "Artist" : selectedType, typeSelectors, parent ) - , m_stylePollCount( 0 ) { setType( "echonest" ); m_editingTimer.setInterval( 500 ); //timeout to edits @@ -705,6 +706,7 @@ Tomahawk::EchonestControl::calculateSummary() void Tomahawk::EchonestControl::checkForMoodsOrStylesFetched() { + s_fetchingMoodsAndStyles = false; if( selectedType() == "Mood" || selectedType() == "Style" ) { QComboBox* cb = qobject_cast< QComboBox* >( m_input.data() ); if( cb && cb->count() == 0 ) { // got nothing, so lets populate @@ -722,16 +724,16 @@ Tomahawk::EchonestControl::insertMoodsAndStyles() if( !combo ) return false; - qDebug() << "Inserting moods and or styles, here's the list" << src; foreach( const QString& item, src ) { combo->addItem( item, item ); } if( src.isEmpty() && !combo->count() ) { - if( m_stylePollCount <= 20 ) { // try for 20s to get the styles... + if( s_stylePollCount <= 20 && !s_fetchingMoodsAndStyles ) { // try for 20s to get the styles... + s_fetchingMoodsAndStyles = true; QTimer::singleShot( 1000, this, SLOT( checkForMoodsOrStylesFetched() ) ); } - m_stylePollCount++; + s_stylePollCount++; return false; } diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.h b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.h index 43e848f94..6544a8643 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.h +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.h @@ -91,7 +91,8 @@ private: Echonest::DynamicPlaylist::PlaylistParamData m_data; QVariant m_cacheData; - int m_stylePollCount; + static bool s_fetchingMoodsAndStyles; + static int s_stylePollCount; QSet< QNetworkReply* > m_suggestWorkers; static QHash< QString, QStringList > s_suggestCache; diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp index f4b8a5306..2feadd9ee 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp @@ -26,6 +26,8 @@ using namespace Tomahawk; QVector< QString > EchonestGenerator::s_moods = QVector< QString >(); QVector< QString > EchonestGenerator::s_styles = QVector< QString >(); +QNetworkReply* EchonestGenerator::s_moodsJob = 0; +QNetworkReply* EchonestGenerator::s_stylesJob = 0; EchonestFactory::EchonestFactory() {} @@ -59,12 +61,14 @@ EchonestGenerator::EchonestGenerator ( QObject* parent ) m_mode = OnDemand; m_logo.load( RESPATH "/images/echonest_logo.png" ); - // fetch style and moods - QNetworkReply* style = Echonest::Artist::listTerms( "style" ); - connect( style, SIGNAL( finished() ), this, SLOT( stylesReceived() ) ); - - QNetworkReply* moods = Echonest::Artist::listTerms( "mood" ); - connect( moods, SIGNAL( finished() ), this, SLOT( moodsReceived() ) ); + if( !s_stylesJob && s_styles.isEmpty() ) { + // fetch style and moods + s_stylesJob = Echonest::Artist::listTerms( "style" ); + connect( s_stylesJob, SIGNAL( finished() ), this, SLOT( stylesReceived() ) ); + } else if( !s_moodsJob && s_moods.isEmpty() ) { + s_moodsJob = Echonest::Artist::listTerms( "mood" ); + connect( s_moodsJob, SIGNAL( finished() ), this, SLOT( moodsReceived() ) ); + } // qDebug() << "ECHONEST:" << m_logo.size(); } @@ -530,6 +534,7 @@ EchonestGenerator::moodsReceived() } catch( Echonest::ParseError& e ) { qWarning() << "Echonest failed to parse moods list"; } + s_moodsJob = 0; } QVector< QString > @@ -549,4 +554,5 @@ EchonestGenerator::stylesReceived() } catch( Echonest::ParseError& e ) { qWarning() << "Echonest failed to parse styles list"; } + s_stylesJob = 0; } diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.h b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.h index 1af9fc12c..aac93b25b 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.h +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.h @@ -95,6 +95,8 @@ private: static QVector< QString > s_styles; static QVector< QString > s_moods; + static QNetworkReply* s_stylesJob; + static QNetworkReply* s_moodsJob; // used for the intermediary song id lookup QSet< QNetworkReply* > m_waiting;