Example #1
0
    def first_step(self, request):
        # first query...
        response, cmd = self.build_response(request,
                                            defaultaction='execute',
                                            actions=['execute'])

        cmd.addChild(node=dataforms.SimpleDataForm(
            title=_('Change status'),
            instructions=_('Set the presence type and description'),
            fields=[
                dataforms.create_field(
                    'list-single',
                    var='presence-type',
                    label='Type of presence:',
                    options=[('chat',
                              _('Free for chat')), (
                                  'online', _('Online')), ('away', _('Away')),
                             ('xa',
                              _('Extended away')), ('dnd',
                                                    _('Do not disturb')),
                             ('offline', _('Offline - disconnect'))],
                    value='online',
                    required=True),
                dataforms.create_field('text-multi',
                                       var='presence-desc',
                                       label=_('Presence description:'))
            ]))

        self.connection.connection.send(response)

        # for next invocation
        self._callback = self.second_step

        return True  # keep the session
Example #2
0
    def second_step(self, request):
        # check if the data is correct
        try:
            form = dataforms.SimpleDataForm(
                extend=request.getTag('command').getTag('x'))
        except Exception:
            self.bad_request(request)
            return False

        try:
            presencetype = form['presence-type'].value
            if presencetype not in ('chat', 'online', 'away', 'xa', 'dnd',
                                    'offline'):
                self.bad_request(request)
                return False
        except Exception:
            # KeyError if there's no presence-type field in form or
            # AttributeError if that field is of wrong type
            self.bad_request(request)
            return False

        try:
            presencedesc = form['presence-desc'].value
        except Exception:  # same exceptions as in last comment
            presencedesc = ''

        response, cmd = self.build_response(request, status='completed')
        cmd.addChild('note', {}, _('The status has been changed.'))

        # if going offline, we need to push response so it won't go into
        # queue and disappear
        self.connection.connection.send(response,
                                        now=presencetype == 'offline')

        # send new status
        app.interface.roster.send_status(self.connection.name, presencetype,
                                         presencedesc)

        return False  # finish the session
Example #3
0
    def second_step(self, request):
        # check if the data is correct
        try:
            form = dataforms.SimpleDataForm(
                extend=request.getTag('command').getTag('x'))
        except Exception:
            self.bad_request(request)
            return False

        try:
            gc = form['groupchats'].values
        except Exception:  # KeyError if there's no groupchats in form
            self.bad_request(request)
            return False
        account = self.connection.name
        try:
            for room_jid in gc:
                gc_control = app.interface.msg_win_mgr.get_gc_control(
                    room_jid, account)
                if not gc_control:
                    minimized_controls = app.interface.minimized_controls
                    gc_control = minimized_controls[account][room_jid]
                    gc_control.shutdown()
                    app.interface.roster.remove_groupchat(room_jid, account)
                    continue
                gc_control.parent_win.remove_tab(gc_control, None, force=True)
        except Exception:  # KeyError if there's no such room opened
            self.bad_request(request)
            return False
        response, cmd = self.build_response(request, status='completed')
        note = _('You left the following group chats:')
        for room_jid in gc:
            note += '\n\t' + room_jid
        cmd.addChild('note', {}, note)

        self.connection.connection.send(response)
        return False
Example #4
0
    def first_step(self, request):
        # first query...
        response, cmd = self.build_response(request,
                                            defaultaction='execute',
                                            actions=['execute'])
        options = []
        account = self.connection.name
        for gc in find_current_groupchats(account):
            options.append(('%s' % gc[0], _('%(nickname)s on %(room_jid)s') % {
                'nickname': gc[1],
                'room_jid': gc[0]
            }))
        if not options:
            response, cmd = self.build_response(request, status='completed')
            cmd.addChild('note', {}, _('You have not joined a group chat.'))

            self.connection.connection.send(response)
            return False

        cmd.addChild(node=dataforms.SimpleDataForm(
            title=_('Leave Group Chats'),
            instructions=_('Choose the group chats you want to leave'),
            fields=[
                dataforms.create_field('list-multi',
                                       var='groupchats',
                                       label=_('Group chats'),
                                       options=options,
                                       required=True)
            ]))

        self.connection.connection.send(response)

        # for next invocation
        self._callback = self.second_step

        return True  # keep the session