diff --git a/src/calibre/gui2/library.py b/src/calibre/gui2/library.py
index ce9db76eed..d03716b54c 100644
--- a/src/calibre/gui2/library.py
+++ b/src/calibre/gui2/library.py
@@ -150,9 +150,13 @@ def row_indices(self, index):
''' Return list indices of all cells in index.row()'''
return [ self.index(index.row(), c) for c in range(self.columnCount(None))]
- def save_to_disk(self, rows, path, single_dir=False):
+ def save_to_disk(self, rows, path, single_dir=False, single_format=None):
rows = [row.row() for row in rows]
- self.db.export_to_dir(path, rows, self.sorted_on[0] == 1, single_dir=single_dir)
+ if single_format is None:
+ return self.db.export_to_dir(path, rows, self.sorted_on[0] == 1, single_dir=single_dir)
+ else:
+ return self.db.export_single_format_to_dir(path, rows, single_format)
+
def delete_books(self, indices):
ids = [ self.id(i) for i in indices ]
diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py
index d640a75733..636f0a888f 100644
--- a/src/calibre/gui2/main.py
+++ b/src/calibre/gui2/main.py
@@ -136,6 +136,7 @@ def __init__(self, single_instance, opts, parent=None):
self.save_menu = QMenu()
self.save_menu.addAction(_('Save to disk'))
self.save_menu.addAction(_('Save to disk in a single directory'))
+ self.save_menu.addAction(_('Save only %s format to disk')%Settings().get('save to disk single format', 'lrf').upper())
self.view_menu = QMenu()
self.view_menu.addAction(_('View'))
@@ -144,6 +145,7 @@ def __init__(self, single_instance, opts, parent=None):
QObject.connect(self.action_save, SIGNAL("triggered(bool)"), self.save_to_disk)
QObject.connect(self.save_menu.actions()[0], SIGNAL("triggered(bool)"), self.save_to_disk)
QObject.connect(self.save_menu.actions()[1], SIGNAL("triggered(bool)"), self.save_to_single_dir)
+ QObject.connect(self.save_menu.actions()[2], SIGNAL("triggered(bool)"), self.save_single_format_to_disk)
QObject.connect(self.action_view, SIGNAL("triggered(bool)"), self.view_book)
QObject.connect(self.view_menu.actions()[0], SIGNAL("triggered(bool)"), self.view_book)
QObject.connect(self.view_menu.actions()[1], SIGNAL("triggered(bool)"), self.view_specific_format)
@@ -662,20 +664,32 @@ def sync_to_device(self, on_card):
############################################################################
############################## Save to disk ################################
+ def save_single_format_to_disk(self, checked):
+ self.save_to_disk(checked, True, Settings().get('save to disk single format', 'lrf'))
+
def save_to_single_dir(self, checked):
self.save_to_disk(checked, True)
- def save_to_disk(self, checked, single_dir=False):
+ def save_to_disk(self, checked, single_dir=False, single_format=None):
rows = self.current_view().selectionModel().selectedRows()
if not rows or len(rows) == 0:
d = error_dialog(self, _('Cannot save to disk'), _('No books selected'))
d.exec_()
return
+
dir = choose_dir(self, 'save to disk dialog', ('Choose destination directory'))
if not dir:
return
if self.current_view() == self.library_view:
- self.current_view().model().save_to_disk(rows, dir, single_dir=single_dir)
+ failures = self.current_view().model().save_to_disk(rows, dir,
+ single_dir=single_dir, single_format=single_format)
+ if failures and single_format is not None:
+ msg = _('Could not save the following books to disk, because the %s format is not available for them:
')%single_format.upper()
+ for f in failures:
+ msg += '- %s
'%f[1]
+ msg += '
'
+ warning_dialog(self, _('Could not save some ebooks'), msg).exec_()
+ QDesktopServices.openUrl(QUrl('file:'+dir))
else:
paths = self.current_view().model().paths(rows)
self.job_manager.run_device_job(self.books_saved,
diff --git a/src/calibre/library/database.py b/src/calibre/library/database.py
index ceff444186..d80917108e 100644
--- a/src/calibre/library/database.py
+++ b/src/calibre/library/database.py
@@ -1548,6 +1548,25 @@ def recursive_import(self, root, single_book_per_directory=True):
if res is not None:
duplicates.extend(res)
return duplicates
+
+ def export_single_format_to_dir(self, dir, indices, format, index_is_id=False):
+ if not index_is_id:
+ indices = map(self.id, indices)
+ failures = []
+ for id in indices:
+ try:
+ data = self.format(id, format, index_is_id=True)
+ except:
+ failures.append((id, self.title(id, index_is_id=True)))
+ title = self.title(id, index_is_id=True)
+ au = self.authors(id, index_is_id=True)
+ if not au:
+ au = _('Unknown')
+ fname = '%s - %s.%s'%(title, au, format.lower())
+ fname = sanitize_file_name(fname)
+ open(os.path.join(dir, fname), 'wb').write(data)
+ return failures
+
class SearchToken(object):