From f27d3b9fe95588aaf25f9de8b467e81a799416fb Mon Sep 17 00:00:00 2001
From: Leo Franchi <lfranchi@kde.org>
Date: Wed, 25 May 2011 21:37:20 -0400
Subject: [PATCH] fix debug/poll and give new stations a better name from a
 seed

---
 .../playlist/dynamic/echonest/EchonestControl.cpp         | 8 ++++++--
 .../playlist/dynamic/echonest/EchonestControl.h           | 1 +
 src/sourcetree/items/categoryitems.cpp                    | 3 ++-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp
index c71c76388..f6ca4dc37 100644
--- a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp
+++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp
@@ -33,6 +33,7 @@ QHash< QString, QStringList > Tomahawk::EchonestControl::s_suggestCache = QHash<
 
 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
@@ -721,8 +722,11 @@ Tomahawk::EchonestControl::insertMoodsAndStyles()
         combo->addItem( item, item );
     }
 
-    if( src.isEmpty() ) {
-        QTimer::singleShot( 400, this, SLOT( checkForMoodsOrStylesFetched() ) );
+    if( src.isEmpty() && !combo->count() ) {
+        if( m_stylePollCount <= 20 ) { // try for 20s to get the styles...
+            QTimer::singleShot( 1000, this, SLOT( checkForMoodsOrStylesFetched() ) );
+        }
+        m_stylePollCount++;
         return false;
     }
 
diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.h b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.h
index df51df523..43e848f94 100644
--- a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.h
+++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.h
@@ -91,6 +91,7 @@ private:
 
     Echonest::DynamicPlaylist::PlaylistParamData m_data;
     QVariant m_cacheData;
+    int m_stylePollCount;
 
     QSet< QNetworkReply* > m_suggestWorkers;
     static QHash< QString, QStringList > s_suggestCache;
diff --git a/src/sourcetree/items/categoryitems.cpp b/src/sourcetree/items/categoryitems.cpp
index 0e1c7ec1c..a66e54719 100644
--- a/src/sourcetree/items/categoryitems.cpp
+++ b/src/sourcetree/items/categoryitems.cpp
@@ -133,7 +133,8 @@ CategoryAddItem::dropMimeData( const QMimeData* data, Qt::DropAction )
             QTimer::singleShot( 300, APP->mainWindow()->sourceTreeView(), SLOT( renamePlaylist() ) );
         } else if( m_categoryType == SourcesModel::StationsCategory ) {
             // seed the playlist with these song filters
-            dynplaylist_ptr newpl = DynamicPlaylist::create( SourceList::instance()->getLocal(), uuid(), "New Station", "", SourceList::instance()->getLocal()->friendlyName(), OnDemand, false );
+            QString name = queries.isEmpty() ? tr( "New Station" ) : tr( "%1 Station" ).arg( queries.first()->track() );
+            dynplaylist_ptr newpl = DynamicPlaylist::create( SourceList::instance()->getLocal(), uuid(), name, "", SourceList::instance()->getLocal()->friendlyName(), OnDemand, false );
             newpl->setMode( OnDemand );
 
             // now we want to add each query as a song filter...