Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2012-06-27 19:40:57 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2012-06-27 19:40:57 (GMT)
commite110fb9acfecdb539c39c2e4255fe487cf59908e (patch)
tree0c53d9ffb21a2af2c16b87af79ffd16e048da806
parent05de79a50f07574b5587f72b870b955d2ca5e76d (diff)
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>
-rw-r--r--jukeboxactivity.py43
1 files 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