Verified Commit 0635d5f7 authored by Rinigus Saar's avatar Rinigus Saar Committed by Jonah Brüchert

Navigation bar: processing URL and address entry via overlay

parent bbd512ad
......@@ -14,7 +14,7 @@ ecm_add_test(useragenttest.cpp ../src/useragent.cpp
LINK_LIBRARIES Qt5::Test
)
ecm_add_test(browsermanagertest.cpp ../src/browsermanager.cpp ../src/urlmodel.cpp
ecm_add_test(browsermanagertest.cpp ../src/browsermanager.cpp ../src/urlmodel.cpp ../src/urlutils.cpp
TEST_NAME browsermanagertest
LINK_LIBRARIES Qt5::Test Qt5::Qml
)
......@@ -22,6 +22,7 @@
#include <QUrl>
#include "browsermanager.h"
#include "urlutils.h"
using namespace AngelFish;
......@@ -62,7 +63,7 @@ private Q_SLOTS:
const QString incompleteUrl = QStringLiteral("kde.org");
const QString completeUrl = QStringLiteral("http://kde.org");
QCOMPARE(m_browserManager->urlFromUserInput(incompleteUrl), completeUrl);
QCOMPARE(UrlUtils::urlFromUserInput(incompleteUrl), completeUrl);
}
private:
......
......@@ -3,6 +3,7 @@ set(angelfish_SRCS
browsermanager.cpp
urlmodel.cpp
urlfilterproxymodel.cpp
urlutils.cpp
useragent.cpp
)
......
......@@ -90,11 +90,6 @@ void BrowserManager::removeFromHistory(const QString &url)
emit historyChanged();
}
QString BrowserManager::urlFromUserInput(const QString &input)
{
return QUrl::fromUserInput(input).toString();
}
void BrowserManager::setHomepage(const QString &homepage)
{
m_settings->setValue("browser/homepage", homepage);
......
......@@ -66,8 +66,6 @@ public:
Q_INVOKABLE void setTabsWritable();
Q_INVOKABLE void rmTab(int index);
Q_INVOKABLE static QString urlFromUserInput(const QString &input);
signals:
void updated();
void bookmarksChanged();
......
......@@ -25,21 +25,18 @@ import QtWebEngine 1.4
import QtQuick.Controls 2.0 as Controls
import org.kde.kirigami 2.5 as Kirigami
import "regex-weburl.js" as RegexWebUrl
import org.kde.mobile.angelfish 1.0
Item {
id: navigation
property bool navigationShown: true
property alias textFocus: urlInput.activeFocus
property alias text: urlInput.text
property int expandedHeight: Kirigami.Units.gridUnit * 3
property int buttonSize: Kirigami.Units.gridUnit * 2
signal activateUrlEntry;
Behavior on height { NumberAnimation { duration: Kirigami.Units.longDuration; easing.type: Easing.InOutQuad} }
Rectangle { anchors.fill: parent; color: Kirigami.Theme.backgroundColor; }
......@@ -106,30 +103,56 @@ Item {
onClicked: currentWebView.goForward()
}
Controls.TextField {
id: urlInput
Item {
id: labelItem
Layout.fillWidth: true
text: currentWebView.url
selectByMouse: true
focus: false
Kirigami.Theme.inherit: true
onActiveFocusChanged: {
if (activeFocus) {
selectAll()
Layout.preferredHeight: layout.height
property string scheme: UrlUtils.urlScheme(currentWebView.url)
Controls.ToolButton {
id: schemeIcon
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
icon.name: {
if (labelItem.scheme === "https") return "lock";
if (labelItem.scheme === "http") return "unlock";
return "";
}
visible: icon.name
height: buttonSize * 0.75
width: visible ? buttonSize * 0.75 : 0
Kirigami.Theme.inherit: true
background: Rectangle {
implicitWidth: schemeIcon.width
implicitHeight: schemeIcon.height
color: "transparent"
}
}
onAccepted: {
if (text.match(RegexWebUrl.re_weburl)) {
load(browserManager.urlFromUserInput(text))
} else {
load(browserManager.urlFromUserInput(browserManager.searchBaseUrl + text))
Controls.Label {
anchors.left: schemeIcon.right
anchors.right: parent.right
anchors.top: parent.top
height: parent.height
text: {
if (labelItem.scheme === "http" || labelItem.scheme === "https") {
var h = UrlUtils.urlHostPort(currentWebView.url);
var p = UrlUtils.urlPath(currentWebView.url);
if (p === "/") p = ""
return '%1<font size="2">%2</font>'.arg(h).arg(p);
}
return currentWebView.url;
}
textFormat: Text.StyledText
elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter
}
MouseArea {
anchors.fill: parent
onClicked: activateUrlEntry()
}
}
......@@ -177,5 +200,4 @@ Item {
PropertyChanges { target: navigation; height: 0}
}
]
}
/***************************************************************************
* *
* Copyright 2019 Simon Schmeisser <s.schmeisser@gmx.net> *
* Copyright 2019 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.7
import QtQuick.Controls 2.2 as Controls
import QtQuick.Layouts 1.2
import org.kde.kirigami 2.5 as Kirigami
import org.kde.mobile.angelfish 1.0
import "regex-weburl.js" as RegexWebUrl
Controls.Drawer {
id: overlay
dragMargin: 0
edge: Qt.BottomEdge
width: parent.width
bottomPadding: 0
topPadding: 0
rightPadding: 0
leftPadding: 0
property int buttonSize: Kirigami.Units.gridUnit * 2
property int fullHeight: 0.9 * rootPage.height
property bool openedState: false
property Item urlInput
property Item listView
contentHeight: fullHeight - topPadding - bottomPadding
contentWidth: parent.width - rightPadding - leftPadding
contentItem: Item {
width: parent.width
height: parent.height
RowLayout {
id: editRow
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
height: Kirigami.Units.gridUnit * 3
width: parent.width - Kirigami.Units.gridUnit
Controls.ToolButton {
Layout.preferredWidth: buttonSize
Layout.preferredHeight: buttonSize
icon.name: "window-minimize"
Kirigami.Theme.inherit: true
onClicked: overlay.close()
}
Controls.TextField {
id: urlInput
Layout.fillWidth: true
clip: true
focus: false
text: currentWebView.url
selectByMouse: true
Kirigami.Theme.inherit: true
onActiveFocusChanged: if (activeFocus) selectAll()
onAccepted: applyUrl()
onTextChanged: urlFilter.setFilterFixedString(text)
Keys.onEscapePressed: if (overlay.sheetOpen) overlay.close()
Component.onCompleted: overlay.urlInput = urlInput
function applyUrl() {
if (text.match(RegexWebUrl.re_weburl)) {
load(UrlUtils.urlFromUserInput(text))
} else {
load(UrlUtils.urlFromUserInput(browserManager.searchBaseUrl + text))
}
overlay.close();
}
}
Controls.ToolButton {
Layout.preferredWidth: buttonSize
Layout.preferredHeight: buttonSize
icon.name: "go-next"
Kirigami.Theme.inherit: true
onClicked: urlInput.applyUrl();
}
}
ListView {
id: listView
anchors {
bottom: parent.bottom
left: parent.left
right: parent.right
top: editRow.bottom
}
boundsBehavior: Flickable.StopAtBounds
clip: true
delegate: UrlDelegate {
showRemove: false
onClicked: overlay.close()
highlightText: urlInput.text
}
model: UrlFilterProxyModel {
id: urlFilter
sourceModel: browserManager.history
}
Component.onCompleted: overlay.listView = listView
}
}
onOpened: {
// check if the drawer was just slightly slided
if (openedState) return;
openedState = true;
urlInput.text = currentWebView.url;
urlInput.forceActiveFocus();
urlInput.selectAll();
listView.positionViewAtBeginning();
}
onClosed: {
openedState = false;
currentWebView.forceActiveFocus();
}
}
......@@ -24,6 +24,7 @@ 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 {
......@@ -84,7 +85,7 @@ Kirigami.ScrollablePage {
placeholderText: browserManager.homepage
onAccepted: {
if (homePagePopup.text !== "")
browserManager.homepage = browserManager.urlFromUserInput(homePagePopup.text)
browserManager.homepage = UrlUtils.urlFromUserInput(homePagePopup.text)
}
}
......@@ -95,7 +96,7 @@ Kirigami.ScrollablePage {
placeholderText: browserManager.searchBaseUrl
onAccepted: {
if (searchEnginePopup.text !== "")
browserManager.searchBaseUrl = browserManager.urlFromUserInput(searchEnginePopup.text);
browserManager.searchBaseUrl = UrlUtils.urlFromUserInput(searchEnginePopup.text);
}
}
......
......@@ -27,6 +27,7 @@ import QtGraphicalEffects 1.0
import org.kde.kirigami 2.7 as Kirigami
import org.kde.mobile.angelfish 1.0
import QtQuick.Layouts 1.2
Kirigami.ApplicationWindow {
id: webBrowser
......@@ -329,8 +330,6 @@ Kirigami.ApplicationWindow {
id: navigation
navigationShown: !webappcontainer && webBrowser.visibility !== Window.FullScreen
z: 2
Kirigami.Theme.colorSet: rootPage.privateMode ? Kirigami.Theme.Complementary : Kirigami.Theme.Window
layer.enabled: navigation.visible
......@@ -343,38 +342,16 @@ Kirigami.ApplicationWindow {
}
anchors {
bottom: completion.top
bottom: parent.bottom
left: parent.left
right: parent.right
}
onTextChanged: urlFilter.setFilterFixedString(text)
onActivateUrlEntry: urlEntry.open()
}
Completion {
id: completion
z: 1
model: UrlFilterProxyModel {
id: urlFilter
sourceModel: browserManager.history
}
width: parent.width
height: 0.5 * parent.height
visible: navigation.textFocus
searchText: navigation.text
Behavior on height {
NumberAnimation {
duration: Kirigami.Units.shortDuration * 2
}
}
anchors {
bottom: parent.bottom
horizontalCenter: navigation.horizontalCenter
}
NavigationEntrySheet {
id: urlEntry
}
// Thin line above navigation
......
......@@ -29,6 +29,7 @@
#include "browsermanager.h"
#include "urlfilterproxymodel.h"
#include "urlmodel.h"
#include "urlutils.h"
#include "useragent.h"
Q_DECL_EXPORT int main(int argc, char *argv[])
......@@ -66,6 +67,15 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
qmlRegisterType<AngelFish::BrowserManager>("org.kde.mobile.angelfish", 1, 0, "BrowserManager");
qmlRegisterType<UrlFilterProxyModel>("org.kde.mobile.angelfish", 1, 0, "UrlFilterProxyModel");
qmlRegisterType<UserAgent>("org.kde.mobile.angelfish", 1, 0, "UserAgentGenerator");
// URL utils
qmlRegisterSingletonType<AngelFish::UrlUtils>("org.kde.mobile.angelfish", 1, 0, "UrlUtils",
[](QQmlEngine * /*engine*/, QJSEngine * /*scriptEngine*/) -> QObject * {
AngelFish::UrlUtils *urlUtils = new AngelFish::UrlUtils();
return urlUtils;
});
// Load QML
engine.load(QUrl(QStringLiteral("qrc:///webbrowser.qml")));
// Error handling
......
......@@ -13,7 +13,7 @@
<file alias="regex-weburl.js">regex-weburl/regex-weburl.js</file>
<file alias="InputSheet.qml">contents/ui/InputSheet.qml</file>
<file alias="ShareSheet.qml">contents/ui/ShareSheet.qml</file>
<file alias="Completion.qml">contents/ui/Completion.qml</file>
<file alias="NavigationEntrySheet.qml">contents/ui/NavigationEntrySheet.qml</file>
<file alias="AuthSheet.qml">contents/ui/AuthSheet.qml</file>
<file alias="NewTabQuestion.qml">contents/ui/NewTabQuestion.qml</file>
<file alias="DownloadQuestion.qml">contents/ui/DownloadQuestion.qml</file>
......
/***************************************************************************
* *
* Copyright 2019 Simon Schmeisser <s.schmeisser@gmx.net> *
* Copyright 2019 Jonah Brüchert <jbb@kaidan.im> *
* Copyright 2020 Jonah Brüchert <jbb@kaidan.im> *
* 2020 Rinigus <rinigus.git@gmail.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 *
......@@ -20,41 +20,46 @@
* *
***************************************************************************/
import QtQuick 2.7
import QtQuick.Controls 2.2 as Controls
import org.kde.kirigami 2.5 as Kirigami
Controls.ScrollView {
id: completion
background: Rectangle {
color: Kirigami.Theme.backgroundColor
}
property string searchText
property alias model: listView.model
property alias count: listView.count
ListView {
id: listView
clip: true
delegate: UrlDelegate {
showRemove: false
onClicked: tabs.forceActiveFocus()
highlightText: completion.searchText
}
}
states: [
State {
name: "hidden"
when: visible === false
PropertyChanges {
target: completion
height: 0
}
}
]
#include "urlutils.h"
#include <QDebug>
#include <QUrl>
#include <QSettings>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
using namespace AngelFish;
UrlUtils::UrlUtils(QObject *parent) : QObject(parent)
{
}
UrlUtils::~UrlUtils()
{
}
QString UrlUtils::urlFromUserInput(const QString &input)
{
return QUrl::fromUserInput(input).toString();
}
QString UrlUtils::urlScheme(const QString &url)
{
return QUrl::fromUserInput(url).scheme();
}
QString UrlUtils::urlHostPort(const QString &url)
{
QUrl u(url);
QString r = u.host();
int p = u.port(-1);
if (p > 0) r = QString("%1:%2").arg(r).arg(p);
return r;
}
QString UrlUtils::urlPath(const QString &url)
{
return QUrl::fromUserInput(url).path();
}
/***************************************************************************
* *
* Copyright 2020 Jonah Brüchert <jbb@kaidan.im> *
* 2020 Rinigus <rinigus.git@gmail.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 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 . *
* *
***************************************************************************/
#ifndef URLUTILS_H
#define URLUTILS_H
#include <QObject>
#include "urlmodel.h"
namespace AngelFish {
/**
* @class UrlUtils
* @short Utilities for URL manipulation and parsing.
*/
class UrlUtils : public QObject
{
Q_OBJECT
public:
UrlUtils(QObject *parent = nullptr);
~UrlUtils() override;
Q_INVOKABLE static QString urlFromUserInput(const QString &input);
Q_INVOKABLE static QString urlScheme(const QString &url);
Q_INVOKABLE static QString urlHostPort(const QString &url);
Q_INVOKABLE static QString urlPath(const QString &url);
};
} // namespace
#endif // URLUTILS_H
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