From 17e397ffa8dc2269f8217c3fab753ae698dc895f Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 14 Aug 2011 15:05:39 +0200 Subject: [PATCH] added spellchecker to service notes dialog (bug #825979); escape texts in various places (bug #825983) Fixes: https://launchpad.net/bugs/825983, https://launchpad.net/bugs/825979 --- openlp/core/lib/spelltextedit.py | 20 +++++++++++--------- openlp/core/ui/printservicedialog.py | 2 +- openlp/core/ui/printserviceform.py | 21 ++++++++++++--------- openlp/core/ui/servicemanager.py | 6 +++++- openlp/core/ui/servicenoteform.py | 4 ++-- 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/openlp/core/lib/spelltextedit.py b/openlp/core/lib/spelltextedit.py index b0bb61e92..e9b5e64f7 100644 --- a/openlp/core/lib/spelltextedit.py +++ b/openlp/core/lib/spelltextedit.py @@ -48,9 +48,10 @@ class SpellTextEdit(QtGui.QPlainTextEdit): """ Spell checking widget based on QPlanTextEdit. """ - def __init__(self, *args): + def __init__(self, parent=None, formatting_tags_allowed=True): global ENCHANT_AVAILABLE - QtGui.QPlainTextEdit.__init__(self, *args) + QtGui.QPlainTextEdit.__init__(self, parent) + self.formattingTagsAllowed = formatting_tags_allowed # Default dictionary based on the current locale. if ENCHANT_AVAILABLE: try: @@ -110,16 +111,17 @@ class SpellTextEdit(QtGui.QPlainTextEdit): spell_menu.addAction(action) # Only add the spelling suggests to the menu if there are # suggestions. - if len(spell_menu.actions()): + if spell_menu.actions(): popupMenu.insertMenu(popupMenu.actions()[0], spell_menu) tagMenu = QtGui.QMenu(translate('OpenLP.SpellTextEdit', 'Formatting Tags')) - for html in FormattingTags.get_html_tags(): - action = SpellAction(html[u'desc'], tagMenu) - action.correct.connect(self.htmlTag) - tagMenu.addAction(action) - popupMenu.insertSeparator(popupMenu.actions()[0]) - popupMenu.insertMenu(popupMenu.actions()[0], tagMenu) + if self.formattingTagsAllowed: + for html in FormattingTags.get_html_tags(): + action = SpellAction(html[u'desc'], tagMenu) + action.correct.connect(self.htmlTag) + tagMenu.addAction(action) + popupMenu.insertSeparator(popupMenu.actions()[0]) + popupMenu.insertMenu(popupMenu.actions()[0], tagMenu) popupMenu.exec_(event.globalPos()) def setLanguage(self, action): diff --git a/openlp/core/ui/printservicedialog.py b/openlp/core/ui/printservicedialog.py index b0065df99..8287ef02a 100644 --- a/openlp/core/ui/printservicedialog.py +++ b/openlp/core/ui/printservicedialog.py @@ -108,7 +108,7 @@ class Ui_PrintServiceDialog(object): self.footerLabel = QtGui.QLabel(self.optionsWidget) self.footerLabel.setObjectName(u'footerLabel') self.optionsLayout.addWidget(self.footerLabel) - self.footerTextEdit = SpellTextEdit(self.optionsWidget) + self.footerTextEdit = SpellTextEdit(self.optionsWidget, False) self.footerTextEdit.setObjectName(u'footerTextEdit') self.optionsLayout.addWidget(self.footerTextEdit) self.optionsGroupBox = QtGui.QGroupBox() diff --git a/openlp/core/ui/printserviceform.py b/openlp/core/ui/printserviceform.py index f50237619..55fc6eb3c 100644 --- a/openlp/core/ui/printserviceform.py +++ b/openlp/core/ui/printserviceform.py @@ -24,6 +24,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### +import cgi import datetime import os @@ -183,7 +184,7 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog): self._addElement(u'style', custom_css, html_data.head, attribute=(u'type', u'text/css')) self._addElement(u'body', parent=html_data) - self._addElement(u'h1', unicode(self.titleLineEdit.text()), + self._addElement(u'h1', cgi.escape(unicode(self.titleLineEdit.text())), html_data.body, classId=u'serviceTitle') for index, item in enumerate(self.serviceManager.serviceItems): self._addPreviewItem(html_data.body, item[u'service_item'], index) @@ -193,8 +194,9 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog): classId=u'customNotes') self._addElement(u'span', translate('OpenLP.ServiceManager', 'Custom Service Notes: '), div, classId=u'customNotesTitle') - self._addElement(u'span', self.footerTextEdit.toPlainText(), div, - classId=u'customNotesText') + self._addElement(u'span', + cgi.escape(self.footerTextEdit.toPlainText()), + div, classId=u'customNotesText') self.document.setHtml(html.tostring(html_data)) self.previewWidget.updatePreview() @@ -204,8 +206,8 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog): item_title = self._addElement(u'h2', parent=div, classId=u'itemTitle') self._addElement(u'img', parent=item_title, attribute=(u'src', item.icon)) - self._addElement(u'span', u' ' + item.get_display_title(), - item_title) + self._addElement(u'span', + u' ' + cgi.escape(item.get_display_title()), item_title) if self.slideTextCheckBox.isChecked(): # Add the text of the service item. if item.is_text(): @@ -230,8 +232,9 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog): foot_text = item.foot_text foot_text = foot_text.partition(u'
')[2] if foot_text: - foot = self._addElement(u'div', foot_text, parent=div, - classId=u'itemFooter') + foot_text = cgi.escape(foot_text.replace(u'
', u'\n')) + self._addElement(u'div', foot_text.replace(u'\n', u'
'), + parent=div, classId=u'itemFooter') # Add service items' notes. if self.notesCheckBox.isChecked(): if item.notes: @@ -239,8 +242,8 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog): self._addElement(u'span', translate('OpenLP.ServiceManager', 'Notes: '), p, classId=u'itemNotesTitle') - notes = self._addElement(u'span', - item.notes.replace(u'\n', u'
'), p, + self._addElement(u'span', + cgi.escape(unicode(item.notes)).replace(u'\n', u'
'), p, classId=u'itemNotesText') # Add play length of media files. if item.is_media() and self.metaDataCheckBox.isChecked(): diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 0ef45af12..3ab2e9239 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -24,6 +24,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### +import cgi import cPickle import logging import os @@ -719,6 +720,9 @@ class ServiceManager(QtGui.QWidget): self.setModified() def onStartTimeForm(self): + """ + Opens a dialog to type in service item notes. + """ item = self.findServiceItem()[0] self.startTimeForm.item = self.serviceItems[item] if self.startTimeForm.exec_(): @@ -957,7 +961,7 @@ class ServiceManager(QtGui.QWidget): if serviceitem.notes: tips.append(u'%s: %s' % (unicode(translate('OpenLP.ServiceManager', 'Notes')), - unicode(serviceitem.notes))) + cgi.escape(unicode(serviceitem.notes)))) if item[u'service_item'] \ .is_capable(ItemCapabilities.AllowsVariableStartTime): tips.append(item[u'service_item'].get_media_time()) diff --git a/openlp/core/ui/servicenoteform.py b/openlp/core/ui/servicenoteform.py index 3bc55e242..ddfcb3381 100644 --- a/openlp/core/ui/servicenoteform.py +++ b/openlp/core/ui/servicenoteform.py @@ -27,7 +27,7 @@ from PyQt4 import QtCore, QtGui -from openlp.core.lib import translate +from openlp.core.lib import translate, SpellTextEdit from openlp.core.lib.ui import create_accept_reject_button_box class ServiceNoteForm(QtGui.QDialog): @@ -52,7 +52,7 @@ class ServiceNoteForm(QtGui.QDialog): self.dialogLayout.setContentsMargins(8, 8, 8, 8) self.dialogLayout.setSpacing(8) self.dialogLayout.setObjectName(u'verticalLayout') - self.textEdit = QtGui.QTextEdit(self) + self.textEdit = SpellTextEdit(self, False) self.textEdit.setObjectName(u'textEdit') self.dialogLayout.addWidget(self.textEdit) self.dialogLayout.addWidget(create_accept_reject_button_box(self))