Notification when new mail arrives in Ubuntu

This commit is contained in:
fuzzgun 2013-05-11 17:33:16 +01:00
parent 24094949cf
commit 7825a3511b
2 changed files with 44 additions and 20 deletions

2
debian/control vendored
View File

@ -2,7 +2,7 @@ Source: pybitmessage
Section: contrib/comm Section: contrib/comm
Priority: extra Priority: extra
Maintainer: Jonathan Warren <jonathan@bitmessage.org> Maintainer: Jonathan Warren <jonathan@bitmessage.org>
Build-Depends: debhelper (>= 8.0.0), python (>= 2.7.0), openssl, python-qt4, libqt4-dev (>= 4.8.0), python-qt4-dev, sqlite3, libsqlite3-dev Build-Depends: debhelper (>= 8.0.0), python (>= 2.7.0), openssl, python-qt4, libqt4-dev (>= 4.8.0), python-qt4-dev, sqlite3, libsqlite3-dev, libmessaging-menu-dev
Standards-Version: 3.9.2 Standards-Version: 3.9.2
Homepage: https://bitmessage.org/ Homepage: https://bitmessage.org/
Vcs-Browser: https://github.com/Bitmessage/PyBitmessage Vcs-Browser: https://github.com/Bitmessage/PyBitmessage

View File

@ -1,3 +1,4 @@
try: try:
from PyQt4.QtCore import * from PyQt4.QtCore import *
from PyQt4.QtGui import * from PyQt4.QtGui import *
@ -6,13 +7,13 @@ except Exception, err:
print 'Error message:', err print 'Error message:', err
sys.exit() sys.exit()
withMessagingMenu = False
try: try:
from gi.repository import MessagingMenu from gi.repository import MessagingMenu
from gi.repository import Notify
withMessagingMenu = True
except ImportError: except ImportError:
MessagingMenu = None MessagingMenu = None
with_messagingmenu = False
else:
with_messagingmenu = True
from addresses import * from addresses import *
import shared import shared
@ -519,8 +520,8 @@ class MyForm(QtGui.QMainWindow):
self.appIndicatorShow() self.appIndicatorShow()
self.ui.tabWidget.setCurrentIndex(5) self.ui.tabWidget.setCurrentIndex(5)
# create application indicator # initialise application indicator
def createAppIndicator(self,app): def appIndicatorInit(self,app):
self.app = app self.app = app
self.app.tray = QSystemTrayIcon(QtGui.QIcon("images/can-icon-24px-red.png"), self.app) self.app.tray = QSystemTrayIcon(QtGui.QIcon("images/can-icon-24px-red.png"), self.app)
m = QMenu() m = QMenu()
@ -624,31 +625,39 @@ class MyForm(QtGui.QMainWindow):
# initialise the Ubuntu messaging menu # initialise the Ubuntu messaging menu
def ubuntuMessagingMenuInit(self): def ubuntuMessagingMenuInit(self):
global withMessagingMenu
# if this isn't ubuntu then don't do anything # if this isn't ubuntu then don't do anything
if not self.isUbuntu(): if not self.isUbuntu():
return return
# has messageing menu been installed # has messageing menu been installed
if not with_messagingmenu: if not withMessagingMenu:
print 'WARNING: libmessaging-menu-dev not installed' print 'WARNING: MessagingMenu is not available. Is libmessaging-menu-dev installed?'
return return
# create the menu server # create the menu server
if with_messagingmenu: if withMessagingMenu:
self.mmapp = MessagingMenu.App(desktop_id='pybitmessage.desktop') try:
self.mmapp.register() self.mmapp = MessagingMenu.App(desktop_id='pybitmessage.desktop')
self.mmapp.connect('activate-source', self.appIndicatorInbox) self.mmapp.register()
self.ubuntuMessagingMenuUnread(True) self.mmapp.connect('activate-source', self.appIndicatorInbox)
self.ubuntuMessagingMenuUnread(True)
except Exception:
withMessagingMenu = False
print 'WARNING: messaging menu disabled'
# update the Ubuntu messaging menu # update the Ubuntu messaging menu
def ubuntuMessagingMenuUpdate(self, drawAttention): def ubuntuMessagingMenuUpdate(self, drawAttention):
global withMessagingMenu
# if this isn't ubuntu then don't do anything # if this isn't ubuntu then don't do anything
if not self.isUbuntu(): if not self.isUbuntu():
return return
# has messageing menu been installed # has messageing menu been installed
if not with_messagingmenu: if not withMessagingMenu:
print 'WARNING: libmessaging-menu-dev not installed' print 'WARNING: messaging menu disabled or libmessaging-menu-dev not installed'
return return
# Remove previous messages and subscriptions entries, then recreate them # Remove previous messages and subscriptions entries, then recreate them
@ -662,6 +671,22 @@ class MyForm(QtGui.QMainWindow):
# update the menu entries # update the menu entries
self.ubuntuMessagingMenuUnread(drawAttention) self.ubuntuMessagingMenuUnread(drawAttention)
# initialise the message notifier
def notifierInit(self):
global withMessagingMenu
if withMessagingMenu:
Notify.init('pybitmessage')
# shows a notification
def notifierShow(self, title, subtitle):
global withMessagingMenu
if withMessagingMenu:
n = Notify.Notification.new(title, subtitle,'notification-message-email')
n.show()
return
# Show with tray
self.trayIcon.showMessage(title, subtitle, 1, 2000)
def tableWidgetInboxKeyPressEvent(self,event): def tableWidgetInboxKeyPressEvent(self,event):
if event.key() == QtCore.Qt.Key_Delete: if event.key() == QtCore.Qt.Key_Delete:
self.on_action_InboxTrash() self.on_action_InboxTrash()
@ -1186,11 +1211,11 @@ class MyForm(QtGui.QMainWindow):
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.trayIcon.showMessage('New Message', 'New message from '+ fromAddress, 1, 2000) 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.trayIcon.showMessage('New Message', 'New message from '+fromLabel, 1, 2000) 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)
@ -1618,7 +1643,6 @@ class MyForm(QtGui.QMainWindow):
self.ui.tableWidgetInbox.selectRow(currentRow) self.ui.tableWidgetInbox.selectRow(currentRow)
else: else:
self.ui.tableWidgetInbox.selectRow(currentRow-1) self.ui.tableWidgetInbox.selectRow(currentRow-1)
self.ubuntuMessagingMenuUpdate(False)
#Send item on the Sent tab to trash #Send item on the Sent tab to trash
def on_action_SentTrash(self): def on_action_SentTrash(self):
@ -1882,7 +1906,6 @@ class MyForm(QtGui.QMainWindow):
shared.sqlReturnQueue.get() shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit') shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release() shared.sqlLock.release()
self.ubuntuMessagingMenuUpdate(False)
def tableWidgetSentItemClicked(self): def tableWidgetSentItemClicked(self):
currentRow = self.ui.tableWidgetSent.currentRow() currentRow = self.ui.tableWidgetSent.currentRow()
@ -2172,7 +2195,8 @@ def run():
#self.hide() #self.hide()
if 'win32' in sys.platform or 'win64' in sys.platform: if 'win32' in sys.platform or 'win64' in sys.platform:
myapp.setWindowFlags(Qt.ToolTip) myapp.setWindowFlags(Qt.ToolTip)
myapp.createAppIndicator(app) myapp.appIndicatorInit(app)
myapp.ubuntuMessagingMenuInit() myapp.ubuntuMessagingMenuInit()
myapp.notifierInit()
sys.exit(app.exec_()) sys.exit(app.exec_())