diff --git a/deluge/event.py b/deluge/event.py index 5f1e1ea51..e36913bd9 100644 --- a/deluge/event.py +++ b/deluge/event.py @@ -17,9 +17,9 @@ # # You should have received a copy of the GNU General Public License # along with deluge. If not, write to: -# The Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor -# Boston, MA 02110-1301, USA. +# The Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor +# Boston, MA 02110-1301, USA. # # In addition, as a special exception, the copyright holders give # permission to link the code of portions of this program with the OpenSSL diff --git a/deluge/ui/common.py b/deluge/ui/common.py index 1748f201a..4ea999da8 100644 --- a/deluge/ui/common.py +++ b/deluge/ui/common.py @@ -75,16 +75,17 @@ def decode_string(s, encoding="utf8"): class TorrentInfo(object): """ Collects information about a torrent file. - + :param filename: The path to the torrent :type filename: string - + """ def __init__(self, filename): # Get the torrent data from the torrent file try: 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: log.warning("Unable to open %s: %s", filename, e) raise e @@ -163,7 +164,7 @@ class TorrentInfo(object): def name(self): """ The name of the torrent. - + :rtype: string """ return self.__m_name @@ -172,7 +173,7 @@ class TorrentInfo(object): def info_hash(self): """ The torrents info_hash - + :rtype: string """ return self.__m_info_hash @@ -181,7 +182,7 @@ class TorrentInfo(object): def files(self): """ A list of the files that the torrent contains. - + :rtype: list """ return self.__m_files @@ -190,15 +191,15 @@ class TorrentInfo(object): def files_tree(self): """ A dictionary based tree of the files. - + :: - + { "some_directory": { "some_file": (index, size, download) } } - + :rtype: dictionary """ return self.__m_files_tree @@ -207,11 +208,21 @@ class TorrentInfo(object): def metadata(self): """ The torrents metadata. - + :rtype: dictionary """ 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): """ Convert a list of paths in a file tree. @@ -219,7 +230,7 @@ class FileTree(object): :param paths: The paths to be converted. :type paths: list """ - + def __init__(self, paths): self.tree = {} diff --git a/deluge/ui/gtkui/addtorrentdialog.py b/deluge/ui/gtkui/addtorrentdialog.py index a9de36a2e..fb253c6bf 100644 --- a/deluge/ui/gtkui/addtorrentdialog.py +++ b/deluge/ui/gtkui/addtorrentdialog.py @@ -211,7 +211,7 @@ class AddTorrentDialog(component.Component): new_row = self.torrent_liststore.append( [info.info_hash, info.name, filename]) 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.set_default_options() @@ -226,7 +226,11 @@ class AddTorrentDialog(component.Component): new_row = None 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: log.debug("Torrent already in list!") continue @@ -716,11 +720,6 @@ class AddTorrentDialog(component.Component): if row is not None: self.save_torrent_options(row) - torrent_filenames = [] - torrent_magnets = [] - torrent_magnet_options = [] - torrent_options = [] - row = self.torrent_liststore.get_iter_first() while row != None: torrent_id = self.torrent_liststore.get_value(row, 0) @@ -735,26 +734,16 @@ class AddTorrentDialog(component.Component): options["file_priorities"] = file_priorities if deluge.common.is_magnet(filename): - torrent_magnets.append(filename) del options["file_priorities"] - torrent_magnet_options.append(options) + client.core.add_torrent_magnet(filename, options) else: - torrent_filenames.append(filename) - torrent_options.append(options) + client.core.add_torrent_file( + os.path.split(filename)[-1], + base64.encodestring(self.infos[torrent_id]), + options) 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() def _on_button_apply_clicked(self, widget): diff --git a/deluge/ui/gtkui/ipcinterface.py b/deluge/ui/gtkui/ipcinterface.py index 046073399..988137fd5 100644 --- a/deluge/ui/gtkui/ipcinterface.py +++ b/deluge/ui/gtkui/ipcinterface.py @@ -71,7 +71,9 @@ class IPCInterface(component.Component): _args = [] for arg in args: 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 socket = os.path.join(deluge.configmanager.get_config_dir("ipc"), "deluge-gtk") @@ -117,7 +119,6 @@ class IPCInterface(component.Component): except Exception, e: log.error("Problem deleting lockfile or socket file!") log.exception(e) - try: self.factory = Factory() self.factory.protocol = IPCProtocolServer diff --git a/deluge/ui/gtkui/mainwindow.py b/deluge/ui/gtkui/mainwindow.py index 85378ee9b..f7a6d2b5a 100644 --- a/deluge/ui/gtkui/mainwindow.py +++ b/deluge/ui/gtkui/mainwindow.py @@ -64,7 +64,7 @@ class MainWindow(component.Component): self.window = self.main_glade.get_widget("main_window") self.window.set_icon(common.get_deluge_icon()) - + self.vpaned = self.main_glade.get_widget("vpaned") self.initial_vpaned_position = self.config["window_pane_position"] @@ -103,14 +103,20 @@ class MainWindow(component.Component): def show(self): try: - self.resume_components() + component.resume("TorrentView") + component.resume("StatusBar") + component.resume("TorrentDetails") except: pass self.window.show() + 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 self.window_x_pos = self.window.get_position()[0] self.window_y_pos = self.window.get_position()[1] @@ -124,31 +130,15 @@ class MainWindow(component.Component): except: pass try: - self.resume_components() + component.resume("TorrentView") + component.resume("StatusBar") + component.resume("TorrentDetails") except: pass self.window.present() 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): """Returns True if the window is active, False if not.""" return self.window.is_active() @@ -191,12 +181,14 @@ class MainWindow(component.Component): if event.changed_mask & gtk.gdk.WINDOW_STATE_ICONIFIED: if event.new_window_state & gtk.gdk.WINDOW_STATE_ICONIFIED: log.debug("MainWindow is minimized..") - self.pause_components() + component.pause("TorrentView") + component.pause("StatusBar") self.is_minimized = True else: log.debug("MainWindow is not minimized..") try: - self.resume_components() + component.resume("TorrentView") + component.resume("StatusBar") except: pass self.is_minimized = False diff --git a/deluge/ui/gtkui/systemtray.py b/deluge/ui/gtkui/systemtray.py index 70f8bd64c..6ccfeb332 100644 --- a/deluge/ui/gtkui/systemtray.py +++ b/deluge/ui/gtkui/systemtray.py @@ -165,7 +165,7 @@ class SystemTray(component.Component): self.tray.set_tooltip(_("Deluge\nNot Connected..")) def shutdown(self): - if self.config["enable_system_tray"]: + if self.config["enable_system_tray"]: self.tray.set_visible(False) def send_status_request(self): @@ -196,6 +196,9 @@ class SystemTray(component.Component): self.upload_rate = deluge.common.fsize(upload_rate) def update(self): + if not self.config["enable_system_tray"]: + return + # Set the tool tip text max_download_speed = self.max_download_speed max_upload_speed = self.max_upload_speed