Mercurial > libervia-backend
comparison frontends/src/primitivus/contact_list.py @ 1230:3abc6563a0d2
primitivus: implement parameter "Show empty groups"
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 06 Oct 2014 13:54:41 +0200 |
parents | 03661d1b216a |
children | 93a5e2673929 |
comparison
equal
deleted
inserted
replaced
1229:03661d1b216a | 1230:3abc6563a0d2 |
---|---|
39 self.selected = None | 39 self.selected = None |
40 self.groups={} | 40 self.groups={} |
41 self.alert_jid=set() | 41 self.alert_jid=set() |
42 self.show_status = False | 42 self.show_status = False |
43 self.show_disconnected = False | 43 self.show_disconnected = False |
44 self.show_empty_groups = True | |
45 # TODO: this may lead to two successive UI refresh and needs an optimization | |
46 self.host.bridge.asyncGetParamA(C.SHOW_EMPTY_GROUPS, "General", profile_key=host.profile, callback=self.showEmptyGroups) | |
44 self.host.bridge.asyncGetParamA(C.SHOW_OFFLINE_CONTACTS, "General", profile_key=host.profile, callback=self.showOfflineContacts) | 47 self.host.bridge.asyncGetParamA(C.SHOW_OFFLINE_CONTACTS, "General", profile_key=host.profile, callback=self.showOfflineContacts) |
45 | 48 |
46 #we now build the widget | 49 #we now build the widget |
47 self.host.status_bar = StatusBar(host) | 50 self.host.status_bar = StatusBar(host) |
48 self.frame = sat_widgets.FocusFrame(self.__buildList(), None, self.host.status_bar) | 51 self.frame = sat_widgets.FocusFrame(self.__buildList(), None, self.host.status_bar) |
139 self.alert_jid.remove(self.selected) | 142 self.alert_jid.remove(self.selected) |
140 self.host.modeHint('INSERTION') | 143 self.host.modeHint('INSERTION') |
141 self.update() | 144 self.update() |
142 self._emit('click') | 145 self._emit('click') |
143 | 146 |
144 def __buildContact(self, content, param_contacts): | 147 def __buildContact(self, content, contacts): |
145 """Add contact representation in widget list | 148 """Add contact representation in widget list |
146 @param content: widget list, e.g. SimpleListWalker | 149 @param content: widget list, e.g. SimpleListWalker |
147 @param contacts: list of JID""" | 150 @param contacts (list): list of JID userhosts""" |
148 contacts = list(param_contacts) | 151 if not contacts: |
149 | 152 return |
150 widgets = [] #list of built widgets | 153 widgets = [] # list of built widgets |
151 | 154 |
152 for contact in contacts: | 155 for contact in contacts: |
153 if contact.startswith(C.PRIVATE_PREFIX): | 156 if contact.startswith(C.PRIVATE_PREFIX): |
154 contact_disp = ('alert' if contact in self.alert_jid else "show_normal", unescapePrivate(contact)) | 157 contact_disp = ('alert' if contact in self.alert_jid else "show_normal", unescapePrivate(contact)) |
155 show_icon = '' | 158 show_icon = '' |
156 status = '' | 159 status = '' |
157 else: | 160 else: |
158 jid=JID(contact) | 161 jid = JID(contact) |
159 name = self.getCache(jid, 'name') | 162 name = self.getCache(jid, 'name') |
160 nick = self.getCache(jid, 'nick') | 163 nick = self.getCache(jid, 'nick') |
161 status = self.getCache(jid, 'status') | 164 status = self.getCache(jid, 'status') |
162 show = self.getCache(jid, 'show') | 165 show = self.getCache(jid, 'show') |
163 if show == None: | 166 if show is None: |
164 show = "unavailable" | 167 show = "unavailable" |
165 if (not self.show_disconnected and show == "unavailable" | 168 if not self.contactToShow(contact): |
166 and not contact in self.alert_jid and contact != self.selected): | |
167 continue | 169 continue |
168 show_icon, show_attr = C.PRESENCE.get(show, ('', 'default')) | 170 show_icon, show_attr = C.PRESENCE.get(show, ('', 'default')) |
169 contact_disp = ('alert' if contact in self.alert_jid else show_attr, nick or name or jid.node or jid.bare) | 171 contact_disp = ('alert' if contact in self.alert_jid else show_attr, nick or name or jid.node or jid.bare) |
170 display = [ show_icon + " " , contact_disp] | 172 display = [show_icon + " ", contact_disp] |
171 if self.show_status: | 173 if self.show_status: |
172 status_disp = ('status',"\n " + status) if status else "" | 174 status_disp = ('status', "\n " + status) if status else "" |
173 display.append(status_disp) | 175 display.append(status_disp) |
174 header = '(*) ' if contact in self.alert_jid else '' | 176 header = '(*) ' if contact in self.alert_jid else '' |
175 widget = sat_widgets.SelectableText(display, | 177 widget = sat_widgets.SelectableText(display, |
176 selected = contact==self.selected, | 178 selected=contact == self.selected, |
177 header=header) | 179 header=header) |
178 widget.data = contact | 180 widget.data = contact |
179 widget.comp = contact_disp[1].lower() #value to use for sorting | 181 widget.comp = contact_disp[1].lower() # value to use for sorting |
180 widgets.append(widget) | 182 widgets.append(widget) |
181 | 183 |
182 widgets.sort(key=lambda widget: widget.comp) | 184 widgets.sort(key=lambda widget: widget.comp) |
183 | 185 |
184 for widget in widgets: | 186 for widget in widgets: |
210 self.__buildSpecials(content) | 212 self.__buildSpecials(content) |
211 if self.specials: | 213 if self.specials: |
212 content.append(urwid.Divider('=')) | 214 content.append(urwid.Divider('=')) |
213 | 215 |
214 group_keys = self.groups.keys() | 216 group_keys = self.groups.keys() |
215 group_keys.sort(key = lambda x: x.lower() if x else x) | 217 group_keys.sort(key=lambda x: x.lower() if x else x) |
216 for key in group_keys: | 218 for key in group_keys: |
217 unfolded = self.groups[key][0] | 219 unfolded = self.groups[key][0] |
218 if key!=None: | 220 contacts = list(self.groups[key][1]) |
221 if key is not None and (self.nonEmptyGroup(contacts) or self.show_empty_groups): | |
219 header = '[-]' if unfolded else '[+]' | 222 header = '[-]' if unfolded else '[+]' |
220 widget = sat_widgets.ClickableText(key,header=header+' ') | 223 widget = sat_widgets.ClickableText(key, header=header + ' ') |
221 content.append(widget) | 224 content.append(widget) |
222 urwid.connect_signal(widget, 'click', self.__groupClicked) | 225 urwid.connect_signal(widget, 'click', self.__groupClicked) |
223 if unfolded: | 226 if unfolded: |
224 self.__buildContact(content, self.groups[key][1]) | 227 self.__buildContact(content, contacts) |
225 return urwid.ListBox(content) | 228 return urwid.ListBox(content) |
229 | |
230 def contactToShow(self, contact): | |
231 """Tell if the contact should be showed or hidden. | |
232 | |
233 @param contact (str): JID userhost of the contact | |
234 @return: True if that contact should be showed in the list""" | |
235 return self.getCache(JID(contact), 'show') != "unavailable" or self.show_disconnected or contact in self.alert_jid or contact == self.selected | |
236 | |
237 def nonEmptyGroup(self, contacts): | |
238 """Tell if a contact group contains some contacts to show. | |
239 | |
240 @param contacts (list[str]): list of JID userhosts | |
241 @return: bool | |
242 """ | |
243 for contact in contacts: | |
244 if self.contactToShow(contact): | |
245 return True | |
246 return False | |
226 | 247 |
227 def unselectAll(self): | 248 def unselectAll(self): |
228 """Unselect all contacts""" | 249 """Unselect all contacts""" |
229 self.selected = None | 250 self.selected = None |
230 for widget in self.frame.body.body: | 251 for widget in self.frame.body.body: |
324 show = C.bool(show) | 345 show = C.bool(show) |
325 if self.show_disconnected == show: | 346 if self.show_disconnected == show: |
326 return | 347 return |
327 self.show_disconnected = show | 348 self.show_disconnected = show |
328 self.update() | 349 self.update() |
350 | |
351 def showEmptyGroups(self, show): | |
352 show = C.bool(show) | |
353 if self.show_empty_groups == show: | |
354 return | |
355 self.show_empty_groups = show | |
356 self.update() |