Book details: Show a clickable link to open the data files folder when extra data files are present for the book

This commit is contained in:
Kovid Goyal 2023-04-21 14:35:51 +05:30
parent 73d1406e29
commit d7632c256c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 18 additions and 2 deletions

View File

@ -6,6 +6,7 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
import os
from functools import partial
from contextlib import suppress
from calibre import prepare_string_for_xml, force_unicode
from calibre.ebooks.metadata import fmt_sidx, rating_to_stars
@ -201,7 +202,6 @@ def mi_to_html(
path = force_unicode(mi.path, filesystem_encoding)
scheme = 'devpath' if isdevice else 'path'
loc = path if isdevice else book_id
pathstr = _('Click to open')
extra = ''
if isdevice:
durl = path
@ -211,7 +211,15 @@ def mi_to_html(
prepare_string_for_xml(durl))
if show_links:
link = '<a href="{}" title="{}">{}</a>{}'.format(action(scheme, book_id=book_id, loc=loc),
prepare_string_for_xml(path, True), pathstr, extra)
prepare_string_for_xml(path, True), _('Click to open'), extra)
if not isdevice:
data_path = os.path.join(path, 'data')
with suppress(OSError):
if os.listdir(data_path):
link += ' \xa0 <a href="{}" title="{}">{}</a>'.format(
action('data-path', book_id=book_id, loc=book_id),
prepare_string_for_xml(data_path, True), _('Data files'))
else:
link = prepare_string_for_xml(path, True)
ans.append((field, row % (name, link)))

View File

@ -281,6 +281,10 @@ class ViewAction(InterfaceAction):
path = self.gui.library_view.model().db.abspath(id_, index_is_id=True)
open_local_file(path)
def view_data_folder_for_id(self, id_):
path = self.gui.library_view.model().db.abspath(id_, index_is_id=True)
open_local_file(os.path.join(path, 'data'))
def view_book(self, triggered):
rows = self.gui.current_view().selectionModel().selectedRows()
self._view_books(rows)

View File

@ -1088,6 +1088,7 @@ class BookDetails(DetailsLayout): # {{{
show_book_info = pyqtSignal()
open_containing_folder = pyqtSignal(int)
open_data_folder = pyqtSignal(int)
view_specific_format = pyqtSignal(int, object)
search_requested = pyqtSignal(object, object)
remove_specific_format = pyqtSignal(int, object)
@ -1237,6 +1238,8 @@ class BookDetails(DetailsLayout): # {{{
browse(data['url'])
elif dt == 'path':
self.open_containing_folder.emit(int(data['loc']))
elif dt == 'data-path':
self.open_data_folder.emit(int(data['loc']))
elif dt == 'devpath':
self.view_device_book.emit(data['loc'])
else:

View File

@ -669,6 +669,7 @@ class LayoutMixin: # {{{
self.iactions['Add Books'].remote_file_dropped_on_book,
type=Qt.ConnectionType.QueuedConnection)
self.book_details.open_containing_folder.connect(self.iactions['View'].view_folder_for_id)
self.book_details.open_data_folder.connect(self.iactions['View'].view_data_folder_for_id)
self.book_details.view_specific_format.connect(self.iactions['View'].view_format_by_id)
self.book_details.search_requested.connect(self.set_search_string_with_append)
self.book_details.remove_specific_format.connect(