mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add empty book: When adding empty book records to the library, add an option to also create empty EPUB files. Useful if you intend to subsequently edit these files with the calibre editor. You can access the add empty books feature by right clicking the Add Book button.
This commit is contained in:
parent
6ee6e6930e
commit
ba30d4d2fe
@ -13,7 +13,7 @@ from PyQt4.Qt import QPixmap, QTimer
|
||||
|
||||
from calibre import as_unicode
|
||||
from calibre.gui2 import (error_dialog, choose_files, choose_dir,
|
||||
warning_dialog, info_dialog)
|
||||
warning_dialog, info_dialog, gprefs)
|
||||
from calibre.gui2.dialogs.add_empty_book import AddEmptyBookDialog
|
||||
from calibre.gui2.dialogs.confirm_delete import confirm
|
||||
from calibre.gui2.dialogs.progress import ProgressDialog
|
||||
@ -25,6 +25,7 @@ from calibre.constants import filesystem_encoding
|
||||
from calibre.gui2.actions import InterfaceAction
|
||||
from calibre.gui2 import question_dialog
|
||||
from calibre.ebooks.metadata import MetaInformation
|
||||
from calibre.ptempfile import PersistentTemporaryFile
|
||||
|
||||
def get_filters():
|
||||
return [
|
||||
@ -194,6 +195,7 @@ class AddAction(InterfaceAction):
|
||||
dlg = AddEmptyBookDialog(self.gui, self.gui.library_view.model().db,
|
||||
author, series)
|
||||
if dlg.exec_() == dlg.Accepted:
|
||||
temp_files = []
|
||||
num = dlg.qty_to_add
|
||||
series = dlg.selected_series
|
||||
db = self.gui.library_view.model().db
|
||||
@ -203,7 +205,15 @@ class AddAction(InterfaceAction):
|
||||
if series:
|
||||
mi.series = series
|
||||
mi.series_index = db.get_next_series_num_for(series)
|
||||
ids.append(db.import_book(mi, []))
|
||||
fmts = []
|
||||
if gprefs.get('create_empty_epub_file', False):
|
||||
from calibre.ebooks.oeb.polish.create import create_book
|
||||
pt = PersistentTemporaryFile(suffix='.epub')
|
||||
pt.close()
|
||||
temp_files.append(pt.name)
|
||||
create_book(mi, pt.name)
|
||||
fmts = [pt.name]
|
||||
ids.append(db.import_book(mi, fmts))
|
||||
self.gui.library_view.model().books_added(num)
|
||||
if hasattr(self.gui, 'db_images'):
|
||||
self.gui.db_images.reset()
|
||||
@ -211,6 +221,8 @@ class AddAction(InterfaceAction):
|
||||
if ids:
|
||||
ids.reverse()
|
||||
self.gui.library_view.select_rows(ids)
|
||||
for path in temp_files:
|
||||
os.remove(path)
|
||||
|
||||
def add_isbns(self, books, add_tags=[]):
|
||||
self.isbn_books = list(books)
|
||||
|
@ -5,10 +5,11 @@ __license__ = 'GPL v3'
|
||||
|
||||
|
||||
from PyQt4.Qt import QDialog, QGridLayout, QLabel, QDialogButtonBox, \
|
||||
QApplication, QSpinBox, QToolButton, QIcon
|
||||
QApplication, QSpinBox, QToolButton, QIcon, QCheckBox
|
||||
from calibre.ebooks.metadata import string_to_authors
|
||||
from calibre.gui2.complete2 import EditWithComplete
|
||||
from calibre.utils.config import tweaks
|
||||
from calibre.gui2 import gprefs
|
||||
|
||||
class AddEmptyBookDialog(QDialog):
|
||||
|
||||
@ -61,12 +62,23 @@ class AddEmptyBookDialog(QDialog):
|
||||
self.sclear_button.clicked.connect(self.reset_series)
|
||||
self._layout.addWidget(self.sclear_button, 5, 1, 1, 1)
|
||||
|
||||
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
||||
self.create_epub = c = QCheckBox(_('Create an empty EPUB file as well'))
|
||||
c.setChecked(gprefs.get('create_empty_epub_file', False))
|
||||
c.setToolTip(_('Also create an empty EPUB file that you can subsequently edit'))
|
||||
self._layout.addWidget(c, 6, 0, 1, -1)
|
||||
|
||||
button_box = self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
||||
button_box.accepted.connect(self.accept)
|
||||
button_box.rejected.connect(self.reject)
|
||||
self._layout.addWidget(button_box)
|
||||
self._layout.addWidget(button_box, 7, 0, 1, -1)
|
||||
self.resize(self.sizeHint())
|
||||
|
||||
def accept(self):
|
||||
oval = gprefs.get('create_empty_epub_file', False)
|
||||
if self.create_epub.isChecked() != oval:
|
||||
gprefs['create_empty_epub_file'] = self.create_epub.isChecked()
|
||||
return QDialog.accept(self)
|
||||
|
||||
def reset_author(self, *args):
|
||||
self.authors_combo.setEditText(_('Unknown'))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user