More config update/adoption
This commit is contained in:
parent
54e2ba4de2
commit
f079d6bf3b
@ -212,7 +212,7 @@ class QuteBrowser(QApplication):
|
||||
|
||||
if self.mainwindow.tabs.count() == 0:
|
||||
logging.debug('Opening startpage')
|
||||
for url in config.config.get('general', 'startpage').split(','):
|
||||
for url in config.config.get('general', 'startpage'):
|
||||
self.mainwindow.tabs.tabopen(url)
|
||||
|
||||
def _python_hacks(self):
|
||||
|
@ -245,14 +245,15 @@ class KeyParser(QObject):
|
||||
|
||||
"""
|
||||
for (key, cmd) in sect.items():
|
||||
if key.startswith('@') and key.endswith('@'):
|
||||
if key.value.startswith('@') and key.value.endswith('@'):
|
||||
# normalize keystring
|
||||
keystr = self._normalize_keystr(key.strip('@'))
|
||||
keystr = self._normalize_keystr(key.value.strip('@'))
|
||||
logging.debug('registered mod key: {} -> {}'.format(keystr,
|
||||
cmd))
|
||||
self._modifier_bindings[keystr] = cmd
|
||||
else:
|
||||
logging.debug('registered key: {} -> {}'.format(key, cmd))
|
||||
logging.debug('registered key: {} -> {}'.format(key.value,
|
||||
cmd))
|
||||
self._bindings[key] = cmd
|
||||
|
||||
def handle(self, e):
|
||||
|
@ -65,9 +65,9 @@ class SearchParser(QObject):
|
||||
self.do_search.emit('', 0)
|
||||
self._text = text
|
||||
self._flags = 0
|
||||
if config.config.getboolean('general', 'ignorecase', fallback=True):
|
||||
if config.config.get('general', 'ignorecase', fallback=True):
|
||||
self._flags |= QWebPage.FindCaseSensitively
|
||||
if config.config.getboolean('general', 'wrapsearch', fallback=True):
|
||||
if config.config.get('general', 'wrapsearch', fallback=True):
|
||||
self._flags |= QWebPage.FindWrapsAroundDocument
|
||||
if rev:
|
||||
self._flags |= QWebPage.FindBackward
|
||||
|
@ -45,11 +45,12 @@ def init(confdir):
|
||||
"""
|
||||
global config, state
|
||||
logging.debug("Config init, confdir {}".format(confdir))
|
||||
config = Config(confdir, 'qutebrowser.conf', read_file('qutebrowser.conf'))
|
||||
#config = Config(confdir, 'qutebrowser.conf', read_file('qutebrowser.conf'))
|
||||
config = NewConfig()
|
||||
state = Config(confdir, 'state', always_save=True)
|
||||
|
||||
|
||||
class ConfigStructure:
|
||||
class NewConfig:
|
||||
|
||||
"""Contains the structure of the config file."""
|
||||
|
||||
@ -109,7 +110,7 @@ class ConfigStructure:
|
||||
('tab.bg.selected', opt.TabSelectedBgColor()),
|
||||
('tab.seperator', opt.TabSeperatorColor()),
|
||||
)),
|
||||
('fonts', KeyValueSection(
|
||||
('fonts', sect.KeyValue(
|
||||
('_monospace', opt.MonospaceFonts()),
|
||||
('completion', opt.CompletionFont()),
|
||||
('tabbar', opt.TabbarFont()),
|
||||
@ -118,6 +119,31 @@ class ConfigStructure:
|
||||
])
|
||||
|
||||
|
||||
def __getitem__(self, key):
|
||||
"""Get a section from the config."""
|
||||
return self.config[key]
|
||||
|
||||
def get(self, section, option, fallback=_UNSET):
|
||||
"""Get the real (transformed) value from a section/option."""
|
||||
try:
|
||||
val = self.config[section][option]
|
||||
except KeyError:
|
||||
if fallback is _UNSET:
|
||||
raise
|
||||
else:
|
||||
return fallback
|
||||
else:
|
||||
return val.value
|
||||
|
||||
def save(self):
|
||||
# FIXME
|
||||
pass
|
||||
|
||||
def dump_userconfig(self):
|
||||
# FIXME
|
||||
pass
|
||||
|
||||
|
||||
class Config(ConfigParser):
|
||||
|
||||
"""Our own ConfigParser subclass.
|
||||
|
@ -86,14 +86,14 @@ class AutoSearch(template.BoolSettingValue):
|
||||
else:
|
||||
return super().validate(self.value)
|
||||
|
||||
def transform(self):
|
||||
if self.value.lower() in ["naive", "dns"]:
|
||||
return self.value.lower()
|
||||
elif super().transform(self.value):
|
||||
def transform(self, value):
|
||||
if value.lower() in ["naive", "dns"]:
|
||||
return value.lower()
|
||||
elif super().transform(value):
|
||||
# boolean true is an alias for naive matching
|
||||
return "naive"
|
||||
else:
|
||||
return "false"
|
||||
return False
|
||||
|
||||
|
||||
class ZoomLevels(template.IntListSettingValue):
|
||||
@ -133,7 +133,7 @@ class ScrollButtons(template.BoolSettingValue):
|
||||
default = "true"
|
||||
|
||||
|
||||
class Position(template.SettingValue):
|
||||
class Position(template.StringSettingValue):
|
||||
|
||||
"""The position of the tab bar."""
|
||||
|
||||
@ -141,7 +141,7 @@ class Position(template.SettingValue):
|
||||
default = "north"
|
||||
|
||||
|
||||
class SelectOnRemove(template.SettingValue):
|
||||
class SelectOnRemove(template.StringSettingValue):
|
||||
|
||||
"""Which tab to select when the focused tab is removed."""
|
||||
|
||||
@ -151,7 +151,7 @@ class SelectOnRemove(template.SettingValue):
|
||||
default = "previous"
|
||||
|
||||
|
||||
class LastClose(template.SettingValue):
|
||||
class LastClose(template.StringSettingValue):
|
||||
|
||||
"""Behaviour when the last tab is closed."""
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
"""Templates for setting options."""
|
||||
|
||||
import logging
|
||||
|
||||
import qutebrowser.commands.utils as cmdutils
|
||||
|
||||
|
||||
@ -64,14 +66,13 @@ class SettingValue:
|
||||
@property
|
||||
def value(self):
|
||||
"""Get the currently valid value."""
|
||||
# FIXME handle default properly
|
||||
#if self._rawvalue is not None:
|
||||
# val = self.rawvalue
|
||||
#else:
|
||||
# val = self.default
|
||||
return self.transform()
|
||||
if self.rawvalue is not None:
|
||||
val = self.rawvalue
|
||||
else:
|
||||
val = self.default
|
||||
return self.transform(val)
|
||||
|
||||
def transform(self):
|
||||
def transform(self, value):
|
||||
"""Transform the setting value.
|
||||
|
||||
This method can assume the value is indeed a valid value.
|
||||
@ -82,7 +83,7 @@ class SettingValue:
|
||||
The transformed value.
|
||||
|
||||
"""
|
||||
return self.value
|
||||
return value
|
||||
|
||||
def validate(self):
|
||||
"""Validate value against possible values.
|
||||
@ -104,6 +105,16 @@ class SettingValue:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class StringSettingValue(SettingValue):
|
||||
|
||||
"""Base class for a string setting (case-insensitive)."""
|
||||
|
||||
typestr = 'string'
|
||||
|
||||
def transform(self, value):
|
||||
return value.lower()
|
||||
|
||||
|
||||
class BoolSettingValue(SettingValue):
|
||||
|
||||
"""Base class for a boolean setting."""
|
||||
@ -115,8 +126,8 @@ class BoolSettingValue(SettingValue):
|
||||
_BOOLEAN_STATES = {'1': True, 'yes': True, 'true': True, 'on': True,
|
||||
'0': False, 'no': False, 'false': False, 'off': False}
|
||||
|
||||
def transform(self):
|
||||
return self._BOOLEAN_STATES[self.value.lower()]
|
||||
def transform(self, value):
|
||||
return self._BOOLEAN_STATES[value.lower()]
|
||||
|
||||
def validate(self):
|
||||
return self.value.lower() in self._BOOLEAN_STATES
|
||||
@ -128,8 +139,8 @@ class IntSettingValue(SettingValue):
|
||||
|
||||
typestr = 'int'
|
||||
|
||||
def transform(self):
|
||||
return int(self.value)
|
||||
def transform(self, value):
|
||||
return int(value)
|
||||
|
||||
def validate(self):
|
||||
try:
|
||||
@ -146,8 +157,8 @@ class ListSettingValue(SettingValue):
|
||||
|
||||
typestr = 'string-list'
|
||||
|
||||
def transform(self):
|
||||
return self.value.split(',')
|
||||
def transform(self, value):
|
||||
return value.split(',')
|
||||
|
||||
def validate(self):
|
||||
return True
|
||||
@ -159,8 +170,8 @@ class IntListSettingValue(ListSettingValue):
|
||||
|
||||
typestr = 'int-list'
|
||||
|
||||
def transform(self):
|
||||
vals = super().transform(self.value)
|
||||
def transform(self, value):
|
||||
vals = super().transform(value)
|
||||
return map(int, vals)
|
||||
|
||||
def validate(self):
|
||||
@ -228,6 +239,7 @@ class ValueListSection:
|
||||
Attributes:
|
||||
values: An OrderedDict with key as index and value as value.
|
||||
default: An OrderedDict with the default configuration as strings.
|
||||
After __init__, the strings become key/value types.
|
||||
types: A tuple for (keytype, valuetype)
|
||||
|
||||
"""
|
||||
@ -236,7 +248,43 @@ class ValueListSection:
|
||||
default = None
|
||||
types = None
|
||||
|
||||
def __init__(self):
|
||||
"""Wrap types over default values. Take care when overriding this."""
|
||||
logging.debug("Default before wrapping: {}".format(self.default))
|
||||
self.default = {self.types[0](key): self.types[1](value)
|
||||
for key, value in self.default.items()}
|
||||
|
||||
def __str__(self):
|
||||
"""Get the key = value pairs as a string."""
|
||||
return '\n'.join('{} = {}'.format(key.rawvalue, val.rawvalue)
|
||||
for key, val in self.values)
|
||||
|
||||
def __getitem__(self, key):
|
||||
"""Get the value for key.
|
||||
|
||||
Args:
|
||||
key: The key to get a value for, as a string.
|
||||
|
||||
Return:
|
||||
The value, as value class.
|
||||
|
||||
"""
|
||||
try:
|
||||
return self.values[key]
|
||||
except KeyError:
|
||||
return self.defaults[key]
|
||||
|
||||
def __iter__(self):
|
||||
"""Iterate over all set values."""
|
||||
# FIXME using a custon iterator this could be done more efficiently
|
||||
valdict = self.default
|
||||
if self.values is not None:
|
||||
valdict.update(self.values)
|
||||
return valdict.__iter__()
|
||||
|
||||
def items(self):
|
||||
"""Get dict items."""
|
||||
valdict = self.default
|
||||
if self.values is not None:
|
||||
valdict.update(self.values)
|
||||
return valdict.items()
|
||||
|
@ -177,20 +177,12 @@ def is_url(url):
|
||||
"""
|
||||
urlstr = urlstring(url)
|
||||
|
||||
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
|
||||
autosearch = config.config.get('general', 'auto_search')
|
||||
|
||||
logging.debug('Checking if "{}" is an URL (autosearch={}).'.format(
|
||||
urlstr, autosearch))
|
||||
|
||||
if autosearch is None:
|
||||
if not autosearch:
|
||||
# no autosearch, so everything is an URL.
|
||||
return True
|
||||
|
||||
|
@ -71,7 +71,7 @@ class BrowserTab(QWebView):
|
||||
self._open_new_tab = False
|
||||
self._destroyed = {}
|
||||
self._zoom = NeighborList(
|
||||
config.config.get('general', 'zoomlevels').split(','),
|
||||
config.config.get('general', 'zoomlevels'),
|
||||
default=config.config.get('general', 'defaultzoom'),
|
||||
mode=NeighborList.BLOCK)
|
||||
self.page_ = BrowserPage(self)
|
||||
|
@ -87,13 +87,11 @@ class TabWidget(QTabWidget):
|
||||
'right': QTabBar.SelectRightTab,
|
||||
'previous': QTabBar.SelectPreviousTab,
|
||||
}
|
||||
self.setMovable(config.config.getboolean('tabbar', 'movable'))
|
||||
self.setTabsClosable(config.config.getboolean('tabbar',
|
||||
'closebuttons'))
|
||||
self.setUsesScrollButtons(config.config.getboolean('tabbar',
|
||||
'scrollbuttons'))
|
||||
posstr = config.config.get('tabbar', 'position').lower()
|
||||
selstr = config.config.get('tabbar', 'select_on_remove').lower()
|
||||
self.setMovable(config.config.get('tabbar', 'movable'))
|
||||
self.setTabsClosable(config.config.get('tabbar', 'closebuttons'))
|
||||
self.setUsesScrollButtons(config.config.get('tabbar', 'scrollbuttons'))
|
||||
posstr = config.config.get('tabbar', 'position')
|
||||
selstr = config.config.get('tabbar', 'select_on_remove')
|
||||
try:
|
||||
self.setTabPosition(position_conv[posstr])
|
||||
self.tabBar().setSelectionBehaviorOnRemove(select_conv[selstr])
|
||||
|
Loading…
Reference in New Issue
Block a user