mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
73d1406e29
commit
d7632c256c
@ -6,6 +6,7 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
from contextlib import suppress
|
||||||
|
|
||||||
from calibre import prepare_string_for_xml, force_unicode
|
from calibre import prepare_string_for_xml, force_unicode
|
||||||
from calibre.ebooks.metadata import fmt_sidx, rating_to_stars
|
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)
|
path = force_unicode(mi.path, filesystem_encoding)
|
||||||
scheme = 'devpath' if isdevice else 'path'
|
scheme = 'devpath' if isdevice else 'path'
|
||||||
loc = path if isdevice else book_id
|
loc = path if isdevice else book_id
|
||||||
pathstr = _('Click to open')
|
|
||||||
extra = ''
|
extra = ''
|
||||||
if isdevice:
|
if isdevice:
|
||||||
durl = path
|
durl = path
|
||||||
@ -211,7 +211,15 @@ def mi_to_html(
|
|||||||
prepare_string_for_xml(durl))
|
prepare_string_for_xml(durl))
|
||||||
if show_links:
|
if show_links:
|
||||||
link = '<a href="{}" title="{}">{}</a>{}'.format(action(scheme, book_id=book_id, loc=loc),
|
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:
|
else:
|
||||||
link = prepare_string_for_xml(path, True)
|
link = prepare_string_for_xml(path, True)
|
||||||
ans.append((field, row % (name, link)))
|
ans.append((field, row % (name, link)))
|
||||||
|
@ -281,6 +281,10 @@ class ViewAction(InterfaceAction):
|
|||||||
path = self.gui.library_view.model().db.abspath(id_, index_is_id=True)
|
path = self.gui.library_view.model().db.abspath(id_, index_is_id=True)
|
||||||
open_local_file(path)
|
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):
|
def view_book(self, triggered):
|
||||||
rows = self.gui.current_view().selectionModel().selectedRows()
|
rows = self.gui.current_view().selectionModel().selectedRows()
|
||||||
self._view_books(rows)
|
self._view_books(rows)
|
||||||
|
@ -1088,6 +1088,7 @@ class BookDetails(DetailsLayout): # {{{
|
|||||||
|
|
||||||
show_book_info = pyqtSignal()
|
show_book_info = pyqtSignal()
|
||||||
open_containing_folder = pyqtSignal(int)
|
open_containing_folder = pyqtSignal(int)
|
||||||
|
open_data_folder = pyqtSignal(int)
|
||||||
view_specific_format = pyqtSignal(int, object)
|
view_specific_format = pyqtSignal(int, object)
|
||||||
search_requested = pyqtSignal(object, object)
|
search_requested = pyqtSignal(object, object)
|
||||||
remove_specific_format = pyqtSignal(int, object)
|
remove_specific_format = pyqtSignal(int, object)
|
||||||
@ -1237,6 +1238,8 @@ class BookDetails(DetailsLayout): # {{{
|
|||||||
browse(data['url'])
|
browse(data['url'])
|
||||||
elif dt == 'path':
|
elif dt == 'path':
|
||||||
self.open_containing_folder.emit(int(data['loc']))
|
self.open_containing_folder.emit(int(data['loc']))
|
||||||
|
elif dt == 'data-path':
|
||||||
|
self.open_data_folder.emit(int(data['loc']))
|
||||||
elif dt == 'devpath':
|
elif dt == 'devpath':
|
||||||
self.view_device_book.emit(data['loc'])
|
self.view_device_book.emit(data['loc'])
|
||||||
else:
|
else:
|
||||||
|
@ -669,6 +669,7 @@ class LayoutMixin: # {{{
|
|||||||
self.iactions['Add Books'].remote_file_dropped_on_book,
|
self.iactions['Add Books'].remote_file_dropped_on_book,
|
||||||
type=Qt.ConnectionType.QueuedConnection)
|
type=Qt.ConnectionType.QueuedConnection)
|
||||||
self.book_details.open_containing_folder.connect(self.iactions['View'].view_folder_for_id)
|
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.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.search_requested.connect(self.set_search_string_with_append)
|
||||||
self.book_details.remove_specific_format.connect(
|
self.book_details.remove_specific_format.connect(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user