Jobs list: Fix killing of job killing the wrong job if other jobs are completed while waiting for kill confirmation.

Merge branch 'master' of https://github.com/JimmXinu/calibre
This commit is contained in:
Kovid Goyal 2017-10-15 08:03:38 +05:30
commit c2f050ed2a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -249,6 +249,9 @@ class JobManager(QAbstractTableModel, AdaptSQP): # {{{
def row_to_job(self, row): def row_to_job(self, row):
return self.jobs[row] return self.jobs[row]
def rows_to_jobs(self, rows):
return [self.jobs[row] for row in rows]
def has_device_jobs(self, queued_also=False): def has_device_jobs(self, queued_also=False):
for job in self.jobs: for job in self.jobs:
if isinstance(job, DeviceJob): if isinstance(job, DeviceJob):
@ -300,8 +303,7 @@ class JobManager(QAbstractTableModel, AdaptSQP): # {{{
for r in xrange(len(self.jobs)): for r in xrange(len(self.jobs)):
self.dataChanged.emit(self.index(r, 0), self.index(r, 0)) self.dataChanged.emit(self.index(r, 0), self.index(r, 0))
def kill_job(self, row, view): def kill_job(self, job, view):
job = self.jobs[row]
if isinstance(job, DeviceJob): if isinstance(job, DeviceJob):
return error_dialog(view, _('Cannot kill job'), return error_dialog(view, _('Cannot kill job'),
_('Cannot kill jobs that communicate with the device')).exec_() _('Cannot kill jobs that communicate with the device')).exec_()
@ -313,8 +315,7 @@ class JobManager(QAbstractTableModel, AdaptSQP): # {{{
_('This job cannot be stopped'), show=True) _('This job cannot be stopped'), show=True)
self._kill_job(job) self._kill_job(job)
def kill_multiple_jobs(self, rows, view): def kill_multiple_jobs(self, jobs, view):
jobs = [self.jobs[row] for row in rows]
devjobs = [j for j in jobs if isinstance(j, DeviceJob)] devjobs = [j for j in jobs if isinstance(j, DeviceJob)]
if devjobs: if devjobs:
error_dialog(view, _('Cannot kill job'), error_dialog(view, _('Cannot kill job'),
@ -667,18 +668,18 @@ class JobsDialog(QDialog, Ui_JobsDialog):
indices = [self.proxy_model.mapToSource(index) for index in indices = [self.proxy_model.mapToSource(index) for index in
self.jobs_view.selectionModel().selectedRows()] self.jobs_view.selectionModel().selectedRows()]
indices = [i for i in indices if i.isValid()] indices = [i for i in indices if i.isValid()]
rows = [index.row() for index in indices] jobs = self.model.rows_to_jobs([index.row() for index in indices])
if not rows: if not jobs:
return error_dialog(self, _('No job'), return error_dialog(self, _('No job'),
_('No job selected'), show=True) _('No job selected'), show=True)
if question_dialog(self, _('Are you sure?'), if question_dialog(self, _('Are you sure?'),
ngettext('Do you really want to stop the selected job?', ngettext('Do you really want to stop the selected job?',
'Do you really want to stop all the selected jobs?', 'Do you really want to stop all the selected jobs?',
len(rows))): len(jobs))):
if len(rows) > 1: if len(jobs) > 1:
self.model.kill_multiple_jobs(rows, self) self.model.kill_multiple_jobs(jobs, self)
else: else:
self.model.kill_job(rows[0], self) self.model.kill_job(jobs[0], self)
def kill_all_jobs(self, *args): def kill_all_jobs(self, *args):
if question_dialog(self, _('Are you sure?'), if question_dialog(self, _('Are you sure?'),