openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #22022
[Merge] lp:~oliwee/openlp/1173749-2.0 into lp:openlp/2.0
Oliver Wieland has proposed merging lp:~oliwee/openlp/1173749-2.0 into lp:openlp/2.0.
Requested reviews:
Tim Bentley (trb143)
Raoul Snyman (raoul-snyman)
Related bugs:
Bug #1173749 in OpenLP: "Songs with mismatching formatting tags still throw an exception"
https://bugs.launchpad.net/openlp/+bug/1173749
Bug #1199639 in OpenLP: "Formatting tags opened and closed in different verses throw an exception "
https://bugs.launchpad.net/openlp/+bug/1199639
For more details, see:
https://code.launchpad.net/~oliwee/openlp/1173749-2.0/+merge/190415
Partially fix of Bug #1173749 and bug #1199639
Validates the tags in the lyrics on editing a song. If there are misplaced tags, a message box will appear.
Tags must be closed before the end of a verse.
--
https://code.launchpad.net/~oliwee/openlp/1173749-2.0/+merge/190415
Your team OpenLP Core is subscribed to branch lp:openlp/2.0.
=== modified file 'openlp/plugins/songs/forms/editsongform.py'
--- openlp/plugins/songs/forms/editsongform.py 2013-08-21 20:26:53 +0000
+++ openlp/plugins/songs/forms/editsongform.py 2013-10-10 16:24:37 +0000
@@ -132,6 +132,7 @@
self.audioListWidget.setAlternatingRowColors(True)
self.findVerseSplit = re.compile(u'---\[\]---\n', re.UNICODE)
self.whitespace = re.compile(r'\W+', re.UNICODE)
+ self.find_tags = re.compile(u'\{/?\w+\}', re.UNICODE)
def keyPressEvent(self, event):
"""
@@ -720,8 +721,53 @@
self.manager.save_object(book)
else:
return False
+ cnt_errors = 0
+ error_list = ''
+ verse_tag = []
+ verse_num = []
+ for i in range(self.verseListWidget.rowCount()):
+ item = self.verseListWidget.item(i, 0)
+ tags = self.find_tags.findall(item.text())
+ if self._validate_tags(tags) == False:
+ field = unicode(item.data(QtCore.Qt.UserRole).toString())
+ verse_tag.append(VerseType.translated_name(field[0]))
+ verse_num.append(field[1:])
+ cnt_errors += 1;
+ if cnt_errors > 0:
+ for i in range(cnt_errors):
+ error_list += '%s %s' % (verse_tag[i], verse_num[i])
+ if i < cnt_errors-1:
+ error_list += ', '
+ critical_error_message_box(
+ message=translate('SongsPlugin.EditSongForm',
+ 'There are misplaced formatting tags in the following verses:\n\n%s\n\n'
+ 'Please correct these tags before continuing.' % error_list))
+ return False
return True
+ def _validate_tags(self, _tags):
+ """
+ Validates a list of tags
+ Deletes the first affiliated tag pair which is located side by side in the list
+ and call itself recursively with the shortened tag list.
+ If there is any misplaced tag in the list, either the lenght of the tag list is not even,
+ or the function won't find any tag pairs side by side.
+ If there is no misplaced tag, the length of the list will be zero on any recursive run.
+
+ Return:
+ True if the function can't find any mismatched tags
+ False if there are mismatched tags.
+ """
+ if len(_tags) == 0:
+ return True
+ if len(_tags) % 2 != 0:
+ return False
+ for i in range(len(_tags)-1):
+ if _tags[i+1] == "{/" + _tags[i][1:]:
+ del _tags[i:i+2]
+ return self._validate_tags(_tags)
+ return False
+
def onCopyrightInsertButtonTriggered(self):
text = self.copyrightEdit.text()
pos = self.copyrightEdit.cursorPosition()
Follow ups