forked from openlp/openlp
head
This commit is contained in:
commit
b312342475
@ -452,14 +452,27 @@ class ServiceItem(object):
|
||||
except IndexError:
|
||||
return u''
|
||||
|
||||
def get_frame_path(self, row=0):
|
||||
def get_frame_path(self, row=0, frame=None):
|
||||
"""
|
||||
Returns the path of the raw frame
|
||||
"""
|
||||
try:
|
||||
return self._raw_frames[row][u'path']
|
||||
except IndexError:
|
||||
return u''
|
||||
if not frame:
|
||||
try:
|
||||
frame = self._raw_frames[row]
|
||||
except IndexError:
|
||||
return u''
|
||||
if self.is_image():
|
||||
path_from = frame[u'path']
|
||||
else:
|
||||
path_from = os.path.join(frame[u'path'], frame[u'title'])
|
||||
return path_from
|
||||
|
||||
def remove_frame(self, frame):
|
||||
"""
|
||||
Remove the soecified frame from the item
|
||||
"""
|
||||
if frame in self._raw_frames:
|
||||
self._raw_frames.remove(frame)
|
||||
|
||||
def get_media_time(self):
|
||||
"""
|
||||
@ -496,3 +509,17 @@ class ServiceItem(object):
|
||||
self._new_item()
|
||||
self.render()
|
||||
|
||||
def remove_invalid_frames(self, invalid_paths=None):
|
||||
"""
|
||||
Remove invalid frames, such as ones where the file no longer exists.
|
||||
"""
|
||||
if self.uses_file():
|
||||
for frame in self.get_frames():
|
||||
if self.get_frame_path(frame=frame) in invalid_paths:
|
||||
self.remove_frame(frame)
|
||||
|
||||
def validate(self):
|
||||
"""
|
||||
Validates this service item
|
||||
"""
|
||||
return bool(self._raw_frames)
|
||||
|
@ -484,59 +484,62 @@ class ServiceManager(QtGui.QWidget):
|
||||
path)
|
||||
service = []
|
||||
write_list = []
|
||||
missing_list = []
|
||||
audio_files = []
|
||||
total_size = 0
|
||||
Receiver.send_message(u'cursor_busy')
|
||||
# Number of items + 1 to zip it
|
||||
self.mainwindow.displayProgressBar(len(self.serviceItems) + 1)
|
||||
# Get list of missing files, and list of files to write
|
||||
for item in self.serviceItems:
|
||||
self.mainwindow.incrementProgressBar()
|
||||
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']:
|
||||
for i, filename in \
|
||||
enumerate(service_item[u'header'][u'background_audio']):
|
||||
new_file = os.path.join(u'audio',
|
||||
item[u'service_item']._uuid, filename)
|
||||
audio_files.append((filename, new_file))
|
||||
service_item[u'header'][u'background_audio'][i] = new_file
|
||||
# Add the service item to the service.
|
||||
service.append({u'serviceitem': service_item})
|
||||
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']
|
||||
else:
|
||||
path_from = os.path.join(frame[u'path'], frame[u'title'])
|
||||
# Only write a file once
|
||||
if path_from in write_list:
|
||||
path_from = item[u'service_item'].get_frame_path(frame=frame)
|
||||
if path_from in write_list or path_from in missing_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')
|
||||
missing_list.append(path_from)
|
||||
else:
|
||||
file_size = os.path.getsize(path_from)
|
||||
write_list.append(path_from)
|
||||
total_size += file_size
|
||||
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()
|
||||
item[u'service_item'].remove_invalid_frames(missing_list)
|
||||
if not item[u'service_item'].validate():
|
||||
self.serviceItems.remove(item)
|
||||
else:
|
||||
service_item = item[u'service_item'].get_service_repr()
|
||||
if service_item[u'header'][u'background_audio']:
|
||||
for i, filename in enumerate(
|
||||
service_item[u'header'][u'background_audio']):
|
||||
new_file = os.path.join(u'audio',
|
||||
item[u'service_item']._uuid, filename)
|
||||
audio_files.append((filename, new_file))
|
||||
service_item[u'header'][u'background_audio'][i] = \
|
||||
new_file
|
||||
# Add the service item to the service.
|
||||
service.append({u'serviceitem': service_item})
|
||||
self.repaintServiceList(-1, -1)
|
||||
for file in write_list:
|
||||
file_size = os.path.getsize(file)
|
||||
total_size += file_size
|
||||
log.debug(u'ServiceManager.saveFile - ZIP contents size is %i bytes' %
|
||||
total_size)
|
||||
service_content = cPickle.dumps(service)
|
||||
|
@ -1351,7 +1351,7 @@ class SlideController(Controller):
|
||||
Respond to the arrival of a media service item
|
||||
"""
|
||||
log.debug(u'SlideController onMediaStart')
|
||||
file = os.path.join(item.get_frame_path(), item.get_frame_title())
|
||||
file = item.get_frame_path()
|
||||
self.mediaController.video(self, file, False, False, self.hideMode())
|
||||
if not self.isLive or self.mediaController.withLivePreview:
|
||||
self.previewDisplay.show()
|
||||
|
@ -330,7 +330,7 @@ class MessageListener(object):
|
||||
item = message[0]
|
||||
log.debug(u'Startup called with message %s' % message)
|
||||
hide_mode = message[2]
|
||||
file = os.path.join(item.get_frame_path(), item.get_frame_title())
|
||||
file = item.get_frame_path()
|
||||
self.handler = item.title
|
||||
if self.handler == self.mediaitem.Automatic:
|
||||
self.handler = self.mediaitem.findControllerByType(file)
|
||||
|
Loading…
Reference in New Issue
Block a user