Mercurial > libervia-web
comparison browser_side/contact.py @ 252:b77940d8a9bf
browser_side: isolate the basic stuff of ContactList in the new GenericContactList class
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 08 Nov 2013 17:07:27 +0100 |
parents | a25aa882e09a |
children | da0487f0a2e7 |
comparison
equal
deleted
inserted
replaced
251:24335e82fef0 | 252:b77940d8a9bf |
---|---|
95 for wid in self: | 95 for wid in self: |
96 if isinstance(wid, GroupLabel) and wid.group == group: | 96 if isinstance(wid, GroupLabel) and wid.group == group: |
97 VerticalPanel.remove(self, wid) | 97 VerticalPanel.remove(self, wid) |
98 | 98 |
99 | 99 |
100 class ContactList(VerticalPanel): | 100 class GenericContactList(VerticalPanel): |
101 """Class that can be used to represent a contact list, but not necessarily | |
102 the one that is displayed on the left side. Special features like popup menu | |
103 panel or changing the contact states must be done in a sub-class.""" | |
101 | 104 |
102 def __init__(self, host): | 105 def __init__(self, host): |
103 VerticalPanel.__init__(self) | 106 VerticalPanel.__init__(self) |
104 self.host = host | 107 self.host = host |
105 self.contacts = set() | 108 self.contacts = set() |
106 self.menu_entries = {"blog": {"title": "Public blog..."}} | 109 |
107 self.context_menu = PopupMenuPanel(entries=self.menu_entries, | 110 def add(self, jid, name=None, item_cb=None): |
108 hide=self.contextMenuHide, | |
109 callback=self.contextMenuCallback, | |
110 vertical=False, menu_style="menu") | |
111 | |
112 def contextMenuHide(self, sender, key): | |
113 """Return True if the item for that sender should be hidden.""" | |
114 # TODO: enable the blogs of users that are on another server | |
115 return JID(sender.jid).domain != self.host._defaultDomain | |
116 | |
117 def contextMenuCallback(self, sender, key): | |
118 if key == "blog": | |
119 # TODO: use the bare when all blogs can be retrieved | |
120 node = JID(sender.jid).node | |
121 web_panel = WebPanel(self.host, "blog/%s" % node) | |
122 self.host.addTab(web_panel, "%s's blog" % node) | |
123 else: | |
124 sender.onClick(sender) | |
125 | |
126 def add(self, jid, name=None): | |
127 if jid in self.contacts: | 111 if jid in self.contacts: |
128 return | 112 return |
129 self.contacts.add(jid) | 113 self.contacts.add(jid) |
130 _item = ContactLabel(self.host, jid, name) | 114 _item = ContactLabel(self.host, jid, name) |
131 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") | 115 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") |
132 VerticalPanel.add(self, _item) | 116 VerticalPanel.add(self, _item) |
133 self.context_menu.registerRightClickSender(_item) | 117 if item_cb is not None: |
118 item_cb(_item) | |
134 | 119 |
135 def remove(self, jid): | 120 def remove(self, jid): |
136 wid = self.getContactLabel(jid) | 121 wid = self.getContactLabel(jid) |
137 if not wid: | 122 if not wid: |
138 return | 123 return |
152 for wid in self: | 137 for wid in self: |
153 if isinstance(wid, ContactLabel) and wid.jid == contact_jid: | 138 if isinstance(wid, ContactLabel) and wid.jid == contact_jid: |
154 return wid | 139 return wid |
155 return None | 140 return None |
156 | 141 |
157 def setState(self, jid, type, state): | 142 |
143 class ContactList(GenericContactList): | |
144 """The contact list that is displayed on the left side.""" | |
145 | |
146 def __init__(self, host): | |
147 GenericContactList.__init__(self, host) | |
148 self.menu_entries = {"blog": {"title": "Public blog..."}} | |
149 self.context_menu = PopupMenuPanel(entries=self.menu_entries, | |
150 hide=self.contextMenuHide, | |
151 callback=self.contextMenuCallback, | |
152 vertical=False, menu_style="menu") | |
153 | |
154 def contextMenuHide(self, sender, key): | |
155 """Return True if the item for that sender should be hidden.""" | |
156 # TODO: enable the blogs of users that are on another server | |
157 return JID(sender.jid).domain != self.host._defaultDomain | |
158 | |
159 def contextMenuCallback(self, sender, key): | |
160 if key == "blog": | |
161 # TODO: use the bare when all blogs can be retrieved | |
162 node = JID(sender.jid).node | |
163 web_panel = WebPanel(self.host, "/blog/%s" % node) | |
164 self.host.addTab(web_panel, "%s's blog" % node) | |
165 else: | |
166 sender.onClick(sender) | |
167 | |
168 def add(self, jid, name=None): | |
169 def item_cb(item): | |
170 self.context_menu.registerRightClickSender(item) | |
171 GenericContactList.add(self, jid, name, item_cb) | |
172 | |
173 def setState(self, jid, type_, state): | |
158 """Change the appearance of the contact, according to the state | 174 """Change the appearance of the contact, according to the state |
159 @param jid: jid which need to change state | 175 @param jid: jid which need to change state |
160 @param type: one of availability, messageWaiting | 176 @param type_: one of availability, messageWaiting |
161 @param state: | 177 @param state: |
162 - for messageWaiting type: | 178 - for messageWaiting type: |
163 True if message are waiting | 179 True if message are waiting |
164 - for availability type: | 180 - for availability type: |
165 'unavailable' if not connected, else presence like RFC6121 #4.7.2.1""" | 181 'unavailable' if not connected, else presence like RFC6121 #4.7.2.1""" |
166 _item = self.getContactLabel(jid) | 182 _item = self.getContactLabel(jid) |
167 if _item: | 183 if _item: |
168 if type == 'availability': | 184 if type_ == 'availability': |
169 if state == 'unavailable': | 185 if state == 'unavailable': |
170 _item.removeStyleName('contactConnected') | 186 _item.removeStyleName('contactConnected') |
171 else: | 187 else: |
172 _item.addStyleName('contactConnected') | 188 _item.addStyleName('contactConnected') |
173 elif type == 'messageWaiting': | 189 elif type_ == 'messageWaiting': |
174 _item.setMessageWaiting(state) | 190 _item.setMessageWaiting(state) |
175 | 191 |
176 | 192 |
177 class ContactTitleLabel(DragLabel, Label, ClickHandler): | 193 class ContactTitleLabel(DragLabel, Label, ClickHandler): |
178 def __init__(self, host, text): | 194 def __init__(self, host, text): |