Merge branch 'master' of http://github.com/fuzzgun/PyBitmessage into fuzzgun-master

This commit is contained in:
Jonathan Warren 2013-05-14 11:50:29 -04:00
commit b5173fd835

View File

@ -36,6 +36,8 @@ import platform
class MyForm(QtGui.QMainWindow): class MyForm(QtGui.QMainWindow):
str_broadcast_subscribers = '[Broadcast subscribers]'
def __init__(self, parent=None): def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent) QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow() self.ui = Ui_MainWindow()
@ -240,13 +242,12 @@ class MyForm(QtGui.QMainWindow):
shared.sqlSubmitQueue.put('') shared.sqlSubmitQueue.put('')
queryreturn = shared.sqlReturnQueue.get() queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release() shared.sqlLock.release()
str_broadcast_subscribers = '[Broadcast subscribers]'
for row in queryreturn: for row in queryreturn:
msgid, toAddress, fromAddress, subject, received, message, read = row msgid, toAddress, fromAddress, subject, received, message, read = row
try: try:
if toAddress == str_broadcast_subscribers: if toAddress == self.str_broadcast_subscribers:
toLabel = str_broadcast_subscribers toLabel = self.str_broadcast_subscribers
else: else:
toLabel = shared.config.get(toAddress, 'label') toLabel = shared.config.get(toAddress, 'label')
except: except:
@ -476,6 +477,12 @@ class MyForm(QtGui.QMainWindow):
# pointer to the application # pointer to the application
#app = None #app = None
# The most recent message
newMessageItem = None
# The most recent broadcast
newBroadcastItem = None
# show the application window # show the application window
def appIndicatorShow(self): def appIndicatorShow(self):
if self.actionShow == None: if self.actionShow == None:
@ -504,29 +511,32 @@ class MyForm(QtGui.QMainWindow):
else: else:
self.appIndicatorShowOrHideWindow()""" self.appIndicatorShowOrHideWindow()"""
# returns the index of the oldest unread message
def getUnreadMessageIndex(self):
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put('''SELECT msgid, received, read FROM inbox where folder='inbox' ORDER BY received DESC ''')
shared.sqlSubmitQueue.put('')
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
i = 0
index = 0
for row in queryreturn:
msgid, received, read = row
if not read:
index = i
i = i + 1
return index
# Show the program window and select inbox tab # Show the program window and select inbox tab
def appIndicatorInbox(self, mm_app, source_id): def appIndicatorInbox(self, mm_app, source_id):
self.appIndicatorShow() self.appIndicatorShow()
# select inbox # select inbox
self.ui.tabWidget.setCurrentIndex(0) self.ui.tabWidget.setCurrentIndex(0)
selectedItem = None
if source_id == 'Subscriptions':
# select unread broadcast
if self.newBroadcastItem is not None:
selectedItem = self.newBroadcastItem
self.newBroadcastItem = None
else:
# select unread message # select unread message
self.ui.tableWidgetInbox.selectRow(self.getUnreadMessageIndex()) if self.newMessageItem is not None:
selectedItem = self.newMessageItem
self.newMessageItem = None
# make it the current item
if selectedItem is not None:
try:
self.ui.tableWidgetInbox.setCurrentItem(selectedItem)
except Exception:
self.ui.tableWidgetInbox.setCurrentCell(0,0)
self.tableWidgetInboxItemClicked()
else:
# just select the first item
self.ui.tableWidgetInbox.setCurrentCell(0,0)
self.tableWidgetInboxItemClicked() self.tableWidgetInboxItemClicked()
# Show the program window and select send tab # Show the program window and select send tab
@ -604,10 +614,35 @@ class MyForm(QtGui.QMainWindow):
return True return True
return False return False
# When an unread inbox row is selected on then clear the messaging menu
def ubuntuMessagingMenuClear(self, inventoryHash):
global withMessagingMenu
# if this isn't ubuntu then don't do anything
if not self.isUbuntu():
return
# has messageing menu been installed
if not withMessagingMenu:
return
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put('''SELECT toaddress, read FROM inbox WHERE msgid=?''')
shared.sqlSubmitQueue.put(inventoryHash)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
for row in queryreturn:
toAddress, read = row
if not read:
if toAddress == self.str_broadcast_subscribers:
if self.mmapp.has_source("Subscriptions"):
self.mmapp.remove_source("Subscriptions")
else:
if self.mmapp.has_source("Messages"):
self.mmapp.remove_source("Messages")
# returns the number of unread messages and subscriptions # returns the number of unread messages and subscriptions
def getUnread(self): def getUnread(self):
str_broadcast_subscribers = '[Broadcast subscribers]'
unreadMessages = 0 unreadMessages = 0
unreadSubscriptions = 0 unreadSubscriptions = 0
@ -620,8 +655,8 @@ class MyForm(QtGui.QMainWindow):
msgid, toAddress, read = row msgid, toAddress, read = row
try: try:
if toAddress == str_broadcast_subscribers: if toAddress == self.str_broadcast_subscribers:
toLabel = str_broadcast_subscribers toLabel = self.str_broadcast_subscribers
else: else:
toLabel = shared.config.get(toAddress, 'label') toLabel = shared.config.get(toAddress, 'label')
except: except:
@ -630,7 +665,7 @@ class MyForm(QtGui.QMainWindow):
toLabel = toAddress toLabel = toAddress
if not read: if not read:
if toLabel == str_broadcast_subscribers: if toLabel == self.str_broadcast_subscribers:
# increment the unread subscriptions # increment the unread subscriptions
unreadSubscriptions = unreadSubscriptions + 1 unreadSubscriptions = unreadSubscriptions + 1
else: else:
@ -678,7 +713,7 @@ class MyForm(QtGui.QMainWindow):
print 'WARNING: messaging menu disabled' print 'WARNING: messaging menu disabled'
# update the Ubuntu messaging menu # update the Ubuntu messaging menu
def ubuntuMessagingMenuUpdate(self, drawAttention): def ubuntuMessagingMenuUpdate(self, drawAttention, newItem, toLabel):
global withMessagingMenu global withMessagingMenu
# if this isn't ubuntu then don't do anything # if this isn't ubuntu then don't do anything
@ -690,6 +725,12 @@ class MyForm(QtGui.QMainWindow):
print 'WARNING: messaging menu disabled or libmessaging-menu-dev not installed' print 'WARNING: messaging menu disabled or libmessaging-menu-dev not installed'
return return
# remember this item to that the messaging menu can find it
if toLabel == self.str_broadcast_subscribers:
self.newBroadcastItem = newItem
else:
self.newMessageItem = newItem
# Remove previous messages and subscriptions entries, then recreate them # Remove previous messages and subscriptions entries, then recreate them
# There might be a better way to do it than this # There might be a better way to do it than this
if self.mmapp.has_source("Messages"): if self.mmapp.has_source("Messages"):
@ -1077,7 +1118,7 @@ class MyForm(QtGui.QMainWindow):
self.statusBar().showMessage('') self.statusBar().showMessage('')
#We don't actually need the ackdata for acknowledgement since this is a broadcast message, but we can use it to update the user interface when the POW is done generating. #We don't actually need the ackdata for acknowledgement since this is a broadcast message, but we can use it to update the user interface when the POW is done generating.
ackdata = OpenSSL.rand(32) ackdata = OpenSSL.rand(32)
toAddress = '[Broadcast subscribers]' toAddress = self.str_broadcast_subscribers
ripe = '' ripe = ''
shared.sqlLock.acquire() shared.sqlLock.acquire()
t = ('',toAddress,ripe,fromAddress,subject,message,ackdata,int(time.time()),'broadcastpending',1,1,'sent',2) t = ('',toAddress,ripe,fromAddress,subject,message,ackdata,int(time.time()),'broadcastpending',1,1,'sent',2)
@ -1096,7 +1137,7 @@ class MyForm(QtGui.QMainWindow):
if fromLabel == '': if fromLabel == '':
fromLabel = fromAddress fromLabel = fromAddress
toLabel = '[Broadcast subscribers]' toLabel = self.str_broadcast_subscribers
self.ui.tableWidgetSent.insertRow(0) self.ui.tableWidgetSent.insertRow(0)
newItem = QtGui.QTableWidgetItem(unicode(toLabel,'utf-8')) newItem = QtGui.QTableWidgetItem(unicode(toLabel,'utf-8'))
@ -1238,8 +1279,8 @@ class MyForm(QtGui.QMainWindow):
fromLabel, = row fromLabel, = row
try: try:
if toAddress == '[Broadcast subscribers]': if toAddress == self.str_broadcast_subscribers:
toLabel = '[Broadcast subscribers]' toLabel = self.str_broadcast_subscribers
else: else:
toLabel = shared.config.get(toAddress, 'label') toLabel = shared.config.get(toAddress, 'label')
except: except:
@ -1285,7 +1326,7 @@ class MyForm(QtGui.QMainWindow):
else: else:
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.setSortingEnabled(True) self.ui.tableWidgetInbox.setSortingEnabled(True)
self.ubuntuMessagingMenuUpdate(True) self.ubuntuMessagingMenuUpdate(True, newItem, toLabel)
def click_pushButtonAddAddressBook(self): def click_pushButtonAddAddressBook(self):
self.NewSubscriptionDialogInstance = NewSubscriptionDialog(self) self.NewSubscriptionDialogInstance = NewSubscriptionDialog(self)
@ -1646,7 +1687,7 @@ class MyForm(QtGui.QMainWindow):
toAddressAtCurrentInboxRow = str(self.ui.tableWidgetInbox.item(currentInboxRow,0).data(Qt.UserRole).toPyObject()) toAddressAtCurrentInboxRow = str(self.ui.tableWidgetInbox.item(currentInboxRow,0).data(Qt.UserRole).toPyObject())
fromAddressAtCurrentInboxRow = str(self.ui.tableWidgetInbox.item(currentInboxRow,1).data(Qt.UserRole).toPyObject()) fromAddressAtCurrentInboxRow = str(self.ui.tableWidgetInbox.item(currentInboxRow,1).data(Qt.UserRole).toPyObject())
if toAddressAtCurrentInboxRow == '[Broadcast subscribers]': if toAddressAtCurrentInboxRow == self.str_broadcast_subscribers:
self.ui.labelFrom.setText('') self.ui.labelFrom.setText('')
else: else:
if not shared.config.get(toAddressAtCurrentInboxRow,'enabled'): if not shared.config.get(toAddressAtCurrentInboxRow,'enabled'):
@ -1971,6 +2012,7 @@ class MyForm(QtGui.QMainWindow):
inventoryHash = str(self.ui.tableWidgetInbox.item(currentRow,3).data(Qt.UserRole).toPyObject()) inventoryHash = str(self.ui.tableWidgetInbox.item(currentRow,3).data(Qt.UserRole).toPyObject())
t = (inventoryHash,) t = (inventoryHash,)
self.ubuntuMessagingMenuClear(t)
shared.sqlLock.acquire() shared.sqlLock.acquire()
shared.sqlSubmitQueue.put('''update inbox set read=1 WHERE msgid=?''') shared.sqlSubmitQueue.put('''update inbox set read=1 WHERE msgid=?''')
shared.sqlSubmitQueue.put(t) shared.sqlSubmitQueue.put(t)