Commits

Damián Nohales  committed 7293527

Change window title when Grooveshark is initializing and Groveshark initialize when user start to type in the search box.

  • Participants
  • Parent commits 914c033

Comments (0)

Files changed (4)

File data/main_window.ui

                     <property name="secondary_icon_activatable">False</property>
                     <property name="primary_icon_sensitive">True</property>
                     <property name="secondary_icon_sensitive">True</property>
+                    <signal name="changed" handler="on_search_text_changed" swapped="no"/>
                     <signal name="activate" handler="on_search_grooveshark" swapped="no"/>
                   </object>
                 </child>

File lib/SharkDown.py

 from tfuncs import KeyListenerThread
 from tfuncs import LyricsThread
 from tfuncs import UpdateThread
+from tfuncs import GroovesharkInitThread
 from SearchResultList import SearchResultList
 from PlayList import PlayList
 from DownloadList import DownloadList
         self.on_playlist_row_changed(self.playlist.get_model())
         self.on_playlist_view_selection_changed(self.playlist.get_view())
         self.set_playing_song(None)
-        groove.onInitError(self.on_init_thread_failed)
-
-    def on_init_thread_failed(self, error):
+        groove.onInitStart(self.on_groove_init_start)
+        groove.onInitFinish(self.on_groove_init_finish)
+        groove.onInitError(self.on_groove_init_error)
+    
+    def on_groove_init_start(self):
+        self.window.set_title(_("gSharkDown - Initializing Grooveshark..."))
+        
+    def on_groove_init_finish(self):
+        self.window.set_title(_("gSharkDown"))
+        
+    def on_groove_init_error(self, error):
         guihelpers.ErrorMessage(self.window,
             _(
 """GrooveShark service has probably changed or is not working!
             search_thread = SearchThread(self, widget.get_text(), "Songs")
             search_thread.start()
             self.on_show_playview(self.downloads_pane_label)
+            
+    def on_search_text_changed(self, widget, data = None):
+        t = GroovesharkInitThread()
+        t.start()
 
     def get_overwritten_filename(self, filename, use_response = None):
         """

File lib/groove.py

 
 if sys.version_info[1] >= 6:
     import json
+    
+def dummy(error = None):
+    pass
 
 _referer = "http://grooveshark.com/JSQueue.swf?20111111.111"
 _token = None
 _isInitialized = False
 _initializingLock = threading.Lock()
-_onInitError = None
+_onInitError = dummy
+_onInitStart = dummy
+_onInitFinish = dummy
 _initFailed = False
 
 h = {}
         return
     
     print "[Initializing Grooveshark]"
+    gobject.idle_add( _onInitStart )
     while True:
         try:
             conn = createCurl("http://grooveshark.com/")
             else:
                 print "[Grooveshark initialized failed]"
                 _initFailed = True
-                if _onInitError != None:
-                    gobject.idle_add(_onInitError, e.__str__())
+                gobject.idle_add(_onInitError, e.__str__())
                 break
     
     _isInitialized = True
     _initializingLock.release()
+    gobject.idle_add( _onInitFinish )
     
     if _initFailed == True:
         raise Exception(_("Grooveshark is not initialized"))
     global _onInitError
     _onInitError = callback
     
+def onInitStart(callback):
+    global _onInitStart
+    _onInitStart = callback
+    
+def onInitFinish(callback):
+    global _onInitFinish
+    _onInitFinish = callback
+    
 def isInitialized():
     return _isInitialized
 

File lib/tfuncs.py

 import gst
 import pycurl
 
+class GroovesharkInitThread(threading.Thread):
+    def run(self):
+        if groove.isInitialized() == False:
+            groove.init()
 
 class PlayThread(threading.Thread):