Add global setting for moving finished torrents
This commit is contained in:
parent
434d0a2b3b
commit
7bfc3adcf1
|
@ -130,6 +130,10 @@ class Epour(object):
|
|||
"storage_path": os.path.expanduser(
|
||||
os.path.join("~", "Downloads")
|
||||
),
|
||||
"move_completed_path": os.path.expanduser(
|
||||
os.path.join("~", "Downloads")
|
||||
),
|
||||
"move_completed_enabled": str(False),
|
||||
"confirm_exit": str(False),
|
||||
"dialog_add_dbus": str(True),
|
||||
"delete_original": str(False),
|
||||
|
|
|
@ -102,7 +102,42 @@ class PreferencesGeneral(PreferencesDialog):
|
|||
limits = Limits(self, session)
|
||||
ports = ListenPorts(self, session)
|
||||
pe = EncryptionSettings(self, session)
|
||||
dlsel = DataStorageSelector(self, conf)
|
||||
save_path_sel = StorageSelector(
|
||||
self,
|
||||
"Storage path",
|
||||
lambda: conf.get("Settings", "storage_path"),
|
||||
lambda x: conf.set("Settings", "storage_path", x),
|
||||
size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ
|
||||
)
|
||||
|
||||
completed_sel_enabled = Check(
|
||||
self, size_hint_align=ALIGN_LEFT, text="Move completed torrents",
|
||||
)
|
||||
completed_sel_enabled.state = conf.getboolean(
|
||||
"Settings", "move_completed_enabled"
|
||||
)
|
||||
|
||||
completed_sel = StorageSelector(
|
||||
self,
|
||||
"Completed torrents",
|
||||
lambda: conf.get("Settings", "move_completed_path"),
|
||||
lambda x: conf.set("Settings", "move_completed_path", x),
|
||||
size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ
|
||||
)
|
||||
|
||||
def completed_sel_enabled_cb(chk, box, completed_sel):
|
||||
enable = chk.state
|
||||
conf.set("Settings", "move_completed_enabled", str(enable))
|
||||
if enable:
|
||||
box.pack_after(completed_sel, chk)
|
||||
completed_sel.show()
|
||||
else:
|
||||
completed_sel.hide()
|
||||
box.unpack(completed_sel)
|
||||
|
||||
completed_sel_enabled.callback_changed_add(
|
||||
completed_sel_enabled_cb, self.box, completed_sel
|
||||
)
|
||||
|
||||
pad = Rectangle(self.evas)
|
||||
pad.color = 0, 0, 0, 0
|
||||
|
@ -138,33 +173,53 @@ class PreferencesGeneral(PreferencesDialog):
|
|||
sep2 = Separator(self)
|
||||
sep2.horizontal = True
|
||||
|
||||
for w in ports, limits, dlsel, pe, pad, sep1, chk1, chk2, chk3, sep2:
|
||||
for w in (
|
||||
ports, limits, save_path_sel, completed_sel_enabled,
|
||||
pe, pad, sep1, chk1, chk2, chk3, sep2
|
||||
):
|
||||
w.show()
|
||||
self.box.pack_end(w)
|
||||
|
||||
if conf.getboolean("Settings", "move_completed_enabled"):
|
||||
print("DRUUU DAT")
|
||||
self.box.pack_after(completed_sel, completed_sel_enabled)
|
||||
completed_sel.show()
|
||||
|
||||
class DataStorageSelector(Frame):
|
||||
|
||||
def __init__(self, parent, conf):
|
||||
Frame.__init__(self, parent)
|
||||
class StorageSelector(Frame):
|
||||
|
||||
self.size_hint_align = FILL_HORIZ
|
||||
self.size_hint_weight = EXPAND_HORIZ
|
||||
self.text = "Data storage"
|
||||
def __init__(self, parent, title, read, write, *args, **kwargs):
|
||||
Frame.__init__(self, parent, *args, **kwargs)
|
||||
|
||||
self.conf = conf
|
||||
self.text = title
|
||||
|
||||
b = Box(parent)
|
||||
|
||||
lbl = self.path_lbl = Label(parent)
|
||||
lbl.text = conf.get("Settings", "storage_path")
|
||||
lbl = Label(parent)
|
||||
lbl.text = read()
|
||||
|
||||
self.dlsel = dlsel = FsButton(
|
||||
dlsel = FsButton(
|
||||
self, size_hint_align=FILL_HORIZ, inwin_mode=False,
|
||||
text="Change path", folder_only=True, expandable=False
|
||||
)
|
||||
dlsel.path = conf.get("Settings", "storage_path")
|
||||
dlsel.callback_file_chosen_add(self.save_dlpath)
|
||||
dlsel.path = read()
|
||||
|
||||
def save_dlpath(fs, path):
|
||||
if not path:
|
||||
return
|
||||
|
||||
if not os.path.exists(path):
|
||||
Error(
|
||||
self,
|
||||
"Invalid path",
|
||||
"You have selected an invalid storage path."
|
||||
)
|
||||
return
|
||||
|
||||
lbl.text = path
|
||||
write(path)
|
||||
|
||||
dlsel.callback_file_chosen_add(save_dlpath)
|
||||
|
||||
for w in lbl, dlsel:
|
||||
w.show()
|
||||
|
@ -173,19 +228,6 @@ class DataStorageSelector(Frame):
|
|||
b.show()
|
||||
self.content = b
|
||||
|
||||
def save_dlpath(self, fs, path):
|
||||
if not path:
|
||||
return
|
||||
|
||||
if not os.path.exists(self.dlsel.path):
|
||||
Error(
|
||||
self, "Invalid storage path",
|
||||
"You have selected an invalid data storage path for torrents.")
|
||||
return
|
||||
|
||||
self.path_lbl.text = path
|
||||
self.conf.set("Settings", "storage_path", self.dlsel.path)
|
||||
|
||||
|
||||
class ListenPorts(Frame):
|
||||
|
||||
|
|
|
@ -86,6 +86,17 @@ class Session(lt.session):
|
|||
self.alert_manager.callback_add(
|
||||
"metadata_received_alert", self._metadata_received_cb)
|
||||
|
||||
def torrent_finished_move_cb(a):
|
||||
h = a.handle
|
||||
if conf.getboolean("Settings", "move_completed_enabled"):
|
||||
path = conf.get("Settings", "move_completed_path")
|
||||
if h.save_path() == path:
|
||||
return
|
||||
h.move_storage(path)
|
||||
|
||||
self.alert_manager.callback_add(
|
||||
"torrent_finished_alert", torrent_finished_move_cb)
|
||||
|
||||
def _add_torrent_cb(self, a):
|
||||
e = a.error
|
||||
if e.value() > 0:
|
||||
|
@ -204,6 +215,7 @@ class Session(lt.session):
|
|||
t = {}
|
||||
t["info"] = lt.bdecode(t_info.metadata())
|
||||
t_dict["ti"] = lt.bencode(t)
|
||||
t_dict["save_path"] = h.save_path()
|
||||
resume_data = lt.bencode(h.write_resume_data())
|
||||
t_dict["resume_data"] = resume_data
|
||||
|
||||
|
|
Loading…
Reference in New Issue