From d75afc007dcc5b45ab1f99432e98e286f758060f Mon Sep 17 00:00:00 2001 From: Matias Wilkman Date: Tue, 21 Feb 2017 22:05:42 +0200 Subject: [PATCH] [GTKUI] Parse u:p@host:port pasted into proxy or connection manager --- deluge/ui/gtkui/connectionmanager.py | 16 ++++++++++++++++ .../gtkui/glade/connection_manager.addhost.ui | 1 + deluge/ui/gtkui/glade/preferences_dialog.ui | 1 + deluge/ui/gtkui/preferences.py | 17 +++++++++++++++++ 4 files changed, 35 insertions(+) diff --git a/deluge/ui/gtkui/connectionmanager.py b/deluge/ui/gtkui/connectionmanager.py index 0192f7956..90b467ee5 100644 --- a/deluge/ui/gtkui/connectionmanager.py +++ b/deluge/ui/gtkui/connectionmanager.py @@ -14,6 +14,7 @@ import logging import os import time from socket import gethostbyname +from urlparse import urlparse import gtk from twisted.internet import reactor @@ -235,6 +236,21 @@ class ConnectionManager(component.Component): # Update the status of the hosts self.__update_list() + def on_entry_host_paste_clipboard(self, widget): + text = gtk.clipboard_get().wait_for_text().strip() + log.debug('on_entry_proxy_host_paste-clipboard: got paste: %s', text) + text = text if '//' in text else '//' + text + parsed = urlparse(text) + if parsed.hostname: + widget.set_text(parsed.hostname) + widget.emit_stop_by_name('paste-clipboard') + if parsed.port: + self.builder.get_object('spinbutton_port').set_value(parsed.port) + if parsed.username: + self.builder.get_object('entry_username').set_text(parsed.username) + if parsed.password: + self.builder.get_object('entry_password').set_text(parsed.password) + # Private methods def __save_hostlist(self): """ diff --git a/deluge/ui/gtkui/glade/connection_manager.addhost.ui b/deluge/ui/gtkui/glade/connection_manager.addhost.ui index 7cb247998..21972260b 100644 --- a/deluge/ui/gtkui/glade/connection_manager.addhost.ui +++ b/deluge/ui/gtkui/glade/connection_manager.addhost.ui @@ -114,6 +114,7 @@ False True True + diff --git a/deluge/ui/gtkui/glade/preferences_dialog.ui b/deluge/ui/gtkui/glade/preferences_dialog.ui index 5533df75d..b763e56f5 100644 --- a/deluge/ui/gtkui/glade/preferences_dialog.ui +++ b/deluge/ui/gtkui/glade/preferences_dialog.ui @@ -3524,6 +3524,7 @@ used sparingly. False True True + 1 diff --git a/deluge/ui/gtkui/preferences.py b/deluge/ui/gtkui/preferences.py index 2e424549c..83b41d900 100644 --- a/deluge/ui/gtkui/preferences.py +++ b/deluge/ui/gtkui/preferences.py @@ -13,6 +13,7 @@ from __future__ import unicode_literals import logging import os from hashlib import sha1 as sha +from urlparse import urlparse import gtk from gtk.gdk import Color @@ -136,6 +137,7 @@ class Preferences(component.Component): 'on_button_cache_refresh_clicked': self._on_button_cache_refresh_clicked, 'on_combo_encryption_changed': self._on_combo_encryption_changed, 'on_combo_proxy_type_changed': self._on_combo_proxy_type_changed, + 'on_entry_proxy_host_paste_clipboard': self._on_entry_proxy_host_paste_clipboard, 'on_button_associate_magnet_clicked': self._on_button_associate_magnet_clicked, 'on_accounts_add_clicked': self._on_accounts_add_clicked, 'on_accounts_delete_clicked': self._on_accounts_delete_clicked, @@ -980,6 +982,21 @@ class Preferences(component.Component): else: self.builder.get_object(entry).hide() + def _on_entry_proxy_host_paste_clipboard(self, widget): + text = gtk.clipboard_get().wait_for_text().strip() + log.debug('on_entry_proxy_host_paste-clipboard: got paste: %s', text) + text = text if '//' in text else '//' + text + parsed = urlparse(text) + if parsed.hostname: + widget.set_text(parsed.hostname) + widget.emit_stop_by_name('paste-clipboard') + if parsed.port: + self.builder.get_object('spin_proxy_port').set_value(parsed.port) + if parsed.username: + self.builder.get_object('entry_proxy_user').set_text(parsed.username) + if parsed.password: + self.builder.get_object('entry_proxy_pass').set_text(parsed.password) + def _on_button_associate_magnet_clicked(self, widget): associate_magnet_links(True)