Move websettings to own file
This commit is contained in:
parent
03227c2b41
commit
fc24cb620c
@ -27,6 +27,8 @@ from signal import signal, SIGINT
|
||||
from argparse import ArgumentParser
|
||||
from base64 import b64encode
|
||||
|
||||
import qutebrowser.config.websettings as websettings
|
||||
|
||||
# Print a nice traceback on segfault -- only available on Python 3.3+, but if
|
||||
# it's unavailable, it doesn't matter much.
|
||||
try:
|
||||
@ -102,6 +104,7 @@ class QuteBrowser(QApplication):
|
||||
confdir = self._args.confdir
|
||||
config.init(confdir)
|
||||
self.config = config.config
|
||||
websettings.init()
|
||||
|
||||
self.commandparser = CommandParser()
|
||||
self.searchparser = SearchParser()
|
||||
@ -137,7 +140,7 @@ class QuteBrowser(QApplication):
|
||||
self.mainwindow.completion.on_config_changed)
|
||||
self.config.changed.connect(self.mainwindow.on_config_changed)
|
||||
self.config.changed.connect(config.cmd_history.on_config_changed)
|
||||
self.config.changed.connect(config.qwebsetting_on_config_changed)
|
||||
self.config.changed.connect(websettings.on_config_changed)
|
||||
|
||||
self.mainwindow.show()
|
||||
self._python_hacks()
|
||||
|
@ -31,7 +31,6 @@ from configparser import ConfigParser, ExtendedInterpolation
|
||||
from collections.abc import MutableMapping
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject
|
||||
from PyQt5.QtWebKit import QWebSettings
|
||||
|
||||
#from qutebrowser.utils.misc import read_file
|
||||
import qutebrowser.config.configdata as configdata
|
||||
@ -44,41 +43,6 @@ state = None
|
||||
cmd_history = None
|
||||
|
||||
|
||||
WEBSETTINGS_MAPPING = {
|
||||
# noqa
|
||||
'auto_load_images': QWebSettings.AutoLoadImages,
|
||||
'dns_prefetch_enabled': QWebSettings.DnsPrefetchEnabled,
|
||||
'javascript_enabled': QWebSettings.JavascriptEnabled,
|
||||
#'java_enabled': #QWebSettings.JavaEnabled,
|
||||
'plugins_enabled': QWebSettings.PluginsEnabled,
|
||||
'private_browsing_enabled': QWebSettings.PrivateBrowsingEnabled,
|
||||
'javascript_can_open_windows': QWebSettings.JavascriptCanOpenWindows,
|
||||
'javascript_can_close_windows': QWebSettings.JavascriptCanCloseWindows,
|
||||
'javascript_can_access_clipboard':
|
||||
QWebSettings.JavascriptCanAccessClipboard,
|
||||
'developer_extras_enabled': QWebSettings.DeveloperExtrasEnabled,
|
||||
'spatial_navigation_enabled': QWebSettings.SpatialNavigationEnabled,
|
||||
'links_included_in_focus_chain': QWebSettings.LinksIncludedInFocusChain,
|
||||
'zoom_text_only': QWebSettings.ZoomTextOnly,
|
||||
'print_element_backgrounds': QWebSettings.PrintElementBackgrounds,
|
||||
'offline_storage_database_enabled':
|
||||
QWebSettings.OfflineStorageDatabaseEnabled,
|
||||
'offline_web_application_storage_enabled':
|
||||
QWebSettings.OfflineWebApplicationCacheEnabled,
|
||||
'local_storage_enabled': QWebSettings.LocalStorageEnabled,
|
||||
'local_content_can_access_remote_urls':
|
||||
QWebSettings.LocalContentCanAccessRemoteUrls,
|
||||
'local_content_can_access_file_urls':
|
||||
QWebSettings.LocalContentCanAccessFileUrls,
|
||||
'xss_auditing_enabled': QWebSettings.XSSAuditingEnabled,
|
||||
#'accelerated_compositing_enabled':
|
||||
# QWebSettings.AcceleratedCompositingEnabled,
|
||||
#'tiled_backing_store_enabled': QWebSettings.TiledBackingStoreEnabled,
|
||||
'frame_flattening_enabled': QWebSettings.FrameFlatteningEnabled,
|
||||
'site_specific_quirks_enabled': QWebSettings.SiteSpecificQuirksEnabled,
|
||||
}
|
||||
|
||||
|
||||
class NoSectionError(configparser.NoSectionError):
|
||||
|
||||
"""Exception raised when a section was not found."""
|
||||
@ -107,22 +71,6 @@ def init(configdir):
|
||||
state = ReadWriteConfigParser(configdir, 'state')
|
||||
cmd_history = LineConfigParser(configdir, 'cmd_history',
|
||||
('general', 'cmd_histlen'))
|
||||
init_qwebsettings()
|
||||
|
||||
|
||||
def init_qwebsettings():
|
||||
"""Initialize the global QWebSettings."""
|
||||
settings = QWebSettings.globalSettings()
|
||||
for name, item in WEBSETTINGS_MAPPING.items():
|
||||
settings.setAttribute(item, config.get('webkit', name))
|
||||
|
||||
|
||||
@pyqtSlot(str, str, object)
|
||||
def qwebsetting_on_config_changed(section, option, value):
|
||||
"""Update global settings when qwebsettings changed."""
|
||||
if section == 'webkit':
|
||||
settings = QWebSettings.globalSettings()
|
||||
settings.setAttribute(WEBSETTINGS_MAPPING[option], value)
|
||||
|
||||
|
||||
class Config(QObject):
|
||||
|
75
qutebrowser/config/websettings.py
Normal file
75
qutebrowser/config/websettings.py
Normal file
@ -0,0 +1,75 @@
|
||||
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||
#
|
||||
# This file is part of qutebrowser.
|
||||
#
|
||||
# qutebrowser is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# qutebrowser is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""Bridge from QWebSettings to our own settings."""
|
||||
|
||||
from PyQt5.QtCore import pyqtSlot
|
||||
from PyQt5.QtWebKit import QWebSettings
|
||||
|
||||
import qutebrowser.config.config as config
|
||||
|
||||
|
||||
MAPPING = {
|
||||
# noqa
|
||||
'auto_load_images': QWebSettings.AutoLoadImages,
|
||||
'dns_prefetch_enabled': QWebSettings.DnsPrefetchEnabled,
|
||||
'javascript_enabled': QWebSettings.JavascriptEnabled,
|
||||
#'java_enabled': #QWebSettings.JavaEnabled,
|
||||
'plugins_enabled': QWebSettings.PluginsEnabled,
|
||||
'private_browsing_enabled': QWebSettings.PrivateBrowsingEnabled,
|
||||
'javascript_can_open_windows': QWebSettings.JavascriptCanOpenWindows,
|
||||
'javascript_can_close_windows': QWebSettings.JavascriptCanCloseWindows,
|
||||
'javascript_can_access_clipboard':
|
||||
QWebSettings.JavascriptCanAccessClipboard,
|
||||
'developer_extras_enabled': QWebSettings.DeveloperExtrasEnabled,
|
||||
'spatial_navigation_enabled': QWebSettings.SpatialNavigationEnabled,
|
||||
'links_included_in_focus_chain': QWebSettings.LinksIncludedInFocusChain,
|
||||
'zoom_text_only': QWebSettings.ZoomTextOnly,
|
||||
'print_element_backgrounds': QWebSettings.PrintElementBackgrounds,
|
||||
'offline_storage_database_enabled':
|
||||
QWebSettings.OfflineStorageDatabaseEnabled,
|
||||
'offline_web_application_storage_enabled':
|
||||
QWebSettings.OfflineWebApplicationCacheEnabled,
|
||||
'local_storage_enabled': QWebSettings.LocalStorageEnabled,
|
||||
'local_content_can_access_remote_urls':
|
||||
QWebSettings.LocalContentCanAccessRemoteUrls,
|
||||
'local_content_can_access_file_urls':
|
||||
QWebSettings.LocalContentCanAccessFileUrls,
|
||||
'xss_auditing_enabled': QWebSettings.XSSAuditingEnabled,
|
||||
#'accelerated_compositing_enabled':
|
||||
# QWebSettings.AcceleratedCompositingEnabled,
|
||||
#'tiled_backing_store_enabled': QWebSettings.TiledBackingStoreEnabled,
|
||||
'frame_flattening_enabled': QWebSettings.FrameFlatteningEnabled,
|
||||
'site_specific_quirks_enabled': QWebSettings.SiteSpecificQuirksEnabled,
|
||||
}
|
||||
|
||||
settings = None
|
||||
|
||||
|
||||
def init():
|
||||
"""Initialize the global QWebSettings."""
|
||||
global settings
|
||||
settings = QWebSettings.globalSettings()
|
||||
for name, item in MAPPING.items():
|
||||
settings.setAttribute(item, config.config.get('webkit', name))
|
||||
|
||||
|
||||
@pyqtSlot(str, str, object)
|
||||
def on_config_changed(section, option, value):
|
||||
"""Update global settings when qwebsettings changed."""
|
||||
if section == 'webkit':
|
||||
settings.setAttribute(MAPPING[option], value)
|
Loading…
Reference in New Issue
Block a user