annotate src/core/sat_main.py @ 388:a617af506154

core: progress callback now use id as first parameter
author Goffi <goffi@goffi.org>
date Thu, 29 Sep 2011 12:14:19 +0200
parents efbfccfed623
children c34fd9d6242e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
goffi@necton2
parents:
diff changeset
4 """
goffi@necton2
parents:
diff changeset
5 SAT: a jabber client
228
b1794cbb88e5 2011 copyright upgrade
Goffi <goffi@goffi.org>
parents: 226
diff changeset
6 Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
7
goffi@necton2
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
goffi@necton2
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
goffi@necton2
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
goffi@necton2
parents:
diff changeset
11 (at your option) any later version.
goffi@necton2
parents:
diff changeset
12
goffi@necton2
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
goffi@necton2
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
goffi@necton2
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
goffi@necton2
parents:
diff changeset
16 GNU General Public License for more details.
goffi@necton2
parents:
diff changeset
17
goffi@necton2
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
goffi@necton2
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
goffi@necton2
parents:
diff changeset
20 """
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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
0
goffi@necton2
parents:
diff changeset
29
39
2e3411a6baad Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents: 37
diff changeset
30 from twisted.words.protocols.jabber import jid, xmlstream
0
goffi@necton2
parents:
diff changeset
31 from twisted.words.xish import domish
goffi@necton2
parents:
diff changeset
32
goffi@necton2
parents:
diff changeset
33 from twisted.internet import reactor
goffi@necton2
parents:
diff changeset
34
331
0a8eb0461f31 core: main SAT class now moved in its own module core.sat_main
Goffi <goffi@goffi.org>
parents: 330
diff changeset
35 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
36 from wokkel.xmppim import RosterItem
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
37
223
86d249b6d9b7 Files reorganisation
Goffi <goffi@goffi.org>
parents: 213
diff changeset
38 from sat.bridge.DBus import DBusBridge
0
goffi@necton2
parents:
diff changeset
39 import logging
goffi@necton2
parents:
diff changeset
40 from logging import debug, info, error
goffi@necton2
parents:
diff changeset
41
331
0a8eb0461f31 core: main SAT class now moved in its own module core.sat_main
Goffi <goffi@goffi.org>
parents: 330
diff changeset
42 import sys
0
goffi@necton2
parents:
diff changeset
43 import os.path
goffi@necton2
parents:
diff changeset
44
332
8c9b9ef13ba1 core: minor refactoring
Goffi <goffi@goffi.org>
parents: 331
diff changeset
45 from sat.core import xmpp
223
86d249b6d9b7 Files reorganisation
Goffi <goffi@goffi.org>
parents: 213
diff changeset
46 from sat.tools.memory import Memory
86d249b6d9b7 Files reorganisation
Goffi <goffi@goffi.org>
parents: 213
diff changeset
47 from sat.tools.xml_tools import tupleList2dataForm
252
c09aa319712e Core: Trigger implementation + version number update
Goffi <goffi@goffi.org>
parents: 245
diff changeset
48 from sat.tools.misc import TriggerManager
0
goffi@necton2
parents:
diff changeset
49 from glob import glob
goffi@necton2
parents:
diff changeset
50
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
51 try:
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
52 from twisted.words.protocols.xmlstream import XMPPHandler
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
53 except ImportError:
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
54 from wokkel.subprotocols import XMPPHandler
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
55
0
goffi@necton2
parents:
diff changeset
56
goffi@necton2
parents:
diff changeset
57 ### logging configuration FIXME: put this elsewhere ###
goffi@necton2
parents:
diff changeset
58 logging.basicConfig(level=logging.DEBUG,
goffi@necton2
parents:
diff changeset
59 format='%(message)s')
goffi@necton2
parents:
diff changeset
60 ###
goffi@necton2
parents:
diff changeset
61
goffi@necton2
parents:
diff changeset
62
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
63 sat_id = 0
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
64
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
65 def sat_next_id():
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
66 global sat_id
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
67 sat_id+=1
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
68 return "sat_id_"+str(sat_id)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
69
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
70 class SAT(service.Service):
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
71
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
72 def get_next_id(self):
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
73 return sat_next_id()
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
74
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 39
diff changeset
75 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
76 """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
77 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
78 _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
79 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
80 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
81 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
82 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
83 pass
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 39
diff changeset
84 if not CONST.has_key(name):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
85 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
86 raise Exception
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 39
diff changeset
87 return CONST[name]
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 39
diff changeset
88
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 39
diff changeset
89 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
90 """Save a constant"""
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 39
diff changeset
91 if CONST.has_key(name):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
92 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
93 raise Exception
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 39
diff changeset
94 CONST[name] = value
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 39
diff changeset
95
0
goffi@necton2
parents:
diff changeset
96 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
97 #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
98
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 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
100 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
101 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
102 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
103 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
104 self.plugins = {}
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
105 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
106
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
107 self.memory=Memory(self)
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 358
diff changeset
108
365
efbfccfed623 core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents: 364
diff changeset
109 local_dir = self.memory.getConfig('', 'local_dir')
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 358
diff changeset
110 if not os.path.exists(local_dir):
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 358
diff changeset
111 os.makedirs(local_dir)
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 358
diff changeset
112
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 358
diff changeset
113 self.trigger = TriggerManager() #trigger are used to change SàT behaviour
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 358
diff changeset
114
0
goffi@necton2
parents:
diff changeset
115
goffi@necton2
parents:
diff changeset
116 self.bridge=DBusBridge()
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 107
diff changeset
117 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
118 self.bridge.register("getProfileName", self.memory.getProfileName)
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 58
diff changeset
119 self.bridge.register("getProfilesList", self.memory.getProfilesList)
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 58
diff changeset
120 self.bridge.register("createProfile", self.memory.createProfile)
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 67
diff changeset
121 self.bridge.register("deleteProfile", self.memory.deleteProfile)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
122 self.bridge.register("registerNewAccount", self.registerNewAccount)
0
goffi@necton2
parents:
diff changeset
123 self.bridge.register("connect", self.connect)
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
124 self.bridge.register("asyncConnect", self.asyncConnect)
1
a06a151fc31f Disconnect first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
125 self.bridge.register("disconnect", self.disconnect)
0
goffi@necton2
parents:
diff changeset
126 self.bridge.register("getContacts", self.memory.getContacts)
goffi@necton2
parents:
diff changeset
127 self.bridge.register("getPresenceStatus", self.memory.getPresenceStatus)
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
128 self.bridge.register("getWaitingSub", self.memory.getWaitingSub)
0
goffi@necton2
parents:
diff changeset
129 self.bridge.register("sendMessage", self.sendMessage)
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 358
diff changeset
130 self.bridge.register("getConfig", self.memory.getConfig)
0
goffi@necton2
parents:
diff changeset
131 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
132 self.bridge.register("getParamA", self.memory.getParamA)
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 103
diff changeset
133 self.bridge.register("getParamsUI", self.memory.getParamsUI)
0
goffi@necton2
parents:
diff changeset
134 self.bridge.register("getParams", self.memory.getParams)
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
135 self.bridge.register("getParamsForCategory", self.memory.getParamsForCategory)
0
goffi@necton2
parents:
diff changeset
136 self.bridge.register("getParamsCategories", self.memory.getParamsCategories)
goffi@necton2
parents:
diff changeset
137 self.bridge.register("getHistory", self.memory.getHistory)
goffi@necton2
parents:
diff changeset
138 self.bridge.register("setPresence", self.setPresence)
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
139 self.bridge.register("subscription", self.subscription)
0
goffi@necton2
parents:
diff changeset
140 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
141 self.bridge.register("updateContact", self.updateContact)
0
goffi@necton2
parents:
diff changeset
142 self.bridge.register("delContact", self.delContact)
goffi@necton2
parents:
diff changeset
143 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
144 self.bridge.register("launchAction", self.launchAction)
0
goffi@necton2
parents:
diff changeset
145 self.bridge.register("confirmationAnswer", self.confirmationAnswer)
goffi@necton2
parents:
diff changeset
146 self.bridge.register("getProgress", self.getProgress)
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
147 self.bridge.register("getMenus", self.getMenus)
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
148 self.bridge.register("getMenuHelp", self.getMenuHelp)
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
149 self.bridge.register("callMenu", self.callMenu)
0
goffi@necton2
parents:
diff changeset
150
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
151 self._import_plugins()
0
goffi@necton2
parents:
diff changeset
152
goffi@necton2
parents:
diff changeset
153
goffi@necton2
parents:
diff changeset
154 def _import_plugins(self):
goffi@necton2
parents:
diff changeset
155 """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
156 import sat.plugins
d8bb72f00eec distutils install: fixed plugin import and log file path
Goffi <goffi@goffi.org>
parents: 225
diff changeset
157 plugins_path = os.path.dirname(sat.plugins.__file__)
d8bb72f00eec distutils install: fixed plugin import and log file path
Goffi <goffi@goffi.org>
parents: 225
diff changeset
158 plug_lst = [os.path.splitext(plugin)[0] for plugin in map(os.path.basename,glob (os.path.join(plugins_path,"plugin*.py")))]
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
159 __plugins_to_import = {} #plugins will still have to import
0
goffi@necton2
parents:
diff changeset
160 for plug in plug_lst:
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
161 plugin_path = 'sat.plugins.'+plug
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
162 __import__(plugin_path)
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
163 mod = sys.modules[plugin_path]
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
164 plugin_info = mod.PLUGIN_INFO
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
165 __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
166 while True:
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
167 self._import_plugins_from_dict(__plugins_to_import)
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
168 if not __plugins_to_import:
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
169 break
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
170
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
171 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
172 """Recursively import and their dependencies in the right order
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
173 @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
174 if self.plugins.has_key(import_name):
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
175 debug('Plugin [%s] already imported, passing' % import_name)
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
176 return
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
177 if not import_name:
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
178 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
179 else:
288
76247af9917c core: added plugin dependency not found import error
Goffi <goffi@goffi.org>
parents: 287
diff changeset
180 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
181 raise ImportError(_('Dependency plugin not found: [%s]') % import_name)
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
182 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
183 dependencies = plugin_info.setdefault("dependencies",[])
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
184 for dependency in dependencies:
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
185 if not self.plugins.has_key(dependency):
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
186 debug('Recursively import dependency of [%s]: [%s]' % (import_name, dependency))
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
187 self._import_plugins_from_dict(plugins_to_import, dependency)
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
188 info (_("importing plugin: %s"), plugin_info['name'])
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
189 self.plugins[import_name] = getattr(mod, plugin_info['main'])(self)
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
190 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
191 self.plugins[import_name].is_handler = True
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
192 else:
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
193 self.plugins[import_name].is_handler = False
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
194 #TODO: test xmppclient presence and register handler parent
0
goffi@necton2
parents:
diff changeset
195
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
196
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
197 def connect(self, profile_key = '@DEFAULT@'):
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
198 """Connect to jabber server"""
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
199 self.asyncConnect(profile_key)
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
200
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
201 def asyncConnect(self, profile_key = '@DEFAULT@', callback=None, errback=None):
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
202 """Connect to jabber server with asynchronous reply
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
203 @param profile_key: %(doc_profile)s
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
204 @param callback: called when the profile is connected
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
205 @param errback: called is the connection fail"""
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
206
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
207 profile = self.memory.getProfileName(profile_key)
324
b069055320b1 core: fixed bad profile check in connect method
Goffi <goffi@goffi.org>
parents: 313
diff changeset
208 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
209 error (_('Trying to connect a non-exsitant profile'))
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
210 return
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
211
89
23caf1051099 multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents: 79
diff changeset
212 if (self.isConnected(profile)):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
213 info(_("already connected !"))
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
214 if callback:
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
215 callback()
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
216 return
332
8c9b9ef13ba1 core: minor refactoring
Goffi <goffi@goffi.org>
parents: 331
diff changeset
217 current = self.profiles[profile] = xmpp.SatXMPPClient(self, profile,
324
b069055320b1 core: fixed bad profile check in connect method
Goffi <goffi@goffi.org>
parents: 313
diff changeset
218 jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key = profile), profile),
b069055320b1 core: fixed bad profile check in connect method
Goffi <goffi@goffi.org>
parents: 313
diff changeset
219 self.memory.getParamA("Password", "Connection", profile_key = profile),
b069055320b1 core: fixed bad profile check in connect method
Goffi <goffi@goffi.org>
parents: 313
diff changeset
220 self.memory.getParamA("Server", "Connection", profile_key = profile), 5222)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
221
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
222 if callback and errback:
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
223 current.getConnectionDeferred().addCallbacks(lambda x:callback(), errback)
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
224
332
8c9b9ef13ba1 core: minor refactoring
Goffi <goffi@goffi.org>
parents: 331
diff changeset
225 current.messageProt = xmpp.SatMessageProtocol(self)
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
226 current.messageProt.setHandlerParent(current)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
227
332
8c9b9ef13ba1 core: minor refactoring
Goffi <goffi@goffi.org>
parents: 331
diff changeset
228 current.roster = xmpp.SatRosterProtocol(self)
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
229 current.roster.setHandlerParent(current)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
230
332
8c9b9ef13ba1 core: minor refactoring
Goffi <goffi@goffi.org>
parents: 331
diff changeset
231 current.presence = xmpp.SatPresenceProtocol(self)
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
232 current.presence.setHandlerParent(current)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
233
332
8c9b9ef13ba1 core: minor refactoring
Goffi <goffi@goffi.org>
parents: 331
diff changeset
234 current.fallBack = xmpp.SatFallbackHandler(self)
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
235 current.fallBack.setHandlerParent(current)
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
236
332
8c9b9ef13ba1 core: minor refactoring
Goffi <goffi@goffi.org>
parents: 331
diff changeset
237 current.versionHandler = xmpp.SatVersionHandler(self.get_const('client_name'),
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 39
diff changeset
238 self.get_const('client_version'))
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
239 current.versionHandler.setHandlerParent(current)
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
240
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
241 debug (_("setting plugins parents"))
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
242
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
243 for plugin in self.plugins.iteritems():
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
244 if plugin[1].is_handler:
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 69
diff changeset
245 plugin[1].getHandler(profile).setHandlerParent(current)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
246
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
247 current.startService()
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
248
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
249 def disconnect(self, profile_key):
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
250 """disconnect from jabber server"""
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
251 if (not self.isConnected(profile_key)):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
252 info(_("not connected !"))
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
253 return
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
254 profile = self.memory.getProfileName(profile_key)
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
255 info(_("Disconnecting..."))
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
256 self.profiles[profile].stopService()
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
257
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
258 def startService(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
259 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
260 #TODO: manage autoconnect
5c420b1f1df4 removed connect on statService, this was causing issue on first launch
Goffi <goffi@goffi.org>
parents: 210
diff changeset
261 #self.connect()
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
262
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
263 def stopService(self):
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
264 self.memory.save()
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
265 info("Salut aussi à Rantanplan")
0
goffi@necton2
parents:
diff changeset
266
goffi@necton2
parents:
diff changeset
267 def run(self):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
268 debug(_("running app"))
0
goffi@necton2
parents:
diff changeset
269 reactor.run()
goffi@necton2
parents:
diff changeset
270
goffi@necton2
parents:
diff changeset
271 def stop(self):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
272 debug(_("stopping app"))
0
goffi@necton2
parents:
diff changeset
273 reactor.stop()
goffi@necton2
parents:
diff changeset
274
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
275 ## Misc methods ##
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
276
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
277 def getJidNStream(self, profile_key):
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
278 """Convenient method to get jid and stream from profile key
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
279 @return: tuple (jid, xmlstream) from profile, can be None"""
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
280 profile = self.memory.getProfileName(profile_key)
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
281 if not profile or not self.profiles[profile].isConnected():
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
282 return (None, None)
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
283 return (self.profiles[profile].jid, self.profiles[profile].xmlstream)
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
284
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
285 def getClient(self, profile_key):
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
286 """Convenient method to get client from profile key
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
287 @return: client or None if it doesn't exist"""
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
288 profile = self.memory.getProfileName(profile_key)
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
289 if not profile:
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
290 return None
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
291 return self.profiles[profile]
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
292
336
953536246d9d core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents: 332
diff changeset
293 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
294 """Connect to a server and create a new account using in-band registration"""
0
goffi@necton2
parents:
diff changeset
295
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
296 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
297 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
298 connector = reactor.connectTCP(server, port, serverRegistrer)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
299 serverRegistrer.clientConnectionLost = lambda conn, reason: connector.disconnect()
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
300
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
301 return next_id
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
302
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
303 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
304 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
305 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
306 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
307
23
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
308 if not user or not password or not server:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
309 info (_('No user or server given'))
23
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
310 #TODO: a proper error message must be sent to frontend
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
311 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
312 return
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
313
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
314 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
315 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
316
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
317 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
318 {"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
319 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
320 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
321 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
322 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
323
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
324 def regisConfirmCB(self, id, accepted, data):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
325 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
326 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
327 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
328 if accepted:
135
7452ac3818e7 Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents: 119
diff changeset
329 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
330 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
331 server = self.memory.getParamA("Server", "Connection", profile_key=profile)
336
953536246d9d core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents: 332
diff changeset
332 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
333 else:
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
334 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
335
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
336 def submitForm(self, action, target, fields, profile_key):
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
337 """submit a form
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
338 @param target: target jid where we are submitting
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
339 @param fields: list of tuples (name, value)
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
340 @return: tuple: (id, deferred)
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
341 """
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
342
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
343 profile = self.memory.getProfileName(profile_key)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
344 assert(profile)
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 33
diff changeset
345 to_jid = jid.JID(target)
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
346
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
347 iq = compat.IQ(self.profiles[profile].xmlstream, 'set')
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
348 iq["to"] = target
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
349 iq["from"] = self.profiles[profile].jid.full()
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
350 query = iq.addElement(('jabber:iq:register', 'query'))
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
351 if action=='SUBMIT':
102
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 101
diff changeset
352 form = tupleList2dataForm(fields)
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
353 query.addChild(form.toElement())
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
354 elif action=='CANCEL':
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
355 query.addElement('remove')
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
356 else:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
357 error (_("FIXME FIXME FIXME: Unmanaged action (%s) in submitForm") % action)
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
358 raise NotImplementedError
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
359
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
360 deferred = iq.send(target)
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
361 return (iq['id'], deferred)
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 33
diff changeset
362
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
363 ## Client management ##
0
goffi@necton2
parents:
diff changeset
364
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
365 def setParam(self, name, value, category, profile_key):
0
goffi@necton2
parents:
diff changeset
366 """set wanted paramater and notice observers"""
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
367 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
368 self.memory.setParam(name, value, category, profile_key)
0
goffi@necton2
parents:
diff changeset
369
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
370 def isConnected(self, profile_key):
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
371 """Return connection status of profile
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
372 @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
373 @return True if connected
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
374 """
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
375 profile = self.memory.getProfileName(profile_key)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
376 if not profile:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
377 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
378 return
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
379 if not self.profiles.has_key(profile):
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
380 return False
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
381 return self.profiles[profile].isConnected()
0
goffi@necton2
parents:
diff changeset
382
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
383 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
384 """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
385 @param type: action type (button)
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
386 @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
387
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
388 @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
389 """
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
390 profile = self.memory.getProfileName(profile_key)
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
391 if not profile:
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
392 error (_('trying to launch action with a non-existant profile'))
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
393 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
394 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
395 try:
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
396 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
397 except KeyError:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
398 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
399 return ""
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
400 id = sat_next_id()
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
401 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
402 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
403 else:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
404 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
405 return ""
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
406
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
407
0
goffi@necton2
parents:
diff changeset
408 ## jabber methods ##
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
409
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents: 257
diff changeset
410 def sendMessage(self, to, msg, subject=None, type='chat', profile_key='@DEFAULT@'):
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
411 #FIXME: check validity of recipient
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
412 profile = self.memory.getProfileName(profile_key)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
413 assert(profile)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
414 current_jid = self.profiles[profile].jid
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
415 debug(_("Sending jabber message to %s..."), to)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
416 message = domish.Element(('jabber:client','message'))
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
417 message["to"] = jid.JID(to).full()
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
418 message["from"] = current_jid.full()
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
419 message["type"] = type
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents: 257
diff changeset
420 if subject:
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents: 257
diff changeset
421 message.addElement("subject", "jabber:client", subject)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
422 message.addElement("body", "jabber:client", msg)
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
423 self.profiles[profile].xmlstream.send(message)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
424 self.memory.addToHistory(current_jid, current_jid, jid.JID(to), message["type"], unicode(msg))
79
db0a0f000e37 Chat presentation enhancement
Goffi <goffi@goffi.org>
parents: 72
diff changeset
425 if type!="groupchat":
276
a00e87d48213 bridge, bridge constructor: fixed mix stuff
Goffi <goffi@goffi.org>
parents: 274
diff changeset
426 self.bridge.newMessage(message['from'], unicode(msg), mess_type=type, to_jid=message['to'], profile=profile) #We send back the message, so all clients are aware of it
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
427
0
goffi@necton2
parents:
diff changeset
428
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
429 def setPresence(self, to="", show="", priority = 0, statuses={}, profile_key='@DEFAULT@'):
0
goffi@necton2
parents:
diff changeset
430 """Send our presence information"""
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
431 profile = self.memory.getProfileName(profile_key)
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
432 assert(profile)
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
433 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
434 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
435 #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
436 if statuses.has_key(''):
cc8ffbfe938c QnD workaround for presence broadcast openfire bug
Goffi <goffi@goffi.org>
parents: 305
diff changeset
437 statuses['default'] = statuses['']
cc8ffbfe938c QnD workaround for presence broadcast openfire bug
Goffi <goffi@goffi.org>
parents: 305
diff changeset
438 del statuses['']
cc8ffbfe938c QnD workaround for presence broadcast openfire bug
Goffi <goffi@goffi.org>
parents: 305
diff changeset
439 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
440 int(priority), statuses, profile)
cc8ffbfe938c QnD workaround for presence broadcast openfire bug
Goffi <goffi@goffi.org>
parents: 305
diff changeset
441
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
442
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
443 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
444 """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
445 @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
446 @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
447 @param profile_key: profile"""
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
448 profile = self.memory.getProfileName(profile_key)
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
449 assert(profile)
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
450 to_jid = jid.JID(raw_jid)
89
23caf1051099 multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents: 79
diff changeset
451 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
452 if subs_type=="subscribe":
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
453 self.profiles[profile].presence.subscribe(to_jid)
89
23caf1051099 multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents: 79
diff changeset
454 elif subs_type=="subscribed":
23caf1051099 multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents: 79
diff changeset
455 self.profiles[profile].presence.subscribed(to_jid)
23caf1051099 multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents: 79
diff changeset
456 elif subs_type=="unsubscribe":
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
457 self.profiles[profile].presence.unsubscribe(to_jid)
89
23caf1051099 multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents: 79
diff changeset
458 elif subs_type=="unsubscribed":
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
459 self.profiles[profile].presence.unsubscribed(to_jid)
0
goffi@necton2
parents:
diff changeset
460
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
461 def addContact(self, to, profile_key):
0
goffi@necton2
parents:
diff changeset
462 """Add a contact in roster list"""
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
463 profile = self.memory.getProfileName(profile_key)
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
464 assert(profile)
0
goffi@necton2
parents:
diff changeset
465 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
466 #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
467 self.profiles[profile].presence.subscribe(to_jid)
0
goffi@necton2
parents:
diff changeset
468
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
469 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
470 """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
471 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
472 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
473 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
474 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
475 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
476 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
477 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
478 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
479
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
480 def delContact(self, to, profile_key):
0
goffi@necton2
parents:
diff changeset
481 """Remove contact from roster list"""
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
482 profile = self.memory.getProfileName(profile_key)
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
483 assert(profile)
0
goffi@necton2
parents:
diff changeset
484 to_jid=jid.JID(to)
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
485 self.profiles[profile].roster.removeItem(to_jid)
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
486 self.profiles[profile].presence.unsubscribe(to_jid)
0
goffi@necton2
parents:
diff changeset
487
goffi@necton2
parents:
diff changeset
488
goffi@necton2
parents:
diff changeset
489 ## callbacks ##
goffi@necton2
parents:
diff changeset
490
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 277
diff changeset
491 def serverDisco(self, disco, profile):
0
goffi@necton2
parents:
diff changeset
492 """xep-0030 Discovery Protocol."""
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
493 for feature in disco.features:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
494 debug (_("Feature found: %s"),feature)
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 277
diff changeset
495 self.memory.addServerFeature(feature, profile)
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
496 for cat, type in disco.identities:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
497 debug (_("Identity found: [%(category)s/%(type)s] %(identity)s") % {'category':cat, 'type':type, 'identity':disco.identities[(cat,type)]})
0
goffi@necton2
parents:
diff changeset
498
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
499 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
500 """xep-0030 Discovery Protocol.
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
501 @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
502 @param disco_client: SatDiscoProtocol instance
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
503 @param profile: profile of the user
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
504 @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
505 def _check_entity_cb(result, entity, profile):
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
506 for category, type in result.identities:
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
507 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
508 '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
509 self.memory.addServerIdentity(category, type, entity, profile)
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
510
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
511 defer_list = []
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
512 for item in disco_result._items:
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
513 defer_list.append(disco_client.requestInfo(item.entity).addCallback(_check_entity_cb, item.entity, profile))
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
514 defer.DeferredList(defer_list).chainDeferred(initialized)
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
515
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
516
0
goffi@necton2
parents:
diff changeset
517 ## 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
518
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
519 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
520 """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
521 @param id: same id used with action
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
522 @param type: result type ("PARAM", "SUCCESS", "ERROR", "XMLUI")
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
523 @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
524 """
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
525 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
526
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
527 def actionResultExt(self, id, type, data):
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
528 """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
529 @param id: same id used with action
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
530 @param type: result type /!\ only "DICT_DICT" for this method
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
531 @param data: dictionary of dictionaries
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
532 """
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
533 if type != "DICT_DICT":
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
534 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
535 type = "DICT_DICT"
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
536 self.bridge.actionResultExt(type, id, data)
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
537
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
538
0
goffi@necton2
parents:
diff changeset
539
goffi@necton2
parents:
diff changeset
540 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
541 """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
542 @param id: id used to get answer
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
543 @param type: confirmation type ("YES/NO", "FILE_TRANSFERT")
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
544 @param data: data (depend of confirmation type)
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
545 @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
546 """
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
547 if self.__waiting_conf.has_key(id):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
548 error (_("Attempt to register two callbacks for the same confirmation"))
0
goffi@necton2
parents:
diff changeset
549 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
550 self.__waiting_conf[id] = cb
0
goffi@necton2
parents:
diff changeset
551 self.bridge.askConfirmation(type, id, data)
goffi@necton2
parents:
diff changeset
552
goffi@necton2
parents:
diff changeset
553
goffi@necton2
parents:
diff changeset
554 def confirmationAnswer(self, id, accepted, data):
goffi@necton2
parents:
diff changeset
555 """Called by frontends to answer confirmation requests"""
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
556 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
557 if not self.__waiting_conf.has_key(id):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
558 error (_("Received an unknown confirmation"))
0
goffi@necton2
parents:
diff changeset
559 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
560 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
561 del self.__waiting_conf[id]
0
goffi@necton2
parents:
diff changeset
562 cb(id, accepted, data)
goffi@necton2
parents:
diff changeset
563
goffi@necton2
parents:
diff changeset
564 def registerProgressCB(self, id, CB):
goffi@necton2
parents:
diff changeset
565 """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
566 self.__progress_cb_map[id] = CB
0
goffi@necton2
parents:
diff changeset
567
goffi@necton2
parents:
diff changeset
568 def removeProgressCB(self, id):
goffi@necton2
parents:
diff changeset
569 """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
570 if not self.__progress_cb_map.has_key(id):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
571 error (_("Trying to remove an unknow progress callback"))
0
goffi@necton2
parents:
diff changeset
572 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
573 del self.__progress_cb_map[id]
0
goffi@necton2
parents:
diff changeset
574
goffi@necton2
parents:
diff changeset
575 def getProgress(self, id):
goffi@necton2
parents:
diff changeset
576 """Return a dict with progress information
goffi@necton2
parents:
diff changeset
577 data['position'] : current possition
goffi@necton2
parents:
diff changeset
578 data['size'] : end_position
goffi@necton2
parents:
diff changeset
579 """
goffi@necton2
parents:
diff changeset
580 data = {}
goffi@necton2
parents:
diff changeset
581 try:
388
a617af506154 core: progress callback now use id as first parameter
Goffi <goffi@goffi.org>
parents: 365
diff changeset
582 self.__progress_cb_map[id](id, data)
0
goffi@necton2
parents:
diff changeset
583 except KeyError:
goffi@necton2
parents:
diff changeset
584 pass
goffi@necton2
parents:
diff changeset
585 #debug("Requested progress for unknown id")
goffi@necton2
parents:
diff changeset
586 return data
goffi@necton2
parents:
diff changeset
587
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
588 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
589 """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
590 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
591
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
592 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
593 """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
594 if not self.__general_cb_map.has_key(name):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
595 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
596 else:
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
597 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
598
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
599 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
600 """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
601 try:
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
602 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
603 except KeyError:
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
604 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
605 return None
0
goffi@necton2
parents:
diff changeset
606
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
607 #Menus management
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
608
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
609 def importMenu(self, category, name, callback, help_string = "", type = "NORMAL"):
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
610 """register a new menu for frontends
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
611 @param category: category of the menu
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
612 @param name: menu item entry
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
613 @param callback: method to be called when menuitem is selected"""
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
614 if self.menus.has_key((category,name)):
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
615 error ("Want to register a menu which already existe")
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
616 return
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
617 self.menus[(category,name,type)] = {'callback':callback, 'help_string':help_string, 'type':type}
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
618
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
619 def getMenus(self):
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
620 """Return all menus registered"""
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
621 return self.menus.keys()
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
622
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
623 def getMenuHelp(self, category, name, type="NORMAL"):
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
624 """return the help string of the menu"""
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
625 try:
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
626 return self.menus[(category,name,type)]['help_string']
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
627 except KeyError:
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
628 error (_("Trying to access an unknown menu"))
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
629 return ""
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
630
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
631 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
632 """return the id of the action"""
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
633 profile = self.memory.getProfileName(profile_key)
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
634 if not profile_key:
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
635 error (_('Non-exsitant profile'))
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
636 return ""
102
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 101
diff changeset
637 if self.menus.has_key((category,name,type)):
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
638 id = self.get_next_id()
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
639 self.menus[(category,name,type)]['callback'](id, profile)
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
640 return id
102
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 101
diff changeset
641 else:
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 101
diff changeset
642 error (_("Trying to access an unknown menu (%(category)s/%(name)s/%(type)s)")%{'category':category, 'name':name,'type':type})
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
643 return ""