diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index a699cebc..b73e9718 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -35,6 +35,7 @@ from addaddressdialog import * from newsubscriptiondialog import * from regenerateaddresses import * from newchandialog import * +from safehtmlparser import * from specialaddressbehavior import * from emailgateway import * from settings import * @@ -4026,10 +4027,9 @@ class MyForm(settingsmixin.SMainWindow): data = self.getCurrentMessageId() if data != False: message = "Error occurred: could not load message from disk." - message = unicode(message, 'utf-8)') messageTextedit.setCurrentFont(QtGui.QFont()) messageTextedit.setTextColor(QtGui.QColor()) - messageTextedit.setPlainText(message) + messageTextedit.setContent(message) def tableWidgetAddressBookItemChanged(self): currentRow = self.ui.tableWidgetAddressBook.currentRow() diff --git a/src/bitmessageqt/bitmessageui.py b/src/bitmessageqt/bitmessageui.py index e303567f..7a565d1c 100644 --- a/src/bitmessageqt/bitmessageui.py +++ b/src/bitmessageqt/bitmessageui.py @@ -8,6 +8,7 @@ # WARNING! All changes made in this file will be lost! from PyQt4 import QtCore, QtGui +from messageview import MessageView import settingsmixin try: @@ -123,7 +124,7 @@ class Ui_MainWindow(object): self.tableWidgetInbox.verticalHeader().setVisible(False) self.tableWidgetInbox.verticalHeader().setDefaultSectionSize(26) self.verticalSplitter_7.addWidget(self.tableWidgetInbox) - self.textEditInboxMessage = QtGui.QTextEdit(self.inbox) + self.textEditInboxMessage = MessageView(self.inbox) self.textEditInboxMessage.setBaseSize(QtCore.QSize(0, 500)) self.textEditInboxMessage.setReadOnly(True) self.textEditInboxMessage.setObjectName(_fromUtf8("textEditInboxMessage")) @@ -428,7 +429,7 @@ class Ui_MainWindow(object): self.tableWidgetInboxSubscriptions.verticalHeader().setVisible(False) self.tableWidgetInboxSubscriptions.verticalHeader().setDefaultSectionSize(26) self.verticalSplitter_4.addWidget(self.tableWidgetInboxSubscriptions) - self.textEditInboxMessageSubscriptions = QtGui.QTextEdit(self.subscriptions) + self.textEditInboxMessageSubscriptions = MessageView(self.subscriptions) self.textEditInboxMessageSubscriptions.setBaseSize(QtCore.QSize(0, 500)) self.textEditInboxMessageSubscriptions.setReadOnly(True) self.textEditInboxMessageSubscriptions.setObjectName(_fromUtf8("textEditInboxMessageSubscriptions")) @@ -527,7 +528,7 @@ class Ui_MainWindow(object): self.tableWidgetInboxChans.verticalHeader().setVisible(False) self.tableWidgetInboxChans.verticalHeader().setDefaultSectionSize(26) self.verticalSplitter_8.addWidget(self.tableWidgetInboxChans) - self.textEditInboxMessageChans = QtGui.QTextEdit(self.chans) + self.textEditInboxMessageChans = MessageView(self.chans) self.textEditInboxMessageChans.setBaseSize(QtCore.QSize(0, 500)) self.textEditInboxMessageChans.setReadOnly(True) self.textEditInboxMessageChans.setObjectName(_fromUtf8("textEditInboxMessageChans")) diff --git a/src/bitmessageqt/messageview.py b/src/bitmessageqt/messageview.py new file mode 100644 index 00000000..94e73ff1 --- /dev/null +++ b/src/bitmessageqt/messageview.py @@ -0,0 +1,44 @@ +from PyQt4 import QtCore, QtGui + +from safehtmlparser import * + +class MessageView(QtGui.QTextEdit): + MODE_PLAIN = 0 + MODE_HTML = 1 + TEXT_PLAIN = "HTML detected, click here to display" + TEXT_HTML = "Click here to disable HTML" + + def __init__(self, parent = 0): + super(MessageView, self).__init__(parent) + self.mode = MessageView.MODE_PLAIN + self.html = None + + def mousePressEvent(self, event): + #text = textCursor.block().text() + if event.button() == QtCore.Qt.LeftButton and self.html.has_html and self.cursorForPosition(event.pos()).block().blockNumber() == 0: + if self.mode == MessageView.MODE_PLAIN: + self.showHTML() + else: + self.showPlain() + else: + super(MessageView, self).mousePressEvent(event) + + def showPlain(self): + self.mode = MessageView.MODE_PLAIN + out = self.html.raw + if self.html.has_html: + out = "