Have bitmessageqt use sql helpers

This commit is contained in:
Grant T. Olson 2013-08-26 20:01:19 -04:00 committed by Grant T. Olson
parent 74cd6c24b2
commit 7a53d2950b

View File

@ -36,6 +36,7 @@ import debug
from debug import logger from debug import logger
import subprocess import subprocess
import datetime import datetime
from helper_sql import *
try: try:
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
@ -346,11 +347,7 @@ class MyForm(QtGui.QMainWindow):
self.loadSent() self.loadSent()
# Initialize the address book # Initialize the address book
shared.sqlLock.acquire() queryreturn = sqlQuery('SELECT * FROM addressbook')
shared.sqlSubmitQueue.put('SELECT * FROM addressbook')
shared.sqlSubmitQueue.put('')
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
for row in queryreturn: for row in queryreturn:
label, address = row label, address = row
self.ui.tableWidgetAddressBook.insertRow(0) self.ui.tableWidgetAddressBook.insertRow(0)
@ -561,7 +558,7 @@ class MyForm(QtGui.QMainWindow):
else: else:
where = "toaddress || fromaddress || subject || message" where = "toaddress || fromaddress || subject || message"
sqlQuery = ''' sql = '''
SELECT toaddress, fromaddress, subject, message, status, ackdata, lastactiontime SELECT toaddress, fromaddress, subject, message, status, ackdata, lastactiontime
FROM sent WHERE folder="sent" AND %s LIKE ? FROM sent WHERE folder="sent" AND %s LIKE ?
ORDER BY lastactiontime ORDER BY lastactiontime
@ -570,12 +567,7 @@ class MyForm(QtGui.QMainWindow):
while self.ui.tableWidgetSent.rowCount() > 0: while self.ui.tableWidgetSent.rowCount() > 0:
self.ui.tableWidgetSent.removeRow(0) self.ui.tableWidgetSent.removeRow(0)
t = (what,) queryreturn = sqlQuery(sql, what)
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put(sqlQuery)
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
for row in queryreturn: for row in queryreturn:
toAddress, fromAddress, subject, message, status, ackdata, lastactiontime = row toAddress, fromAddress, subject, message, status, ackdata, lastactiontime = row
subject = shared.fixPotentiallyInvalidUTF8Data(subject) subject = shared.fixPotentiallyInvalidUTF8Data(subject)
@ -588,13 +580,8 @@ class MyForm(QtGui.QMainWindow):
fromLabel = fromAddress fromLabel = fromAddress
toLabel = '' toLabel = ''
t = (toAddress,) queryreturn = sqlQuery(
shared.sqlLock.acquire() '''select label from addressbook where address=?''', toAddress)
shared.sqlSubmitQueue.put(
'''select label from addressbook where address=?''')
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
if queryreturn != []: if queryreturn != []:
for row in queryreturn: for row in queryreturn:
@ -691,7 +678,7 @@ class MyForm(QtGui.QMainWindow):
else: else:
where = "toaddress || fromaddress || subject || message" where = "toaddress || fromaddress || subject || message"
sqlQuery = ''' sql = '''
SELECT msgid, toaddress, fromaddress, subject, received, message, read SELECT msgid, toaddress, fromaddress, subject, received, message, read
FROM inbox WHERE folder="inbox" AND %s LIKE ? FROM inbox WHERE folder="inbox" AND %s LIKE ?
ORDER BY received ORDER BY received
@ -702,12 +689,7 @@ class MyForm(QtGui.QMainWindow):
font = QFont() font = QFont()
font.setBold(True) font.setBold(True)
t = (what,) queryreturn = sqlQuery(sql, what)
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put(sqlQuery)
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
for row in queryreturn: for row in queryreturn:
msgid, toAddress, fromAddress, subject, received, message, read = row msgid, toAddress, fromAddress, subject, received, message, read = row
subject = shared.fixPotentiallyInvalidUTF8Data(subject) subject = shared.fixPotentiallyInvalidUTF8Data(subject)
@ -723,26 +705,16 @@ class MyForm(QtGui.QMainWindow):
toLabel = toAddress toLabel = toAddress
fromLabel = '' fromLabel = ''
t = (fromAddress,) queryreturn = sqlQuery(
shared.sqlLock.acquire() '''select label from addressbook where address=?''', fromAddress)
shared.sqlSubmitQueue.put(
'''select label from addressbook where address=?''')
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
if queryreturn != []: if queryreturn != []:
for row in queryreturn: for row in queryreturn:
fromLabel, = row fromLabel, = row
if fromLabel == '': # If this address wasn't in our address book... if fromLabel == '': # If this address wasn't in our address book...
t = (fromAddress,) queryReturn = sqlQuery(
shared.sqlLock.acquire() '''select label from subscriptions where address=?''', fromAddress)
shared.sqlSubmitQueue.put(
'''select label from subscriptions where address=?''')
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
if queryreturn != []: if queryreturn != []:
for row in queryreturn: for row in queryreturn:
@ -883,12 +855,8 @@ class MyForm(QtGui.QMainWindow):
if not (self.mmapp.has_source("Subscriptions") or self.mmapp.has_source("Messages")): if not (self.mmapp.has_source("Subscriptions") or self.mmapp.has_source("Messages")):
return return
shared.sqlLock.acquire() queryreturn = sqlQuery(
shared.sqlSubmitQueue.put( '''SELECT toaddress, read FROM inbox WHERE msgid=?''', inventoryHash)
'''SELECT toaddress, read FROM inbox WHERE msgid=?''')
shared.sqlSubmitQueue.put(inventoryHash)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
for row in queryreturn: for row in queryreturn:
toAddress, read = row toAddress, read = row
if not read: if not read:
@ -904,12 +872,8 @@ class MyForm(QtGui.QMainWindow):
unreadMessages = 0 unreadMessages = 0
unreadSubscriptions = 0 unreadSubscriptions = 0
shared.sqlLock.acquire() queryreturn = sqlQuery(
shared.sqlSubmitQueue.put(
'''SELECT msgid, toaddress, read FROM inbox where folder='inbox' ''') '''SELECT msgid, toaddress, read FROM inbox where folder='inbox' ''')
shared.sqlSubmitQueue.put('')
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
for row in queryreturn: for row in queryreturn:
msgid, toAddress, read = row msgid, toAddress, read = row
@ -1156,9 +1120,7 @@ class MyForm(QtGui.QMainWindow):
def click_actionDeleteAllTrashedMessages(self): def click_actionDeleteAllTrashedMessages(self):
if QtGui.QMessageBox.question(self, _translate("MainWindow", "Delete trash?"), _translate("MainWindow", "Are you sure you want to delete all trashed messages?"), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) == QtGui.QMessageBox.No: if QtGui.QMessageBox.question(self, _translate("MainWindow", "Delete trash?"), _translate("MainWindow", "Are you sure you want to delete all trashed messages?"), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) == QtGui.QMessageBox.No:
return return
shared.sqlLock.acquire() sqlStoredProcedure('deleteandvacuume')
shared.sqlSubmitQueue.put('deleteandvacuume')
shared.sqlLock.release()
def click_actionRegenerateDeterministicAddresses(self): def click_actionRegenerateDeterministicAddresses(self):
self.regenerateAddressesDialogInstance = regenerateAddressesDialog( self.regenerateAddressesDialogInstance = regenerateAddressesDialog(
@ -1439,13 +1401,8 @@ class MyForm(QtGui.QMainWindow):
addressToLookup = str(self.ui.tableWidgetInbox.item( addressToLookup = str(self.ui.tableWidgetInbox.item(
i, 1).data(Qt.UserRole).toPyObject()) i, 1).data(Qt.UserRole).toPyObject())
fromLabel = '' fromLabel = ''
t = (addressToLookup,) queryreturn = sqlQuery(
shared.sqlLock.acquire() '''select label from addressbook where address=?''', addressToLookup)
shared.sqlSubmitQueue.put(
'''select label from addressbook where address=?''')
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
if queryreturn != []: if queryreturn != []:
for row in queryreturn: for row in queryreturn:
@ -1455,12 +1412,8 @@ class MyForm(QtGui.QMainWindow):
else: else:
# It might be a broadcast message. We should check for that # It might be a broadcast message. We should check for that
# label. # label.
shared.sqlLock.acquire() queryreturn = sqlQuery(
shared.sqlSubmitQueue.put( '''select label from subscriptions where address=?''', addressToLookup)
'''select label from subscriptions where address=?''')
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
if queryreturn != []: if queryreturn != []:
for row in queryreturn: for row in queryreturn:
@ -1506,13 +1459,8 @@ class MyForm(QtGui.QMainWindow):
addressToLookup = str(self.ui.tableWidgetSent.item( addressToLookup = str(self.ui.tableWidgetSent.item(
i, 0).data(Qt.UserRole).toPyObject()) i, 0).data(Qt.UserRole).toPyObject())
toLabel = '' toLabel = ''
t = (addressToLookup,) queryreturn = sqlQuery(
shared.sqlLock.acquire() '''select label from addressbook where address=?''', addressToLookup)
shared.sqlSubmitQueue.put(
'''select label from addressbook where address=?''')
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
if queryreturn != []: if queryreturn != []:
for row in queryreturn: for row in queryreturn:
@ -1522,12 +1470,7 @@ class MyForm(QtGui.QMainWindow):
def rerenderSubscriptions(self): def rerenderSubscriptions(self):
self.ui.tableWidgetSubscriptions.setRowCount(0) self.ui.tableWidgetSubscriptions.setRowCount(0)
shared.sqlLock.acquire() queryreturn = sqlQuery('SELECT label, address, enabled FROM subscriptions')
shared.sqlSubmitQueue.put(
'SELECT label, address, enabled FROM subscriptions')
shared.sqlSubmitQueue.put('')
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
for row in queryreturn: for row in queryreturn:
label, address, enabled = row label, address, enabled = row
self.ui.tableWidgetSubscriptions.insertRow(0) self.ui.tableWidgetSubscriptions.insertRow(0)
@ -1610,24 +1553,26 @@ class MyForm(QtGui.QMainWindow):
self.statusBar().showMessage(_translate( self.statusBar().showMessage(_translate(
"MainWindow", "Warning: You are currently not connected. Bitmessage will do the work necessary to send the message but it won\'t send until you connect.")) "MainWindow", "Warning: You are currently not connected. Bitmessage will do the work necessary to send the message but it won\'t send until you connect."))
ackdata = OpenSSL.rand(32) ackdata = OpenSSL.rand(32)
shared.sqlLock.acquire() t = ()
t = ('', toAddress, ripe, fromAddress, subject, message, ackdata, int( sqlExecute(
time.time()), 'msgqueued', 1, 1, 'sent', 2) '''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)''',
shared.sqlSubmitQueue.put( '',
'''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)''') toAddress,
shared.sqlSubmitQueue.put(t) ripe,
shared.sqlReturnQueue.get() fromAddress,
shared.sqlSubmitQueue.put('commit') subject,
shared.sqlLock.release() message,
ackdata,
int(time.time()),
'msgqueued',
1,
1,
'sent',
2)
toLabel = '' toLabel = ''
t = (toAddress,) queryreturn = sqlQuery('''select label from addressbook where address=?''',
shared.sqlLock.acquire() toAddress)
shared.sqlSubmitQueue.put(
'''select label from addressbook where address=?''')
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
if queryreturn != []: if queryreturn != []:
for row in queryreturn: for row in queryreturn:
toLabel, = row toLabel, = row
@ -1658,15 +1603,10 @@ class MyForm(QtGui.QMainWindow):
ackdata = OpenSSL.rand(32) ackdata = OpenSSL.rand(32)
toAddress = self.str_broadcast_subscribers toAddress = self.str_broadcast_subscribers
ripe = '' ripe = ''
shared.sqlLock.acquire()
t = ('', toAddress, ripe, fromAddress, subject, message, ackdata, int( t = ('', toAddress, ripe, fromAddress, subject, message, ackdata, int(
time.time()), 'broadcastqueued', 1, 1, 'sent', 2) time.time()), 'broadcastqueued', 1, 1, 'sent', 2)
shared.sqlSubmitQueue.put( sqlExecute(
'''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)''') '''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)''', t)
shared.sqlSubmitQueue.put(t)
shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
shared.workerQueue.put(('sendbroadcast', '')) shared.workerQueue.put(('sendbroadcast', ''))
@ -1822,25 +1762,15 @@ class MyForm(QtGui.QMainWindow):
subject = shared.fixPotentiallyInvalidUTF8Data(subject) subject = shared.fixPotentiallyInvalidUTF8Data(subject)
message = shared.fixPotentiallyInvalidUTF8Data(message) message = shared.fixPotentiallyInvalidUTF8Data(message)
fromLabel = '' fromLabel = ''
shared.sqlLock.acquire() queryreturn = sqlQuery(
t = (fromAddress,) '''select label from addressbook where address=?''', fromAddress)
shared.sqlSubmitQueue.put(
'''select label from addressbook where address=?''')
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
if queryreturn != []: if queryreturn != []:
for row in queryreturn: for row in queryreturn:
fromLabel, = row fromLabel, = row
else: else:
# There might be a label in the subscriptions table # There might be a label in the subscriptions table
shared.sqlLock.acquire() queryreturn = sqlQuery(
t = (fromAddress,) '''select label from subscriptions where address=?''', fromAddress)
shared.sqlSubmitQueue.put(
'''select label from subscriptions where address=?''')
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
if queryreturn != []: if queryreturn != []:
for row in queryreturn: for row in queryreturn:
fromLabel, = row fromLabel, = row
@ -1914,13 +1844,7 @@ class MyForm(QtGui.QMainWindow):
"MainWindow", "The address you entered was invalid. Ignoring it.")) "MainWindow", "The address you entered was invalid. Ignoring it."))
def addEntryToAddressBook(self,address,label): def addEntryToAddressBook(self,address,label):
shared.sqlLock.acquire() sqlQuery('''select * from addressbook where address=?''', address)
t = (address,)
shared.sqlSubmitQueue.put(
'''select * from addressbook where address=?''')
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
if queryreturn == []: if queryreturn == []:
self.ui.tableWidgetAddressBook.setSortingEnabled(False) self.ui.tableWidgetAddressBook.setSortingEnabled(False)
self.ui.tableWidgetAddressBook.insertRow(0) self.ui.tableWidgetAddressBook.insertRow(0)
@ -1931,14 +1855,7 @@ class MyForm(QtGui.QMainWindow):
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.ui.tableWidgetAddressBook.setItem(0, 1, newItem) self.ui.tableWidgetAddressBook.setItem(0, 1, newItem)
self.ui.tableWidgetAddressBook.setSortingEnabled(True) self.ui.tableWidgetAddressBook.setSortingEnabled(True)
t = (str(label), address) sqlExecute('''INSERT INTO addressbook VALUES (?,?)''', str(label), address)
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put(
'''INSERT INTO addressbook VALUES (?,?)''')
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
self.rerenderInboxFromLabels() self.rerenderInboxFromLabels()
self.rerenderSentToLabels() self.rerenderSentToLabels()
else: else:
@ -1960,13 +1877,7 @@ class MyForm(QtGui.QMainWindow):
self.ui.tableWidgetSubscriptions.setItem(0,1,newItem) self.ui.tableWidgetSubscriptions.setItem(0,1,newItem)
self.ui.tableWidgetSubscriptions.setSortingEnabled(True) self.ui.tableWidgetSubscriptions.setSortingEnabled(True)
#Add to database (perhaps this should be separated from the MyForm class) #Add to database (perhaps this should be separated from the MyForm class)
t = (str(label),address,True) sqlExecute('''INSERT INTO subscriptions VALUES (?,?,?)''',str(label),address,True)
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put('''INSERT INTO subscriptions VALUES (?,?,?)''')
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
self.rerenderInboxFromLabels() self.rerenderInboxFromLabels()
shared.reloadBroadcastSendersForWhichImWatching() shared.reloadBroadcastSendersForWhichImWatching()
@ -1987,16 +1898,10 @@ class MyForm(QtGui.QMainWindow):
def loadBlackWhiteList(self): def loadBlackWhiteList(self):
# Initialize the Blacklist or Whitelist table # Initialize the Blacklist or Whitelist table
listType = shared.config.get('bitmessagesettings', 'blackwhitelist') listType = shared.config.get('bitmessagesettings', 'blackwhitelist')
shared.sqlLock.acquire()
if listType == 'black': if listType == 'black':
shared.sqlSubmitQueue.put( queryreturn = sqlQuery('''SELECT label, address, enabled FROM blacklist''')
'''SELECT label, address, enabled FROM blacklist''')
else: else:
shared.sqlSubmitQueue.put( queryreturn = sqlQuery('''SELECT label, address, enabled FROM whitelist''')
'''SELECT label, address, enabled FROM whitelist''')
shared.sqlSubmitQueue.put('')
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
for row in queryreturn: for row in queryreturn:
label, address, enabled = row label, address, enabled = row
self.ui.tableWidgetBlacklist.insertRow(0) self.ui.tableWidgetBlacklist.insertRow(0)
@ -2115,9 +2020,7 @@ class MyForm(QtGui.QMainWindow):
if shared.appdata != '' and self.settingsDialogInstance.ui.checkBoxPortableMode.isChecked(): # If we are NOT using portable mode now but the user selected that we should... if shared.appdata != '' and self.settingsDialogInstance.ui.checkBoxPortableMode.isChecked(): # If we are NOT using portable mode now but the user selected that we should...
# Write the keys.dat file to disk in the new location # Write the keys.dat file to disk in the new location
shared.sqlLock.acquire() sqlStoredProcedure('movemessagstoprog')
shared.sqlSubmitQueue.put('movemessagstoprog')
shared.sqlLock.release()
with open('keys.dat', 'wb') as configfile: with open('keys.dat', 'wb') as configfile:
shared.config.write(configfile) shared.config.write(configfile)
# Write the knownnodes.dat file to disk in the new location # Write the knownnodes.dat file to disk in the new location
@ -2141,9 +2044,7 @@ class MyForm(QtGui.QMainWindow):
shared.appdata = shared.lookupAppdataFolder() shared.appdata = shared.lookupAppdataFolder()
if not os.path.exists(shared.appdata): if not os.path.exists(shared.appdata):
os.makedirs(shared.appdata) os.makedirs(shared.appdata)
shared.sqlLock.acquire() sqlStoredProcedure('movemessagstoappdata')
shared.sqlSubmitQueue.put('movemessagstoappdata')
shared.sqlLock.release()
# Write the keys.dat file to disk in the new location # Write the keys.dat file to disk in the new location
with open(shared.appdata + 'keys.dat', 'wb') as configfile: with open(shared.appdata + 'keys.dat', 'wb') as configfile:
shared.config.write(configfile) shared.config.write(configfile)
@ -2189,18 +2090,13 @@ class MyForm(QtGui.QMainWindow):
# First we must check to see if the address is already in the # First we must check to see if the address is already in the
# address book. The user cannot add it again or else it will # address book. The user cannot add it again or else it will
# cause problems when updating and deleting the entry. # cause problems when updating and deleting the entry.
shared.sqlLock.acquire()
t = (addBMIfNotPresent(str( t = (addBMIfNotPresent(str(
self.NewBlacklistDialogInstance.ui.lineEditSubscriptionAddress.text())),) self.NewBlacklistDialogInstance.ui.lineEditSubscriptionAddress.text())),)
if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'black': if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'black':
shared.sqlSubmitQueue.put( sql = '''select * from blacklist where address=?'''
'''select * from blacklist where address=?''')
else: else:
shared.sqlSubmitQueue.put( sql = '''select * from whitelist where address=?'''
'''select * from whitelist where address=?''') queryreturn = sqlQuery(sql,*t)
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
if queryreturn == []: if queryreturn == []:
self.ui.tableWidgetBlacklist.setSortingEnabled(False) self.ui.tableWidgetBlacklist.setSortingEnabled(False)
self.ui.tableWidgetBlacklist.insertRow(0) self.ui.tableWidgetBlacklist.insertRow(0)
@ -2215,17 +2111,11 @@ class MyForm(QtGui.QMainWindow):
self.ui.tableWidgetBlacklist.setSortingEnabled(True) self.ui.tableWidgetBlacklist.setSortingEnabled(True)
t = (str(self.NewBlacklistDialogInstance.ui.newsubscriptionlabel.text().toUtf8()), addBMIfNotPresent( t = (str(self.NewBlacklistDialogInstance.ui.newsubscriptionlabel.text().toUtf8()), addBMIfNotPresent(
str(self.NewBlacklistDialogInstance.ui.lineEditSubscriptionAddress.text())), True) str(self.NewBlacklistDialogInstance.ui.lineEditSubscriptionAddress.text())), True)
shared.sqlLock.acquire()
if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'black': if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'black':
shared.sqlSubmitQueue.put( sql = '''INSERT INTO blacklist VALUES (?,?,?)'''
'''INSERT INTO blacklist VALUES (?,?,?)''')
else: else:
shared.sqlSubmitQueue.put( sql = '''INSERT INTO whitelist VALUES (?,?,?)'''
'''INSERT INTO whitelist VALUES (?,?,?)''') sqlExecute(sql, *t)
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
else: else:
self.statusBar().showMessage(_translate( self.statusBar().showMessage(_translate(
"MainWindow", "Error: You cannot add the same address to your list twice. Perhaps rename the existing one if you want.")) "MainWindow", "Error: You cannot add the same address to your list twice. Perhaps rename the existing one if you want."))
@ -2352,20 +2242,11 @@ class MyForm(QtGui.QMainWindow):
currentRow = row.row() currentRow = row.row()
inventoryHashToMarkUnread = str(self.ui.tableWidgetInbox.item( inventoryHashToMarkUnread = str(self.ui.tableWidgetInbox.item(
currentRow, 3).data(Qt.UserRole).toPyObject()) currentRow, 3).data(Qt.UserRole).toPyObject())
t = (inventoryHashToMarkUnread,) sqlExecute('''UPDATE inbox SET read=0 WHERE msgid=?''', inventoryHashToMarkUnread)
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put(
'''UPDATE inbox SET read=0 WHERE msgid=?''')
shared.sqlSubmitQueue.put(t)
shared.sqlReturnQueue.get()
shared.sqlLock.release()
self.ui.tableWidgetInbox.item(currentRow, 0).setFont(font) self.ui.tableWidgetInbox.item(currentRow, 0).setFont(font)
self.ui.tableWidgetInbox.item(currentRow, 1).setFont(font) self.ui.tableWidgetInbox.item(currentRow, 1).setFont(font)
self.ui.tableWidgetInbox.item(currentRow, 2).setFont(font) self.ui.tableWidgetInbox.item(currentRow, 2).setFont(font)
self.ui.tableWidgetInbox.item(currentRow, 3).setFont(font) self.ui.tableWidgetInbox.item(currentRow, 3).setFont(font)
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
# self.ui.tableWidgetInbox.selectRow(currentRow + 1) # self.ui.tableWidgetInbox.selectRow(currentRow + 1)
# This doesn't de-select the last message if you try to mark it unread, but that doesn't interfere. Might not be necessary. # This doesn't de-select the last message if you try to mark it unread, but that doesn't interfere. Might not be necessary.
# We could also select upwards, but then our problem would be with the topmost message. # We could also select upwards, but then our problem would be with the topmost message.
@ -2410,13 +2291,8 @@ class MyForm(QtGui.QMainWindow):
addressAtCurrentInboxRow = str(self.ui.tableWidgetInbox.item( addressAtCurrentInboxRow = str(self.ui.tableWidgetInbox.item(
currentInboxRow, 1).data(Qt.UserRole).toPyObject()) currentInboxRow, 1).data(Qt.UserRole).toPyObject())
# Let's make sure that it isn't already in the address book # Let's make sure that it isn't already in the address book
shared.sqlLock.acquire() queryreturn = sqlQuery('''select * from addressbook where address=?''',
t = (addressAtCurrentInboxRow,) addressAtCurrentInboxRow)
shared.sqlSubmitQueue.put(
'''select * from addressbook where address=?''')
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
if queryreturn == []: if queryreturn == []:
self.ui.tableWidgetAddressBook.insertRow(0) self.ui.tableWidgetAddressBook.insertRow(0)
newItem = QtGui.QTableWidgetItem( newItem = QtGui.QTableWidgetItem(
@ -2426,15 +2302,9 @@ class MyForm(QtGui.QMainWindow):
newItem.setFlags( newItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.ui.tableWidgetAddressBook.setItem(0, 1, newItem) self.ui.tableWidgetAddressBook.setItem(0, 1, newItem)
t = ('--New entry. Change label in Address Book.--', sqlExecute('''INSERT INTO addressbook VALUES (?,?)''',
'--New entry. Change label in Address Book.--',
addressAtCurrentInboxRow) addressAtCurrentInboxRow)
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put(
'''INSERT INTO addressbook VALUES (?,?)''')
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
self.ui.tabWidget.setCurrentIndex(5) self.ui.tabWidget.setCurrentIndex(5)
self.ui.tableWidgetAddressBook.setCurrentCell(0, 0) self.ui.tableWidgetAddressBook.setCurrentCell(0, 0)
self.statusBar().showMessage(_translate( self.statusBar().showMessage(_translate(
@ -2449,20 +2319,11 @@ class MyForm(QtGui.QMainWindow):
currentRow = self.ui.tableWidgetInbox.selectedIndexes()[0].row() currentRow = self.ui.tableWidgetInbox.selectedIndexes()[0].row()
inventoryHashToTrash = str(self.ui.tableWidgetInbox.item( inventoryHashToTrash = str(self.ui.tableWidgetInbox.item(
currentRow, 3).data(Qt.UserRole).toPyObject()) currentRow, 3).data(Qt.UserRole).toPyObject())
t = (inventoryHashToTrash,) sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', inventoryHashToTrash)
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put(
'''UPDATE inbox SET folder='trash' WHERE msgid=?''')
shared.sqlSubmitQueue.put(t)
shared.sqlReturnQueue.get()
shared.sqlLock.release()
self.ui.textEditInboxMessage.setText("") self.ui.textEditInboxMessage.setText("")
self.ui.tableWidgetInbox.removeRow(currentRow) self.ui.tableWidgetInbox.removeRow(currentRow)
self.statusBar().showMessage(_translate( self.statusBar().showMessage(_translate(
"MainWindow", "Moved items to trash. There is no user interface to view your trash, but it is still on disk if you are desperate to get it back.")) "MainWindow", "Moved items to trash. There is no user interface to view your trash, but it is still on disk if you are desperate to get it back."))
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
if currentRow == 0: if currentRow == 0:
self.ui.tableWidgetInbox.selectRow(currentRow) self.ui.tableWidgetInbox.selectRow(currentRow)
else: else:
@ -2493,20 +2354,11 @@ class MyForm(QtGui.QMainWindow):
currentRow = self.ui.tableWidgetSent.selectedIndexes()[0].row() currentRow = self.ui.tableWidgetSent.selectedIndexes()[0].row()
ackdataToTrash = str(self.ui.tableWidgetSent.item( ackdataToTrash = str(self.ui.tableWidgetSent.item(
currentRow, 3).data(Qt.UserRole).toPyObject()) currentRow, 3).data(Qt.UserRole).toPyObject())
t = (ackdataToTrash,) sqlExecute('''UPDATE sent SET folder='trash' WHERE ackdata=?''', ackdataToTrash)
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put(
'''UPDATE sent SET folder='trash' WHERE ackdata=?''')
shared.sqlSubmitQueue.put(t)
shared.sqlReturnQueue.get()
shared.sqlLock.release()
self.ui.textEditSentMessage.setPlainText("") self.ui.textEditSentMessage.setPlainText("")
self.ui.tableWidgetSent.removeRow(currentRow) self.ui.tableWidgetSent.removeRow(currentRow)
self.statusBar().showMessage(_translate( self.statusBar().showMessage(_translate(
"MainWindow", "Moved items to trash. There is no user interface to view your trash, but it is still on disk if you are desperate to get it back.")) "MainWindow", "Moved items to trash. There is no user interface to view your trash, but it is still on disk if you are desperate to get it back."))
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
if currentRow == 0: if currentRow == 0:
self.ui.tableWidgetSent.selectRow(currentRow) self.ui.tableWidgetSent.selectRow(currentRow)
else: else:
@ -2517,18 +2369,10 @@ class MyForm(QtGui.QMainWindow):
addressAtCurrentRow = str(self.ui.tableWidgetSent.item( addressAtCurrentRow = str(self.ui.tableWidgetSent.item(
currentRow, 0).data(Qt.UserRole).toPyObject()) currentRow, 0).data(Qt.UserRole).toPyObject())
toRipe = decodeAddress(addressAtCurrentRow)[3] toRipe = decodeAddress(addressAtCurrentRow)[3]
t = (toRipe,) sqlExecute(
shared.sqlLock.acquire() '''UPDATE sent SET status='forcepow' WHERE toripe=? AND status='toodifficult' and folder='sent' ''',
shared.sqlSubmitQueue.put( toRipe)
'''UPDATE sent SET status='forcepow' WHERE toripe=? AND status='toodifficult' and folder='sent' ''') queryreturn = sqlQuery('''select ackdata FROM sent WHERE status='forcepow' ''')
shared.sqlSubmitQueue.put(t)
shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
shared.sqlSubmitQueue.put(
'''select ackdata FROM sent WHERE status='forcepow' ''')
shared.sqlSubmitQueue.put('')
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
for row in queryreturn: for row in queryreturn:
ackdata, = row ackdata, = row
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', ( shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (
@ -2554,14 +2398,8 @@ class MyForm(QtGui.QMainWindow):
currentRow, 0).text().toUtf8() currentRow, 0).text().toUtf8()
addressAtCurrentRow = self.ui.tableWidgetAddressBook.item( addressAtCurrentRow = self.ui.tableWidgetAddressBook.item(
currentRow, 1).text() currentRow, 1).text()
t = (str(labelAtCurrentRow), str(addressAtCurrentRow)) sqlExecute('''DELETE FROM addressbook WHERE label=? AND address=?''',
shared.sqlLock.acquire() str(labelAtCurrentRow), str(addressAtCurrentRow))
shared.sqlSubmitQueue.put(
'''DELETE FROM addressbook WHERE label=? AND address=?''')
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
self.ui.tableWidgetAddressBook.removeRow(currentRow) self.ui.tableWidgetAddressBook.removeRow(currentRow)
self.rerenderInboxFromLabels() self.rerenderInboxFromLabels()
self.rerenderSentToLabels() self.rerenderSentToLabels()
@ -2631,14 +2469,8 @@ class MyForm(QtGui.QMainWindow):
currentRow, 0).text().toUtf8() currentRow, 0).text().toUtf8()
addressAtCurrentRow = self.ui.tableWidgetSubscriptions.item( addressAtCurrentRow = self.ui.tableWidgetSubscriptions.item(
currentRow, 1).text() currentRow, 1).text()
t = (str(labelAtCurrentRow), str(addressAtCurrentRow)) sqlExecute('''DELETE FROM subscriptions WHERE label=? AND address=?''',
shared.sqlLock.acquire() str(labelAtCurrentRow), str(addressAtCurrentRow))
shared.sqlSubmitQueue.put(
'''DELETE FROM subscriptions WHERE label=? AND address=?''')
shared.sqlSubmitQueue.put(t)
shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
self.ui.tableWidgetSubscriptions.removeRow(currentRow) self.ui.tableWidgetSubscriptions.removeRow(currentRow)
self.rerenderInboxFromLabels() self.rerenderInboxFromLabels()
shared.reloadBroadcastSendersForWhichImWatching() shared.reloadBroadcastSendersForWhichImWatching()
@ -2656,14 +2488,9 @@ class MyForm(QtGui.QMainWindow):
currentRow, 0).text().toUtf8() currentRow, 0).text().toUtf8()
addressAtCurrentRow = self.ui.tableWidgetSubscriptions.item( addressAtCurrentRow = self.ui.tableWidgetSubscriptions.item(
currentRow, 1).text() currentRow, 1).text()
t = (str(labelAtCurrentRow), str(addressAtCurrentRow)) sqlExecute(
shared.sqlLock.acquire() '''update subscriptions set enabled=1 WHERE label=? AND address=?''',
shared.sqlSubmitQueue.put( str(labelAtCurrentRow), str(addressAtCurrentRow))
'''update subscriptions set enabled=1 WHERE label=? AND address=?''')
shared.sqlSubmitQueue.put(t)
shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
self.ui.tableWidgetSubscriptions.item( self.ui.tableWidgetSubscriptions.item(
currentRow, 0).setTextColor(QApplication.palette().text().color()) currentRow, 0).setTextColor(QApplication.palette().text().color())
self.ui.tableWidgetSubscriptions.item( self.ui.tableWidgetSubscriptions.item(
@ -2676,14 +2503,9 @@ class MyForm(QtGui.QMainWindow):
currentRow, 0).text().toUtf8() currentRow, 0).text().toUtf8()
addressAtCurrentRow = self.ui.tableWidgetSubscriptions.item( addressAtCurrentRow = self.ui.tableWidgetSubscriptions.item(
currentRow, 1).text() currentRow, 1).text()
t = (str(labelAtCurrentRow), str(addressAtCurrentRow)) sqlExecute(
shared.sqlLock.acquire() '''update subscriptions set enabled=0 WHERE label=? AND address=?''',
shared.sqlSubmitQueue.put( str(labelAtCurrentRow), str(addressAtCurrentRow))
'''update subscriptions set enabled=0 WHERE label=? AND address=?''')
shared.sqlSubmitQueue.put(t)
shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
self.ui.tableWidgetSubscriptions.item( self.ui.tableWidgetSubscriptions.item(
currentRow, 0).setTextColor(QtGui.QColor(128, 128, 128)) currentRow, 0).setTextColor(QtGui.QColor(128, 128, 128))
self.ui.tableWidgetSubscriptions.item( self.ui.tableWidgetSubscriptions.item(
@ -2704,20 +2526,14 @@ class MyForm(QtGui.QMainWindow):
currentRow, 0).text().toUtf8() currentRow, 0).text().toUtf8()
addressAtCurrentRow = self.ui.tableWidgetBlacklist.item( addressAtCurrentRow = self.ui.tableWidgetBlacklist.item(
currentRow, 1).text() currentRow, 1).text()
t = (str(labelAtCurrentRow), str(addressAtCurrentRow))
shared.sqlLock.acquire()
if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'black': if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'black':
shared.sqlSubmitQueue.put( sqlExecute(
'''DELETE FROM blacklist WHERE label=? AND address=?''') '''DELETE FROM blacklist WHERE label=? AND address=?''',
shared.sqlSubmitQueue.put(t) str(labelAtCurrentRow), str(addressAtCurrentRow))
shared.sqlReturnQueue.get()
else: else:
shared.sqlSubmitQueue.put( sqlExecute(
'''DELETE FROM whitelist WHERE label=? AND address=?''') '''DELETE FROM whitelist WHERE label=? AND address=?''',
shared.sqlSubmitQueue.put(t) str(labelAtCurrentRow), str(addressAtCurrentRow))
shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
self.ui.tableWidgetBlacklist.removeRow(currentRow) self.ui.tableWidgetBlacklist.removeRow(currentRow)
def on_action_BlacklistClipboard(self): def on_action_BlacklistClipboard(self):
@ -2739,20 +2555,14 @@ class MyForm(QtGui.QMainWindow):
currentRow, 0).setTextColor(QApplication.palette().text().color()) currentRow, 0).setTextColor(QApplication.palette().text().color())
self.ui.tableWidgetBlacklist.item( self.ui.tableWidgetBlacklist.item(
currentRow, 1).setTextColor(QApplication.palette().text().color()) currentRow, 1).setTextColor(QApplication.palette().text().color())
t = (str(addressAtCurrentRow),)
shared.sqlLock.acquire()
if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'black': if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'black':
shared.sqlSubmitQueue.put( sqlExecute(
'''UPDATE blacklist SET enabled=1 WHERE address=?''') '''UPDATE blacklist SET enabled=1 WHERE address=?''',
shared.sqlSubmitQueue.put(t) str(addressAtCurrentRow))
shared.sqlReturnQueue.get()
else: else:
shared.sqlSubmitQueue.put( sqlExecute(
'''UPDATE whitelist SET enabled=1 WHERE address=?''') '''UPDATE whitelist SET enabled=1 WHERE address=?''',
shared.sqlSubmitQueue.put(t) str(addressAtCurrentRow))
shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
def on_action_BlacklistDisable(self): def on_action_BlacklistDisable(self):
currentRow = self.ui.tableWidgetBlacklist.currentRow() currentRow = self.ui.tableWidgetBlacklist.currentRow()
@ -2762,20 +2572,12 @@ class MyForm(QtGui.QMainWindow):
currentRow, 0).setTextColor(QtGui.QColor(128, 128, 128)) currentRow, 0).setTextColor(QtGui.QColor(128, 128, 128))
self.ui.tableWidgetBlacklist.item( self.ui.tableWidgetBlacklist.item(
currentRow, 1).setTextColor(QtGui.QColor(128, 128, 128)) currentRow, 1).setTextColor(QtGui.QColor(128, 128, 128))
t = (str(addressAtCurrentRow),)
shared.sqlLock.acquire()
if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'black': if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'black':
shared.sqlSubmitQueue.put( sqlExecute(
'''UPDATE blacklist SET enabled=0 WHERE address=?''') '''UPDATE blacklist SET enabled=0 WHERE address=?''', str(addressAtCurrentRow))
shared.sqlSubmitQueue.put(t)
shared.sqlReturnQueue.get()
else: else:
shared.sqlSubmitQueue.put( sqlExecute(
'''UPDATE whitelist SET enabled=0 WHERE address=?''') '''UPDATE whitelist SET enabled=0 WHERE address=?''', str(addressAtCurrentRow))
shared.sqlSubmitQueue.put(t)
shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
# Group of functions for the Your Identities dialog box # Group of functions for the Your Identities dialog box
def on_action_YourIdentitiesNew(self): def on_action_YourIdentitiesNew(self):
@ -2841,12 +2643,7 @@ class MyForm(QtGui.QMainWindow):
currentRow = self.ui.tableWidgetSent.currentRow() currentRow = self.ui.tableWidgetSent.currentRow()
ackData = str(self.ui.tableWidgetSent.item( ackData = str(self.ui.tableWidgetSent.item(
currentRow, 3).data(Qt.UserRole).toPyObject()) currentRow, 3).data(Qt.UserRole).toPyObject())
shared.sqlLock.acquire() queryreturn = sqlQuery('''SELECT status FROM sent where ackdata=?''', ackData)
shared.sqlSubmitQueue.put(
'''SELECT status FROM sent where ackdata=?''')
shared.sqlSubmitQueue.put((ackData,))
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
for row in queryreturn: for row in queryreturn:
status, = row status, = row
if status == 'toodifficult': if status == 'toodifficult':
@ -2903,13 +2700,7 @@ class MyForm(QtGui.QMainWindow):
currentRow, 3).data(Qt.UserRole).toPyObject()) currentRow, 3).data(Qt.UserRole).toPyObject())
t = (inventoryHash,) t = (inventoryHash,)
self.ubuntuMessagingMenuClear(t) self.ubuntuMessagingMenuClear(t)
shared.sqlLock.acquire() sqlExecute('''update inbox set read=1 WHERE msgid=?''', *t)
shared.sqlSubmitQueue.put(
'''update inbox set read=1 WHERE msgid=?''')
shared.sqlSubmitQueue.put(t)
shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
def tableWidgetSentItemClicked(self): def tableWidgetSentItemClicked(self):
currentRow = self.ui.tableWidgetSent.currentRow() currentRow = self.ui.tableWidgetSent.currentRow()
@ -2934,35 +2725,23 @@ class MyForm(QtGui.QMainWindow):
def tableWidgetAddressBookItemChanged(self): def tableWidgetAddressBookItemChanged(self):
currentRow = self.ui.tableWidgetAddressBook.currentRow() currentRow = self.ui.tableWidgetAddressBook.currentRow()
shared.sqlLock.acquire()
if currentRow >= 0: if currentRow >= 0:
addressAtCurrentRow = self.ui.tableWidgetAddressBook.item( addressAtCurrentRow = self.ui.tableWidgetAddressBook.item(
currentRow, 1).text() currentRow, 1).text()
t = (str(self.ui.tableWidgetAddressBook.item( sqlExecute('''UPDATE addressbook set label=? WHERE address=?''',
currentRow, 0).text().toUtf8()), str(addressAtCurrentRow)) str(self.ui.tableWidgetAddressBook.item(currentRow, 0).text().toUtf8()),
shared.sqlSubmitQueue.put( str(addressAtCurrentRow))
'''UPDATE addressbook set label=? WHERE address=?''')
shared.sqlSubmitQueue.put(t)
shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
self.rerenderInboxFromLabels() self.rerenderInboxFromLabels()
self.rerenderSentToLabels() self.rerenderSentToLabels()
def tableWidgetSubscriptionsItemChanged(self): def tableWidgetSubscriptionsItemChanged(self):
currentRow = self.ui.tableWidgetSubscriptions.currentRow() currentRow = self.ui.tableWidgetSubscriptions.currentRow()
shared.sqlLock.acquire()
if currentRow >= 0: if currentRow >= 0:
addressAtCurrentRow = self.ui.tableWidgetSubscriptions.item( addressAtCurrentRow = self.ui.tableWidgetSubscriptions.item(
currentRow, 1).text() currentRow, 1).text()
t = (str(self.ui.tableWidgetSubscriptions.item( sqlExecute('''UPDATE subscriptions set label=? WHERE address=?''',
currentRow, 0).text().toUtf8()), str(addressAtCurrentRow)) str(self.ui.tableWidgetSubscriptions.item(currentRow, 0).text().toUtf8()),
shared.sqlSubmitQueue.put( str(addressAtCurrentRow))
'''UPDATE subscriptions set label=? WHERE address=?''')
shared.sqlSubmitQueue.put(t)
shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
self.rerenderInboxFromLabels() self.rerenderInboxFromLabels()
self.rerenderSentToLabels() self.rerenderSentToLabels()