Ticket #4011: 0001-Show-error-page-when-downloading-a-PDF-fails-SL-4011.patch

File 0001-Show-error-page-when-downloading-a-PDF-fails-SL-4011.patch, 5.4 KB (added by humitos, 11 years ago)

Candidate patch

  • new file icons/activity-web.svg

    From dbc37a0582518e8a27b03118b61371d6a2e23328 Mon Sep 17 00:00:00 2001
    From: Manuel Kaufmann <humitos@gmail.com>
    Date: Thu, 14 Feb 2013 12:44:14 -0300
    Subject: [PATCH Browse] 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 <humitos@gmail.com>
    ---
     icons/activity-web.svg | 15 +++++++++++
     pdfviewer.py           | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++
     2 files changed, 85 insertions(+)
     create mode 100644 icons/activity-web.svg
    
    diff --git a/icons/activity-web.svg b/icons/activity-web.svg
    new file mode 100644
    index 0000000..c8f466a
    - +  
     1<?xml version="1.0" ?><!DOCTYPE svg  PUBLIC '-//W3C//DTD SVG 1.1//EN'  'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' [
     2        <!ENTITY stroke_color "#010101">
     3        <!ENTITY fill_color "#FFFFFF">
     4]><svg enable-background="new 0 0 55 55" height="55px" version="1.1" viewBox="0 0 55 55" width="55px" x="0px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" y="0px"><g display="block" id="activity-browse">
     5        <circle cx="27.375" cy="27.5" display="inline" fill="&fill_color;" r="19.903" stroke="&stroke_color;" stroke-width="3.5"/>
     6        <g display="inline">
     7                <path d="M27.376,7.598c0,0-11.205,8.394-11.205,19.976    c0,11.583,11.205,19.829,11.205,19.829" fill="&fill_color;" stroke="&stroke_color;" stroke-width="3.5"/>
     8                <path d="M27.376,7.598c0,0,11.066,9.141,11.066,19.976    c0,10.839-11.066,19.829-11.066,19.829" fill="&fill_color;" stroke="&stroke_color;" stroke-width="3.5"/>
     9                <line fill="&fill_color;" stroke="&stroke_color;" stroke-width="3.5" x1="27.376" x2="27.376" y1="7.598" y2="47.402"/>
     10                <line fill="&fill_color;" stroke="&stroke_color;" stroke-width="3.5" x1="27.376" x2="27.376" y1="7.598" y2="47.402"/>
     11                <line fill="&fill_color;" stroke="&stroke_color;" stroke-width="3.5" x1="27.376" x2="27.376" y1="7.598" y2="47.402"/>
     12                <line fill="&fill_color;" stroke="&stroke_color;" stroke-width="3.5" x1="7.472" x2="47.278" y1="27.5" y2="27.5"/>
     13        </g>
     14</g></svg>
     15
  • pdfviewer.py

    diff --git a/pdfviewer.py b/pdfviewer.py
    index 40de7ec..2da12cb 100644
    a b class PDFMessageBox(Gtk.EventBox): 
    345345        button.show()
    346346
    347347
     348class PDFErrorMessageBox(Gtk.EventBox):
     349    def __init__(self, title, message, button_callback):
     350        Gtk.EventBox.__init__(self)
     351
     352        self.modify_bg(Gtk.StateType.NORMAL,
     353                       style.COLOR_WHITE.get_gdk_color())
     354
     355        alignment = Gtk.Alignment.new(0.5, 0.5, 0.1, 0.1)
     356        self.add(alignment)
     357        alignment.show()
     358
     359        box = Gtk.VBox()
     360        alignment.add(box)
     361        box.show()
     362
     363        icon = Icon(pixel_size=style.LARGE_ICON_SIZE,
     364                    icon_name='activity-web',
     365                    stroke_color=style.COLOR_BUTTON_GREY.get_svg(),
     366                    fill_color=style.COLOR_TRANSPARENT.get_svg())
     367
     368        box.pack_start(icon, expand=True, fill=False, padding=0)
     369        icon.show()
     370
     371        color = style.COLOR_BUTTON_GREY.get_html()
     372
     373        label = Gtk.Label()
     374        label.set_markup('<span weight="bold" color="%s">%s</span>' % ( \
     375                color, GLib.markup_escape_text(title)))
     376        box.pack_start(label, expand=True, fill=False, padding=0)
     377        label.show()
     378
     379        label = Gtk.Label()
     380        label.set_markup('<span color="%s">%s</span>' % ( \
     381                color, GLib.markup_escape_text(message)))
     382        box.pack_start(label, expand=True, fill=False, padding=0)
     383        label.show()
     384
     385        button_box = Gtk.HButtonBox()
     386        button_box.set_layout(Gtk.ButtonBoxStyle.CENTER)
     387        box.pack_start(button_box, False, True, 0)
     388        button_box.show()
     389
     390        button = Gtk.Button(label=_('Try again'))
     391        button.connect('clicked', button_callback)
     392        button.props.image = Icon(icon_name='entry-refresh',
     393                                  icon_size=Gtk.IconSize.BUTTON,
     394                                  stroke_color=style.COLOR_WHITE.get_svg(),
     395                                  fill_color=style.COLOR_TRANSPARENT.get_svg())
     396        button_box.pack_start(button, expand=True, fill=False, padding=0)
     397        button.show()
     398
     399
    348400class PDFTabPage(Gtk.HBox):
    349401    """Shows a basic PDF viewer, download the file first if the PDF is
    350402    in a remote location.
    class PDFTabPage(Gtk.HBox): 
    475527    def __download_error_cb(self, download, err_code, err_detail, reason):
    476528        logging.debug('Download error! code %s, detail %s: %s' % \
    477529                          (err_code, err_detail, reason))
     530        title = _('This web page could not be loaded')
     531        self._browser.props.title = title
     532
     533        if self._message_box is not None:
     534            self.remove(self._message_box)
     535
     536        self._message_box = PDFErrorMessageBox(
     537            title=title,
     538            message=_('This PDF could not be loaded. Please '
     539                      'make sure you are connected to the internet.'),
     540            button_callback=self.reload)
     541        self.pack_start(self._message_box, True, True, 0)
     542        self._message_box.show()
     543
     544    def reload(self, button=None):
     545        self.remove(self._message_box)
     546        self._message_box = None
     547        self.setup(self._requested_uri)
    478548
    479549    def close_tab(self, button=None):
    480550        self._browser.emit_close_tab()