Ticket #883: new_gmail_v3.patch

File new_gmail_v3.patch, 5.5 KB (added by knuckles@…, 4 years ago)
  • src/notify.py

     
    195195                        else: 
    196196                                txt = '' 
    197197                elif event_type == _('New E-mail'): 
    198                         txt = _('You have new E-mail on %s.') % (jid) 
     198                        no_of_messages = int(msg_type) 
     199                        text = i18n.ngettext('You have %d new E-mail message', 'You have %d new E-mail messages', no_of_messages, no_of_messages, no_of_messages) 
     200                        txt = _('%(new_mail_gajim_ui_msg)s on %(gmail_mail_address)s') % {'new_mail_gajim_ui_msg': text, 'gmail_mail_address': jid} 
    199201                        ntype = 'gmail.notify' 
    200202                        img = 'single_msg_recv.png' #FIXME: find a better image 
     203                        self.msg_type = msg_type = 'gmail' 
    201204                else: 
    202205                        # defaul failsafe values 
    203206                        img = 'chat_msg_recv.png' # img to display 
  • src/dialogs.py

     
    924924                        dodgerblue = gtk.gdk.color_parse('dodgerblue') 
    925925                        close_button.modify_bg(gtk.STATE_NORMAL, dodgerblue) 
    926926                        eventbox.modify_bg(gtk.STATE_NORMAL, dodgerblue) 
    927                         txt = _('You have new E-mail on %s.') % (jid) 
     927                        no_of_messages = int(msg_type) 
     928                        text = i18n.ngettext('You have %d new E-mail message', 'You have %d new E-mail messages', no_of_messages, no_of_messages, no_of_messages) 
     929                        txt = _('%(new_mail_gajim_ui_msg)s on %(gmail_mail_address)s') % {'new_mail_gajim_ui_msg': text, 'gmail_mail_address': jid} 
     930                        self.msg_type = msg_type = 'gmail' 
    928931                        event_description_label.set_markup('<span foreground="black">%s</span>' % txt) 
    929932                # position the window to bottom-right of screen 
    930933                window_width, self.window_height = self.window.get_size() 
  • src/gajim.py

     
    852852                        notify.notify(_('File Transfer Error'), 
    853853                                jid, account, 'file-send-error', file_props) 
    854854                                 
    855         def handle_event_gmail_notify(self, account, jid): 
     855        def handle_event_gmail_notify(self, account, array): 
     856                jid = array[0] 
     857                newmsgs = array[1] 
    856858                if gajim.config.get('notify_on_new_gmail_email'): 
    857                         notify.notify(_('New E-mail'), jid, account) 
     859                        notify.notify(_('New E-mail'), jid, account, newmsgs) 
    858860 
    859861        def add_event(self, account, jid, typ, args): 
    860862                '''add an event to the awaiting_events var''' 
     
    13221324                        ev = gajim.get_first_event(account, jid, typ) 
    13231325                        # Open the window 
    13241326                        self.roster.open_event(account, jid, ev) 
     1327                elif typ == message_control.TYPE_GMAIL: 
     1328                        if gajim.config.get_per('accounts', account, 'savepass'): 
     1329                                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')) 
     1330                        else: 
     1331                                url = ('http://mail.google.com/') 
     1332                        helpers.launch_browser_mailer('url', url) 
    13251333                if w: 
    13261334                        w.set_active_tab(jid) 
    13271335                        w.window.present() 
  • src/common/connection.py

     
    331331                        else: 
    332332                                self.dispatch('VCARD', vcard) 
    333333 
    334         def _gMailCB(self, con, gm): 
     334        def _gMailNewMailCB(self, con, gm): 
    335335                """Called when we get notified of new mail messages in gmail account""" 
    336336                if not gm.getTag('new-mail'): 
    337337                        return 
    338338                if gm.getTag('new-mail').getNamespace() == common.xmpp.NS_GMAILNOTIFY: 
     339                        # we'll now ask the server for the exact number of new messages 
    339340                        jid = gajim.get_jid_from_account(self.name) 
    340                         gajim.log.debug(('Notifying user of new gmail e-mail on %s.') % (jid)) 
    341                         self.dispatch('GMAIL_NOTIFY', jid) 
     341                        gajim.log.debug(('Got notification of new gmail e-mail on %s. Asking the server for more info.') % (jid)) 
     342                        iq = common.xmpp.Iq(typ = 'get') 
     343                        iq.setAttr('id', '13') 
     344                        query = iq.setTag('query') 
     345                        query.setNamespace(common.xmpp.NS_GMAILNOTIFY) 
     346                        self.to_be_sent.append(iq) 
    342347                        raise common.xmpp.NodeProcessed 
     348                 
     349        def _gMailQueryCB(self, con, gm): 
     350                """Called when we receive results from Querying the server for mail messages in gmail account""" 
     351                if not gm.getTag('mailbox'): 
     352                        return 
     353                if gm.getTag('mailbox').getNamespace() == common.xmpp.NS_GMAILNOTIFY: 
     354                        newmsgs = gm.getTag('mailbox').getAttr('total-matched') 
     355                        if newmsgs != '0': 
     356                                # there are new messages 
     357                                jid = gajim.get_jid_from_account(self.name) 
     358                                gajim.log.debug(('User has %s new gmail e-mails on %s.') % (newmsgs, jid)) 
     359                                self.dispatch('GMAIL_NOTIFY', (jid, newmsgs)) 
     360                        raise common.xmpp.NodeProcessed 
    343361 
    344362        def _messageCB(self, con, msg): 
    345363                """Called when we receive a message""" 
     
    17461764                        common.xmpp.NS_PRIVATE) 
    17471765                con.RegisterHandler('iq', self._HttpAuthCB, 'get', 
    17481766                        common.xmpp.NS_HTTP_AUTH) 
    1749                 con.RegisterHandler('iq', self._gMailCB, 'set', 
     1767                con.RegisterHandler('iq', self._gMailNewMailCB, 'set', 
    17501768                        common.xmpp.NS_GMAILNOTIFY) 
     1769                con.RegisterHandler('iq', self._gMailQueryCB, 'result', 
     1770                        common.xmpp.NS_GMAILNOTIFY) 
    17511771                con.RegisterHandler('iq', self._ErrorCB, 'error') 
    17521772                con.RegisterHandler('iq', self._IqCB) 
    17531773                con.RegisterHandler('iq', self._StanzaArrivedCB) 
  • src/message_control.py

     
    2424TYPE_CHAT = 'chat' 
    2525TYPE_GC = 'gc' 
    2626TYPE_PM = 'pm' 
     27TYPE_GMAIL = 'gmail' 
    2728 
    2829#################### 
    2930# FIXME: Can't this stuff happen once?