Merge pull request #576 from yurivict/tray_inbox_unread_indicator

[NEW FEATURE] Implemented the indicator in tray icon that there are unread messages
This commit is contained in:
Jonathan Warren 2013-12-24 21:31:49 -08:00
commit 12adccf965
4 changed files with 66 additions and 9 deletions

View File

@ -518,6 +518,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
# UPDATE is slow, only update if status is different
if queryreturn != [] and (queryreturn[0][0] == 1) != readStatus:
sqlExecute('''UPDATE inbox set read = ? WHERE msgid=?''', readStatus, msgid)
shared.UISignalQueue.put(('changedInboxUnread', None))
queryreturn = sqlQuery('''SELECT msgid, toaddress, fromaddress, subject, received, message, encodingtype, read FROM inbox WHERE msgid=?''', msgid)
data = '{"inboxMessage":['
for row in queryreturn:

View File

@ -610,6 +610,8 @@ class MyForm(QtGui.QMainWindow):
"updateNumberOfBroadcastsProcessed()"), self.updateNumberOfBroadcastsProcessed)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"setStatusIcon(PyQt_PyObject)"), self.setStatusIcon)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"changedInboxUnread(PyQt_PyObject)"), self.changedInboxUnread)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"rerenderInboxFromLabels()"), self.rerenderInboxFromLabels)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
@ -981,8 +983,7 @@ class MyForm(QtGui.QMainWindow):
# create application indicator
def appIndicatorInit(self, app):
self.tray = QSystemTrayIcon(QtGui.QIcon(
":/newPrefix/images/can-icon-24px-red.png"), app)
self.initTrayIcon("can-icon-24px-red.png", app)
if sys.platform[0:3] == 'win':
traySignal = "activated(QSystemTrayIcon::ActivationReason)"
QtCore.QObject.connect(self.tray, QtCore.SIGNAL(
@ -1540,8 +1541,7 @@ class MyForm(QtGui.QMainWindow):
if self.actionStatus is not None:
self.actionStatus.setText(_translate(
"MainWindow", "Not Connected"))
self.tray.setIcon(QtGui.QIcon(
":/newPrefix/images/can-icon-24px-red.png"))
self.setTrayIconFile("can-icon-24px-red.png")
if color == 'yellow':
if self.statusBar().currentMessage() == 'Warning: You are currently not connected. Bitmessage will do the work necessary to send the message but it won\'t send until you connect.':
self.statusBar().showMessage('')
@ -1558,8 +1558,7 @@ class MyForm(QtGui.QMainWindow):
if self.actionStatus is not None:
self.actionStatus.setText(_translate(
"MainWindow", "Connected"))
self.tray.setIcon(QtGui.QIcon(
":/newPrefix/images/can-icon-24px-yellow.png"))
self.setTrayIconFile("can-icon-24px-yellow.png")
if color == 'green':
if self.statusBar().currentMessage() == 'Warning: You are currently not connected. Bitmessage will do the work necessary to send the message but it won\'t send until you connect.':
self.statusBar().showMessage('')
@ -1575,8 +1574,59 @@ class MyForm(QtGui.QMainWindow):
if self.actionStatus is not None:
self.actionStatus.setText(_translate(
"MainWindow", "Connected"))
self.tray.setIcon(QtGui.QIcon(
":/newPrefix/images/can-icon-24px-green.png"))
self.setTrayIconFile("can-icon-24px-green.png")
def initTrayIcon(self, iconFileName, app):
self.currentTrayIconFileName = iconFileName
self.tray = QSystemTrayIcon(
self.calcTrayIcon(iconFileName, self.findInboxUnreadCount()), app)
def setTrayIconFile(self, iconFileName):
self.currentTrayIconFileName = iconFileName
self.drawTrayIcon(iconFileName, self.findInboxUnreadCount())
def calcTrayIcon(self, iconFileName, inboxUnreadCount):
pixmap = QtGui.QPixmap(":/newPrefix/images/"+iconFileName)
if inboxUnreadCount > 0:
# choose font and calculate font parameters
fontName = "Lucida"
fontSize = 10
font = QtGui.QFont(fontName, fontSize, QtGui.QFont.Bold)
fontMetrics = QtGui.QFontMetrics(font)
# text
txt = str(inboxUnreadCount)
rect = fontMetrics.boundingRect(txt)
# margins that we add in the top-right corner
marginX = 2
marginY = 0 # it looks like -2 is also ok due to the error of metric
# if it renders too wide we need to change it to a plus symbol
if rect.width() > 20:
txt = "+"
fontSize = 15
font = QtGui.QFont(fontName, fontSize, QtGui.QFont.Bold)
fontMetrics = QtGui.QFontMetrics(font)
rect = fontMetrics.boundingRect(txt)
# draw text
painter = QPainter()
painter.begin(pixmap)
painter.setPen(QtGui.QPen(QtGui.QColor(255, 0, 0), Qt.SolidPattern))
painter.setFont(font)
painter.drawText(24-rect.right()-marginX, -rect.top()+marginY, txt)
painter.end()
return QtGui.QIcon(pixmap)
def drawTrayIcon(self, iconFileName, inboxUnreadCount):
self.tray.setIcon(self.calcTrayIcon(iconFileName, inboxUnreadCount))
def changedInboxUnread(self):
self.drawTrayIcon(self.currentTrayIconFileName, self.findInboxUnreadCount())
def findInboxUnreadCount(self):
queryreturn = sqlQuery('''SELECT count(*) from inbox WHERE folder='inbox' and read=0''')
cnt = 0
for row in queryreturn:
cnt, = row
return int(cnt)
def updateSentItemStatusByHash(self, toRipe, textToDisplay):
for i in range(self.ui.tableWidgetSent.rowCount()):
@ -1623,6 +1673,7 @@ class MyForm(QtGui.QMainWindow):
"MainWindow", "Message trashed"))
self.ui.tableWidgetInbox.removeRow(i)
break
self.changedInboxUnread()
def displayAlert(self, title, text, exitAfterUserClicksOk):
self.statusBar().showMessage(text)
@ -2556,6 +2607,7 @@ class MyForm(QtGui.QMainWindow):
self.ui.tableWidgetInbox.item(currentRow, 1).setFont(font)
self.ui.tableWidgetInbox.item(currentRow, 2).setFont(font)
self.ui.tableWidgetInbox.item(currentRow, 3).setFont(font)
self.changedInboxUnread()
# 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.
# We could also select upwards, but then our problem would be with the topmost message.
@ -3079,7 +3131,6 @@ class MyForm(QtGui.QMainWindow):
def tableWidgetInboxItemClicked(self):
currentRow = self.ui.tableWidgetInbox.currentRow()
if currentRow >= 0:
font = QFont()
font.setBold(False)
self.ui.textEditInboxMessage.setCurrentFont(font)
@ -3122,6 +3173,7 @@ class MyForm(QtGui.QMainWindow):
currentRow, 3).data(Qt.UserRole).toPyObject())
self.ubuntuMessagingMenuClear(inventoryHash)
sqlExecute('''update inbox set read=1 WHERE msgid=?''', inventoryHash)
self.changedInboxUnread()
def tableWidgetSentItemClicked(self):
currentRow = self.ui.tableWidgetSent.currentRow()
@ -3669,6 +3721,8 @@ class UISignaler(QThread):
self.emit(SIGNAL("updateNumberOfBroadcastsProcessed()"))
elif command == 'setStatusIcon':
self.emit(SIGNAL("setStatusIcon(PyQt_PyObject)"), data)
elif command == 'changedInboxUnread':
self.emit(SIGNAL("changedInboxUnread(PyQt_PyObject)"), data)
elif command == 'rerenderInboxFromLabels':
self.emit(SIGNAL("rerenderInboxFromLabels()"))
elif command == 'rerenderSentToLabels':

View File

@ -3,6 +3,7 @@ import shared
def insert(t):
sqlExecute('''INSERT INTO inbox VALUES (?,?,?,?,?,?,?,?,?)''', *t)
shared.UISignalQueue.put(('changedInboxUnread', None))
def trash(msgid):
sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', msgid)

View File

@ -85,6 +85,7 @@ def markAllInboxMessagesAsUnread():
cur.execute(item, parameters)
output = cur.fetchall()
conn.commit()
shared.UISignalQueue.put(('changedInboxUnread', None))
print 'done'
def vacuum():