core (menus): improvments:

- use the new convention for bridge names (getMenus ==> menusGet, etc.)
    - menu now use canonical path, which is the untranslated path with each element stripped and lowercase, it must be unique by menu type
    - added menuLaunch method to manually launch a menu like an action, canonical path is used instead of id
    - added SECURITY_LIMIT_MAX constant
This commit is contained in:
Goffi 2017-01-26 20:29:48 +01:00
commit d8b9c85cc0
3 changed files with 164 additions and 65 deletions

View file

@ -338,34 +338,6 @@ class Bridge(BridgeFrontend):
kwargs['error_handler'] = error_handler
return unicode(self.db_core_iface.getMainResource(contact_jid, profile_key, **kwargs))
def getMenuHelp(self, menu_id, language, callback=None, errback=None):
if callback is None:
error_handler = None
else:
if errback is None:
errback = log.error
error_handler = lambda err:errback(dbus_to_bridge_exception(err))
kwargs={}
if callback is not None:
kwargs['timeout'] = const_TIMEOUT
kwargs['reply_handler'] = callback
kwargs['error_handler'] = error_handler
return unicode(self.db_core_iface.getMenuHelp(menu_id, language, **kwargs))
def getMenus(self, language, security_limit, callback=None, errback=None):
if callback is None:
error_handler = None
else:
if errback is None:
errback = log.error
error_handler = lambda err:errback(dbus_to_bridge_exception(err))
kwargs={}
if callback is not None:
kwargs['timeout'] = const_TIMEOUT
kwargs['reply_handler'] = callback
kwargs['error_handler'] = error_handler
return self.db_core_iface.getMenus(language, security_limit, **kwargs)
def getParamA(self, name, category, attribute="value", profile_key="@DEFAULT@", callback=None, errback=None):
if callback is None:
error_handler = None
@ -528,6 +500,43 @@ class Bridge(BridgeFrontend):
kwargs['error_handler'] = error_handler
return self.db_core_iface.loadParamsTemplate(filename, **kwargs)
def menuHelpGet(self, menu_id, language, callback=None, errback=None):
if callback is None:
error_handler = None
else:
if errback is None:
errback = log.error
error_handler = lambda err:errback(dbus_to_bridge_exception(err))
kwargs={}
if callback is not None:
kwargs['timeout'] = const_TIMEOUT
kwargs['reply_handler'] = callback
kwargs['error_handler'] = error_handler
return unicode(self.db_core_iface.menuHelpGet(menu_id, language, **kwargs))
def menuLaunch(self, menu_type, path, data, security_limit, profile_key, callback=None, errback=None):
if callback is None:
error_handler = None
else:
if errback is None:
errback = log.error
error_handler = lambda err:errback(dbus_to_bridge_exception(err))
return self.db_core_iface.menuLaunch(menu_type, path, data, security_limit, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
def menusGet(self, language, security_limit, callback=None, errback=None):
if callback is None:
error_handler = None
else:
if errback is None:
errback = log.error
error_handler = lambda err:errback(dbus_to_bridge_exception(err))
kwargs={}
if callback is not None:
kwargs['timeout'] = const_TIMEOUT
kwargs['reply_handler'] = callback
kwargs['error_handler'] = error_handler
return self.db_core_iface.menusGet(language, security_limit, **kwargs)
def messageSend(self, to_jid, message, subject={}, mess_type="auto", extra={}, profile_key="@NONE@", callback=None, errback=None):
if callback is None:
error_handler = None

View file

@ -514,7 +514,7 @@ class PrimitivusApp(QuickApp, InputHistory):
"""
def add_menu_cb(callback_id):
self.launchAction(callback_id, menu_data, profile=self.current_profile)
for id_, type_, path, path_i18n, extra in self.bridge.getMenus("", C.NO_SECURITY_LIMIT ): # TODO: manage extra
for id_, type_, path, path_i18n, extra in self.bridge.menusGet("", C.NO_SECURITY_LIMIT ): # TODO: manage extra
if type_ != type_filter:
continue
if len(path) != 2:

View file

@ -857,8 +857,15 @@ class QuickApp(object):
if action_data:
raise exceptions.DataError(u"Not all keys in action_data are managed ({keys})".format(keys=', '.join(action_data.keys())))
def _actionCb(self, data, callback, callback_id, profile):
if callback is None:
self.actionManager(data, profile=profile)
else:
callback(data=data, cb_id=callback_id, profile=profile)
def launchAction(self, callback_id, data=None, callback=None, profile=C.PROF_KEY_NONE):
""" Launch a dynamic action
"""Launch a dynamic action
@param callback_id: id of the action to launch
@param data: data needed only for certain actions
@ -873,16 +880,29 @@ class QuickApp(object):
"""
if data is None:
data = dict()
def action_cb(data):
if callback is None:
self.actionManager(data, profile=profile)
else:
callback(data=data, cb_id=callback_id, profile=profile)
action_cb = lambda data: self._actionCb(data, callback, callback_id, profile)
self.bridge.launchAction(callback_id, data, profile, callback=action_cb, errback=self.dialogFailure)
def launchMenu(self, menu_type, path, data=None, callback=None, security_limit=C.SECURITY_LIMIT_MAX, profile=C.PROF_KEY_NONE):
"""Launch a menu manually
@param menu_type(unicode): type of the menu to launch
@param path(iterable[unicode]): path to the menu
@param data: data needed only for certain actions
@param callback(callable, None): will be called with the resut
if None, self.actionManager will be called
else the callable will be called with the following kw parameters:
- data: action_data
- cb_id: (menu_type, path) tuple
- profile: %(doc_profile)s
@param profile: %(doc_profile)s
"""
if data is None:
data = dict()
action_cb = lambda data: self._actionCb(data, callback, (menu_type, path), profile)
self.bridge.menuLaunch(menu_type, path, data, security_limit, profile, callback=action_cb, errback=self.dialogFailure)
def _avatarGetCb(self, avatar_path, entity, contact_list, profile):
path = avatar_path or self.getDefaultAvatar(entity)
contact_list.setCache(entity, "avatar", path)