[Pkg-sugar-commit] [sugar-jukebox-activity] 01/10: Avoid error if the media referenced in a playlist is not available - v2
Jonas Smedegaard
dr at jones.dk
Sat Jun 27 01:57:02 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag v26.1
in repository sugar-jukebox-activity.
commit e110fb9acfecdb539c39c2e4255fe487cf59908e
Author: Gonzalo Odiard <godiard at gmail.com>
Date: Wed Jun 27 16:40:57 2012 -0300
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 at 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/jukeboxactivity.py
+++ b/jukeboxactivity.py
@@ -31,6 +31,7 @@ from sugar.activity import activity
from sugar.graphics.objectchooser import ObjectChooser
from sugar import mime
from sugar.datastore import datastore
+from sugar.graphics.alert import ErrorAlert
OLD_TOOLBAR = False
try:
@@ -272,14 +273,22 @@ class JukeboxActivity(activity.Activity):
self.player.connect("tag", self._player_new_tag_cb)
self.player.connect("stream-info", self._player_stream_info_cb)
url = self.playlist[self.currentplaying]['url']
+ error = None
if url.startswith('journal://'):
- jobject = datastore.get(url[len("journal://"):])
- url = 'file://' + jobject.file_path
- self.player.set_uri(url)
-
- self.play_toggled()
-
+ try:
+ jobject = datastore.get(url[len("journal://"):])
+ url = 'file://' + jobject.file_path
+ except:
+ path = url[len("journal://"):]
+ error = _('The file %s was not found') % path
self.check_if_next_prev()
+ if error is None:
+ self.player.set_uri(url)
+ self.play_toggled()
+ else:
+ self.control.set_disabled()
+ self._show_error_alert(_('Error'), error)
+
self.playlist_widget.set_cursor(self.currentplaying)
def _player_eos_cb(self, widget):
@@ -294,6 +303,17 @@ class JukeboxActivity(activity.Activity):
text.show_all()
self.bin.add(text)
+ def _show_error_alert(self, title, text=None):
+ alert = ErrorAlert()
+ alert.props.title = title
+ alert.props.msg = text
+ self.add_alert(alert)
+ alert.connect('response', self._alert_cancel_cb)
+ alert.show()
+
+ def _alert_cancel_cb(self, alert, response_id):
+ self.remove_alert(alert)
+
def _player_new_tag_cb(self, widget, tag, value):
if not tag in [gst.TAG_TITLE, gst.TAG_ARTIST, gst.TAG_ALBUM]:
return
@@ -476,6 +496,7 @@ class JukeboxActivity(activity.Activity):
self.playlist.append({'url': uri, 'title': title})
if uri.endswith(title) or title is None or title == '' or \
object_id is not None:
+ error = False
logging.error('Try get a better title reading tags')
# TODO: unify this code....
url = self.playlist[len(self.playlist) - 1]['url']
@@ -483,10 +504,14 @@ class JukeboxActivity(activity.Activity):
url = url[len("journal://"):]
url = 'file://' + url
elif url.startswith('journal://'):
- jobject = datastore.get(url[len("journal://"):])
- url = 'file://' + jobject.file_path
+ try:
+ jobject = datastore.get(url[len("journal://"):])
+ url = 'file://' + jobject.file_path
+ except:
+ error = True
# jobject.destroy() ??
- self.tag_reader.set_file(url, len(self.playlist) - 1)
+ if not error:
+ self.tag_reader.set_file(url, len(self.playlist) - 1)
if not self.player:
# lazy init the player so that videowidget is realized
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-sugar/sugar-jukebox-activity.git
More information about the pkg-sugar-commit
mailing list