Unify auto_search/addressbar_dns_lookup

This commit is contained in:
Florian Bruhin 2014-02-18 10:28:34 +01:00
parent 833da4a8e5
commit 88ea6e62b1
3 changed files with 24 additions and 10 deletions

1
TODO
View File

@ -46,7 +46,6 @@ Minor features
Hiding scrollbars Hiding scrollbars
:bind :bind
Ctrl+A/X to increase/decrease last number in URL Ctrl+A/X to increase/decrease last number in URL
unify dns/autosearch
position remembering position remembering
multiple commands with ; multiple commands with ;

View File

@ -20,16 +20,16 @@
# wrapsearch: bool, whether to wrap search to the top when arriving at the end. # wrapsearch: bool, whether to wrap search to the top when arriving at the end.
# startpage: The default pages to open at the start, multiple pages can be # startpage: The default pages to open at the start, multiple pages can be
# separated with commas. # separated with commas.
# addressbar_dns_lookup: bool, whether to do a lookup in the DNS to figure out # auto_search: Whether to start a search automatically when something
# if something is a search term or not. Might be slow. # which is not an url is entered.
# auto_search: bool, whether to start a search automatically when something # true/naive: Use simple/naive check
# which is not an url is entered. # dns: Use DNS matching (might be slow)
# false: Never search automatically
show_completion = true show_completion = true
ignorecase = true ignorecase = true
wrapsearch = true wrapsearch = true
startpage = http://www.duckduckgo.com/ startpage = http://www.duckduckgo.com/
addressbar_dns_lookup = false auto_search = fuzzy
auto_search = true
[tabbar] [tabbar]
# movable: bool, whether tabs should be movable # movable: bool, whether tabs should be movable

View File

@ -49,7 +49,7 @@ def fuzzy_url(url):
""" """
u = qurl(url) u = qurl(url)
urlstr = urlstring(url) urlstr = urlstring(url)
if (not config.config.getboolean('general', 'auto_search')) or is_url(u): if is_url(u):
# probably an address # probably an address
logging.debug("url is a fuzzy address") logging.debug("url is a fuzzy address")
newurl = QUrl.fromUserInput(urlstr) newurl = QUrl.fromUserInput(urlstr)
@ -94,14 +94,29 @@ def is_url(url):
"""Return True if url (QUrl) seems to be a valid URL.""" """Return True if url (QUrl) seems to be a valid URL."""
urlstr = urlstring(url) urlstr = urlstring(url)
logging.debug('Checking if "{}" is an URL'.format(urlstr)) logging.debug('Checking if "{}" is an URL'.format(urlstr))
try:
autosearch = config.config.getboolean('general', 'auto_search')
except ValueError:
autosearch = config.config.get('general', 'auto_search')
else:
if autosearch:
autosearch = 'naive'
else:
autosearch = None
if autosearch is None:
# no autosearch, so everything is an URL.
return True
if ' ' in urlstr: if ' ' in urlstr:
# An URL will never contain a space # An URL will never contain a space
logging.debug('Contains space -> no url') logging.debug('Contains space -> no url')
return False return False
elif config.config.getboolean('general', 'addressbar_dns_lookup'): elif autosearch == 'dns':
logging.debug('Checking via DNS') logging.debug('Checking via DNS')
return _is_url_dns(QUrl.fromUserInput(urlstr)) return _is_url_dns(QUrl.fromUserInput(urlstr))
else: elif autosearch == 'naive':
logging.debug('Checking via naive check') logging.debug('Checking via naive check')
return _is_url_naive(url) return _is_url_naive(url)