Ticket #3709: 0001-Avoid-error-if-the-media-referenced-in-a-playlist-is.patch

File 0001-Avoid-error-if-the-media-referenced-in-a-playlist-is.patch, 4.2 KB (added by godiard, 12 years ago)
  • jukeboxactivity.py

    From 0d46b41a5c5456387d98316c8efc66f276bc9ca2 Mon Sep 17 00:00:00 2001
    From: Gonzalo Odiard <godiard@gmail.com>
    Date: Thu, 21 Jun 2012 17:40:09 -0300
    Subject: [PATCH] Avoid error if the media referenced in a playlist is not
     available
    
    If the user try play a non existent media, show a alert.
    
    Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
    ---
     jukeboxactivity.py |   55 ++++++++++++++++++++++++++++++++++++++++------------
     1 file changed, 43 insertions(+), 12 deletions(-)
    
    diff --git a/jukeboxactivity.py b/jukeboxactivity.py
    index a16fbd1..a957e19 100644
    a b from sugar.activity import activity 
    3131from sugar.graphics.objectchooser import ObjectChooser
    3232from sugar import mime
    3333from sugar.datastore import datastore
     34from sugar.graphics.alert import ErrorAlert
    3435
    3536OLD_TOOLBAR = False
    3637try:
    class JukeboxActivity(activity.Activity): 
    155156
    156157        self.jobjectlist = []
    157158        self.playpath = None
    158         self.currentplaying = None
     159        self.currentplaying = 0
    159160        self.playflag = False
    160161        self.tags = {}
    161162        self.only_audio = False
    class JukeboxActivity(activity.Activity): 
    277278        self.player.connect("tag", self._player_new_tag_cb)
    278279        self.player.connect("stream-info", self._player_stream_info_cb)
    279280        url = self.playlist[self.currentplaying]['url']
     281        error = None
    280282        if url.startswith('journal://'):
    281             jobject = datastore.get(url[len("journal://"):])
    282             url = 'file://' + jobject.file_path
    283         self.player.set_uri(url)
    284 
    285         self.play_toggled()
     283            url = url[len("journal://"):]
     284            if os.path.exists(url):
     285                jobject = datastore.get(url)
     286                url = 'file://' + jobject.file_path
     287            else:
     288                error = _('The file %s was not found') % url
    286289
    287290        self.check_if_next_prev()
    288291        self.playlist_widget.set_cursor(self.currentplaying)
     292        if error is None:
     293            self.player.set_uri(url)
     294            self.play_toggled()
     295        else:
     296            self._show_error_alert(_('Error'), error)
     297
     298
     299    def _show_error_alert(self, title, text=None):
     300        alert = ErrorAlert()
     301        alert.props.title = title
     302        alert.props.msg = text
     303        self.add_alert(alert)
     304        alert.connect('response', self._alert_cancel_cb)
     305        alert.show()
     306
     307    def _alert_cancel_cb(self, alert, response_id):
     308        self.remove_alert(alert)
    289309
    290310    def _player_eos_cb(self, widget):
    291311        self.songchange('next')
    class JukeboxActivity(activity.Activity): 
    486506            url = self.playlist[len(self.playlist) - 1]['url']
    487507            if url.find('home') > 0:
    488508                url = url[len("journal://"):]
    489                 url = 'file://' + url
     509                if os.path.exists(url):
     510                    url = 'file://' + url
     511                    self.tag_reader.set_file(url, len(self.playlist) - 1)
     512
    490513            elif url.startswith('journal://'):
    491                 jobject = datastore.get(url[len("journal://"):])
    492                 url = 'file://' + jobject.file_path
    493                 # jobject.destroy() ??
    494             self.tag_reader.set_file(url, len(self.playlist) - 1)
     514                url = url[len("journal://"):]
     515                if os.path.exists(url):
     516                    jobject = datastore.get(url)
     517                    url = 'file://' + jobject.file_path
     518                    self.tag_reader.set_file(url, len(self.playlist) - 1)
    495519
    496520        if not self.player:
    497521            # lazy init the player so that videowidget is realized
    class JukeboxActivity(activity.Activity): 
    536560            self.player.pause()
    537561            self.control.set_button_play()
    538562        else:
    539             if self.player.error:
     563            url = self.playlist[self.currentplaying]['url']
     564            if url.startswith('journal://'):
     565                url = url[len("journal://"):]
     566            if not os.path.exists(url):
     567                self._show_error_alert(_('Error'),
     568                        _('The file %s was not found') % url)
     569                self.control.set_disabled()
     570            elif self.player.error:
    540571                self.control.set_disabled()
    541572            else:
    542573                self.player.play()