From 5e48a0361734df2dcf6993d1b33de6192cc0994b Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Thu, 14 Feb 2013 15:44:14 +0000 Subject: Show error page when downloading a PDF fails SL #4011 When the 'error' signal is emitted while a PDF file is being downloaded, Browse shows an error page similar to the one showed when a web page could not be reached. Signed-off-by: Manuel Kaufmann Signed-off-by: Manuel QuiƱones --- diff --git a/browser.py b/browser.py index b786b6b..545bf3b 100644 --- a/browser.py +++ b/browser.py @@ -727,7 +727,7 @@ class Browser(WebKit.WebView): 'title': _('This web page could not be loaded'), 'message': _('"%s" could not be loaded. Please check for ' 'typing errors, and make sure you are connected ' - 'to the internet.') % uri, + 'to the Internet.') % uri, 'btn_value': _('Try again'), 'url': uri, } diff --git a/pdfviewer.py b/pdfviewer.py index 40de7ec..7557594 100644 --- a/pdfviewer.py +++ b/pdfviewer.py @@ -34,6 +34,7 @@ from sugar3.graphics.progressicon import ProgressIcon from sugar3.graphics import style from sugar3.datastore import datastore from sugar3.activity import activity +from sugar3.bundle.activitybundle import ActivityBundle class EvinceViewer(Gtk.Overlay): @@ -301,7 +302,7 @@ class DummyBrowser(GObject.GObject): pass -class PDFMessageBox(Gtk.EventBox): +class PDFProgressMessageBox(Gtk.EventBox): def __init__(self, message, button_callback): Gtk.EventBox.__init__(self) @@ -345,6 +346,61 @@ class PDFMessageBox(Gtk.EventBox): button.show() +class PDFErrorMessageBox(Gtk.EventBox): + def __init__(self, title, message, button_callback): + Gtk.EventBox.__init__(self) + + self.modify_bg(Gtk.StateType.NORMAL, + style.COLOR_WHITE.get_gdk_color()) + + alignment = Gtk.Alignment.new(0.5, 0.5, 0.1, 0.1) + self.add(alignment) + alignment.show() + + box = Gtk.VBox() + alignment.add(box) + box.show() + + # Get the icon of this activity through the bundle path. + bundle_path = activity.get_bundle_path() + activity_bundle = ActivityBundle(bundle_path) + icon = Icon(pixel_size=style.LARGE_ICON_SIZE, + file=activity_bundle.get_icon(), + stroke_color=style.COLOR_BUTTON_GREY.get_svg(), + fill_color=style.COLOR_TRANSPARENT.get_svg()) + + box.pack_start(icon, expand=True, fill=False, padding=0) + icon.show() + + color = style.COLOR_BUTTON_GREY.get_html() + + label = Gtk.Label() + label.set_markup('%s' % ( \ + color, GLib.markup_escape_text(title))) + box.pack_start(label, expand=True, fill=False, padding=0) + label.show() + + label = Gtk.Label() + label.set_markup('%s' % ( \ + color, GLib.markup_escape_text(message))) + box.pack_start(label, expand=True, fill=False, padding=0) + label.show() + + button_box = Gtk.HButtonBox() + button_box.set_layout(Gtk.ButtonBoxStyle.CENTER) + box.pack_start(button_box, False, True, 0) + button_box.show() + + button = Gtk.Button(label=_('Try again')) + button.connect('clicked', button_callback) + button.props.image = Icon(icon_name='entry-refresh', + icon_size=Gtk.IconSize.BUTTON, + stroke_color=style.COLOR_WHITE.get_svg(), + fill_color=style.COLOR_TRANSPARENT.get_svg()) + button_box.pack_start(button, expand=True, fill=False, padding=0) + button.show() + + class PDFTabPage(Gtk.HBox): """Shows a basic PDF viewer, download the file first if the PDF is in a remote location. @@ -428,7 +484,7 @@ class PDFTabPage(Gtk.HBox): """Download the PDF from a remote location to a temporal file.""" # Display a message - self._message_box = PDFMessageBox( + self._message_box = PDFProgressMessageBox( message=_("Downloading document..."), button_callback=self.close_tab) self.pack_start(self._message_box, True, True, 0) @@ -475,6 +531,23 @@ class PDFTabPage(Gtk.HBox): def __download_error_cb(self, download, err_code, err_detail, reason): logging.debug('Download error! code %s, detail %s: %s' % \ (err_code, err_detail, reason)) + title = _('This document could not be loaded') + self._browser.props.title = title + + if self._message_box is not None: + self.remove(self._message_box) + + self._message_box = PDFErrorMessageBox( + title=title, + message=_('Please make sure you are connected to the Internet.'), + button_callback=self.reload) + self.pack_start(self._message_box, True, True, 0) + self._message_box.show() + + def reload(self, button=None): + self.remove(self._message_box) + self._message_box = None + self.setup(self._requested_uri) def close_tab(self, button=None): self._browser.emit_close_tab() -- cgit v0.9.1