mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 09:32:12 +01:00
Initial introduction of SiteSettingsManager
- New database SQL querry - Update current database - Preparation for setting site settings WIP: This is an initial draft and the design of the database table might change as the development goes on. WIP2: Even this commit and commit message will be scraped. Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
parent
34bbe6fa76
commit
dc9ff73693
|
@ -150,6 +150,7 @@ set(SRCS ${SRCS}
|
|||
other/qzsettings.cpp
|
||||
other/siteinfo.cpp
|
||||
other/siteinfowidget.cpp
|
||||
other/sitesettingsmanager.cpp
|
||||
other/statusbar.cpp
|
||||
other/updater.cpp
|
||||
other/useragentmanager.cpp
|
||||
|
@ -380,6 +381,7 @@ set(SRCS ${SRCS}
|
|||
other/qzsettings.h
|
||||
other/siteinfo.h
|
||||
other/siteinfowidget.h
|
||||
other/sitesettingsmanager.h
|
||||
other/statusbar.h
|
||||
other/updater.h
|
||||
other/useragentmanager.h
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "searchenginesmanager.h"
|
||||
#include "desktopnotificationsfactory.h"
|
||||
#include "html5permissions/html5permissionsmanager.h"
|
||||
#include "sitesettingsmanager.h"
|
||||
#include "scripts.h"
|
||||
#include "sessionmanager.h"
|
||||
#include "closedwindowsmanager.h"
|
||||
|
@ -105,6 +106,7 @@ MainApplication::MainApplication(int &argc, char** argv)
|
|||
, m_closedWindowsManager(nullptr)
|
||||
, m_protocolHandlerManager(nullptr)
|
||||
, m_html5PermissionsManager(nullptr)
|
||||
, m_siteSettingsManager(nullptr)
|
||||
, m_desktopNotifications(nullptr)
|
||||
, m_webProfile(nullptr)
|
||||
, m_autoSaver(nullptr)
|
||||
|
@ -645,6 +647,14 @@ HTML5PermissionsManager* MainApplication::html5PermissionsManager()
|
|||
return m_html5PermissionsManager;
|
||||
}
|
||||
|
||||
SiteSettingsManager * MainApplication::siteSettingsManager()
|
||||
{
|
||||
if (!m_siteSettingsManager) {
|
||||
m_siteSettingsManager = new SiteSettingsManager(this);
|
||||
}
|
||||
return m_siteSettingsManager;
|
||||
}
|
||||
|
||||
DesktopNotificationsFactory* MainApplication::desktopNotifications()
|
||||
{
|
||||
if (!m_desktopNotifications) {
|
||||
|
|
|
@ -53,6 +53,7 @@ class ProxyStyle;
|
|||
class SessionManager;
|
||||
class ClosedWindowsManager;
|
||||
class ProtocolHandlerManager;
|
||||
class SiteSettingsManager;
|
||||
|
||||
class FALKON_EXPORT MainApplication : public QtSingleApplication
|
||||
{
|
||||
|
@ -111,6 +112,7 @@ public:
|
|||
ClosedWindowsManager* closedWindowsManager();
|
||||
ProtocolHandlerManager *protocolHandlerManager();
|
||||
HTML5PermissionsManager* html5PermissionsManager();
|
||||
SiteSettingsManager* siteSettingsManager();
|
||||
DesktopNotificationsFactory* desktopNotifications();
|
||||
QWebEngineProfile* webProfile() const;
|
||||
QWebEngineSettings *webSettings() const;
|
||||
|
@ -188,6 +190,7 @@ private:
|
|||
ClosedWindowsManager* m_closedWindowsManager;
|
||||
ProtocolHandlerManager *m_protocolHandlerManager;
|
||||
HTML5PermissionsManager* m_html5PermissionsManager;
|
||||
SiteSettingsManager* m_siteSettingsManager;
|
||||
DesktopNotificationsFactory* m_desktopNotifications;
|
||||
QWebEngineProfile* m_webProfile;
|
||||
|
||||
|
|
|
@ -89,6 +89,7 @@ void ProfileManager::initCurrentProfile(const QString &profileName)
|
|||
|
||||
updateCurrentProfile();
|
||||
connectDatabase();
|
||||
updateDatabase();
|
||||
}
|
||||
|
||||
int ProfileManager::createProfile(const QString &profileName)
|
||||
|
@ -311,3 +312,64 @@ void ProfileManager::connectDatabase()
|
|||
|
||||
SqlDatabase::instance()->setDatabase(db);
|
||||
}
|
||||
|
||||
void ProfileManager::updateDatabase()
|
||||
{
|
||||
if ((Qz::VERSION) == profileVersion) {
|
||||
return;
|
||||
}
|
||||
|
||||
Updater::Version prof(profileVersion);
|
||||
|
||||
/* Profile is from newer version than running application */
|
||||
if (prof > Updater::Version(Qz::VERSION)) {
|
||||
// Ignore
|
||||
return;
|
||||
}
|
||||
|
||||
/* Do not try to update database of too old profile */
|
||||
if (prof < Updater::Version(QStringLiteral("1.9.0"))) {
|
||||
std::cout << "Falkon: Using profile from QupZilla " << qPrintable(profileVersion) << " is not supported!" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Update in 22.11.00 */
|
||||
if (prof < Updater::Version(QStringLiteral("22.11.70"))) {
|
||||
std::cout << "Falkon: Updating database to version " << qPrintable(Qz::VERSION) << std::endl;
|
||||
|
||||
QSqlQuery query(SqlDatabase::instance()->database());
|
||||
query.prepare(QStringLiteral(
|
||||
"CREATE TABLE IF NOT EXISTS site_settings ("
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"domain TEXT NOT NULL,"
|
||||
"zoom_level INTEGER DEFAULT 0,"
|
||||
"allow_cookies INTEGER DEFAULT 0,"
|
||||
"allow_images INTEGER DEFAULT 0,"
|
||||
"allow_javascript INTEGER DEFAULT 0,"
|
||||
"allow_notifications INTEGER DEFAULT 0,"
|
||||
"allow_geolocation INTEGER DEFAULT 0,"
|
||||
"allow_media_audio_capture INTEGER DEFAULT 0,"
|
||||
"allow_media_video_capture INTEGER DEFAULT 0,"
|
||||
"allow_media_audio_video_capture INTEGER DEFAULT 0,"
|
||||
"allow_mouse_lock INTEGER DEFAULT 0,"
|
||||
"allow_desktop_video_capture INTEGER DEFAULT 0,"
|
||||
"allow_desktop_audio_video_capture INTEGER DEFAULT 0"
|
||||
");"
|
||||
));
|
||||
|
||||
if (!query.exec()) {
|
||||
qCritical() << "Error while creating table 'site_settings' in database: " << query.lastError().text();
|
||||
qFatal("ProfileManager::updateDatabase Unable to create table 'site_settings' in the database!");
|
||||
}
|
||||
|
||||
query.prepare(QStringLiteral(
|
||||
"CREATE UNIQUE INDEX IF NOT EXISTS site_settings_domainuniqueindex ON site_settings (domain);"
|
||||
));
|
||||
|
||||
if (!query.exec()) {
|
||||
qCritical() << "Error while creating unique index for table 'site_settings': " << query.lastError().text();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,8 +52,11 @@ private:
|
|||
void updateProfile(const QString ¤t, const QString &profile);
|
||||
void copyDataToProfile();
|
||||
void migrateFromQupZilla();
|
||||
void updateDatabase();
|
||||
|
||||
void connectDatabase();
|
||||
|
||||
QString profileVersion;
|
||||
};
|
||||
|
||||
#endif // PROFILEMANAGER_H
|
||||
|
|
|
@ -55,4 +55,22 @@ CREATE TABLE icons (
|
|||
);
|
||||
CREATE UNIQUE INDEX icons_urluniqueindex ON icons (url);
|
||||
|
||||
CREATE TABLE site_settings (
|
||||
id INTEGER PRIMARY KEY,
|
||||
server TEXT NOT NULL,
|
||||
zoom_level INTEGER DEFAULT 0,
|
||||
allow_cookies INTEGER DEFAULT 0,
|
||||
allow_images INTEGER DEFAULT 0,
|
||||
allow_javascript INTEGER DEFAULT 0,
|
||||
allow_notifications INTEGER DEFAULT 0,
|
||||
allow_geolocation INTEGER DEFAULT 0,
|
||||
allow_media_audio_capture INTEGER DEFAULT 0,
|
||||
allow_media_video_capture INTEGER DEFAULT 0,
|
||||
allow_media_audio_video_capture INTEGER DEFAULT 0,
|
||||
allow_mouse_lock INTEGER DEFAULT 0,
|
||||
allow_desktop_video_capture INTEGER DEFAULT 0,
|
||||
allow_desktop_audio_video_capture INTEGER DEFAULT 0
|
||||
);
|
||||
CREATE UNIQUE INDEX site_settings_serveruniqueindex ON site_settings (server);
|
||||
|
||||
-- Data
|
||||
|
|
77
src/lib/other/sitesettingsmanager.cpp
Normal file
77
src/lib/other/sitesettingsmanager.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2022 Juraj Oravec <jurajoravec@mailo.com>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "sitesettingsmanager.h"
|
||||
|
||||
#include "mainapplication.h"
|
||||
#include "settings.h"
|
||||
#include "sqldatabase.h"
|
||||
#include <QUrl>
|
||||
#include <qwebenginesettings.h>
|
||||
|
||||
SiteSettingsManager::SiteSettingsManager ( QObject* parent )
|
||||
: QObject(parent)
|
||||
{
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
SiteSettingsManager::~SiteSettingsManager() noexcept
|
||||
{
|
||||
}
|
||||
|
||||
void SiteSettingsManager::loadSettings()
|
||||
{
|
||||
Settings settings;
|
||||
settings.beginGroup("Web-Browser-Settings");
|
||||
// m_isSaving = settings.value("allowPerDomainZoom", true).toBool();
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
SiteWebEngineSettings SiteSettingsManager::getWebEngineSettings(const QUrl& url)
|
||||
{
|
||||
SiteWebEngineSettings settings;
|
||||
|
||||
QSqlQuery query(SqlDatabase::instance()->database());
|
||||
query.prepare("SELECT allow_images, allow_javascript FROM history WHERE server=?");
|
||||
query.bindValue(0, url.host());
|
||||
query.exec();
|
||||
|
||||
if (query.next()) {
|
||||
int allow_images = query.value("allow_images").toInt();
|
||||
int allow_javascript = query.value("allow_javascript").toInt();
|
||||
|
||||
if (allow_images == 0) {
|
||||
settings.allowImages = mApp->webSettings()->testAttribute(QWebEngineSettings::AutoLoadImages);
|
||||
}
|
||||
else {
|
||||
settings.allowImages = (allow_images == 1);
|
||||
}
|
||||
|
||||
if (allow_javascript == 0) {
|
||||
settings.allowJavaScript = mApp->webSettings()->testAttribute(QWebEngineSettings::JavascriptEnabled);
|
||||
}
|
||||
else {
|
||||
settings.allowJavaScript = (allow_javascript == 1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
settings.allowImages = mApp->webSettings()->testAttribute(QWebEngineSettings::AutoLoadImages);
|
||||
settings.allowJavaScript = mApp->webSettings()->testAttribute(QWebEngineSettings::JavascriptEnabled);
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
53
src/lib/other/sitesettingsmanager.h
Normal file
53
src/lib/other/sitesettingsmanager.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2022 Juraj Oravec <jurajoravec@mailo.com>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#ifndef SITESETTINGS_MANAGER_H
|
||||
#define SITESETTINGS_MANAGER_H
|
||||
|
||||
#include "qzcommon.h"
|
||||
|
||||
class QUrl;
|
||||
|
||||
class SiteWebEngineSettings
|
||||
{
|
||||
public:
|
||||
bool allowJavaScript;
|
||||
bool allowImages;
|
||||
};
|
||||
|
||||
class FALKON_EXPORT SiteSettingsManager : QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SiteSettingsManager(QObject *parent = 0);
|
||||
~SiteSettingsManager();
|
||||
|
||||
void loadSettings();
|
||||
|
||||
/**
|
||||
* @brief Get settings which should be applied to webpage before loading.
|
||||
* Since this is using blocking database querry group all settings
|
||||
* in one SQL call for faster laoding.
|
||||
* @param url Address for which to fetch the settings
|
||||
*/
|
||||
SiteWebEngineSettings getWebEngineSettings(const QUrl &url);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif // SITESETTINGS_MANAGER_H
|
Loading…
Reference in New Issue
Block a user