When emailling to kindle set the filename based on the post plugboard title

This commit is contained in:
Kovid Goyal 2022-11-01 08:30:57 +05:30
parent 4b05986bbd
commit f77e2d693d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 19 additions and 18 deletions

View File

@ -401,12 +401,10 @@ class EmailMixin: # {{{
if not ids or len(ids) == 0: if not ids or len(ids) == 0:
return return
files, _auto_ids = self.library_view.model().get_preferred_formats_from_ids(ids, modified_metadata = []
fmts, set_metadata=True, files, _auto_ids = self.library_view.model().get_preferred_formats_from_ids(
specific_format=specific_format, ids, fmts, set_metadata=True, specific_format=specific_format, exclude_auto=do_auto_convert,
exclude_auto=do_auto_convert, use_plugboard=plugboard_email_value, plugboard_formats=plugboard_email_formats, modified_metadata=modified_metadata)
use_plugboard=plugboard_email_value,
plugboard_formats=plugboard_email_formats)
if do_auto_convert: if do_auto_convert:
nids = list(set(ids).difference(_auto_ids)) nids = list(set(ids).difference(_auto_ids))
ids = [i for i in ids if i in nids] ids = [i for i in ids if i in nids]
@ -418,10 +416,10 @@ class EmailMixin: # {{{
bad, remove_ids, jobnames = [], [], [] bad, remove_ids, jobnames = [], [], []
texts, subjects, attachments, attachment_names = [], [], [], [] texts, subjects, attachments, attachment_names = [], [], [], []
for f, mi, id in zip(files, full_metadata, ids): for f, mi, id, newmi in zip(files, full_metadata, ids, modified_metadata):
t = mi.title if not newmi:
if not t: newmi = mi
t = _('Unknown') t = mi.title or _('Unknown')
if f is None: if f is None:
bad.append(t) bad.append(t)
else: else:
@ -435,8 +433,7 @@ class EmailMixin: # {{{
if not components: if not components:
components = [mi.title] components = [mi.title]
subjects.append(os.path.join(*components)) subjects.append(os.path.join(*components))
a = authors_to_string(mi.authors if mi.authors else a = authors_to_string(mi.authors or [_('Unknown')])
[_('Unknown')])
texts.append(_('Attached, you will find the e-book') + texts.append(_('Attached, you will find the e-book') +
'\n\n' + t + '\n\t' + _('by') + ' ' + a + '\n\n' + '\n\n' + t + '\n\t' + _('by') + ' ' + a + '\n\n' +
_('in the %s format.') % _('in the %s format.') %
@ -445,7 +442,7 @@ class EmailMixin: # {{{
from calibre.utils.html2text import html2text from calibre.utils.html2text import html2text
texts[-1] += '\n\n' + _('About this book:') + '\n\n' + textwrap.fill(html2text(mi.comments)) texts[-1] += '\n\n' + _('About this book:') + '\n\n' + textwrap.fill(html2text(mi.comments))
if is_for_kindle(to): if is_for_kindle(to):
prefix = str(t) prefix = str(newmi.title or t)
else: else:
prefix = f'{t} - {a}' prefix = f'{t} - {a}'
if not isinstance(prefix, str): if not isinstance(prefix, str):

View File

@ -680,13 +680,15 @@ class BooksModel(QAbstractTableModel): # {{{
else: else:
return metadata return metadata
def get_preferred_formats_from_ids(self, ids, formats, def get_preferred_formats_from_ids(
set_metadata=False, specific_format=None, self, ids, formats,
exclude_auto=False, mode='r+b', set_metadata=False, specific_format=None, exclude_auto=False, mode='r+b',
use_plugboard=None, plugboard_formats=None): use_plugboard=None, plugboard_formats=None, modified_metadata=None,
):
from calibre.ebooks.metadata.meta import set_metadata as _set_metadata from calibre.ebooks.metadata.meta import set_metadata as _set_metadata
ans = [] ans = []
need_auto = [] need_auto = []
modified_metadata = [] if modified_metadata is None else modified_metadata
if specific_format is not None: if specific_format is not None:
formats = [specific_format.lower()] formats = [specific_format.lower()]
for id in ids: for id in ids:
@ -705,12 +707,12 @@ class BooksModel(QAbstractTableModel): # {{{
pt = PersistentTemporaryFile(suffix='caltmpfmt.'+format) pt = PersistentTemporaryFile(suffix='caltmpfmt.'+format)
self.db.copy_format_to(id, format, pt, index_is_id=True) self.db.copy_format_to(id, format, pt, index_is_id=True)
pt.seek(0) pt.seek(0)
newmi = None
if set_metadata: if set_metadata:
try: try:
mi = self.db.get_metadata(id, get_cover=True, mi = self.db.get_metadata(id, get_cover=True,
index_is_id=True, index_is_id=True,
cover_as_data=True) cover_as_data=True)
newmi = None
if use_plugboard and format.lower() in plugboard_formats: if use_plugboard and format.lower() in plugboard_formats:
plugboards = self.db.new_api.pref('plugboards', {}) plugboards = self.db.new_api.pref('plugboards', {})
cpb = find_plugboard(use_plugboard, format.lower(), cpb = find_plugboard(use_plugboard, format.lower(),
@ -731,10 +733,12 @@ class BooksModel(QAbstractTableModel): # {{{
x = x.decode(filesystem_encoding) x = x.decode(filesystem_encoding)
return x return x
ans.append(to_uni(os.path.abspath(pt.name))) ans.append(to_uni(os.path.abspath(pt.name)))
modified_metadata.append(newmi)
else: else:
need_auto.append(id) need_auto.append(id)
if not exclude_auto: if not exclude_auto:
ans.append(None) ans.append(None)
modified_metadata.append(None)
return ans, need_auto return ans, need_auto
def get_preferred_formats(self, rows, formats, paths=False, def get_preferred_formats(self, rows, formats, paths=False,