2013-01-21 07:59:28 +00:00
|
|
|
"""
|
|
|
|
SleekXMPP: The Sleek XMPP Library
|
|
|
|
Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout
|
|
|
|
This file is part of SleekXMPP.
|
|
|
|
|
|
|
|
See the file LICENSE for copying permission.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from sleekxmpp.stanza import Iq
|
|
|
|
from sleekxmpp.xmlstream.handler import Callback
|
2013-01-21 09:38:42 +00:00
|
|
|
from sleekxmpp.xmlstream.matcher import StanzaPath
|
2013-01-21 07:59:28 +00:00
|
|
|
from sleekxmpp.xmlstream import register_stanza_plugin
|
|
|
|
from sleekxmpp.plugins import BasePlugin
|
|
|
|
from sleekxmpp.plugins.google_settings import stanza
|
|
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class GoogleSettings(BasePlugin):
|
|
|
|
|
|
|
|
"""
|
|
|
|
Google: Gmail Notifications
|
|
|
|
|
|
|
|
Also see <https://developers.google.com/talk/jep_extensions/usersettings>.
|
|
|
|
"""
|
|
|
|
|
|
|
|
name = 'google_settings'
|
|
|
|
description = 'Google: User Settings'
|
|
|
|
dependencies = set()
|
|
|
|
stanza = stanza
|
|
|
|
|
|
|
|
def plugin_init(self):
|
|
|
|
register_stanza_plugin(Iq, stanza.UserSettings)
|
|
|
|
|
|
|
|
self.xmpp.register_handler(
|
|
|
|
Callback('Google Settings',
|
2013-01-21 09:38:42 +00:00
|
|
|
StanzaPath('iq@type=set/google_settings'),
|
2013-01-21 07:59:28 +00:00
|
|
|
self._handle_settings_change))
|
|
|
|
|
|
|
|
def plugin_end(self):
|
|
|
|
self.xmpp.remove_handler('Google Settings')
|
|
|
|
|
|
|
|
def get(self, block=True, timeout=None, callback=None):
|
|
|
|
iq = self.xmpp.Iq()
|
|
|
|
iq['type'] = 'get'
|
|
|
|
iq.enable('google_settings')
|
|
|
|
return iq.send(block=block, timeout=timeout, callback=callback)
|
|
|
|
|
2013-01-21 09:38:42 +00:00
|
|
|
def update(self, settings, block=True, timeout=None, callback=None):
|
2013-01-21 07:59:28 +00:00
|
|
|
iq = self.xmpp.Iq()
|
|
|
|
iq['type'] = 'set'
|
|
|
|
iq.enable('google_settings')
|
|
|
|
|
|
|
|
for setting, value in settings.items():
|
|
|
|
iq['google_settings'][setting] = value
|
|
|
|
|
|
|
|
return iq.send(block=block, timeout=timeout, callback=callback)
|
|
|
|
|
|
|
|
def _handle_settings_change(self, iq):
|
2013-01-21 09:38:42 +00:00
|
|
|
reply = self.xmpp.Iq()
|
|
|
|
reply['type'] = 'result'
|
|
|
|
reply['id'] = iq['id']
|
|
|
|
reply['to'] = iq['from']
|
|
|
|
reply.send()
|
2013-01-21 07:59:28 +00:00
|
|
|
self.xmpp.event('google_settings_change', iq)
|