Ticket #2411: path-mapping-multihost-noui.patch

File path-mapping-multihost-noui.patch, 3.9 KB (added by eerorika, 11 years ago)
  • deluge/ui/gtkui/common.py

    diff --git a/deluge/ui/gtkui/common.py b/deluge/ui/gtkui/common.py
    index a7715ed..74f04e7 100644
    a b def associate_magnet_links(overwrite=False):  
    263263                    log.error("Unable to register Deluge as default magnet uri handler.")
    264264                    return False
    265265    return False
     266
     267def current_path_mapping():
     268    from deluge.configmanager import ConfigManager
     269    host_mapping = ConfigManager("gtkui.conf")["path_mapping"]
     270    host, _, _ = client.connection_info()
     271    return host_mapping[host] if host in host_mapping else []
     272
     273def open_file(filepath):
     274    if client.is_localhost():
     275        return deluge.common.open_file(filepath)
     276    from re import subn
     277    from os import sep, path
     278    for local, remote in current_path_mapping():
     279        sub_path, match_found = subn("^%s" % remote, "", filepath)
     280        if(match_found):
     281            filepath = path.join(local, sub_path.lstrip(sep))
     282            return deluge.common.open_file(filepath)
  • deluge/ui/gtkui/files_tab.py

    diff --git a/deluge/ui/gtkui/files_tab.py b/deluge/ui/gtkui/files_tab.py
    index 0856f36..33bb08d 100644
    a b def __init__(self):  
    237237        self.torrent_id = None
    238238
    239239    def start(self):
    240         attr = "hide" if not client.is_localhost() else "show"
     240        attr = "hide" if not (client.is_localhost() or deluge.ui.gtkui.common.current_path_mapping()) else "show"
    241241        for widget in self.localhost_widgets:
    242242            getattr(widget, attr)()
    243243
    def clear(self):  
    341341        self.torrent_id = None
    342342
    343343    def _on_row_activated(self, tree, path, view_column):
    344         if client.is_localhost:
     344        if client.is_localhost() or deluge.ui.gtkui.common.current_path_mapping():
    345345            component.get("SessionProxy").get_torrent_status(self.torrent_id, ["save_path", "files"]).addCallback(self._on_open_file)
    346346
    347347    def get_file_path(self, row, path=""):
    def _on_open_file(self, status):  
    361361            path = self.get_file_path(select).split("/")
    362362            filepath = os.path.join(status["save_path"], *path)
    363363            log.debug("Open file '%s'", filepath)
    364             deluge.common.open_file(filepath)
     364            deluge.ui.gtkui.common.open_file(filepath)
    365365
    366366    ## The following 3 methods create the folder/file view in the treeview
    367367    def prepare_file_store(self, files):
  • deluge/ui/gtkui/gtkui.py

    diff --git a/deluge/ui/gtkui/gtkui.py b/deluge/ui/gtkui/gtkui.py
    index bbe1195..8ec03a5 100644
    a b def start():  
    167167    "sidebar_position": 170,
    168168    "show_rate_in_title": False,
    169169    "focus_main_window_on_add": True,
    170     "createtorrent.trackers": []
     170    "createtorrent.trackers": [],
     171    "path_mapping": {},
    171172}
    172173
    173174class GtkUI(object):
  • deluge/ui/gtkui/menubar.py

    diff --git a/deluge/ui/gtkui/menubar.py b/deluge/ui/gtkui/menubar.py
    index 214c4b7..7aa7ce6 100644
    a b def start(self):  
    184184            "menuitem_open_folder",
    185185            "separator4"
    186186        ]
    187         if not client.is_localhost():
     187        if not (client.is_localhost() or deluge.ui.gtkui.common.current_path_mapping()):
    188188            for widget in non_remote_items:
    189189                self.torrentmenu_glade.get_widget(widget).hide()
    190190                self.torrentmenu_glade.get_widget(widget).set_no_show_all(True)
    def on_menuitem_recheck_activate(self, data=None):  
    306306    def on_menuitem_open_folder_activate(self, data=None):
    307307        log.debug("on_menuitem_open_folder")
    308308        def _on_torrent_status(status):
    309             deluge.common.open_file(status["save_path"])
     309            deluge.ui.gtkui.common.open_file(status["save_path"])
    310310        for torrent_id in component.get("TorrentView").get_selected_torrents():
    311311            component.get("SessionProxy").get_torrent_status(torrent_id, ["save_path"]).addCallback(_on_torrent_status)
    312312