diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index dd8875984d..6d7fd63378 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -24,6 +24,7 @@ from calibre.gui2 import APP_UID, warning_dialog, choose_files, error_dialog, \ max_available_height, config, info_dialog, \ available_width, GetMetadata from calibre.gui2.cover_flow import CoverFlow, DatabaseImages, pictureflowerror +from calibre.gui2.widgets import ProgressIndicator, WarningDialog from calibre.gui2.dialogs.scheduler import Scheduler from calibre.gui2.update import CheckForUpdates from calibre.gui2.dialogs.progress import ProgressDialog @@ -75,6 +76,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): Ui_MainWindow.__init__(self) self.setupUi(self) self.setWindowTitle(__appname__) + self.progress_indicator = ProgressIndicator(self) self.verbose = opts.verbose self.get_metadata = GetMetadata() self.read_settings() @@ -170,6 +172,9 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): md.addAction(_('Edit metadata individually')) md.addSeparator() md.addAction(_('Edit metadata in bulk')) + md.addSeparator() + md.addAction(_('Download metadata and covers')) + md.addAction(_('Download only metadata')) self.metadata_menu = md self.add_menu = QMenu() self.add_menu.addAction(_('Add books from a single directory')) @@ -196,6 +201,12 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): partial(self.edit_metadata, bulk=False)) QObject.connect(md.actions()[2], SIGNAL('triggered(bool)'), partial(self.edit_metadata, bulk=True)) + QObject.connect(md.actions()[4], SIGNAL('triggered(bool)'), + partial(self.download_metadata, covers=True)) + QObject.connect(md.actions()[5], SIGNAL('triggered(bool)'), + partial(self.download_metadata, covers=False)) + + self.save_menu = QMenu() self.save_menu.addAction(_('Save to disk')) self.save_menu.addAction(_('Save to disk in a single directory')) @@ -824,6 +835,54 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): ############################################################################ ############################### Edit metadata ############################## + + def download_metadata(self, checked, covers=True): + rows = self.library_view.selectionModel().selectedRows() + previous = self.library_view.currentIndex() + if not rows or len(rows) == 0: + d = error_dialog(self, _('Cannot download metadata'), + _('No books selected')) + d.exec_() + return + db = self.library_view.model().db + ids = [db.id(row.row()) for row in rows] + from calibre.gui2.metadata import DownloadMetadata + self._download_book_metadata = DownloadMetadata(db, ids, get_covers=covers) + self._download_book_metadata.start() + self.progress_indicator.start( + _('Downloading metadata for %d book(s)')%len(ids)) + self._book_metadata_download_check = QTimer(self) + self.connect(self._book_metadata_download_check, + SIGNAL('timeout()'), self.book_metadata_download_check) + self._book_metadata_download_check.start(100) + + def book_metadata_download_check(self): + if self._download_book_metadata.is_alive(): + return + self._book_metadata_download_check.stop() + self.progress_indicator.stop() + cr = self.library_view.currentIndex().row() + x = self._download_book_metadata + self._download_book_metadata = None + if x.exception is None: + db = self.library_view.model().refresh_ids( + x.updated, cr) + if x.failures: + details = ['
'+x.tb+'' + ConversionErrorDialog(self, _('Error'), err, + show=True) + + + + def edit_metadata(self, checked, bulk=None): ''' Edit metadata of selected books in library. diff --git a/src/calibre/gui2/metadata.py b/src/calibre/gui2/metadata.py new file mode 100644 index 0000000000..607fd6a41b --- /dev/null +++ b/src/calibre/gui2/metadata.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python +# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import with_statement + +__license__ = 'GPL v3' +__copyright__ = '2009, Kovid Goyal