Fix issues with per-domain proof-of-concept
This commit is contained in:
parent
d09afdf0ee
commit
74a7676111
@ -299,7 +299,7 @@ def init(args):
|
||||
|
||||
|
||||
def update_for_tab(tab, url):
|
||||
websettings.update_mappings(MAPPINGS, option, url, tab.settings())
|
||||
websettings.update_for_tab(MAPPINGS, tab, url)
|
||||
|
||||
|
||||
def shutdown():
|
||||
|
@ -906,7 +906,7 @@ class WebEngineTab(browsertab.AbstractTab):
|
||||
page.loadFinished.connect(self._restore_zoom)
|
||||
page.loadFinished.connect(self._on_load_finished)
|
||||
|
||||
self.on_url_changed.connect(
|
||||
self.url_changed.connect(
|
||||
functools.partial(webenginesettings.update_for_tab, self))
|
||||
|
||||
def event_target(self):
|
||||
|
@ -118,8 +118,8 @@ def _update_settings(option):
|
||||
websettings.update_mappings(MAPPINGS, option)
|
||||
|
||||
|
||||
def update_for_tab(tab, url, option):
|
||||
websettings.update_mappings(MAPPINGS, option, url, tab.settings())
|
||||
def update_for_tab(tab, url):
|
||||
websettings.update_for_tab(MAPPINGS, tab, url)
|
||||
|
||||
|
||||
def init(_args):
|
||||
|
@ -36,7 +36,8 @@ from PyQt5.QtWebKit import QWebSettings
|
||||
from PyQt5.QtPrintSupport import QPrinter
|
||||
|
||||
from qutebrowser.browser import browsertab
|
||||
from qutebrowser.browser.webkit import webview, tabhistory, webkitelem
|
||||
from qutebrowser.browser.webkit import (webview, tabhistory, webkitelem,
|
||||
webkitsettings)
|
||||
from qutebrowser.utils import qtutils, objreg, usertypes, utils, log, debug
|
||||
|
||||
|
||||
@ -780,7 +781,7 @@ class WebKitTab(browsertab.AbstractTab):
|
||||
frame.contentsSizeChanged.connect(self._on_contents_size_changed)
|
||||
frame.initialLayoutCompleted.connect(self._on_history_trigger)
|
||||
|
||||
self.on_url_changed.connect(
|
||||
self.url_changed.connect(
|
||||
functools.partial(webkitsettings.update_for_tab, self))
|
||||
|
||||
def event_target(self):
|
||||
|
@ -190,7 +190,7 @@ class KeyConfig:
|
||||
log.keyboard.vdebug("Adding binding {} -> {} in mode {}.".format(
|
||||
key, command, mode))
|
||||
|
||||
bindings = self._config.get_obj('bindings.commands')
|
||||
bindings = self._config.get_mutable_obj('bindings.commands')
|
||||
if mode not in bindings:
|
||||
bindings[mode] = {}
|
||||
bindings[mode][key] = command
|
||||
@ -200,7 +200,7 @@ class KeyConfig:
|
||||
"""Restore a default keybinding."""
|
||||
key = self._prepare(key, mode)
|
||||
|
||||
bindings_commands = self._config.get_obj('bindings.commands')
|
||||
bindings_commands = self._config.get_mutable_obj('bindings.commands')
|
||||
try:
|
||||
del bindings_commands[mode][key]
|
||||
except KeyError:
|
||||
@ -212,7 +212,7 @@ class KeyConfig:
|
||||
"""Unbind the given key in the given mode."""
|
||||
key = self._prepare(key, mode)
|
||||
|
||||
bindings_commands = self._config.get_obj('bindings.commands')
|
||||
bindings_commands = self._config.get_mutable_obj('bindings.commands')
|
||||
|
||||
if val.bindings.commands[mode].get(key, None) is not None:
|
||||
# In custom bindings -> remove it
|
||||
@ -252,15 +252,17 @@ class Config(QObject):
|
||||
def __init__(self, yaml_config, parent=None):
|
||||
super().__init__(parent)
|
||||
self.changed.connect(_render_stylesheet.cache_clear)
|
||||
self._values = {}
|
||||
self._mutables = {}
|
||||
self._yaml = yaml_config
|
||||
|
||||
self._values = {}
|
||||
for name, opt in configdata.DATA.items():
|
||||
self._values[name] = configutils.Values(opt)
|
||||
|
||||
def __iter__(self):
|
||||
"""Iterate over Option, ScopedValue tuples."""
|
||||
"""Iterate over Option, configutils.Values tuples."""
|
||||
for name, values in sorted(self._values.items()):
|
||||
for scoped in values:
|
||||
yield self.get_opt(name), scoped
|
||||
yield self.get_opt(name), values
|
||||
|
||||
def init_save_manager(self, save_manager):
|
||||
"""Make sure the config gets saved properly.
|
||||
@ -277,8 +279,7 @@ class Config(QObject):
|
||||
raise configexc.BackendError(opt.name, objects.backend)
|
||||
|
||||
opt.typ.to_py(value) # for validation
|
||||
scoped = configutils.ScopedValue(opt.typ.from_obj(value), pattern)
|
||||
self._values[opt.name].add(scoped)
|
||||
self._values[opt.name].add(opt.typ.from_obj(value), pattern)
|
||||
|
||||
self.changed.emit(opt.name)
|
||||
log.config.debug("Config option changed: {} = {}".format(
|
||||
@ -305,7 +306,7 @@ class Config(QObject):
|
||||
def get(self, name, url=None):
|
||||
"""Get the given setting converted for Python code."""
|
||||
opt = self.get_opt(name)
|
||||
obj = self.get_obj(name, mutable=False, url=url)
|
||||
obj = self.get_obj(name, url=url)
|
||||
return opt.typ.to_py(obj)
|
||||
|
||||
def _maybe_copy(self, value):
|
||||
@ -511,7 +512,7 @@ class ConfigContainer:
|
||||
return self._config.get(name)
|
||||
else:
|
||||
# access from config.py
|
||||
return self._config.get_obj(name)
|
||||
return self._config.get_mutable_obj(name)
|
||||
|
||||
def __setattr__(self, attr, value):
|
||||
"""Set the given option in the config."""
|
||||
|
@ -191,8 +191,8 @@ class ConfigCommands:
|
||||
|
||||
with self._handle_config_error():
|
||||
opt = self._config.get_opt(option)
|
||||
old_value = self._config.get_obj(option, mutable=False,
|
||||
pattern=pattern)
|
||||
old_value = self._config.get_obj_for_pattern(option,
|
||||
pattern=pattern)
|
||||
|
||||
if not values and isinstance(opt.typ, configtypes.Bool):
|
||||
values = ['true', 'false']
|
||||
@ -318,7 +318,7 @@ class ConfigCommands:
|
||||
commented = True
|
||||
else:
|
||||
options = list(self._config)
|
||||
bindings = dict(self._config.get_obj('bindings.commands'))
|
||||
bindings = dict(self._config.get_mutable_obj('bindings.commands'))
|
||||
commented = False
|
||||
|
||||
writer = configfiles.ConfigPyWriter(options, bindings,
|
||||
|
@ -87,9 +87,12 @@ class YamlConfig(QObject):
|
||||
super().__init__(parent)
|
||||
self._filename = os.path.join(standarddir.config(auto=True),
|
||||
'autoconfig.yml')
|
||||
self._values = {}
|
||||
self._dirty = None
|
||||
|
||||
self._values = {}
|
||||
for name, opt in configdata.DATA.items():
|
||||
self._values[name] = configutils.Values(opt)
|
||||
|
||||
def init_save_manager(self, save_manager):
|
||||
"""Make sure the config gets saved properly.
|
||||
|
||||
@ -163,7 +166,7 @@ class YamlConfig(QObject):
|
||||
self._handle_migrations()
|
||||
self._validate()
|
||||
|
||||
def _load_settings_obj(self, settings_obj):
|
||||
def _load_settings_object(self, settings_obj):
|
||||
"""Load the settings from the settings: key."""
|
||||
if not isinstance(settings_obj, dict):
|
||||
desc = configexc.ConfigErrorDesc(
|
||||
@ -172,16 +175,13 @@ class YamlConfig(QObject):
|
||||
raise configexc.ConfigFileErrors('autoconfig.yml', [desc])
|
||||
|
||||
# FIXME:conf test this
|
||||
self._values = {}
|
||||
for name, yaml_values in settings_obj.items():
|
||||
values = configutils.Values(self._config.get_opt(name))
|
||||
if 'global' in yaml_values:
|
||||
scoped = configutils.ScopedValue(yaml_values.pop('global'))
|
||||
values.add(scoped)
|
||||
values.add(yaml_values.pop('global'))
|
||||
|
||||
for pattern, value in yaml_values.items():
|
||||
scoped = configutils.ScopedValue(value, pattern)
|
||||
values.add(scoped)
|
||||
values.add(value, pattern)
|
||||
|
||||
self._values[name] = values
|
||||
|
||||
@ -230,16 +230,11 @@ class YamlConfig(QObject):
|
||||
|
||||
def set_obj(self, name, value, *, pattern=None):
|
||||
"""Set the given setting to the given value."""
|
||||
values = self._get_values(pattern)
|
||||
values[name] = value
|
||||
self._values[name].add(value, pattern)
|
||||
|
||||
def unset(self, name, *, pattern=None):
|
||||
"""Remove the given option name if it's configured."""
|
||||
values = self._get_values(pattern)
|
||||
try:
|
||||
del values[name]
|
||||
except KeyError:
|
||||
return
|
||||
self._values[name].remove(pattern)
|
||||
self._mark_changed()
|
||||
|
||||
def clear(self):
|
||||
@ -294,7 +289,7 @@ class ConfigAPI:
|
||||
|
||||
def get(self, name):
|
||||
with self._handle_error('getting', name):
|
||||
return self._config.get_obj(name)
|
||||
return self._config.get_mutable_obj(name)
|
||||
|
||||
def set(self, name, value):
|
||||
with self._handle_error('setting', name):
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
from PyQt5.QtGui import QFont
|
||||
|
||||
from qutebrowser.config import config
|
||||
from qutebrowser.config import config, configutils
|
||||
from qutebrowser.utils import log, utils, debug, usertypes
|
||||
from qutebrowser.misc import objects
|
||||
|
||||
@ -198,15 +198,25 @@ def init_mappings(mappings):
|
||||
mapping.set(value)
|
||||
|
||||
|
||||
def update_mappings(mappings, option, url=None, settings=None):
|
||||
def update_mappings(mappings, option):
|
||||
"""Update global settings when QWeb(Engine)Settings changed."""
|
||||
try:
|
||||
mapping = mappings[option]
|
||||
except KeyError:
|
||||
return
|
||||
value = config.instance.get(option, url=url)
|
||||
# FIXME:conf handle settings != None with global/static setters
|
||||
mapping.set(value, settings=settings)
|
||||
value = config.instance.get(option)
|
||||
mapping.set(value)
|
||||
|
||||
|
||||
def update_for_tab(mappings, tab, url):
|
||||
"""Update settings customized for the given tab."""
|
||||
for opt, values in config.instance:
|
||||
value = values.get_for_url(url, fallback=False)
|
||||
if value is not configutils.UNSET and opt.name in mappings:
|
||||
# FIXME:conf handle settings != None with global/static setters
|
||||
mapping = mappings[opt.name]
|
||||
# FIXME:conf have a proper API for this.
|
||||
mapping.set(value, settings=tab._widget.settings())
|
||||
|
||||
|
||||
def init(args):
|
||||
|
Loading…
Reference in New Issue
Block a user