Send reference to GUI to store download jobs. This way db references are not stored in the download queue. This should prevent issues where the db or model reference is invalid because the user changed libraries during a download.

This commit is contained in:
John Schember 2011-03-12 08:48:48 -05:00
parent 5ec3737e30
commit 9f7eb04762

View File

@ -23,11 +23,11 @@ from calibre.utils.ipc.job import BaseJob
class EbookDownloadJob(BaseJob): class EbookDownloadJob(BaseJob):
def __init__(self, callback, description, job_manager, model, cookie_file=None, url='', filename='', save_as_loc='', add_to_lib=True, tags=[]): def __init__(self, callback, description, job_manager, gui, cookie_file=None, url='', filename='', save_as_loc='', add_to_lib=True, tags=[]):
BaseJob.__init__(self, description) BaseJob.__init__(self, description)
self.exception = None self.exception = None
self.job_manager = job_manager self.job_manager = job_manager
self.model = model self.gui = gui
self.cookie_file = cookie_file self.cookie_file = cookie_file
self.args = (url, filename, save_as_loc, add_to_lib, tags) self.args = (url, filename, save_as_loc, add_to_lib, tags)
self.tmp_file_name = '' self.tmp_file_name = ''
@ -175,10 +175,10 @@ class EbookDownloader(Thread):
mi = get_metadata(f, ext) mi = get_metadata(f, ext)
mi.tags.extend(tags) mi.tags.extend(tags)
id = job.model.db.create_book_entry(mi) id = job.gui.library_view.model().db.create_book_entry(mi)
job.model.db.add_format_with_hooks(id, ext.upper(), job.tmp_file_name, index_is_id=True) job.gui.library_view.model().db.add_format_with_hooks(id, ext.upper(), job.tmp_file_name, index_is_id=True)
job.model.books_added(1) job.gui.library_view.model().books_added(1)
job.model.count_changed() job.gui.library_view.model().count_changed()
def _save_as(self, job): def _save_as(self, job):
url, filename, save_loc, add_to_lib, tags = job.args url, filename, save_loc, add_to_lib, tags = job.args
@ -187,9 +187,9 @@ class EbookDownloader(Thread):
shutil.copy(job.tmp_file_name, save_loc) shutil.copy(job.tmp_file_name, save_loc)
def download_ebook(self, callback, model, cookie_file=None, url='', filename='', save_as_loc='', add_to_lib=True, tags=[]): def download_ebook(self, callback, gui, cookie_file=None, url='', filename='', save_as_loc='', add_to_lib=True, tags=[]):
description = _('Downloading %s') % filename if filename else url description = _('Downloading %s') % filename if filename else url
job = EbookDownloadJob(callback, description, self.job_manager, model, cookie_file, url, filename, save_as_loc, add_to_lib, tags) job = EbookDownloadJob(callback, description, self.job_manager, gui, cookie_file, url, filename, save_as_loc, add_to_lib, tags)
self.job_manager.add_job(job) self.job_manager.add_job(job)
self.jobs.put(job) self.jobs.put(job)
@ -205,7 +205,7 @@ class EbookDownloadMixin(object):
if tags: if tags:
if isinstance(tags, basestring): if isinstance(tags, basestring):
tags = tags.split(',') tags = tags.split(',')
self.ebook_downloader.download_ebook(Dispatcher(self.downloaded_ebook), self.library_view.model(), cookie_file, url, filename, save_as_loc, add_to_lib, tags) self.ebook_downloader.download_ebook(Dispatcher(self.downloaded_ebook), self, cookie_file, url, filename, save_as_loc, add_to_lib, tags)
self.status_bar.show_message(_('Downloading') + ' ' + filename if filename else url, 3000) self.status_bar.show_message(_('Downloading') + ' ' + filename if filename else url, 3000)
def downloaded_ebook(self, job): def downloaded_ebook(self, job):