[master 4/8] Move the URL protocol removal out of the input check
dashea
installerbot-noreply at redhat.com
Wed Jun 17 18:07:14 UTC 2015
From: David Shea <dshea at redhat.com>
This is the code that automatically removes the http:// part of the URL
when you paste in a URL. This should be run right away instead of
waiting for the input validation timer, so move it out of the validation
function and into a separate signal handler.
---
pyanaconda/ui/gui/spokes/source.glade | 1 +
pyanaconda/ui/gui/spokes/source.py | 45 +++++++++++++++++++++++------------
2 files changed, 31 insertions(+), 15 deletions(-)
diff --git a/pyanaconda/ui/gui/spokes/source.glade b/pyanaconda/ui/gui/spokes/source.glade
index 0abbe9f..e8c3640 100644
--- a/pyanaconda/ui/gui/spokes/source.glade
+++ b/pyanaconda/ui/gui/spokes/source.glade
@@ -765,6 +765,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
+ <signal name="changed" handler="on_urlEntry_changed" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
diff --git a/pyanaconda/ui/gui/spokes/source.py b/pyanaconda/ui/gui/spokes/source.py
index ed259a3..120d7da 100644
--- a/pyanaconda/ui/gui/spokes/source.py
+++ b/pyanaconda/ui/gui/spokes/source.py
@@ -926,22 +926,11 @@ def _checkURL(self, inputcheck, combo):
if not m:
return _("Invalid URL")
- # If there is a protocol in the URL, and the protocol matches the
- # combo box, just remove it. This makes it more convenient to paste
- # in URLs. It'll probably freak out people who are typing out http://
- # in the box themselves, but why would you do that? Don't do that.
- # If the protocols don't match, complain.
+ # Matching protocols in the URL should already have been removed
+ # by _removeUrlPrefix. If there's still one there, it's wrong.
url_protocol = m.group('protocol')
if url_protocol:
- if (url_protocol == 'http://' and combo_protocol == PROTOCOL_HTTP) or \
- (url_protocol == 'https://' and combo_protocol == PROTOCOL_HTTPS) or \
- (url_protocol == 'ftp://' and combo_protocol == PROTOCOL_FTP):
- # Disable the check to block a recursive check call
- inputcheck.enabled = False
- inputcheck.input_obj.set_text(url_string[len(url_protocol):])
- inputcheck.enabled = True
- else:
- return _("Protocol in URL does not match selected protocol")
+ return _("Protocol in URL does not match selected protocol")
elif combo_protocol == PROTOCOL_NFS:
if not url_string:
return _("NFS server is empty")
@@ -1305,6 +1294,29 @@ def _update_repo_info(self, repo):
log.error("Failed to parse proxy for repo %s: %s", repo.name, e)
return
+ def _removeUrlPrefix(self, editable, combo, handler):
+ # If there is a protocol in the URL, and the protocol matches the
+ # combo box, just remove it. This makes it more convenient to paste
+ # in URLs. It'll probably freak out people who are typing out http://
+ # in the box themselves, but why would you do that? Don't do that.
+
+ combo_protocol = combo.get_active_id()
+ if combo_protocol in (PROTOCOL_HTTP, PROTOCOL_HTTPS, PROTOCOL_FTP):
+ url_string = editable.get_text()
+ m = URL_PARSE.match(url_string)
+ if m:
+ url_protocol = m.group('protocol')
+ if (url_protocol == 'http://' and combo_protocol == PROTOCOL_HTTP) or \
+ (url_protocol == 'https://' and combo_protocol == PROTOCOL_HTTPS) or \
+ (url_protocol == 'ftp://' and combo_protocol == PROTOCOL_FTP):
+ # URL protocol matches. Block the changed signal and remove it
+ with blockedHandler(editable, handler):
+ editable.set_text(url_string[len(url_protocol):])
+
+ def on_urlEntry_changed(self, editable, data=None):
+ # Check for and remove a URL prefix that matches the protocol dropdown
+ self._removeUrlPrefix(editable, self._protocolComboBox, self.on_urlEntry_changed)
+
def on_noUpdatesCheckbox_toggled(self, *args):
""" Toggle the enable state of the updates repo
@@ -1376,7 +1388,7 @@ def on_repoNameEntry_changed(self, entry):
del self._repoChecks[old_name]
self._repoChecks[name].name_check.update_check_status()
- def on_repoUrl_changed(self, *args):
+ def on_repoUrl_changed(self, editable, data=None):
""" proxy url or protocol changed
"""
itr = self._repoSelection.get_selected()[1]
@@ -1393,6 +1405,9 @@ def on_repoUrl_changed(self, *args):
self._repoChecks[repo.name].url_check.update_check_status()
+ # Check for and remove a URL prefix that matches the protocol dropdown
+ self._removeUrlPrefix(editable, self._repoProtocolComboBox, self.on_repoUrl_changed)
+
def on_repoMirrorlistCheckbox_toggled(self, *args):
""" mirror state changed
"""
--
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/8d277417dd58176dde7bca1c42a6118f7afde005
More information about the anaconda-patches
mailing list