Ticket #2411: remote-path.patch

File remote-path.patch, 8.5 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..afce40a 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 path_to_local(path):
     272    from re import subn
     273    pathmapping = ConfigManager("gtkui.conf")["pathmapping"]
     274    found_count = 0
     275    if not pathmapping:
     276        return path, found_count
     277    for mapstr in pathmapping.splitlines():
     278        mapping = mapstr.split('=', 2)
     279        if(len(mapping) < 2):
     280            continue
     281        path, found_count = subn('^%s' % mapping[0], mapping[1], path)
     282        if(found_count):
     283            break
     284    return path, found_count
  • 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..f239ec4 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        from deluge.ui.gtkui.common import files_available
     241        attr = "hide" if not files_available() else "show"
    241242        for widget in self.localhost_widgets:
    242243            getattr(widget, attr)()
    243244
    def clear(self):  
    341342        self.torrent_id = None
    342343
    343344    def _on_row_activated(self, tree, path, view_column):
    344         if client.is_localhost:
     345        from deluge.ui.gtkui.common import files_available
     346        if files_available():
    345347            component.get("SessionProxy").get_torrent_status(self.torrent_id, ["save_path", "files"]).addCallback(self._on_open_file)
    346348
    347349    def get_file_path(self, row, path=""):
    def get_file_path(self, row, path=""):  
    352354        return self.get_file_path(self.treestore.iter_parent(row), path)
    353355
    354356    def _on_open_file(self, status):
     357        save_path = status["save_path"]
     358        open_file = True
     359        if not client.is_localhost():
     360            from deluge.ui.gtkui.common import path_to_local
     361            save_path, open_file = path_to_local(save_path)
     362        if not open_file:
     363            return
    355364        paths = self.listview.get_selection().get_selected_rows()[1]
    356365        selected = []
    357366        for path in paths:
    358367            selected.append(self.treestore.get_iter(path))
    359 
    360368        for select in selected:
    361369            path = self.get_file_path(select).split("/")
    362             filepath = os.path.join(status["save_path"], *path)
     370            filepath = os.path.join(save_path, *path)
    363371            log.debug("Open file '%s'", filepath)
    364372            deluge.common.open_file(filepath)
    365373
  • 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..78cc64a 100644
    a b def start(self):  
    184184            "menuitem_open_folder",
    185185            "separator4"
    186186        ]
    187         if not client.is_localhost():
     187        from deluge.ui.gtkui.common import files_available
     188        if not files_available():
    188189            for widget in non_remote_items:
    189190                self.torrentmenu_glade.get_widget(widget).hide()
    190191                self.torrentmenu_glade.get_widget(widget).set_no_show_all(True)
    def on_menuitem_recheck_activate(self, data=None):  
    306307    def on_menuitem_open_folder_activate(self, data=None):
    307308        log.debug("on_menuitem_open_folder")
    308309        def _on_torrent_status(status):
    309             deluge.common.open_file(status["save_path"])
     310            save_path = status["save_path"]
     311            open_file = True
     312            if not client.is_localhost():
     313                from deluge.ui.gtkui.common import path_to_local
     314                save_path, open_file = path_to_local(save_path)
     315            if(open_file):
     316                deluge.common.open_file(save_path)
    310317        for torrent_id in component.get("TorrentView").get_selected_torrents():
    311318            component.get("SessionProxy").get_torrent_status(torrent_id, ["save_path"]).addCallback(_on_torrent_status)
    312319