Use a special file type for open cover with entries

This commit is contained in:
Kovid Goyal 2015-02-27 16:21:19 +05:30
parent fd5dad9bce
commit 9a38645fe2
2 changed files with 9 additions and 9 deletions

View File

@ -219,13 +219,13 @@ class CoverView(QWidget): # {{{
gc.triggered.connect(self.generate_cover) gc.triggered.connect(self.generate_cover)
m = QMenu(_('Open cover with...')) m = QMenu(_('Open cover with...'))
populate_menu(m, self.open_with, 'jpeg') populate_menu(m, self.open_with, 'cover_image')
if len(m.actions()) == 0: if len(m.actions()) == 0:
cm.addAction(_('Open cover with...'), self.choose_open_with) cm.addAction(_('Open cover with...'), self.choose_open_with)
else: else:
m.addSeparator() m.addSeparator()
m.addAction(_('Add another application to open cover...'), self.choose_open_with) m.addAction(_('Add another application to open cover...'), self.choose_open_with)
m.addAction(_('Edit Open With applications...'), partial(edit_programs, 'jpeg', self)) m.addAction(_('Edit Open With applications...'), partial(edit_programs, 'cover_image', self))
cm.addMenu(m) cm.addMenu(m)
cm.exec_(ev.globalPos()) cm.exec_(ev.globalPos())
@ -236,7 +236,7 @@ class CoverView(QWidget): # {{{
def choose_open_with(self): def choose_open_with(self):
from calibre.gui2.open_with import choose_program from calibre.gui2.open_with import choose_program
entry = choose_program('jpeg', self) entry = choose_program('cover_image', self)
if entry is not None: if entry is not None:
self.open_with(entry) self.open_with(entry)

View File

@ -180,19 +180,19 @@ class ChooseProgram(Dialog): # {{{
oprefs.defaults['entries'] = {} oprefs.defaults['entries'] = {}
def choose_program(file_type='jpeg', parent=None, prefs=oprefs): def choose_program(file_type='jpeg', parent=None, prefs=oprefs):
file_type = file_type.lower() oft = file_type = file_type.lower()
file_type = {'cover_image':'jpeg'}.get(oft, oft)
d = ChooseProgram(file_type, parent, prefs) d = ChooseProgram(file_type, parent, prefs)
d.exec_() d.exec_()
entry = choose_manually(file_type, parent) if d.select_manually else d.selected_entry entry = choose_manually(file_type, parent) if d.select_manually else d.selected_entry
if entry is not None: if entry is not None:
entry = finalize_entry(entry) entry = finalize_entry(entry)
entry['keyboard_shortcut'] = None
entry['uuid'] = type('')(uuid.uuid4()) entry['uuid'] = type('')(uuid.uuid4())
entries = oprefs['entries'] entries = oprefs['entries']
if file_type not in entries: if oft not in entries:
entries[file_type] = [] entries[oft] = []
entries[file_type].append(entry) entries[oft].append(entry)
entries[file_type].sort(key=entry_sort_key) entries[oft].sort(key=entry_sort_key)
oprefs['entries'] = entries oprefs['entries'] = entries
return entry return entry