From 98c9ddf2b1dc0e4e963d7ca88ccf179b73ef2997 Mon Sep 17 00:00:00 2001
From: Leo Franchi <lfranchi@kde.org>
Date: Tue, 17 May 2011 16:00:11 +0200
Subject: [PATCH] Add a timeout after last edit in artist line edits

---
 .../playlist/dynamic/echonest/EchonestControl.cpp         | 8 +++++++-
 .../playlist/dynamic/echonest/EchonestControl.h           | 1 +
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp
index 7a4c3fb47..d742f9899 100644
--- a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp
+++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp
@@ -33,8 +33,12 @@ Tomahawk::EchonestControl::EchonestControl( const QString& selectedType, const Q
     setType( "echonest" );
     m_editingTimer.setInterval( 500 ); //timeout to edits
     m_editingTimer.setSingleShot( true );
-    
     connect( &m_editingTimer, SIGNAL( timeout() ), this, SLOT( editTimerFired() ) );
+    
+    m_delayedEditTimer.setInterval( 250 ); // additional timer for "just typing" without enter or focus change
+    m_delayedEditTimer.setSingleShot( true );
+    connect( &m_delayedEditTimer, SIGNAL( timeout() ), &m_editingTimer, SLOT( start() ) );
+
     updateWidgets();
 }
 
@@ -149,6 +153,7 @@ Tomahawk::EchonestControl::updateWidgets()
         connect( input, SIGNAL( textChanged(QString) ), this, SLOT( updateData() ) );
         connect( input, SIGNAL( editingFinished() ), this, SLOT( editingFinished() ) );
         connect( input, SIGNAL( textEdited( QString ) ), &m_editingTimer, SLOT( stop() ) );
+        connect( input, SIGNAL( textEdited( QString ) ), &m_delayedEditTimer, SLOT( start() ) );
         
         match->hide();
         input->hide();
@@ -166,6 +171,7 @@ Tomahawk::EchonestControl::updateWidgets()
         connect( input, SIGNAL( textChanged(QString) ), this, SLOT( updateData() ) );
         connect( input, SIGNAL( editingFinished() ), this, SLOT( editingFinished() ) );
         connect( input, SIGNAL( textEdited( QString ) ), &m_editingTimer, SLOT( stop() ) );
+        connect( input, SIGNAL( textEdited( QString ) ), &m_delayedEditTimer, SLOT( start() ) );
         
         match->hide();
         input->hide();
diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.h b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.h
index 405bed0c5..897af0ad8 100644
--- a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.h
+++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.h
@@ -80,6 +80,7 @@ private:
     QString m_summary;
     
     QTimer m_editingTimer;
+    QTimer m_delayedEditTimer;
     
     Echonest::DynamicPlaylist::PlaylistParamData m_data;
     QVariant m_cacheData;