Commit b5c22410 authored by Jonah Brüchert's avatar Jonah Brüchert 🌳

Add settings for homepage and search engine

parent 3776133b
......@@ -21,13 +21,16 @@
#include <QDebug>
#include <QUrl>
#include <QSettings>
using namespace AngelFish;
BrowserManager::BrowserManager(QObject *parent)
: QObject(parent),
m_bookmarks(nullptr),
m_history(nullptr)
m_history(nullptr),
m_settings(new QSettings)
Please register or sign in to reply
{
}
......@@ -35,6 +38,7 @@ BrowserManager::~BrowserManager()
{
history()->save();
bookmarks()->save();
delete m_settings;
Please register or sign in to reply
}
void BrowserManager::reload()
......@@ -94,3 +98,24 @@ QString BrowserManager::urlFromUserInput(const QString& input)
return url.toString();
}
void BrowserManager::setHomepage(const QString homepage)
  • while QString is already CopyOnWrite internally people still use const QString& typically

Please register or sign in to reply
{
m_settings->setValue("browser/homepage", homepage);
emit homepageChanged();
}
QString BrowserManager::homepage()
{
return m_settings->value("browser/homepage", "https://searx.me").toString();
}
void BrowserManager::setSearchBaseUrl(const QString searchBaseUrl)
Please register or sign in to reply
{
m_settings->setValue("browser/searchBaseUrl", searchBaseUrl);
emit searchBaseUrlChanged();
}
QString BrowserManager::searchBaseUrl()
{
return m_settings->value("browser/searchBaseUrl", "https://searx.me/?q=").toString();
}
......@@ -27,6 +27,8 @@
#include "urlmodel.h"
class QSettings;
namespace AngelFish {
/**
* @class BookmarksManager
......@@ -41,23 +43,31 @@ class BrowserManager : public QObject
Q_PROPERTY(QAbstractListModel* bookmarks READ bookmarks NOTIFY bookmarksChanged)
Q_PROPERTY(QAbstractListModel* history READ history NOTIFY historyChanged)
Q_PROPERTY(QString homepage READ homepage WRITE setHomepage NOTIFY homepageChanged)
Q_PROPERTY(QString searchBaseUrl READ searchBaseUrl WRITE setSearchBaseUrl NOTIFY searchBaseUrlChanged)
public:
BrowserManager(QObject *parent = 0);
BrowserManager(QObject *parent = nullptr);
~BrowserManager();
UrlModel* bookmarks();
UrlModel* history();
Q_INVOKABLE static QString urlFromUserInput(const QString &input);
QString homepage();
QString searchBaseUrl();
Q_INVOKABLE static QString urlFromUserInput(const QString &input);
Q_SIGNALS:
signals:
void updated();
void bookmarksChanged();
void historyChanged();
public Q_SLOTS:
void homepageChanged();
void searchBaseUrlChanged();
public slots:
void reload();
void addBookmark(const QVariantMap &bookmarkdata);
......@@ -66,13 +76,16 @@ public Q_SLOTS:
void addToHistory(const QVariantMap &pagedata);
void removeFromHistory(const QString &url);
void setHomepage(const QString homepage);
void setSearchBaseUrl(const QString searchBaseUrl);
private:
UrlModel* m_bookmarks;
UrlModel* m_history;
QSettings* m_settings;
};
} // namespace
#endif //BOOKMARKSMANAGER_H
/***************************************************************************
* *
* Copyright 2019 Jonah Brüchert *
* *
* 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.Controls 2.1 as Controls
import QtQuick.Layouts 1.7
import QtQuick 2.7
import org.kde.kirigami 2.5 as Kirigami
Kirigami.OverlaySheet {
id: inputSheet
property string placeholderText
property string description
property string title
property string text
signal accepted
ColumnLayout {
Kirigami.Heading {
text: title
}
Controls.Label {
Layout.fillWidth: true
text: inputSheet.description
wrapMode: Text.WordWrap
}
Controls.TextField {
id: sheetTextField
Layout.fillWidth: true
placeholderText: inputSheet.placeholderText
}
Controls.Button {
text: "Ok"
Layout.alignment: Qt.AlignRight
onClicked: {
inputSheet.text = sheetTextField.text
inputSheet.close()
accepted()
}
}
}
}
......@@ -46,9 +46,7 @@ ListView {
model: ListModel {
id: tabsModel
ListElement { pageurl: "https://duckduckgo.com" }
// ListElement { pageurl: "http://tagesschau.de" }
// ListElement { pageurl: "http://bbc.co.uk" }
ListElement { pageurl: "https://plasma-mobile.org" }
}
delegate: WebView {
......@@ -64,4 +62,13 @@ ListView {
function newTab(url) {
tabsModel.append({pageurl: url});
}
Component.onCompleted: {
if (initialUrl !== "") {
load(initialUrl)
} else {
console.log("Using homepage")
load(browserManager.homepage)
}
}
}
......@@ -32,8 +32,6 @@ import "regex-weburl.js" as RegexWebUrl
Item {
id: errorHandler
property string searchUrl: "https://duckduckgo.com/?q="
property string errorCode: ""
property bool navigationShown: errorCode != "" || webBrowser.url === "" || true
......@@ -109,7 +107,7 @@ Item {
if (text.match(RegexWebUrl.re_weburl)) {
load(browserManager.urlFromUserInput(text))
} else {
load(browserManager.urlFromUserInput(searchUrl + text))
load(browserManager.urlFromUserInput(browserManager.searchBaseUrl + text))
}
}
}
......
......@@ -58,10 +58,47 @@ Kirigami.ScrollablePage {
}
}
InputDialog {
Please register or sign in to reply
id: homePagePopup
title: i18n("Homepage")
description: i18n("website that should be loaded on startup")
placeholderText: browserManager.homepage
onAccepted: {
if (homePagePopup.text !== "")
browserManager.homepage = homePagePopup.text
}
}
InputDialog {
Please register or sign in to reply
id: searchEnginePopup
title: i18n("Search Engine")
description: i18n("Base url of your preferred search engine")
placeholderText: browserManager.searchBaseUrl
onAccepted: {
if (searchEnginePopup.text !== "")
browserManager.searchBaseUrl = searchEnginePopup.text;
}
}
Controls.ItemDelegate {
text: i18n("Homepage")
  • why hide the actual value?

    text: i18n("Homepage: %1).arg(browserManager.homepage)

    or maybe better make it two controls so it can be formatted properly

Please register or sign in to reply
Layout.fillWidth: true
onClicked: {
homePagePopup.open()
}
}
Controls.ItemDelegate {
text: i18n("Search Engine")
Layout.fillWidth: true
onClicked: {
searchEnginePopup.open()
}
}
Item {
Layout.fillHeight: true
}
}
}
......@@ -192,10 +192,4 @@ Kirigami.ApplicationWindow {
}
}
Component.onCompleted: {
if (initialUrl && !initialUrl.isEmpty())
load(initialUrl)
}
}
......@@ -29,8 +29,10 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
QtWebEngine::initialize();
// initial url command line parameter
QString initialUrl;
if (!parser.positionalArguments().isEmpty())
engine.rootContext()->setContextProperty("initialUrl", QUrl::fromUserInput(parser.positionalArguments()[0].toUtf8()));
initialUrl = QUrl::fromUserInput(parser.positionalArguments()[0].toUtf8()).toEncoded();
engine.rootContext()->setContextProperty("initialUrl", initialUrl);
// Browser managger
AngelFish::BrowserManager *browserManager = new AngelFish::BrowserManager(engine.rootContext());
......
......@@ -15,5 +15,6 @@
<file alias="webbrowser.qml">contents/ui/webbrowser.qml</file>
<file alias="WebView.qml">contents/ui/WebView.qml</file>
<file alias="regex-weburl.js">regex-weburl/regex-weburl.js</file>
<file alias="InputSheet.qml">contents/ui/InputSheet.qml</file>
</qresource>
</RCC>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment