Logo Search packages:      
Sourcecode: gajim version File versions  Download package

def roster_window::RosterWindow::add_contact_to_roster (   self,
  jid,
  account 
)

Add a contact to the roster and add groups if they aren't in roster
force is about	force to add it, even if it is offline and show offline
is False, because it has online children, so we need to show it.
If add_children is True, we also add all children, even if they were not
already drawn

Definition at line 201 of file roster_window.py.

00201                                                    :
            '''Add a contact to the roster and add groups if they aren't in roster
            force is about    force to add it, even if it is offline and show offline
            is False, because it has online children, so we need to show it.
            If add_children is True, we also add all children, even if they were not
            already drawn'''
            showOffline = gajim.config.get('showoffline')
            model = self.tree.get_model()
            contact = gajim.contacts.get_first_contact_from_jid(account, jid)
            if not contact:
                  return
            # If contact already in roster, do not add it
            if len(self.get_contact_iter(jid, account)):
                  return
            if gajim.jid_is_transport(contact.jid):
                  contact.groups = [_('Transports')]

            # JEP-0162
            hide = True
            if contact.sub in ('both', 'to'):
                  hide = False
            elif contact.ask == 'subscribe':
                  hide = False
            elif contact.name or len(contact.groups):
                  hide = False

            observer = False
            if hide:
                  if contact.sub == 'from':
                        observer = True
                  else:
                        return

            if observer:
                  # if he has a tag, remove it
                  tag = gajim.contacts.get_metacontacts_tag(account, jid)
                  if tag:
                        gajim.contacts.remove_metacontact(account, jid)

            # family is [{'account': acct, 'jid': jid, 'priority': prio}, ]
            # 'priority' is optional
            family = gajim.contacts.get_metacontacts_family(account, jid)

            shown_family = [] # family members that are in roster.
            if family:
                  for data in family:
                        _jid = data['jid']
                        _account = data['account']
                        if self.get_contact_iter(_jid, _account):
                              shown_family.append(data)
                        if _jid == jid:
                              our_data = data
                  shown_family.append(our_data)
                  big_brother_data = gajim.contacts.get_metacontacts_big_brother(
                        shown_family)
                  big_brother_jid = big_brother_data['jid']
                  big_brother_account = big_brother_data['account']
                  if big_brother_jid != jid:
                        # We are adding a child contact
                        if contact.show in ('offline', 'error') and \
                        not showOffline and not gajim.awaiting_events[account].has_key(jid):
                              return
                        parent_iters = self.get_contact_iter(big_brother_jid,
                              big_brother_account)
                        name = contact.get_shown_name()
                        for i in parent_iters:
                              # we add some values here. see draw_contact for more
                              model.append(i, (None, name, 'contact', jid, account,
                                    False, None))
                        self.draw_contact(jid, account)
                        self.draw_avatar(jid, account)
                        # Redraw parent to change icon
                        self.draw_contact(big_brother_jid, big_brother_account)
                        return

            if (contact.show in ('offline', 'error') or hide) and \
                  not showOffline and (not _('Transports') in contact.groups or \
                  gajim.connections[account].connected < 2) and \
                  not gajim.awaiting_events[account].has_key(jid):
                  return

            # Remove brother contacts that are already in roster to add them
            # under this iter
            for data in shown_family:
                  contacts = gajim.contacts.get_contact(data['account'],
                        data['jid'])
                  for c in contacts:
                        self.remove_contact(c, data['account'])
            groups = contact.groups
            if observer:
                  groups = [_('Observers')]
            elif not groups:
                  groups = [_('General')]
            for g in groups:
                  iterG = self.get_group_iter(g, account)
                  if not iterG:
                        IterAcct = self.get_account_iter(account)
                        iterG = model.append(IterAcct, [
                              self.jabber_state_images['16']['closed'],
                              gtkgui_helpers.escape_for_pango_markup(g), 'group', g, account,
                              False, None])
                  if not gajim.groups[account].has_key(g): # It can probably never append
                        if account + g in self.collapsed_rows:
                              ishidden = False
                        else:
                              ishidden = True
                        gajim.groups[account][g] = { 'expand': ishidden }
                  if not account in self.collapsed_rows:
                        self.tree.expand_row((model.get_path(iterG)[0]), False)

                  typestr = 'contact'
                  if g == _('Transports'):
                        typestr = 'agent'

                  name = contact.get_shown_name()
                  # we add some values here. see draw_contact for more
                  model.append(iterG, (None, name, typestr, contact.jid, account,
                        False, None))

                  if gajim.groups[account][g]['expand']:
                        self.tree.expand_row(model.get_path(iterG), False)
            self.draw_contact(jid, account)
            self.draw_avatar(jid, account)
            # put the children under this iter
            for data in shown_family:
                  contacts = gajim.contacts.get_contact(data['account'],
                        data['jid'])
                  self.add_contact_to_roster(data['jid'], data['account'])

      def add_transport_to_roster(self, account, transport):


Generated by  Doxygen 1.6.0   Back to index