From af0fe52cd1cdd559b269a2a04fb357c6cdcb6de9 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Wed, 25 May 2011 17:25:20 -0400 Subject: [PATCH] Don't rely on mood/style fetch being faster than dynamic control loading --- .../dynamic/echonest/EchonestControl.cpp | 39 +++++++++++++++++-- .../dynamic/echonest/EchonestControl.h | 4 +- .../dynamic/echonest/EchonestGenerator.cpp | 1 + 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp index 4d66f45f3..c71c76388 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp @@ -354,10 +354,6 @@ Tomahawk::EchonestControl::updateWidgets() QLabel* match = new QLabel( tr( "is" ) ); QComboBox* combo = new QComboBox; - QVector< QString > src = selectedType() == "Mood" ? EchonestGenerator::moods() : EchonestGenerator::styles(); - foreach( const QString& item, src ) { - combo->addItem( item, item ); - } m_matchString = match->text(); m_matchData = match->text(); @@ -370,6 +366,8 @@ Tomahawk::EchonestControl::updateWidgets() combo->hide(); m_match = QWeakPointer< QWidget >( match ); m_input = QWeakPointer< QWidget >( combo ); + + insertMoodsAndStyles(); } else { m_match = QWeakPointer( new QWidget ); m_input = QWeakPointer( new QWidget ); @@ -697,3 +695,36 @@ Tomahawk::EchonestControl::calculateSummary() } m_summary = summary; } + +void +Tomahawk::EchonestControl::checkForMoodsOrStylesFetched() +{ + if( selectedType() == "Mood" || selectedType() == "Style" ) { + QComboBox* cb = qobject_cast< QComboBox* >( m_input.data() ); + if( cb && cb->count() == 0 ) { // got nothing, so lets populate + if( insertMoodsAndStyles() ) + updateWidgetsFromData(); + } + } +} + +bool +Tomahawk::EchonestControl::insertMoodsAndStyles() +{ + QVector< QString > src = selectedType() == "Mood" ? EchonestGenerator::moods() : EchonestGenerator::styles(); + QComboBox* combo = qobject_cast< QComboBox* >( m_input.data() ); + 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() ) { + QTimer::singleShot( 400, this, SLOT( checkForMoodsOrStylesFetched() ) ); + return false; + } + + return true; +} diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.h b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.h index d1e8159cc..df51df523 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.h +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.h @@ -50,6 +50,7 @@ public: public slots: virtual void setSelectedType ( const QString& type ); + private slots: void updateData(); void editingFinished(); @@ -58,7 +59,7 @@ private slots: void artistTextEdited( const QString& ); void suggestFinished(); - + void checkForMoodsOrStylesFetched(); private: void updateWidgets(); void updateWidgetsFromData(); @@ -67,6 +68,7 @@ private: void setupMinMaxWidgets( Echonest::DynamicPlaylist::PlaylistParam min, Echonest::DynamicPlaylist::PlaylistParam max, const QString& leftL, const QString& rightL, int maxRange ); void updateFromComboAndSlider( bool smooth = false ); void updateFromLabelAndCombo(); + bool insertMoodsAndStyles(); void updateToComboAndSlider( bool smooth = false ); void updateToLabelAndCombo(); diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp index ee55ae3a0..d88c37465 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp @@ -66,6 +66,7 @@ EchonestGenerator::EchonestGenerator ( QObject* parent ) QNetworkReply* moods = Echonest::Artist::listTerms( "mood" ); connect( moods, SIGNAL( finished() ), this, SLOT( moodsReceived() ) ); + QTimer::singleShot( 20000, this, SLOT( get() ) ); // qDebug() << "ECHONEST:" << m_logo.size(); }