Commit 6a45f341 authored by Rinigus Saar's avatar Rinigus Saar Committed by Jonah Brüchert
Browse files

add selection of search engines

parent 0289d736
......@@ -76,6 +76,8 @@ void BrowserManager::updateIcon(const QString &url, const QString &iconSource)
void BrowserManager::setHomepage(const QString &homepage)
{
if (this->homepage() == homepage)
return;
m_settings->setValue("browser/homepage", homepage);
emit homepageChanged();
}
......@@ -87,6 +89,8 @@ QString BrowserManager::homepage()
void BrowserManager::setSearchBaseUrl(const QString &searchBaseUrl)
{
if (this->searchBaseUrl() == searchBaseUrl)
return;
m_settings->setValue("browser/searchBaseUrl", searchBaseUrl);
emit searchBaseUrlChanged();
}
......
......@@ -55,8 +55,9 @@ Kirigami.OverlaySheet {
id: sheetTextField
Layout.fillWidth: true
placeholderText: inputSheet.placeholderText
text: inputSheet.text
focus: true
onEditingFinished: accept()
onAccepted: accept()
}
Controls.Button {
......
......@@ -41,6 +41,9 @@ QtObject {
property bool navBarReload: !Kirigami.Settings.isMobile
property bool navBarContextMenu: true
// Search engine
property string searchCustomUrl
///////////////////////////////////
// settings storage
......@@ -59,4 +62,9 @@ QtObject {
property alias reload: settings.navBarReload
property alias contextMenu: settings.navBarContextMenu
}
property QtSettings.Settings _settingsSearch: QtSettings.Settings {
category: "SearchEngine"
property alias customUrl: settings.searchCustomUrl
}
}
......@@ -80,17 +80,6 @@ Kirigami.ScrollablePage {
}
}
InputSheet {
id: searchEnginePopup
title: i18n("Search Engine")
description: i18n("Base URL of your preferred search engine")
placeholderText: BrowserManager.searchBaseUrl
onAccepted: {
if (searchEnginePopup.text !== "")
BrowserManager.searchBaseUrl = UrlUtils.urlFromUserInput(searchEnginePopup.text)
}
}
Kirigami.Separator {
Layout.fillWidth: true
}
......@@ -113,9 +102,7 @@ Kirigami.ScrollablePage {
Controls.ItemDelegate {
text: i18n("Search Engine")
Layout.fillWidth: true
onClicked: {
searchEnginePopup.open()
}
onClicked: pageStack.push(Qt.resolvedUrl("SettingsSearchEnginePage.qml"))
leftPadding: Kirigami.Units.gridUnit
rightPadding: Kirigami.Units.gridUnit
implicitHeight: Kirigami.Units.gridUnit * 2.5
......
/***************************************************************************
* *
* 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 QtQuick.Controls 2.4 as Controls
import QtQuick.Layouts 1.11
import org.kde.kirigami 2.7 as Kirigami
import org.kde.mobile.angelfish 1.0
Kirigami.ScrollablePage {
title: i18n("Search Engine")
topPadding: 0
bottomPadding: 0
leftPadding: 0
rightPadding: 0
Kirigami.ColumnView.fillWidth: false
background: Rectangle {
Kirigami.Theme.colorSet: Kirigami.Theme.View
color: Kirigami.Theme.backgroundColor
}
property string baseUrl: BrowserManager.searchBaseUrl
ColumnLayout {
id: list
spacing: 0
property string customName: i18n("Custom")
// custom search engine input sheet
InputSheet {
id: searchEnginePopup
title: i18n("Search Engine")
description: i18n("Base URL of your preferred search engine")
text: settings.searchCustomUrl
onAccepted: {
var t = UrlUtils.urlFromUserInput(searchEnginePopup.text);
settings.searchCustomUrl = t;
baseUrl = t;
searchEngines.setProperty(searchEngines.count - 1, "url", t);
}
}
Kirigami.Separator {
Layout.fillWidth: true
}
Repeater {
model: ListModel {
id: searchEngines
ListElement {
title: "Bing"
url: "https://www.bing.com/search?q="
}
ListElement {
title: "DuckDuckGo"
url: "https://start.duckduckgo.com/?q="
}
ListElement {
title: "Ecosia"
url: "https://www.ecosia.org/search?q="
}
ListElement {
title: "Google"
url: "https://www.google.com/search?q="
}
ListElement {
title: "Lilo"
url: "https://search.lilo.org/searchweb.php?q="
}
ListElement {
title: "Peekier"
url: "https://peekier.com/#!"
}
ListElement {
title: "Qwant"
url: "https://www.qwant.com/?q="
}
ListElement {
title: "Qwant Junior"
url: "https://www.qwantjunior.com/?q="
}
ListElement {
title: "StartPage"
url: "https://www.startpage.com/do/dsearch?query="
}
ListElement {
title: "Swisscows"
url: "https://swisscows.com/web?query="
}
ListElement {
title: "Wikipedia"
url: "https://wikipedia.org/wiki/Special:Search?search="
}
}
delegate: ColumnLayout {
spacing: 0
Controls.RadioDelegate {
leftPadding: Kirigami.Units.gridUnit
rightPadding: Kirigami.Units.gridUnit
implicitHeight: Kirigami.Units.gridUnit * 2.5
Layout.fillWidth: true
checked: model.url === baseUrl
text: model.title
onClicked: {
if (model.title !== list.customName)
baseUrl = model.url;
else {
searchEnginePopup.open();
}
// restore property binding
checked = Qt.binding(function() { return (model.url === baseUrl) });
}
}
Kirigami.Separator {
Layout.fillWidth: true
}
}
}
}
onBaseUrlChanged: {
var t = UrlUtils.urlFromUserInput(baseUrl);
BrowserManager.searchBaseUrl = t;
}
Component.onCompleted: {
searchEngines.append({ "title": list.customName, "url": settings.searchCustomUrl });
}
}
......@@ -8,6 +8,7 @@
<file alias="Settings.qml">contents/ui/Settings.qml</file>
<file alias="SettingsPage.qml">contents/ui/SettingsPage.qml</file>
<file alias="SettingsNavigationBarPage.qml">contents/ui/SettingsNavigationBarPage.qml</file>
<file alias="SettingsSearchEnginePage.qml">contents/ui/SettingsSearchEnginePage.qml</file>
<file alias="Tabs.qml">contents/ui/Tabs.qml</file>
<file alias="UrlDelegate.qml">contents/ui/UrlDelegate.qml</file>
<file alias="webbrowser.qml">contents/ui/webbrowser.qml</file>
......
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