2 * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
6 * Privacy Browser PC is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Browser PC is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
20 // Application headers
24 // KDE Framework headers.
27 // Qt framework headers.
28 #include <QWebEngineView>
30 MainView::MainView(QWidget *parent) : QWidget(parent)
32 // Instantiate the mainview UI.
33 Ui::MainView mainViewUi;
36 mainViewUi.setupUi(this);
38 // Get handles for the views.
39 urlLineEditPointer = mainViewUi.urlLineEdit;
40 webEngineViewPointer = mainViewUi.webEngineView;
42 // Update the webengine view from the URL line edit.
43 connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrl(const QString)));
45 // Update the URL line edit form the webengine view.
46 connect(webEngineViewPointer, SIGNAL(loadStarted()), this, SLOT(updateUrlLineEdit()));
47 connect(webEngineViewPointer, SIGNAL(loadProgress(int)), this, SLOT(updateUrlLineEdit()));
48 connect(webEngineViewPointer, SIGNAL(loadFinished(bool)), this, SLOT(updateUrlLineEdit()));
51 webEngineViewPointer->setUrl(QUrl(QStringLiteral("https://www.stoutner.com/")));
54 void MainView::loadUrl(const QString &urlFromUser)
56 // Load the URL, adding standard protocol sections if needed. TODO. Replace this with logic that prefers HTTPS.
57 webEngineViewPointer->setUrl(QUrl::fromUserInput(urlFromUser));
60 void MainView::updateUrlLineEdit()
62 // Update the URL line edit.
63 urlLineEditPointer->setText(webEngineViewPointer->url().toString());