changeset 130:6576c5a90060

Working Radio Collective \o/
author Goffi <goffi@goffi.org>
date Sun, 29 Jan 2012 02:56:21 +0100
parents dd0d39ae7d24
children ddfcc4cb6cee
files browser_side/radiocol.py libervia.py libervia.tac public/libervia.css
diffstat 4 files changed, 75 insertions(+), 16 deletions(-) [+]
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)
+
--- a/libervia.py	Sun Jan 29 00:15:04 2012 +0100
+++ b/libervia.py	Sun Jan 29 02:56:21 2012 +0100
@@ -245,6 +245,14 @@
             self._radioColStartedCb(*args)
         elif name == 'radiocolPreload':
             self._radioColGenericCb(name, args[0], args[1:])
+        elif name == 'radiocolPlay':
+            self._radioColGenericCb(name, args[0], args[1:])
+        elif name == 'radiocolNoUpload':
+            self._radioColGenericCb(name, args[0], args[1:])
+        elif name == 'radiocolUploadOk':
+            self._radioColGenericCb(name, args[0], args[1:])
+        elif name == 'radiocolSongRejected':
+            self._radioColGenericCb(name, args[0], args[1:])
         elif name == 'subscribe':
             self._subscribeCb(*args)
         elif name == 'contactDeleted':
--- a/libervia.tac	Sun Jan 29 00:15:04 2012 +0100
+++ b/libervia.tac	Sun Jan 29 02:56:21 2012 +0100
@@ -508,7 +508,7 @@
                 del self.sat_host.signal_handler.queue[profile]
             except KeyError:
                 pass
-            #and now we deconnect the profile
+            #and now we disconnect the profile
             self.sat_host.bridge.disconnect(profile) 
        
         _session.notifyOnExpire(onExpire)
@@ -675,7 +675,7 @@
         #plugins
         for signal_name in ['personalEvent', 'roomJoined', 'roomUserJoined', 'roomUserLeft', 'tarotGameStarted', 'tarotGameNew', 'tarotGameChooseContrat',
                             'tarotGameShowCards', 'tarotGameInvalidCards', 'tarotGameCardsPlayed', 'tarotGameYourTurn', 'tarotGameScore', 
-                            'radiocolStarted', 'radiocolPreload']:
+                            'radiocolStarted', 'radiocolPreload', 'radiocolPlay', 'radiocolNoUpload', 'radiocolUploadOk', 'radiocolSongRejected']:
             self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name), "plugin")
         self.media_dir = self.bridge.getConfig('','media_dir')
         self.local_dir = self.bridge.getConfig('','local_dir')
--- a/public/libervia.css	Sun Jan 29 00:15:04 2012 +0100
+++ b/public/libervia.css	Sun Jan 29 02:56:21 2012 +0100
@@ -869,6 +869,20 @@
     font-style:italic;
 }
 
+.radiocol_upload_status_ok {
+    margin-left: 10px;
+    margin-right: 10px;
+    font-weight: bold;
+	color: #28F215;
+}
+
+.radiocol_upload_status_ko {
+    margin-left: 10px;
+    margin-right: 10px;
+    font-weight: bold;
+	color: #B80000;
+}
+
 /* Drag and drop */
 
 .dragover {