show number of participants in groupchats. fixes #3418

This commit is contained in:
Yann Leboulanger 2008-09-02 07:00:35 +00:00
parent 2a1d6edd68
commit 66f8bab7d6
2 changed files with 48 additions and 13 deletions

View file

@ -629,4 +629,17 @@ class Contacts:
return None return None
return self._gc_contacts[account][room_jid][nick] return self._gc_contacts[account][room_jid][nick]
def get_nb_role_total_gc_contacts(self, account, room_jid, role):
'''Returns the number of group chat contacts for the given role and the
total number of group chat contacts'''
if account not in self._gc_contacts:
return 0, 0
if room_jid not in self._gc_contacts[account]:
return 0, 0
nb_role = nb_total = 0
for nick in self._gc_contacts[account][room_jid]:
if self._gc_contacts[account][room_jid][nick].role == role:
nb_role += 1
nb_total += 1
return nb_role, nb_total
# vim: se ts=3: # vim: se ts=3:

View file

@ -926,8 +926,8 @@ class GroupchatControl(ChatControlBase):
gc_contact = gajim.contacts.get_gc_contact(self.account, self.room_jid, gc_contact = gajim.contacts.get_gc_contact(self.account, self.room_jid,
nick) nick)
self.add_contact_to_roster(nick, gc_contact.show, gc_contact.role, self.add_contact_to_roster(nick, gc_contact.show, gc_contact.role,
gc_contact.affiliation, gc_contact.status, gc_contact.affiliation, gc_contact.status, gc_contact.jid)
gc_contact.jid) self.draw_all_roles()
# Recalculate column width for ellipsizin # Recalculate column width for ellipsizin
self.list_treeview.columns_autosize() self.list_treeview.columns_autosize()
@ -1005,6 +1005,22 @@ class GroupchatControl(ChatControlBase):
scaled_pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'roster') scaled_pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'roster')
model[iter][C_AVATAR] = scaled_pixbuf model[iter][C_AVATAR] = scaled_pixbuf
def draw_role(self, role):
role_iter = self.get_role_iter(role)
if not role_iter:
return
model = self.list_treeview.get_model()
role_name = helpers.get_uf_role(role, plural=True)
if gajim.config.get('show_contacts_number'):
nbr_role, nbr_total = gajim.contacts.get_nb_role_total_gc_contacts(
self.account, self.room_jid, role)
role_name += ' (%s/%s)' % (repr(nbr_role), repr(nbr_total))
model[role_iter][C_TEXT] = role_name
def draw_all_roles(self):
for role in ('visitor', 'participant', 'moderator'):
self.draw_role(role)
def chg_contact_status(self, nick, show, status, role, affiliation, jid, def chg_contact_status(self, nick, show, status, role, affiliation, jid,
reason, actor, statusCode, new_nick, avatar_sha, tim = None): reason, actor, statusCode, new_nick, avatar_sha, tim = None):
'''When an occupant changes his or her status''' '''When an occupant changes his or her status'''
@ -1092,7 +1108,8 @@ class GroupchatControl(ChatControlBase):
puny_nick = helpers.sanitize_filename(nick) puny_nick = helpers.sanitize_filename(nick)
puny_new_nick = helpers.sanitize_filename(new_nick) puny_new_nick = helpers.sanitize_filename(new_nick)
old_path = os.path.join(gajim.VCARD_PATH, puny_jid, puny_nick) old_path = os.path.join(gajim.VCARD_PATH, puny_jid, puny_nick)
new_path = os.path.join(gajim.VCARD_PATH, puny_jid, puny_new_nick) new_path = os.path.join(gajim.VCARD_PATH, puny_jid,
puny_new_nick)
files = {old_path: new_path} files = {old_path: new_path}
path = os.path.join(gajim.AVATAR_PATH, puny_jid) path = os.path.join(gajim.AVATAR_PATH, puny_jid)
# possible extensions # possible extensions
@ -1126,6 +1143,7 @@ class GroupchatControl(ChatControlBase):
if len(gajim.events.get_events(self.account, fake_jid)) == 0: if len(gajim.events.get_events(self.account, fake_jid)) == 0:
self.remove_contact(nick) self.remove_contact(nick)
self.draw_all_roles()
else: else:
c = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick) c = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick)
c.show = show c.show = show
@ -1145,6 +1163,7 @@ class GroupchatControl(ChatControlBase):
iter = self.add_contact_to_roster(nick, show, role, affiliation, iter = self.add_contact_to_roster(nick, show, role, affiliation,
status, jid) status, jid)
newly_created = True newly_created = True
self.draw_all_roles()
if statusCode and '201' in statusCode: # We just created the room if statusCode and '201' in statusCode: # We just created the room
gajim.connections[self.account].request_gc_config(self.room_jid) gajim.connections[self.account].request_gc_config(self.room_jid)
else: else:
@ -1201,6 +1220,8 @@ class GroupchatControl(ChatControlBase):
self.remove_contact(nick) self.remove_contact(nick)
self.add_contact_to_roster(nick, show, role, self.add_contact_to_roster(nick, show, role,
affiliation, status, jid) affiliation, status, jid)
self.draw_role(actual_role)
self.draw_role(role)
if actor: if actor:
st = _('** Role of %(nick)s has been set to %(role)s by ' st = _('** Role of %(nick)s has been set to %(role)s by '
'%(actor)s') % {'nick': nick_jid, 'role': role, '%(actor)s') % {'nick': nick_jid, 'role': role,
@ -1269,7 +1290,8 @@ class GroupchatControl(ChatControlBase):
if not role_iter: if not role_iter:
role_iter = model.append(None, role_iter = model.append(None,
(gajim.interface.jabber_state_images['16']['closed'], role, (gajim.interface.jabber_state_images['16']['closed'], role,
'role', '%s' % role_name, None)) 'role', role_name, None))
self.draw_all_roles()
iter = model.append(role_iter, (None, nick, 'contact', name, None)) iter = model.append(role_iter, (None, nick, 'contact', name, None))
if not nick in gajim.contacts.get_nick_list(self.account, self.room_jid): if not nick in gajim.contacts.get_nick_list(self.account, self.room_jid):
gc_contact = gajim.contacts.create_gc_contact(room_jid = self.room_jid, gc_contact = gajim.contacts.create_gc_contact(room_jid = self.room_jid,