Ticket #2411: path-mapping.patch

File path-mapping.patch, 7.7 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..de24c4e 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
     267from deluge.configmanager import ConfigManager
     268def files_available():
     269    return client.is_localhost() or ConfigManager("gtkui.conf")["pathmapping"]
     270
     271def open_file(path):
     272    open_file = True
     273    if not client.is_localhost():
     274        from re import subn
     275        open_file = False
     276        pathmapping = ConfigManager("gtkui.conf")["pathmapping"]
     277        if not pathmapping:
     278            return
     279        for mapstr in pathmapping.splitlines():
     280            mapping = mapstr.split('=', 2)
     281            if(len(mapping) < 2):
     282                continue
     283            path, open_file = subn('^%s' % mapping[0], mapping[1], path)
     284            if(open_file):
     285                break
     286    if open_file:
     287        deluge.common.open_file(path)
  • deluge/ui/gtkui/connectionmanager.py

    diff --git a/deluge/ui/gtkui/connectionmanager.py b/deluge/ui/gtkui/connectionmanager.py
    index 71aab09..9e1b3dd 100644
    a b def __load_options(self):  
    327327        self.glade.get_widget("chk_autoconnect").set_active(self.gtkui_config["autoconnect"])
    328328        self.glade.get_widget("chk_autostart").set_active(self.gtkui_config["autostart_localhost"])
    329329        self.glade.get_widget("chk_donotshow").set_active(not self.gtkui_config["show_connection_manager_on_start"])
     330        self.glade.get_widget("entry_pathmapping").get_buffer().set_text(self.gtkui_config["pathmapping"])
    330331
    331332    def __save_options(self):
    332333        """
    def __save_options(self):  
    335336        self.gtkui_config["autoconnect"] = self.glade.get_widget("chk_autoconnect").get_active()
    336337        self.gtkui_config["autostart_localhost"] = self.glade.get_widget("chk_autostart").get_active()
    337338        self.gtkui_config["show_connection_manager_on_start"] = not self.glade.get_widget("chk_donotshow").get_active()
     339        buffer = self.glade.get_widget("entry_pathmapping").get_buffer()
     340        self.gtkui_config["pathmapping"] = buffer.get_text(*buffer.get_bounds())
    338341
    339342    def __update_buttons(self):
    340343        """
  • deluge/ui/gtkui/files_tab.py

    diff --git a/deluge/ui/gtkui/files_tab.py b/deluge/ui/gtkui/files_tab.py
    index 0856f36..2ae2ef5 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 deluge.ui.gtkui.common.files_available() 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 deluge.ui.gtkui.common.files_available():
    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/glade/connection_manager.glade

    diff --git a/deluge/ui/gtkui/glade/connection_manager.glade b/deluge/ui/gtkui/glade/connection_manager.glade
    index cfe3906..61de802 100644
    a b  
    449449                        <property name="position">2</property>
    450450                      </packing>
    451451                    </child>
     452                    <child>
     453                      <widget class="GtkVBox" id="vbox_pathmapping">
     454                        <property name="visible">True</property>
     455                        <property name="can_focus">False</property>
     456                        <child>
     457                          <widget class="GtkLabel" id="label_pathmapping">
     458                            <property name="visible">True</property>
     459                            <property name="can_focus">False</property>
     460                            <property name="xalign">0</property>
     461                            <property name="label" translatable="yes">Path Mapping
     462Example:
     463/path/on/server=/local/path
     464/another/remote/path=/another/local/path</property>
     465                          </widget>
     466                          <packing>
     467                            <property name="expand">True</property>
     468                            <property name="fill">True</property>
     469                            <property name="position">0</property>
     470                          </packing>
     471                        </child>
     472                        <child>
     473                          <widget class="GtkTextView" id="entry_pathmapping">
     474                            <property name="height_request">48</property>
     475                            <property name="visible">True</property>
     476                            <property name="can_focus">True</property>
     477                            <property name="accepts_tab">False</property>
     478                          </widget>
     479                          <packing>
     480                            <property name="expand">True</property>
     481                            <property name="fill">True</property>
     482                            <property name="position">1</property>
     483                          </packing>
     484                        </child>
     485                      </widget>
     486                      <packing>
     487                        <property name="expand">True</property>
     488                        <property name="fill">True</property>
     489                        <property name="position">3</property>
     490                      </packing>
     491                    </child>
    452492                  </widget>
    453493                </child>
    454494              </widget>
  • deluge/ui/gtkui/gtkui.py

    diff --git a/deluge/ui/gtkui/gtkui.py b/deluge/ui/gtkui/gtkui.py
    index bbe1195..843b754 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    "pathmapping": "",
    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..d8ab4b2 100644
    a b def start(self):  
    184184            "menuitem_open_folder",
    185185            "separator4"
    186186        ]
    187         if not client.is_localhost():
     187        if not deluge.ui.gtkui.common.files_available():
    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