From 20dc0a5e8adc8f18f097ef7707ff97dd4e659b22 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Wed, 25 Nov 2009 01:41:50 +0000 Subject: [PATCH] Fix files list when using magnet uris --- deluge/core/torrent.py | 16 +++++++--------- deluge/ui/gtkui/files_tab.py | 19 +++++++++---------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index a6984467f..3f03763ad 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -113,9 +113,6 @@ class Torrent: except RuntimeError: self.torrent_info = None - # Files dictionary - self.files = self.get_files() - # Default total_uploaded to 0, this may be changed by the state self.total_uploaded = 0 @@ -254,7 +251,7 @@ class Torrent: self.options["move_completed_path"] = move_completed_path def set_file_priorities(self, file_priorities): - if len(file_priorities) != len(self.files): + if len(file_priorities) != len(self.get_files()): log.debug("file_priorities len != num_files") self.options["file_priorities"] = self.handle.file_priorities() return @@ -491,7 +488,7 @@ class Torrent: file_progress = self.handle.file_progress() ret = [] - for i,f in enumerate(self.files): + for i,f in enumerate(self.get_files()): try: ret.append(float(file_progress[i]) / float(f["size"])) except ZeroDivisionError: @@ -559,7 +556,6 @@ class Torrent: "distributed_copies": distributed_copies, "download_payload_rate": self.status.download_payload_rate, "file_priorities": self.options["file_priorities"], - "files": self.files, "hash": self.torrent_id, "is_auto_managed": self.options["auto_managed"], "is_finished": self.is_finished, @@ -641,6 +637,7 @@ class Torrent: "comment": ti_comment, "eta": self.get_eta, "file_progress": self.get_file_progress, + "files": self.get_files, "is_seed": self.handle.is_seed, "name": ti_name, "num_files": ti_num_files, @@ -764,9 +761,10 @@ class Torrent: self.torrent_id) log.debug("Writing torrent file: %s", path) try: - ti = self.handle.get_torrent_info() - md = lt.bdecode(ti.metadata()) - log.debug("md: %s", md) + self.torrent_info = self.handle.get_torrent_info() + # Regenerate the file priorities + self.set_file_priorities([]) + md = lt.bdecode(self.torrent_info.metadata()) torrent_file = {} torrent_file["info"] = md open(path, "wb").write(lt.bencode(torrent_file)) diff --git a/deluge/ui/gtkui/files_tab.py b/deluge/ui/gtkui/files_tab.py index 6282bbd49..de1adb153 100644 --- a/deluge/ui/gtkui/files_tab.py +++ b/deluge/ui/gtkui/files_tab.py @@ -310,16 +310,16 @@ class FilesTab(Tab): self.torrent_id = torrent_id status_keys += ["compact"] - if self.torrent_id not in self.files_list.keys(): - # We need to get the files list - log.debug("Getting file list from core..") - status_keys += ["files"] - else: + if self.torrent_id in self.files_list: # We already have the files list stored, so just update the view self.update_files() + if self.torrent_id not in self.files_list or not self.files_list[self.torrent_id]: + # We need to get the files list + log.debug("Getting file list from core..") + status_keys += ["files"] + client.core.get_torrent_status(self.torrent_id, status_keys).addCallback(self._on_get_torrent_status) - client.force_call(True) def clear(self): self.treestore.clear() @@ -328,7 +328,6 @@ class FilesTab(Tab): def _on_row_activated(self, tree, path, view_column): if client.is_localhost: client.core.get_torrent_status(self.torrent_id, ["save_path", "files"]).addCallback(self._on_open_file) - client.force_call(False) def get_file_path(self, row, path=""): if not row: @@ -472,15 +471,15 @@ class FilesTab(Tab): self.file_menu.popup(None, None, None, event.button, event.time) return True - + def _on_key_press_event(self, widget, event): # Menu key if gtk.gdk.keyval_name(event.keyval) != "Menu": return - + if not self.get_selected_files(): return - + self.file_menu.popup(None, None, None, 3, event.time) return True