Fix some accidental reverts

This commit is contained in:
Andrew Resch 2009-11-25 01:00:25 +00:00
parent 1cb42252b8
commit e6135aa2a9
6 changed files with 59 additions and 63 deletions

View File

@ -84,7 +84,8 @@ class TorrentInfo(object):
# Get the torrent data from the torrent file # Get the torrent data from the torrent file
try: try:
log.debug("Attempting to open %s.", filename) log.debug("Attempting to open %s.", filename)
self.__m_metadata = bencode.bdecode(open(filename, "rb").read()) self.__m_filedata = open(filename, "rb").read()
self.__m_metadata = bencode.bdecode(self.__m_filedata)
except Exception, e: except Exception, e:
log.warning("Unable to open %s: %s", filename, e) log.warning("Unable to open %s: %s", filename, e)
raise e raise e
@ -212,6 +213,16 @@ class TorrentInfo(object):
""" """
return self.__m_metadata return self.__m_metadata
@property
def filedata(self):
"""
The torrents file data. This will be the bencoded dictionary read
from the torrent file.
:rtype: string
"""
return self.__m_filedata
class FileTree(object): class FileTree(object):
""" """
Convert a list of paths in a file tree. Convert a list of paths in a file tree.

View File

@ -211,7 +211,7 @@ class AddTorrentDialog(component.Component):
new_row = self.torrent_liststore.append( new_row = self.torrent_liststore.append(
[info.info_hash, info.name, filename]) [info.info_hash, info.name, filename])
self.files[info.info_hash] = info.files self.files[info.info_hash] = info.files
self.infos[info.info_hash] = info.metadata self.infos[info.info_hash] = info.filedata
self.listview_torrents.get_selection().select_iter(new_row) self.listview_torrents.get_selection().select_iter(new_row)
self.set_default_options() self.set_default_options()
@ -226,7 +226,11 @@ class AddTorrentDialog(component.Component):
new_row = None new_row = None
for uri in uris: for uri in uris:
info_hash = base64.b32decode(uri.split("&")[0][20:]).encode("hex") s = uri.split("&")[0][20:]
if len(s) == 32:
info_hash = base64.b32decode(s).encode("hex")
elif len(s) == 40:
info_hash = s
if info_hash in self.infos: if info_hash in self.infos:
log.debug("Torrent already in list!") log.debug("Torrent already in list!")
continue continue
@ -716,11 +720,6 @@ class AddTorrentDialog(component.Component):
if row is not None: if row is not None:
self.save_torrent_options(row) self.save_torrent_options(row)
torrent_filenames = []
torrent_magnets = []
torrent_magnet_options = []
torrent_options = []
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) torrent_id = self.torrent_liststore.get_value(row, 0)
@ -735,26 +734,16 @@ class AddTorrentDialog(component.Component):
options["file_priorities"] = file_priorities options["file_priorities"] = file_priorities
if deluge.common.is_magnet(filename): if deluge.common.is_magnet(filename):
torrent_magnets.append(filename)
del options["file_priorities"] del options["file_priorities"]
torrent_magnet_options.append(options) client.core.add_torrent_magnet(filename, options)
else: else:
torrent_filenames.append(filename) client.core.add_torrent_file(
torrent_options.append(options) os.path.split(filename)[-1],
base64.encodestring(self.infos[torrent_id]),
options)
row = self.torrent_liststore.iter_next(row) row = self.torrent_liststore.iter_next(row)
if torrent_filenames:
for i, f in enumerate(torrent_filenames):
client.core.add_torrent_file(
os.path.split(f)[-1],
base64.encodestring(open(f, "rb").read()),
torrent_options[i])
if torrent_magnets:
for i, m in enumerate(torrent_magnets):
client.core.add_torrent_magnet(m, torrent_magnet_options[i])
client.force_call(False)
self.hide() self.hide()
def _on_button_apply_clicked(self, widget): def _on_button_apply_clicked(self, widget):

View File

@ -71,7 +71,9 @@ class IPCInterface(component.Component):
_args = [] _args = []
for arg in args: for arg in args:
if arg.strip(): if arg.strip():
_args.append(os.path.abspath(arg)) if not deluge.common.is_magnet(arg) and not deluge.common.is_url(arg):
arg = os.path.abspath(arg)
_args.append(arg)
args = _args args = _args
socket = os.path.join(deluge.configmanager.get_config_dir("ipc"), "deluge-gtk") socket = os.path.join(deluge.configmanager.get_config_dir("ipc"), "deluge-gtk")
@ -117,7 +119,6 @@ class IPCInterface(component.Component):
except Exception, e: except Exception, e:
log.error("Problem deleting lockfile or socket file!") log.error("Problem deleting lockfile or socket file!")
log.exception(e) log.exception(e)
try: try:
self.factory = Factory() self.factory = Factory()
self.factory.protocol = IPCProtocolServer self.factory.protocol = IPCProtocolServer

View File

@ -103,14 +103,20 @@ class MainWindow(component.Component):
def show(self): def show(self):
try: try:
self.resume_components() component.resume("TorrentView")
component.resume("StatusBar")
component.resume("TorrentDetails")
except: except:
pass pass
self.window.show() self.window.show()
def hide(self): def hide(self):
self.pause_components() component.pause("TorrentView")
component.get("TorrentView").save_state()
component.pause("StatusBar")
component.pause("TorrentDetails")
# Store the x, y positions for when we restore the window # Store the x, y positions for when we restore the window
self.window_x_pos = self.window.get_position()[0] self.window_x_pos = self.window.get_position()[0]
self.window_y_pos = self.window.get_position()[1] self.window_y_pos = self.window.get_position()[1]
@ -124,31 +130,15 @@ class MainWindow(component.Component):
except: except:
pass pass
try: try:
self.resume_components() component.resume("TorrentView")
component.resume("StatusBar")
component.resume("TorrentDetails")
except: except:
pass pass
self.window.present() self.window.present()
self.load_window_state() self.load_window_state()
def pause_components(self):
"""
Pause certain components. This is useful when the main window is not
being shown to reduce cpu usage.
"""
component.pause("TorrentView")
component.get("TorrentView").save_state()
component.pause("StatusBar")
component.pause("TorrentDetails")
def resume_components(self):
"""
Resumes components that are paused in `:meth:pause_components`.
"""
component.resume("TorrentView")
component.resume("StatusBar")
component.resume("TorrentDetails")
def active(self): def active(self):
"""Returns True if the window is active, False if not.""" """Returns True if the window is active, False if not."""
return self.window.is_active() return self.window.is_active()
@ -191,12 +181,14 @@ class MainWindow(component.Component):
if event.changed_mask & gtk.gdk.WINDOW_STATE_ICONIFIED: if event.changed_mask & gtk.gdk.WINDOW_STATE_ICONIFIED:
if event.new_window_state & gtk.gdk.WINDOW_STATE_ICONIFIED: if event.new_window_state & gtk.gdk.WINDOW_STATE_ICONIFIED:
log.debug("MainWindow is minimized..") log.debug("MainWindow is minimized..")
self.pause_components() component.pause("TorrentView")
component.pause("StatusBar")
self.is_minimized = True self.is_minimized = True
else: else:
log.debug("MainWindow is not minimized..") log.debug("MainWindow is not minimized..")
try: try:
self.resume_components() component.resume("TorrentView")
component.resume("StatusBar")
except: except:
pass pass
self.is_minimized = False self.is_minimized = False

View File

@ -196,6 +196,9 @@ class SystemTray(component.Component):
self.upload_rate = deluge.common.fsize(upload_rate) self.upload_rate = deluge.common.fsize(upload_rate)
def update(self): def update(self):
if not self.config["enable_system_tray"]:
return
# Set the tool tip text # Set the tool tip text
max_download_speed = self.max_download_speed max_download_speed = self.max_download_speed
max_upload_speed = self.max_upload_speed max_upload_speed = self.max_upload_speed