mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Allow restoring of the ORIGINAL_XXX format by right-clicking it in the book details panel
This commit is contained in:
parent
5e28991c17
commit
2388668aa9
@ -180,6 +180,13 @@ class DeleteAction(InterfaceAction):
|
|||||||
self.gui.library_view.currentIndex())
|
self.gui.library_view.currentIndex())
|
||||||
self.gui.tags_view.recount()
|
self.gui.tags_view.recount()
|
||||||
|
|
||||||
|
def restore_format(self, book_id, original_fmt):
|
||||||
|
self.gui.current_db.restore_original_format(book_id, original_fmt)
|
||||||
|
self.gui.library_view.model().refresh_ids([book_id])
|
||||||
|
self.gui.library_view.model().current_changed(self.gui.library_view.currentIndex(),
|
||||||
|
self.gui.library_view.currentIndex())
|
||||||
|
self.gui.tags_view.recount()
|
||||||
|
|
||||||
def delete_selected_formats(self, *args):
|
def delete_selected_formats(self, *args):
|
||||||
ids = self._get_selected_ids()
|
ids = self._get_selected_ids()
|
||||||
if not ids:
|
if not ids:
|
||||||
|
@ -405,6 +405,7 @@ class BookInfo(QWebView):
|
|||||||
link_clicked = pyqtSignal(object)
|
link_clicked = pyqtSignal(object)
|
||||||
remove_format = pyqtSignal(int, object)
|
remove_format = pyqtSignal(int, object)
|
||||||
save_format = pyqtSignal(int, object)
|
save_format = pyqtSignal(int, object)
|
||||||
|
restore_format = pyqtSignal(int, object)
|
||||||
|
|
||||||
def __init__(self, vertical, parent=None):
|
def __init__(self, vertical, parent=None):
|
||||||
QWebView.__init__(self, parent)
|
QWebView.__init__(self, parent)
|
||||||
@ -418,7 +419,7 @@ class BookInfo(QWebView):
|
|||||||
palette.setBrush(QPalette.Base, Qt.transparent)
|
palette.setBrush(QPalette.Base, Qt.transparent)
|
||||||
self.page().setPalette(palette)
|
self.page().setPalette(palette)
|
||||||
self.css = P('templates/book_details.css', data=True).decode('utf-8')
|
self.css = P('templates/book_details.css', data=True).decode('utf-8')
|
||||||
for x, icon in [('remove', 'trash.png'), ('save', 'save.png')]:
|
for x, icon in [('remove', 'trash.png'), ('save', 'save.png'), ('restore', 'edit-undo.png')]:
|
||||||
ac = QAction(QIcon(I(icon)), '', self)
|
ac = QAction(QIcon(I(icon)), '', self)
|
||||||
ac.current_fmt = None
|
ac.current_fmt = None
|
||||||
ac.triggered.connect(getattr(self, '%s_format_triggerred'%x))
|
ac.triggered.connect(getattr(self, '%s_format_triggerred'%x))
|
||||||
@ -436,6 +437,9 @@ class BookInfo(QWebView):
|
|||||||
def save_format_triggerred(self):
|
def save_format_triggerred(self):
|
||||||
self.context_action_triggered('save')
|
self.context_action_triggered('save')
|
||||||
|
|
||||||
|
def restore_format_triggerred(self):
|
||||||
|
self.context_action_triggered('restore')
|
||||||
|
|
||||||
def link_activated(self, link):
|
def link_activated(self, link):
|
||||||
self._link_clicked = True
|
self._link_clicked = True
|
||||||
if unicode(link.scheme()) in ('http', 'https'):
|
if unicode(link.scheme()) in ('http', 'https'):
|
||||||
@ -479,7 +483,11 @@ class BookInfo(QWebView):
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
else:
|
else:
|
||||||
for a, t in [('remove', _('Delete the %s format')),
|
for a, t in [('remove', _('Delete the %s format')),
|
||||||
('save', _('Save the %s format to disk'))]:
|
('save', _('Save the %s format to disk')),
|
||||||
|
('restore', _('Restore the %s format')),
|
||||||
|
]:
|
||||||
|
if a == 'restore' and not fmt.upper().startswith('ORIGINAL_'):
|
||||||
|
continue
|
||||||
ac = getattr(self, '%s_format_action'%a)
|
ac = getattr(self, '%s_format_action'%a)
|
||||||
ac.current_fmt = (book_id, fmt)
|
ac.current_fmt = (book_id, fmt)
|
||||||
ac.setText(t%parts[2])
|
ac.setText(t%parts[2])
|
||||||
@ -585,6 +593,7 @@ class BookDetails(QWidget): # {{{
|
|||||||
view_specific_format = pyqtSignal(int, object)
|
view_specific_format = pyqtSignal(int, object)
|
||||||
remove_specific_format = pyqtSignal(int, object)
|
remove_specific_format = pyqtSignal(int, object)
|
||||||
save_specific_format = pyqtSignal(int, object)
|
save_specific_format = pyqtSignal(int, object)
|
||||||
|
restore_specific_format = pyqtSignal(int, object)
|
||||||
remote_file_dropped = pyqtSignal(object, object)
|
remote_file_dropped = pyqtSignal(object, object)
|
||||||
files_dropped = pyqtSignal(object, object)
|
files_dropped = pyqtSignal(object, object)
|
||||||
cover_changed = pyqtSignal(object, object)
|
cover_changed = pyqtSignal(object, object)
|
||||||
@ -654,6 +663,7 @@ class BookDetails(QWidget): # {{{
|
|||||||
self.book_info.link_clicked.connect(self.handle_click)
|
self.book_info.link_clicked.connect(self.handle_click)
|
||||||
self.book_info.remove_format.connect(self.remove_specific_format)
|
self.book_info.remove_format.connect(self.remove_specific_format)
|
||||||
self.book_info.save_format.connect(self.save_specific_format)
|
self.book_info.save_format.connect(self.save_specific_format)
|
||||||
|
self.book_info.restore_format.connect(self.restore_specific_format)
|
||||||
self.setCursor(Qt.PointingHandCursor)
|
self.setCursor(Qt.PointingHandCursor)
|
||||||
|
|
||||||
def handle_click(self, link):
|
def handle_click(self, link):
|
||||||
|
@ -272,6 +272,8 @@ class LayoutMixin(object): # {{{
|
|||||||
self.iactions['Remove Books'].remove_format_by_id)
|
self.iactions['Remove Books'].remove_format_by_id)
|
||||||
self.book_details.save_specific_format.connect(
|
self.book_details.save_specific_format.connect(
|
||||||
self.iactions['Save To Disk'].save_library_format_by_ids)
|
self.iactions['Save To Disk'].save_library_format_by_ids)
|
||||||
|
self.book_details.restore_specific_format.connect(
|
||||||
|
self.iactions['Remove Books'].restore_format)
|
||||||
self.book_details.view_device_book.connect(
|
self.book_details.view_device_book.connect(
|
||||||
self.iactions['View'].view_device_book)
|
self.iactions['View'].view_device_book)
|
||||||
|
|
||||||
|
@ -1541,6 +1541,14 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
opath = self.format_abspath(book_id, nfmt, index_is_id=True)
|
opath = self.format_abspath(book_id, nfmt, index_is_id=True)
|
||||||
return fmt if opath is None else nfmt
|
return fmt if opath is None else nfmt
|
||||||
|
|
||||||
|
def restore_original_format(self, book_id, original_fmt, notify=True):
|
||||||
|
opath = self.format_abspath(book_id, original_fmt, index_is_id=True)
|
||||||
|
if opath is not None:
|
||||||
|
fmt = original_fmt.partition('_')[2]
|
||||||
|
with lopen(opath, 'rb') as f:
|
||||||
|
self.add_format(book_id, fmt, f, index_is_id=True, notify=False)
|
||||||
|
self.remove_format(book_id, original_fmt, index_is_id=True, notify=notify)
|
||||||
|
|
||||||
def delete_book(self, id, notify=True, commit=True, permanent=False,
|
def delete_book(self, id, notify=True, commit=True, permanent=False,
|
||||||
do_clean=True):
|
do_clean=True):
|
||||||
'''
|
'''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user