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-08-17 21:14:24 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2012-08-21 12:14:03 (GMT)
commit1fc8b40f2497aeaa408feaa7fd68e728dd85182c (patch)
tree58d43a64f90b44f11ae952dab817e9cd95235f98
parent3294a7f118dc2c6dd54c71d92dcf40570364dd61 (diff)
Avoid loosing data in playlist if media is removed - SL #3709
This patch solves the lost of data in the playlist if the data is in a external media and is removed. We need improve the error message but will be done in another patch. Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r--jukeboxactivity.py42
1 files changed, 34 insertions, 8 deletions
diff --git a/jukeboxactivity.py b/jukeboxactivity.py
index 7062fc3..a84f9af 100644
--- a/jukeboxactivity.py
+++ b/jukeboxactivity.py
@@ -36,6 +36,7 @@ from sugar3.graphics.toolbarbox import ToolbarBox
from sugar3.graphics.toolbarbox import ToolbarButton
from sugar3.activity.widgets import StopButton
from sugar3.activity.widgets import ActivityToolbarButton
+from sugar3.graphics.alert import ErrorAlert
import gi
gi.require_version('Gtk', '3.0')
@@ -250,19 +251,39 @@ 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)
+
self.playlist_widget.set_cursor(self.currentplaying)
def _player_eos_cb(self, widget):
self.songchange('next')
+ def _show_error_alert(self, title):
+ alert = ErrorAlert()
+ alert.props.title = title
+ 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_error_cb(self, widget, message, detail):
self.player.stop()
self.player.set_uri(None)
@@ -458,6 +479,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']
@@ -465,10 +487,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