/*
- SPDX-FileCopyrightText: %{CURRENT_YEAR} %{AUTHOR} <%{EMAIL}>
+ * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+ *
+ * Privacy Browser PC 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Browser PC 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 Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
+ */
- SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
-*/
-
-// application headers
+// Application headers
#include "mainview.h"
-
#include "settings.h"
-#include "privacybrowserdebug.h"
+// KDE Framework headers.
+#include <KLineEdit>
-MainView::MainView(QWidget *parent)
- : QWidget(parent)
-{
- m_ui.setupUi(this);
- handleSettingsChanged();
-}
+// Qt framework headers.
+#include <QWebEngineView>
-MainView::~MainView()
+MainView::MainView(QWidget *parent) : QWidget(parent)
{
+ // Instantiate the mainview UI.
+ Ui::MainView mainViewUi;
+
+ // Setup the UI.
+ mainViewUi.setupUi(this);
+
+ // Get handles for the views.
+ urlLineEditPointer = mainViewUi.urlLineEdit;
+ webEngineViewPointer = mainViewUi.webEngineView;
+
+ // Update the webengine view from the URL line edit.
+ connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrl(const QString)));
+
+ // Update the URL line edit form the webengine view.
+ connect(webEngineViewPointer, SIGNAL(loadStarted()), this, SLOT(updateUrlLineEdit()));
+ connect(webEngineViewPointer, SIGNAL(loadProgress(int)), this, SLOT(updateUrlLineEdit()));
+ connect(webEngineViewPointer, SIGNAL(loadFinished(bool)), this, SLOT(updateUrlLineEdit()));
+
+ // Set the zoom factor.
+ webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
+
+ // Load a website.
+ webEngineViewPointer->setUrl(QUrl(QStringLiteral("https://www.stoutner.com/")));
}
-void MainView::switchColors()
+void MainView::loadUrl(const QString &urlFromUser)
{
- // switch the foreground/background colors of the label
- QColor color = Settings::colorBackground();
- Settings::setColorBackground(Settings::colorForeground());
- Settings::setColorForeground(color);
-
- handleSettingsChanged();
+ // Load the URL, adding standard protocol sections if needed. TODO. Replace this with logic that prefers HTTPS.
+ webEngineViewPointer->setUrl(QUrl::fromUserInput(urlFromUser));
}
-void MainView::handleSettingsChanged()
+void MainView::updateUrlLineEdit()
{
- qCDebug(PRIVACYBROWSER) << "MainView::handleSettingsChanged()";
- QPalette palette = m_ui.templateLabel->palette();
- palette.setColor(QPalette::Window, Settings::colorBackground());
- palette.setColor(QPalette::WindowText, Settings::colorForeground());
- m_ui.templateLabel->setPalette(palette);
-
- // i18n : internationalization
- m_ui.templateLabel->setText(i18n("This project is %1 days old", Settings::ageInDays()));
+ // Update the URL line edit.
+ urlLineEditPointer->setUrl(webEngineViewPointer->url().toString());
+
+ // Reapply the zoom factor. This is a bug in QWebEngineView that resets the zoom with every load. Hopefully it will be fixed in Qt6. <https://bugreports.qt.io/browse/QTBUG-51992>
+ webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
}