From 234e6827e8223c4c0236350e42cc625697939fe7 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sat, 29 Sep 2007 10:37:46 +0000 Subject: [PATCH] Load .fastresume files on add. Fix opening browser function. --- deluge/core/core.py | 3 +-- deluge/core/torrentmanager.py | 18 ++++++++++++++++-- deluge/ui/functions.py | 19 +++++++++---------- deluge/ui/gtkui/preferences.py | 7 ++++--- deluge/ui/gtkui/systemtray.py | 2 -- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/deluge/core/core.py b/deluge/core/core.py index af3478a19..3ae8b74e0 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -265,8 +265,7 @@ class Core(dbus.service.Object): status = self.torrents[torrent_id].get_status(nkeys) except KeyError: # The torrent_id is not found in the torrentmanager, so return None - status = None - return status + return None # Get the leftover fields and ask the plugin manager to fill them leftover_fields = list(set(nkeys) - set(status.keys())) diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index ab8478dd8..b8985665a 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -121,7 +121,20 @@ class TorrentManager: except IOError: log.warning("Unable to open %s", filename) return None - + + # Attempt to load fastresume data + try: + _file = open( + os.path.join( + self.config["torrentfiles_location"], + filename + ".fastresume"), + "rb") + fastresume = lt.bdecode(_file.read()) + _file.close() + except IOError: + log.debug("Unable to load .fastresume..") + fastresume = None + # Bdecode the filedata torrent_filedump = lt.bdecode(filedump) handle = None @@ -134,7 +147,8 @@ class TorrentManager: handle = self.session.add_torrent( lt.torrent_info(torrent_filedump), self.config["download_location"], - compact) + resume_data=fastresume, + compact_mode=compact) except RuntimeError: log.warning("Error adding torrent") diff --git a/deluge/ui/functions.py b/deluge/ui/functions.py index 65f26b2e0..3c894f67e 100644 --- a/deluge/ui/functions.py +++ b/deluge/ui/functions.py @@ -177,14 +177,13 @@ def get_listen_port(core=None): core = get_core() return int(core.get_listen_port()) -def open_url_in_browser(link): +def open_url_in_browser(url): """Opens link in the desktop's default browser""" - import threading - import webbrowser - class BrowserThread(threading.Thread): - def __init__(self, link): - threading.Thread.__init__(self) - self.url = link - def run(self): - webbrowser.open(self.url) - BrowserThread(link).start() + def start_browser(): + import webbrowser + log.debug("Opening webbrowser with url: %s", url) + webbrowser.open(url) + return False + + import gobject + gobject.idle_add(start_browser) diff --git a/deluge/ui/gtkui/preferences.py b/deluge/ui/gtkui/preferences.py index d1966ade8..38f18db7e 100644 --- a/deluge/ui/gtkui/preferences.py +++ b/deluge/ui/gtkui/preferences.py @@ -356,7 +356,8 @@ class Preferences: self.notebook.set_current_page(model.get_value(row, 0)) def on_test_port_clicked(self, data): - functions.open_url_in_browser('\ - http://www.deluge-torrent.org/test-port.php?port=%s' % \ - functions.get_listen_port(self.core)) + log.debug("on_test_port_clicked") + url = "http://deluge-torrent.org/test-port.php?port=%s" % \ + functions.get_listen_port(self.core) + functions.open_url_in_browser(url) diff --git a/deluge/ui/gtkui/systemtray.py b/deluge/ui/gtkui/systemtray.py index ec7b013e7..115dce987 100644 --- a/deluge/ui/gtkui/systemtray.py +++ b/deluge/ui/gtkui/systemtray.py @@ -45,8 +45,6 @@ class SystemTray: self.config = ConfigManager("gtkui.conf") self.config.register_set_function("enable_system_tray", self.on_enable_system_tray_set) - #if self.config["enable_system_tray"]: - # self.enable() def enable(self): """Enables the system tray icon."""