diff browser_side/radiocol.py @ 130:6576c5a90060

Working Radio Collective \o/
author Goffi <goffi@goffi.org>
date Sun, 29 Jan 2012 02:56:21 +0100
parents dd0d39ae7d24
children ddfcc4cb6cee
line wrap: on
line diff
--- a/browser_side/radiocol.py	Sun Jan 29 00:15:04 2012 +0100
+++ b/browser_side/radiocol.py	Sun Jan 29 02:56:21 2012 +0100
@@ -87,13 +87,15 @@
 
         hPanel = HorizontalPanel()
         hPanel.setSpacing(5)
-        self.field = FileUpload()
-        self.field.setName("song")
-        hPanel.add(self.field)
+        self.file_upload = FileUpload()
+        self.file_upload.setName("song")
+        hPanel.add(self.file_upload)
 
-        hPanel.add(Button("Upload song", getattr(self, "onBtnClick")))
+        self.upload_btn = Button("Upload song", getattr(self, "onBtnClick"))
+        hPanel.add(self.upload_btn)
 
         self.status = Label()
+        hPanel.add(self.status)
 
         vPanel.add(hPanel)
         
@@ -113,14 +115,23 @@
     def onSubmit(self, event):
         pass
 
+    def blockUpload(self):
+        self.file_upload.setVisible(False)
+        self.upload_btn.setEnabled(False)
+
+    def unblockUpload(self):
+        self.file_upload.setVisible(True)
+        self.upload_btn.setEnabled(True)
+
+
     def onSubmitComplete(self, event):
         result = event.getResults()
         if result == "OK":
-            self.status.setText('Your song has been added to queue')
+            self.status.setText('[Your song has been added to queue]')
             self.status.setStyleName('radiocol_upload_status_ok')
             self._timer.schedule(5000)
         elif result == "KO":
-            self.status.setText('Something went wrong during your song upload')
+            self.status.setText('[Something went wrong during your song upload]')
             self.status.setStyleName('radiocol_upload_status_ko')
         else:
             Window.alert('Submit error: %s' % result)
@@ -183,21 +194,28 @@
         self.right_panel.add(self.control_panel)
         self.add(self.right_panel)
         #self.right_panel.setBorderWidth(1)
-        self.next_song_1 = Label()
-        self.next_song_1.setStyleName("radiocol_next_song")
-        self.next_song_2 = Label()
-        self.next_song_2.setStyleName("radiocol_next_song")
-        self.left_panel.add(self.next_song_1)
-        self.left_panel.add(self.next_song_2)
+        self.next_songs = []
         self.players = [Player("player_%d" % i, self.metadata_panel) for i in range(4)]
         self.current_player = None
         for player in self.players:
             self.right_panel.add(player)
         self.addClickListener(self)
+
+    def pushNextSong(self, title):
+        """Add a song to the left panel's next songs queue"""
+        next_song = Label(title)
+        next_song.setStyleName("radiocol_next_song")
+        self.next_songs.append(next_song)
+        self.left_panel.append(next_song)
+
+    def popNextSong(self):
+        """Remove the first song of next songs list
+        should be called when the song is played"""
+        #FIXME: should check that the song we remove is the one we play
+        next_song = self.next_songs.pop(0)
+        self.left_panel.remove(next_song)
     
     def radiocolPreload(self, filename, title, artist, album):
-        self.next_song_1.setText(self.next_song_2.getText())
-        self.next_song_2.setText(title)
         preloaded = False
         for player in self.players:
             if not player.filename or \
@@ -209,5 +227,24 @@
                 break
         if not preloaded:
             print("WARNING: Can't preload song, we are getting too many songs to preload, we shouldn't have more than 2 at once")
+        else:
+            self.pushNextSong(title)
+    
+    def radiocolPlay(self, filename):
+        for player in self.players:
+            if player.filename == filename:
+                player.play()
+                self.popNextSong()
+                self.current_player = player
+                return
+        print("WARNING: Song not found in queue, can't play it. This should not happen")
 
+    def radiocolNoUpload(self):
+        self.control_panel.blockUpload()
 
+    def radiocolUploadOk(self):
+        self.control_panel.unblockUpload()
+
+    def radiocolSongRejected(self, reason):
+        Window.alert("Song rejected: %s" % reason)
+