Fix files list when using magnet uris

This commit is contained in:
Andrew Resch 2009-11-25 01:41:50 +00:00
parent e6135aa2a9
commit 20dc0a5e8a
2 changed files with 16 additions and 19 deletions

View File

@ -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))

View File

@ -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