Ubuntu Messaging Menu #149

Merged
ghost merged 3 commits from master into master 2013-05-14 19:10:44 +02:00
Showing only changes of commit 09a854c203 - Show all commits

View File

@ -35,6 +35,8 @@ import pickle
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()
@ -239,13 +241,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:
@ -481,6 +482,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:
@ -508,30 +515,33 @@ class MyForm(QtGui.QMainWindow):
self.show() self.show()
self.setWindowState(self.windowState() & QtCore.Qt.WindowMaximized) self.setWindowState(self.windowState() & QtCore.Qt.WindowMaximized)
# 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)
# select unread message selectedItem = None
self.ui.tableWidgetInbox.selectRow(self.getUnreadMessageIndex()) if source_id == 'Subscriptions':
self.tableWidgetInboxItemClicked() # select unread broadcast
if self.newBroadcastItem is not None:
selectedItem = self.newBroadcastItem
self.newBroadcastItem = None
else:
# select unread message
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 # Show the program window and select send tab
def appIndicatorSend(self): def appIndicatorSend(self):
@ -603,10 +613,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
@ -619,8 +654,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:
@ -629,7 +664,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:
@ -677,7 +712,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
@ -689,6 +724,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"):
@ -1073,7 +1114,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)
@ -1092,7 +1133,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'))
@ -1234,8 +1275,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:
@ -1246,7 +1287,7 @@ class MyForm(QtGui.QMainWindow):
font = QFont() font = QFont()
font.setBold(True) font.setBold(True)
self.ui.tableWidgetInbox.setSortingEnabled(False) self.ui.tableWidgetInbox.setSortingEnabled(False)
newItem = QtGui.QTableWidgetItem(unicode(toLabel,'utf-8')) newItem = QtGui.QTableWidgetItem(unicode(toLabel,'utf-8'))
newItem.setFont(font) newItem.setFont(font)
newItem.setData(Qt.UserRole,str(toAddress)) newItem.setData(Qt.UserRole,str(toAddress))
if shared.safeConfigGetBoolean(str(toAddress),'mailinglist'): if shared.safeConfigGetBoolean(str(toAddress),'mailinglist'):
@ -1255,17 +1296,17 @@ class MyForm(QtGui.QMainWindow):
self.ui.tableWidgetInbox.setItem(0,0,newItem) self.ui.tableWidgetInbox.setItem(0,0,newItem)
if fromLabel == '': if fromLabel == '':
newItem = QtGui.QTableWidgetItem(unicode(fromAddress,'utf-8')) newItem = QtGui.QTableWidgetItem(unicode(fromAddress,'utf-8'))
if shared.config.getboolean('bitmessagesettings', 'showtraynotifications'): if shared.config.getboolean('bitmessagesettings', 'showtraynotifications'):
self.notifierShow('New Message', 'From '+ fromAddress) self.notifierShow('New Message', 'From '+ fromAddress)
else: else:
newItem = QtGui.QTableWidgetItem(unicode(fromLabel,'utf-8')) newItem = QtGui.QTableWidgetItem(unicode(fromLabel,'utf-8'))
if shared.config.getboolean('bitmessagesettings', 'showtraynotifications'): if shared.config.getboolean('bitmessagesettings', 'showtraynotifications'):
self.notifierShow('New Message', 'From ' + fromLabel) self.notifierShow('New Message', 'From ' + fromLabel)
newItem.setData(Qt.UserRole,str(fromAddress)) newItem.setData(Qt.UserRole,str(fromAddress))
newItem.setFont(font) newItem.setFont(font)
self.ui.tableWidgetInbox.setItem(0,1,newItem) self.ui.tableWidgetInbox.setItem(0,1,newItem)
newItem = QtGui.QTableWidgetItem(unicode(subject,'utf-8)')) newItem = QtGui.QTableWidgetItem(unicode(subject,'utf-8)'))
newItem.setData(Qt.UserRole,unicode(message,'utf-8)')) newItem.setData(Qt.UserRole,unicode(message,'utf-8)'))
newItem.setFont(font) newItem.setFont(font)
self.ui.tableWidgetInbox.setItem(0,2,newItem) self.ui.tableWidgetInbox.setItem(0,2,newItem)
@ -1281,7 +1322,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)
@ -1641,7 +1682,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'):
@ -1966,6 +2007,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)