From c1710ca0f4d5bc5b33b61169cbdf06791c9c0624 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Fri, 25 Jan 2008 02:55:48 +0000 Subject: [PATCH] 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. --- deluge/core/torrent.py | 6 ++++- deluge/core/torrentmanager.py | 9 +++++-- deluge/ui/gtkui/addtorrentdialog.py | 39 ++++++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index 126f5c61e..0b0aba982 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -110,7 +110,11 @@ 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() diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index 268e57f84..c254a6a08 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -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) @@ -214,7 +214,7 @@ class TorrentManager(component.Component): if not handle or not handle.is_valid(): # The torrent was not added to the session - return None + return None # Create a Torrent object torrent = Torrent(filename, handle, compact, @@ -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() diff --git a/deluge/ui/gtkui/addtorrentdialog.py b/deluge/ui/gtkui/addtorrentdialog.py index 6cfca8a6a..8f23becc7 100644 --- a/deluge/ui/gtkui/addtorrentdialog.py +++ b/deluge/ui/gtkui/addtorrentdialog.py @@ -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( @@ -282,10 +293,26 @@ class AddTorrentDialog: self.core_config["prioritize_first_last_pieces"]) 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() - for path in paths: + 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)) @@ -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)