diff --git a/src/browsermanager.cpp b/src/browsermanager.cpp index c053911..f025e34 100644 --- a/src/browsermanager.cpp +++ b/src/browsermanager.cpp @@ -1,117 +1,116 @@ /*************************************************************************** * Copyright 2014 Sebastian Kügler * * * * 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 . * ***************************************************************************/ #include "browsermanager.h" #include #include #include using namespace AngelFish; BrowserManager::BrowserManager(QObject *parent) : QObject(parent), m_settings(new QSettings) { } BrowserManager::~BrowserManager() { history()->save(); bookmarks()->save(); delete m_settings; } void BrowserManager::reload() { qDebug() << "BookmarksManager::reload()"; } UrlModel *BrowserManager::bookmarks() { // qDebug() << "BookmarksManager::bookmarks()"; if (!m_bookmarks) { m_bookmarks = new UrlModel(QStringLiteral("bookmarks.json"), this); m_bookmarks->load(); } return m_bookmarks; } UrlModel *BrowserManager::history() { // qDebug() << "BrowserManager::history()"; if (!m_history) { m_history = new UrlModel(QStringLiteral("history.json"), this); m_history->load(); } return m_history; } void BrowserManager::addBookmark(const QVariantMap &bookmarkdata) { qDebug() << "Add bookmark"; qDebug() << " data: " << bookmarkdata; bookmarks()->add(QJsonObject::fromVariantMap(bookmarkdata)); } void BrowserManager::removeBookmark(const QString &url) { bookmarks()->remove(url); } void BrowserManager::addToHistory(const QVariantMap &pagedata) { // qDebug() << "Add History"; // qDebug() << " data: " << pagedata; history()->add(QJsonObject::fromVariantMap(pagedata)); emit historyChanged(); } void BrowserManager::removeFromHistory(const QString &url) { history()->remove(url); emit historyChanged(); } QString BrowserManager::urlFromUserInput(const QString &input) { - QUrl url = QUrl::fromUserInput(input); - return url.toString(); + return QUrl::fromUserInput(input).toString(); } void BrowserManager::setHomepage(const QString &homepage) { m_settings->setValue("browser/homepage", homepage); emit homepageChanged(); } QString BrowserManager::homepage() { return m_settings->value("browser/homepage", "https://start.duckduckgo.com").toString(); } void BrowserManager::setSearchBaseUrl(const QString &searchBaseUrl) { m_settings->setValue("browser/searchBaseUrl", searchBaseUrl); emit searchBaseUrlChanged(); } QString BrowserManager::searchBaseUrl() { return m_settings->value("browser/searchBaseUrl", "https://start.duckduckgo.com/?q=") .toString(); } diff --git a/src/contents/ui/Settings.qml b/src/contents/ui/Settings.qml index d9ca638..c151f46 100644 --- a/src/contents/ui/Settings.qml +++ b/src/contents/ui/Settings.qml @@ -1,122 +1,122 @@ /*************************************************************************** * * * Copyright 2014-2015 Sebastian Kügler * * * * 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.2 as Kirigami Kirigami.ScrollablePage { title: i18n("Settings") topPadding: 0 bottomPadding: 0 leftPadding: 0 rightPadding: 0 background: Rectangle { Kirigami.Theme.colorSet: Kirigami.Theme.View color: Kirigami.Theme.backgroundColor } ColumnLayout { id: settingsPage spacing: 0 Kirigami.AbstractListItem { width: parent.width Controls.CheckBox { text: i18n("Enable JavaScript") Layout.fillWidth: true onCheckedChanged: { var settings = currentWebView.settings; settings.javascriptEnabled = checked; // FIXME: save to config } Component.onCompleted: { checked = currentWebView.settings.javascriptEnabled; } } } Kirigami.AbstractListItem { width: parent.width Controls.CheckBox { text: i18n("Load images") Layout.fillWidth: true onCheckedChanged: { var settings = currentWebView.settings; settings.autoLoadImages = checked; // FIXME: save to config } Component.onCompleted: { checked = currentWebView.settings.autoLoadImages; } } } InputSheet { 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 + browserManager.homepage = browserManager.urlFromUserInput(homePagePopup.text) } } 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 = searchEnginePopup.text; + browserManager.searchBaseUrl = browserManager.urlFromUserInput(searchEnginePopup.text); } } Kirigami.BasicListItem { text: i18n("Homepage") Layout.fillWidth: true onClicked: { homePagePopup.open() } } Kirigami.BasicListItem { text: i18n("Search Engine") Layout.fillWidth: true onClicked: { searchEnginePopup.open() } } Item { Layout.fillHeight: true } } }