示例#1
0
文件: handlers.py 项目: Perdu/poezio
def on_gaming_event(self, message):
    """
    Called when a pep notification for user gaming
    is received
    """
    contact = roster[message['from'].bare]
    if not contact:
        return
    item = message['pubsub_event']['items']['item']
    old_gaming = contact.gaming
    if item.xml.find('{urn:xmpp:gaming:0}gaming'):
        item = item['gaming']
        # only name and server_address are used for now
        contact.gaming = {
                'character_name': item['character_name'],
                'character_profile': item['character_profile'],
                'name': item['name'],
                'level': item['level'],
                'uri': item['uri'],
                'server_name': item['server_name'],
                'server_address': item['server_address'],
            }
    else:
        contact.gaming = {}

    if contact.gaming:
        logger.log_roster_change(contact.bare_jid, 'is playing %s' % (common.format_gaming_string(contact.gaming)))

    if old_gaming != contact.gaming and config.get_by_tabname('display_gaming_notifications', contact.bare_jid):
        if contact.gaming:
            self.information('%s is playing %s' % (contact.bare_jid, common.format_gaming_string(contact.gaming)), 'Gaming')
        else:
            self.information(contact.bare_jid + ' stopped playing.', 'Gaming')
示例#2
0
    def draw_contact_info(self, contact):
        """
        draw the contact information
        """
        resource = contact.get_highest_priority_resource()
        if contact:
            jid = contact.bare_jid
        elif resource:
            jid = 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
示例#3
0
文件: rostertab.py 项目: Perdu/poezio
 def show_contact_info(self):
     """
     Show the contact info (resource number, status, presence, etc)
     when 'i' is pressed.
     """
     selected_row = self.roster_win.get_selected_row()
     if isinstance(selected_row, Contact):
         cont = selected_row
         res = selected_row.get_highest_priority_resource()
         acc = []
         acc.append('Contact: %s (%s)' %
                    (cont.bare_jid, res.presence if res else 'unavailable'))
         if res:
             acc.append('%s connected resource%s' %
                        (len(cont), '' if len(cont) == 1 else 's'))
             acc.append('Current status: %s' % res.status)
         if cont.tune:
             acc.append('Tune: %s' % common.format_tune_string(cont.tune))
         if cont.mood:
             acc.append('Mood: %s' % cont.mood)
         if cont.activity:
             acc.append('Activity: %s' % cont.activity)
         if cont.gaming:
             acc.append('Game: %s' %
                        (common.format_gaming_string(cont.gaming)))
         msg = '\n'.join(acc)
     elif isinstance(selected_row, Resource):
         res = selected_row
         msg = 'Resource: %s (%s)\nCurrent status: %s\nPriority: %s' % (
             res.jid, res.presence, res.status, res.priority)
     elif isinstance(selected_row, RosterGroup):
         rg = selected_row
         msg = 'Group: %s [%s/%s] contacts online' % (
             rg.name,
             rg.get_nb_connected_contacts(),
             len(rg),
         )
     else:
         msg = None
     if msg:
         self.core.information(msg, 'Info')
示例#4
0
 def show_contact_info(self):
     """
     Show the contact info (resource number, status, presence, etc)
     when 'i' is pressed.
     """
     selected_row = self.roster_win.get_selected_row()
     if isinstance(selected_row, Contact):
         cont = selected_row
         res = selected_row.get_highest_priority_resource()
         acc = []
         acc.append('Contact: %s (%s)' % (cont.bare_jid, res.presence if res else 'unavailable'))
         if res:
             acc.append('%s connected resource%s' % (len(cont), '' if len(cont) == 1 else 's'))
             acc.append('Current status: %s' % res.status)
         if cont.tune:
             acc.append('Tune: %s' % common.format_tune_string(cont.tune))
         if cont.mood:
             acc.append('Mood: %s' % cont.mood)
         if cont.activity:
             acc.append('Activity: %s' % cont.activity)
         if cont.gaming:
             acc.append('Game: %s' % (common.format_gaming_string(cont.gaming)))
         msg = '\n'.join(acc)
     elif isinstance(selected_row, Resource):
         res = selected_row
         msg = 'Resource: %s (%s)\nCurrent status: %s\nPriority: %s' % (
                 res.jid,
                 res.presence,
                 res.status,
                 res.priority)
     elif isinstance(selected_row, RosterGroup):
         rg = selected_row
         msg = 'Group: %s [%s/%s] contacts online' % (
                 rg.name,
                 rg.get_nb_connected_contacts(),
                 len(rg),)
     else:
         msg = None
     if msg:
         self.core.information(msg, 'Info')
示例#5
0
    def draw_contact_info(self, contact):
        """
        draw the contact information
        """
        resource = contact.get_highest_priority_resource()
        if contact:
            jid = contact.bare_jid
        elif resource:
            jid = 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