diff --git a/deluge/ui/gtk3/glade/preferences_dialog.ui b/deluge/ui/gtk3/glade/preferences_dialog.ui index 4cfceddcf..4b223cb44 100644 --- a/deluge/ui/gtk3/glade/preferences_dialog.ui +++ b/deluge/ui/gtk3/glade/preferences_dialog.ui @@ -478,6 +478,23 @@ 1 + + + Detect torrent URLs from clipboard + True + True + False + Automatically open Add Torrent dialog when clipboard contains a torrent URL + start + True + + + + True + True + 2 + + True @@ -501,7 +518,7 @@ and daemon (does not apply in Standalone mode). True True - 2 + 3 @@ -697,7 +714,7 @@ and daemon (does not apply in Standalone mode). False False - 3 + 4 diff --git a/deluge/ui/gtk3/gtkui.py b/deluge/ui/gtk3/gtkui.py index 74f29384e..02b309078 100644 --- a/deluge/ui/gtk3/gtkui.py +++ b/deluge/ui/gtk3/gtkui.py @@ -130,6 +130,7 @@ DEFAULT_PREFS = { 'show_rate_in_title': False, 'createtorrent.trackers': [], 'show_piecesbar': False, + 'detect_urls': True, 'pieces_color_missing': [65535, 0, 0], 'pieces_color_waiting': [4874, 56494, 0], 'pieces_color_downloading': [65535, 55255, 0], diff --git a/deluge/ui/gtk3/mainwindow.py b/deluge/ui/gtk3/mainwindow.py index 740a9d13a..b7d751410 100644 --- a/deluge/ui/gtk3/mainwindow.py +++ b/deluge/ui/gtk3/mainwindow.py @@ -20,11 +20,11 @@ from twisted.internet import reactor from twisted.internet.error import ReactorNotRunning import deluge.component as component -from deluge.common import decode_bytes, fspeed, resource_filename +from deluge.common import decode_bytes, fspeed, is_magnet, is_url, resource_filename from deluge.configmanager import ConfigManager from deluge.ui.client import client -from .common import get_deluge_icon, windowing +from .common import get_clipboard_text, get_deluge_icon, windowing from .dialogs import PasswordDialog from .ipcinterface import process_args @@ -132,6 +132,7 @@ class MainWindow(component.Component): self.window.connect('configure-event', self.on_window_configure_event) self.window.connect('delete-event', self.on_window_delete_event) self.window.connect('drag-data-received', self.on_drag_data_received_event) + self.window.connect('notify::is-active', self.on_focus) self.tabsbar_pane.connect( 'notify::position', self.on_tabsbar_pane_position_event ) @@ -148,6 +149,9 @@ class MainWindow(component.Component): 'NewVersionAvailableEvent', self.on_newversionavailable_event ) + self.previous_clipboard_text = '' + self.first_run = True + def connect_signals(self, mapping_or_class): self.gtk_builder_signals_holder.connect_signals(mapping_or_class) @@ -330,6 +334,19 @@ class MainWindow(component.Component): def on_expose_event(self, widget, event): component.get('SystemTray').blink(False) + def on_focus(self, window, param): + if window.props.is_active and not self.first_run and self.config['detect_urls']: + text = get_clipboard_text() + if text == self.previous_clipboard_text: + return + self.previous_clipboard_text = text + if text and ( + (is_url(text) and text.endswith('.torrent')) or is_magnet(text) + ): + component.get('AddTorrentDialog').show() + component.get('AddTorrentDialog').on_button_url_clicked(window) + self.first_run = False + def stop(self): self.window.set_title('Deluge') diff --git a/deluge/ui/gtk3/preferences.py b/deluge/ui/gtk3/preferences.py index ec4b3265a..13930fc55 100644 --- a/deluge/ui/gtk3/preferences.py +++ b/deluge/ui/gtk3/preferences.py @@ -570,6 +570,9 @@ class Preferences(component.Component): self.builder.get_object('piecesbar_toggle').set_active( self.gtkui_config['show_piecesbar'] ) + self.builder.get_object('urldetect_toggle').set_active( + self.gtkui_config['detect_urls'] + ) self.__set_color('completed', from_config=True) self.__set_color('downloading', from_config=True) self.__set_color('waiting', from_config=True) @@ -1461,6 +1464,9 @@ class Preferences(component.Component): colors_widget = self.builder.get_object('piecebar_colors_expander') colors_widget.set_visible(widget.get_active()) + def on_urldetect_toggle_toggled(self, widget): + self.gtkui_config['detect_urls'] = widget.get_active() + def on_checkbutton_language_toggled(self, widget): self.language_combo.set_visible(not self.language_checkbox.get_active())