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):
|
def set_save_path(self, save_path):
|
||||||
self.save_path = 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):
|
def get_state(self):
|
||||||
"""Returns the state of this torrent for saving to the session state"""
|
"""Returns the state of this torrent for saving to the session state"""
|
||||||
status = self.handle.status()
|
status = self.handle.status()
|
||||||
|
|
|
@ -134,7 +134,7 @@ class TorrentManager(component.Component):
|
||||||
trackers=None):
|
trackers=None):
|
||||||
"""Add a torrent to the manager and returns it's torrent_id"""
|
"""Add a torrent to the manager and returns it's torrent_id"""
|
||||||
log.info("Adding torrent: %s", filename)
|
log.info("Adding torrent: %s", filename)
|
||||||
|
log.debug("options: %s", options)
|
||||||
# Make sure 'filename' is a python string
|
# Make sure 'filename' is a python string
|
||||||
filename = str(filename)
|
filename = str(filename)
|
||||||
|
|
||||||
|
@ -237,6 +237,11 @@ class TorrentManager(component.Component):
|
||||||
options["prioritize_first_last_pieces"])
|
options["prioritize_first_last_pieces"])
|
||||||
torrent.set_private_flag(options["default_private"])
|
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
|
# Resume the torrent if needed
|
||||||
if paused == False:
|
if paused == False:
|
||||||
handle.resume()
|
handle.resume()
|
||||||
|
|
|
@ -262,6 +262,17 @@ class AddTorrentDialog:
|
||||||
|
|
||||||
self.options[torrent_id] = options
|
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):
|
def set_default_options(self):
|
||||||
# FIXME: does not account for remote core
|
# FIXME: does not account for remote core
|
||||||
self.glade.get_widget("button_location").set_current_folder(
|
self.glade.get_widget("button_location").set_current_folder(
|
||||||
|
@ -283,11 +294,27 @@ class AddTorrentDialog:
|
||||||
self.glade.get_widget("chk_private").set_active(
|
self.glade.get_widget("chk_private").set_active(
|
||||||
self.core_config["default_private"])
|
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):
|
def _on_file_toggled(self, render, path):
|
||||||
(model, paths) = self.listview_files.get_selection().get_selected_rows()
|
(model, paths) = self.listview_files.get_selection().get_selected_rows()
|
||||||
|
if len(paths) > 1:
|
||||||
for path in paths:
|
for path in paths:
|
||||||
row = model.get_iter(path)
|
row = model.get_iter(path)
|
||||||
model.set_value(row, 0, not model.get_value(row, 0))
|
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):
|
def _on_button_file_clicked(self, widget):
|
||||||
log.debug("_on_button_file_clicked")
|
log.debug("_on_button_file_clicked")
|
||||||
|
@ -399,13 +426,17 @@ class AddTorrentDialog:
|
||||||
|
|
||||||
row = self.torrent_liststore.get_iter_first()
|
row = self.torrent_liststore.get_iter_first()
|
||||||
while row != None:
|
while row != None:
|
||||||
|
torrent_id = self.torrent_liststore.get_value(row, 0)
|
||||||
filename = self.torrent_liststore.get_value(row, 2)
|
filename = self.torrent_liststore.get_value(row, 2)
|
||||||
try:
|
try:
|
||||||
options = self.options[
|
options = self.options[torrent_id]
|
||||||
self.torrent_liststore.get_value(row, 0)]
|
|
||||||
except:
|
except:
|
||||||
options = None
|
options = None
|
||||||
|
|
||||||
|
file_priorities = self.get_file_priorities(torrent_id)
|
||||||
|
if options != None:
|
||||||
|
options["file_priorities"] = file_priorities
|
||||||
|
|
||||||
torrent_filenames.append(filename)
|
torrent_filenames.append(filename)
|
||||||
torrent_options.append(options)
|
torrent_options.append(options)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue