[knuckles] GMail notification now shows number of messages and if clicked opens inbox and all that :)
This commit is contained in:
parent
8516a7a094
commit
a9727e39db
|
@ -340,14 +340,32 @@ class Connection:
|
||||||
else:
|
else:
|
||||||
self.dispatch('VCARD', vcard)
|
self.dispatch('VCARD', vcard)
|
||||||
|
|
||||||
def _gMailCB(self, con, gm):
|
def _gMailNewMailCB(self, con, gm):
|
||||||
"""Called when we get notified of new mail messages in gmail account"""
|
"""Called when we get notified of new mail messages in gmail account"""
|
||||||
if not gm.getTag('new-mail'):
|
if not gm.getTag('new-mail'):
|
||||||
return
|
return
|
||||||
if gm.getTag('new-mail').getNamespace() == common.xmpp.NS_GMAILNOTIFY:
|
if gm.getTag('new-mail').getNamespace() == common.xmpp.NS_GMAILNOTIFY:
|
||||||
|
# we'll now ask the server for the exact number of new messages
|
||||||
jid = gajim.get_jid_from_account(self.name)
|
jid = gajim.get_jid_from_account(self.name)
|
||||||
gajim.log.debug(('Notifying user of new gmail e-mail on %s.') % (jid))
|
gajim.log.debug(('Got notification of new gmail e-mail on %s. Asking the server for more info.') % (jid))
|
||||||
self.dispatch('GMAIL_NOTIFY', jid)
|
iq = common.xmpp.Iq(typ = 'get')
|
||||||
|
iq.setAttr('id', '13')
|
||||||
|
query = iq.setTag('query')
|
||||||
|
query.setNamespace(common.xmpp.NS_GMAILNOTIFY)
|
||||||
|
self.to_be_sent.append(iq)
|
||||||
|
raise common.xmpp.NodeProcessed
|
||||||
|
|
||||||
|
def _gMailQueryCB(self, con, gm):
|
||||||
|
"""Called when we receive results from Querying the server for mail messages in gmail account"""
|
||||||
|
if not gm.getTag('mailbox'):
|
||||||
|
return
|
||||||
|
if gm.getTag('mailbox').getNamespace() == common.xmpp.NS_GMAILNOTIFY:
|
||||||
|
newmsgs = gm.getTag('mailbox').getAttr('total-matched')
|
||||||
|
if newmsgs != '0':
|
||||||
|
# there are new messages
|
||||||
|
jid = gajim.get_jid_from_account(self.name)
|
||||||
|
gajim.log.debug(('User has %s new gmail e-mails on %s.') % (newmsgs, jid))
|
||||||
|
self.dispatch('GMAIL_NOTIFY', (jid, newmsgs))
|
||||||
raise common.xmpp.NodeProcessed
|
raise common.xmpp.NodeProcessed
|
||||||
|
|
||||||
def _messageCB(self, con, msg):
|
def _messageCB(self, con, msg):
|
||||||
|
@ -1769,7 +1787,9 @@ class Connection:
|
||||||
common.xmpp.NS_PRIVATE)
|
common.xmpp.NS_PRIVATE)
|
||||||
con.RegisterHandler('iq', self._HttpAuthCB, 'get',
|
con.RegisterHandler('iq', self._HttpAuthCB, 'get',
|
||||||
common.xmpp.NS_HTTP_AUTH)
|
common.xmpp.NS_HTTP_AUTH)
|
||||||
con.RegisterHandler('iq', self._gMailCB, 'set',
|
con.RegisterHandler('iq', self._gMailNewMailCB, 'set',
|
||||||
|
common.xmpp.NS_GMAILNOTIFY)
|
||||||
|
con.RegisterHandler('iq', self._gMailQueryCB, 'result',
|
||||||
common.xmpp.NS_GMAILNOTIFY)
|
common.xmpp.NS_GMAILNOTIFY)
|
||||||
con.RegisterHandler('iq', self._ErrorCB, 'error')
|
con.RegisterHandler('iq', self._ErrorCB, 'error')
|
||||||
con.RegisterHandler('iq', self._IqCB)
|
con.RegisterHandler('iq', self._IqCB)
|
||||||
|
|
|
@ -859,7 +859,7 @@ _('Without a connection, you can not change your password.')).get_response()
|
||||||
|
|
||||||
|
|
||||||
class PopupNotificationWindow:
|
class PopupNotificationWindow:
|
||||||
def __init__(self, event_type, jid, account, msg_type = '', file_props = None):
|
def __init__(self, event_type, jid, account, msg_type = '', file_props = None, gmail_new_messages = None):
|
||||||
self.account = account
|
self.account = account
|
||||||
self.jid = jid
|
self.jid = jid
|
||||||
self.msg_type = msg_type
|
self.msg_type = msg_type
|
||||||
|
@ -947,7 +947,8 @@ class PopupNotificationWindow:
|
||||||
dodgerblue = gtk.gdk.color_parse('dodgerblue')
|
dodgerblue = gtk.gdk.color_parse('dodgerblue')
|
||||||
close_button.modify_bg(gtk.STATE_NORMAL, dodgerblue)
|
close_button.modify_bg(gtk.STATE_NORMAL, dodgerblue)
|
||||||
eventbox.modify_bg(gtk.STATE_NORMAL, dodgerblue)
|
eventbox.modify_bg(gtk.STATE_NORMAL, dodgerblue)
|
||||||
txt = _('You have new E-mail on %s.') % (jid)
|
text = i18n.ngettext('You have %d new E-mail message', 'You have %d new E-mail messages', gmail_new_messages, gmail_new_messages, gmail_new_messages)
|
||||||
|
txt = _('%(new_mail_gajim_ui_msg)s on %(gmail_mail_address)s') % {'new_mail_gajim_ui_msg': text, 'gmail_mail_address': jid}
|
||||||
event_description_label.set_markup('<span foreground="black">%s</span>' % txt)
|
event_description_label.set_markup('<span foreground="black">%s</span>' % txt)
|
||||||
# position the window to bottom-right of screen
|
# position the window to bottom-right of screen
|
||||||
window_width, self.window_height = self.window.get_size()
|
window_width, self.window_height = self.window.get_size()
|
||||||
|
|
12
src/gajim.py
12
src/gajim.py
|
@ -834,9 +834,11 @@ class Interface:
|
||||||
notify.notify(_('File Transfer Error'),
|
notify.notify(_('File Transfer Error'),
|
||||||
jid, account, 'file-send-error', file_props)
|
jid, account, 'file-send-error', file_props)
|
||||||
|
|
||||||
def handle_event_gmail_notify(self, account, jid):
|
def handle_event_gmail_notify(self, account, array):
|
||||||
|
jid = array[0]
|
||||||
|
newmsgs = array[1]
|
||||||
if gajim.config.get('notify_on_new_gmail_email'):
|
if gajim.config.get('notify_on_new_gmail_email'):
|
||||||
notify.notify(_('New E-mail'), jid, account)
|
notify.notify(_('New E-mail'), jid, account, 'gmail', gmail_new_messages = int(newmsgs))
|
||||||
|
|
||||||
def save_avatar_files(self, jid, photo_decoded):
|
def save_avatar_files(self, jid, photo_decoded):
|
||||||
'''Save the decoded avatar to a separate file, and generate files for dbus notifications'''
|
'''Save the decoded avatar to a separate file, and generate files for dbus notifications'''
|
||||||
|
@ -1328,6 +1330,12 @@ class Interface:
|
||||||
ev = gajim.get_first_event(account, jid, typ)
|
ev = gajim.get_first_event(account, jid, typ)
|
||||||
# Open the window
|
# Open the window
|
||||||
self.roster.open_event(account, jid, ev)
|
self.roster.open_event(account, jid, ev)
|
||||||
|
elif typ == message_control.TYPE_GMAIL:
|
||||||
|
if gajim.config.get_per('accounts', account, 'savepass'):
|
||||||
|
url = ('http://www.google.com/accounts/ServiceLoginAuth?service=mail&Email=%s&Passwd=%s&continue=https://mail.google.com/mail') % (gajim.config.get_per('accounts', account, 'name'),gajim.config.get_per('accounts', account, 'password'))
|
||||||
|
else:
|
||||||
|
url = ('http://mail.google.com/')
|
||||||
|
helpers.launch_browser_mailer('url', url)
|
||||||
if w:
|
if w:
|
||||||
w.set_active_tab(jid)
|
w.set_active_tab(jid)
|
||||||
w.window.present()
|
w.window.present()
|
||||||
|
|
|
@ -24,6 +24,7 @@ from common import gajim
|
||||||
TYPE_CHAT = 'chat'
|
TYPE_CHAT = 'chat'
|
||||||
TYPE_GC = 'gc'
|
TYPE_GC = 'gc'
|
||||||
TYPE_PM = 'pm'
|
TYPE_PM = 'pm'
|
||||||
|
TYPE_GMAIL = 'gmail'
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# FIXME: Can't this stuff happen once?
|
# FIXME: Can't this stuff happen once?
|
||||||
|
|
|
@ -48,14 +48,14 @@ if dbus_support.supported:
|
||||||
import dbus.service
|
import dbus.service
|
||||||
|
|
||||||
def notify(event_type, jid, account, msg_type = '', file_props = None,
|
def notify(event_type, jid, account, msg_type = '', file_props = None,
|
||||||
path_to_image = None):
|
path_to_image = None, gmail_new_messages = None):
|
||||||
'''Notifies a user of an event. It first tries to a valid implementation of
|
'''Notifies a user of an event. It first tries to a valid implementation of
|
||||||
the Desktop Notification Specification. If that fails, then we fall back to
|
the Desktop Notification Specification. If that fails, then we fall back to
|
||||||
the older style PopupNotificationWindow method.'''
|
the older style PopupNotificationWindow method.'''
|
||||||
if gajim.config.get('use_notif_daemon') and dbus_support.supported:
|
if gajim.config.get('use_notif_daemon') and dbus_support.supported:
|
||||||
try:
|
try:
|
||||||
DesktopNotification(event_type, jid, account, msg_type, file_props,
|
DesktopNotification(event_type, jid, account, msg_type, file_props,
|
||||||
path_to_image)
|
path_to_image, gmail_new_messages)
|
||||||
return
|
return
|
||||||
except dbus.dbus_bindings.DBusException, e:
|
except dbus.dbus_bindings.DBusException, e:
|
||||||
# Connection to D-Bus failed, try popup
|
# Connection to D-Bus failed, try popup
|
||||||
|
@ -64,7 +64,7 @@ def notify(event_type, jid, account, msg_type = '', file_props = None,
|
||||||
# This means that we sent the message incorrectly
|
# This means that we sent the message incorrectly
|
||||||
gajim.log.debug(str(e))
|
gajim.log.debug(str(e))
|
||||||
instance = dialogs.PopupNotificationWindow(event_type, jid, account,
|
instance = dialogs.PopupNotificationWindow(event_type, jid, account,
|
||||||
msg_type, file_props)
|
msg_type, file_props, gmail_new_messages)
|
||||||
gajim.interface.roster.popup_notification_windows.append(instance)
|
gajim.interface.roster.popup_notification_windows.append(instance)
|
||||||
|
|
||||||
class NotificationResponseManager:
|
class NotificationResponseManager:
|
||||||
|
@ -102,7 +102,7 @@ class DesktopNotification:
|
||||||
'''A DesktopNotification that interfaces with DBus via the Desktop
|
'''A DesktopNotification that interfaces with DBus via the Desktop
|
||||||
Notification specification'''
|
Notification specification'''
|
||||||
def __init__(self, event_type, jid, account, msg_type = '',
|
def __init__(self, event_type, jid, account, msg_type = '',
|
||||||
file_props = None, path_to_image = None):
|
file_props = None, path_to_image = None, gmail_new_messages = None):
|
||||||
self.account = account
|
self.account = account
|
||||||
self.jid = jid
|
self.jid = jid
|
||||||
self.msg_type = msg_type
|
self.msg_type = msg_type
|
||||||
|
@ -197,7 +197,8 @@ class DesktopNotification:
|
||||||
else:
|
else:
|
||||||
txt = ''
|
txt = ''
|
||||||
elif event_type == _('New E-mail'):
|
elif event_type == _('New E-mail'):
|
||||||
txt = _('You have new E-mail on %s.') % (jid)
|
text = i18n.ngettext('You have %d new E-mail message', 'You have %d new E-mail messages', gmail_new_messages, gmail_new_messages, gmail_new_messages)
|
||||||
|
txt = _('%(new_mail_gajim_ui_msg)s on %(gmail_mail_address)s') % {'new_mail_gajim_ui_msg': text, 'gmail_mail_address': jid}
|
||||||
ntype = 'gmail.notify'
|
ntype = 'gmail.notify'
|
||||||
img = 'single_msg_recv.png' #FIXME: find a better image
|
img = 'single_msg_recv.png' #FIXME: find a better image
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue