Exemplo n.º 1
0
 def get_and_set(self, jid):
     contact = self.contacts.get(jid)
     if contact is None:
         contact = Contact(self.__node[jid])
         self.contacts[jid] = contact
         return contact
     return contact
Exemplo n.º 2
0
 def __getitem__(self, key):
     """Get a Contact from his bare JID"""
     key = safeJID(key).bare
     if key in self.contacts and self.contacts[key] is not None:
         return self.contacts[key]
     if key in self.jids():
         contact = Contact(self.__node[key])
         self.contacts[key] = contact
         return contact
Exemplo n.º 3
0
    def draw_contact_info(self, contact: Contact) -> None:
        """
        draw the contact information
        """
        resource = contact.get_highest_priority_resource()
        if contact:
            jid = str(contact.bare_jid)
        elif resource:
            jid = str(resource.jid)
        else:
            jid = '*****@*****.**'  # should never happen
        if resource:
            presence = resource.presence
        else:
            presence = 'unavailable'
        i = 0
        self.addstr(0, 0, '%s (%s)' % (
            jid,
            presence,
        ), to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
        self.finish_line(get_theme().COLOR_INFORMATION_BAR)
        i += 1
        self.addstr(i, 0, 'Subscription: %s' % (contact.subscription, ))
        self.finish_line()
        i += 1
        if contact.ask:
            if contact.ask == 'asked':
                self.addstr(i, 0, 'Ask: %s' % (contact.ask, ),
                            to_curses_attr(get_theme().COLOR_IMPORTANT_TEXT))
            else:
                self.addstr(i, 0, 'Ask: %s' % (contact.ask, ))
            self.finish_line()
            i += 1
        if resource:
            self.addstr(i, 0, 'Status: %s' % (resource.status))
            self.finish_line()
            i += 1

        if contact.error:
            self.addstr(i, 0, 'Error: %s' % contact.error,
                        to_curses_attr(get_theme().COLOR_ROSTER_ERROR))
            self.finish_line()
            i += 1

        if contact.tune:
            self.addstr(i, 0,
                        'Tune: %s' % common.format_tune_string(contact.tune),
                        to_curses_attr(get_theme().COLOR_NORMAL_TEXT))
            self.finish_line()
            i += 1

        if contact.mood:
            self.addstr(i, 0, 'Mood: %s' % contact.mood,
                        to_curses_attr(get_theme().COLOR_NORMAL_TEXT))
            self.finish_line()
            i += 1

        if contact.activity:
            self.addstr(i, 0, 'Activity: %s' % contact.activity,
                        to_curses_attr(get_theme().COLOR_NORMAL_TEXT))
            self.finish_line()
            i += 1

        if contact.gaming:
            self.addstr(
                i, 0, 'Game: %s' % common.format_gaming_string(contact.gaming),
                to_curses_attr(get_theme().COLOR_NORMAL_TEXT))
            self.finish_line()
            i += 1
Exemplo n.º 4
0
    def draw_contact_line(self,
                          y: int,
                          contact: Contact,
                          colored: bool,
                          group: str,
                          show_roster_sub: Optional[str] = None,
                          show_s2s_errors: bool = True,
                          show_roster_jids: bool = False) -> None:
        """
        Draw on a line all information about one contact.
        This is basically the highest priority resource's information
        Use 'color' to draw the jid/display_name to show what is
        the currently selected contact in the list
        """

        theme = get_theme()
        resource = contact.get_highest_priority_resource()
        if not resource:
            # There's no online resource
            presence = 'unavailable'
            nb = ''
        else:
            presence = resource.presence
            nb = ' (%s)' % len(contact)
        color = theme.color_show(presence)
        added = 2 + len(theme.CHAR_STATUS) + len(nb)

        self.addstr(y, 0, ' ')
        self.addstr(theme.CHAR_STATUS, to_curses_attr(color))

        self.addstr(' ')
        if resource:
            self.addstr('[+] ' if contact.folded(group) else '[-] ')
        else:
            self.addstr('    ')
        added += 4

        if contact.ask:
            added += len(get_theme().CHAR_ROSTER_ASKED)
        if show_s2s_errors and contact.error:
            added += len(get_theme().CHAR_ROSTER_ERROR)
        if contact.tune:
            added += len(get_theme().CHAR_ROSTER_TUNE)
        if contact.mood:
            added += len(get_theme().CHAR_ROSTER_MOOD)
        if contact.activity:
            added += len(get_theme().CHAR_ROSTER_ACTIVITY)
        if contact.gaming:
            added += len(get_theme().CHAR_ROSTER_GAMING)
        if show_roster_sub in ('all', 'incomplete', 'to', 'from', 'both',
                               'none'):
            added += len(
                theme.char_subscription(contact.subscription,
                                        keep=show_roster_sub))

        if not show_roster_jids and contact.name:
            display_name = contact.name
        elif contact.name and contact.name != contact.bare_jid:
            display_name = '%s (%s)' % (contact.name, contact.bare_jid)
        else:
            display_name = contact.bare_jid

        display_name = self.truncate_name(display_name, added) + nb

        if colored:
            self.addstr(display_name,
                        to_curses_attr(get_theme().COLOR_SELECTED_ROW))
        else:
            self.addstr(display_name)

        if show_roster_sub in ('all', 'incomplete', 'to', 'from', 'both',
                               'none'):
            self.addstr(
                theme.char_subscription(contact.subscription,
                                        keep=show_roster_sub),
                to_curses_attr(theme.COLOR_ROSTER_SUBSCRIPTION))
        if contact.ask:
            self.addstr(get_theme().CHAR_ROSTER_ASKED,
                        to_curses_attr(get_theme().COLOR_IMPORTANT_TEXT))
        if show_s2s_errors and contact.error:
            self.addstr(get_theme().CHAR_ROSTER_ERROR,
                        to_curses_attr(get_theme().COLOR_ROSTER_ERROR))
        if contact.tune:
            self.addstr(get_theme().CHAR_ROSTER_TUNE,
                        to_curses_attr(get_theme().COLOR_ROSTER_TUNE))
        if contact.activity:
            self.addstr(get_theme().CHAR_ROSTER_ACTIVITY,
                        to_curses_attr(get_theme().COLOR_ROSTER_ACTIVITY))
        if contact.mood:
            self.addstr(get_theme().CHAR_ROSTER_MOOD,
                        to_curses_attr(get_theme().COLOR_ROSTER_MOOD))
        if contact.gaming:
            self.addstr(get_theme().CHAR_ROSTER_GAMING,
                        to_curses_attr(get_theme().COLOR_ROSTER_GAMING))
        self.finish_line()
Exemplo n.º 5
0
    def draw_contact_info(self, contact: Contact) -> None:
        """
        draw the contact information
        """
        resource = contact.get_highest_priority_resource()
        if contact:
            jid = str(contact.bare_jid)
        elif resource:
            jid = str(resource.jid)
        else:
            jid = '*****@*****.**'  # should never happen
        if resource:
            presence = resource.presence
        else:
            presence = 'unavailable'
        i = 0
        self.addstr(0, 0, '%s (%s)' % (
            jid,
            presence,
        ), to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
        self.finish_line(get_theme().COLOR_INFORMATION_BAR)
        i += 1
        self.addstr(i, 0, 'Subscription: %s' % (contact.subscription, ))
        self.finish_line()
        i += 1
        if contact.ask:
            if contact.ask == 'asked':
                self.addstr(i, 0, 'Ask: %s' % (contact.ask, ),
                            to_curses_attr(get_theme().COLOR_IMPORTANT_TEXT))
            else:
                self.addstr(i, 0, 'Ask: %s' % (contact.ask, ))
            self.finish_line()
            i += 1
        if resource:
            self.addstr(i, 0, 'Status: %s' % (resource.status))
            self.finish_line()
            i += 1

        if contact.error:
            self.addstr(i, 0, 'Error: %s' % contact.error,
                        to_curses_attr(get_theme().COLOR_ROSTER_ERROR))
            self.finish_line()
            i += 1

        if contact.tune:
            self.addstr(i, 0,
                        'Tune: %s' % common.format_tune_string(contact.tune),
                        to_curses_attr(get_theme().COLOR_NORMAL_TEXT))
            self.finish_line()
            i += 1

        if contact.mood:
            self.addstr(i, 0, 'Mood: %s' % contact.mood,
                        to_curses_attr(get_theme().COLOR_NORMAL_TEXT))
            self.finish_line()
            i += 1

        if contact.activity:
            self.addstr(i, 0, 'Activity: %s' % contact.activity,
                        to_curses_attr(get_theme().COLOR_NORMAL_TEXT))
            self.finish_line()
            i += 1

        if contact.gaming:
            self.addstr(
                i, 0, 'Game: %s' % common.format_gaming_string(contact.gaming),
                to_curses_attr(get_theme().COLOR_NORMAL_TEXT))
            self.finish_line()
            i += 1
Exemplo n.º 6
0
    def draw_contact_line(self,
                          y: int,
                          contact: Contact,
                          colored: bool,
                          group: str,
                          show_roster_sub: Optional[str] = None,
                          show_s2s_errors: bool = True,
                          show_roster_jids: bool = False) -> None:
        """
        Draw on a line all information about one contact.
        This is basically the highest priority resource's information
        Use 'color' to draw the jid/display_name to show what is
        the currently selected contact in the list
        """

        theme = get_theme()
        resource = contact.get_highest_priority_resource()
        if not resource:
            # There's no online resource
            presence = 'unavailable'
            nb = ''
        else:
            presence = resource.presence
            nb = ' (%s)' % len(contact)
        color = theme.color_show(presence)
        added = 2 + len(theme.CHAR_STATUS) + len(nb)

        self.addstr(y, 0, ' ')
        self.addstr(theme.CHAR_STATUS, to_curses_attr(color))

        self.addstr(' ')
        if resource:
            self.addstr('[+] ' if contact.folded(group) else '[-] ')
        else:
            self.addstr('    ')
        added += 4

        if contact.ask:
            added += len(get_theme().CHAR_ROSTER_ASKED)
        if show_s2s_errors and contact.error:
            added += len(get_theme().CHAR_ROSTER_ERROR)
        if contact.tune:
            added += len(get_theme().CHAR_ROSTER_TUNE)
        if contact.mood:
            added += len(get_theme().CHAR_ROSTER_MOOD)
        if contact.activity:
            added += len(get_theme().CHAR_ROSTER_ACTIVITY)
        if contact.gaming:
            added += len(get_theme().CHAR_ROSTER_GAMING)
        if show_roster_sub in ('all', 'incomplete', 'to', 'from', 'both',
                               'none'):
            added += len(
                theme.char_subscription(
                    contact.subscription, keep=show_roster_sub))

        if not show_roster_jids and contact.name:
            display_name = contact.name
        elif contact.name and contact.name != contact.bare_jid:
            display_name = '%s (%s)' % (contact.name, contact.bare_jid)
        else:
            display_name = contact.bare_jid

        display_name = self.truncate_name(display_name, added) + nb

        if colored:
            self.addstr(display_name,
                        to_curses_attr(get_theme().COLOR_SELECTED_ROW))
        else:
            self.addstr(display_name)

        if show_roster_sub in ('all', 'incomplete', 'to', 'from', 'both',
                               'none'):
            self.addstr(
                theme.char_subscription(
                    contact.subscription, keep=show_roster_sub),
                to_curses_attr(theme.COLOR_ROSTER_SUBSCRIPTION))
        if contact.ask:
            self.addstr(get_theme().CHAR_ROSTER_ASKED,
                        to_curses_attr(get_theme().COLOR_IMPORTANT_TEXT))
        if show_s2s_errors and contact.error:
            self.addstr(get_theme().CHAR_ROSTER_ERROR,
                        to_curses_attr(get_theme().COLOR_ROSTER_ERROR))
        if contact.tune:
            self.addstr(get_theme().CHAR_ROSTER_TUNE,
                        to_curses_attr(get_theme().COLOR_ROSTER_TUNE))
        if contact.activity:
            self.addstr(get_theme().CHAR_ROSTER_ACTIVITY,
                        to_curses_attr(get_theme().COLOR_ROSTER_ACTIVITY))
        if contact.mood:
            self.addstr(get_theme().CHAR_ROSTER_MOOD,
                        to_curses_attr(get_theme().COLOR_ROSTER_MOOD))
        if contact.gaming:
            self.addstr(get_theme().CHAR_ROSTER_GAMING,
                        to_curses_attr(get_theme().COLOR_ROSTER_GAMING))
        self.finish_line()