示例#1
0
    def __init__(self, torrentlist):
        self.torrentlist = torrentlist
        self.torrentview = torrentlist.torrentview

        title = 'Visible columns (Esc to exit)'
        InputPopup.__init__(
            self,
            torrentlist,
            title,
            close_cb=self._do_set_column_visibility,
            immediate_action=True,
            height_req=len(column_pref_names) - 5,
            width_req=max(len(col)
                          for col in column_pref_names + [title]) + 14,
            border_off_west=1,
            allow_rearrange=True,
        )

        msg_fmt = '%-25s'
        self.add_header((msg_fmt % _('Columns')) + ' ' + _('Width'),
                        space_below=True)

        for colpref_name in column_pref_names:
            col = self.torrentview.config['torrentview']['columns'][
                colpref_name]
            width_spin = IntSpinInput(
                self,
                colpref_name + '_ width',
                '',
                self.move,
                col['width'],
                min_val=-1,
                max_val=99,
                fmt='%2d',
            )

            def on_width_func(name, width):
                self.torrentview.config['torrentview']['columns'][name][
                    'width'] = width

            self._add_input(
                ColumnAndWidth(
                    self,
                    colpref_name,
                    torrent_data_fields[colpref_name]['name'],
                    width_spin,
                    on_width_func,
                    checked=col['visible'],
                    checked_char='*',
                    msg_fmt=msg_fmt,
                    show_usage_hints=False,
                    child_always_visible=True,
                ))
示例#2
0
    def remove_dialog(status):
        status = [t_status[1] for t_status in status]

        if len(torrent_ids) == 1:
            rem_msg = '{!info!}Remove the following torrent?{!input!}'
        else:
            rem_msg = '{!info!}Remove the following %d torrents?{!input!}' % len(
                torrent_ids)

        show_max = 6
        for i, (name, state) in enumerate(status):
            color = colors.state_color[state]
            rem_msg += '\n %s* {!input!}%s' % (color, name)
            if i == show_max - 1:
                if i < len(status) - 1:
                    rem_msg += '\n  {!red!}And %i more' % (len(status) -
                                                           show_max)
                break

        popup = InputPopup(mode,
                           '(Esc to cancel, Enter to remove)',
                           close_cb=do_remove,
                           border_off_west=1,
                           border_off_north=1)
        popup.add_text(rem_msg)
        popup.add_spaces(1)
        popup.add_select_input('remove_files', '{!info!}Torrent files:',
                               ['Keep', 'Remove'], [False, True], False)
        mode.push_popup(popup)
示例#3
0
    def _show_rename_popup(self):
        # Perhaps in the future: Renaming multiple files
        if self.marked:
            self.report_message(
                'Error (Enter to close)',
                'Sorry, you cannot rename multiple files, please clear '
                'selection with {!info!}"c"{!normal!} key',
            )
        else:
            _file = self.__get_file_by_num(self.current_file_idx,
                                           self.file_list)
            old_filename = _file[0]
            idx = self._selection_to_file_idx()
            tid = self.torrentid

            if _file[3]:

                def do_rename(result, **kwargs):
                    if (not result or not result['new_foldername']['value']
                            or kwargs.get('close', False)):
                        self.popup.close(None, call_cb=False)
                        return
                    old_fname = self._get_full_folder_path(
                        self.current_file_idx)
                    new_fname = '%s/%s/' % (
                        old_fname.strip('/').rpartition('/')[0],
                        result['new_foldername']['value'],
                    )
                    self._do_rename_folder(tid, old_fname, new_fname)

                popup = InputPopup(self,
                                   'Rename folder (Esc to cancel)',
                                   close_cb=do_rename)
                popup.add_text_input(
                    'new_foldername',
                    'Enter new folder name:',
                    old_filename.strip('/'),
                    complete=True,
                )
                self.push_popup(popup)
            else:

                def do_rename(result, **kwargs):
                    if (not result or not result['new_filename']['value']
                            or kwargs.get('close', False)):
                        self.popup.close(None, call_cb=False)
                        return
                    fname = '%s/%s' % (
                        self.full_names[idx].rpartition('/')[0],
                        result['new_filename']['value'],
                    )
                    self._do_rename_file(tid, idx, fname)

                popup = InputPopup(self, ' Rename file ', close_cb=do_rename)
                popup.add_text_input('new_filename',
                                     'Enter new filename:',
                                     old_filename,
                                     complete=True)
                self.push_popup(popup)
 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)
示例#5
0
 def handle_read(self, c):
     if c == ord('h'):
         popup = MessagePopup(self.torrentlist,
                              'Help',
                              COLUMN_VIEW_HELP_STR,
                              width_req=70,
                              border_off_west=1)
         self.torrentlist.push_popup(popup)
         return util.ReadState.READ
     return InputPopup.handle_read(self, c)
示例#6
0
    def create_popup(status):
        mode.pop_popup()

        def cb(result, **kwargs):
            if result is None:
                return
            _do_set_torrent_options(torrent_ids, result)
            if kwargs.get('close', False):
                mode.pop_popup()
                return True

        option_popup = InputPopup(
            mode,
            ' Set Torrent Options ',
            close_cb=cb,
            border_off_west=1,
            border_off_north=1,
            base_popup=kwargs.get('base_popup', None),
        )
        for field in torrent_options:
            caption = '{!info!}' + TORRENT_DATA_FIELD[field]['name']
            value = options[field]
            if isinstance(value, ''.__class__):
                option_popup.add_text_input(field, caption, value)
            elif isinstance(value, bool):
                choices = (['Yes', 'No'], [True, False], [True,
                                                          False].index(value))
                option_popup.add_select_input(field, caption, choices[0],
                                              choices[1], choices[2])
            elif isinstance(value, float):
                option_popup.add_float_spin_input(field,
                                                  caption,
                                                  value=value,
                                                  min_val=-1)
            elif isinstance(value, int):
                option_popup.add_int_spin_input(field,
                                                caption,
                                                value=value,
                                                min_val=-1)

        mode.push_popup(option_popup)
示例#7
0
 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)
示例#8
0
 def add_popup(self):
     self.inlist = False
     popup = InputPopup(
         self,
         _('Add Host (Up & Down arrows to navigate, Esc to cancel)'),
         border_off_north=1,
         border_off_east=1,
         close_cb=self._do_add)
     popup.add_text_input('hostname', _('Hostname:'))
     popup.add_text_input('port', _('Port:'))
     popup.add_text_input('username', _('Username:'******'password', _('Password:'))
     self.push_popup(popup, clear=True)
     self.refresh()
 def add_popup(self):
     self.inlist = False
     popup = InputPopup(
         self,
         _('Add Host (Up & Down arrows to navigate, Esc to cancel)'),
         border_off_north=1,
         border_off_east=1,
         close_cb=self._do_add)
     popup.add_text_input('hostname', _('Hostname:'))
     popup.add_text_input('port', _('Port:'))
     popup.add_text_input('username', _('Username:'******'password', _('Password:'))
     self.push_popup(popup, clear=True)
     self.refresh()
示例#10
0
    def _show_rename_popup(self):
        # Perhaps in the future: Renaming multiple files
        if self.marked:
            self.report_message('Error (Enter to close)',
                                'Sorry, you cannot rename multiple files, please clear '
                                'selection with {!info!}"c"{!normal!} key')
        else:
            _file = self.__get_file_by_num(self.current_file_idx, self.file_list)
            old_filename = _file[0]
            idx = self._selection_to_file_idx()
            tid = self.torrentid

            if _file[3]:

                def do_rename(result, **kwargs):
                    if not result or not result['new_foldername']['value'] or kwargs.get('close', False):
                        self.popup.close(None, call_cb=False)
                        return
                    old_fname = self._get_full_folder_path(self.current_file_idx)
                    new_fname = '%s/%s/' % (old_fname.strip('/').rpartition('/')[0], result['new_foldername']['value'])
                    self._do_rename_folder(tid, old_fname, new_fname)

                popup = InputPopup(self, 'Rename folder (Esc to cancel)', close_cb=do_rename)
                popup.add_text_input('new_foldername', 'Enter new folder name:', old_filename.strip('/'), complete=True)
                self.push_popup(popup)
            else:

                def do_rename(result, **kwargs):
                    if not result or not result['new_filename']['value'] or kwargs.get('close', False):
                        self.popup.close(None, call_cb=False)
                        return
                    fname = '%s/%s' % (self.full_names[idx].rpartition('/')[0], result['new_filename']['value'])
                    self._do_rename_file(tid, idx, fname)

                popup = InputPopup(self, ' Rename file ', close_cb=do_rename)
                popup.add_text_input('new_filename', 'Enter new filename:', old_filename, complete=True)
                self.push_popup(popup)
示例#11
0
    def _show_add_dialog(self):
        def _do_add(result, **kwargs):
            ress = {'succ': 0, 'fail': 0, 'total': len(self.marked), 'fmsg': []}

            def fail_cb(msg, t_file, ress):
                log.debug('failed to add torrent: %s: %s', t_file, msg)
                ress['fail'] += 1
                ress['fmsg'].append('{!input!} * %s: {!error!}%s' % (t_file, msg))
                if (ress['succ'] + ress['fail']) >= ress['total']:
                    report_add_status(
                        component.get('TorrentList'),
                        ress['succ'],
                        ress['fail'],
                        ress['fmsg'],
                    )

            def success_cb(tid, t_file, ress):
                if tid:
                    log.debug('added torrent: %s (%s)', t_file, tid)
                    ress['succ'] += 1
                    if (ress['succ'] + ress['fail']) >= ress['total']:
                        report_add_status(
                            component.get('TorrentList'),
                            ress['succ'],
                            ress['fail'],
                            ress['fmsg'],
                        )
                else:
                    fail_cb('Already in session (probably)', t_file, ress)

            for m in self.marked:
                filename = m
                directory = os.path.join(*self.path_stack[: self.path_stack_pos])
                path = os.path.join(directory, filename)
                with open(path, 'rb') as _file:
                    filedump = b64encode(_file.read())
                t_options = {}
                if result['location']['value']:
                    t_options['download_location'] = result['location']['value']
                t_options['add_paused'] = result['add_paused']['value']

                d = client.core.add_torrent_file_async(filename, filedump, t_options)
                d.addCallback(success_cb, filename, ress)
                d.addErrback(fail_cb, filename, ress)

            self.console_config['addtorrents']['last_path'] = os.path.join(
                *self.path_stack[: self.path_stack_pos]
            )
            self.console_config.save()

            self.back_to_overview()

        config = component.get('ConsoleUI').coreconfig
        if config['add_paused']:
            ap = 0
        else:
            ap = 1
        self.popup = InputPopup(
            self, 'Add Torrents (Esc to cancel)', close_cb=_do_add, height_req=17
        )

        msg = 'Adding torrent files:'
        for i, m in enumerate(self.marked):
            name = m
            msg += '\n * {!input!}%s' % name
            if i == 5:
                if i < len(self.marked):
                    msg += '\n  {!red!}And %i more' % (len(self.marked) - 5)
                break
        self.popup.add_text(msg)
        self.popup.add_spaces(1)

        self.popup.add_text_input(
            'location', 'Download Folder:', config['download_location'], complete=True
        )
        self.popup.add_select_input(
            'add_paused', 'Add Paused:', ['Yes', 'No'], [True, False], ap
        )
示例#12
0
def torrent_action(action, *args, **kwargs):
    retval = False
    torrent_ids = kwargs.get('torrent_ids', None)
    mode = kwargs.get('mode', None)

    if torrent_ids is None:
        return

    if action == ACTION.PAUSE:
        log.debug('Pausing torrents: %s', torrent_ids)
        client.core.pause_torrent(torrent_ids).addErrback(action_error, mode)
        retval = True
    elif action == ACTION.RESUME:
        log.debug('Resuming torrents: %s', torrent_ids)
        client.core.resume_torrent(torrent_ids).addErrback(action_error, mode)
        retval = True
    elif action == ACTION.QUEUE:
        queue_mode = QueueMode(mode, torrent_ids)
        queue_mode.popup(**kwargs)
        return False
    elif action == ACTION.REMOVE:
        action_remove(**kwargs)
        return False
    elif action == ACTION.MOVE_STORAGE:

        def do_move(res, **kwargs):
            if res is None or kwargs.get('close', False):
                mode.pop_popup()
                return True

            if os.path.exists(res['path']['value']) and not os.path.isdir(
                    res['path']['value']):
                mode.report_message(
                    'Cannot Move Download Folder',
                    '{!error!}%s exists and is not a directory' %
                    res['path']['value'])
            else:
                log.debug('Moving %s to: %s', torrent_ids,
                          res['path']['value'])
                client.core.move_storage(torrent_ids,
                                         res['path']['value']).addErrback(
                                             action_error, mode)

        popup = InputPopup(mode,
                           'Move Download Folder',
                           close_cb=do_move,
                           border_off_east=1)
        popup.add_text_input('path', 'Enter path to move to:', complete=True)
        mode.push_popup(popup)
    elif action == ACTION.RECHECK:
        log.debug('Rechecking torrents: %s', torrent_ids)
        client.core.force_recheck(torrent_ids).addErrback(action_error, mode)
        retval = True
    elif action == ACTION.REANNOUNCE:
        log.debug('Reannouncing torrents: %s', torrent_ids)
        client.core.force_reannounce(torrent_ids).addErrback(
            action_error, mode)
        retval = True
    elif action == ACTION.DETAILS:
        log.debug('Torrent details')
        tid = mode.torrentview.current_torrent_id()
        if tid:
            mode.show_torrent_details(tid)
        else:
            log.error('No current torrent in _torrentaction, this is a bug')
    elif action == ACTION.TORRENT_OPTIONS:
        action_torrent_info(**kwargs)

    return retval