Fixes bug1065423 "Missing image in service causes traceback when opening"

Fixes bug1065420 ""missing files" dialog opens more then once when more files are missing"
This commit is contained in:
Philip Ridout 2012-10-27 10:06:33 +01:00
parent 0e4aeaac76
commit fafe262adc

View File

@ -349,6 +349,16 @@ class ServiceManager(QtGui.QWidget):
""" """
return self._modified return self._modified
def get_frame_file_path(self, item, frame):
"""
Getter to get service item file path.
"""
if item[u'service_item'].is_image():
path_from = frame[u'path']
else:
path_from = os.path.join(frame[u'path'], frame[u'title'])
return path_from
def setFileName(self, fileName): def setFileName(self, fileName):
""" """
Setter for service file. Setter for service file.
@ -483,58 +493,65 @@ class ServiceManager(QtGui.QWidget):
path) path)
service = [] service = []
write_list = [] write_list = []
missing_list = []
audio_files = [] audio_files = []
total_size = 0 total_size = 0
Receiver.send_message(u'cursor_busy') Receiver.send_message(u'cursor_busy')
# Number of items + 1 to zip it # Number of items + 1 to zip it
self.mainwindow.displayProgressBar(len(self.serviceItems) + 1) self.mainwindow.displayProgressBar(len(self.serviceItems) + 1)
# Get list of missing files, and list of files to write
for item in self.serviceItems: for item in self.serviceItems:
if not item[u'service_item'].uses_file():
continue
for frame in item[u'service_item'].get_frames():
path_from = self.get_frame_file_path(item, frame)
if path_from in write_list or path_from in missing_list:
continue
if not os.path.exists(path_from):
missing_list.append(path_from)
else:
write_list.append(path_from)
if missing_list:
Receiver.send_message(u'cursor_normal')
title = unicode(translate('OpenLP.ServiceManager',
'Service File(s) Missing'))
message = unicode(translate('OpenLP.ServiceManager',
'The following file(s) in the service are missing:\n\t%s\n\n'
'These files will be removed if you continue to save.')
) % "\n\t".join(missing_list)
answer = QtGui.QMessageBox.critical(self, title,
message,
QtGui.QMessageBox.StandardButtons(
QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel))
if answer == QtGui.QMessageBox.Cancel:
self.mainwindow.finishedProgressBar()
return False
Receiver.send_message(u'cursor_busy')
# Check if item contains a missing file.
for item in list(self.serviceItems):
self.mainwindow.incrementProgressBar() self.mainwindow.incrementProgressBar()
if item[u'service_item'].uses_file():
for frame in item[u'service_item'].get_frames():
path_from = self.get_frame_file_path(item, frame)
if path_from in missing_list:
item[u'service_item']._raw_frames.remove(frame)
if not item[u'service_item']._raw_frames:
self.serviceItems.remove(item)
else:
service_item = item[u'service_item'].get_service_repr() service_item = item[u'service_item'].get_service_repr()
# Get all the audio files, and ready them for embedding in the
# service file.
if service_item[u'header'][u'background_audio']: if service_item[u'header'][u'background_audio']:
for i, filename in\ for i, filename in\
enumerate(service_item[u'header'][u'background_audio']): enumerate(service_item[u'header'][u'background_audio']):
new_file = os.path.join(u'audio', new_file = os.path.join(u'audio',
item[u'service_item']._uuid, filename) item[u'service_item']._uuid, filename)
audio_files.append((filename, new_file)) audio_files.append((filename, new_file))
service_item[u'header'][u'background_audio'][i] = new_file service_item[u'header'][u'background_audio'][i] = \
new_file
# Add the service item to the service. # Add the service item to the service.
service.append({u'serviceitem': service_item}) service.append({u'serviceitem': service_item})
if not item[u'service_item'].uses_file(): self.repaintServiceList(-1, -1)
continue for file in write_list:
skipMissing = False file_size = os.path.getsize(file)
for frame in item[u'service_item'].get_frames():
if item[u'service_item'].is_image():
path_from = frame[u'path']
else:
path_from = os.path.join(frame[u'path'], frame[u'title'])
# Only write a file once
if path_from in write_list:
continue
if not os.path.exists(path_from):
if not skipMissing:
Receiver.send_message(u'cursor_normal')
title = unicode(translate('OpenLP.ServiceManager',
'Service File Missing'))
message = unicode(translate('OpenLP.ServiceManager',
'File missing from service\n\n %s \n\n'
'Continue saving?')) % path_from
answer = QtGui.QMessageBox.critical(self, title,
message,
QtGui.QMessageBox.StandardButtons(
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No |
QtGui.QMessageBox.YesToAll))
if answer == QtGui.QMessageBox.No:
self.mainwindow.finishedProgressBar()
return False
if answer == QtGui.QMessageBox.YesToAll:
skipMissing = True
Receiver.send_message(u'cursor_busy')
else:
file_size = os.path.getsize(path_from)
write_list.append(path_from)
total_size += file_size total_size += file_size
log.debug(u'ServiceManager.saveFile - ZIP contents size is %i bytes' % log.debug(u'ServiceManager.saveFile - ZIP contents size is %i bytes' %
total_size) total_size)