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

@ -272,7 +272,7 @@ class Contacts:
else: else:
return [] return []
def get_contact(self, account, jid, resource = None): def get_contact(self, account, jid, resource=None):
### WARNING ### ### WARNING ###
# This function returns a *RANDOM* resource if resource = None! # This function returns a *RANDOM* resource if resource = None!
# Do *NOT* use if you need to get the contact to which you # Do *NOT* use if you need to get the contact to which you
@ -331,7 +331,7 @@ class Contacts:
group_contacts += contacts group_contacts += contacts
return group_contacts return group_contacts
def get_nb_online_total_contacts(self, accounts = [], groups = []): def get_nb_online_total_contacts(self, accounts=[], groups=[]):
'''Returns the number of online contacts and the total number of '''Returns the number of online contacts and the total number of
contacts''' contacts'''
if accounts == []: if accounts == []:
@ -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

@ -628,14 +628,14 @@ class GroupchatControl(ChatControlBase):
return self.gc_popup_menu return self.gc_popup_menu
def on_message(self, nick, msg, tim, has_timestamp = False, xhtml = None, def on_message(self, nick, msg, tim, has_timestamp=False, xhtml=None,
status_code = []): status_code=[]):
if '100' in status_code: if '100' in status_code:
# Room is not anonymous # Room is not anonymous
self.is_anonymous = False self.is_anonymous = False
if not nick: if not nick:
# message from server # message from server
self.print_conversation(msg, tim = tim, xhtml = xhtml) self.print_conversation(msg, tim=tim, xhtml=xhtml)
else: else:
# message from someone # message from someone
if has_timestamp: if has_timestamp:
@ -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,
@ -1247,12 +1268,12 @@ class GroupchatControl(ChatControlBase):
if st: if st:
if status: if status:
st += ' (' + status + ')' st += ' (' + status + ')'
self.print_conversation(st, tim = tim) self.print_conversation(st, tim=tim)
def add_contact_to_roster(self, nick, show, role, affiliation, status, def add_contact_to_roster(self, nick, show, role, affiliation, status,
jid = ''): jid=''):
model = self.list_treeview.get_model() model = self.list_treeview.get_model()
role_name = helpers.get_uf_role(role, plural = True) role_name = helpers.get_uf_role(role, plural=True)
resource = '' resource = ''
if jid: if jid:
@ -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,