1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-21 00:09:47 +01:00

Don't rely on mood/style fetch being faster than dynamic control loading

This commit is contained in:
Leo Franchi 2011-05-25 17:25:20 -04:00
parent c59747e1e1
commit af0fe52cd1
3 changed files with 39 additions and 5 deletions

View File

@ -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<QWidget>( new QWidget );
m_input = QWeakPointer<QWidget>( 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;
}

View File

@ -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();

View File

@ -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();
}