From 24d43645ab93eb5735a780089b9917fc793704c2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 7 Apr 2015 08:36:15 +0530 Subject: [PATCH] Book details panel: Allow copying full path to ebook files by right clicking on the format link. See #1437756 ([Enhancement] Option to create and place a link to a selected book.) --- src/calibre/ebooks/metadata/book/render.py | 13 +++++++------ src/calibre/gui2/book_details.py | 5 +++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/calibre/ebooks/metadata/book/render.py b/src/calibre/ebooks/metadata/book/render.py index b1ff212793..59e704b908 100644 --- a/src/calibre/ebooks/metadata/book/render.py +++ b/src/calibre/ebooks/metadata/book/render.py @@ -131,15 +131,16 @@ def mi_to_html(mi, field_list=None, default_author_link=None, use_roman_numbers= elif field == 'formats': if isdevice: continue - path = '' - if mi.path: - h, t = os.path.split(mi.path) - path = '/'.join((os.path.basename(h), t)) + path = mi.path or '' + bpath = '' + if path: + h, t = os.path.split(path) + bpath = '/'.join((os.path.basename(h), t)) data = ({ 'fmt':x, 'path':a(path or ''), 'fname':a(mi.format_files.get(x, '')), - 'ext':x.lower(), 'id':mi.id + 'ext':x.lower(), 'id':mi.id, 'bpath':bpath, } for x in mi.formats) - fmts = [u'{fmt}'.format(**x) for x in data] + fmts = [u'{fmt}'.format(**x) for x in data] ans.append((field, row % (name, u', '.join(fmts)))) elif field == 'identifiers': urls = urls_from_identifiers(mi.identifiers) diff --git a/src/calibre/gui2/book_details.py b/src/calibre/gui2/book_details.py index 34433b76d6..442c64f091 100644 --- a/src/calibre/gui2/book_details.py +++ b/src/calibre/gui2/book_details.py @@ -441,6 +441,11 @@ class BookInfo(QWebView): m.addAction(_('Add other application for %s files...') % fmt.upper(), partial(self.choose_open_with, book_id, fmt)) m.addAction(_('Edit Open With applications...'), partial(edit_programs, fmt, self)) menu.addMenu(m) + ac = self.copy_link_action + ac.current_url = r.linkElement().attribute('data-full-path') + if ac.current_url: + ac.setText(_('&Copy path to file')) + menu.addAction(ac) else: el = r.linkElement() author = el.toPlainText() if unicode(el.attribute('calibre-data')) == u'authors' else None