diff --git a/src/calibre/gui2/actions/__init__.py b/src/calibre/gui2/actions/__init__.py index ebb030edb6..f70332d15a 100644 --- a/src/calibre/gui2/actions/__init__.py +++ b/src/calibre/gui2/actions/__init__.py @@ -296,6 +296,17 @@ class AddAction(object): # {{{ self.library_view.model().db.import_book(MetaInformation(None), []) self.library_view.model().books_added(num) + def add_isbns(self, isbns): + from calibre.ebooks.metadata import MetaInformation + ids = set([]) + for x in isbns: + mi = MetaInformation(None) + mi.isbn = x + ids.add(self.library_view.model().db.import_book(mi, [])) + self.library_view.model().books_added(len(isbns)) + self.do_download_metadata(ids) + + def files_dropped(self, paths): to_device = self.stack.currentIndex() != 0 self._add_books(paths, to_device) @@ -342,6 +353,12 @@ class AddAction(object): # {{{ def add_filesystem_book(self, paths, allow_device=True): self._add_filesystem_book(paths, allow_device=allow_device) + def add_from_isbn(self, *args): + from calibre.gui2.dialogs.add_from_isbn import AddFromISBN + d = AddFromISBN(self) + if d.exec_() == d.Accepted: + self.add_isbns(d.isbns) + def add_books(self, *args): ''' Add books from the local filesystem to either the library or the device. @@ -625,6 +642,13 @@ class EditMetadataAction(object): # {{{ return db = self.library_view.model().db ids = [db.id(row.row()) for row in rows] + self.do_download_metadata(ids, covers=covers, + set_metadata=set_metadata, + set_social_metadata=set_social_metadata) + + def do_download_metadata(self, ids, covers=True, set_metadata=True, + set_social_metadata=None): + db = self.library_view.model().db if set_social_metadata is None: get_social_metadata = config['get_social_metadata'] else: diff --git a/src/calibre/gui2/dialogs/add_from_isbn.py b/src/calibre/gui2/dialogs/add_from_isbn.py new file mode 100644 index 0000000000..a7bd578d61 --- /dev/null +++ b/src/calibre/gui2/dialogs/add_from_isbn.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai + +__license__ = 'GPL v3' +__copyright__ = '2010, Kovid Goyal ' +__docformat__ = 'restructuredtext en' + +from PyQt4.Qt import QDialog, QApplication + +from calibre.gui2.dialogs.add_from_isbn_ui import Ui_Dialog +from calibre.ebooks.metadata import check_isbn + +class AddFromISBN(QDialog, Ui_Dialog): + + def __init__(self, parent=None): + QDialog.__init__(self, parent) + self.setupUi(self) + + self.isbns = [] + self.paste_button.clicked.connect(self.paste) + + def paste(self, *args): + app = QApplication.instance() + c = app.clipboard() + txt = unicode(c.text()).strip() + if txt: + old = unicode(self.isbn_box.toPlainText()).strip() + new = old + '\n' + txt + self.isbn_box.setPlainText(new) + + def accept(self, *args): + for line in unicode(self.isbn_box.toPlainText()).strip().splitlines(): + if line: + isbn = check_isbn(line) + if isbn is not None: + isbn = isbn.upper() + if isbn not in self.isbns: + self.isbns.append(isbn) + QDialog.accept(self, *args) + diff --git a/src/calibre/gui2/dialogs/add_from_isbn.ui b/src/calibre/gui2/dialogs/add_from_isbn.ui new file mode 100644 index 0000000000..e4882f7d18 --- /dev/null +++ b/src/calibre/gui2/dialogs/add_from_isbn.ui @@ -0,0 +1,90 @@ + + + Dialog + + + + 0 + 0 + 678 + 430 + + + + Add books by ISBN + + + + :/images/add_book.svg:/images/add_book.svg + + + + + + + + + <p>Enter a list of ISBNs in the box to the left, one per line. calibre will automatically create entries for books based on the ISBN and download metadata and covers for them.<p>Any invalid ISBNs in the list will be ignored. + + + true + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + &Paste from clipboard + + + + + + + + + + + buttonBox + accepted() + Dialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Dialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/calibre/gui2/layout.py b/src/calibre/gui2/layout.py index d13b938902..8a919c59f5 100644 --- a/src/calibre/gui2/layout.py +++ b/src/calibre/gui2/layout.py @@ -538,8 +538,10 @@ class MainWindowMixin(object): self.add_menu.addAction(_('Add books from directories, including ' 'sub directories (Multiple books per directory, assumes every ' 'ebook file is a different book)'), self.add_recursive_multiple) + self.add_menu.addSeparator() self.add_menu.addAction(_('Add Empty book. (Book entry with no ' 'formats)'), self.add_empty) + self.add_menu.addAction(_('Add from ISBN'), self.add_from_isbn) self.action_add.setMenu(self.add_menu) self.action_add.triggered.connect(self.add_books) self.action_del.triggered.connect(self.delete_books) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 7fe7deee5c..6a259a655f 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -1673,6 +1673,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): self.data.refresh_ids(self, [id]) # Needed to update format list and size if notify: self.notify('add', [id]) + return id def get_top_level_move_items(self): items = set(os.listdir(self.library_path))