When adding empty books, allow setting of the series for the new boks. Also select the newly added book records after adding.

This commit is contained in:
Kovid Goyal 2012-12-24 09:44:47 +05:30
parent 4edf62a269
commit 4892defbec
2 changed files with 43 additions and 4 deletions

View File

@ -151,7 +151,7 @@ class AddAction(InterfaceAction):
Add an empty book item to the library. This does not import any formats Add an empty book item to the library. This does not import any formats
from a book file. from a book file.
''' '''
author = None author = series = None
index = self.gui.library_view.currentIndex() index = self.gui.library_view.currentIndex()
if index.isValid(): if index.isValid():
raw = index.model().db.authors(index.row()) raw = index.model().db.authors(index.row())
@ -159,16 +159,27 @@ class AddAction(InterfaceAction):
authors = [a.strip().replace('|', ',') for a in raw.split(',')] authors = [a.strip().replace('|', ',') for a in raw.split(',')]
if authors: if authors:
author = authors[0] author = authors[0]
dlg = AddEmptyBookDialog(self.gui, self.gui.library_view.model().db, author) series = index.model().db.series(index.row())
dlg = AddEmptyBookDialog(self.gui, self.gui.library_view.model().db,
author, series)
if dlg.exec_() == dlg.Accepted: if dlg.exec_() == dlg.Accepted:
num = dlg.qty_to_add num = dlg.qty_to_add
series = dlg.selected_series
db = self.gui.library_view.model().db
ids = []
for x in xrange(num): for x in xrange(num):
mi = MetaInformation(_('Unknown'), dlg.selected_authors) mi = MetaInformation(_('Unknown'), dlg.selected_authors)
self.gui.library_view.model().db.import_book(mi, []) if series:
mi.series = series
mi.series_index = db.get_next_series_num_for(series)
ids.append(db.import_book(mi, []))
self.gui.library_view.model().books_added(num) self.gui.library_view.model().books_added(num)
if hasattr(self.gui, 'db_images'): if hasattr(self.gui, 'db_images'):
self.gui.db_images.reset() self.gui.db_images.reset()
self.gui.tags_view.recount() self.gui.tags_view.recount()
if ids:
ids.reverse()
self.gui.library_view.select_rows(ids)
def add_isbns(self, books, add_tags=[]): def add_isbns(self, books, add_tags=[]):
self.isbn_books = list(books) self.isbn_books = list(books)

View File

@ -12,7 +12,7 @@ from calibre.utils.config import tweaks
class AddEmptyBookDialog(QDialog): class AddEmptyBookDialog(QDialog):
def __init__(self, parent, db, author): def __init__(self, parent, db, author, series=None):
QDialog.__init__(self, parent) QDialog.__init__(self, parent)
self.db = db self.db = db
@ -45,6 +45,22 @@ class AddEmptyBookDialog(QDialog):
self.clear_button.clicked.connect(self.reset_author) self.clear_button.clicked.connect(self.reset_author)
self._layout.addWidget(self.clear_button, 3, 1, 1, 1) self._layout.addWidget(self.clear_button, 3, 1, 1, 1)
self.series_label = QLabel(_('Set the series of the new books to:'))
self._layout.addWidget(self.series_label, 4, 0, 1, 2)
self.series_combo = EditWithComplete(self)
self.authors_combo.setSizeAdjustPolicy(
self.authors_combo.AdjustToMinimumContentsLengthWithIcon)
self.series_combo.setEditable(True)
self._layout.addWidget(self.series_combo, 5, 0, 1, 1)
self.initialize_series(db, series)
self.sclear_button = QToolButton(self)
self.sclear_button.setIcon(QIcon(I('trash.png')))
self.sclear_button.setToolTip(_('Reset series'))
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) button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
button_box.accepted.connect(self.accept) button_box.accepted.connect(self.accept)
button_box.rejected.connect(self.reject) button_box.rejected.connect(self.reject)
@ -54,6 +70,9 @@ class AddEmptyBookDialog(QDialog):
def reset_author(self, *args): def reset_author(self, *args):
self.authors_combo.setEditText(_('Unknown')) self.authors_combo.setEditText(_('Unknown'))
def reset_series(self):
self.series_combo.setEditText('')
def initialize_authors(self, db, author): def initialize_authors(self, db, author):
au = author au = author
if not au: if not au:
@ -65,6 +84,11 @@ class AddEmptyBookDialog(QDialog):
self.authors_combo.set_add_separator(tweaks['authors_completer_append_separator']) self.authors_combo.set_add_separator(tweaks['authors_completer_append_separator'])
self.authors_combo.update_items_cache(db.all_author_names()) self.authors_combo.update_items_cache(db.all_author_names())
def initialize_series(self, db, series):
self.series_combo.show_initial_value(series or '')
self.series_combo.update_items_cache(db.all_series_names())
self.series_combo.set_separator(None)
@property @property
def qty_to_add(self): def qty_to_add(self):
return self.qty_spinbox.value() return self.qty_spinbox.value()
@ -73,6 +97,10 @@ class AddEmptyBookDialog(QDialog):
def selected_authors(self): def selected_authors(self):
return string_to_authors(unicode(self.authors_combo.text())) return string_to_authors(unicode(self.authors_combo.text()))
@property
def selected_series(self):
return unicode(self.series_combo.text())
if __name__ == '__main__': if __name__ == '__main__':
app = QApplication([]) app = QApplication([])
d = AddEmptyBookDialog() d = AddEmptyBookDialog()