diff --git a/deluge/data/pixmaps/magnet.png b/deluge/data/pixmaps/magnet.png new file mode 100644 index 000000000..a192cd8ad Binary files /dev/null and b/deluge/data/pixmaps/magnet.png differ diff --git a/deluge/ui/gtkui/common.py b/deluge/ui/gtkui/common.py index 66327c8c5..5b25fa537 100644 --- a/deluge/ui/gtkui/common.py +++ b/deluge/ui/gtkui/common.py @@ -228,3 +228,35 @@ def get_deluge_icon(): return icon_theme.load_icon("deluge", 64, 0) except: return get_logo(64) + +def associate_magnet_links(overwrite=False): + """ + Associates magnet links to Deluge. + + :param overwrite: if this is True, the current setting will be overwritten + :type overwrite: bool + :returns: True if association was set + :rtype: bool + + """ + if not deluge.common.windows_check(): + # gconf method is only available in a GNOME environment + try: + import gconf + except ImportError: + log.debug("gconf not available, so will not attempt to register magnet uri handler") + return False + else: + key = "/desktop/gnome/url-handlers/magnet/command" + gconf_client = gconf.client_get_default() + if (gconf_client.get(key) and overwrite) or not gconf_client.get(key): + # We are either going to overwrite the key, or do it if it hasn't been set yet + if gconf_client.set_string(key, "deluge '%s'"): + gconf_client.set_bool("/desktop/gnome/url-handlers/magnet/needs_terminal", False) + gconf_client.set_bool("/desktop/gnome/url-handlers/magnet/enabled", True) + log.info("Deluge registered as default magnet uri handler!") + return True + else: + log.error("Unable to register Deluge as default magnet uri handler.") + return False + return False diff --git a/deluge/ui/gtkui/glade/preferences_dialog.glade b/deluge/ui/gtkui/glade/preferences_dialog.glade index ab9e1257a..b8921b320 100644 --- a/deluge/ui/gtkui/glade/preferences_dialog.glade +++ b/deluge/ui/gtkui/glade/preferences_dialog.glade @@ -17,6 +17,7 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical 2 @@ -65,6 +66,7 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical True @@ -498,6 +500,7 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical True @@ -537,6 +540,7 @@ True + vertical True @@ -734,6 +738,7 @@ True + vertical 5 @@ -905,6 +910,7 @@ True + vertical True @@ -1104,6 +1110,7 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical True @@ -1135,6 +1142,7 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical True @@ -1168,6 +1176,7 @@ Either True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical True @@ -1281,6 +1290,7 @@ Disabled True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical True @@ -1320,6 +1330,7 @@ Disabled True + vertical 5 @@ -1778,6 +1789,7 @@ Disabled True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical True @@ -1863,6 +1875,7 @@ Disabled True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical Show session speed in titlebar @@ -1913,6 +1926,7 @@ Disabled True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical Always show @@ -1982,6 +1996,7 @@ Disabled True + vertical Enable system tray icon @@ -2160,6 +2175,7 @@ Disabled True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical True @@ -2201,6 +2217,7 @@ Disabled True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical True @@ -2262,6 +2279,7 @@ Disabled True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical True @@ -2337,6 +2355,7 @@ Disabled True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical True @@ -2399,6 +2418,60 @@ Disabled 4 + + + True + 12 + + + True + start + + + True + True + True + + + + True + 2 + + + True + gtk-missing-image + + + 0 + + + + + True + Associate Magnet links with Deluge + + + 1 + + + + + + + False + False + 0 + + + + + + + False + False + 5 + + @@ -2436,6 +2509,7 @@ Disabled True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical True @@ -2477,6 +2551,7 @@ Disabled True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical True @@ -2661,6 +2736,7 @@ Disabled True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical True @@ -2690,6 +2766,7 @@ Disabled True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical 5 @@ -2707,6 +2784,7 @@ Disabled True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical Queue new torrents to top @@ -2757,6 +2835,7 @@ Disabled True + vertical 5 @@ -2908,6 +2987,7 @@ Disabled True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical 2 @@ -3133,6 +3213,7 @@ Disabled True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical True @@ -3160,6 +3241,7 @@ Disabled True + vertical 5 @@ -3936,6 +4018,7 @@ HTTP W/ Auth True + vertical True @@ -3967,6 +4050,7 @@ HTTP W/ Auth True + vertical True @@ -4076,6 +4160,7 @@ HTTP W/ Auth True + vertical True @@ -4467,15 +4552,6 @@ HTTP W/ Auth tab - - - - - - - tab - - True @@ -4493,6 +4569,7 @@ HTTP W/ Auth True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical True @@ -4523,6 +4600,7 @@ HTTP W/ Auth True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical True @@ -4881,7 +4959,7 @@ HTTP W/ Auth - 10 + 9 @@ -4890,6 +4968,15 @@ HTTP W/ Auth tab + + + + + + + tab + + True diff --git a/deluge/ui/gtkui/gtkui.py b/deluge/ui/gtkui/gtkui.py index c41ff3619..ae7941c52 100644 --- a/deluge/ui/gtkui/gtkui.py +++ b/deluge/ui/gtkui/gtkui.py @@ -81,6 +81,7 @@ from deluge.ui.tracker_icons import TrackerIcons from queuedtorrents import QueuedTorrents from addtorrentdialog import AddTorrentDialog import dialogs +import common import deluge.configmanager import deluge.common @@ -180,21 +181,9 @@ class GtkUI(object): return 1 SetConsoleCtrlHandler(win_handler) - # Attempt to register a magnet URI handler with gconf - try: - import gconf - except ImportError: - log.debug("gconf not available, so will not attempt to register magnet uri handler") - else: - key = "/desktop/gnome/url-handlers/magnet/command" - gconf_client = gconf.client_get_default() - if not gconf_client.get(key): - if gconf_client.set_string(key, "deluge '%s'"): - gconf_client.set_bool("/desktop/gnome/url-handlers/magnet/needs_terminal", False) - gconf_client.set_bool("/desktop/gnome/url-handlers/magnet/enabled", True) - log.info("Deluge registered as default magnet uri handler!") - else: - log.error("Unable to register Deluge as default magnet uri handler.") + # Attempt to register a magnet URI handler with gconf, but do not overwrite + # if already set by another program. + common.associate_magnet_links(False) # Make sure gtkui.conf has at least the defaults set self.config = deluge.configmanager.ConfigManager("gtkui.conf", DEFAULT_PREFS) diff --git a/deluge/ui/gtkui/preferences.py b/deluge/ui/gtkui/preferences.py index a9c6b7a4d..0abf7dbb6 100644 --- a/deluge/ui/gtkui/preferences.py +++ b/deluge/ui/gtkui/preferences.py @@ -60,6 +60,10 @@ class Preferences(component.Component): self.treeview = self.glade.get_widget("treeview") self.notebook = self.glade.get_widget("notebook") self.gtkui_config = ConfigManager("gtkui.conf") + + self.glade.get_widget("image_magnet").set_from_file( + deluge.common.get_pixmap("magnet.png")) + # Setup the liststore for the categories (tab pages) self.liststore = gtk.ListStore(int, str) self.treeview.set_model(self.liststore) @@ -105,7 +109,8 @@ class Preferences(component.Component): "on_button_rescan_plugins_clicked": self._on_button_rescan_plugins_clicked, "on_button_find_plugins_clicked": self._on_button_find_plugins_clicked, "on_button_cache_refresh_clicked": self._on_button_cache_refresh_clicked, - "on_combo_proxy_type_changed": self._on_combo_proxy_type_changed + "on_combo_proxy_type_changed": self._on_combo_proxy_type_changed, + "on_button_associate_magnet_clicked": self._on_button_associate_magnet_clicked }) # These get updated by requests done to the core @@ -927,3 +932,6 @@ class Preferences(component.Component): w = self.glade.get_widget(p + s + "_" + name) if w: w.show() + + def _on_button_associate_magnet_clicked(self, widget): + common.associate_magnet_links(True)