# HG changeset patch # User Goffi # Date 1348607422 -7200 # Node ID debcf5dd404af5fc7a1a53372e0b1f50baf8cb0f # Parent e9634d2e7b38ae2f04044e1188483caf6a1ca0b3 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 diff -r e9634d2e7b38 -r debcf5dd404a frontends/src/primitivus/contact_list.py --- a/frontends/src/primitivus/contact_list.py Tue Sep 25 00:58:34 2012 +0200 +++ b/frontends/src/primitivus/contact_list.py Tue Sep 25 23:10:22 2012 +0200 @@ -32,6 +32,7 @@ self.host = host self.selected = None self.groups={} + self.special={} self.alert_jid=set() self.show_status = False self.show_disconnected = False @@ -76,9 +77,12 @@ """give focus to the first group or contact with the given name""" idx = 0 for widget in self.frame.body.body: - if widget.getValue() == name: - self.frame.body.set_focus(idx) - return + try: + if widget.getValue() == name: + self.frame.body.set_focus(idx) + return + except AttributeError: + pass idx+=1 def putAlert(self, jid): @@ -141,9 +145,32 @@ content.append(widget) urwid.connect_signal(widget, 'change', self.__contactClicked) + def __buildSpecials(self, content): + """Build the special entities""" + specials = self.special.keys() + specials.sort() + for special in specials: + jid=JID(special) + name = self.getCache(jid, 'name') + nick = self.getCache(jid, 'nick') + special_disp = ('alert' if special in self.alert_jid else 'default', nick or name or jid.node or jid.short) + display = [ " " , special_disp] + header = '(*) ' if special in self.alert_jid else '' + widget = sat_widgets.SelectableText(display, + selected = special==self.selected, + header=header) + widget.data = special + content.append(widget) + urwid.connect_signal(widget, 'change', self.__contactClicked) + def __buildList(self): """Build the main contact list widget""" content = urwid.SimpleListWalker([]) + + self.__buildSpecials(content) + if self.special: + content.append(urwid.Divider('=')) + group_keys = self.groups.keys() group_keys.sort(key = lambda x: x.lower() if x else x) for key in group_keys: @@ -178,6 +205,8 @@ def replace(self, jid, groups=None, attributes=None): """add a contact to the list if doesn't exist, else update it""" + if jid.short in self.special: + return if not groups: groups = [None] if not attributes: @@ -216,3 +245,21 @@ """add a contact to the list""" self.replace(jid,param_groups) + def setSpecial(self, special_jid, special_type): + """Set entity as a special + @param jid: jid of the entity + @param _type: special type (e.g.: "MUC") + """ + self.special[special_jid.short] = special_type + if None in self.groups: + folded,group_jids = self.groups[None] + for group_jid in group_jids: + if JID(group_jid).short == special_jid.short: + group_jids.remove(group_jid) + break + self.update() + + def updatePresence(self, jid, show, priority, statuses): + #XXX: for the moment, we ignore presence updates for special entities + if jid.short not in self.special: + QuickContactList.updatePresence(self, jid, show, priority, statuses) diff -r e9634d2e7b38 -r debcf5dd404a frontends/src/quick_frontend/quick_app.py --- a/frontends/src/quick_frontend/quick_app.py Tue Sep 25 00:58:34 2012 +0200 +++ b/frontends/src/quick_frontend/quick_app.py Tue Sep 25 23:10:22 2012 +0200 @@ -285,6 +285,7 @@ self.chat_wins[room_jid].setType("group") self.chat_wins[room_jid].id = room_jid self.chat_wins[room_jid].setPresents(list(set([user_nick]+room_nicks))) + self.contact_list.setSpecial(JID(room_jid), "MUC") def roomUserJoined(self, room_jid, user_nick, user_data, profile): diff -r e9634d2e7b38 -r debcf5dd404a frontends/src/quick_frontend/quick_contact_list.py --- a/frontends/src/quick_frontend/quick_contact_list.py Tue Sep 25 00:58:34 2012 +0200 +++ b/frontends/src/quick_frontend/quick_contact_list.py Tue Sep 25 23:10:22 2012 +0200 @@ -70,6 +70,13 @@ """add a contact to the list""" raise NotImplementedError + def setSpecial(self, jid, _type): + """Set entity as a special + @param jid: jid of the entity + @param _type: special type (e.g.: "MUC") + """ + raise NotImplementedError + def updatePresence(self, jid, show, priority, statuses): """Update entity's presence status @param jid: entity to update's jid @@ -80,3 +87,4 @@ self.setCache(jid, 'prority', priority) self.setCache(jid, 'statuses', statuses) self.update_jid(jid) + diff -r e9634d2e7b38 -r debcf5dd404a frontends/src/wix/contact_list.py --- a/frontends/src/wix/contact_list.py Tue Sep 25 00:58:34 2012 +0200 +++ b/frontends/src/wix/contact_list.py Tue Sep 25 23:10:22 2012 +0200 @@ -168,6 +168,8 @@ if _present: self.Insert(_present, gp_idx+1, contact) + def setSpecial(self, special_jid, special_type): + pass def remove(self, contact):