fixed bug 802150 (Attempt to save a service causes a crash when image/media/presentation files do not exist)

bzr-revno: 1707
Fixes: https://launchpad.net/bugs/802150
This commit is contained in:
Stevan Pettit 2011-08-11 11:20:29 +02:00 committed by Andreas Preikschat
commit f92552735f

View File

@ -487,6 +487,7 @@ class ServiceManager(QtGui.QWidget):
item[u'service_item'].get_service_repr()})
if not item[u'service_item'].uses_file():
continue
skipMissing = False
for frame in item[u'service_item'].get_frames():
if item[u'service_item'].is_image():
path_from = frame[u'path']
@ -495,25 +496,29 @@ class ServiceManager(QtGui.QWidget):
# Only write a file once
if path_from in write_list:
continue
file_size = os.path.getsize(path_from)
size_limit = 52428800 # 50MiB
#if file_size > size_limit:
# # File exeeds size_limit bytes, ask user
# message = unicode(translate('OpenLP.ServiceManager',
# 'Do you want to include \n%.1f MB file "%s"\n'
# 'into the service file?\nThis may take some time.\n\n'
# 'Please note that you need to\ntake care of that file'
# ' yourself,\nif you leave it out.')) % \
# (file_size/1048576, os.path.split(path_from)[1])
# ans = QtGui.QMessageBox.question(self.mainwindow,
# translate('OpenLP.ServiceManager', 'Including Large '
# 'File'), message, QtGui.QMessageBox.StandardButtons(
# QtGui.QMessageBox.Ok|QtGui.QMessageBox.Cancel),
# QtGui.QMessageBox.Ok)
# if ans == QtGui.QMessageBox.Cancel:
# continue
write_list.append(path_from)
total_size += file_size
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
log.debug(u'ServiceManager.saveFile - ZIP contents size is %i bytes' %
total_size)
service_content = cPickle.dumps(service)