This commit is contained in:
Kovid Goyal 2011-04-11 17:19:38 -06:00
parent 71967fd4ba
commit d7438cbc49
3 changed files with 49 additions and 2 deletions

View File

@ -10,7 +10,7 @@ from functools import partial
from PyQt4.Qt import Qt, QMenu, QModelIndex
from calibre.gui2 import error_dialog, config
from calibre.gui2 import error_dialog, config, Dispatcher
from calibre.gui2.dialogs.metadata_single import MetadataSingleDialog
from calibre.gui2.dialogs.metadata_bulk import MetadataBulkDialog
from calibre.gui2.dialogs.confirm_delete import confirm
@ -88,6 +88,11 @@ class EditMetadataAction(InterfaceAction):
_('No books selected'), show=True)
db = self.gui.library_view.model().db
ids = [db.id(row.row()) for row in rows]
from calibre.gui2.metadata.bulk_download2 import start_download
start_download(self.gui, ids, Dispatcher(self.bulk_metadata_downloaded))
def bulk_metadata_downloaded(self, job):
print repr(job.result)
def download_metadata_old(self, checked, covers=True, set_metadata=True,
set_social_metadata=None):

View File

@ -7,5 +7,44 @@ __license__ = 'GPL v3'
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
from functools import partial
from PyQt4.Qt import QIcon
from calibre.gui2.dialogs.message_box import MessageBox
from calibre.gui2.threaded_jobs import ThreadedJob
def show_config(gui, parent):
from calibre.gui2.preferences import show_config_widget
show_config_widget('Sharing', 'Metadata download', parent=parent,
gui=gui, never_shutdown=True)
def start_download(gui, ids, callback):
q = MessageBox(MessageBox.QUESTION, _('Schedule download?'),
_('The download of metadata for <b>%d book(s)</b> will'
' run in the background. Proceed?')%len(ids),
show_copy_button=False, parent=gui)
b = q.bb.addButton(_('Configure download'), q.bb.ActionRole)
b.setIcon(QIcon(I('config.png')))
b.clicked.connect(partial(show_config, gui, q))
q.det_msg_toggle.setVisible(False)
ret = q.exec_()
b.clicked.disconnect()
if ret != q.Accepted:
return
job = ThreadedJob('metadata bulk download',
_('Download metadata for %d books')%len(ids),
download, (ids, gui.current_db), {}, callback)
gui.job_manager.run_threaded_job(job)
def download(ids, db, log=None, abort=None, notifications=None):
ids = list(ids)
metadata = [db.get_metadata(i, index_is_id=True, get_user_categories=False)
for i in ids]
return (ids, [mi.last_modified for mi in metadata])

View File

@ -91,7 +91,8 @@ class ThreadedJob(BaseJob):
try:
self.callback(self)
except:
pass
import traceback
traceback.print_exc()
self._cleanup()
def _cleanup(self):
@ -103,6 +104,8 @@ class ThreadedJob(BaseJob):
# No need to keep references to these around anymore
self.func = self.args = self.kwargs = self.notifications = None
# We can't delete self.callback as it might be a Dispatch object and if
# it is garbage collected it won't work
def kill(self):
if self.start_time is None: