Implement reloading of book from server

This commit is contained in:
Kovid Goyal 2016-06-08 10:10:25 +05:30
parent f7a7150f28
commit c7439742e3
3 changed files with 26 additions and 5 deletions

View File

@ -111,6 +111,9 @@ class Boss:
self.apply_mode() self.apply_mode()
self.read_ui.load_book(book_id, fmt, metadata) 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): def return_to_book_list(self, book_id):
# Note that book_id could refer to a deleted book, that is, a book no # Note that book_id could refer to a deleted book, that is, a book no
# longer in local storage # longer in local storage

View File

@ -37,17 +37,22 @@ class LoadingMessage: # {{{
class DeleteBook: # {{{ class DeleteBook: # {{{
def __init__(self, overlay): def __init__(self, overlay, question, ok_icon, ok_text, reload_book):
self.overlay = overlay 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): def show(self, container):
self.container_id = container.getAttribute('id') self.container_id = container.getAttribute('id')
set_css(container, display='flex', justify_content='center', flex_direction='column', background_color=get_color('window-background')) set_css(container, display='flex', justify_content='center', flex_direction='column', background_color=get_color('window-background'))
container.appendChild( container.appendChild(
E.div(style='margin:1ex 1em', 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', 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'), E.span('\xa0'),
create_button(_('Cancel'), action=self.cancel), 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) view.ui.show_error(_('Failed to delete book'), _('Failed to delete book from local storage, click "Show details" for more information.'), errmsg)
else: else:
book_id = book.key[1] 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): def cancel(self):
@ -136,7 +144,7 @@ class MainOverlay: # {{{
add_button('arrow-left', _('Back'), self.back) add_button('arrow-left', _('Back'), self.back)
add_button('arrow-right', _('Forward'), self.forward) add_button('arrow-right', _('Forward'), self.forward)
add_button() 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('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('trash', _('Delete this book from the device'), self.overlay.delete_book)
add_button() add_button()
@ -236,3 +244,8 @@ class Overlay:
self.hide_current_panel() self.hide_current_panel()
self.panels = [DeleteBook(self)] self.panels = [DeleteBook(self)]
self.show_current_panel() 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()

View File

@ -102,6 +102,11 @@ class ReadUI:
return return
self.start_load(book_id, fmt, metadata) 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 @property
def url_data(self): def url_data(self):
ans = {'book_id':self.base_url_data.book_id, 'fmt': self.base_url_data.fmt} ans = {'book_id':self.base_url_data.book_id, 'fmt': self.base_url_data.fmt}