Refactor most stuff using config.val.ui
This commit is contained in:
parent
1ed8df8903
commit
1a6511c7a8
@ -464,7 +464,7 @@ def _init_modules(args, crash_handler):
|
||||
completionmodels.init()
|
||||
|
||||
log.init.debug("Misc initialization...")
|
||||
if config.val.ui.hide_wayland_decoration:
|
||||
if config.val.window.hide_wayland_decoration:
|
||||
os.environ['QT_WAYLAND_DISABLE_WINDOWDECORATION'] = '1'
|
||||
else:
|
||||
os.environ.pop('QT_WAYLAND_DISABLE_WINDOWDECORATION', None)
|
||||
|
@ -264,17 +264,17 @@ class AbstractZoom(QObject):
|
||||
def _on_config_changed(self, section, option):
|
||||
if section == 'ui' and option in ['zoom-levels', 'default-zoom']:
|
||||
if not self._default_zoom_changed:
|
||||
factor = float(config.val.ui.default_zoom) / 100
|
||||
factor = float(config.val.zoom.default) / 100
|
||||
self._set_factor_internal(factor)
|
||||
self._default_zoom_changed = False
|
||||
self._init_neighborlist()
|
||||
|
||||
def _init_neighborlist(self):
|
||||
"""Initialize self._neighborlist."""
|
||||
levels = config.val.ui.zoom_levels
|
||||
levels = config.val.zoom.levels
|
||||
self._neighborlist = usertypes.NeighborList(
|
||||
levels, mode=usertypes.NeighborList.Modes.edge)
|
||||
self._neighborlist.fuzzyval = config.val.ui.default_zoom
|
||||
self._neighborlist.fuzzyval = config.val.zoom.default
|
||||
|
||||
def offset(self, offset):
|
||||
"""Increase/Decrease the zoom level by the given offset.
|
||||
@ -310,8 +310,7 @@ class AbstractZoom(QObject):
|
||||
raise NotImplementedError
|
||||
|
||||
def set_default(self):
|
||||
default_zoom = config.val.ui.default_zoom
|
||||
self._set_factor_internal(float(default_zoom) / 100)
|
||||
self._set_factor_internal(float(config.val.zoom.default) / 100)
|
||||
|
||||
|
||||
class AbstractCaret(QObject):
|
||||
|
@ -888,7 +888,7 @@ class CommandDispatcher:
|
||||
|
||||
level = count if count is not None else zoom
|
||||
if level is None:
|
||||
level = config.val.ui.default_zoom
|
||||
level = config.val.zoom.default
|
||||
tab = self._current_widget()
|
||||
|
||||
try:
|
||||
|
@ -735,7 +735,7 @@ class AbstractDownloadManager(QObject):
|
||||
download.remove_requested.connect(functools.partial(
|
||||
self._remove_item, download))
|
||||
|
||||
delay = config.val.ui.remove_finished_downloads
|
||||
delay = config.val.downloads.remove_finished
|
||||
if delay > -1:
|
||||
download.finished.connect(
|
||||
lambda: QTimer.singleShot(delay, download.remove))
|
||||
|
@ -368,7 +368,7 @@ class DownloadManager(downloads.AbstractDownloadManager):
|
||||
super().__init__(parent)
|
||||
self._networkmanager = networkmanager.NetworkManager(
|
||||
win_id=win_id, tab_id=None,
|
||||
private=config.val.private_browsing, parent=self)
|
||||
private=config.val.content.private_browsing, parent=self)
|
||||
|
||||
@pyqtSlot('QUrl')
|
||||
def get(self, url, *, user_agent=None, **kwargs):
|
||||
|
@ -285,7 +285,7 @@ def qute_history(url):
|
||||
return 'text/html', jinja.render(
|
||||
'history.html',
|
||||
title='History',
|
||||
session_interval=config.val.ui.history_session_interval
|
||||
session_interval=config.val.history_session_interval
|
||||
)
|
||||
else:
|
||||
# Get current date from query parameter, if not given choose today.
|
||||
|
@ -72,7 +72,7 @@ def authentication_required(url, authenticator, abort_on):
|
||||
def javascript_confirm(url, js_msg, abort_on):
|
||||
"""Display a javascript confirm prompt."""
|
||||
log.js.debug("confirm: {}".format(js_msg))
|
||||
if config.val.ui.modal_js_dialog:
|
||||
if config.val.content.javascript.modal_dialog:
|
||||
raise CallSuper
|
||||
|
||||
msg = 'From <b>{}</b>:<br/>{}'.format(html.escape(url.toDisplayString()),
|
||||
@ -86,7 +86,7 @@ def javascript_confirm(url, js_msg, abort_on):
|
||||
def javascript_prompt(url, js_msg, default, abort_on):
|
||||
"""Display a javascript prompt."""
|
||||
log.js.debug("prompt: {}".format(js_msg))
|
||||
if config.val.ui.modal_js_dialog:
|
||||
if config.val.content.javascript.modal_dialog:
|
||||
raise CallSuper
|
||||
if config.val.content.ignore_javascript_prompt:
|
||||
return (False, "")
|
||||
@ -107,7 +107,7 @@ def javascript_prompt(url, js_msg, default, abort_on):
|
||||
def javascript_alert(url, js_msg, abort_on):
|
||||
"""Display a javascript alert."""
|
||||
log.js.debug("alert: {}".format(js_msg))
|
||||
if config.val.ui.modal_js_dialog:
|
||||
if config.val.content.javascript.modal_dialog:
|
||||
raise CallSuper
|
||||
|
||||
if config.val.content.ignore_javascript_alert:
|
||||
@ -233,7 +233,7 @@ def get_tab(win_id, target):
|
||||
|
||||
def get_user_stylesheet():
|
||||
"""Get the combined user-stylesheet."""
|
||||
filename = config.val.ui.user_stylesheet
|
||||
filename = config.val.content.user_stylesheet
|
||||
|
||||
if filename is None:
|
||||
css = ''
|
||||
@ -241,7 +241,7 @@ def get_user_stylesheet():
|
||||
with open(filename, 'r', encoding='utf-8') as f:
|
||||
css = f.read()
|
||||
|
||||
if config.val.ui.hide_scrollbar:
|
||||
if config.val.scrolling.bar:
|
||||
css += '\nhtml > ::-webkit-scrollbar { width: 0px; height: 0px; }'
|
||||
|
||||
return css
|
||||
|
@ -168,7 +168,7 @@ class WebKitElement(webelem.AbstractWebElement):
|
||||
if width > 1 and height > 1:
|
||||
# fix coordinates according to zoom level
|
||||
zoom = self._elem.webFrame().zoomFactor()
|
||||
if not config.val.ui.zoom_text_only:
|
||||
if not config.val.zoom.text_only:
|
||||
rect["left"] *= zoom
|
||||
rect["top"] *= zoom
|
||||
width *= zoom
|
||||
|
@ -132,7 +132,7 @@ def init(_args):
|
||||
QWebSettings.setOfflineStoragePath(
|
||||
os.path.join(data_path, 'offline-storage'))
|
||||
|
||||
if (config.val.private_browsing and
|
||||
if (config.val.content.private_browsing and
|
||||
not qtutils.version_check('5.4.2')):
|
||||
# WORKAROUND for https://codereview.qt-project.org/#/c/108936/
|
||||
# Won't work when private browsing is not enabled globally, but that's
|
||||
|
@ -163,7 +163,7 @@ class MainWindow(QWidget):
|
||||
self._init_downloadmanager()
|
||||
self._downloadview = downloadview.DownloadView(self.win_id)
|
||||
|
||||
if config.val.private_browsing:
|
||||
if config.val.content.private_browsing:
|
||||
# This setting always trumps what's passed in.
|
||||
private = True
|
||||
else:
|
||||
@ -250,7 +250,7 @@ class MainWindow(QWidget):
|
||||
left = (self.width() - width) / 2 if centered else 0
|
||||
|
||||
height_padding = 20
|
||||
status_position = config.val.ui.status_position
|
||||
status_position = config.val.statusbar.position
|
||||
if status_position == 'bottom':
|
||||
if self.status.isVisible():
|
||||
status_height = self.status.height()
|
||||
@ -341,10 +341,9 @@ class MainWindow(QWidget):
|
||||
self._vbox.removeWidget(self.tabbed_browser)
|
||||
self._vbox.removeWidget(self._downloadview)
|
||||
self._vbox.removeWidget(self.status)
|
||||
downloads_position = config.val.ui.downloads_position
|
||||
status_position = config.val.ui.status_position
|
||||
widgets = [self.tabbed_browser]
|
||||
|
||||
downloads_position = config.val.downloads.position
|
||||
if downloads_position == 'top':
|
||||
widgets.insert(0, self._downloadview)
|
||||
elif downloads_position == 'bottom':
|
||||
@ -352,6 +351,7 @@ class MainWindow(QWidget):
|
||||
else:
|
||||
raise ValueError("Invalid position {}!".format(downloads_position))
|
||||
|
||||
status_position = config.val.statusbar.position
|
||||
if status_position == 'top':
|
||||
widgets.insert(0, self.status)
|
||||
elif status_position == 'bottom':
|
||||
@ -536,23 +536,22 @@ class MainWindow(QWidget):
|
||||
if crashsignal.is_crashing:
|
||||
e.accept()
|
||||
return
|
||||
confirm_quit = config.val.ui.confirm_quit
|
||||
tab_count = self.tabbed_browser.count()
|
||||
download_model = objreg.get('download-model', scope='window',
|
||||
window=self.win_id)
|
||||
download_count = download_model.running_downloads()
|
||||
quit_texts = []
|
||||
# Ask if multiple-tabs are open
|
||||
if 'multiple-tabs' in confirm_quit and tab_count > 1:
|
||||
if 'multiple-tabs' in config.val.confirm_quit and tab_count > 1:
|
||||
quit_texts.append("{} {} open.".format(
|
||||
tab_count, "tab is" if tab_count == 1 else "tabs are"))
|
||||
# Ask if multiple downloads running
|
||||
if 'downloads' in confirm_quit and download_count > 0:
|
||||
if 'downloads' in config.val.confirm_quit and download_count > 0:
|
||||
quit_texts.append("{} {} running.".format(
|
||||
download_count,
|
||||
"download is" if download_count == 1 else "downloads are"))
|
||||
# Process all quit messages that user must confirm
|
||||
if quit_texts or 'always' in confirm_quit:
|
||||
if quit_texts or 'always' in config.val.confirm_quit:
|
||||
msg = jinja2.Template("""
|
||||
<ul>
|
||||
{% for text in quit_texts %}
|
||||
|
@ -126,7 +126,7 @@ class MessageView(QWidget):
|
||||
widget = Message(level, text, replace=replace, parent=self)
|
||||
self._vbox.addWidget(widget)
|
||||
widget.show()
|
||||
if config.val.ui.message_timeout != 0:
|
||||
if config.val.messages.timeout != 0:
|
||||
self._clear_timer.start()
|
||||
self._messages.append(widget)
|
||||
self._last_text = text
|
||||
|
@ -233,14 +233,13 @@ class PromptContainer(QWidget):
|
||||
"""
|
||||
|
||||
STYLESHEET = """
|
||||
{% set prompt_radius = config.val.ui.prompt_radius %}
|
||||
QWidget#PromptContainer {
|
||||
{% if config.val.ui.status_position == 'top' %}
|
||||
border-bottom-left-radius: {{ prompt_radius }}px;
|
||||
border-bottom-right-radius: {{ prompt_radius }}px;
|
||||
{% if config.val.statusbar.position == 'top' %}
|
||||
border-bottom-left-radius: {{ config.val.prompt.radius }}px;
|
||||
border-bottom-right-radius: {{ config.val.prompt.radius }}px;
|
||||
{% else %}
|
||||
border-top-left-radius: {{ prompt_radius }}px;
|
||||
border-top-right-radius: {{ prompt_radius }}px;
|
||||
border-top-left-radius: {{ config.val.prompt.radius }}px;
|
||||
border-top-right-radius: {{ config.val.prompt.radius }}px;
|
||||
{% endif %}
|
||||
}
|
||||
|
||||
@ -566,7 +565,7 @@ class FilenamePrompt(_BasePrompt):
|
||||
self.setFocusProxy(self._lineedit)
|
||||
self._init_key_label()
|
||||
|
||||
if config.val.ui.prompt_filebrowser:
|
||||
if config.val.ui.prompt.filebrowser:
|
||||
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
|
||||
|
||||
@pyqtSlot(str)
|
||||
@ -628,7 +627,7 @@ class FilenamePrompt(_BasePrompt):
|
||||
self._file_view.setModel(self._file_model)
|
||||
self._file_view.clicked.connect(self._insert_path)
|
||||
|
||||
if config.val.ui.prompt_filebrowser:
|
||||
if config.val.ui.prompt.filebrowser:
|
||||
self._vbox.addWidget(self._file_view)
|
||||
else:
|
||||
self._file_view.hide()
|
||||
|
@ -211,15 +211,15 @@ class StatusBar(QWidget):
|
||||
@pyqtSlot()
|
||||
def maybe_hide(self):
|
||||
"""Hide the statusbar if it's configured to do so."""
|
||||
hide = config.val.ui.hide_statusbar
|
||||
tab = self._current_tab()
|
||||
hide = config.val.statusbar.hide
|
||||
if hide or (tab is not None and tab.data.fullscreen):
|
||||
self.hide()
|
||||
else:
|
||||
self.show()
|
||||
|
||||
def _set_hbox_padding(self):
|
||||
padding = config.val.ui.statusbar_padding
|
||||
padding = config.val.statusbar.padding
|
||||
self._hbox.setContentsMargins(padding.left, 0, padding.right, 0)
|
||||
|
||||
@pyqtProperty('QStringList')
|
||||
@ -344,7 +344,7 @@ class StatusBar(QWidget):
|
||||
|
||||
def minimumSizeHint(self):
|
||||
"""Set the minimum height to the text height plus some padding."""
|
||||
padding = config.val.ui.statusbar_padding
|
||||
padding = config.val.statusbar.padding
|
||||
width = super().minimumSizeHint().width()
|
||||
height = self.fontMetrics().height() + padding.top + padding.bottom
|
||||
return QSize(width, height)
|
||||
|
@ -432,7 +432,7 @@ class ExceptionCrashDialog(_CrashDialog):
|
||||
self._chk_log = QCheckBox("Include a debug log in the report",
|
||||
checked=True)
|
||||
try:
|
||||
if config.val.private_browsing:
|
||||
if config.val.content.private_browsing:
|
||||
self._chk_log.setChecked(False)
|
||||
except Exception:
|
||||
log.misc.exception("Error while checking private browsing mode")
|
||||
@ -524,7 +524,7 @@ class FatalCrashDialog(_CrashDialog):
|
||||
"accessed pages in the report.",
|
||||
checked=True)
|
||||
try:
|
||||
if config.val.private_browsing:
|
||||
if config.val.content.private_browsing:
|
||||
self._chk_history.setChecked(False)
|
||||
except Exception:
|
||||
log.misc.exception("Error while checking private browsing mode")
|
||||
|
@ -51,7 +51,7 @@ class KeyHintView(QLabel):
|
||||
color: {{ color['keyhint.fg'] }};
|
||||
background-color: {{ color['keyhint.bg'] }};
|
||||
padding: 6px;
|
||||
{% if config.val.ui.status_position == 'top' %}
|
||||
{% if config.val.statusbar.position == 'top' %}
|
||||
border-bottom-right-radius: 6px;
|
||||
{% else %}
|
||||
border-top-right-radius: 6px;
|
||||
@ -90,7 +90,7 @@ class KeyHintView(QLabel):
|
||||
self.hide()
|
||||
return
|
||||
|
||||
blacklist = config.val.ui.keyhint_blacklist or []
|
||||
blacklist = config.val.keyhint.blacklist or []
|
||||
keyconf = objreg.get('key-config')
|
||||
|
||||
def blacklisted(keychain):
|
||||
@ -107,7 +107,7 @@ class KeyHintView(QLabel):
|
||||
return
|
||||
|
||||
# delay so a quickly typed keychain doesn't display hints
|
||||
self._show_timer.setInterval(config.val.ui.keyhint_delay)
|
||||
self._show_timer.setInterval(config.val.keyhint.delay)
|
||||
self._show_timer.start()
|
||||
suffix_color = html.escape(config.val.colors.keyhint.fg.suffix)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user