1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 17:52:10 +02:00

Start working on QWESettings Attributes

Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
Juraj Oravec 2022-09-09 09:45:59 +02:00
parent 6f0249f78b
commit bbad4d86a8
Signed by: SGOrava
GPG Key ID: 13660A3F1D9F093B
2 changed files with 66 additions and 2 deletions

View File

@ -111,6 +111,53 @@ SiteWebEngineSettings SiteSettingsManager::getWebEngineSettings(const QUrl& url)
return settings;
}
QHash<QWebEngineSettings::WebAttribute, bool> SiteSettingsManager::getWebAttributes(const QUrl& url)
{
QHash<QWebEngineSettings::WebAttribute, bool> attribute;
QSqlQuery query(SqlDatabase::instance()->database());
query.prepare(QSL("SELECT allow_images, allow_javascript FROM site_settings WHERE server=?"));
query.addBindValue(url.host());
query.exec();
// Fill the default values
// Might not be required
// TODO I hope the defaults are set with default webengine profile settings, needs testing
attribute[QWebEngineSettings::AutoLoadImages] = getDefaultPermission(poAllowImages) == Allow;
attribute[QWebEngineSettings::JavascriptEnabled] = getDefaultPermission(poAllowJavascript) == Allow;
if (query.next()) {
Permission perm;
auto paerToBool = [&perm, &attribute]() {
if (perm == Allow) {
attribute[QWebEngineSettings::AutoLoadImages] = true;
}
else if (perm == Deny) {
attribute[QWebEngineSettings::AutoLoadImages] = false;
}
};
perm = intToPermission(query.value(QSL("allow_images")).toInt());
if (perm == Allow) {
attribute[QWebEngineSettings::AutoLoadImages] = true;
}
else if (perm == Deny) {
attribute[QWebEngineSettings::AutoLoadImages] = false;
}
perm = intToPermission(query.value(QSL("allow_javascript")).toInt());
if (perm == Allow) {
attribute[QWebEngineSettings::JavascriptEnabled] = true;
}
else if (perm == Deny) {
attribute[QWebEngineSettings::JavascriptEnabled] = false;
}
}
return attribute;
}
void SiteSettingsManager::setJavascript(const QUrl& url, const int value)
{
setOption(poAllowJavascript, url, value);

View File

@ -46,8 +46,23 @@ public:
Q_ENUM(Permission);
enum PageOptions {
poAllowJavascript,
poAllowImages,
/* Javascript stuff */
poAllowJavascript,
poJavascriptCanOpenWindows,
poJavascriptCanAccessClipboard,
poJavascriptCanPaste,
poAllowWindowActivationFromJavaScript,
poLocalStorageEnabled,
poScrollAnimatorEnabled,
poFullScreenSupportEnabled,
poAllowRunningInsecureContent,
poAllowGeolocationOnInsecureOrigins,
poPlaybackRequiresUserGesture,
poWebRTCPublicInterfacesOnly,
poAllowCookies,
poZoomLevel,
poAllowNotifications,
@ -66,7 +81,7 @@ public:
Permission AllowJavascript;
Permission AllowImages;
Permission AllowCookies;
Permission ZoomLevel;
int ZoomLevel;
Permission AllowNotifications;
Permission AllowGeolocation;
Permission AllowMediaAudioCapture;
@ -92,6 +107,8 @@ public:
*/
SiteWebEngineSettings getWebEngineSettings(const QUrl &url);
QHash<QWebEngineSettings::WebAttribute, bool> getWebAttributes(const QUrl &url);
void setJavascript(const QUrl &url, const int value);
void setImages(const QUrl &url, const int value);