Added setting per-torrent options to console mode. Mapped to 'o' key, supports setting options for multiple torrents at once(when values differ, leave the default value alone to not touch that option)
This commit is contained in:
parent
2625bbc7fd
commit
3f5099bd05
|
@ -53,6 +53,8 @@ from torrent_actions import torrent_actions_popup
|
||||||
from eventview import EventView
|
from eventview import EventView
|
||||||
from legacy import Legacy
|
from legacy import Legacy
|
||||||
|
|
||||||
|
from twisted.internet import defer
|
||||||
|
|
||||||
import format_utils,column
|
import format_utils,column
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -200,6 +202,36 @@ prefs_to_names = {
|
||||||
"owner":"Owner",
|
"owner":"Owner",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
torrent_options = [
|
||||||
|
("max_download_speed", float),
|
||||||
|
("max_upload_speed", float),
|
||||||
|
("max_connections", int),
|
||||||
|
("max_upload_slots", int),
|
||||||
|
("private", bool),
|
||||||
|
("prioritize_first_last", bool),
|
||||||
|
("is_auto_managed", bool),
|
||||||
|
("stop_at_ratio", bool),
|
||||||
|
("stop_ratio", float),
|
||||||
|
("remove_at_ratio", bool),
|
||||||
|
("move_on_completed", bool),
|
||||||
|
("move_on_completed_path", str)
|
||||||
|
]
|
||||||
|
|
||||||
|
torrent_options_to_names = {
|
||||||
|
"max_download_speed": "Max DL speed",
|
||||||
|
"max_upload_speed": "Max UL speed",
|
||||||
|
"max_connections": "Max connections",
|
||||||
|
"max_upload_slots": "Max upload slots",
|
||||||
|
"private": "Private",
|
||||||
|
"prioritize_first_last": "Prioritize first/last pieces",
|
||||||
|
"is_auto_managed": "Is auto managed?",
|
||||||
|
"stop_at_ratio": "Stop at ratio",
|
||||||
|
"stop_ratio": "Seeding ratio limit",
|
||||||
|
"remove_at_ratio": "Remove after reaching ratio",
|
||||||
|
"move_on_completed": "Move torrent after completion",
|
||||||
|
"move_on_completed_path": "Path to move the torrent to"
|
||||||
|
}
|
||||||
|
|
||||||
class AllTorrents(BaseMode, component.Component):
|
class AllTorrents(BaseMode, component.Component):
|
||||||
def __init__(self, stdscr, encoding=None):
|
def __init__(self, stdscr, encoding=None):
|
||||||
self.formatted_rows = None
|
self.formatted_rows = None
|
||||||
|
@ -561,6 +593,74 @@ class AllTorrents(BaseMode, component.Component):
|
||||||
self.popup.add_spaces(1)
|
self.popup.add_spaces(1)
|
||||||
self.popup.add_select_input("Path is:","path_type",["Auto","File","URL"],[0,1,2],0)
|
self.popup.add_select_input("Path is:","path_type",["Auto","File","URL"],[0,1,2],0)
|
||||||
|
|
||||||
|
def _show_torrent_options_popup(self):
|
||||||
|
if self.marked:
|
||||||
|
get_tid = lambda idx: self._sorted_ids[idx-1]
|
||||||
|
torrents = map(get_tid, self.marked)
|
||||||
|
else:
|
||||||
|
torrents = [self.current_torrent_id()]
|
||||||
|
|
||||||
|
options = {}
|
||||||
|
|
||||||
|
def on_torrent_status(status):
|
||||||
|
for key in status:
|
||||||
|
if key not in options:
|
||||||
|
options[key] = status[key]
|
||||||
|
elif options[key] != status[key]:
|
||||||
|
options[key] = "multiple"
|
||||||
|
|
||||||
|
def create_popup(status):
|
||||||
|
cb = lambda result, ids=torrents: self._do_set_torrent_options(ids, result)
|
||||||
|
try:
|
||||||
|
option_popup = InputPopup(self,"Set torrent options (Esc to cancel)",close_cb=cb, height_req=22)
|
||||||
|
except:
|
||||||
|
option_popup = InputPopup(self,"Set torrent options (Esc to cancel)",close_cb=cb)
|
||||||
|
|
||||||
|
for (field, field_type) in torrent_options:
|
||||||
|
caption = "{!info!}" + torrent_options_to_names[field]
|
||||||
|
value = options[field]
|
||||||
|
if field_type == str:
|
||||||
|
option_popup.add_text_input(caption, field, str(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)
|
||||||
|
|
||||||
|
self.set_popup(option_popup)
|
||||||
|
self.refresh()
|
||||||
|
|
||||||
|
callbacks = []
|
||||||
|
|
||||||
|
field_list = map(lambda t: t[0], torrent_options)
|
||||||
|
|
||||||
|
for tid in torrents:
|
||||||
|
deferred = component.get("SessionProxy").get_torrent_status(tid, field_list)
|
||||||
|
callbacks.append( deferred.addCallback(on_torrent_status) )
|
||||||
|
|
||||||
|
callbacks = defer.DeferredList(callbacks)
|
||||||
|
callbacks.addCallback(create_popup)
|
||||||
|
|
||||||
|
def _do_set_torrent_options(self, ids, result):
|
||||||
|
options = {}
|
||||||
|
for opt in result:
|
||||||
|
if result[opt] not in ["multiple", None]:
|
||||||
|
options[opt] = result[opt]
|
||||||
|
client.core.set_torrent_options( ids, options )
|
||||||
|
|
||||||
def report_message(self,title,message):
|
def report_message(self,title,message):
|
||||||
self.messages.append((title,message))
|
self.messages.append((title,message))
|
||||||
|
|
||||||
|
@ -853,6 +953,10 @@ class AllTorrents(BaseMode, component.Component):
|
||||||
self.last_mark = -1
|
self.last_mark = -1
|
||||||
elif chr(c) == 'a':
|
elif chr(c) == 'a':
|
||||||
self._show_torrent_add_popup()
|
self._show_torrent_add_popup()
|
||||||
|
elif chr(c) == 'o':
|
||||||
|
self.popup = Popup(self, "Torrent options")
|
||||||
|
self.popup.add_line("Querying core, please wait...")
|
||||||
|
self._show_torrent_options_popup()
|
||||||
elif chr(c) == 'f':
|
elif chr(c) == 'f':
|
||||||
self._show_torrent_filter_popup()
|
self._show_torrent_filter_popup()
|
||||||
elif chr(c) == 'h':
|
elif chr(c) == 'h':
|
||||||
|
|
Loading…
Reference in New Issue