[GTKUI] Parse u:p@host:port pasted into proxy or connection manager

This commit is contained in:
Matias Wilkman 2017-02-21 22:05:42 +02:00 committed by Calum Lind
parent b32c5d8247
commit d75afc007d
4 changed files with 35 additions and 0 deletions

View File

@ -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):
"""

View File

@ -114,6 +114,7 @@
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
<signal name="paste-clipboard" handler="on_entry_host_paste_clipboard" />
</object>
</child>
</object>

View File

@ -3524,6 +3524,7 @@ used sparingly.</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
<signal name="paste-clipboard" handler="on_entry_proxy_host_paste_clipboard" />
</object>
<packing>
<property name="left_attach">1</property>

View File

@ -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)