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

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

    From e110fb9acfecdb539c39c2e4255fe487cf59908e Mon Sep 17 00:00:00 2001
    From: Gonzalo Odiard <godiard@gmail.com>
    Date: Wed, 27 Jun 2012 16:40:57 -0300
    Subject: [PATCH] Avoid error if the media referenced in a playlist is not
     available - v2
    
    If the user try play a non existent media, show a alert.
    
    Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
    ---
     jukeboxactivity.py |   43 ++++++++++++++++++++++++++++++++++---------
     1 file changed, 34 insertions(+), 9 deletions(-)
    
    diff --git a/jukeboxactivity.py b/jukeboxactivity.py
    index 8ad59d6..e900263 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): 
    272273        self.player.connect("tag", self._player_new_tag_cb)
    273274        self.player.connect("stream-info", self._player_stream_info_cb)
    274275        url = self.playlist[self.currentplaying]['url']
     276        error = None
    275277        if url.startswith('journal://'):
    276             jobject = datastore.get(url[len("journal://"):])
    277             url = 'file://' + jobject.file_path
    278         self.player.set_uri(url)
    279 
    280         self.play_toggled()
    281 
     278            try:
     279                jobject = datastore.get(url[len("journal://"):])
     280                url = 'file://' + jobject.file_path
     281            except:
     282                path = url[len("journal://"):]
     283                error = _('The file %s was not found') % path
    282284        self.check_if_next_prev()
     285        if error is None:
     286            self.player.set_uri(url)
     287            self.play_toggled()
     288        else:
     289            self.control.set_disabled()
     290            self._show_error_alert(_('Error'), error)
     291
    283292        self.playlist_widget.set_cursor(self.currentplaying)
    284293
    285294    def _player_eos_cb(self, widget):
    class JukeboxActivity(activity.Activity): 
    294303        text.show_all()
    295304        self.bin.add(text)
    296305
     306    def _show_error_alert(self, title, text=None):
     307        alert = ErrorAlert()
     308        alert.props.title = title
     309        alert.props.msg = text
     310        self.add_alert(alert)
     311        alert.connect('response', self._alert_cancel_cb)
     312        alert.show()
     313
     314    def _alert_cancel_cb(self, alert, response_id):
     315        self.remove_alert(alert)
     316
    297317    def _player_new_tag_cb(self, widget, tag, value):
    298318        if not tag in [gst.TAG_TITLE, gst.TAG_ARTIST, gst.TAG_ALBUM]:
    299319            return
    class JukeboxActivity(activity.Activity): 
    476496                self.playlist.append({'url': uri, 'title': title})
    477497        if uri.endswith(title) or title is None or title == '' or \
    478498                object_id is not None:
     499            error = False
    479500            logging.error('Try get a better title reading tags')
    480501            # TODO: unify this code....
    481502            url = self.playlist[len(self.playlist) - 1]['url']
    class JukeboxActivity(activity.Activity): 
    483504                url = url[len("journal://"):]
    484505                url = 'file://' + url
    485506            elif url.startswith('journal://'):
    486                 jobject = datastore.get(url[len("journal://"):])
    487                 url = 'file://' + jobject.file_path
     507                try:
     508                    jobject = datastore.get(url[len("journal://"):])
     509                    url = 'file://' + jobject.file_path
     510                except:
     511                    error = True
    488512                # jobject.destroy() ??
    489             self.tag_reader.set_file(url, len(self.playlist) - 1)
     513            if not error:
     514                self.tag_reader.set_file(url, len(self.playlist) - 1)
    490515
    491516        if not self.player:
    492517            # lazy init the player so that videowidget is realized