Verified Commit 16761bda authored by Jonah Brüchert's avatar Jonah Brüchert 🌳

Port Settings to KConfigXT

parent 7b047a1e
......@@ -2,7 +2,7 @@ project(angelfish)
cmake_minimum_required(VERSION 2.8.12)
set(KF5_MIN_VERSION "5.62.0")
set(QT_MIN_VERSION "5.13.0")
set(QT_MIN_VERSION "5.14.0")
option(BUILD_TESTING "Build test programs" ON)
......
......@@ -9,11 +9,15 @@ set(angelfish_webapp_SRCS
../src/urlobserver.cpp
../src/useragent.cpp
../src/tabsmodel.cpp
../src/settingshelper.cpp
webapp-resources.qrc
../src/resources.qrc
)
add_executable(angelfish-webapp ${angelfish_webapp_SRCS} ${RESOURCES} ${WEBAPP_RESOURCES})
kconfig_add_kcfg_files(angelfish-webapp GENERATE_MOC ../src/angelfishsettings.kcfgc)
target_include_directories(angelfish-webapp PRIVATE ../src/)
target_compile_definitions(angelfish-webapp PRIVATE -DQT_NO_CAST_FROM_ASCII)
target_link_libraries(angelfish-webapp
......
......@@ -34,9 +34,6 @@ Kirigami.ApplicationWindow {
id: webBrowser
title: webView.title
// Pointer to browser settings
property Settings settings: settings
property int borderWidth: Math.round(Kirigami.Units.gridUnit / 18);
property color borderColor: Kirigami.Theme.highlightColor;
......@@ -136,10 +133,6 @@ Kirigami.ApplicationWindow {
property alias height: webBrowser.height
}
Settings {
id: settings
}
function popSubPages() {
while (webBrowser.pageStack.depth > 1)
webBrowser.pageStack.pop();
......
......@@ -2,11 +2,15 @@ include(ECMAddTests)
find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Test Sql Gui Quick)
include_directories(../src)
include_directories(../src ${CMAKE_CURRENT_BINARY_DIR}/../src/)
set(SETTINGS_SHARED_SRCS ../src/settingshelper.cpp)
kconfig_add_kcfg_files(SETTINGS_SHARED_SRCS GENERATE_MOC ../src/angelfishsettings.kcfgc)
ecm_add_test(dbmanagertest.cpp ../src/dbmanager.cpp ../src/iconimageprovider.cpp ../src/sqlquerymodel.cpp
${SETTINGS_SHARED_SRCS}
TEST_NAME dbmanagertest
LINK_LIBRARIES Qt5::Test Qt5::Sql Qt5::Quick
LINK_LIBRARIES Qt5::Test Qt5::Sql Qt5::Quick KF5::ConfigGui
)
ecm_add_test(useragenttest.cpp ../src/useragent.cpp
......@@ -15,11 +19,18 @@ ecm_add_test(useragenttest.cpp ../src/useragent.cpp
)
ecm_add_test(browsermanagertest.cpp ../src/browsermanager.cpp ../src/dbmanager.cpp ../src/iconimageprovider.cpp ../src/urlutils.cpp
${SETTINGS_SHARED_SRCS}
TEST_NAME browsermanagertest
LINK_LIBRARIES Qt5::Test Qt5::Sql Qt5::Gui Qt5::Quick
LINK_LIBRARIES Qt5::Test Qt5::Sql Qt5::Gui Qt5::Quick KF5::ConfigGui
)
ecm_add_test(tabsmodeltest.cpp ../src/tabsmodel.cpp ../src/browsermanager.cpp ../src/dbmanager.cpp ../src/iconimageprovider.cpp
${SETTINGS_SHARED_SRCS}
TEST_NAME tabsmodeltest
LINK_LIBRARIES Qt5::Test Qt5::Sql Qt5::Gui Qt5::Quick
LINK_LIBRARIES Qt5::Test Qt5::Sql Qt5::Gui Qt5::Quick KF5::ConfigGui
)
ecm_add_test(configtest.cpp ${SETTINGS_SHARED_SRCS}
TEST_NAME configtest
LINK_LIBRARIES Qt5::Test KF5::ConfigGui
)
......@@ -24,6 +24,7 @@
#include "browsermanager.h"
#include "urlutils.h"
#include "angelfishsettings.h"
class UserAgentTest : public QObject
{
......@@ -69,7 +70,6 @@ private Q_SLOTS:
QCOMPARE(UrlUtils::urlFromUserInput(incompleteUrl), completeUrl);
}
private:
BrowserManager *m_browserManager;
};
......
/*
* Copyright 2020 Jonah Brüchert <jbb@kaidan.im>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License version 2 as published by the Free Software Foundation;
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <QTest>
#include "angelfishsettings.h"
class ConfigTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testDefaultValues() {
QCOMPARE(AngelfishSettings::defaultHomepageValue(), "https://start.duckduckgo.com");
QCOMPARE(AngelfishSettings::defaultSearchBaseUrlValue(), "https://start.duckduckgo.com/?q=");
QCOMPARE(AngelfishSettings::defaultWebAutoLoadImagesValue(), true);
QCOMPARE(AngelfishSettings::defaultWebJavaScriptEnabledValue(), true);
QCOMPARE(AngelfishSettings::defaultNavBarMainMenuValue(), true);
QCOMPARE(AngelfishSettings::defaultNavBarTabsValue(), true);
}
void testSettingsHelper() {
qputenv("QT_QUICK_CONTROLS_MOBILE", "true");
QCOMPARE(SettingsHelper::instance()->isMobile(), true);
QCOMPARE(AngelfishSettings::defaultNavBarBackValue(), false);
QCOMPARE(AngelfishSettings::defaultNavBarForwardValue(), false);
QCOMPARE(AngelfishSettings::defaultNavBarReloadValue(), false);
qputenv("QT_QUICK_CONTROLS_MOBILE", "false");
QCOMPARE(SettingsHelper::instance()->isMobile(), false);
QCOMPARE(AngelfishSettings::defaultNavBarBackValue(), true);
QCOMPARE(AngelfishSettings::defaultNavBarForwardValue(), true);
QCOMPARE(AngelfishSettings::defaultNavBarReloadValue(), true);
}
};
QTEST_GUILESS_MAIN(ConfigTest);
#include "configtest.moc"
......@@ -10,11 +10,16 @@ set(angelfish_SRCS
urlobserver.cpp
tabsmodel.cpp
desktopfilegenerator.cpp
settingshelper.cpp
)
qt5_add_resources(RESOURCES resources.qrc)
add_executable(angelfish ${angelfish_SRCS} ${RESOURCES})
kconfig_add_kcfg_files(angelfish GENERATE_MOC angelfishsettings.kcfgc)
target_include_directories(angelfish PRIVATE)
target_compile_definitions(angelfish PRIVATE -DQT_NO_CAST_FROM_ASCII)
target_link_libraries(angelfish
Qt5::Core
......@@ -25,6 +30,8 @@ target_link_libraries(angelfish
Qt5::WebEngine
KF5::I18n
KF5::ConfigCore
KF5::ConfigGui
)
install(TARGETS angelfish ${KF5_INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES angelfishsettings.kcfg DESTINATION ${KCFG_INSTALL_DIR})
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="angelfishrc" />
<include>"settingshelper.h"</include>
<group name="General">
<!-- Search Engine -->
<entry key="searchCustomUrl" type="string"></entry>
</group>
<group name="Browser">
<entry key="homepage" type="string">
<default>QStringLiteral("https://start.duckduckgo.com")</default>
</entry>
<entry key="searchBaseUrl" type="string">
<default>QStringLiteral("https://start.duckduckgo.com/?q=")</default>
</entry>
</group>
<!-- Remember states -->
<group name="WebView">
<entry key="webAutoLoadImages" type="bool">
<default>true</default>
</entry>
<entry key="webJavaScriptEnabled" type="bool">
<default>true</default>
</entry>
</group>
<group name="NavigationBar">
<entry key="navBarMainMenu" type="bool">
<default>true</default>
</entry>
<entry key="navBarTabs" type="bool">
<default>true</default>
</entry>
<entry key="navBarBack" type="bool">
<default>!SettingsHelper::instance()->isMobile()</default>
</entry>
<entry key="navBarForward" type="bool">
<default>!SettingsHelper::instance()->isMobile()</default>
</entry>
<entry key="navBarReload" type="bool">
<default>!SettingsHelper::instance()->isMobile()</default>
</entry>
<entry key="navBarContextMenu" type="bool"></entry>
</group>
</kcfg>
File=angelfishsettings.kcfg
ClassName=AngelfishSettings
Mutators=true
DefaultValueGetters=true
GenerateProperties=true
ParentInConstructor=true
Singleton=true
Notifiers=true
......@@ -26,12 +26,13 @@
#include <QSettings>
#include <QUrl>
#include "angelfishsettings.h"
BrowserManager *BrowserManager::s_instance = nullptr;
BrowserManager::BrowserManager(QObject *parent)
: QObject(parent)
, m_dbmanager(new DBManager)
, m_settings(new QSettings(this))
{
connect(m_dbmanager, &DBManager::databaseTableChanged, this, &BrowserManager::databaseTableChanged);
}
......@@ -81,20 +82,22 @@ void BrowserManager::setHomepage(const QString &homepage)
{
if (this->homepage() == homepage)
return;
m_settings->setValue(QStringLiteral("browser/homepage"), homepage);
AngelfishSettings::self()->setHomepage(homepage);
emit homepageChanged();
}
QString BrowserManager::homepage()
{
return m_settings->value(QStringLiteral("browser/homepage"), QStringLiteral("https://start.duckduckgo.com")).toString();
return AngelfishSettings::self()->homepage();
}
void BrowserManager::setSearchBaseUrl(const QString &searchBaseUrl)
{
if (this->searchBaseUrl() == searchBaseUrl)
return;
m_settings->setValue(QStringLiteral("browser/searchBaseUrl"), searchBaseUrl);
AngelfishSettings::self()->setSearchBaseUrl(searchBaseUrl);
emit searchBaseUrlChanged();
}
......@@ -108,14 +111,9 @@ void BrowserManager::setInitialUrl(const QString &initialUrl)
m_initialUrl = initialUrl;
}
QSettings *BrowserManager::settings() const
{
return m_settings;
}
QString BrowserManager::searchBaseUrl()
{
return m_settings->value(QStringLiteral("browser/searchBaseUrl"), QStringLiteral("https://start.duckduckgo.com/?q=")).toString();
return AngelfishSettings::self()->searchBaseUrl();
}
BrowserManager *BrowserManager::instance()
......
......@@ -85,8 +85,6 @@ private:
DBManager *m_dbmanager;
QSettings *m_settings;
QString m_initialUrl;
static BrowserManager *s_instance;
......
......@@ -58,7 +58,7 @@ Item {
Controls.ToolButton {
id: mainMenuButton
icon.name: rootPage.privateMode ? "view-private" : "open-menu-symbolic"
visible: webBrowser.landscape || settings.navBarMainMenu
visible: webBrowser.landscape || Settings.navBarMainMenu
Layout.preferredWidth: buttonSize
Layout.preferredHeight: buttonSize
......@@ -69,7 +69,7 @@ Item {
}
Controls.ToolButton {
visible: webBrowser.landscape || settings.navBarTabs
visible: webBrowser.landscape || Settings.navBarTabs
Layout.preferredWidth: buttonSize
Layout.preferredHeight: buttonSize
......@@ -109,7 +109,7 @@ Item {
Layout.preferredWidth: buttonSize
Layout.preferredHeight: buttonSize
visible: currentWebView.canGoBack && settings.navBarBack
visible: currentWebView.canGoBack && Settings.navBarBack
icon.name: "go-previous"
Kirigami.Theme.inherit: true
......@@ -127,7 +127,7 @@ Item {
Layout.preferredWidth: buttonSize
Layout.preferredHeight: buttonSize
visible: currentWebView.canGoForward && settings.navBarForward
visible: currentWebView.canGoForward && Settings.navBarForward
icon.name: "go-next"
Kirigami.Theme.inherit: true
......@@ -177,7 +177,10 @@ Item {
if (labelItem.scheme === "http" || labelItem.scheme === "https") {
var h = UrlUtils.urlHostPort(currentWebView.requestedUrl);
var p = UrlUtils.urlPath(currentWebView.requestedUrl);
if (p === "/") p = ""
if (p === "/")
p = ""
return '%1<font size="2">%2</font>'.arg(h).arg(p);
}
return currentWebView.requestedUrl;
......@@ -197,7 +200,7 @@ Item {
Layout.preferredWidth: buttonSize
Layout.preferredHeight: buttonSize
visible: settings.navBarReload
visible: Settings.navBarReload
icon.name: currentWebView.loading ? "process-stop" : "view-refresh"
Kirigami.Theme.inherit: true
......@@ -215,7 +218,7 @@ Item {
Layout.preferredWidth: buttonSize
Layout.preferredHeight: buttonSize
visible: webBrowser.landscape || settings.navBarContextMenu
visible: webBrowser.landscape || Settings.navBarContextMenu
icon.name: "overflow-menu"
Kirigami.Theme.inherit: true
......
/***************************************************************************
* *
* Copyright 2020 Rinigus <rinigus.git@gmail.com> *
* 2020 Jonah Brüchert <jbb@kaidan.im> *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
* *
***************************************************************************/
import QtQuick 2.3
import Qt.labs.settings 1.0 as QtSettings
import org.kde.kirigami 2.7 as Kirigami
import org.kde.mobile.angelfish 1.0
QtObject {
id: settings
// All the settings that are initialized using functions
// leading to property bindings, should be unbound after
// component construction in Component.onCompleted. Otherwise,
// it can lead to the conflicts between loading of the
// settings from configuration file and bindings. Example
// issue at
// https://invent.kde.org/kde/plasma-angelfish/-/issues/27
// WebView
property bool webAutoLoadImages: true
property bool webJavascriptEnabled: true
// Navigation bar
property bool navBarMainMenu: true
property bool navBarTabs: true
property bool navBarBack: !Kirigami.Settings.isMobile
property bool navBarForward: !Kirigami.Settings.isMobile
property bool navBarReload: !Kirigami.Settings.isMobile
property bool navBarContextMenu: true
// Search engine
property string searchCustomUrl
///////////////////////////////////
// settings storage
property QtSettings.Settings _settingsWebView: QtSettings.Settings {
category: "WebView"
property alias autoLoadImages: settings.webAutoLoadImages
property alias javascriptEnabled: settings.webJavascriptEnabled
}
property QtSettings.Settings _settingsNavBar: QtSettings.Settings {
category: "NavigationBar"
property alias mainMenu: settings.navBarMainMenu
property alias tabs: settings.navBarTabs
property alias back: settings.navBarBack
property alias forward: settings.navBarForward
property alias reload: settings.navBarReload
property alias contextMenu: settings.navBarContextMenu
}
property QtSettings.Settings _settingsSearch: QtSettings.Settings {
category: "SearchEngine"
property alias customUrl: settings.searchCustomUrl
}
Component.onCompleted: {
// break bindings to avoid conflicts with
// loading of the settings
navBarBack = navBarBack;
navBarForward = navBarForward;
navBarReload = navBarReload;
}
}
......@@ -67,11 +67,11 @@ Kirigami.ScrollablePage {
Controls.SwitchDelegate {
text: i18n("Main menu in portrait")
Layout.fillWidth: true
checked: settings.navBarMainMenu
checked: Settings.navBarMainMenu
leftPadding: Kirigami.Units.gridUnit
rightPadding: Kirigami.Units.gridUnit
implicitHeight: parent.itemHeight
onCheckedChanged: settings.navBarMainMenu = checked
onCheckedChanged: Settings.navBarMainMenu = checked
}
Kirigami.Separator {
......@@ -81,11 +81,11 @@ Kirigami.ScrollablePage {
Controls.SwitchDelegate {
text: i18n("Tabs in portrait")
Layout.fillWidth: true
checked: settings.navBarTabs
checked: Settings.navBarTabs
leftPadding: Kirigami.Units.gridUnit
rightPadding: Kirigami.Units.gridUnit
implicitHeight: parent.itemHeight
onCheckedChanged: settings.navBarTabs = checked
onCheckedChanged: Settings.navBarTabs = checked
}
Kirigami.Separator {
......@@ -95,11 +95,11 @@ Kirigami.ScrollablePage {
Controls.SwitchDelegate {
text: i18n("Context menu in portrait")
Layout.fillWidth: true
checked: settings.navBarContextMenu
checked: Settings.navBarContextMenu
leftPadding: Kirigami.Units.gridUnit
rightPadding: Kirigami.Units.gridUnit
implicitHeight: parent.itemHeight
onCheckedChanged: settings.navBarContextMenu = checked
onCheckedChanged: Settings.navBarContextMenu = checked
}
Kirigami.Separator {
......@@ -109,11 +109,11 @@ Kirigami.ScrollablePage {
Controls.SwitchDelegate {
text: i18n("Go back")
Layout.fillWidth: true
checked: settings.navBarBack
checked: Settings.navBarBack
leftPadding: Kirigami.Units.gridUnit
rightPadding: Kirigami.Units.gridUnit
implicitHeight: parent.itemHeight
onCheckedChanged: settings.navBarBack = checked
onCheckedChanged: Settings.navBarBack = checked
}
Kirigami.Separator {
......@@ -123,11 +123,11 @@ Kirigami.ScrollablePage {
Controls.SwitchDelegate {
text: i18n("Go forward")
Layout.fillWidth: true
checked: settings.navBarForward
checked: Settings.navBarForward
leftPadding: Kirigami.Units.gridUnit
rightPadding: Kirigami.Units.gridUnit
implicitHeight: parent.itemHeight
onCheckedChanged: settings.navBarForward = checked
onCheckedChanged: Settings.navBarForward = checked
}
Kirigami.Separator {
......@@ -137,11 +137,11 @@ Kirigami.ScrollablePage {
Controls.SwitchDelegate {
text: i18n("Reload/Stop")
Layout.fillWidth: true
checked: settings.navBarReload
checked: Settings.navBarReload
leftPadding: Kirigami.Units.gridUnit
rightPadding: Kirigami.Units.gridUnit
implicitHeight: parent.itemHeight
onCheckedChanged: settings.navBarReload = checked
onCheckedChanged: Settings.navBarReload = checked
}
Kirigami.Separator {
......
......@@ -48,8 +48,8 @@ Kirigami.ScrollablePage {
Controls.SwitchDelegate {
text: i18n("Enable JavaScript")
Layout.fillWidth: true
checked: settings.webJavascriptEnabled
onCheckedChanged: settings.webJavascriptEnabled = checked
checked: Settings.webJavaScriptEnabled
onClicked: Settings.webJavaScriptEnabled = checked
leftPadding: Kirigami.Units.gridUnit
rightPadding: Kirigami.Units.gridUnit
implicitHeight: Kirigami.Units.gridUnit * 2.5
......@@ -62,8 +62,8 @@ Kirigami.ScrollablePage {
Controls.SwitchDelegate {
text: i18n("Load images")
Layout.fillWidth: true
checked: settings.webAutoLoadImages
onCheckedChanged: settings.webAutoLoadImages = checked
checked: Settings.webAutoLoadImages
onClicked: Settings.webAutoLoadImages = checked
leftPadding: Kirigami.Units.gridUnit
rightPadding: Kirigami.Units.gridUnit
implicitHeight: Kirigami.Units.gridUnit * 2.5
......
......@@ -54,10 +54,10 @@ Kirigami.ScrollablePage {
id: searchEnginePopup
title: i18n("Search Engine")
description: i18n("Base URL of your preferred search engine")
text: settings.searchCustomUrl
text: Settings.searchCustomUrl
onAccepted: {
var t = UrlUtils.urlFromUserInput(searchEnginePopup.text);
settings.searchCustomUrl = t;
Settings.searchCustomUrl = t;
baseUrl = t;
searchEngines.setProperty(searchEngines.count - 1, "url", t);
}
......@@ -161,6 +161,6 @@ Kirigami.ScrollablePage {
}
Component.onCompleted: {
searchEngines.append({ "title": list.customName, "url": settings.searchCustomUrl });
searchEngines.append({ "title": list.customName, "url": Settings.searchCustomUrl });
}
}
......@@ -98,8 +98,8 @@ WebEngineView {
}
settings {
autoLoadImages: webBrowser.settings.webAutoLoadImages
javascriptEnabled: webBrowser.settings.webJavascriptEnabled
autoLoadImages: Settings.webAutoLoadImages
javascriptEnabled: Settings.webJavascriptEnabled
// Disable builtin error pages in favor of our own
errorPageEnabled: false
// Load larger touch icons
......
......@@ -47,9 +47,6 @@ Kirigami.ApplicationWindow {
// them according to the current mode.
property ListWebView tabs: rootPage.privateMode ? privateTabs : regularTabs
// Pointer to browser settings
property Settings settings: settings
// Used to determine if the window is in landscape mode
property bool landscape: width > height
......@@ -430,10 +427,6 @@ Kirigami.ApplicationWindow {
property alias height: webBrowser.height
}
Settings {
id: settings
}
Component.onCompleted: rootPage.initialized = true
function popSubPages() {
......
......@@ -34,6 +34,7 @@
#include "urlutils.h"
#include "useragent.h"
#include "desktopfilegenerator.h"
#include "angelfishsettings.h"
Q_DECL_EXPORT int main(int argc, char *argv[])
{
......@@ -90,10 +91,17 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
return static_cast<QObject *>(BrowserManager::instance());
});
// Angelfish-webapp generator
qmlRegisterSingletonType<DesktopFileGenerator>("org.kde.mobile.angelfish", 1, 0, "DesktopFileGenerator", [](QQmlEngine *engine, QJSEngine *) -> QObject * {
return static_cast<QObject *>(new DesktopFileGenerator(engine));
});
qmlRegisterSingletonInstance<AngelfishSettings>("org.kde.mobile.angelfish", 1, 0, "Settings", AngelfishSettings::self());
QObject::connect(QApplication::instance(), &QCoreApplication::aboutToQuit, QApplication::instance(), [] {
AngelfishSettings::self()->save();
});
// Load QML
engine.load(QUrl(QStringLiteral("qrc:///webbrowser.qml")));
......
......@@ -6,7 +6,6 @@
<file alias="HistorySheet.qml">contents/ui/HistorySheet.qml</file>
<file alias="ListWebView.qml">contents/ui/ListWebView.qml</file>
<file alias="Navigation.qml">contents/ui/Navigation.qml</file>
<file alias="Settings.qml">contents/ui/Settings.qml</file>
<file alias="SettingsPage.qml">contents/ui/SettingsPage.qml</file>