diff --git a/src/common/connection.py b/src/common/connection.py index d3da893aa..80469311e 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -340,14 +340,32 @@ class Connection: else: 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""" if not gm.getTag('new-mail'): return 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) - gajim.log.debug(('Notifying user of new gmail e-mail on %s.') % (jid)) - self.dispatch('GMAIL_NOTIFY', jid) + gajim.log.debug(('Got notification of new gmail e-mail on %s. Asking the server for more info.') % (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 def _messageCB(self, con, msg): @@ -1769,7 +1787,9 @@ class Connection: common.xmpp.NS_PRIVATE) con.RegisterHandler('iq', self._HttpAuthCB, 'get', 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) con.RegisterHandler('iq', self._ErrorCB, 'error') con.RegisterHandler('iq', self._IqCB) diff --git a/src/dialogs.py b/src/dialogs.py index bf2f37943..8dc80545f 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -859,7 +859,7 @@ _('Without a connection, you can not change your password.')).get_response() 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.jid = jid self.msg_type = msg_type @@ -947,7 +947,8 @@ class PopupNotificationWindow: dodgerblue = gtk.gdk.color_parse('dodgerblue') close_button.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('%s' % txt) # position the window to bottom-right of screen window_width, self.window_height = self.window.get_size() diff --git a/src/gajim.py b/src/gajim.py index e18d57582..e29d5865c 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -834,9 +834,11 @@ class Interface: notify.notify(_('File Transfer Error'), 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'): - 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): '''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) # Open the window 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: w.set_active_tab(jid) w.window.present() diff --git a/src/message_control.py b/src/message_control.py index 6a2eaa35e..14707341c 100644 --- a/src/message_control.py +++ b/src/message_control.py @@ -24,6 +24,7 @@ from common import gajim TYPE_CHAT = 'chat' TYPE_GC = 'gc' TYPE_PM = 'pm' +TYPE_GMAIL = 'gmail' #################### # FIXME: Can't this stuff happen once? diff --git a/src/notify.py b/src/notify.py index 93e2619d0..97ba1517a 100644 --- a/src/notify.py +++ b/src/notify.py @@ -48,14 +48,14 @@ if dbus_support.supported: import dbus.service 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 the Desktop Notification Specification. If that fails, then we fall back to the older style PopupNotificationWindow method.''' if gajim.config.get('use_notif_daemon') and dbus_support.supported: try: DesktopNotification(event_type, jid, account, msg_type, file_props, - path_to_image) + path_to_image, gmail_new_messages) return except dbus.dbus_bindings.DBusException, e: # 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 gajim.log.debug(str(e)) 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) class NotificationResponseManager: @@ -102,7 +102,7 @@ class DesktopNotification: '''A DesktopNotification that interfaces with DBus via the Desktop Notification specification''' 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.jid = jid self.msg_type = msg_type @@ -197,7 +197,8 @@ class DesktopNotification: else: txt = '' 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' img = 'single_msg_recv.png' #FIXME: find a better image else: