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 list indices of all cells in index.row()'''
|
||||||
return [ self.index(index.row(), c) for c in range(self.columnCount(None))]
|
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]
|
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):
|
def delete_books(self, indices):
|
||||||
ids = [ self.id(i) for i in 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(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()[0], SIGNAL('triggered(bool)'), self.sync_to_main_memory)
|
||||||
QObject.connect(sm.actions()[1], SIGNAL('triggered(bool)'), self.sync_to_card)
|
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.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)
|
QObject.connect(self.action_view, SIGNAL("triggered(bool)"), self.view_book)
|
||||||
self.action_sync.setMenu(sm)
|
self.action_sync.setMenu(sm)
|
||||||
self.action_edit.setMenu(md)
|
self.action_edit.setMenu(md)
|
||||||
|
self.action_save.setMenu(self.save_menu)
|
||||||
self.news_menu = NewsMenu(self.customize_feeds)
|
self.news_menu = NewsMenu(self.customize_feeds)
|
||||||
self.action_news.setMenu(self.news_menu)
|
self.action_news.setMenu(self.news_menu)
|
||||||
QObject.connect(self.news_menu, SIGNAL('fetch_news(PyQt_PyObject)'), self.fetch_news)
|
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_edit).setPopupMode(QToolButton.MenuButtonPopup)
|
||||||
self.tool_bar.widgetForAction(self.action_sync).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_convert).setPopupMode(QToolButton.MenuButtonPopup)
|
||||||
|
self.tool_bar.widgetForAction(self.action_save).setPopupMode(QToolButton.MenuButtonPopup)
|
||||||
self.tool_bar.setContextMenuPolicy(Qt.PreventContextMenu)
|
self.tool_bar.setContextMenuPolicy(Qt.PreventContextMenu)
|
||||||
|
|
||||||
QObject.connect(self.config_button, SIGNAL('clicked(bool)'), self.do_config)
|
QObject.connect(self.config_button, SIGNAL('clicked(bool)'), self.do_config)
|
||||||
@ -515,7 +523,10 @@ class Main(MainWindow, Ui_MainWindow):
|
|||||||
############################################################################
|
############################################################################
|
||||||
|
|
||||||
############################## Save to disk ################################
|
############################## 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()
|
rows = self.current_view().selectionModel().selectedRows()
|
||||||
if not rows or len(rows) == 0:
|
if not rows or len(rows) == 0:
|
||||||
d = error_dialog(self, _('Cannot save to disk'), _('No books selected'))
|
d = error_dialog(self, _('Cannot save to disk'), _('No books selected'))
|
||||||
@ -525,7 +536,7 @@ class Main(MainWindow, Ui_MainWindow):
|
|||||||
if not dir:
|
if not dir:
|
||||||
return
|
return
|
||||||
if self.current_view() == self.library_view:
|
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:
|
else:
|
||||||
paths = self.current_view().model().paths(rows)
|
paths = self.current_view().model().paths(rows)
|
||||||
self.job_manager.run_device_job(self.books_saved,
|
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.execute('VACUUM;')
|
||||||
self.conn.commit()
|
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):
|
if not os.path.exists(dir):
|
||||||
raise IOError('Target directory does not exist: '+dir)
|
raise IOError('Target directory does not exist: '+dir)
|
||||||
by_author = {}
|
by_author = {}
|
||||||
@ -1311,6 +1311,7 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
|||||||
os.mkdir(tpath)
|
os.mkdir(tpath)
|
||||||
mi = OPFCreator(self.get_metadata(idx))
|
mi = OPFCreator(self.get_metadata(idx))
|
||||||
cover = self.cover(idx)
|
cover = self.cover(idx)
|
||||||
|
if not single_dir:
|
||||||
if cover is not None:
|
if cover is not None:
|
||||||
f = open(os.path.join(tpath, 'cover.jpg'), 'wb')
|
f = open(os.path.join(tpath, 'cover.jpg'), 'wb')
|
||||||
f.write(cover)
|
f.write(cover)
|
||||||
@ -1324,9 +1325,12 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
|||||||
data = self.format(idx, fmt)
|
data = self.format(idx, fmt)
|
||||||
name = au + ' - ' + title if byauthor else title + ' - ' + au
|
name = au + ' - ' + title if byauthor else title + ' - ' + au
|
||||||
fname = name +'_'+id+'.'+fmt.lower()
|
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.write(data)
|
||||||
f.flush()
|
f.flush()
|
||||||
|
f.seek(0)
|
||||||
try:
|
try:
|
||||||
set_metadata(f, mi, fmt.lower())
|
set_metadata(f, mi, fmt.lower())
|
||||||
except:
|
except:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user