Merge branch 'tray_inbox_unread_indicator'

This commit is contained in:
Yuri 2013-11-28 17:07:15 -08:00
commit 58af281e75
4 changed files with 66 additions and 9 deletions

View File

@ -516,6 +516,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
# UPDATE is slow, only update if status is different # UPDATE is slow, only update if status is different
if queryreturn != [] and (queryreturn[0][0] == 1) != readStatus: if queryreturn != [] and (queryreturn[0][0] == 1) != readStatus:
sqlExecute('''UPDATE inbox set read = ? WHERE msgid=?''', readStatus, msgid) 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) queryreturn = sqlQuery('''SELECT msgid, toaddress, fromaddress, subject, received, message, encodingtype, read FROM inbox WHERE msgid=?''', msgid)
data = '{"inboxMessage":[' data = '{"inboxMessage":['
for row in queryreturn: for row in queryreturn:

View File

@ -609,6 +609,8 @@ class MyForm(QtGui.QMainWindow):
"updateNumberOfBroadcastsProcessed()"), self.updateNumberOfBroadcastsProcessed) "updateNumberOfBroadcastsProcessed()"), self.updateNumberOfBroadcastsProcessed)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"setStatusIcon(PyQt_PyObject)"), self.setStatusIcon) "setStatusIcon(PyQt_PyObject)"), self.setStatusIcon)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"changedInboxUnread(PyQt_PyObject)"), self.changedInboxUnread)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"rerenderInboxFromLabels()"), self.rerenderInboxFromLabels) "rerenderInboxFromLabels()"), self.rerenderInboxFromLabels)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
@ -980,8 +982,7 @@ class MyForm(QtGui.QMainWindow):
# create application indicator # create application indicator
def appIndicatorInit(self, app): def appIndicatorInit(self, app):
self.tray = QSystemTrayIcon(QtGui.QIcon( self.initTrayIcon("can-icon-24px-red.png", app)
":/newPrefix/images/can-icon-24px-red.png"), app)
if sys.platform[0:3] == 'win': if sys.platform[0:3] == 'win':
traySignal = "activated(QSystemTrayIcon::ActivationReason)" traySignal = "activated(QSystemTrayIcon::ActivationReason)"
QtCore.QObject.connect(self.tray, QtCore.SIGNAL( QtCore.QObject.connect(self.tray, QtCore.SIGNAL(
@ -1539,8 +1540,7 @@ class MyForm(QtGui.QMainWindow):
if self.actionStatus is not None: if self.actionStatus is not None:
self.actionStatus.setText(_translate( self.actionStatus.setText(_translate(
"MainWindow", "Not Connected")) "MainWindow", "Not Connected"))
self.tray.setIcon(QtGui.QIcon( self.setTrayIconFile("can-icon-24px-red.png")
":/newPrefix/images/can-icon-24px-red.png"))
if color == 'yellow': 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.': 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('') self.statusBar().showMessage('')
@ -1557,8 +1557,7 @@ class MyForm(QtGui.QMainWindow):
if self.actionStatus is not None: if self.actionStatus is not None:
self.actionStatus.setText(_translate( self.actionStatus.setText(_translate(
"MainWindow", "Connected")) "MainWindow", "Connected"))
self.tray.setIcon(QtGui.QIcon( self.setTrayIconFile("can-icon-24px-yellow.png")
":/newPrefix/images/can-icon-24px-yellow.png"))
if color == 'green': 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.': 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('') self.statusBar().showMessage('')
@ -1574,8 +1573,59 @@ class MyForm(QtGui.QMainWindow):
if self.actionStatus is not None: if self.actionStatus is not None:
self.actionStatus.setText(_translate( self.actionStatus.setText(_translate(
"MainWindow", "Connected")) "MainWindow", "Connected"))
self.tray.setIcon(QtGui.QIcon( self.setTrayIconFile("can-icon-24px-green.png")
":/newPrefix/images/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): def updateSentItemStatusByHash(self, toRipe, textToDisplay):
for i in range(self.ui.tableWidgetSent.rowCount()): for i in range(self.ui.tableWidgetSent.rowCount()):
@ -1622,6 +1672,7 @@ class MyForm(QtGui.QMainWindow):
"MainWindow", "Message trashed")) "MainWindow", "Message trashed"))
self.ui.tableWidgetInbox.removeRow(i) self.ui.tableWidgetInbox.removeRow(i)
break break
self.changedInboxUnread()
def displayAlert(self, title, text, exitAfterUserClicksOk): def displayAlert(self, title, text, exitAfterUserClicksOk):
self.statusBar().showMessage(text) self.statusBar().showMessage(text)
@ -2539,6 +2590,7 @@ class MyForm(QtGui.QMainWindow):
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)
self.changedInboxUnread()
# 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.
@ -3062,7 +3114,6 @@ class MyForm(QtGui.QMainWindow):
def tableWidgetInboxItemClicked(self): def tableWidgetInboxItemClicked(self):
currentRow = self.ui.tableWidgetInbox.currentRow() currentRow = self.ui.tableWidgetInbox.currentRow()
if currentRow >= 0: if currentRow >= 0:
font = QFont() font = QFont()
font.setBold(False) font.setBold(False)
self.ui.textEditInboxMessage.setCurrentFont(font) self.ui.textEditInboxMessage.setCurrentFont(font)
@ -3105,6 +3156,7 @@ class MyForm(QtGui.QMainWindow):
currentRow, 3).data(Qt.UserRole).toPyObject()) currentRow, 3).data(Qt.UserRole).toPyObject())
self.ubuntuMessagingMenuClear(inventoryHash) self.ubuntuMessagingMenuClear(inventoryHash)
sqlExecute('''update inbox set read=1 WHERE msgid=?''', inventoryHash) sqlExecute('''update inbox set read=1 WHERE msgid=?''', inventoryHash)
self.changedInboxUnread()
def tableWidgetSentItemClicked(self): def tableWidgetSentItemClicked(self):
currentRow = self.ui.tableWidgetSent.currentRow() currentRow = self.ui.tableWidgetSent.currentRow()
@ -3593,6 +3645,8 @@ class UISignaler(QThread):
self.emit(SIGNAL("updateNumberOfBroadcastsProcessed()")) self.emit(SIGNAL("updateNumberOfBroadcastsProcessed()"))
elif command == 'setStatusIcon': elif command == 'setStatusIcon':
self.emit(SIGNAL("setStatusIcon(PyQt_PyObject)"), data) self.emit(SIGNAL("setStatusIcon(PyQt_PyObject)"), data)
elif command == 'changedInboxUnread':
self.emit(SIGNAL("changedInboxUnread(PyQt_PyObject)"), data)
elif command == 'rerenderInboxFromLabels': elif command == 'rerenderInboxFromLabels':
self.emit(SIGNAL("rerenderInboxFromLabels()")) self.emit(SIGNAL("rerenderInboxFromLabels()"))
elif command == 'rerenderSentToLabels': elif command == 'rerenderSentToLabels':

View File

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

View File

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