Add the ability to set file priorities for torrents in the core.
The Add Torrent dialog now sets proper file priorities based on user input.
This commit is contained in:
parent
073b62408f
commit
c1710ca0f4
|
@ -111,6 +111,10 @@ class Torrent:
|
|||
def set_save_path(self, save_path):
|
||||
self.save_path = save_path
|
||||
|
||||
def set_file_priorities(self, file_priorities):
|
||||
self.file_priorities = file_priorities
|
||||
self.handle.prioritize_files(file_priorities)
|
||||
|
||||
def get_state(self):
|
||||
"""Returns the state of this torrent for saving to the session state"""
|
||||
status = self.handle.status()
|
||||
|
|
|
@ -134,7 +134,7 @@ class TorrentManager(component.Component):
|
|||
trackers=None):
|
||||
"""Add a torrent to the manager and returns it's torrent_id"""
|
||||
log.info("Adding torrent: %s", filename)
|
||||
|
||||
log.debug("options: %s", options)
|
||||
# Make sure 'filename' is a python string
|
||||
filename = str(filename)
|
||||
|
||||
|
@ -237,6 +237,11 @@ class TorrentManager(component.Component):
|
|||
options["prioritize_first_last_pieces"])
|
||||
torrent.set_private_flag(options["default_private"])
|
||||
|
||||
if options.has_key("file_priorities"):
|
||||
if options["file_priorities"] != None:
|
||||
log.debug("set file priorities: %s", options["file_priorities"])
|
||||
torrent.set_file_priorities(options["file_priorities"])
|
||||
|
||||
# Resume the torrent if needed
|
||||
if paused == False:
|
||||
handle.resume()
|
||||
|
|
|
@ -262,6 +262,17 @@ class AddTorrentDialog:
|
|||
|
||||
self.options[torrent_id] = options
|
||||
|
||||
# Save the file priorities
|
||||
row = self.files_liststore.get_iter_first()
|
||||
files_priorities = []
|
||||
while row != None:
|
||||
download = self.files_liststore.get_value(row, 0)
|
||||
files_priorities.append(download)
|
||||
row = self.files_liststore.iter_next(row)
|
||||
|
||||
for i, file_dict in enumerate(self.files[torrent_id]):
|
||||
file_dict["download"] = files_priorities[i]
|
||||
|
||||
def set_default_options(self):
|
||||
# FIXME: does not account for remote core
|
||||
self.glade.get_widget("button_location").set_current_folder(
|
||||
|
@ -283,11 +294,27 @@ class AddTorrentDialog:
|
|||
self.glade.get_widget("chk_private").set_active(
|
||||
self.core_config["default_private"])
|
||||
|
||||
def get_file_priorities(self, torrent_id):
|
||||
# A list of priorities
|
||||
files_list = []
|
||||
|
||||
for file_dict in self.files[torrent_id]:
|
||||
if file_dict["download"] == False:
|
||||
files_list.append(0)
|
||||
else:
|
||||
files_list.append(1)
|
||||
|
||||
return files_list
|
||||
|
||||
def _on_file_toggled(self, render, path):
|
||||
(model, paths) = self.listview_files.get_selection().get_selected_rows()
|
||||
if len(paths) > 1:
|
||||
for path in paths:
|
||||
row = model.get_iter(path)
|
||||
model.set_value(row, 0, not model.get_value(row, 0))
|
||||
else:
|
||||
row = model.get_iter(path)
|
||||
model.set_value(row, 0, not model.get_value(row, 0))
|
||||
|
||||
def _on_button_file_clicked(self, widget):
|
||||
log.debug("_on_button_file_clicked")
|
||||
|
@ -399,13 +426,17 @@ class AddTorrentDialog:
|
|||
|
||||
row = self.torrent_liststore.get_iter_first()
|
||||
while row != None:
|
||||
torrent_id = self.torrent_liststore.get_value(row, 0)
|
||||
filename = self.torrent_liststore.get_value(row, 2)
|
||||
try:
|
||||
options = self.options[
|
||||
self.torrent_liststore.get_value(row, 0)]
|
||||
options = self.options[torrent_id]
|
||||
except:
|
||||
options = None
|
||||
|
||||
file_priorities = self.get_file_priorities(torrent_id)
|
||||
if options != None:
|
||||
options["file_priorities"] = file_priorities
|
||||
|
||||
torrent_filenames.append(filename)
|
||||
torrent_options.append(options)
|
||||
|
||||
|
|
Loading…
Reference in New Issue