comparison sat/core/sat_main.py @ 2810:c161a294fffd

core: added a base menu allowing to set encryption session or show the trust management UI.
author Goffi <goffi@goffi.org>
date Sun, 24 Feb 2019 14:11:08 +0100
parents 034c88e9cd93
children 5ba98fd6c9a4
comparison
equal deleted inserted replaced
2809:00d905e1b0ef 2810:c161a294fffd
15 # GNU Affero General Public License for more details. 15 # GNU Affero General Public License for more details.
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from glob import glob
21 import sys
22 import os.path
23 import uuid
20 import sat 24 import sat
21 from sat.core.i18n import _, languageSwitch 25 from sat.core.i18n import _, languageSwitch
22 from sat.core import patches 26 from sat.core import patches
23 patches.apply() 27 patches.apply()
24 from twisted.application import service 28 from twisted.application import service
28 from wokkel.xmppim import RosterItem 32 from wokkel.xmppim import RosterItem
29 from sat.core import xmpp 33 from sat.core import xmpp
30 from sat.core import exceptions 34 from sat.core import exceptions
31 from sat.core.log import getLogger 35 from sat.core.log import getLogger
32 36
33 log = getLogger(__name__)
34 from sat.core.constants import Const as C 37 from sat.core.constants import Const as C
35 from sat.memory import memory 38 from sat.memory import memory
36 from sat.memory import cache 39 from sat.memory import cache
37 from sat.memory import encryption 40 from sat.memory import encryption
38 from sat.tools import async_trigger as trigger 41 from sat.tools import async_trigger as trigger
39 from sat.tools import utils 42 from sat.tools import utils
40 from sat.tools.common import dynamic_import 43 from sat.tools.common import dynamic_import
41 from sat.tools.common import regex 44 from sat.tools.common import regex
42 from sat.stdui import ui_contact_list, ui_profile_manager 45 from sat.stdui import ui_contact_list, ui_profile_manager
43 import sat.plugins 46 import sat.plugins
44 from glob import glob
45 import sys
46 import os.path
47 import uuid
48 47
49 48
50 try: 49 try:
51 from collections import OrderedDict # only available from python 2.7 50 from collections import OrderedDict # only available from python 2.7
52 except ImportError: 51 except ImportError:
53 from ordereddict import OrderedDict 52 from ordereddict import OrderedDict
54 53
54 log = getLogger(__name__)
55 55
56 class SAT(service.Service): 56 class SAT(service.Service):
57 def __init__(self): 57 def __init__(self):
58 self._cb_map = {} # map from callback_id to callbacks 58 self._cb_map = {} # map from callback_id to callbacks
59 self._menus = ( 59 self._menus = (
204 _(u"Could not initialize backend: {reason}").format( 204 _(u"Could not initialize backend: {reason}").format(
205 reason=str(e).decode("utf-8", "ignore") 205 reason=str(e).decode("utf-8", "ignore")
206 ) 206 )
207 ) 207 )
208 sys.exit(1) 208 sys.exit(1)
209 self._addBaseMenus()
209 self.initialised.callback(None) 210 self.initialised.callback(None)
210 log.info(_(u"Backend is ready")) 211 log.info(_(u"Backend is ready"))
212
213 def _addBaseMenus(self):
214 """Add base menus"""
215 encryption.EncryptionHandler._importMenus(self)
211 216
212 def _unimport_plugin(self, plugin_path): 217 def _unimport_plugin(self, plugin_path):
213 """remove a plugin from sys.modules if it is there""" 218 """remove a plugin from sys.modules if it is there"""
214 try: 219 try:
215 del sys.modules[plugin_path] 220 del sys.modules[plugin_path]
930 d_list.append(self.getDiscoInfos(client, full_jid)) 935 d_list.append(self.getDiscoInfos(client, full_jid))
931 936
932 d_list = defer.DeferredList(d_list) 937 d_list = defer.DeferredList(d_list)
933 # XXX: 10 seconds may be too low for slow connections (e.g. mobiles) 938 # XXX: 10 seconds may be too low for slow connections (e.g. mobiles)
934 # but for discovery, that's also the time the user will wait the first time 939 # but for discovery, that's also the time the user will wait the first time
935 # before seing the page. 940 # before seing the page, if something goes wrong.
936 d_list.addTimeout(10, reactor) 941 d_list.addTimeout(10, reactor)
937 infos_data = yield d_list 942 infos_data = yield d_list
938 943
939 for idx, (success, infos) in enumerate(infos_data): 944 for idx, (success, infos) in enumerate(infos_data):
940 full_jid = full_jids[idx] 945 full_jid = full_jids[idx]
1186 @param path(iterable[unicode]): untranslated path to menu 1191 @param path(iterable[unicode]): untranslated path to menu
1187 @return (tuple[unicode]): canonical form of path 1192 @return (tuple[unicode]): canonical form of path
1188 """ 1193 """
1189 return tuple((p.lower().strip() for p in path)) 1194 return tuple((p.lower().strip() for p in path))
1190 1195
1191 def importMenu( 1196 def importMenu(self, path, callback, security_limit=C.NO_SECURITY_LIMIT,
1192 self, 1197 help_string="", type_=C.MENU_GLOBAL):
1193 path,
1194 callback,
1195 security_limit=C.NO_SECURITY_LIMIT,
1196 help_string="",
1197 type_=C.MENU_GLOBAL,
1198 ):
1199 """register a new menu for frontends 1198 """register a new menu for frontends
1200 1199
1201 @param path(iterable[unicode]): path to go to the menu 1200 @param path(iterable[unicode]): path to go to the menu
1202 (category/subcategory/.../item) (e.g.: ("File", "Open")) 1201 (category/subcategory/.../item) (e.g.: ("File", "Open"))
1203 /!\ use D_() instead of _() for translations (e.g. (D_("File"), D_("Open"))) 1202 /!\ use D_() instead of _() for translations (e.g. (D_("File"), D_("Open")))