diff browser_side/radiocol.py @ 300:4f221f34bdc7

browser_side (plugins radiocol, xep-0054): handle upload errors
author souliane <souliane@mailoo.org>
date Tue, 17 Dec 2013 19:37:47 +0100
parents 7a1dc69112b8
children 5943eaa6f422
line wrap: on
line diff
--- a/browser_side/radiocol.py	Tue Dec 24 02:00:30 2013 +0100
+++ b/browser_side/radiocol.py	Tue Dec 17 19:37:47 2013 +0100
@@ -81,6 +81,7 @@
         self.setEncoding(FormPanel.ENCODING_MULTIPART)
         self.setMethod(FormPanel.METHOD_POST)
         self.setAction("upload_radiocol")
+        self.timer_on = False
         self._parent = parent
         vPanel = VerticalPanel()
 
@@ -105,6 +106,8 @@
         self.addFormHandler(self)
 
     def updateStatus(self):
+        if self.timer_on:
+            return
         # TODO: the status should be different if a song is being played or not
         queue = self._parent.getQueueSize()
         queue_data = self._parent.queue_data
@@ -138,7 +141,13 @@
     def setTemporaryStatus(self, text, style):
         self.status.setText(text)
         self.status.setStyleName('radiocol_upload_status_%s' % style)
-        Timer(5000, self.updateStatus)
+        self.timer_on = True
+
+        def cb():
+            self.timer_on = False
+            self.updateStatus()
+
+        Timer(5000, cb)
 
     def onSubmitComplete(self, event):
         result = event.getResults()
@@ -147,6 +156,10 @@
             self.setTemporaryStatus('[Your song has been submitted to the radio]', "ok")
         elif result == "KO":
             self.setTemporaryStatus('[Something went wrong during your song upload]', "ko")
+            self._parent.radiocolSongRejected("Uploaded file is not Ogg Vorbis song, only Ogg Vorbis songs are acceptable")
+            # TODO: would be great to re-use the original Exception class and message
+            # but it is lost in the middle of the traceback and encapsulated within
+            # a DBusException instance --> extract the data from the traceback?
         else:
             Window.alert('Submit error: %s' % result)
             self.status.setText('')