Mercurial > libervia-backend
comparison frontends/src/primitivus/contact_list.py @ 502:debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
- MUC rooms are special entities
- Primitivus: special entities are shown at the top of the contacts list above a divider,
presence updates are temporary ignored for them
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 25 Sep 2012 23:10:22 +0200 |
parents | e9634d2e7b38 |
children | f98bef71a918 |
comparison
equal
deleted
inserted
replaced
501:e9634d2e7b38 | 502:debcf5dd404a |
---|---|
30 | 30 |
31 def __init__(self, host, on_click=None, on_change=None, user_data=None): | 31 def __init__(self, host, on_click=None, on_change=None, user_data=None): |
32 self.host = host | 32 self.host = host |
33 self.selected = None | 33 self.selected = None |
34 self.groups={} | 34 self.groups={} |
35 self.special={} | |
35 self.alert_jid=set() | 36 self.alert_jid=set() |
36 self.show_status = False | 37 self.show_status = False |
37 self.show_disconnected = False | 38 self.show_disconnected = False |
38 | 39 |
39 #we now build the widget | 40 #we now build the widget |
74 | 75 |
75 def setFocus(self, name): | 76 def setFocus(self, name): |
76 """give focus to the first group or contact with the given name""" | 77 """give focus to the first group or contact with the given name""" |
77 idx = 0 | 78 idx = 0 |
78 for widget in self.frame.body.body: | 79 for widget in self.frame.body.body: |
79 if widget.getValue() == name: | 80 try: |
80 self.frame.body.set_focus(idx) | 81 if widget.getValue() == name: |
81 return | 82 self.frame.body.set_focus(idx) |
83 return | |
84 except AttributeError: | |
85 pass | |
82 idx+=1 | 86 idx+=1 |
83 | 87 |
84 def putAlert(self, jid): | 88 def putAlert(self, jid): |
85 """Put an alert on the jid to get attention from user (e.g. for new message)""" | 89 """Put an alert on the jid to get attention from user (e.g. for new message)""" |
86 self.alert_jid.add(jid.short) | 90 self.alert_jid.add(jid.short) |
139 | 143 |
140 for widget in widgets: | 144 for widget in widgets: |
141 content.append(widget) | 145 content.append(widget) |
142 urwid.connect_signal(widget, 'change', self.__contactClicked) | 146 urwid.connect_signal(widget, 'change', self.__contactClicked) |
143 | 147 |
148 def __buildSpecials(self, content): | |
149 """Build the special entities""" | |
150 specials = self.special.keys() | |
151 specials.sort() | |
152 for special in specials: | |
153 jid=JID(special) | |
154 name = self.getCache(jid, 'name') | |
155 nick = self.getCache(jid, 'nick') | |
156 special_disp = ('alert' if special in self.alert_jid else 'default', nick or name or jid.node or jid.short) | |
157 display = [ " " , special_disp] | |
158 header = '(*) ' if special in self.alert_jid else '' | |
159 widget = sat_widgets.SelectableText(display, | |
160 selected = special==self.selected, | |
161 header=header) | |
162 widget.data = special | |
163 content.append(widget) | |
164 urwid.connect_signal(widget, 'change', self.__contactClicked) | |
165 | |
144 def __buildList(self): | 166 def __buildList(self): |
145 """Build the main contact list widget""" | 167 """Build the main contact list widget""" |
146 content = urwid.SimpleListWalker([]) | 168 content = urwid.SimpleListWalker([]) |
169 | |
170 self.__buildSpecials(content) | |
171 if self.special: | |
172 content.append(urwid.Divider('=')) | |
173 | |
147 group_keys = self.groups.keys() | 174 group_keys = self.groups.keys() |
148 group_keys.sort(key = lambda x: x.lower() if x else x) | 175 group_keys.sort(key = lambda x: x.lower() if x else x) |
149 for key in group_keys: | 176 for key in group_keys: |
150 unfolded = self.groups[key][0] | 177 unfolded = self.groups[key][0] |
151 if key!=None: | 178 if key!=None: |
176 self.unselectAll() | 203 self.unselectAll() |
177 self.update() | 204 self.update() |
178 | 205 |
179 def replace(self, jid, groups=None, attributes=None): | 206 def replace(self, jid, groups=None, attributes=None): |
180 """add a contact to the list if doesn't exist, else update it""" | 207 """add a contact to the list if doesn't exist, else update it""" |
208 if jid.short in self.special: | |
209 return | |
181 if not groups: | 210 if not groups: |
182 groups = [None] | 211 groups = [None] |
183 if not attributes: | 212 if not attributes: |
184 attributes={} | 213 attributes={} |
185 assert isinstance(groups, list) | 214 assert isinstance(groups, list) |
214 | 243 |
215 def add(self, jid, param_groups=[None]): | 244 def add(self, jid, param_groups=[None]): |
216 """add a contact to the list""" | 245 """add a contact to the list""" |
217 self.replace(jid,param_groups) | 246 self.replace(jid,param_groups) |
218 | 247 |
248 def setSpecial(self, special_jid, special_type): | |
249 """Set entity as a special | |
250 @param jid: jid of the entity | |
251 @param _type: special type (e.g.: "MUC") | |
252 """ | |
253 self.special[special_jid.short] = special_type | |
254 if None in self.groups: | |
255 folded,group_jids = self.groups[None] | |
256 for group_jid in group_jids: | |
257 if JID(group_jid).short == special_jid.short: | |
258 group_jids.remove(group_jid) | |
259 break | |
260 self.update() | |
261 | |
262 def updatePresence(self, jid, show, priority, statuses): | |
263 #XXX: for the moment, we ignore presence updates for special entities | |
264 if jid.short not in self.special: | |
265 QuickContactList.updatePresence(self, jid, show, priority, statuses) |