From c7439742e389230ca8f8772873c08afd6f7efba7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 8 Jun 2016 10:10:25 +0530 Subject: [PATCH] Implement reloading of book from server --- src/pyj/book_list/boss.pyj | 3 +++ src/pyj/read_book/overlay.pyj | 23 ++++++++++++++++++----- src/pyj/read_book/ui.pyj | 5 +++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/pyj/book_list/boss.pyj b/src/pyj/book_list/boss.pyj index 7f7ab6f178..f760ec5076 100644 --- a/src/pyj/book_list/boss.pyj +++ b/src/pyj/book_list/boss.pyj @@ -111,6 +111,9 @@ class Boss: self.apply_mode() self.read_ui.load_book(book_id, fmt, metadata) + def reload_book(self): + self.read_ui.reload_book() + def return_to_book_list(self, book_id): # Note that book_id could refer to a deleted book, that is, a book no # longer in local storage diff --git a/src/pyj/read_book/overlay.pyj b/src/pyj/read_book/overlay.pyj index 2104b11439..630d93b7a5 100644 --- a/src/pyj/read_book/overlay.pyj +++ b/src/pyj/read_book/overlay.pyj @@ -37,17 +37,22 @@ class LoadingMessage: # {{{ class DeleteBook: # {{{ - def __init__(self, overlay): + def __init__(self, overlay, question, ok_icon, ok_text, reload_book): self.overlay = overlay + self.question = question or _( + 'Are you sure you want to remove this book from local storage? You will have to re-download it from calibre if you want to read it again.') + self.ok_icon = ok_icon or 'trash' + self.ok_text = ok_text or _('Delete book') + self.reload_book = reload_book def show(self, container): self.container_id = container.getAttribute('id') set_css(container, display='flex', justify_content='center', flex_direction='column', background_color=get_color('window-background')) container.appendChild( E.div(style='margin:1ex 1em', - E.h2(_('Are you sure you want to remove this book from local storage? You will have to re-download it from calibre if you want to read it again.')), + E.h2(self.question), E.div(style='display:flex; justify-content:flex-end', - create_button(_('Delete book'), 'trash', action=self.delete_book, highlight=True), + create_button(self.ok_text, self.ok_icon, action=self.delete_book, highlight=True), E.span('\xa0'), create_button(_('Cancel'), action=self.cancel), ) @@ -77,7 +82,10 @@ class DeleteBook: # {{{ view.ui.show_error(_('Failed to delete book'), _('Failed to delete book from local storage, click "Show details" for more information.'), errmsg) else: book_id = book.key[1] - get_boss().return_to_book_list(book_id) + if self.reload_book: + get_boss().reload_book() + else: + get_boss().return_to_book_list(book_id) ) def cancel(self): @@ -136,7 +144,7 @@ class MainOverlay: # {{{ add_button('arrow-left', _('Back'), self.back) add_button('arrow-right', _('Forward'), self.forward) add_button() - add_button('refresh', _('Reload this book from the server')) + add_button('refresh', _('Reload this book from the server'), self.overlay.reload_book) add_button('cloud-download', _('Get last read position and annotations from the server')) add_button('trash', _('Delete this book from the device'), self.overlay.delete_book) add_button() @@ -236,3 +244,8 @@ class Overlay: self.hide_current_panel() self.panels = [DeleteBook(self)] self.show_current_panel() + + def reload_book(self): + self.hide_current_panel() + self.panels = [DeleteBook(self, _('Are you sure you want to reload this book?'), 'refresh', _('Reload book'), True)] + self.show_current_panel() diff --git a/src/pyj/read_book/ui.pyj b/src/pyj/read_book/ui.pyj index a5120805f2..769579a8bc 100644 --- a/src/pyj/read_book/ui.pyj +++ b/src/pyj/read_book/ui.pyj @@ -102,6 +102,11 @@ class ReadUI: return self.start_load(book_id, fmt, metadata) + def reload_book(self): + book_id = self.base_url_data.book_id + metadata = self.metadata or self.interface_data.metadata[book_id] + self.load_book(book_id, self.base_url_data.fmt, metadata) + @property def url_data(self): ans = {'book_id':self.base_url_data.book_id, 'fmt': self.base_url_data.fmt}