quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
This refactoring allow primitivus to manage correctly several profiles at once, with various other improvments:
- profile_manager can now plug several profiles at once, requesting password when needed. No more profile plug specific method is used anymore in backend, instead a "validated" key is used in actions
- Primitivus widget are now based on a common "PrimitivusWidget" classe which mainly manage the decoration so far
- all widgets are treated in the same way (contactList, Chat, Progress, etc), no more chat_wins specific behaviour
- widgets are created in a dedicated manager, with facilities to react on new widget creation or other events
- quick_frontend introduce a new QuickWidget class, which aims to be as generic and flexible as possible. It can manage several targets (jids or something else), and several profiles
- each widget class return a Hash according to its target. For example if given a target jid and a profile, a widget class return a hash like (target.bare, profile), the same widget will be used for all resources of the same jid
- better management of CHAT_GROUP mode for Chat widgets
- some code moved from Primitivus to QuickFrontend, the final goal is to have most non backend code in QuickFrontend, and just graphic code in subclasses
- no more (un)escapePrivate/PRIVATE_PREFIX
- contactList improved a lot: entities not in roster and special entities (private MUC conversations) are better managed
- resources can be displayed in Primitivus, and their status messages
- profiles are managed in QuickFrontend with dedicated managers
This is work in progress, other frontends are broken. Urwid SàText need to be updated. Most of features of Primitivus should work as before (or in a better way ;))
This commit is contained in:
parent
b9f967ea5f
commit
e4708c9cbb
2 changed files with 1583 additions and 969 deletions
|
|
@ -22,12 +22,12 @@ class JID(unicode):
|
|||
"""This class help manage JID (Node@Domaine/Resource)"""
|
||||
|
||||
def __new__(cls, jid):
|
||||
self = unicode.__new__(cls, cls.__normalize(jid))
|
||||
self.__parse()
|
||||
self = unicode.__new__(cls, cls._normalize(jid))
|
||||
self._parse()
|
||||
return self
|
||||
|
||||
@classmethod
|
||||
def __normalize(cls, jid):
|
||||
def _normalize(cls, jid):
|
||||
"""Naive normalization before instantiating and parsing the JID"""
|
||||
if not jid:
|
||||
return jid
|
||||
|
|
@ -35,21 +35,25 @@ class JID(unicode):
|
|||
tokens[0] = tokens[0].lower() # force node and domain to lower-case
|
||||
return '/'.join(tokens)
|
||||
|
||||
def __parse(self):
|
||||
@property
|
||||
def bare(self):
|
||||
if not self.node:
|
||||
return JID(self.domain)
|
||||
return JID(u"{}@{}".format(self.node, self.domain))
|
||||
|
||||
def _parse(self):
|
||||
"""Find node domain and resource"""
|
||||
node_end = self.find('@')
|
||||
if node_end < 0:
|
||||
node_end = 0
|
||||
domain_end = self.find('/')
|
||||
if domain_end < 1:
|
||||
if domain_end == 0:
|
||||
raise ValueError("a jid can't start with '/'")
|
||||
if domain_end == -1:
|
||||
domain_end = len(self)
|
||||
self.node = self[:node_end]
|
||||
self.node = self[:node_end] or None
|
||||
self.domain = self[(node_end + 1) if node_end else 0:domain_end]
|
||||
self.resource = self[domain_end + 1:]
|
||||
if not node_end:
|
||||
self.bare = self
|
||||
else:
|
||||
self.bare = self.node + '@' + self.domain
|
||||
self.resource = self[domain_end + 1:] or None
|
||||
|
||||
def is_valid(self):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ class XMLUIBase(object):
|
|||
This class must not be instancied directly
|
||||
"""
|
||||
|
||||
def __init__(self, host, parsed_dom, title = None, flags = None):
|
||||
def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE):
|
||||
"""Initialise the XMLUI instance
|
||||
|
||||
@param host: %(doc_host)s
|
||||
|
|
@ -210,15 +210,18 @@ class XMLUIBase(object):
|
|||
@param title: force the title, or use XMLUI one if None
|
||||
@param flags: list of string which can be:
|
||||
- NO_CANCEL: the UI can't be cancelled
|
||||
@param callback: if present, will be use with launchAction
|
||||
"""
|
||||
self.host = host
|
||||
top=parsed_dom.documentElement
|
||||
self.session_id = top.getAttribute("session_id") or None
|
||||
self.submit_id = top.getAttribute("submit") or None
|
||||
self.title = title or top.getAttribute("title") or u""
|
||||
self.xmlui_title = title or top.getAttribute("title") or u""
|
||||
if flags is None:
|
||||
flags = []
|
||||
self.flags = flags
|
||||
self.callback = callback
|
||||
self.profile = profile
|
||||
|
||||
def _isAttrSet(self, name, node):
|
||||
"""Returnw widget boolean attribute status
|
||||
|
|
@ -253,7 +256,7 @@ class XMLUIBase(object):
|
|||
self._xmluiLaunchAction(self.submit_id, data)
|
||||
|
||||
def _xmluiLaunchAction(self, action_id, data):
|
||||
self.host.launchAction(action_id, data, profile_key = self.host.profile)
|
||||
self.host.launchAction(action_id, data, callback=self.callback, profile=self.profile)
|
||||
|
||||
|
||||
class XMLUIPanel(XMLUIBase):
|
||||
|
|
@ -265,8 +268,8 @@ class XMLUIPanel(XMLUIBase):
|
|||
"""
|
||||
widget_factory = None
|
||||
|
||||
def __init__(self, host, parsed_dom, title = None, flags = None):
|
||||
super(XMLUIPanel, self).__init__(host, parsed_dom, title = None, flags = None)
|
||||
def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE):
|
||||
super(XMLUIPanel, self).__init__(host, parsed_dom, title=title, flags=flags, callback=callback, profile=profile)
|
||||
self.ctrl_list = {} # usefull to access ctrl
|
||||
self._main_cont = None
|
||||
self.constructUI(parsed_dom)
|
||||
|
|
@ -462,7 +465,7 @@ class XMLUIPanel(XMLUIBase):
|
|||
raise NotImplementedError
|
||||
|
||||
def _xmluiSetParam(self, name, value, category):
|
||||
self.host.bridge.setParam(name, value, category, profile_key=self.host.profile)
|
||||
self.host.bridge.setParam(name, value, category, profile=self.profile)
|
||||
|
||||
##EVENTS##
|
||||
|
||||
|
|
@ -639,8 +642,8 @@ class XMLUIPanel(XMLUIBase):
|
|||
class XMLUIDialog(XMLUIBase):
|
||||
dialog_factory = None
|
||||
|
||||
def __init__(self, host, parsed_dom, title = None, flags = None):
|
||||
super(XMLUIDialog, self).__init__(host, parsed_dom, title = None, flags = None)
|
||||
def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE):
|
||||
super(XMLUIDialog, self).__init__(host, parsed_dom, title=None, flags=None, callback=callback, profile=C.PROF_KEY_NONE)
|
||||
top=parsed_dom.documentElement
|
||||
dlg_elt = self._getChildNode(top, "dialog")
|
||||
if dlg_elt is None:
|
||||
|
|
@ -654,23 +657,23 @@ class XMLUIDialog(XMLUIBase):
|
|||
level = dlg_elt.getAttribute(C.XMLUI_DATA_LVL) or C.XMLUI_DATA_LVL_INFO
|
||||
|
||||
if dlg_type == C.XMLUI_DIALOG_MESSAGE:
|
||||
self.dlg = self.dialog_factory.createMessageDialog(self, self.title, message, level)
|
||||
self.dlg = self.dialog_factory.createMessageDialog(self, self.xmlui_title, message, level)
|
||||
elif dlg_type == C.XMLUI_DIALOG_NOTE:
|
||||
self.dlg = self.dialog_factory.createNoteDialog(self, self.title, message, level)
|
||||
self.dlg = self.dialog_factory.createNoteDialog(self, self.xmlui_title, message, level)
|
||||
elif dlg_type == C.XMLUI_DIALOG_CONFIRM:
|
||||
try:
|
||||
buttons_elt = self._getChildNode(dlg_elt, "buttons")
|
||||
buttons_set = buttons_elt.getAttribute("set") or C.XMLUI_DATA_BTNS_SET_DEFAULT
|
||||
except (TypeError, AttributeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError
|
||||
buttons_set = C.XMLUI_DATA_BTNS_SET_DEFAULT
|
||||
self.dlg = self.dialog_factory.createConfirmDialog(self, self.title, message, level, buttons_set)
|
||||
self.dlg = self.dialog_factory.createConfirmDialog(self, self.xmlui_title, message, level, buttons_set)
|
||||
elif dlg_type == C.XMLUI_DIALOG_FILE:
|
||||
try:
|
||||
file_elt = self._getChildNode(dlg_elt, "file")
|
||||
filetype = file_elt.getAttribute("type") or C.XMLUI_DATA_FILETYPE_DEFAULT
|
||||
except (TypeError, AttributeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError
|
||||
filetype = C.XMLUI_DATA_FILETYPE_DEFAULT
|
||||
self.dlg = self.dialog_factory.createFileDialog(self, self.title, message, level, filetype)
|
||||
self.dlg = self.dialog_factory.createFileDialog(self, self.xmlui_title, message, level, filetype)
|
||||
else:
|
||||
raise ValueError("Unknown dialog type [%s]" % dlg_type)
|
||||
|
||||
|
|
@ -690,7 +693,7 @@ def registerClass(type_, class_):
|
|||
class_map[type_] = class_
|
||||
|
||||
|
||||
def create(host, xml_data, title = None, flags = None, dom_parse=None, dom_free=None):
|
||||
def create(host, xml_data, title=None, flags=None, dom_parse=None, dom_free=None, callback=None, profile=C.PROF_KEY_NONE):
|
||||
"""
|
||||
@param dom_parse: methode equivalent to minidom.parseString (but which must manage unicode), or None to use default one
|
||||
@param dom_free: method used to free the parsed DOM
|
||||
|
|
@ -713,6 +716,6 @@ def create(host, xml_data, title = None, flags = None, dom_parse=None, dom_free=
|
|||
except KeyError:
|
||||
raise ClassNotRegistedError(_("You must register classes with registerClass before creating a XMLUI"))
|
||||
|
||||
xmlui = cls(host, parsed_dom, title, flags)
|
||||
xmlui = cls(host, parsed_dom, title, flags, callback, profile)
|
||||
dom_free(parsed_dom)
|
||||
return xmlui
|
||||
|
|
|
|||
Loading…
Reference in a new issue