Mercurial > libervia-backend
annotate src/sat.tac @ 288:76247af9917c
core: added plugin dependency not found import error
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 06 Feb 2011 23:32:13 +0100 |
parents | 2720536b5a22 |
children | f7bd973bba5a |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 SAT: a jabber client | |
228 | 6 Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org) |
0 | 7 |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
22 CONST = { |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
23 'client_name' : u'SàT (Salut à toi)', |
252
c09aa319712e
Core: Trigger implementation + version number update
Goffi <goffi@goffi.org>
parents:
245
diff
changeset
|
24 'client_version' : u'0.1.1D', #Please add 'D' at the end for dev versions |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
25 'local_dir' : '~/.sat' |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
26 } |
0 | 27 |
106 | 28 import gettext |
29 gettext.install('sat', "i18n", unicode=True) | |
69 | 30 |
2
c49345fd7737
refactoring: moved sat to sat.tac, now a twisted application so we can use twistd.
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
31 from twisted.application import internet, service |
12
ef8060d365cb
whitespace ping to avoid disconnection (was disconnected after 6 min of inactivity with openfire)
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
32 from twisted.internet import glib2reactor, protocol, task |
0 | 33 glib2reactor.install() |
34 | |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
35 from twisted.words.protocols.jabber import jid, xmlstream |
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
36 from twisted.words.protocols.jabber import error as jab_error |
0 | 37 from twisted.words.xish import domish |
38 | |
39 from twisted.internet import reactor | |
40 import pdb | |
41 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
42 from wokkel import client, disco, xmppim, generic, compat |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
43 |
223 | 44 from sat.bridge.DBus import DBusBridge |
0 | 45 import logging |
46 from logging import debug, info, error | |
47 | |
48 import signal, sys | |
49 import os.path | |
50 | |
223 | 51 from sat.tools.memory import Memory |
52 from sat.tools.xml_tools import tupleList2dataForm | |
252
c09aa319712e
Core: Trigger implementation + version number update
Goffi <goffi@goffi.org>
parents:
245
diff
changeset
|
53 from sat.tools.misc import TriggerManager |
0 | 54 from glob import glob |
55 | |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
56 try: |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
57 from twisted.words.protocols.xmlstream import XMPPHandler |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
58 except ImportError: |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
59 from wokkel.subprotocols import XMPPHandler |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
60 |
0 | 61 |
62 ### logging configuration FIXME: put this elsewhere ### | |
63 logging.basicConfig(level=logging.DEBUG, | |
64 format='%(message)s') | |
65 ### | |
66 | |
67 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
68 sat_id = 0 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
69 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
70 def sat_next_id(): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
71 global sat_id |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
72 sat_id+=1 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
73 return "sat_id_"+str(sat_id) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
74 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
75 class SatXMPPClient(client.XMPPClient): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
76 |
64 | 77 def __init__(self, host_app, profile, user_jid, password, host=None, port=5222): |
50 | 78 client.XMPPClient.__init__(self, user_jid, password, host, port) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
79 self.factory.clientConnectionLost = self.connectionLost |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
80 self.__connected=False |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
81 self.profile = profile |
64 | 82 self.host_app = host_app |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
83 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
84 def _authd(self, xmlstream): |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
85 if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile): |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
86 return |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
87 client.XMPPClient._authd(self, xmlstream) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
88 self.__connected=True |
69 | 89 info (_("********** [%s] CONNECTED **********") % self.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
90 self.streamInitialized() |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
91 self.host_app.bridge.connected(self.profile) #we send the signal to the clients |
277 | 92 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
93 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
94 def streamInitialized(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
95 """Called after _authd""" |
69 | 96 debug (_("XML stream is initialized")) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
97 self.keep_alife = task.LoopingCall(self.xmlstream.send, " ") #Needed to avoid disconnection (specially with openfire) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
98 self.keep_alife.start(180) |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
99 |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
100 self.disco = SatDiscoProtocol(self) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
101 self.disco.setHandlerParent(self) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
102 self.discoHandler = disco.DiscoHandler() |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
103 self.discoHandler.setHandlerParent(self) |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
104 |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
105 if not self.host_app.trigger.point("Disco Handled", self.profile): |
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
106 return |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
107 |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
108 self.roster.requestRoster() |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
109 |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
110 self.presence.available() |
64 | 111 |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
112 self.disco.requestInfo(jid.JID(self.host_app.memory.getParamA("Server", "Connection", profile_key=self.profile))).addCallback(self.host_app.serverDisco, self.profile) #FIXME: use these informations |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
113 |
262
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
114 def initializationFailed(self, reason): |
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
115 print ("initializationFailed: %s" % reason) |
274
c1ad04586edf
Bridge: rename connection_error to connectionError for function name consistency
Goffi <goffi@goffi.org>
parents:
266
diff
changeset
|
116 self.host_app.bridge.connectionError("AUTH_ERROR", self.profile) |
262
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
117 try: |
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
118 client.XMPPClient.initializationFailed(self, reason) |
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
119 except: |
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
120 #we already send an error signal, no need to raise an exception |
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
121 pass |
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
122 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
123 def isConnected(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
124 return self.__connected |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
125 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
126 def connectionLost(self, connector, unused_reason): |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
127 self.__connected=False |
69 | 128 info (_("********** [%s] DISCONNECTED **********") % self.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
129 try: |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
130 self.keep_alife.stop() |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
131 except AttributeError: |
69 | 132 debug (_("No keep_alife")) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
133 self.host_app.bridge.disconnected(self.profile) #we send the signal to the clients |
0 | 134 |
135 | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
136 class SatMessageProtocol(xmppim.MessageProtocol): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
137 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
138 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
139 xmppim.MessageProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
140 self.host = host |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
141 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
142 def onMessage(self, message): |
69 | 143 debug (_(u"got message from: %s"), message["from"]) |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
252
diff
changeset
|
144 if not self.host.trigger.point("MessageReceived",message, profile=self.parent.profile): |
252
c09aa319712e
Core: Trigger implementation + version number update
Goffi <goffi@goffi.org>
parents:
245
diff
changeset
|
145 return |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
146 for e in message.elements(): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
147 if e.name == "body": |
264 | 148 mess_type = message['type'] if message.hasAttribute('type') else 'normal' |
276
a00e87d48213
bridge, bridge constructor: fixed mix stuff
Goffi <goffi@goffi.org>
parents:
274
diff
changeset
|
149 self.host.bridge.newMessage(message["from"], e.children[0], mess_type, message['to'], profile=self.parent.profile) |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
150 self.host.memory.addToHistory(self.parent.jid, jid.JID(message["from"]), self.parent.jid, "chat", e.children[0]) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
151 break |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
152 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
153 class SatRosterProtocol(xmppim.RosterClientProtocol): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
154 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
155 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
156 xmppim.RosterClientProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
157 self.host = host |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
158 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
159 def rosterCb(self, roster): |
50 | 160 for raw_jid, item in roster.iteritems(): |
161 self.onRosterSet(item) | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
162 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
163 def requestRoster(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
164 """ ask the server for Roster list """ |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
165 debug("requestRoster") |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
166 self.getRoster().addCallback(self.rosterCb) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
167 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
168 def removeItem(self, to): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
169 """Remove a contact from roster list""" |
50 | 170 xmppim.RosterClientProtocol.removeItem(self, to) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
171 #TODO: check IQ result |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
172 |
187
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
173 #XXX: disabled (cf http://wokkel.ik.nu/ticket/56)) |
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
174 #def addItem(self, to): |
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
175 #"""Add a contact to roster list""" |
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
176 #xmppim.RosterClientProtocol.addItem(self, to) |
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
177 #TODO: check IQ result""" |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
178 |
50 | 179 def onRosterSet(self, item): |
180 """Called when a new/update roster item is received""" | |
181 #TODO: send a signal to frontends | |
182 item_attr = {'to': str(item.subscriptionTo), | |
183 'from': str(item.subscriptionFrom), | |
184 'ask': str(item.ask) | |
185 } | |
186 if item.name: | |
187 item_attr['name'] = item.name | |
69 | 188 info (_("new contact in roster list: %s"), item.jid.full()) |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
189 self.host.memory.addContact(item.jid, item_attr, item.groups, self.parent.profile) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
190 self.host.bridge.newContact(item.jid.full(), item_attr, item.groups, self.parent.profile) |
50 | 191 |
192 def onRosterRemove(self, entity): | |
193 """Called when a roster removal event is received""" | |
194 #TODO: send a signal to frontends | |
69 | 195 print _("removing %s from roster list") % entity.full() |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
196 self.host.memory.delContact(entity, self.parent.profile) |
50 | 197 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
198 class SatPresenceProtocol(xmppim.PresenceClientProtocol): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
199 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
200 def __init__(self, host): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
201 xmppim.PresenceClientProtocol.__init__(self) |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
202 self.host = host |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
203 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
204 def availableReceived(self, entity, show=None, statuses=None, priority=0): |
72 | 205 debug (_("presence update for [%(entity)s] (available, show=%(show)s statuses=%(statuses)s priority=%(priority)d)") % {'entity':entity, 'show':show, 'statuses':statuses, 'priority':priority}) |
50 | 206 |
207 if statuses.has_key(None): #we only want string keys | |
208 statuses["default"] = statuses[None] | |
209 del statuses[None] | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
210 |
50 | 211 self.host.memory.addPresenceStatus(entity, show or "", |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
212 int(priority), statuses, self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
213 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
214 #now it's time to notify frontends |
50 | 215 self.host.bridge.presenceUpdate(entity.full(), show or "", |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
216 int(priority), statuses, self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
217 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
218 def unavailableReceived(self, entity, statuses=None): |
72 | 219 debug (_("presence update for [%(entity)s] (unavailable, statuses=%(statuses)s)") % {'entity':entity, 'statuses':statuses}) |
50 | 220 if statuses and statuses.has_key(None): #we only want string keys |
221 statuses["default"] = statuses[None] | |
222 del statuses[None] | |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
223 self.host.memory.addPresenceStatus(entity, "unavailable", 0, statuses, self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
224 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
225 #now it's time to notify frontends |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
226 self.host.bridge.presenceUpdate(entity.full(), "unavailable", 0, statuses, self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
227 |
50 | 228 |
229 def available(self, entity=None, show=None, statuses=None, priority=0): | |
230 if statuses and statuses.has_key('default'): | |
231 statuses[None] = statuses['default'] | |
232 del statuses['default'] | |
233 xmppim.PresenceClientProtocol.available(self, entity, show, statuses, priority) | |
234 | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
235 def subscribedReceived(self, entity): |
69 | 236 debug (_("subscription approved for [%s]") % entity.userhost()) |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
237 self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
238 self.host.bridge.subscribe('subscribed', entity.userhost(), self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
239 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
240 def unsubscribedReceived(self, entity): |
69 | 241 debug (_("unsubscription confirmed for [%s]") % entity.userhost()) |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
242 self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
243 self.host.bridge.subscribe('unsubscribed', entity.userhost(), self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
244 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
245 def subscribeReceived(self, entity): |
69 | 246 debug (_("subscription request for [%s]") % entity.userhost()) |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
247 self.host.memory.addWaitingSub('subscribe', entity.userhost(), self.parent.profile) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
248 self.host.bridge.subscribe('subscribe', entity.userhost(), self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
249 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
250 def unsubscribeReceived(self, entity): |
69 | 251 debug (_("unsubscription asked for [%s]") % entity.userhost()) |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
252 self.host.memory.addWaitingSub('unsubscribe', entity.userhost(), self.parent.profile) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
253 self.host.bridge.subscribe('unsubscribe', entity.userhost(), self.parent.profile) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
254 |
14 | 255 class SatDiscoProtocol(disco.DiscoClientProtocol): |
256 def __init__(self, host): | |
257 disco.DiscoClientProtocol.__init__(self) | |
258 | |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
259 class SatFallbackHandler(generic.FallbackHandler): |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
260 def __init__(self, host): |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
261 generic.FallbackHandler.__init__(self) |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
262 |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
263 def iqFallback(self, iq): |
155
61f1e509e684
SàT: fixed exception when using unmanaged IQ
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
264 debug (u"iqFallback: xml = [%s], handled=%s" % (iq.toXml(), "True" if iq.handled else "False")) |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
265 generic.FallbackHandler.iqFallback(self, iq) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
266 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
267 class RegisteringAuthenticator(xmlstream.ConnectAuthenticator): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
268 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
269 def __init__(self, host, jabber_host, user_login, user_pass, answer_id): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
270 xmlstream.ConnectAuthenticator.__init__(self, jabber_host) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
271 self.host = host |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
272 self.jabber_host = jabber_host |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
273 self.user_login = user_login |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
274 self.user_pass = user_pass |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
275 self.answer_id = answer_id |
69 | 276 print _("Registration asked for"),user_login, user_pass, jabber_host |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
277 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
278 def connectionMade(self): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
279 print "connectionMade" |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
280 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
281 self.xmlstream.namespace = "jabber:client" |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
282 self.xmlstream.sendHeader() |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
283 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
284 iq = compat.IQ(self.xmlstream, 'set') |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
285 iq["to"] = self.jabber_host |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
286 query = iq.addElement(('jabber:iq:register', 'query')) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
287 _user = query.addElement('username') |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
288 _user.addContent(self.user_login) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
289 _pass = query.addElement('password') |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
290 _pass.addContent(self.user_pass) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
291 reg = iq.send(self.jabber_host).addCallbacks(self.registrationAnswer, self.registrationFailure) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
292 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
293 def registrationAnswer(self, answer): |
69 | 294 debug (_("registration answer: %s") % answer.toXml()) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
295 answer_type = "SUCCESS" |
69 | 296 answer_data={"message":_("Registration successfull")} |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
297 self.host.bridge.actionResult(answer_type, self.answer_id, answer_data) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
298 self.xmlstream.sendFooter() |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
299 |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
300 def registrationFailure(self, failure): |
69 | 301 info (_("Registration failure: %s") % str(failure.value)) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
302 answer_type = "ERROR" |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
303 answer_data = {} |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
304 if failure.value.condition == 'conflict': |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
305 answer_data['reason'] = 'conflict' |
69 | 306 answer_data={"message":_("Username already exists, please choose an other one")} |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
307 else: |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
308 answer_data['reason'] = 'unknown' |
69 | 309 answer_data={"message":_("Registration failed (%s)") % str(failure.value.condition)} |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
310 self.host.bridge.actionResult(answer_type, self.answer_id, answer_data) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
311 self.xmlstream.sendFooter() |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
312 |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
313 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
314 class SAT(service.Service): |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
315 |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
316 def get_next_id(self): |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
317 return sat_next_id() |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
318 |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
319 def get_const(self, name): |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
320 """Return a constant""" |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
321 if not CONST.has_key(name): |
69 | 322 error(_('Trying to access an undefined constant')) |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
323 raise Exception |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
324 return CONST[name] |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
325 |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
326 def set_const(self, name, value): |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
327 """Save a constant""" |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
328 if CONST.has_key(name): |
69 | 329 error(_('Trying to redefine a constant')) |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
330 raise Exception |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
331 CONST[name] = value |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
332 |
0 | 333 def __init__(self): |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
334 #TODO: standardize callback system |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
335 |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
336 local_dir = os.path.expanduser(self.get_const('local_dir')) |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
337 if not os.path.exists(local_dir): |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
338 os.makedirs(local_dir) |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
339 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
340 self.__waiting_conf = {} #callback called when a confirmation is received |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
341 self.__progress_cb_map = {} #callback called when a progress is requested (key = progress id) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
342 self.__general_cb_map = {} #callback called for general reasons (key = name) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
343 self.__private_data = {} #used for internal callbacks (key = id) |
252
c09aa319712e
Core: Trigger implementation + version number update
Goffi <goffi@goffi.org>
parents:
245
diff
changeset
|
344 self.trigger = TriggerManager() #trigger are user to change SàT behaviour |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
345 self.profiles = {} |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
346 self.plugins = {} |
101 | 347 self.menus = {} #used to know which new menus are wanted by plugins |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
348 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
349 self.memory=Memory(self) |
0 | 350 |
351 self.bridge=DBusBridge() | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
107
diff
changeset
|
352 self.bridge.register("getVersion", lambda: self.get_const('client_version')) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
353 self.bridge.register("getProfileName", self.memory.getProfileName) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
58
diff
changeset
|
354 self.bridge.register("getProfilesList", self.memory.getProfilesList) |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
58
diff
changeset
|
355 self.bridge.register("createProfile", self.memory.createProfile) |
68 | 356 self.bridge.register("deleteProfile", self.memory.deleteProfile) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
357 self.bridge.register("registerNewAccount", self.registerNewAccount) |
0 | 358 self.bridge.register("connect", self.connect) |
1 | 359 self.bridge.register("disconnect", self.disconnect) |
0 | 360 self.bridge.register("getContacts", self.memory.getContacts) |
361 self.bridge.register("getPresenceStatus", self.memory.getPresenceStatus) | |
50 | 362 self.bridge.register("getWaitingSub", self.memory.getWaitingSub) |
0 | 363 self.bridge.register("sendMessage", self.sendMessage) |
364 self.bridge.register("setParam", self.setParam) | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
365 self.bridge.register("getParamA", self.memory.getParamA) |
105 | 366 self.bridge.register("getParamsUI", self.memory.getParamsUI) |
0 | 367 self.bridge.register("getParams", self.memory.getParams) |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
368 self.bridge.register("getParamsForCategory", self.memory.getParamsForCategory) |
0 | 369 self.bridge.register("getParamsCategories", self.memory.getParamsCategories) |
370 self.bridge.register("getHistory", self.memory.getHistory) | |
371 self.bridge.register("setPresence", self.setPresence) | |
50 | 372 self.bridge.register("subscription", self.subscription) |
0 | 373 self.bridge.register("addContact", self.addContact) |
374 self.bridge.register("delContact", self.delContact) | |
375 self.bridge.register("isConnected", self.isConnected) | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
376 self.bridge.register("launchAction", self.launchAction) |
0 | 377 self.bridge.register("confirmationAnswer", self.confirmationAnswer) |
378 self.bridge.register("getProgress", self.getProgress) | |
101 | 379 self.bridge.register("getMenus", self.getMenus) |
380 self.bridge.register("getMenuHelp", self.getMenuHelp) | |
381 self.bridge.register("callMenu", self.callMenu) | |
0 | 382 |
64 | 383 self._import_plugins() |
0 | 384 |
385 | |
386 def _import_plugins(self): | |
387 """Import all plugins found in plugins directory""" | |
226
d8bb72f00eec
distutils install: fixed plugin import and log file path
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
388 import sat.plugins |
d8bb72f00eec
distutils install: fixed plugin import and log file path
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
389 plugins_path = os.path.dirname(sat.plugins.__file__) |
d8bb72f00eec
distutils install: fixed plugin import and log file path
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
390 plug_lst = [os.path.splitext(plugin)[0] for plugin in map(os.path.basename,glob (os.path.join(plugins_path,"plugin*.py")))] |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
391 __plugins_to_import = {} #plugins will still have to import |
0 | 392 for plug in plug_lst: |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
393 plugin_path = 'sat.plugins.'+plug |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
394 __import__(plugin_path) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
395 mod = sys.modules[plugin_path] |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
396 plugin_info = mod.PLUGIN_INFO |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
397 __plugins_to_import[plugin_info['import_name']] = (plugin_path, mod, plugin_info) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
398 while True: |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
399 self._import_plugins_from_dict(__plugins_to_import) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
400 if not __plugins_to_import: |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
401 break |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
402 |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
403 def _import_plugins_from_dict(self, plugins_to_import, import_name=None): |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
404 """Recursively import and their dependencies in the right order |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
405 @param plugins_to_import: dict where key=import_name and values= (plugin_path, module, plugin_info)""" |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
406 if self.plugins.has_key(import_name): |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
407 debug('Plugin [%s] already imported, passing' % import_name) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
408 return |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
409 if not import_name: |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
410 import_name,(plugin_path, mod, plugin_info) = plugins_to_import.popitem() |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
411 else: |
288
76247af9917c
core: added plugin dependency not found import error
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
412 if not import_name in plugins_to_import: |
76247af9917c
core: added plugin dependency not found import error
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
413 raise ImportError(_('Dependency plugin not found: [%s]') % import_name) |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
414 plugin_path, mod, plugin_info = plugins_to_import.pop(import_name) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
415 dependencies = plugin_info.setdefault("dependencies",[]) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
416 for dependency in dependencies: |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
417 if not self.plugins.has_key(dependency): |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
418 debug('Recursively import dependency of [%s]: [%s]' % (import_name, dependency)) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
419 self._import_plugins_from_dict(plugins_to_import, dependency) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
420 info (_("importing plugin: %s"), plugin_info['name']) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
421 self.plugins[import_name] = getattr(mod, plugin_info['main'])(self) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
422 if plugin_info.has_key('handler') and plugin_info['handler'] == 'yes': |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
423 self.plugins[import_name].is_handler = True |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
424 else: |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
425 self.plugins[import_name].is_handler = False |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
426 #TODO: test xmppclient presence and register handler parent |
0 | 427 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
428 def connect(self, profile_key = '@DEFAULT@'): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
429 """Connect to jabber server""" |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
430 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
431 profile = self.memory.getProfileName(profile_key) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
432 if not profile_key: |
69 | 433 error (_('Trying to connect a non-exsitant profile')) |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
434 return |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
435 |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
79
diff
changeset
|
436 if (self.isConnected(profile)): |
69 | 437 info(_("already connected !")) |
6
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
438 return |
64 | 439 current = self.profiles[profile] = SatXMPPClient(self, profile, |
440 jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key = profile_key), profile), | |
441 self.memory.getParamA("Password", "Connection", profile_key = profile_key), | |
442 self.memory.getParamA("Server", "Connection", profile_key = profile_key), 5222) | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
443 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
444 current.messageProt = SatMessageProtocol(self) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
445 current.messageProt.setHandlerParent(current) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
446 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
447 current.roster = SatRosterProtocol(self) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
448 current.roster.setHandlerParent(current) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
449 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
450 current.presence = SatPresenceProtocol(self) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
451 current.presence.setHandlerParent(current) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
452 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
453 current.fallBack = SatFallbackHandler(self) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
454 current.fallBack.setHandlerParent(current) |
14 | 455 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
456 current.versionHandler = generic.VersionHandler(self.get_const('client_name'), |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
457 self.get_const('client_version')) |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
458 current.versionHandler.setHandlerParent(current) |
14 | 459 |
69 | 460 debug (_("setting plugins parents")) |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
461 |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
462 for plugin in self.plugins.iteritems(): |
64 | 463 if plugin[1].is_handler: |
72 | 464 plugin[1].getHandler(profile).setHandlerParent(current) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
465 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
466 current.startService() |
2
c49345fd7737
refactoring: moved sat to sat.tac, now a twisted application so we can use twistd.
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
467 |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
468 def disconnect(self, profile_key='@DEFAULT@'): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
469 """disconnect from jabber server""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
470 if (not self.isConnected(profile_key)): |
69 | 471 info(_("not connected !")) |
6
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
472 return |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
473 profile = self.memory.getProfileName(profile_key) |
69 | 474 info(_("Disconnecting...")) |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
475 self.profiles[profile].stopService() |
6
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
476 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
477 def startService(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
478 info("Salut à toi ô mon frère !") |
213
5c420b1f1df4
removed connect on statService, this was causing issue on first launch
Goffi <goffi@goffi.org>
parents:
210
diff
changeset
|
479 #TODO: manage autoconnect |
5c420b1f1df4
removed connect on statService, this was causing issue on first launch
Goffi <goffi@goffi.org>
parents:
210
diff
changeset
|
480 #self.connect() |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
481 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
482 def stopService(self): |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
483 self.memory.save() |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
484 info("Salut aussi à Rantanplan") |
0 | 485 |
486 def run(self): | |
69 | 487 debug(_("running app")) |
0 | 488 reactor.run() |
489 | |
490 def stop(self): | |
69 | 491 debug(_("stopping app")) |
0 | 492 reactor.stop() |
493 | |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
494 ## Misc methods ## |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
495 |
64 | 496 def getJidNStream(self, profile_key): |
497 """Convenient method to get jid and stream from profile key | |
498 @return: tuple (jid, xmlstream) from profile, can be None""" | |
499 profile = self.memory.getProfileName(profile_key) | |
500 if not profile or not self.profiles[profile].isConnected(): | |
501 return (None, None) | |
502 return (self.profiles[profile].jid, self.profiles[profile].xmlstream) | |
503 | |
504 def getClient(self, profile_key): | |
505 """Convenient method to get client from profile key | |
506 @return: client or None if it doesn't exist""" | |
507 profile = self.memory.getProfileName(profile_key) | |
508 if not profile: | |
509 return None | |
510 return self.profiles[profile] | |
511 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
512 def registerNewAccount(self, login, password, server, port = 5222, id = None): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
513 """Connect to a server and create a new account using in-band registration""" |
0 | 514 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
515 next_id = id or sat_next_id() #the id is used to send server's answer |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
516 serverRegistrer = xmlstream.XmlStreamFactory(RegisteringAuthenticator(self, server, login, password, next_id)) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
517 connector = reactor.connectTCP(server, port, serverRegistrer) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
518 serverRegistrer.clientConnectionLost = lambda conn, reason: connector.disconnect() |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
519 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
520 return next_id |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
521 |
107 | 522 def registerNewAccountCB(self, id, data, profile): |
135
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
523 user = jid.parse(self.memory.getParamA("JabberID", "Connection", profile_key=profile))[0] |
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
524 password = self.memory.getParamA("Password", "Connection", profile_key=profile) |
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
525 server = self.memory.getParamA("Server", "Connection", profile_key=profile) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
526 |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
527 if not user or not password or not server: |
69 | 528 info (_('No user or server given')) |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
529 #TODO: a proper error message must be sent to frontend |
69 | 530 self.actionResult(id, "ERROR", {'message':_("No user, password or server given, can't register new account.")}) |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
531 return |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
532 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
533 confirm_id = sat_next_id() |
135
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
534 self.__private_data[confirm_id]=(id,profile) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
535 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
536 self.askConfirmation(confirm_id, "YES/NO", |
135
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
537 {"message":_("Are you sure to register new account [%(user)s] to server %(server)s ?") % {'user':user, 'server':server, 'profile':profile}}, |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
538 self.regisConfirmCB) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
539 print ("===============+++++++++++ REGISTER NEW ACCOUNT++++++++++++++============") |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
540 print "id=",id |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
541 print "data=",data |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
542 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
543 def regisConfirmCB(self, id, accepted, data): |
69 | 544 print _("register Confirmation CB ! (%s)") % str(accepted) |
135
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
545 action_id,profile = self.__private_data[id] |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
546 del self.__private_data[id] |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
547 if accepted: |
135
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
548 user = jid.parse(self.memory.getParamA("JabberID", "Connection", profile_key=profile))[0] |
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
549 password = self.memory.getParamA("Password", "Connection", profile_key=profile) |
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
550 server = self.memory.getParamA("Server", "Connection", profile_key=profile) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
551 self.registerNewAccount(user, password, server, id=action_id) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
552 else: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
553 self.actionResult(action_id, "SUPPRESS", {}) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
554 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
555 def submitForm(self, action, target, fields, profile_key='@DEFAULT@'): |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
556 """submit a form |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
557 @param target: target jid where we are submitting |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
558 @param fields: list of tuples (name, value) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
559 @return: tuple: (id, deferred) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
560 """ |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
561 |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
562 profile = self.memory.getProfileName(profile_key) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
563 assert(profile) |
36 | 564 to_jid = jid.JID(target) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
565 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
566 iq = compat.IQ(self.profiles[profile].xmlstream, 'set') |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
567 iq["to"] = target |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
568 iq["from"] = self.profiles[profile].jid.full() |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
569 query = iq.addElement(('jabber:iq:register', 'query')) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
570 if action=='SUBMIT': |
102 | 571 form = tupleList2dataForm(fields) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
572 query.addChild(form.toElement()) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
573 elif action=='CANCEL': |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
574 query.addElement('remove') |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
575 else: |
69 | 576 error (_("FIXME FIXME FIXME: Unmanaged action (%s) in submitForm") % action) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
577 raise NotImplementedError |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
578 |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
579 deferred = iq.send(target) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
580 return (iq['id'], deferred) |
36 | 581 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
582 ## Client management ## |
0 | 583 |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
584 def setParam(self, name, value, category, profile_key='@DEFAULT@'): |
0 | 585 """set wanted paramater and notice observers""" |
69 | 586 info (_("setting param: %(name)s=%(value)s in category %(category)s") % {'name':name, 'value':value, 'category':category}) |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
587 self.memory.setParam(name, value, category, profile_key) |
0 | 588 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
589 def isConnected(self, profile_key='@DEFAULT@'): |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
590 """Return connection status of profile |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
591 @param profile_key: key_word or profile name to determine profile name |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
592 @return True if connected |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
593 """ |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
594 profile = self.memory.getProfileName(profile_key) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
595 if not profile: |
69 | 596 error (_('asking connection status for a non-existant profile')) |
213
5c420b1f1df4
removed connect on statService, this was causing issue on first launch
Goffi <goffi@goffi.org>
parents:
210
diff
changeset
|
597 return |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
598 if not self.profiles.has_key(profile): |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
599 return False |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
600 return self.profiles[profile].isConnected() |
0 | 601 |
107 | 602 def launchAction(self, type, data, profile_key='@DEFAULT@'): |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
603 """Launch a specific action asked by client |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
604 @param type: action type (button) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
605 @param data: needed data to launch the action |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
606 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
607 @return: action id for result, or empty string in case or error |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
608 """ |
107 | 609 profile = self.memory.getProfileName(profile_key) |
610 if not profile: | |
611 error (_('trying to launch action with a non-existant profile')) | |
612 raise Exception #TODO: raise a proper exception | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
613 if type=="button": |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
614 try: |
106 | 615 cb_name = data['callback_id'] |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
616 except KeyError: |
69 | 617 error (_("Incomplete data")) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
618 return "" |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
619 id = sat_next_id() |
107 | 620 self.callGeneralCB(cb_name, id, data, profile = profile) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
621 return id |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
622 else: |
69 | 623 error (_("Unknown action type")) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
624 return "" |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
625 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
626 |
0 | 627 ## jabber methods ## |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
628 |
260
c8406fe5e81e
Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
257
diff
changeset
|
629 def sendMessage(self, to, msg, subject=None, type='chat', profile_key='@DEFAULT@'): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
630 #FIXME: check validity of recipient |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
631 profile = self.memory.getProfileName(profile_key) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
632 assert(profile) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
633 current_jid = self.profiles[profile].jid |
69 | 634 debug(_("Sending jabber message to %s..."), to) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
635 message = domish.Element(('jabber:client','message')) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
636 message["to"] = jid.JID(to).full() |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
637 message["from"] = current_jid.full() |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
638 message["type"] = type |
260
c8406fe5e81e
Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
257
diff
changeset
|
639 if subject: |
c8406fe5e81e
Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
257
diff
changeset
|
640 message.addElement("subject", "jabber:client", subject) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
641 message.addElement("body", "jabber:client", msg) |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
642 self.profiles[profile].xmlstream.send(message) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
643 self.memory.addToHistory(current_jid, current_jid, jid.JID(to), message["type"], unicode(msg)) |
79 | 644 if type!="groupchat": |
276
a00e87d48213
bridge, bridge constructor: fixed mix stuff
Goffi <goffi@goffi.org>
parents:
274
diff
changeset
|
645 self.bridge.newMessage(message['from'], unicode(msg), mess_type=type, to_jid=message['to'], profile=profile) #We send back the message, so all clients are aware of it |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
646 |
0 | 647 |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
648 def setPresence(self, to="", show="", priority = 0, statuses={}, profile_key='@DEFAULT@'): |
0 | 649 """Send our presence information""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
650 profile = self.memory.getProfileName(profile_key) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
651 assert(profile) |
50 | 652 to_jid = jid.JID(to) if to else None |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
653 self.profiles[profile].presence.available(to_jid, show, statuses, priority) |
50 | 654 |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
79
diff
changeset
|
655 def subscription(self, subs_type, raw_jid, profile_key='@DEFAULT@'): |
187
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
656 """Called to manage subscription |
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
657 @param subs_type: subsciption type (cf RFC 3921) |
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
658 @param raw_jid: unicode entity's jid |
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
659 @param profile_key: profile""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
660 profile = self.memory.getProfileName(profile_key) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
661 assert(profile) |
50 | 662 to_jid = jid.JID(raw_jid) |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
79
diff
changeset
|
663 debug (_('subsciption request [%(subs_type)s] for %(jid)s') % {'subs_type':subs_type, 'jid':to_jid.full()}) |
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
79
diff
changeset
|
664 if subs_type=="subscribe": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
665 self.profiles[profile].presence.subscribe(to_jid) |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
79
diff
changeset
|
666 elif subs_type=="subscribed": |
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
79
diff
changeset
|
667 self.profiles[profile].presence.subscribed(to_jid) |
50 | 668 contact = self.memory.getContact(to_jid) |
669 if not contact or not bool(contact['to']): #we automatically subscribe to 'to' presence | |
69 | 670 debug(_('sending automatic "to" subscription request')) |
50 | 671 self.subscription('subscribe', to_jid.userhost()) |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
79
diff
changeset
|
672 elif subs_type=="unsubscribe": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
673 self.profiles[profile].presence.unsubscribe(to_jid) |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
79
diff
changeset
|
674 elif subs_type=="unsubscribed": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
675 self.profiles[profile].presence.unsubscribed(to_jid) |
0 | 676 |
677 | |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
678 def addContact(self, to, profile_key='@DEFAULT@'): |
0 | 679 """Add a contact in roster list""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
680 profile = self.memory.getProfileName(profile_key) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
681 assert(profile) |
0 | 682 to_jid=jid.JID(to) |
187
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
683 #self.profiles[profile].roster.addItem(to_jid) XXX: disabled (cf http://wokkel.ik.nu/ticket/56)) |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
684 self.profiles[profile].presence.subscribe(to_jid) |
0 | 685 |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
686 def delContact(self, to, profile_key='@DEFAULT@'): |
0 | 687 """Remove contact from roster list""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
688 profile = self.memory.getProfileName(profile_key) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
689 assert(profile) |
0 | 690 to_jid=jid.JID(to) |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
691 self.profiles[profile].roster.removeItem(to_jid) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
692 self.profiles[profile].presence.unsubscribe(to_jid) |
135
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
693 self.bridge.contactDeleted(to, profile) |
0 | 694 |
695 | |
696 ## callbacks ## | |
697 | |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
698 def serverDisco(self, disco, profile): |
0 | 699 """xep-0030 Discovery Protocol.""" |
14 | 700 for feature in disco.features: |
69 | 701 debug (_("Feature found: %s"),feature) |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
702 self.memory.addServerFeature(feature, profile) |
14 | 703 for cat, type in disco.identities: |
69 | 704 debug (_("Identity found: [%(category)s/%(type)s] %(identity)s") % {'category':cat, 'type':type, 'identity':disco.identities[(cat,type)]}) |
0 | 705 |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
706 |
0 | 707 ## Generic HMI ## |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
708 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
709 def actionResult(self, id, type, data): |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
710 """Send the result of an action |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
711 @param id: same id used with action |
103 | 712 @param type: result type ("PARAM", "SUCCESS", "ERROR", "XMLUI") |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
713 @param data: dictionary |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
714 """ |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
715 self.bridge.actionResult(type, id, data) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
716 |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
717 def actionResultExt(self, id, type, data): |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
718 """Send the result of an action, extended version |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
719 @param id: same id used with action |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
720 @param type: result type /!\ only "DICT_DICT" for this method |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
721 @param data: dictionary of dictionaries |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
722 """ |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
723 if type != "DICT_DICT": |
69 | 724 error(_("type for actionResultExt must be DICT_DICT, fixing it")) |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
725 type = "DICT_DICT" |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
726 self.bridge.actionResultExt(type, id, data) |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
727 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
728 |
0 | 729 |
730 def askConfirmation(self, id, type, data, cb): | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
731 """Add a confirmation callback |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
732 @param id: id used to get answer |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
733 @param type: confirmation type ("YES/NO", "FILE_TRANSFERT") |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
734 @param data: data (depend of confirmation type) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
735 @param cb: callback called with the answer |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
736 """ |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
737 if self.__waiting_conf.has_key(id): |
69 | 738 error (_("Attempt to register two callbacks for the same confirmation")) |
0 | 739 else: |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
740 self.__waiting_conf[id] = cb |
0 | 741 self.bridge.askConfirmation(type, id, data) |
742 | |
743 | |
744 def confirmationAnswer(self, id, accepted, data): | |
745 """Called by frontends to answer confirmation requests""" | |
101 | 746 debug (_("Received confirmation answer for id [%(id)s]: %(success)s") % {'id': id, 'success':_("accepted") if accepted else _("refused")}) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
747 if not self.__waiting_conf.has_key(id): |
69 | 748 error (_("Received an unknown confirmation")) |
0 | 749 else: |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
750 cb = self.__waiting_conf[id] |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
751 del self.__waiting_conf[id] |
0 | 752 cb(id, accepted, data) |
753 | |
754 def registerProgressCB(self, id, CB): | |
755 """Register a callback called when progress is requested for id""" | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
756 self.__progress_cb_map[id] = CB |
0 | 757 |
758 def removeProgressCB(self, id): | |
759 """Remove a progress callback""" | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
760 if not self.__progress_cb_map.has_key(id): |
69 | 761 error (_("Trying to remove an unknow progress callback")) |
0 | 762 else: |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
763 del self.__progress_cb_map[id] |
0 | 764 |
765 def getProgress(self, id): | |
766 """Return a dict with progress information | |
767 data['position'] : current possition | |
768 data['size'] : end_position | |
769 """ | |
770 data = {} | |
771 try: | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
772 self.__progress_cb_map[id](data) |
0 | 773 except KeyError: |
774 pass | |
775 #debug("Requested progress for unknown id") | |
776 return data | |
777 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
778 def registerGeneralCB(self, name, CB): |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
779 """Register a callback called for general reason""" |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
780 self.__general_cb_map[name] = CB |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
781 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
782 def removeGeneralCB(self, name): |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
783 """Remove a general callback""" |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
784 if not self.__general_cb_map.has_key(name): |
69 | 785 error (_("Trying to remove an unknow general callback")) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
786 else: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
787 del self.__general_cb_map[name] |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
788 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
789 def callGeneralCB(self, name, *args, **kwargs): |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
790 """Call general function back""" |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
791 try: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
792 return self.__general_cb_map[name](*args, **kwargs) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
793 except KeyError: |
107 | 794 error(_("Trying to call unknown function (%s)") % name) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
795 return None |
0 | 796 |
101 | 797 #Menus management |
798 | |
799 def importMenu(self, category, name, callback, help_string = "", type = "NORMAL"): | |
800 """register a new menu for frontends | |
801 @param category: category of the menu | |
802 @param name: menu item entry | |
803 @param callback: method to be called when menuitem is selected""" | |
804 if self.menus.has_key((category,name)): | |
805 error ("Want to register a menu which already existe") | |
806 return | |
807 self.menus[(category,name,type)] = {'callback':callback, 'help_string':help_string, 'type':type} | |
808 | |
809 def getMenus(self): | |
810 """Return all menus registered""" | |
811 return self.menus.keys() | |
812 | |
813 def getMenuHelp(self, category, name, type="NORMAL"): | |
814 """return the help string of the menu""" | |
815 try: | |
816 return self.menus[(category,name,type)]['help_string'] | |
817 except KeyError: | |
818 error (_("Trying to access an unknown menu")) | |
819 return "" | |
820 | |
821 def callMenu(self, category, name, type="NORMAL", profile_key='@DEFAULT@'): | |
266
c4b84a2d2ad1
bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents:
264
diff
changeset
|
822 """return the id of the action""" |
101 | 823 profile = self.memory.getProfileName(profile_key) |
824 if not profile_key: | |
825 error (_('Non-exsitant profile')) | |
826 return "" | |
102 | 827 if self.menus.has_key((category,name,type)): |
101 | 828 id = self.get_next_id() |
829 self.menus[(category,name,type)]['callback'](id, profile) | |
830 return id | |
102 | 831 else: |
832 error (_("Trying to access an unknown menu (%(category)s/%(name)s/%(type)s)")%{'category':category, 'name':name,'type':type}) | |
101 | 833 return "" |
834 | |
835 | |
836 | |
2
c49345fd7737
refactoring: moved sat to sat.tac, now a twisted application so we can use twistd.
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
837 application = service.Application('SàT') |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
838 service = SAT() |
2
c49345fd7737
refactoring: moved sat to sat.tac, now a twisted application so we can use twistd.
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
839 service.setServiceParent(application) |