Use SQL-stored message when using 'Display as HTML' feature

This commit is contained in:
Jonathan Warren 2013-10-16 01:08:22 -04:00
parent 24452cddb2
commit 7a30db75f1
2 changed files with 29 additions and 44 deletions

View File

@ -1632,44 +1632,12 @@ class MyForm(QtGui.QMainWindow):
sqlExecute( sqlExecute(
'''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t) '''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)
shared.workerQueue.put(('sendbroadcast', ''))
try:
fromLabel = shared.config.get(fromAddress, 'label')
except:
fromLabel = ''
if fromLabel == '':
fromLabel = fromAddress
toLabel = self.str_broadcast_subscribers toLabel = self.str_broadcast_subscribers
self.ui.tableWidgetSent.insertRow(0) self.displayNewSentMessage(
newItem = QtGui.QTableWidgetItem(unicode(toLabel, 'utf-8')) toAddress, toLabel, fromAddress, subject, message, ackdata)
newItem.setData(Qt.UserRole, str(toAddress))
self.ui.tableWidgetSent.setItem(0, 0, newItem)
if fromLabel == '': shared.workerQueue.put(('sendbroadcast', ''))
newItem = QtGui.QTableWidgetItem(
unicode(fromAddress, 'utf-8'))
else:
newItem = QtGui.QTableWidgetItem(
unicode(fromLabel, 'utf-8'))
newItem.setData(Qt.UserRole, str(fromAddress))
self.ui.tableWidgetSent.setItem(0, 1, newItem)
newItem = QtGui.QTableWidgetItem(unicode(subject, 'utf-8)'))
newItem.setData(Qt.UserRole, unicode(message, 'utf-8)'))
self.ui.tableWidgetSent.setItem(0, 2, newItem)
# newItem = QtGui.QTableWidgetItem('Doing work necessary to
# send broadcast...'+
# unicode(strftime(config.get('bitmessagesettings',
# 'timeformat'),localtime(int(time.time()))),'utf-8'))
newItem = myTableWidgetItem(_translate("MainWindow", "Work is queued."))
newItem.setData(Qt.UserRole, QByteArray(ackdata))
newItem.setData(33, int(time.time()))
self.ui.tableWidgetSent.setItem(0, 3, newItem)
self.ui.textEditSentMessage.setPlainText(
self.ui.tableWidgetSent.item(0, 2).data(Qt.UserRole).toPyObject())
self.ui.comboBoxSendFrom.setCurrentIndex(0) self.ui.comboBoxSendFrom.setCurrentIndex(0)
self.ui.labelFrom.setText('') self.ui.labelFrom.setText('')
@ -1778,7 +1746,7 @@ class MyForm(QtGui.QMainWindow):
newItem.setData(Qt.UserRole, QByteArray(ackdata)) newItem.setData(Qt.UserRole, QByteArray(ackdata))
newItem.setData(33, int(time.time())) newItem.setData(33, int(time.time()))
self.ui.tableWidgetSent.setItem(0, 3, newItem) self.ui.tableWidgetSent.setItem(0, 3, newItem)
self.ui.textEditSentMessage.setPlainText(message) self.ui.textEditSentMessage.setPlainText(unicode(message, 'utf-8)'))
self.ui.tableWidgetSent.setSortingEnabled(True) self.ui.tableWidgetSent.setSortingEnabled(True)
def displayNewInboxMessage(self, inventoryHash, toAddress, fromAddress, subject, message): def displayNewInboxMessage(self, inventoryHash, toAddress, fromAddress, subject, message):
@ -2254,10 +2222,18 @@ class MyForm(QtGui.QMainWindow):
def on_action_InboxMessageForceHtml(self): def on_action_InboxMessageForceHtml(self):
currentInboxRow = self.ui.tableWidgetInbox.currentRow() currentInboxRow = self.ui.tableWidgetInbox.currentRow()
lines = self.ui.tableWidgetInbox.item(
currentInboxRow, 2).data(Qt.UserRole).toPyObject().split('\n') msgid = str(self.ui.tableWidgetInbox.item(
currentInboxRow, 3).data(Qt.UserRole).toPyObject())
queryreturn = sqlQuery(
'''select message from inbox where msgid=?''', msgid)
if queryreturn != []:
for row in queryreturn:
messageAtCurrentInboxRow, = row
lines = messageAtCurrentInboxRow.split('\n')
for i in xrange(len(lines)): for i in xrange(len(lines)):
if lines[i].contains('Message ostensibly from '): if 'Message ostensibly from ' in lines[i]:
lines[i] = '<p style="font-size: 12px; color: grey;">%s</span></p>' % ( lines[i] = '<p style="font-size: 12px; color: grey;">%s</span></p>' % (
lines[i]) lines[i])
elif lines[i] == '------------------------------------------------------': elif lines[i] == '------------------------------------------------------':
@ -2381,14 +2357,23 @@ class MyForm(QtGui.QMainWindow):
subjectAtCurrentInboxRow = str(self.ui.tableWidgetInbox.item(currentInboxRow,2).text()) subjectAtCurrentInboxRow = str(self.ui.tableWidgetInbox.item(currentInboxRow,2).text())
except: except:
subjectAtCurrentInboxRow = '' subjectAtCurrentInboxRow = ''
# Retrieve the message data out of the SQL database
msgid = str(self.ui.tableWidgetInbox.item(
currentInboxRow, 3).data(Qt.UserRole).toPyObject())
queryreturn = sqlQuery(
'''select message from inbox where msgid=?''', msgid)
if queryreturn != []:
for row in queryreturn:
message, = row
defaultFilename = "".join(x for x in subjectAtCurrentInboxRow if x.isalnum()) + '.txt' defaultFilename = "".join(x for x in subjectAtCurrentInboxRow if x.isalnum()) + '.txt'
data = self.ui.tableWidgetInbox.item(currentInboxRow,2).data(Qt.UserRole).toPyObject()
filename = QFileDialog.getSaveFileName(self, _translate("MainWindow","Save As..."), defaultFilename, "Text files (*.txt);;All files (*.*)") filename = QFileDialog.getSaveFileName(self, _translate("MainWindow","Save As..."), defaultFilename, "Text files (*.txt);;All files (*.*)")
if filename == '': if filename == '':
return return
try: try:
f = open(filename, 'w') f = open(filename, 'w')
f.write( self.ui.tableWidgetInbox.item(currentInboxRow,2).data(Qt.UserRole).toPyObject() ) f.write(message)
f.close() f.close()
except Exception, e: except Exception, e:
sys.stderr.write('Write error: '+ e) sys.stderr.write('Write error: '+ e)

View File

@ -279,6 +279,8 @@ def reloadBroadcastSendersForWhichImWatching():
def doCleanShutdown(): def doCleanShutdown():
global shutdown global shutdown
shutdown = 1 #Used to tell proof of work worker threads to exit. shutdown = 1 #Used to tell proof of work worker threads to exit.
broadcastToSendDataQueues((0, 'shutdown', 'all'))
knownNodesLock.acquire() knownNodesLock.acquire()
UISignalQueue.put(('updateStatusBar','Saving the knownNodes list of peers to disk...')) UISignalQueue.put(('updateStatusBar','Saving the knownNodes list of peers to disk...'))
output = open(appdata + 'knownnodes.dat', 'wb') output = open(appdata + 'knownnodes.dat', 'wb')
@ -290,8 +292,6 @@ def doCleanShutdown():
logger.info('Finished closing knownnodes.dat output file.') logger.info('Finished closing knownnodes.dat output file.')
UISignalQueue.put(('updateStatusBar','Done saving the knownNodes list of peers to disk.')) UISignalQueue.put(('updateStatusBar','Done saving the knownNodes list of peers to disk.'))
broadcastToSendDataQueues((0, 'shutdown', 'all'))
logger.info('Flushing inventory in memory out to disk...') logger.info('Flushing inventory in memory out to disk...')
UISignalQueue.put(( UISignalQueue.put((
'updateStatusBar', 'updateStatusBar',