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

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)