Ticket #883: new_gmail_v4.patch

File new_gmail_v4.patch, 7.1 KB (added by knuckles@…, 4 years ago)

latest latest version

  • src/notify.py

     
    4848                import dbus.service 
    4949 
    5050def notify(event_type, jid, account, msg_type = '', file_props = None, 
    51         path_to_image = None): 
     51        path_to_image = None, gmail_new_messages = None): 
    5252        '''Notifies a user of an event. It first tries to a valid implementation of 
    5353        the Desktop Notification Specification. If that fails, then we fall back to 
    5454        the older style PopupNotificationWindow method.''' 
    5555        if gajim.config.get('use_notif_daemon') and dbus_support.supported: 
    5656                try: 
    5757                        DesktopNotification(event_type, jid, account, msg_type, file_props, 
    58                                 path_to_image) 
     58                                path_to_image, gmail_new_messages) 
    5959                        return 
    6060                except dbus.dbus_bindings.DBusException, e: 
    6161                        # Connection to D-Bus failed, try popup 
     
    6464                        # This means that we sent the message incorrectly 
    6565                        gajim.log.debug(str(e)) 
    6666        instance = dialogs.PopupNotificationWindow(event_type, jid, account, 
    67                 msg_type, file_props) 
     67                msg_type, file_props, gmail_new_messages) 
    6868        gajim.interface.roster.popup_notification_windows.append(instance) 
    6969 
    7070class NotificationResponseManager: 
     
    102102        '''A DesktopNotification that interfaces with DBus via the Desktop 
    103103        Notification specification''' 
    104104        def __init__(self, event_type, jid, account, msg_type = '', 
    105                 file_props = None, path_to_image = None): 
     105                file_props = None, path_to_image = None, gmail_new_messages = None): 
    106106                self.account = account 
    107107                self.jid = jid 
    108108                self.msg_type = msg_type 
     
    195195                        else: 
    196196                                txt = '' 
    197197                elif event_type == _('New E-mail'): 
    198                         txt = _('You have new E-mail on %s.') % (jid) 
     198                        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) 
     199                        txt = _('%(new_mail_gajim_ui_msg)s on %(gmail_mail_address)s') % {'new_mail_gajim_ui_msg': text, 'gmail_mail_address': jid} 
    199200                        ntype = 'gmail.notify' 
    200201                        img = 'single_msg_recv.png' #FIXME: find a better image 
    201202                else: 
  • src/dialogs.py

     
    859859 
    860860 
    861861class PopupNotificationWindow: 
    862         def __init__(self, event_type, jid, account, msg_type = '', file_props = None): 
     862        def __init__(self, event_type, jid, account, msg_type = '', file_props = None, gmail_new_messages = None): 
    863863                self.account = account 
    864864                self.jid = jid 
    865865                self.msg_type = msg_type 
     
    947947                        dodgerblue = gtk.gdk.color_parse('dodgerblue') 
    948948                        close_button.modify_bg(gtk.STATE_NORMAL, dodgerblue) 
    949949                        eventbox.modify_bg(gtk.STATE_NORMAL, dodgerblue) 
    950                         txt = _('You have new E-mail on %s.') % (jid) 
     950                        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) 
     951                        txt = _('%(new_mail_gajim_ui_msg)s on %(gmail_mail_address)s') % {'new_mail_gajim_ui_msg': text, 'gmail_mail_address': jid} 
    951952                        event_description_label.set_markup('<span foreground="black">%s</span>' % txt) 
    952953                # position the window to bottom-right of screen 
    953954                window_width, self.window_height = self.window.get_size() 
  • src/gajim.py

     
    864864                        notify.notify(_('File Transfer Error'), 
    865865                                jid, account, 'file-send-error', file_props) 
    866866                                 
    867         def handle_event_gmail_notify(self, account, jid): 
     867        def handle_event_gmail_notify(self, account, array): 
     868                jid = array[0] 
     869                newmsgs = array[1] 
    868870                if gajim.config.get('notify_on_new_gmail_email'): 
    869                         notify.notify(_('New E-mail'), jid, account) 
     871                        notify.notify(_('New E-mail'), jid, account, gmail_new_messages = int(newmsgs)) 
    870872 
    871873        def add_event(self, account, jid, typ, args): 
    872874                '''add an event to the awaiting_events var''' 
     
    13351337                        ev = gajim.get_first_event(account, jid, typ) 
    13361338                        # Open the window 
    13371339                        self.roster.open_event(account, jid, ev) 
     1340                elif typ == message_control.TYPE_GMAIL: 
     1341                        if gajim.config.get_per('accounts', account, 'savepass'): 
     1342                                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')) 
     1343                        else: 
     1344                                url = ('http://mail.google.com/') 
     1345                        helpers.launch_browser_mailer('url', url) 
    13381346                if w: 
    13391347                        w.set_active_tab(jid) 
    13401348                        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""" 
     
    17601778                        common.xmpp.NS_PRIVATE) 
    17611779                con.RegisterHandler('iq', self._HttpAuthCB, 'get', 
    17621780                        common.xmpp.NS_HTTP_AUTH) 
    1763                 con.RegisterHandler('iq', self._gMailCB, 'set', 
     1781                con.RegisterHandler('iq', self._gMailNewMailCB, 'set', 
    17641782                        common.xmpp.NS_GMAILNOTIFY) 
     1783                con.RegisterHandler('iq', self._gMailQueryCB, 'result', 
     1784                        common.xmpp.NS_GMAILNOTIFY) 
    17651785                con.RegisterHandler('iq', self._ErrorCB, 'error') 
    17661786                con.RegisterHandler('iq', self._IqCB) 
    17671787                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?