コード例 #1
0
ファイル: torrent_actions.py プロジェクト: Ashod/Deluge
            def create_popup(status):
                cb = lambda result, ids=ids: _do_set_torrent_options(ids, result)
                option_popup = InputPopup(mode,"Set torrent options (Esc to cancel)",close_cb=cb, height_req=22)

                for (field, field_type) in torrent_options:
                    caption = "{!info!}" + torrent_options_to_names[field]
                    value = options[field]
                    if   field_type == str:
                        if not isinstance(value, basestring):
                            value = str(value)
                        option_popup.add_text_input(caption, field, value)
                    elif field_type == bool:
                        if options[field] == "multiple":
                            choices = (
                                ["Yes", "No", "Mixed"],
                                [True, False, None],
                                2
                            )
                        else:
                            choices = (
                                ["Yes", "No"],
                                [True, False],
                                [True, False].index(options[field])
                            )
                        option_popup.add_select_input(caption, field, choices[0], choices[1], choices[2])
                    elif field_type == float:
                        option_popup.add_float_spin_input(caption, field, value, min_val = -1)
                    elif field_type == int:
                        option_popup.add_int_spin_input(caption, field, value, min_val = -1)

                mode.set_popup(option_popup)
                mode.refresh()
コード例 #2
0
 def __add_popup(self):
     self.inlist = False
     self.popup = InputPopup(self,"Add Host (esc to cancel)",close_cb=self.__do_add)
     self.popup.add_text_input("Hostname:","hostname")
     self.popup.add_text_input("Port:","port")
     self.popup.add_text_input("Username:"******"username")
     self.popup.add_text_input("Password:"******"password")
     self.refresh()
コード例 #3
0
ファイル: torrent_actions.py プロジェクト: Ashod/Deluge
            def finish_up(status):
                status = map(lambda x: x[1], status)

                if len(ids) == 1:
                    rem_msg = "{!info!}Removing the following torrent:{!input!}"
                else:
                    rem_msg = "{!info!}Removing the following torrents:{!input!}"

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

                popup = InputPopup(mode, "(Esc to cancel, Enter to remove)", close_cb=do_remove)
                popup.add_text(rem_msg)
                popup.add_spaces(1)
                popup.add_select_input("{!info!}Torrent files:", 'remove_files', ["Keep", "Remove"], [False, True], False)
                mode.set_popup(popup)
コード例 #4
0
ファイル: torrentdetail.py プロジェクト: Ashod/Deluge
    def _show_rename_popup(self):
        #Perhaps in the future: Renaming multiple files
        if self.marked:
            title = "Error (Enter to close)"
            text = "Sorry, you can't rename multiple files, please clear selection with {!info!}'c'{!normal!} key"
            self.popup = MessagePopup(self, title, text)
        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):
                    if not result["new_foldername"]:
                        return
                    old_fname = self._get_full_folder_path(self.current_file_idx)
                    new_fname = "%s/%s/" % (old_fname.strip("/").rpartition("/")[0], result["new_foldername"])
                    self._do_rename_folder(tid, old_fname, new_fname)

                popup = InputPopup(self,"Rename folder (Esc to cancel)",close_cb=do_rename)
                popup.add_text("{!info!}Renaming folder:{!input!}")
                popup.add_text(" * %s\n" % old_filename)
                popup.add_text_input("Enter new folder name:", "new_foldername", old_filename.strip("/"))

                self.popup = popup
            else:

                def do_rename(result):
                    fname = "%s/%s" % (self.full_names[idx].rpartition("/")[0], result["new_filename"])
                    self._do_rename_file(tid, idx, fname)

                popup = InputPopup(self,"Rename file (Esc to cancel)",close_cb=do_rename)
                popup.add_text("{!info!}Renaming file:{!input!}")
                popup.add_text(" * %s\n" % old_filename)
                popup.add_text_input("Enter new filename:", "new_filename", old_filename)

                self.popup = popup
コード例 #5
0
def torrent_action(idx, data, mode, ids):
    if ids:
        if data == ACTION.PAUSE:
            log.debug("Pausing torrents: %s", ids)
            client.core.pause_torrent(ids).addErrback(action_error, mode)
        elif data == ACTION.RESUME:
            log.debug("Resuming torrents: %s", ids)
            client.core.resume_torrent(ids).addErrback(action_error, mode)
        elif data == ACTION.QUEUE:

            def do_queue(idx, qact, mode, ids):
                if qact == ACTION.QUEUE_TOP:
                    log.debug("Queuing torrents top")
                    client.core.queue_top(ids)
                elif qact == ACTION.QUEUE_UP:
                    log.debug("Queuing torrents up")
                    client.core.queue_up(ids)
                elif qact == ACTION.QUEUE_DOWN:
                    log.debug("Queuing torrents down")
                    client.core.queue_down(ids)
                elif qact == ACTION.QUEUE_BOTTOM:
                    log.debug("Queuing torrents bottom")
                    client.core.queue_bottom(ids)
                if len(ids) == 1:
                    mode.clear_marks()
                return True

            popup = SelectablePopup(mode, "Queue Action", do_queue, mode, ids)
            popup.add_line("_Top", data=ACTION.QUEUE_TOP)
            popup.add_line("_Up", data=ACTION.QUEUE_UP)
            popup.add_line("_Down", data=ACTION.QUEUE_DOWN)
            popup.add_line("_Bottom", data=ACTION.QUEUE_BOTTOM)
            mode.set_popup(popup)
            return False
        elif data == ACTION.REMOVE:

            def do_remove(idx, data, mode, ids):
                if data:
                    wd = data == ACTION.REMOVE_DATA
                    for tid in ids:
                        log.debug("Removing torrent: %s,%d", tid, wd)
                        client.core.remove_torrent(tid, wd).addErrback(
                            action_error, mode)
                if len(ids) == 1:
                    mode.clear_marks()
                return True

            popup = SelectablePopup(mode, "Confirm Remove", do_remove, mode,
                                    ids)
            popup.add_line(
                "Are you sure you want to remove the marked torrents?",
                selectable=False)
            popup.add_line("Remove with _data", data=ACTION.REMOVE_DATA)
            popup.add_line("Remove _torrent", data=ACTION.REMOVE_NODATA)
            popup.add_line("_Cancel", data=0)
            mode.set_popup(popup)
            return False
        elif data == ACTION.MOVE_STORAGE:

            def do_move(res):
                import os.path
                if os.path.exists(
                        res["path"]) and not os.path.isdir(res["path"]):
                    mode.report_message(
                        "Cannot Move Storage",
                        "{!error!}%s exists and is not a directory" %
                        res["path"])
                else:
                    log.debug("Moving %s to: %s", ids, res["path"])
                    client.core.move_storage(ids, res["path"]).addErrback(
                        action_error, mode)
                if len(ids) == 1:
                    mode.clear_marks()
                return True

            popup = InputPopup(mode,
                               "Move Storage (Esc to cancel)",
                               close_cb=do_move)
            popup.add_text_input("Enter path to move to:", "path")
            mode.set_popup(popup)
            return False
        elif data == ACTION.RECHECK:
            log.debug("Rechecking torrents: %s", ids)
            client.core.force_recheck(ids).addErrback(action_error, mode)
        elif data == ACTION.REANNOUNCE:
            log.debug("Reannouncing torrents: %s", ids)
            client.core.force_reannounce(ids).addErrback(action_error, mode)
        elif data == ACTION.DETAILS:
            log.debug("Torrent details")
            tid = mode.current_torrent_id()
            if tid:
                mode.show_torrent_details(tid)
            else:
                log.error(
                    "No current torrent in _torrent_action, this is a bug")
    if len(ids) == 1:
        mode.clear_marks()
    return True
コード例 #6
0
 def show_input(self, title, text, callback=None, is_password_input=False):
     p = self.show_popup_obj(InputPopup(self.app, self.screen, title, text),
                             title, text, callback)
     p.is_password_input = is_password_input
     return p
コード例 #7
0
    def _show_add_dialog(self):
        def _do_add(result):
            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"]:
                    self.alltorrentmode._report_add_status(
                        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"]:
                        self.alltorrentmode._report_add_status(
                            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)
                filedump = base64.encodestring(open(path).read())
                t_options = {}
                if result["location"]:
                    t_options["download_location"] = result["location"]
                t_options["add_paused"] = result["add_paused"]

                d = client.core.add_torrent_file(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
        dl = config["download_location"]
        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("Save Location:", "location", dl)
        self.popup.add_select_input("Add Paused:", "add_paused", ["Yes", "No"],
                                    [True, False], ap)