mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Add option to save books to single output folder
This commit is contained in:
parent
baef59dce7
commit
c5daec10f1
@ -138,9 +138,9 @@ class BooksModel(QAbstractTableModel):
|
||||
''' 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):
|
||||
def save_to_disk(self, rows, path, single_dir=False):
|
||||
rows = [row.row() for row in rows]
|
||||
self.db.export_to_dir(path, rows, self.sorted_on[0] == 1)
|
||||
self.db.export_to_dir(path, rows, self.sorted_on[0] == 1, single_dir=single_dir)
|
||||
|
||||
def delete_books(self, indices):
|
||||
ids = [ self.id(i) for i in indices ]
|
||||
|
@ -125,10 +125,17 @@ class Main(MainWindow, Ui_MainWindow):
|
||||
QObject.connect(self.action_sync, SIGNAL("triggered(bool)"), self.sync_to_main_memory)
|
||||
QObject.connect(sm.actions()[0], SIGNAL('triggered(bool)'), self.sync_to_main_memory)
|
||||
QObject.connect(sm.actions()[1], SIGNAL('triggered(bool)'), self.sync_to_card)
|
||||
self.save_menu = QMenu()
|
||||
self.save_menu.addAction(_('Save to disk'))
|
||||
self.save_menu.addAction(_('Save to disk in a single directory'))
|
||||
|
||||
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.action_view, SIGNAL("triggered(bool)"), self.view_book)
|
||||
self.action_sync.setMenu(sm)
|
||||
self.action_edit.setMenu(md)
|
||||
self.action_save.setMenu(self.save_menu)
|
||||
self.news_menu = NewsMenu(self.customize_feeds)
|
||||
self.action_news.setMenu(self.news_menu)
|
||||
QObject.connect(self.news_menu, SIGNAL('fetch_news(PyQt_PyObject)'), self.fetch_news)
|
||||
@ -147,6 +154,7 @@ class Main(MainWindow, Ui_MainWindow):
|
||||
self.tool_bar.widgetForAction(self.action_edit).setPopupMode(QToolButton.MenuButtonPopup)
|
||||
self.tool_bar.widgetForAction(self.action_sync).setPopupMode(QToolButton.MenuButtonPopup)
|
||||
self.tool_bar.widgetForAction(self.action_convert).setPopupMode(QToolButton.MenuButtonPopup)
|
||||
self.tool_bar.widgetForAction(self.action_save).setPopupMode(QToolButton.MenuButtonPopup)
|
||||
self.tool_bar.setContextMenuPolicy(Qt.PreventContextMenu)
|
||||
|
||||
QObject.connect(self.config_button, SIGNAL('clicked(bool)'), self.do_config)
|
||||
@ -515,7 +523,10 @@ class Main(MainWindow, Ui_MainWindow):
|
||||
############################################################################
|
||||
|
||||
############################## Save to disk ################################
|
||||
def save_to_disk(self, checked):
|
||||
def save_to_single_dir(self, checked):
|
||||
self.save_to_disk(checked, True)
|
||||
|
||||
def save_to_disk(self, checked, single_dir=False):
|
||||
rows = self.current_view().selectionModel().selectedRows()
|
||||
if not rows or len(rows) == 0:
|
||||
d = error_dialog(self, _('Cannot save to disk'), _('No books selected'))
|
||||
@ -525,7 +536,7 @@ class Main(MainWindow, Ui_MainWindow):
|
||||
if not dir:
|
||||
return
|
||||
if self.current_view() == self.library_view:
|
||||
self.current_view().model().save_to_disk(rows, dir)
|
||||
self.current_view().model().save_to_disk(rows, dir, single_dir=single_dir)
|
||||
else:
|
||||
paths = self.current_view().model().paths(rows)
|
||||
self.job_manager.run_device_job(self.books_saved,
|
||||
|
@ -1281,7 +1281,7 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
self.conn.execute('VACUUM;')
|
||||
self.conn.commit()
|
||||
|
||||
def export_to_dir(self, dir, indices, byauthor=False):
|
||||
def export_to_dir(self, dir, indices, byauthor=False, single_dir=False):
|
||||
if not os.path.exists(dir):
|
||||
raise IOError('Target directory does not exist: '+dir)
|
||||
by_author = {}
|
||||
@ -1311,6 +1311,7 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
os.mkdir(tpath)
|
||||
mi = OPFCreator(self.get_metadata(idx))
|
||||
cover = self.cover(idx)
|
||||
if not single_dir:
|
||||
if cover is not None:
|
||||
f = open(os.path.join(tpath, 'cover.jpg'), 'wb')
|
||||
f.write(cover)
|
||||
@ -1324,9 +1325,12 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
data = self.format(idx, fmt)
|
||||
name = au + ' - ' + title if byauthor else title + ' - ' + au
|
||||
fname = name +'_'+id+'.'+fmt.lower()
|
||||
f = open(os.path.join(tpath, sanitize_file_name(fname)), 'w+b')
|
||||
fname = sanitize_file_name(fname)
|
||||
base = dir if single_dir else tpath
|
||||
f = open(os.path.join(base, fname), 'w+b')
|
||||
f.write(data)
|
||||
f.flush()
|
||||
f.seek(0)
|
||||
try:
|
||||
set_metadata(f, mi, fmt.lower())
|
||||
except:
|
||||
|
Loading…
x
Reference in New Issue
Block a user