mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Save single format to disk: Only show the format available in the selected books. Fixes #1007287 (Save single format to disc menu)
This commit is contained in:
parent
b689b6facd
commit
2fe4e54ce4
@ -116,7 +116,7 @@ class DeleteAction(InterfaceAction):
|
|||||||
for action in list(self.delete_menu.actions())[1:]:
|
for action in list(self.delete_menu.actions())[1:]:
|
||||||
action.setEnabled(enabled)
|
action.setEnabled(enabled)
|
||||||
|
|
||||||
def _get_selected_formats(self, msg, ids, exclude=False):
|
def _get_selected_formats(self, msg, ids, exclude=False, single=False):
|
||||||
from calibre.gui2.dialogs.select_formats import SelectFormats
|
from calibre.gui2.dialogs.select_formats import SelectFormats
|
||||||
c = Counter()
|
c = Counter()
|
||||||
db = self.gui.library_view.model().db
|
db = self.gui.library_view.model().db
|
||||||
@ -125,7 +125,8 @@ class DeleteAction(InterfaceAction):
|
|||||||
if fmts_:
|
if fmts_:
|
||||||
for x in frozenset([x.lower() for x in fmts_.split(',')]):
|
for x in frozenset([x.lower() for x in fmts_.split(',')]):
|
||||||
c[x] += 1
|
c[x] += 1
|
||||||
d = SelectFormats(c, msg, parent=self.gui, exclude=exclude)
|
d = SelectFormats(c, msg, parent=self.gui, exclude=exclude,
|
||||||
|
single=single)
|
||||||
if d.exec_() != d.Accepted:
|
if d.exec_() != d.Accepted:
|
||||||
return None
|
return None
|
||||||
return d.selected_formats
|
return d.selected_formats
|
||||||
|
@ -8,30 +8,11 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import os
|
import os
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from PyQt4.Qt import QMenu, pyqtSignal
|
|
||||||
|
|
||||||
from calibre.utils.config import prefs
|
from calibre.utils.config import prefs
|
||||||
from calibre.gui2 import (error_dialog, Dispatcher, gprefs,
|
from calibre.gui2 import (error_dialog, Dispatcher, gprefs,
|
||||||
choose_dir, warning_dialog, open_local_file)
|
choose_dir, warning_dialog, open_local_file)
|
||||||
from calibre.gui2.actions import InterfaceAction
|
from calibre.gui2.actions import InterfaceAction
|
||||||
from calibre.ebooks import BOOK_EXTENSIONS
|
|
||||||
|
|
||||||
class SaveMenu(QMenu): # {{{
|
|
||||||
|
|
||||||
save_fmt = pyqtSignal(object)
|
|
||||||
|
|
||||||
def __init__(self, parent):
|
|
||||||
QMenu.__init__(self, _('Save single format to disk...'), parent)
|
|
||||||
for ext in sorted(BOOK_EXTENSIONS):
|
|
||||||
action = self.addAction(ext.upper())
|
|
||||||
setattr(self, 'do_'+ext, partial(self.do, ext))
|
|
||||||
action.triggered.connect(
|
|
||||||
getattr(self, 'do_'+ext))
|
|
||||||
|
|
||||||
def do(self, ext, *args):
|
|
||||||
self.save_fmt.emit(ext)
|
|
||||||
|
|
||||||
# }}}
|
|
||||||
|
|
||||||
class SaveToDiskAction(InterfaceAction):
|
class SaveToDiskAction(InterfaceAction):
|
||||||
|
|
||||||
@ -54,9 +35,8 @@ class SaveToDiskAction(InterfaceAction):
|
|||||||
_('Save only %s format to disk in a single directory')%
|
_('Save only %s format to disk in a single directory')%
|
||||||
prefs['output_format'].upper(),
|
prefs['output_format'].upper(),
|
||||||
triggered=partial(self.save_single_fmt_to_single_dir, False))
|
triggered=partial(self.save_single_fmt_to_single_dir, False))
|
||||||
self.save_sub_menu = SaveMenu(self.gui)
|
cm('specific format', _('Save single format to disk...'),
|
||||||
self.save_sub_menu_action = self.save_menu.addMenu(self.save_sub_menu)
|
triggered=self.save_specific_format_disk)
|
||||||
self.save_sub_menu.save_fmt.connect(self.save_specific_format_disk)
|
|
||||||
|
|
||||||
def location_selected(self, loc):
|
def location_selected(self, loc):
|
||||||
enabled = loc == 'library'
|
enabled = loc == 'library'
|
||||||
@ -74,8 +54,17 @@ class SaveToDiskAction(InterfaceAction):
|
|||||||
def save_single_format_to_disk(self, checked):
|
def save_single_format_to_disk(self, checked):
|
||||||
self.save_to_disk(checked, False, prefs['output_format'])
|
self.save_to_disk(checked, False, prefs['output_format'])
|
||||||
|
|
||||||
def save_specific_format_disk(self, fmt):
|
def save_specific_format_disk(self):
|
||||||
self.save_to_disk(False, False, fmt)
|
rb = self.gui.iactions['Remove Books']
|
||||||
|
ids = rb._get_selected_ids(err_title=
|
||||||
|
_('Cannot save to disk'))
|
||||||
|
if not ids: return
|
||||||
|
fmts = rb._get_selected_formats(
|
||||||
|
_('Choose format to save to disk'), ids,
|
||||||
|
single=True)
|
||||||
|
if not fmts:
|
||||||
|
return
|
||||||
|
self.save_to_disk(False, False, list(fmts)[0])
|
||||||
|
|
||||||
def save_to_single_dir(self, checked):
|
def save_to_single_dir(self, checked):
|
||||||
self.save_to_disk(checked, True)
|
self.save_to_disk(checked, True)
|
||||||
|
@ -50,6 +50,7 @@ class SelectFormats(QDialog):
|
|||||||
def __init__(self, fmt_count, msg, single=False, parent=None, exclude=False):
|
def __init__(self, fmt_count, msg, single=False, parent=None, exclude=False):
|
||||||
QDialog.__init__(self, parent)
|
QDialog.__init__(self, parent)
|
||||||
self._l = QVBoxLayout(self)
|
self._l = QVBoxLayout(self)
|
||||||
|
self.single_fmt = single
|
||||||
self.setLayout(self._l)
|
self.setLayout(self._l)
|
||||||
self.setWindowTitle(_('Choose formats'))
|
self.setWindowTitle(_('Choose formats'))
|
||||||
self._m = QLabel(msg)
|
self._m = QLabel(msg)
|
||||||
@ -57,6 +58,8 @@ class SelectFormats(QDialog):
|
|||||||
self._l.addWidget(self._m)
|
self._l.addWidget(self._m)
|
||||||
self.formats = Formats(fmt_count)
|
self.formats = Formats(fmt_count)
|
||||||
self.fview = QListView(self)
|
self.fview = QListView(self)
|
||||||
|
self.fview.doubleClicked.connect(self.double_clicked,
|
||||||
|
type=Qt.QueuedConnection)
|
||||||
if exclude:
|
if exclude:
|
||||||
self.fview.setStyleSheet('''
|
self.fview.setStyleSheet('''
|
||||||
QListView { background-color: #FAE7B5}
|
QListView { background-color: #FAE7B5}
|
||||||
@ -82,6 +85,11 @@ class SelectFormats(QDialog):
|
|||||||
self.selected_formats.add(self.formats.fmt(idx))
|
self.selected_formats.add(self.formats.fmt(idx))
|
||||||
QDialog.accept(self, *args)
|
QDialog.accept(self, *args)
|
||||||
|
|
||||||
|
def double_clicked(self, index):
|
||||||
|
if self.single_fmt:
|
||||||
|
self.accept()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from PyQt4.Qt import QApplication
|
from PyQt4.Qt import QApplication
|
||||||
app = QApplication([])
|
app = QApplication([])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user