diff options
author | Matias Wilkman <matias.wilkman@gmail.com> | 2021-02-15 14:07:01 -0500 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2021-10-03 19:34:09 +0100 |
commit | d56636426e061931fdf58118487705f9746fa3fe (patch) | |
tree | bc8eda7630128f7f04296ef13cae9177fec1fb2f /deluge/ui/gtk3/mainwindow.py | |
parent | de4fbd2e8223031484d439ca99bce89785ea5db3 (diff) | |
download | deluge-d56636426e061931fdf58118487705f9746fa3fe.tar.gz deluge-d56636426e061931fdf58118487705f9746fa3fe.tar.bz2 deluge-d56636426e061931fdf58118487705f9746fa3fe.zip |
[GTKUI] Added detection of torrent URL on GTK UI focus
In case deluge GTK gets focus with a new torrent URL on the clipboard,
the "Add Torrent from URL" dialog will pop up automatically
Closes: deluge-torrent/deluge#306
Diffstat (limited to 'deluge/ui/gtk3/mainwindow.py')
-rw-r--r-- | deluge/ui/gtk3/mainwindow.py | 21 |
1 files changed, 19 insertions, 2 deletions
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') |