mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-01 11:53:07 +02:00
Make logic to get preferred view format re-useable
This commit is contained in:
parent
ac97fe16ac
commit
4b2c386c95
1 changed files with 12 additions and 8 deletions
|
|
@ -24,6 +24,16 @@
|
|||
from polyglot.builtins import as_bytes, unicode_type
|
||||
|
||||
|
||||
def preferred_format(formats):
|
||||
formats = tuple(x.upper() for x in formats if x)
|
||||
fmt = formats[0]
|
||||
for format in prefs['input_format_order']:
|
||||
if format in formats:
|
||||
fmt = format
|
||||
break
|
||||
return fmt
|
||||
|
||||
|
||||
class HistoryAction(QAction):
|
||||
|
||||
view_historical = pyqtSignal(object)
|
||||
|
|
@ -303,19 +313,13 @@ def _view_calibre_books(self, ids):
|
|||
self.update_history([], remove={id_})
|
||||
continue
|
||||
|
||||
formats = db.formats(id_, index_is_id=True)
|
||||
formats = db.new_api.formats(id_, verify_formats=True)
|
||||
if not formats:
|
||||
error_dialog(self.gui, _('Cannot view'),
|
||||
_('%s has no available formats.')%(title,), show=True)
|
||||
continue
|
||||
|
||||
formats = formats.upper().split(',')
|
||||
|
||||
fmt = formats[0]
|
||||
for format in prefs['input_format_order']:
|
||||
if format in formats:
|
||||
fmt = format
|
||||
break
|
||||
fmt = preferred_format(formats)
|
||||
views.append((id_, title))
|
||||
self.view_format_by_id(id_, fmt)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue