Mercurial > libervia-backend
annotate src/core/sat_main.py @ 504:65ecbb473cbb
core, quick frontend, plugin xep-0054, bridge: use of memory's entities data for vcard:
- bridge: new bridge method getEntityData and signal entityDataUpdated
- core: entityDataUpdated signal sent on new string data
- quick frontend: fixed avatars/vcard infos, fixed _replace in quick_contact_list
- plugin xep-0054: dropped updatedValue signal, use entities data instead
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 26 Sep 2012 01:23:56 +0200 |
parents | e9634d2e7b38 |
children | 2e43c74815ad |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 SAT: a jabber client | |
459 | 6 Copyright (C) 2009, 2010, 2011, 2012 Jérôme Poisson (goffi@goffi.org) |
0 | 7 |
8 This program is free software: you can redistribute it and/or modify | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
0 | 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 | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
16 GNU Affero General Public License for more details. |
0 | 17 |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
0 | 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)', |
357
d98b7391d76c
Changed version number to dev version
Goffi <goffi@goffi.org>
parents:
353
diff
changeset
|
24 'client_version' : u'0.2.0D', #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 } |
0 | 26 |
331
0a8eb0461f31
core: main SAT class now moved in its own module core.sat_main
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
27 from twisted.application import service |
0a8eb0461f31
core: main SAT class now moved in its own module core.sat_main
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
28 from twisted.internet import defer |
489 | 29 from twisted.internet.defer import inlineCallbacks, returnValue |
0 | 30 |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
31 from twisted.words.protocols.jabber import jid, xmlstream |
0 | 32 from twisted.words.xish import domish |
33 | |
34 from twisted.internet import reactor | |
35 | |
331
0a8eb0461f31
core: main SAT class now moved in its own module core.sat_main
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
36 from wokkel import compat |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
37 from wokkel.xmppim import RosterItem |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
38 |
223 | 39 from sat.bridge.DBus import DBusBridge |
0 | 40 import logging |
460
fb1abc0f8c6a
backend: added warning message when jabberfr workaround is used + fixed missing warning method
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
41 from logging import debug, info, warning, error |
0 | 42 |
331
0a8eb0461f31
core: main SAT class now moved in its own module core.sat_main
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
43 import sys |
0 | 44 import os.path |
45 | |
332 | 46 from sat.core import xmpp |
489 | 47 from sat.core.exceptions import ProfileUnknownError, UnknownEntityError |
434
d7e5df876a04
core: path update for Memory import
Goffi <goffi@goffi.org>
parents:
427
diff
changeset
|
48 from sat.memory.memory import Memory |
223 | 49 from sat.tools.xml_tools import tupleList2dataForm |
252
c09aa319712e
Core: Trigger implementation + version number update
Goffi <goffi@goffi.org>
parents:
245
diff
changeset
|
50 from sat.tools.misc import TriggerManager |
0 | 51 from glob import glob |
52 | |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
53 try: |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
54 from twisted.words.protocols.xmlstream import XMPPHandler |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
55 except ImportError: |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
56 from wokkel.subprotocols import XMPPHandler |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
57 |
0 | 58 |
59 ### logging configuration FIXME: put this elsewhere ### | |
60 logging.basicConfig(level=logging.DEBUG, | |
61 format='%(message)s') | |
62 ### | |
63 | |
64 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
65 sat_id = 0 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
66 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
67 def sat_next_id(): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
68 global sat_id |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
69 sat_id+=1 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
70 return "sat_id_"+str(sat_id) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
71 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
72 class SAT(service.Service): |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
73 |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
74 def get_next_id(self): |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
75 return sat_next_id() |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
76 |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
77 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
|
78 """Return a constant""" |
358
f147b778511a
core: local_dir can now be overrided (usefull to launch 2 instances at the same time)
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
79 try: |
f147b778511a
core: local_dir can now be overrided (usefull to launch 2 instances at the same time)
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
80 _const = os.environ['SAT_CONST_%s' % name] |
f147b778511a
core: local_dir can now be overrided (usefull to launch 2 instances at the same time)
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
81 if _const: |
f147b778511a
core: local_dir can now be overrided (usefull to launch 2 instances at the same time)
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
82 debug(_("Constant %(name)s overrided with [%(value)s]") % {'name':name, 'value': _const}) |
f147b778511a
core: local_dir can now be overrided (usefull to launch 2 instances at the same time)
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
83 return _const |
f147b778511a
core: local_dir can now be overrided (usefull to launch 2 instances at the same time)
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
84 except KeyError: |
f147b778511a
core: local_dir can now be overrided (usefull to launch 2 instances at the same time)
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
85 pass |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
86 if not CONST.has_key(name): |
69 | 87 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
|
88 raise Exception |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
89 return CONST[name] |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
90 |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
91 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
|
92 """Save a constant""" |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
93 if CONST.has_key(name): |
69 | 94 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
|
95 raise Exception |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
96 CONST[name] = value |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
97 |
0 | 98 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
|
99 #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
|
100 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 self.__private_data = {} #used for internal callbacks (key = id) |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
105 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
|
106 self.plugins = {} |
101 | 107 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
|
108 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
109 self.memory=Memory(self) |
364 | 110 |
365
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
111 local_dir = self.memory.getConfig('', 'local_dir') |
364 | 112 if not os.path.exists(local_dir): |
113 os.makedirs(local_dir) | |
114 | |
115 self.trigger = TriggerManager() #trigger are used to change SàT behaviour | |
116 | |
0 | 117 self.bridge=DBusBridge() |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
107
diff
changeset
|
118 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
|
119 self.bridge.register("getProfileName", self.memory.getProfileName) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
58
diff
changeset
|
120 self.bridge.register("getProfilesList", self.memory.getProfilesList) |
504
65ecbb473cbb
core, quick frontend, plugin xep-0054, bridge: use of memory's entities data for vcard:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
121 self.bridge.register("getEntityData", lambda _jid, keys, profile: self.memory.getEntityData(jid.JID(_jid),keys, profile)) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
58
diff
changeset
|
122 self.bridge.register("createProfile", self.memory.createProfile) |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
123 self.bridge.register("asyncCreateProfile", self.memory.asyncCreateProfile) |
68 | 124 self.bridge.register("deleteProfile", self.memory.deleteProfile) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
125 self.bridge.register("registerNewAccount", self.registerNewAccount) |
0 | 126 self.bridge.register("connect", self.connect) |
341 | 127 self.bridge.register("asyncConnect", self.asyncConnect) |
1 | 128 self.bridge.register("disconnect", self.disconnect) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
129 self.bridge.register("getContacts", self.getContacts) |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
130 self.bridge.register("getContactsFromGroup", self.getContactsFromGroup) |
399 | 131 self.bridge.register("getLastResource", self.memory.getLastResource) |
0 | 132 self.bridge.register("getPresenceStatus", self.memory.getPresenceStatus) |
50 | 133 self.bridge.register("getWaitingSub", self.memory.getWaitingSub) |
0 | 134 self.bridge.register("sendMessage", self.sendMessage) |
364 | 135 self.bridge.register("getConfig", self.memory.getConfig) |
0 | 136 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
|
137 self.bridge.register("getParamA", self.memory.getParamA) |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
138 self.bridge.register("asyncGetParamA", self.memory.asyncGetParamA) |
105 | 139 self.bridge.register("getParamsUI", self.memory.getParamsUI) |
0 | 140 self.bridge.register("getParams", self.memory.getParams) |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
141 self.bridge.register("getParamsForCategory", self.memory.getParamsForCategory) |
0 | 142 self.bridge.register("getParamsCategories", self.memory.getParamsCategories) |
143 self.bridge.register("getHistory", self.memory.getHistory) | |
144 self.bridge.register("setPresence", self.setPresence) | |
50 | 145 self.bridge.register("subscription", self.subscription) |
0 | 146 self.bridge.register("addContact", self.addContact) |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
147 self.bridge.register("updateContact", self.updateContact) |
0 | 148 self.bridge.register("delContact", self.delContact) |
149 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
|
150 self.bridge.register("launchAction", self.launchAction) |
0 | 151 self.bridge.register("confirmationAnswer", self.confirmationAnswer) |
152 self.bridge.register("getProgress", self.getProgress) | |
101 | 153 self.bridge.register("getMenus", self.getMenus) |
154 self.bridge.register("getMenuHelp", self.getMenuHelp) | |
155 self.bridge.register("callMenu", self.callMenu) | |
412 | 156 |
157 self.memory.initialized.addCallback(self._postMemoryInit) | |
0 | 158 |
412 | 159 def _postMemoryInit(self, ignore): |
160 """Method called after memory initialization is done""" | |
161 info(_("Memory initialised")) | |
64 | 162 self._import_plugins() |
0 | 163 |
164 | |
165 def _import_plugins(self): | |
166 """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
|
167 import sat.plugins |
d8bb72f00eec
distutils install: fixed plugin import and log file path
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
168 plugins_path = os.path.dirname(sat.plugins.__file__) |
412 | 169 plug_lst = [os.path.splitext(plugin)[0] for plugin in map(os.path.basename,glob(os.path.join(plugins_path,"plugin*.py")))] |
170 __plugins_to_import = {} #plugins we still have to import | |
0 | 171 for plug in plug_lst: |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
172 plugin_path = 'sat.plugins.'+plug |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
173 __import__(plugin_path) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
174 mod = sys.modules[plugin_path] |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
175 plugin_info = mod.PLUGIN_INFO |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
176 __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
|
177 while True: |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
178 self._import_plugins_from_dict(__plugins_to_import) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
179 if not __plugins_to_import: |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
180 break |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
181 |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
182 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
|
183 """Recursively import and their dependencies in the right order |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
184 @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
|
185 if self.plugins.has_key(import_name): |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
186 debug('Plugin [%s] already imported, passing' % import_name) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
187 return |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
188 if not import_name: |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
189 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
|
190 else: |
288
76247af9917c
core: added plugin dependency not found import error
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
191 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
|
192 raise ImportError(_('Dependency plugin not found: [%s]') % import_name) |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
193 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
|
194 dependencies = plugin_info.setdefault("dependencies",[]) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
195 for dependency in dependencies: |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
196 if not self.plugins.has_key(dependency): |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
197 debug('Recursively import dependency of [%s]: [%s]' % (import_name, dependency)) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
198 self._import_plugins_from_dict(plugins_to_import, dependency) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
199 info (_("importing plugin: %s"), plugin_info['name']) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
200 self.plugins[import_name] = getattr(mod, plugin_info['main'])(self) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
201 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
|
202 self.plugins[import_name].is_handler = True |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
203 else: |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
204 self.plugins[import_name].is_handler = False |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
205 #TODO: test xmppclient presence and register handler parent |
0 | 206 |
341 | 207 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
208 def connect(self, profile_key = '@DEFAULT@'): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
209 """Connect to jabber server""" |
341 | 210 self.asyncConnect(profile_key) |
211 | |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
212 def asyncConnect(self, profile_key = '@DEFAULT@'): |
341 | 213 """Connect to jabber server with asynchronous reply |
214 @param profile_key: %(doc_profile)s | |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
215 """ |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
216 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
217 profile = self.memory.getProfileName(profile_key) |
324
b069055320b1
core: fixed bad profile check in connect method
Goffi <goffi@goffi.org>
parents:
313
diff
changeset
|
218 if not profile: |
69 | 219 error (_('Trying to connect a non-exsitant profile')) |
471 | 220 raise ProfileUnknownError(profile_key) |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
221 |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
79
diff
changeset
|
222 if (self.isConnected(profile)): |
69 | 223 info(_("already connected !")) |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
224 return defer.succeed("None") |
412 | 225 |
226 def afterMemoryInit(ignore): | |
227 """This part must be called when we have loaded individual parameters from memory""" | |
228 current = self.profiles[profile] = xmpp.SatXMPPClient(self, profile, | |
229 jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key = profile), profile), | |
230 self.memory.getParamA("Password", "Connection", profile_key = profile), | |
231 self.memory.getParamA("Server", "Connection", profile_key = profile), 5222) | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
232 |
412 | 233 current.messageProt = xmpp.SatMessageProtocol(self) |
234 current.messageProt.setHandlerParent(current) | |
235 | |
236 current.roster = xmpp.SatRosterProtocol(self) | |
237 current.roster.setHandlerParent(current) | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
238 |
412 | 239 current.presence = xmpp.SatPresenceProtocol(self) |
240 current.presence.setHandlerParent(current) | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
241 |
412 | 242 current.fallBack = xmpp.SatFallbackHandler(self) |
243 current.fallBack.setHandlerParent(current) | |
244 | |
245 current.versionHandler = xmpp.SatVersionHandler(self.get_const('client_name'), | |
246 self.get_const('client_version')) | |
247 current.versionHandler.setHandlerParent(current) | |
14 | 248 |
412 | 249 debug (_("setting plugins parents")) |
250 | |
251 for plugin in self.plugins.iteritems(): | |
252 if plugin[1].is_handler: | |
253 plugin[1].getHandler(profile).setHandlerParent(current) | |
438
62145e50eae5
core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents:
434
diff
changeset
|
254 connected_cb = getattr(plugin[1], "profileConnected", None) |
62145e50eae5
core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents:
434
diff
changeset
|
255 if connected_cb: |
62145e50eae5
core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents:
434
diff
changeset
|
256 connected_cb(profile) |
14 | 257 |
412 | 258 current.startService() |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
259 |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
260 return current.getConnectionDeferred() |
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
261 |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
262 self.memory.startProfileSession(profile) |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
263 return self.memory.loadIndividualParams(profile).addCallback(afterMemoryInit) |
341 | 264 |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
265 def disconnect(self, profile_key): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
266 """disconnect from jabber server""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
267 if (not self.isConnected(profile_key)): |
69 | 268 info(_("not connected !")) |
6
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
269 return |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
270 profile = self.memory.getProfileName(profile_key) |
69 | 271 info(_("Disconnecting...")) |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
272 self.profiles[profile].stopService() |
438
62145e50eae5
core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents:
434
diff
changeset
|
273 for plugin in self.plugins.iteritems(): |
62145e50eae5
core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents:
434
diff
changeset
|
274 disconnected_cb = getattr(plugin[1], "profileDisconnected", None) |
62145e50eae5
core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents:
434
diff
changeset
|
275 if disconnected_cb: |
62145e50eae5
core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents:
434
diff
changeset
|
276 disconnected_cb(profile) |
6
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
277 |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
278 def getContacts(self, profile_key): |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
279 client = self.getClient(profile_key) |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
280 if not client: |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
281 raise ProfileUnknownError(_('Asking contacts for a non-existant profile')) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
282 ret = [] |
504
65ecbb473cbb
core, quick frontend, plugin xep-0054, bridge: use of memory's entities data for vcard:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
283 for item in client.roster.getItems(): #we get all items for client's roster |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
284 #and convert them to expected format |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
285 attr = client.roster.getAttributes(item) |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
286 ret.append([item.jid.userhost(), attr, item.groups]) |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
287 return ret |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
288 |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
289 def getContactsFromGroup(self, group, profile_key): |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
290 client = self.getClient(profile_key) |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
291 if not client: |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
292 raise ProfileUnknownError(_("Asking group's contacts for a non-existant profile")) |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
293 return client.roster.getJidsFromGroup(group) |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
294 |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
295 def purgeClient(self, profile): |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
296 """Remove reference to a profile client and purge cache |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
297 the garbage collector can then free the memory""" |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
298 try: |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
299 del self.profiles[profile] |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
300 except KeyError: |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
301 error(_("Trying to remove reference to a client not referenced")) |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
302 self.memory.purgeProfileSession(profile) |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
303 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
304 def startService(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
305 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
|
306 #TODO: manage autoconnect |
5c420b1f1df4
removed connect on statService, this was causing issue on first launch
Goffi <goffi@goffi.org>
parents:
210
diff
changeset
|
307 #self.connect() |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
308 |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
309 def stopService(self): |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
310 self.memory.save() |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
311 info("Salut aussi à Rantanplan") |
0 | 312 |
313 def run(self): | |
69 | 314 debug(_("running app")) |
0 | 315 reactor.run() |
316 | |
317 def stop(self): | |
69 | 318 debug(_("stopping app")) |
0 | 319 reactor.stop() |
320 | |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
321 ## Misc methods ## |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
322 |
64 | 323 def getJidNStream(self, profile_key): |
324 """Convenient method to get jid and stream from profile key | |
325 @return: tuple (jid, xmlstream) from profile, can be None""" | |
326 profile = self.memory.getProfileName(profile_key) | |
327 if not profile or not self.profiles[profile].isConnected(): | |
328 return (None, None) | |
329 return (self.profiles[profile].jid, self.profiles[profile].xmlstream) | |
330 | |
331 def getClient(self, profile_key): | |
332 """Convenient method to get client from profile key | |
333 @return: client or None if it doesn't exist""" | |
334 profile = self.memory.getProfileName(profile_key) | |
335 if not profile: | |
336 return None | |
337 return self.profiles[profile] | |
338 | |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
339 def registerNewAccount(self, login, password, email, server, port = 5222, id = None): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
340 """Connect to a server and create a new account using in-band registration""" |
0 | 341 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
342 next_id = id or sat_next_id() #the id is used to send server's answer |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
343 serverRegistrer = xmlstream.XmlStreamFactory(xmpp.RegisteringAuthenticator(self, server, login, password, email, next_id)) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
344 connector = reactor.connectTCP(server, port, serverRegistrer) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
345 serverRegistrer.clientConnectionLost = lambda conn, reason: connector.disconnect() |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
346 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
347 return next_id |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
348 |
107 | 349 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
|
350 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
|
351 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
|
352 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
|
353 |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
354 if not user or not password or not server: |
69 | 355 info (_('No user or server given')) |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
356 #TODO: a proper error message must be sent to frontend |
69 | 357 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
|
358 return |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
359 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
360 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
|
361 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
|
362 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
363 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
|
364 {"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
|
365 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
|
366 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
|
367 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
|
368 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
|
369 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
370 def regisConfirmCB(self, id, accepted, data): |
69 | 371 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
|
372 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
|
373 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
|
374 if accepted: |
135
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
375 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
|
376 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
|
377 server = self.memory.getParamA("Server", "Connection", profile_key=profile) |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
378 self.registerNewAccount(user, password, None, server, id=action_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
|
379 else: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
380 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
|
381 |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
382 def submitForm(self, action, target, fields, profile_key): |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
383 """submit a form |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
384 @param target: target jid where we are submitting |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
385 @param fields: list of tuples (name, value) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
386 @return: tuple: (id, deferred) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
387 """ |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
388 |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
389 profile = self.memory.getProfileName(profile_key) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
390 assert(profile) |
36 | 391 to_jid = jid.JID(target) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
392 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
393 iq = compat.IQ(self.profiles[profile].xmlstream, 'set') |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
394 iq["to"] = target |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
395 iq["from"] = self.profiles[profile].jid.full() |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
396 query = iq.addElement(('jabber:iq:register', 'query')) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
397 if action=='SUBMIT': |
102 | 398 form = tupleList2dataForm(fields) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
399 query.addChild(form.toElement()) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
400 elif action=='CANCEL': |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
401 query.addElement('remove') |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
402 else: |
69 | 403 error (_("FIXME FIXME FIXME: Unmanaged action (%s) in submitForm") % action) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
404 raise NotImplementedError |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
405 |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
406 deferred = iq.send(target) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
407 return (iq['id'], deferred) |
36 | 408 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
409 ## Client management ## |
0 | 410 |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
411 def setParam(self, name, value, category, profile_key): |
0 | 412 """set wanted paramater and notice observers""" |
69 | 413 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
|
414 self.memory.setParam(name, value, category, profile_key) |
0 | 415 |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
416 def isConnected(self, profile_key): |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
417 """Return connection status of profile |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
418 @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
|
419 @return True if connected |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
420 """ |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
421 profile = self.memory.getProfileName(profile_key) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
422 if not profile: |
69 | 423 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
|
424 return |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
425 if not self.profiles.has_key(profile): |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
426 return False |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
427 return self.profiles[profile].isConnected() |
0 | 428 |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
429 def launchAction(self, type, data, profile_key): |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
430 """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
|
431 @param type: action type (button) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
432 @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
|
433 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
434 @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
|
435 """ |
107 | 436 profile = self.memory.getProfileName(profile_key) |
437 if not profile: | |
438 error (_('trying to launch action with a non-existant profile')) | |
439 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
|
440 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
|
441 try: |
106 | 442 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
|
443 except KeyError: |
69 | 444 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
|
445 return "" |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
446 id = sat_next_id() |
107 | 447 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
|
448 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
|
449 else: |
69 | 450 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
|
451 return "" |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
452 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
453 |
0 | 454 ## jabber methods ## |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
455 |
489 | 456 def sendMessage(self, to, msg, subject=None, mess_type='auto', profile_key='@DEFAULT@'): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
457 #FIXME: check validity of recipient |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
458 profile = self.memory.getProfileName(profile_key) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
459 assert(profile) |
489 | 460 client = self.profiles[profile] |
461 current_jid = client.jid | |
462 mess_data = { #we put data in a dict, so trigger methods can change them | |
463 "to": jid.JID(to), | |
464 "message": msg, | |
465 "subject": subject, | |
466 "type": mess_type | |
467 } | |
468 if not self.trigger.point("sendMessage", mess_data, profile): | |
469 return | |
470 if mess_data["type"] == "auto": | |
471 #XXX: if the type has not been changed by a trigger method, | |
472 # we try to guess it | |
473 if mess_data["subject"]: | |
474 mess_data["type"] = 'normal' | |
475 elif not mess_data["to"].resource: #if to JID has a resource, the type is not 'groupchat' | |
476 #we may have a groupchat message, we check if the we know this jid | |
477 try: | |
478 entity_type = self.memory.getEntityData(mess_data["to"], ['type'], profile)["type"] | |
479 #FIXME: should entity_type manage ressources ? | |
480 except (UnknownEntityError, KeyError): | |
481 entity_type = "contact" | |
482 | |
483 if entity_type == "chatroom": | |
484 mess_data["type"] = 'groupchat' | |
485 else: | |
486 mess_data["type"] = 'chat' | |
487 else: | |
488 mess_data["type"] == 'chat' | |
489 mess_data["type"] == "chat" if mess_data["subject"] else "normal" | |
490 debug(_("Sending jabber message of type [%(type)s] to %(to)s...") % {"type": mess_data["type"], "to": to}) | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
491 message = domish.Element(('jabber:client','message')) |
489 | 492 message["to"] = mess_data["to"].full() |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
493 message["from"] = current_jid.full() |
489 | 494 message["type"] = mess_data["type"] |
495 if mess_data["subject"]: | |
260
c8406fe5e81e
Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
257
diff
changeset
|
496 message.addElement("subject", "jabber:client", subject) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
497 message.addElement("body", "jabber:client", msg) |
489 | 498 client.xmlstream.send(message) |
499 if mess_data["type"]!="groupchat": | |
427
bb0236633da5
core: outgoing groupchat message are not added to history anymore
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
500 self.memory.addToHistory(current_jid, jid.JID(to), unicode(msg), profile=profile) #we don't add groupchat message to history, as we get them back |
489 | 501 #and they will be added then |
502 self.bridge.newMessage(message['from'], unicode(msg), mess_type=mess_data["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
|
503 |
0 | 504 |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
505 def setPresence(self, to="", show="", priority = 0, statuses={}, profile_key='@DEFAULT@'): |
0 | 506 """Send our presence information""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
507 profile = self.memory.getProfileName(profile_key) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
508 assert(profile) |
50 | 509 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
|
510 self.profiles[profile].presence.available(to_jid, show, statuses, priority) |
313
cc8ffbfe938c
QnD workaround for presence broadcast openfire bug
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
511 #XXX: FIXME: temporary fix to work around openfire 3.7.0 bug (presence is not broadcasted to generating resource) |
cc8ffbfe938c
QnD workaround for presence broadcast openfire bug
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
512 if statuses.has_key(''): |
cc8ffbfe938c
QnD workaround for presence broadcast openfire bug
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
513 statuses['default'] = statuses[''] |
cc8ffbfe938c
QnD workaround for presence broadcast openfire bug
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
514 del statuses[''] |
cc8ffbfe938c
QnD workaround for presence broadcast openfire bug
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
515 self.bridge.presenceUpdate(self.profiles[profile].jid.full(), show, |
cc8ffbfe938c
QnD workaround for presence broadcast openfire bug
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
516 int(priority), statuses, profile) |
cc8ffbfe938c
QnD workaround for presence broadcast openfire bug
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
517 |
50 | 518 |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
519 def subscription(self, subs_type, raw_jid, profile_key): |
187
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
520 """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
|
521 @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
|
522 @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
|
523 @param profile_key: profile""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
524 profile = self.memory.getProfileName(profile_key) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
525 assert(profile) |
50 | 526 to_jid = jid.JID(raw_jid) |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
79
diff
changeset
|
527 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
|
528 if subs_type=="subscribe": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
529 self.profiles[profile].presence.subscribe(to_jid) |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
79
diff
changeset
|
530 elif subs_type=="subscribed": |
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
79
diff
changeset
|
531 self.profiles[profile].presence.subscribed(to_jid) |
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
79
diff
changeset
|
532 elif subs_type=="unsubscribe": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
533 self.profiles[profile].presence.unsubscribe(to_jid) |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
79
diff
changeset
|
534 elif subs_type=="unsubscribed": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
535 self.profiles[profile].presence.unsubscribed(to_jid) |
0 | 536 |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
537 def addContact(self, to, profile_key): |
0 | 538 """Add a contact in roster list""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
539 profile = self.memory.getProfileName(profile_key) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
540 assert(profile) |
0 | 541 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
|
542 #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
|
543 self.profiles[profile].presence.subscribe(to_jid) |
0 | 544 |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
545 def updateContact(self, to, name, groups, profile_key): |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
546 """update a contact in roster list""" |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
547 profile = self.memory.getProfileName(profile_key) |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
548 assert(profile) |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
549 to_jid = jid.JID(to) |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
550 groups = set(groups) |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
551 roster_item = RosterItem(to_jid) |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
552 roster_item.name = name or None |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
553 roster_item.groups = set(groups) |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
554 self.profiles[profile].roster.updateItem(roster_item) |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
555 |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
556 def delContact(self, to, profile_key): |
0 | 557 """Remove contact from roster list""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
558 profile = self.memory.getProfileName(profile_key) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
559 assert(profile) |
0 | 560 to_jid=jid.JID(to) |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
561 self.profiles[profile].roster.removeItem(to_jid) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
562 self.profiles[profile].presence.unsubscribe(to_jid) |
0 | 563 |
564 | |
565 ## callbacks ## | |
566 | |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
567 def serverDisco(self, disco, profile): |
0 | 568 """xep-0030 Discovery Protocol.""" |
14 | 569 for feature in disco.features: |
69 | 570 debug (_("Feature found: %s"),feature) |
282
6a0c6d8e119d
added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
571 self.memory.addServerFeature(feature, profile) |
14 | 572 for cat, type in disco.identities: |
69 | 573 debug (_("Identity found: [%(category)s/%(type)s] %(identity)s") % {'category':cat, 'type':type, 'identity':disco.identities[(cat,type)]}) |
0 | 574 |
305
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
575 def serverDiscoItems(self, disco_result, disco_client, profile, initialized): |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
576 """xep-0030 Discovery Protocol. |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
577 @param disco_result: result of the disco item querry |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
578 @param disco_client: SatDiscoProtocol instance |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
579 @param profile: profile of the user |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
580 @param initialized: deferred which must be chained when everything is done""" |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
581 def _check_entity_cb(result, entity, profile): |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
582 for category, type in result.identities: |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
583 debug (_('Identity added: (%(category)s,%(type)s) ==> %(entity)s [%(profile)s]') % { |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
584 'category':category, 'type':type, 'entity':entity, 'profile':profile}) |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
585 self.memory.addServerIdentity(category, type, entity, profile) |
397
ccfd69d090c3
core: workaround to avoid a bug in item detection on jabber.fr. Need more investigation with jabber.fr admins (may be a bug in ejabberd)
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
586 |
ccfd69d090c3
core: workaround to avoid a bug in item detection on jabber.fr. Need more investigation with jabber.fr admins (may be a bug in ejabberd)
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
587 def _errback(result, entity, profile): |
ccfd69d090c3
core: workaround to avoid a bug in item detection on jabber.fr. Need more investigation with jabber.fr admins (may be a bug in ejabberd)
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
588 warning(_("Can't get information on identity [%(entity)s] for profile [%(profile)s]") % {'entity':entity, 'profile': profile}) |
305
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
589 |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
590 defer_list = [] |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
591 for item in disco_result._items: |
397
ccfd69d090c3
core: workaround to avoid a bug in item detection on jabber.fr. Need more investigation with jabber.fr admins (may be a bug in ejabberd)
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
592 if item.entity.full().count('.') == 1: #XXX: workaround for a bug on jabberfr, tmp |
460
fb1abc0f8c6a
backend: added warning message when jabberfr workaround is used + fixed missing warning method
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
593 warning(_('Using jabberfr workaround, be sure your domain has at least two levels (e.g. "example.tld", not "example" alone)')) |
397
ccfd69d090c3
core: workaround to avoid a bug in item detection on jabber.fr. Need more investigation with jabber.fr admins (may be a bug in ejabberd)
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
594 continue |
ccfd69d090c3
core: workaround to avoid a bug in item detection on jabber.fr. Need more investigation with jabber.fr admins (may be a bug in ejabberd)
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
595 args = [item.entity, profile] |
ccfd69d090c3
core: workaround to avoid a bug in item detection on jabber.fr. Need more investigation with jabber.fr admins (may be a bug in ejabberd)
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
596 defer_list.append(disco_client.requestInfo(item.entity).addCallbacks(_check_entity_cb, _errback, args, None, args)) |
305
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
597 defer.DeferredList(defer_list).chainDeferred(initialized) |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
598 |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
599 |
0 | 600 ## 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
|
601 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
602 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
|
603 """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
|
604 @param id: same id used with action |
103 | 605 @param type: result type ("PARAM", "SUCCESS", "ERROR", "XMLUI") |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
606 @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
|
607 """ |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
608 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
|
609 |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
610 def actionResultExt(self, id, type, data): |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
611 """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
|
612 @param id: same id used with action |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
613 @param type: result type /!\ only "DICT_DICT" for this method |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
614 @param data: dictionary of dictionaries |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
615 """ |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
616 if type != "DICT_DICT": |
69 | 617 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
|
618 type = "DICT_DICT" |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
619 self.bridge.actionResultExt(type, id, data) |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
620 |
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 |
0 | 622 |
623 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
|
624 """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
|
625 @param id: id used to get answer |
391 | 626 @param type: confirmation type ("YES/NO", "FILE_TRANSFER") |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
627 @param data: data (depend of confirmation type) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
628 @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
|
629 """ |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
630 if self.__waiting_conf.has_key(id): |
69 | 631 error (_("Attempt to register two callbacks for the same confirmation")) |
0 | 632 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
|
633 self.__waiting_conf[id] = cb |
0 | 634 self.bridge.askConfirmation(type, id, data) |
635 | |
636 | |
637 def confirmationAnswer(self, id, accepted, data): | |
638 """Called by frontends to answer confirmation requests""" | |
101 | 639 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
|
640 if not self.__waiting_conf.has_key(id): |
69 | 641 error (_("Received an unknown confirmation")) |
0 | 642 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
|
643 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
|
644 del self.__waiting_conf[id] |
0 | 645 cb(id, accepted, data) |
646 | |
647 def registerProgressCB(self, id, CB): | |
648 """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
|
649 self.__progress_cb_map[id] = CB |
0 | 650 |
651 def removeProgressCB(self, id): | |
652 """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
|
653 if not self.__progress_cb_map.has_key(id): |
69 | 654 error (_("Trying to remove an unknow progress callback")) |
0 | 655 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
|
656 del self.__progress_cb_map[id] |
0 | 657 |
658 def getProgress(self, id): | |
659 """Return a dict with progress information | |
660 data['position'] : current possition | |
661 data['size'] : end_position | |
662 """ | |
663 data = {} | |
664 try: | |
388
a617af506154
core: progress callback now use id as first parameter
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
665 self.__progress_cb_map[id](id, data) |
0 | 666 except KeyError: |
667 pass | |
668 #debug("Requested progress for unknown id") | |
669 return data | |
670 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
671 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
|
672 """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
|
673 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
|
674 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
675 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
|
676 """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
|
677 if not self.__general_cb_map.has_key(name): |
69 | 678 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
|
679 else: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
680 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
|
681 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
682 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
|
683 """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
|
684 try: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
685 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
|
686 except KeyError: |
107 | 687 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
|
688 return None |
0 | 689 |
101 | 690 #Menus management |
691 | |
692 def importMenu(self, category, name, callback, help_string = "", type = "NORMAL"): | |
693 """register a new menu for frontends | |
694 @param category: category of the menu | |
695 @param name: menu item entry | |
696 @param callback: method to be called when menuitem is selected""" | |
697 if self.menus.has_key((category,name)): | |
698 error ("Want to register a menu which already existe") | |
699 return | |
700 self.menus[(category,name,type)] = {'callback':callback, 'help_string':help_string, 'type':type} | |
701 | |
702 def getMenus(self): | |
703 """Return all menus registered""" | |
704 return self.menus.keys() | |
705 | |
706 def getMenuHelp(self, category, name, type="NORMAL"): | |
707 """return the help string of the menu""" | |
708 try: | |
709 return self.menus[(category,name,type)]['help_string'] | |
710 except KeyError: | |
711 error (_("Trying to access an unknown menu")) | |
712 return "" | |
713 | |
714 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
|
715 """return the id of the action""" |
101 | 716 profile = self.memory.getProfileName(profile_key) |
717 if not profile_key: | |
718 error (_('Non-exsitant profile')) | |
719 return "" | |
102 | 720 if self.menus.has_key((category,name,type)): |
101 | 721 id = self.get_next_id() |
722 self.menus[(category,name,type)]['callback'](id, profile) | |
723 return id | |
102 | 724 else: |
725 error (_("Trying to access an unknown menu (%(category)s/%(name)s/%(type)s)")%{'category':category, 'name':name,'type':type}) | |
101 | 726 return "" |