Add context menu action to view message as richtext #101

Merged
Atheros1 merged 5 commits from master into master 2013-04-02 18:32:35 +02:00

View File

@ -509,7 +509,7 @@ class receiveDataThread(QThread):
if embeddedTime < (int(time.time())-maximumAgeOfAnObjectThatIAmWillingToAccept): if embeddedTime < (int(time.time())-maximumAgeOfAnObjectThatIAmWillingToAccept):
print 'The embedded time in this broadcast message is too old. Ignoring message.' print 'The embedded time in this broadcast message is too old. Ignoring message.'
return return
if self.payloadLength < 66: #todo: When version 1 addresses are completely abandoned, this should be changed to 180 if len(data) < 180:
print 'The payload length of this broadcast packet is unreasonably low. Someone is probably trying funny business. Ignoring message.' print 'The payload length of this broadcast packet is unreasonably low. Someone is probably trying funny business. Ignoring message.'
return return
inventoryLock.acquire() inventoryLock.acquire()
@ -533,11 +533,11 @@ class receiveDataThread(QThread):
self.processbroadcast(data)#When this function returns, we will have either successfully processed this broadcast because we are interested in it, ignored it because we aren't interested in it, or found problem with the broadcast that warranted ignoring it. self.processbroadcast(data)#When this function returns, we will have either successfully processed this broadcast because we are interested in it, ignored it because we aren't interested in it, or found problem with the broadcast that warranted ignoring it.
# Let us now set lengthOfTimeWeShouldUseToProcessThisMessage. If we haven't used the specified amount of time, we shall sleep. These values are mostly the same values used for msg messages although broadcast messages are processed faster. # Let us now set lengthOfTimeWeShouldUseToProcessThisMessage. If we haven't used the specified amount of time, we shall sleep. These values are mostly the same values used for msg messages although broadcast messages are processed faster.
if self.payloadLength > 100000000: #Size is greater than 100 megabytes if len(data) > 100000000: #Size is greater than 100 megabytes
lengthOfTimeWeShouldUseToProcessThisMessage = 100 #seconds. lengthOfTimeWeShouldUseToProcessThisMessage = 100 #seconds.
elif self.payloadLength > 10000000: #Between 100 and 10 megabytes elif len(data) > 10000000: #Between 100 and 10 megabytes
lengthOfTimeWeShouldUseToProcessThisMessage = 20 #seconds. lengthOfTimeWeShouldUseToProcessThisMessage = 20 #seconds.
elif self.payloadLength > 1000000: #Between 10 and 1 megabyte elif len(data) > 1000000: #Between 10 and 1 megabyte
lengthOfTimeWeShouldUseToProcessThisMessage = 3 #seconds. lengthOfTimeWeShouldUseToProcessThisMessage = 3 #seconds.
else: #Less than 1 megabyte else: #Less than 1 megabyte
lengthOfTimeWeShouldUseToProcessThisMessage = .1 #seconds. lengthOfTimeWeShouldUseToProcessThisMessage = .1 #seconds.
@ -714,11 +714,11 @@ class receiveDataThread(QThread):
self.processmsg(readPosition,data) #When this function returns, we will have either successfully processed the message bound for us, ignored it because it isn't bound for us, or found problem with the message that warranted ignoring it. self.processmsg(readPosition,data) #When this function returns, we will have either successfully processed the message bound for us, ignored it because it isn't bound for us, or found problem with the message that warranted ignoring it.
# Let us now set lengthOfTimeWeShouldUseToProcessThisMessage. If we haven't used the specified amount of time, we shall sleep. These values are based on test timings and you may change them at-will. # Let us now set lengthOfTimeWeShouldUseToProcessThisMessage. If we haven't used the specified amount of time, we shall sleep. These values are based on test timings and you may change them at-will.
if self.payloadLength > 100000000: #Size is greater than 100 megabytes if len(data) > 100000000: #Size is greater than 100 megabytes
lengthOfTimeWeShouldUseToProcessThisMessage = 100 #seconds. Actual length of time it took my computer to decrypt and verify the signature of a 100 MB message: 3.7 seconds. lengthOfTimeWeShouldUseToProcessThisMessage = 100 #seconds. Actual length of time it took my computer to decrypt and verify the signature of a 100 MB message: 3.7 seconds.
elif self.payloadLength > 10000000: #Between 100 and 10 megabytes elif len(data) > 10000000: #Between 100 and 10 megabytes
lengthOfTimeWeShouldUseToProcessThisMessage = 20 #seconds. Actual length of time it took my computer to decrypt and verify the signature of a 10 MB message: 0.53 seconds. Actual length of time it takes in practice when processing a real message: 1.44 seconds. lengthOfTimeWeShouldUseToProcessThisMessage = 20 #seconds. Actual length of time it took my computer to decrypt and verify the signature of a 10 MB message: 0.53 seconds. Actual length of time it takes in practice when processing a real message: 1.44 seconds.
elif self.payloadLength > 1000000: #Between 10 and 1 megabyte elif len(data) > 1000000: #Between 10 and 1 megabyte
lengthOfTimeWeShouldUseToProcessThisMessage = 3 #seconds. Actual length of time it took my computer to decrypt and verify the signature of a 1 MB message: 0.18 seconds. Actual length of time it takes in practice when processing a real message: 0.30 seconds. lengthOfTimeWeShouldUseToProcessThisMessage = 3 #seconds. Actual length of time it took my computer to decrypt and verify the signature of a 1 MB message: 0.18 seconds. Actual length of time it takes in practice when processing a real message: 0.30 seconds.
else: #Less than 1 megabyte else: #Less than 1 megabyte
lengthOfTimeWeShouldUseToProcessThisMessage = .6 #seconds. Actual length of time it took my computer to decrypt and verify the signature of a 100 KB message: 0.15 seconds. Actual length of time it takes in practice when processing a real message: 0.25 seconds. lengthOfTimeWeShouldUseToProcessThisMessage = .6 #seconds. Actual length of time it took my computer to decrypt and verify the signature of a 100 KB message: 0.15 seconds. Actual length of time it takes in practice when processing a real message: 0.25 seconds.
@ -1072,8 +1072,8 @@ class receiveDataThread(QThread):
printLock.release() printLock.release()
return return
if addressVersion == 2: if addressVersion == 2:
if self.payloadLength < 146: #sanity check. This is the minimum possible length. if len(data) < 146: #sanity check. This is the minimum possible length.
print 'payloadLength less than 146. Sanity check failed.' print '(within processpubkey) payloadLength less than 146. Sanity check failed.'
return return
bitfieldBehaviors = data[readPosition:readPosition+4] bitfieldBehaviors = data[readPosition:readPosition+4]
readPosition += 4 readPosition += 4
@ -1521,7 +1521,7 @@ class receiveDataThread(QThread):
#We have received a version message #We have received a version message
def recversion(self,data): def recversion(self,data):
if self.payloadLength < 83: if len(data) < 83:
#This version message is unreasonably short. Forget it. #This version message is unreasonably short. Forget it.
return return
elif not self.verackSent: elif not self.verackSent:
@ -3426,9 +3426,12 @@ class MyForm(QtGui.QMainWindow):
self.actionReply = self.ui.inboxContextMenuToolbar.addAction("Reply", self.on_action_InboxReply) self.actionReply = self.ui.inboxContextMenuToolbar.addAction("Reply", self.on_action_InboxReply)
self.actionAddSenderToAddressBook = self.ui.inboxContextMenuToolbar.addAction("Add sender to your Address Book", self.on_action_InboxAddSenderToAddressBook) self.actionAddSenderToAddressBook = self.ui.inboxContextMenuToolbar.addAction("Add sender to your Address Book", self.on_action_InboxAddSenderToAddressBook)
self.actionTrashInboxMessage = self.ui.inboxContextMenuToolbar.addAction("Move to Trash", self.on_action_InboxTrash) self.actionTrashInboxMessage = self.ui.inboxContextMenuToolbar.addAction("Move to Trash", self.on_action_InboxTrash)
self.actionForceHtml = self.ui.inboxContextMenuToolbar.addAction("View as Richtext", self.on_action_InboxMessageForceHtml)
self.ui.tableWidgetInbox.setContextMenuPolicy( QtCore.Qt.CustomContextMenu ) self.ui.tableWidgetInbox.setContextMenuPolicy( QtCore.Qt.CustomContextMenu )
self.connect(self.ui.tableWidgetInbox, QtCore.SIGNAL('customContextMenuRequested(const QPoint&)'), self.on_context_menuInbox) self.connect(self.ui.tableWidgetInbox, QtCore.SIGNAL('customContextMenuRequested(const QPoint&)'), self.on_context_menuInbox)
self.popMenuInbox = QtGui.QMenu( self ) self.popMenuInbox = QtGui.QMenu( self )
self.popMenuInbox.addAction( self.actionForceHtml )
self.popMenuInbox.addSeparator()
self.popMenuInbox.addAction( self.actionReply ) self.popMenuInbox.addAction( self.actionReply )
self.popMenuInbox.addAction( self.actionAddSenderToAddressBook ) self.popMenuInbox.addAction( self.actionAddSenderToAddressBook )
self.popMenuInbox.addSeparator() self.popMenuInbox.addSeparator()
@ -3600,6 +3603,7 @@ class MyForm(QtGui.QMainWindow):
newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled ) newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled )
self.ui.tableWidgetInbox.setItem(0,3,newItem) self.ui.tableWidgetInbox.setItem(0,3,newItem)
#self.ui.textEditInboxMessage.setPlainText(self.ui.tableWidgetInbox.item(0,2).data(Qt.UserRole).toPyObject()) #self.ui.textEditInboxMessage.setPlainText(self.ui.tableWidgetInbox.item(0,2).data(Qt.UserRole).toPyObject())
self.ui.tableWidgetInbox.sortItems(3,Qt.DescendingOrder)
self.ui.tableWidgetInbox.keyPressEvent = self.tableWidgetInboxKeyPressEvent self.ui.tableWidgetInbox.keyPressEvent = self.tableWidgetInboxKeyPressEvent
#Load Sent items from database #Load Sent items from database
@ -3662,6 +3666,7 @@ class MyForm(QtGui.QMainWindow):
newItem.setData(33,int(lastactiontime)) newItem.setData(33,int(lastactiontime))
newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled ) newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled )
self.ui.tableWidgetSent.setItem(0,3,newItem) self.ui.tableWidgetSent.setItem(0,3,newItem)
self.ui.tableWidgetSent.sortItems(3,Qt.DescendingOrder)
#Initialize the address book #Initialize the address book
sqlSubmitQueue.put('SELECT * FROM addressbook') sqlSubmitQueue.put('SELECT * FROM addressbook')
@ -4637,6 +4642,23 @@ class MyForm(QtGui.QMainWindow):
event.accept() event.accept()
raise SystemExit raise SystemExit
def on_action_InboxMessageForceHtml(self):
# Updated to work with all characters. Previously, non-english characters caused errors.
try:
lines = str(self.ui.textEditInboxMessage.toPlainText()).split('\n')
except UnicodeEncodeError:
currentInboxRow = self.ui.tableWidgetInbox.currentRow()
self.ui.textEditInboxMessage.setHtml(self.ui.tableWidgetInbox.item(currentInboxRow,2).data(Qt.UserRole).toPyObject())
return
from_prefix = 'Message ostensibly from '
for i in xrange(len(lines)):
if lines[i].find(from_prefix) != -1:
lines[i] = '<p style="font-size: 12px; color: grey;">%s<span style="font-size: 12px; color: black;">%s</span></p>' % (from_prefix,lines[i][24:-1])
elif lines[i] == '------------------------------------------------------':
lines[i] = '<hr>'
content = '\n'.join(lines)
content = content.replace('\n\n', '<br><br>')
self.ui.textEditInboxMessage.setHtml(QtCore.QString(content))
def on_action_InboxReply(self): def on_action_InboxReply(self):
currentInboxRow = self.ui.tableWidgetInbox.currentRow() currentInboxRow = self.ui.tableWidgetInbox.currentRow()