comparison src/core/sat_main.py @ 332:8c9b9ef13ba1

core: minor refactoring
author Goffi <goffi@goffi.org>
date Tue, 24 May 2011 00:48:29 +0200
parents 0a8eb0461f31
children 953536246d9d
comparison
equal deleted inserted replaced
331:0a8eb0461f31 332:8c9b9ef13ba1
40 from logging import debug, info, error 40 from logging import debug, info, error
41 41
42 import sys 42 import sys
43 import os.path 43 import os.path
44 44
45 from sat.core.xmpp import SatXMPPClient, SatMessageProtocol, SatRosterProtocol, SatPresenceProtocol, SatDiscoProtocol, SatFallbackHandler, RegisteringAuthenticator, SatVersionHandler 45 from sat.core import xmpp
46 from sat.tools.memory import Memory 46 from sat.tools.memory import Memory
47 from sat.tools.xml_tools import tupleList2dataForm 47 from sat.tools.xml_tools import tupleList2dataForm
48 from sat.tools.misc import TriggerManager 48 from sat.tools.misc import TriggerManager
49 from glob import glob 49 from glob import glob
50 50
95 95
96 self.__waiting_conf = {} #callback called when a confirmation is received 96 self.__waiting_conf = {} #callback called when a confirmation is received
97 self.__progress_cb_map = {} #callback called when a progress is requested (key = progress id) 97 self.__progress_cb_map = {} #callback called when a progress is requested (key = progress id)
98 self.__general_cb_map = {} #callback called for general reasons (key = name) 98 self.__general_cb_map = {} #callback called for general reasons (key = name)
99 self.__private_data = {} #used for internal callbacks (key = id) 99 self.__private_data = {} #used for internal callbacks (key = id)
100 self.trigger = TriggerManager() #trigger are user to change SàT behaviour 100 self.trigger = TriggerManager() #trigger are used to change SàT behaviour
101 self.profiles = {} 101 self.profiles = {}
102 self.plugins = {} 102 self.plugins = {}
103 self.menus = {} #used to know which new menus are wanted by plugins 103 self.menus = {} #used to know which new menus are wanted by plugins
104 104
105 self.memory=Memory(self) 105 self.memory=Memory(self)
190 return 190 return
191 191
192 if (self.isConnected(profile)): 192 if (self.isConnected(profile)):
193 info(_("already connected !")) 193 info(_("already connected !"))
194 return 194 return
195 current = self.profiles[profile] = SatXMPPClient(self, profile, 195 current = self.profiles[profile] = xmpp.SatXMPPClient(self, profile,
196 jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key = profile), profile), 196 jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key = profile), profile),
197 self.memory.getParamA("Password", "Connection", profile_key = profile), 197 self.memory.getParamA("Password", "Connection", profile_key = profile),
198 self.memory.getParamA("Server", "Connection", profile_key = profile), 5222) 198 self.memory.getParamA("Server", "Connection", profile_key = profile), 5222)
199 199
200 current.messageProt = SatMessageProtocol(self) 200 current.messageProt = xmpp.SatMessageProtocol(self)
201 current.messageProt.setHandlerParent(current) 201 current.messageProt.setHandlerParent(current)
202 202
203 current.roster = SatRosterProtocol(self) 203 current.roster = xmpp.SatRosterProtocol(self)
204 current.roster.setHandlerParent(current) 204 current.roster.setHandlerParent(current)
205 205
206 current.presence = SatPresenceProtocol(self) 206 current.presence = xmpp.SatPresenceProtocol(self)
207 current.presence.setHandlerParent(current) 207 current.presence.setHandlerParent(current)
208 208
209 current.fallBack = SatFallbackHandler(self) 209 current.fallBack = xmpp.SatFallbackHandler(self)
210 current.fallBack.setHandlerParent(current) 210 current.fallBack.setHandlerParent(current)
211 211
212 current.versionHandler = SatVersionHandler(self.get_const('client_name'), 212 current.versionHandler = xmpp.SatVersionHandler(self.get_const('client_name'),
213 self.get_const('client_version')) 213 self.get_const('client_version'))
214 current.versionHandler.setHandlerParent(current) 214 current.versionHandler.setHandlerParent(current)
215 215
216 debug (_("setting plugins parents")) 216 debug (_("setting plugins parents"))
217 217
267 267
268 def registerNewAccount(self, login, password, server, port = 5222, id = None): 268 def registerNewAccount(self, login, password, server, port = 5222, id = None):
269 """Connect to a server and create a new account using in-band registration""" 269 """Connect to a server and create a new account using in-band registration"""
270 270
271 next_id = id or sat_next_id() #the id is used to send server's answer 271 next_id = id or sat_next_id() #the id is used to send server's answer
272 serverRegistrer = xmlstream.XmlStreamFactory(RegisteringAuthenticator(self, server, login, password, next_id)) 272 serverRegistrer = xmlstream.XmlStreamFactory(xmpp.RegisteringAuthenticator(self, server, login, password, next_id))
273 connector = reactor.connectTCP(server, port, serverRegistrer) 273 connector = reactor.connectTCP(server, port, serverRegistrer)
274 serverRegistrer.clientConnectionLost = lambda conn, reason: connector.disconnect() 274 serverRegistrer.clientConnectionLost = lambda conn, reason: connector.disconnect()
275 275
276 return next_id 276 return next_id
277 277