Esempio n. 1
0
    def update_select_host_popup(self):
        selected_index = self.popup.current_selection() if self.popup else None

        popup = SelectablePopup(self,
                                _('Select Host'),
                                self._host_selected,
                                border_off_west=1,
                                active_wrap=True)
        popup.add_header("{!white,black,bold!}'Q'=%s, 'a'=%s, 'D'=%s" %
                         (_('Quit'), _('Add Host'), _('Delete Host')),
                         space_below=True)
        self.push_popup(popup, clear=True)

        for host_entry in self.hostlist.get_hosts_info():
            host_id, hostname, port, user = host_entry
            args = {'data': host_id, 'foreground': 'red'}
            state = 'Offline'
            if host_id in self.statuses:
                state = 'Online'
                args.update({
                    'data': self.statuses[host_id],
                    'foreground': 'green'
                })
            host_str = '%s:%d [%s]' % (hostname, port, state)
            self.popup.add_line(host_id,
                                host_str,
                                selectable=True,
                                use_underline=True,
                                **args)

        if selected_index:
            self.popup.set_selection(selected_index)
        self.inlist = True
        self.refresh()
Esempio n. 2
0
    def handle_read(self, c):
        if c in [util.KEY_SPACE, curses.KEY_ENTER, util.KEY_ENTER2]:

            def search_handler(key):
                """Handle keyboard input to seach the list"""
                if not util.is_printable_chr(key):
                    return
                selected = select_popup.current_selection()

                def select_in_range(begin, end):
                    for i in range(begin, end):
                        val = select_popup.inputs[i].get_value()
                        if val.lower().startswith(chr(key)):
                            select_popup.set_selection(i)
                            return True
                    return False

                # First search downwards
                if not select_in_range(selected + 1, len(select_popup.inputs)):
                    # No match, so start at beginning
                    select_in_range(0, selected)

            from deluge.ui.console.widgets.popup import SelectablePopup  # Must import here
            select_popup = SelectablePopup(self.parent, ' %s ' % _('Select Language'), self._lang_selected,
                                           input_cb=search_handler if self.searchable else None,
                                           border_off_west=1, active_wrap=False, width_req=self.choices_width + 12)
            for choice in self.choices:
                args = {'data': choice[0]}
                select_popup.add_line(choice[0], choice[1], selectable=True,
                                      selected=choice[0] == self.get_value(), **args)
            self.parent.push_popup(select_popup)
            return util.ReadState.CHANGED
        return util.ReadState.IGNORED
Esempio n. 3
0
 def popup(self, **kwargs):
     popup = SelectablePopup(self.torrentslist, 'Queue Action', self.do_queue, cb_args=kwargs, border_off_west=1)
     popup.add_line(ACTION.QUEUE_TOP, '_Top')
     popup.add_line(ACTION.QUEUE_UP, '_Up')
     popup.add_line(ACTION.QUEUE_DOWN, '_Down')
     popup.add_line(ACTION.QUEUE_BOTTOM, '_Bottom')
     self.torrentslist.push_popup(popup)
Esempio n. 4
0
 def popup(self, **kwargs):
     popup = SelectablePopup(self.torrentslist,
                             'Queue Action',
                             self.do_queue,
                             cb_args=kwargs,
                             border_off_west=1)
     popup.add_line(ACTION.QUEUE_TOP, '_Top')
     popup.add_line(ACTION.QUEUE_UP, '_Up')
     popup.add_line(ACTION.QUEUE_DOWN, '_Down')
     popup.add_line(ACTION.QUEUE_BOTTOM, '_Bottom')
     self.torrentslist.push_popup(popup)
Esempio n. 5
0
    def handle_read(self, c):
        if c in [util.KEY_SPACE, curses.KEY_ENTER, util.KEY_ENTER2]:

            def search_handler(key):
                """Handle keyboard input to seach the list"""
                if not util.is_printable_chr(key):
                    return
                selected = select_popup.current_selection()

                def select_in_range(begin, end):
                    for i in range(begin, end):
                        val = select_popup.inputs[i].get_value()
                        if val.lower().startswith(chr(key)):
                            select_popup.set_selection(i)
                            return True
                    return False

                # First search downwards
                if not select_in_range(selected + 1, len(select_popup.inputs)):
                    # No match, so start at beginning
                    select_in_range(0, selected)

            from deluge.ui.console.widgets.popup import (  # Must import here
                SelectablePopup, )

            select_popup = SelectablePopup(
                self.parent,
                ' %s ' % _('Select Language'),
                self._lang_selected,
                input_cb=search_handler if self.searchable else None,
                border_off_west=1,
                active_wrap=False,
                width_req=self.choices_width + 12,
            )
            for choice in self.choices:
                args = {'data': choice[0]}
                select_popup.add_line(choice[0],
                                      choice[1],
                                      selectable=True,
                                      selected=choice[0] == self.get_value(),
                                      **args)
            self.parent.push_popup(select_popup)
            return util.ReadState.CHANGED
        return util.ReadState.IGNORED
def show_torrent_add_popup(torrentlist):

    def do_add_from_url(data=None, **kwargs):
        torrentlist.pop_popup()
        if not data or kwargs.get('close', False):
            return

        def fail_cb(msg, url):
            log.debug('failed to add torrent: %s: %s', url, msg)
            error_msg = '{!input!} * %s: {!error!}%s' % (url, msg)
            report_add_status(torrentlist, 0, 1, [error_msg])

        def success_cb(tid, url):
            if tid:
                log.debug('added torrent: %s (%s)', url, tid)
                report_add_status(torrentlist, 1, 0, [])
            else:
                fail_cb('Already in session (probably)', url)

        url = data['url']['value']
        if not url:
            return

        t_options = {'download_location': data['path']['value'], 'add_paused': data['add_paused']['value']}

        if deluge.common.is_magnet(url):
            client.core.add_torrent_magnet(url, t_options).addCallback(success_cb, url).addErrback(fail_cb, url)
        elif deluge.common.is_url(url):
            client.core.add_torrent_url(url, t_options).addCallback(success_cb, url).addErrback(fail_cb, url)
        else:
            torrentlist.report_message('Error', '{!error!}Invalid URL or magnet link: %s' % url)
            return

        log.debug('Adding Torrent(s): %s (dl path: %s) (paused: %d)',
                  url, data['path']['value'], data['add_paused']['value'])

    def show_add_url_popup():
        add_paused = 1 if 'add_paused' in torrentlist.coreconfig else 0
        popup = InputPopup(torrentlist, 'Add Torrent (Esc to cancel)', close_cb=do_add_from_url)
        popup.add_text_input('url', 'Enter torrent URL or Magnet link:')
        popup.add_text_input('path', 'Enter save path:', torrentlist.coreconfig.get('download_location', ''),
                             complete=True)
        popup.add_select_input('add_paused', 'Add Paused:', ['Yes', 'No'], [True, False], add_paused)
        torrentlist.push_popup(popup)

    def option_chosen(selected, *args, **kwargs):
        if not selected or selected == 'cancel':
            torrentlist.pop_popup()
            return
        if selected == 'file':
            torrentlist.consoleui.set_mode('AddTorrents')
        elif selected == 'url':
            show_add_url_popup()

    popup = SelectablePopup(torrentlist, 'Add torrent', option_chosen)
    popup.add_line('file', '- From _File(s)', use_underline=True)
    popup.add_line('url', '- From _URL or Magnet', use_underline=True)
    popup.add_line('cancel', '- _Cancel', use_underline=True)
    torrentlist.push_popup(popup, clear=True)
Esempio n. 7
0
    def show_priority_popup(self, was_empty):

        def popup_func(data, *args, **kwargs):
            if data is None:
                return
            return self.do_priority(data, kwargs[data], was_empty)

        if self.marked:
            popup = SelectablePopup(self, 'Set File Priority', popup_func, border_off_north=1)
            popup.add_line('ignore_priority', '_Ignore',
                           cb_arg=FILE_PRIORITY['Ignore'], foreground='red')
            popup.add_line('low_priority', '_Low Priority',
                           cb_arg=FILE_PRIORITY['Low Priority'], foreground='yellow')
            popup.add_line('normal_priority', '_Normal Priority',
                           cb_arg=FILE_PRIORITY['Normal Priority'])
            popup.add_line('high_priority', '_High Priority',
                           cb_arg=FILE_PRIORITY['High Priority'], foreground='green')
            popup._selected = 1
            self.push_popup(popup)
Esempio n. 8
0
    def update_select_host_popup(self):
        selected_index = self.popup.current_selection() if self.popup else None

        popup = SelectablePopup(
            self, _('Select Host'), self._host_selected, border_off_west=1, active_wrap=True)
        popup.add_header(
            "{!white,black,bold!}'Q'=%s, 'a'=%s, 'D'=%s" %
            (_('Quit'), _('Add Host'), _('Delete Host')), space_below=True)
        self.push_popup(popup, clear=True)

        for host_entry in self.hostlist.get_hosts_info():
            host_id, hostname, port, user = host_entry
            args = {'data': host_id, 'foreground': 'red'}
            state = 'Offline'
            if host_id in self.statuses:
                state = 'Online'
                args.update({'data': self.statuses[host_id], 'foreground': 'green'})
            host_str = '%s:%d [%s]' % (hostname, port, state)
            self.popup.add_line(host_id, host_str, selectable=True, use_underline=True, **args)

        if selected_index:
            self.popup.set_selection(selected_index)
        self.inlist = True
        self.refresh()
Esempio n. 9
0
def show_torrent_add_popup(torrentlist):
    def do_add_from_url(data=None, **kwargs):
        torrentlist.pop_popup()
        if not data or kwargs.get('close', False):
            return

        def fail_cb(msg, url):
            log.debug('failed to add torrent: %s: %s', url, msg)
            error_msg = '{!input!} * %s: {!error!}%s' % (url, msg)
            report_add_status(torrentlist, 0, 1, [error_msg])

        def success_cb(tid, url):
            if tid:
                log.debug('added torrent: %s (%s)', url, tid)
                report_add_status(torrentlist, 1, 0, [])
            else:
                fail_cb('Already in session (probably)', url)

        url = data['url']['value']
        if not url:
            return

        t_options = {
            'download_location': data['path']['value'],
            'add_paused': data['add_paused']['value'],
        }

        if deluge.common.is_magnet(url):
            client.core.add_torrent_magnet(url, t_options).addCallback(
                success_cb, url
            ).addErrback(fail_cb, url)
        elif deluge.common.is_url(url):
            client.core.add_torrent_url(url, t_options).addCallback(
                success_cb, url
            ).addErrback(fail_cb, url)
        else:
            torrentlist.report_message(
                'Error', '{!error!}Invalid URL or magnet link: %s' % url
            )
            return

        log.debug(
            'Adding Torrent(s): %s (dl path: %s) (paused: %d)',
            url,
            data['path']['value'],
            data['add_paused']['value'],
        )

    def show_add_url_popup():
        add_paused = 1 if 'add_paused' in torrentlist.coreconfig else 0
        popup = InputPopup(
            torrentlist, 'Add Torrent (Esc to cancel)', close_cb=do_add_from_url
        )
        popup.add_text_input('url', 'Enter torrent URL or Magnet link:')
        popup.add_text_input(
            'path',
            'Enter save path:',
            torrentlist.coreconfig.get('download_location', ''),
            complete=True,
        )
        popup.add_select_input(
            'add_paused', 'Add Paused:', ['Yes', 'No'], [True, False], add_paused
        )
        torrentlist.push_popup(popup)

    def option_chosen(selected, *args, **kwargs):
        if not selected or selected == 'cancel':
            torrentlist.pop_popup()
            return
        if selected == 'file':
            torrentlist.consoleui.set_mode('AddTorrents')
        elif selected == 'url':
            show_add_url_popup()

    popup = SelectablePopup(torrentlist, 'Add torrent', option_chosen)
    popup.add_line('file', '- From _File(s)', use_underline=True)
    popup.add_line('url', '- From _URL or Magnet', use_underline=True)
    popup.add_line('cancel', '- _Cancel', use_underline=True)
    torrentlist.push_popup(popup, clear=True)
Esempio n. 10
0
def torrent_actions_popup(mode,
                          torrent_ids,
                          details=False,
                          action=None,
                          close_cb=None):

    if action is not None:
        torrent_action(action, mode=mode, torrent_ids=torrent_ids)
        return

    popup = SelectablePopup(mode,
                            'Torrent Actions',
                            torrent_action,
                            cb_args={
                                'mode': mode,
                                'torrent_ids': torrent_ids
                            },
                            close_cb=close_cb,
                            border_off_north=1,
                            border_off_west=1,
                            border_off_east=1)
    popup.add_line(ACTION.PAUSE, '_Pause')
    popup.add_line(ACTION.RESUME, '_Resume')
    if details:
        popup.add_divider()
        popup.add_line(ACTION.QUEUE, 'Queue')
    popup.add_divider()
    popup.add_line(ACTION.REANNOUNCE, '_Update Tracker')
    popup.add_divider()
    popup.add_line(ACTION.REMOVE, 'Remo_ve Torrent')
    popup.add_line(ACTION.RECHECK, '_Force Recheck')
    popup.add_line(ACTION.MOVE_STORAGE, '_Move Download Folder')
    popup.add_divider()
    if details:
        popup.add_line(ACTION.DETAILS, 'Torrent _Details')
    popup.add_line(ACTION.TORRENT_OPTIONS, 'Torrent _Options')
    mode.push_popup(popup)
Esempio n. 11
0
    def show_priority_popup(self, was_empty):
        def popup_func(name, data, was_empty, **kwargs):
            if not name:
                return
            return self.do_priority(data[name], was_empty)

        if self.marked:
            popup = SelectablePopup(
                self,
                'Set File Priority',
                popup_func,
                border_off_north=1,
                cb_args={'was_empty': was_empty},
            )
            popup.add_line(
                'skip_priority',
                '_Skip',
                foreground='red',
                cb_arg=FILE_PRIORITY['Skip'],
                was_empty=was_empty,
            )
            popup.add_line('low_priority',
                           '_Low',
                           cb_arg=FILE_PRIORITY['Low'],
                           foreground='yellow')
            popup.add_line('normal_priority',
                           '_Normal',
                           cb_arg=FILE_PRIORITY['Normal'])
            popup.add_line(
                'high_priority',
                '_High',
                cb_arg=FILE_PRIORITY['High'],
                foreground='green',
            )
            popup._selected = 1
            self.push_popup(popup)
Esempio n. 12
0
    def show_priority_popup(self, was_empty):
        def popup_func(data, *args, **kwargs):
            if data is None:
                return
            return self.do_priority(data, kwargs[data], was_empty)

        if self.marked:
            popup = SelectablePopup(self,
                                    'Set File Priority',
                                    popup_func,
                                    border_off_north=1)
            popup.add_line('ignore_priority',
                           '_Ignore',
                           cb_arg=FILE_PRIORITY['Ignore'],
                           foreground='red')
            popup.add_line('low_priority',
                           '_Low Priority',
                           cb_arg=FILE_PRIORITY['Low Priority'],
                           foreground='yellow')
            popup.add_line('normal_priority',
                           '_Normal Priority',
                           cb_arg=FILE_PRIORITY['Normal Priority'])
            popup.add_line('high_priority',
                           '_High Priority',
                           cb_arg=FILE_PRIORITY['High Priority'],
                           foreground='green')
            popup._selected = 1
            self.push_popup(popup)