diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index 32ae9271c..ee04ed545 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -192,6 +192,7 @@ class ServiceItem(object): service items to see if they are the same. """ self._uuid = unicode(uuid.uuid1()) + self.validate_item() def add_capability(self, capability): """ @@ -614,8 +615,25 @@ class ServiceItem(object): if self.get_frame_path(frame=frame) in invalid_paths: self.remove_frame(frame) - def validate(self): + def missing_frames(self): """ - Validates this service item + Returns if there are any frames in the service item """ return bool(self._raw_frames) + + def validate_item(self, suffix_list=None): + """ + Validates a service item to make sure it is valid + """ + self.is_valid = True + for frame in self._raw_frames: + if self.is_image() and not os.path.exists((frame[u'path'])): + self.is_valid = False + elif self.is_command(): + file = os.path.join(frame[u'path'],frame[u'title']) + if not os.path.exists(file): + self.is_valid = False + if suffix_list: + type = frame[u'title'].split(u'.')[-1] + if type.lower() not in suffix_list: + self.is_valid = False diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 42d82c7bb..7d1663b8e 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -536,7 +536,7 @@ class ServiceManager(QtGui.QWidget): 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(): + if item[u'service_item'].missing_frames(): self.serviceItems.remove(item) else: service_item = item[u'service_item'].get_service_repr(self._saveLite) @@ -795,7 +795,7 @@ class ServiceManager(QtGui.QWidget): serviceItem.set_from_service(item) else: serviceItem.set_from_service(item, self.servicePath) - self.validateItem(serviceItem) + serviceItem.validate_item(self.suffixes) self.load_item_uuid = 0 if serviceItem.is_capable(ItemCapabilities.OnLoadUpdate): Receiver.send_message(u'%s_service_load' % @@ -1215,18 +1215,6 @@ class ServiceManager(QtGui.QWidget): self.serviceManagerList.setCurrentItem(treewidgetitem) treewidgetitem.setExpanded(item[u'expanded']) - def validateItem(self, serviceItem): - """ - Validates the service item and if the suffix matches an accepted - one it allows the item to be displayed. - """ - #@todo check file items exist - if serviceItem.is_command(): - type = serviceItem._raw_frames[0][u'title'].split(u'.')[-1] - if type.lower() not in self.suffixes: - serviceItem.is_valid = False - #@todo check file items exist - def cleanUp(self): """ Empties the servicePath of temporary files on system exit. diff --git a/testing/conftest.py b/tests/conftest.py similarity index 100% rename from testing/conftest.py rename to tests/conftest.py diff --git a/testing/run.py b/tests/run.py similarity index 100% rename from testing/run.py rename to tests/run.py diff --git a/testing/test_app.py b/tests/test_app.py similarity index 99% rename from testing/test_app.py rename to tests/test_app.py index 53e2eab0a..c0b1e651a 100644 --- a/testing/test_app.py +++ b/tests/test_app.py @@ -34,4 +34,4 @@ from openlp.core.ui.mainwindow import MainWindow def test_start_app(openlpapp): assert type(openlpapp) == OpenLP assert type(openlpapp.mainWindow) == MainWindow - assert unicode(openlpapp.mainWindow.windowTitle()) == u'OpenLP 2.0' + assert unicode(openlpapp.mainWindow.windowTitle()) == u'OpenLP 2.1'