Merge branch 'master' of http://github.com/fuzzgun/PyBitmessage into fuzzgun-master
This commit is contained in:
commit
b5173fd835
|
@ -36,6 +36,8 @@ import platform
|
|||
|
||||
class MyForm(QtGui.QMainWindow):
|
||||
|
||||
str_broadcast_subscribers = '[Broadcast subscribers]'
|
||||
|
||||
def __init__(self, parent=None):
|
||||
QtGui.QWidget.__init__(self, parent)
|
||||
self.ui = Ui_MainWindow()
|
||||
|
@ -240,13 +242,12 @@ class MyForm(QtGui.QMainWindow):
|
|||
shared.sqlSubmitQueue.put('')
|
||||
queryreturn = shared.sqlReturnQueue.get()
|
||||
shared.sqlLock.release()
|
||||
str_broadcast_subscribers = '[Broadcast subscribers]'
|
||||
for row in queryreturn:
|
||||
msgid, toAddress, fromAddress, subject, received, message, read = row
|
||||
|
||||
try:
|
||||
if toAddress == str_broadcast_subscribers:
|
||||
toLabel = str_broadcast_subscribers
|
||||
if toAddress == self.str_broadcast_subscribers:
|
||||
toLabel = self.str_broadcast_subscribers
|
||||
else:
|
||||
toLabel = shared.config.get(toAddress, 'label')
|
||||
except:
|
||||
|
@ -476,6 +477,12 @@ class MyForm(QtGui.QMainWindow):
|
|||
# pointer to the application
|
||||
#app = None
|
||||
|
||||
# The most recent message
|
||||
newMessageItem = None
|
||||
|
||||
# The most recent broadcast
|
||||
newBroadcastItem = None
|
||||
|
||||
# show the application window
|
||||
def appIndicatorShow(self):
|
||||
if self.actionShow == None:
|
||||
|
@ -504,29 +511,32 @@ class MyForm(QtGui.QMainWindow):
|
|||
else:
|
||||
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
|
||||
def appIndicatorInbox(self, mm_app, source_id):
|
||||
self.appIndicatorShow()
|
||||
# select inbox
|
||||
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
|
||||
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()
|
||||
|
||||
# Show the program window and select send tab
|
||||
|
@ -604,10 +614,35 @@ class MyForm(QtGui.QMainWindow):
|
|||
return True
|
||||
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
|
||||
def getUnread(self):
|
||||
str_broadcast_subscribers = '[Broadcast subscribers]'
|
||||
|
||||
unreadMessages = 0
|
||||
unreadSubscriptions = 0
|
||||
|
||||
|
@ -620,8 +655,8 @@ class MyForm(QtGui.QMainWindow):
|
|||
msgid, toAddress, read = row
|
||||
|
||||
try:
|
||||
if toAddress == str_broadcast_subscribers:
|
||||
toLabel = str_broadcast_subscribers
|
||||
if toAddress == self.str_broadcast_subscribers:
|
||||
toLabel = self.str_broadcast_subscribers
|
||||
else:
|
||||
toLabel = shared.config.get(toAddress, 'label')
|
||||
except:
|
||||
|
@ -630,7 +665,7 @@ class MyForm(QtGui.QMainWindow):
|
|||
toLabel = toAddress
|
||||
|
||||
if not read:
|
||||
if toLabel == str_broadcast_subscribers:
|
||||
if toLabel == self.str_broadcast_subscribers:
|
||||
# increment the unread subscriptions
|
||||
unreadSubscriptions = unreadSubscriptions + 1
|
||||
else:
|
||||
|
@ -678,7 +713,7 @@ class MyForm(QtGui.QMainWindow):
|
|||
print 'WARNING: messaging menu disabled'
|
||||
|
||||
# update the Ubuntu messaging menu
|
||||
def ubuntuMessagingMenuUpdate(self, drawAttention):
|
||||
def ubuntuMessagingMenuUpdate(self, drawAttention, newItem, toLabel):
|
||||
global withMessagingMenu
|
||||
|
||||
# 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'
|
||||
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
|
||||
# There might be a better way to do it than this
|
||||
if self.mmapp.has_source("Messages"):
|
||||
|
@ -1077,7 +1118,7 @@ class MyForm(QtGui.QMainWindow):
|
|||
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.
|
||||
ackdata = OpenSSL.rand(32)
|
||||
toAddress = '[Broadcast subscribers]'
|
||||
toAddress = self.str_broadcast_subscribers
|
||||
ripe = ''
|
||||
shared.sqlLock.acquire()
|
||||
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 == '':
|
||||
fromLabel = fromAddress
|
||||
|
||||
toLabel = '[Broadcast subscribers]'
|
||||
toLabel = self.str_broadcast_subscribers
|
||||
|
||||
self.ui.tableWidgetSent.insertRow(0)
|
||||
newItem = QtGui.QTableWidgetItem(unicode(toLabel,'utf-8'))
|
||||
|
@ -1238,8 +1279,8 @@ class MyForm(QtGui.QMainWindow):
|
|||
fromLabel, = row
|
||||
|
||||
try:
|
||||
if toAddress == '[Broadcast subscribers]':
|
||||
toLabel = '[Broadcast subscribers]'
|
||||
if toAddress == self.str_broadcast_subscribers:
|
||||
toLabel = self.str_broadcast_subscribers
|
||||
else:
|
||||
toLabel = shared.config.get(toAddress, 'label')
|
||||
except:
|
||||
|
@ -1285,7 +1326,7 @@ class MyForm(QtGui.QMainWindow):
|
|||
else:
|
||||
self.ui.textEditInboxMessage.setPlainText(self.ui.tableWidgetInbox.item(0,2).data(Qt.UserRole).toPyObject())"""
|
||||
self.ui.tableWidgetInbox.setSortingEnabled(True)
|
||||
self.ubuntuMessagingMenuUpdate(True)
|
||||
self.ubuntuMessagingMenuUpdate(True, newItem, toLabel)
|
||||
|
||||
def click_pushButtonAddAddressBook(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())
|
||||
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('')
|
||||
else:
|
||||
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())
|
||||
t = (inventoryHash,)
|
||||
self.ubuntuMessagingMenuClear(t)
|
||||
shared.sqlLock.acquire()
|
||||
shared.sqlSubmitQueue.put('''update inbox set read=1 WHERE msgid=?''')
|
||||
shared.sqlSubmitQueue.put(t)
|
||||
|
|
Loading…
Reference in New Issue
Block a user