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