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
This commit is contained in:
Andreas Preikschat 2011-08-14 15:05:39 +02:00
parent cb16463d99
commit 17e397ffa8
5 changed files with 31 additions and 22 deletions

View File

@ -48,9 +48,10 @@ class SpellTextEdit(QtGui.QPlainTextEdit):
""" """
Spell checking widget based on QPlanTextEdit. Spell checking widget based on QPlanTextEdit.
""" """
def __init__(self, *args): def __init__(self, parent=None, formatting_tags_allowed=True):
global ENCHANT_AVAILABLE 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. # Default dictionary based on the current locale.
if ENCHANT_AVAILABLE: if ENCHANT_AVAILABLE:
try: try:
@ -110,10 +111,11 @@ class SpellTextEdit(QtGui.QPlainTextEdit):
spell_menu.addAction(action) spell_menu.addAction(action)
# Only add the spelling suggests to the menu if there are # Only add the spelling suggests to the menu if there are
# suggestions. # suggestions.
if len(spell_menu.actions()): if spell_menu.actions():
popupMenu.insertMenu(popupMenu.actions()[0], spell_menu) popupMenu.insertMenu(popupMenu.actions()[0], spell_menu)
tagMenu = QtGui.QMenu(translate('OpenLP.SpellTextEdit', tagMenu = QtGui.QMenu(translate('OpenLP.SpellTextEdit',
'Formatting Tags')) 'Formatting Tags'))
if self.formattingTagsAllowed:
for html in FormattingTags.get_html_tags(): for html in FormattingTags.get_html_tags():
action = SpellAction(html[u'desc'], tagMenu) action = SpellAction(html[u'desc'], tagMenu)
action.correct.connect(self.htmlTag) action.correct.connect(self.htmlTag)

View File

@ -108,7 +108,7 @@ class Ui_PrintServiceDialog(object):
self.footerLabel = QtGui.QLabel(self.optionsWidget) self.footerLabel = QtGui.QLabel(self.optionsWidget)
self.footerLabel.setObjectName(u'footerLabel') self.footerLabel.setObjectName(u'footerLabel')
self.optionsLayout.addWidget(self.footerLabel) self.optionsLayout.addWidget(self.footerLabel)
self.footerTextEdit = SpellTextEdit(self.optionsWidget) self.footerTextEdit = SpellTextEdit(self.optionsWidget, False)
self.footerTextEdit.setObjectName(u'footerTextEdit') self.footerTextEdit.setObjectName(u'footerTextEdit')
self.optionsLayout.addWidget(self.footerTextEdit) self.optionsLayout.addWidget(self.footerTextEdit)
self.optionsGroupBox = QtGui.QGroupBox() self.optionsGroupBox = QtGui.QGroupBox()

View File

@ -24,6 +24,7 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 # # with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
############################################################################### ###############################################################################
import cgi
import datetime import datetime
import os import os
@ -183,7 +184,7 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog):
self._addElement(u'style', custom_css, html_data.head, self._addElement(u'style', custom_css, html_data.head,
attribute=(u'type', u'text/css')) attribute=(u'type', u'text/css'))
self._addElement(u'body', parent=html_data) 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') html_data.body, classId=u'serviceTitle')
for index, item in enumerate(self.serviceManager.serviceItems): for index, item in enumerate(self.serviceManager.serviceItems):
self._addPreviewItem(html_data.body, item[u'service_item'], index) self._addPreviewItem(html_data.body, item[u'service_item'], index)
@ -193,8 +194,9 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog):
classId=u'customNotes') classId=u'customNotes')
self._addElement(u'span', translate('OpenLP.ServiceManager', self._addElement(u'span', translate('OpenLP.ServiceManager',
'Custom Service Notes: '), div, classId=u'customNotesTitle') 'Custom Service Notes: '), div, classId=u'customNotesTitle')
self._addElement(u'span', self.footerTextEdit.toPlainText(), div, self._addElement(u'span',
classId=u'customNotesText') cgi.escape(self.footerTextEdit.toPlainText()),
div, classId=u'customNotesText')
self.document.setHtml(html.tostring(html_data)) self.document.setHtml(html.tostring(html_data))
self.previewWidget.updatePreview() self.previewWidget.updatePreview()
@ -204,8 +206,8 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog):
item_title = self._addElement(u'h2', parent=div, classId=u'itemTitle') item_title = self._addElement(u'h2', parent=div, classId=u'itemTitle')
self._addElement(u'img', parent=item_title, self._addElement(u'img', parent=item_title,
attribute=(u'src', item.icon)) attribute=(u'src', item.icon))
self._addElement(u'span', u' ' + item.get_display_title(), self._addElement(u'span',
item_title) u' ' + cgi.escape(item.get_display_title()), item_title)
if self.slideTextCheckBox.isChecked(): if self.slideTextCheckBox.isChecked():
# Add the text of the service item. # Add the text of the service item.
if item.is_text(): if item.is_text():
@ -230,8 +232,9 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog):
foot_text = item.foot_text foot_text = item.foot_text
foot_text = foot_text.partition(u'<br>')[2] foot_text = foot_text.partition(u'<br>')[2]
if foot_text: if foot_text:
foot = self._addElement(u'div', foot_text, parent=div, foot_text = cgi.escape(foot_text.replace(u'<br>', u'\n'))
classId=u'itemFooter') self._addElement(u'div', foot_text.replace(u'\n', u'<br>'),
parent=div, classId=u'itemFooter')
# Add service items' notes. # Add service items' notes.
if self.notesCheckBox.isChecked(): if self.notesCheckBox.isChecked():
if item.notes: if item.notes:
@ -239,8 +242,8 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog):
self._addElement(u'span', self._addElement(u'span',
translate('OpenLP.ServiceManager', 'Notes: '), p, translate('OpenLP.ServiceManager', 'Notes: '), p,
classId=u'itemNotesTitle') classId=u'itemNotesTitle')
notes = self._addElement(u'span', self._addElement(u'span',
item.notes.replace(u'\n', u'<br>'), p, cgi.escape(unicode(item.notes)).replace(u'\n', u'<br>'), p,
classId=u'itemNotesText') classId=u'itemNotesText')
# Add play length of media files. # Add play length of media files.
if item.is_media() and self.metaDataCheckBox.isChecked(): if item.is_media() and self.metaDataCheckBox.isChecked():

View File

@ -24,6 +24,7 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 # # with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
############################################################################### ###############################################################################
import cgi
import cPickle import cPickle
import logging import logging
import os import os
@ -719,6 +720,9 @@ class ServiceManager(QtGui.QWidget):
self.setModified() self.setModified()
def onStartTimeForm(self): def onStartTimeForm(self):
"""
Opens a dialog to type in service item notes.
"""
item = self.findServiceItem()[0] item = self.findServiceItem()[0]
self.startTimeForm.item = self.serviceItems[item] self.startTimeForm.item = self.serviceItems[item]
if self.startTimeForm.exec_(): if self.startTimeForm.exec_():
@ -957,7 +961,7 @@ class ServiceManager(QtGui.QWidget):
if serviceitem.notes: if serviceitem.notes:
tips.append(u'<strong>%s: </strong> %s' % tips.append(u'<strong>%s: </strong> %s' %
(unicode(translate('OpenLP.ServiceManager', 'Notes')), (unicode(translate('OpenLP.ServiceManager', 'Notes')),
unicode(serviceitem.notes))) cgi.escape(unicode(serviceitem.notes))))
if item[u'service_item'] \ if item[u'service_item'] \
.is_capable(ItemCapabilities.AllowsVariableStartTime): .is_capable(ItemCapabilities.AllowsVariableStartTime):
tips.append(item[u'service_item'].get_media_time()) tips.append(item[u'service_item'].get_media_time())

View File

@ -27,7 +27,7 @@
from PyQt4 import QtCore, QtGui 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 from openlp.core.lib.ui import create_accept_reject_button_box
class ServiceNoteForm(QtGui.QDialog): class ServiceNoteForm(QtGui.QDialog):
@ -52,7 +52,7 @@ class ServiceNoteForm(QtGui.QDialog):
self.dialogLayout.setContentsMargins(8, 8, 8, 8) self.dialogLayout.setContentsMargins(8, 8, 8, 8)
self.dialogLayout.setSpacing(8) self.dialogLayout.setSpacing(8)
self.dialogLayout.setObjectName(u'verticalLayout') self.dialogLayout.setObjectName(u'verticalLayout')
self.textEdit = QtGui.QTextEdit(self) self.textEdit = SpellTextEdit(self, False)
self.textEdit.setObjectName(u'textEdit') self.textEdit.setObjectName(u'textEdit')
self.dialogLayout.addWidget(self.textEdit) self.dialogLayout.addWidget(self.textEdit)
self.dialogLayout.addWidget(create_accept_reject_button_box(self)) self.dialogLayout.addWidget(create_accept_reject_button_box(self))