]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/mainview.cpp
Add the URL line edit.
[PrivacyBrowserPC.git] / src / mainview.cpp
index 844f930971428834cd1bd747df6d028a5624b204..a1e018b400734422350bbf1b8cf3c46d5ef88685 100644 (file)
 #include "mainview.h"
 #include "settings.h"
 
 #include "mainview.h"
 #include "settings.h"
 
+// KDE Framework headers.
+#include <KLineEdit>
+
 // Qt framework headers.
 #include <QWebEngineView>
 
 MainView::MainView(QWidget *parent) : QWidget(parent)
 {
 // Qt framework headers.
 #include <QWebEngineView>
 
 MainView::MainView(QWidget *parent) : QWidget(parent)
 {
+    // Instantiate the mainview UI.
+    Ui::MainView mainViewUi;
+
     // Setup the UI.
     mainViewUi.setupUi(this);
 
     // Setup the UI.
     mainViewUi.setupUi(this);
 
-    // Get a handle for the web engine view.
-    QWebEngineView *webEngineViewPointer = mainViewUi.webEngineView;
+    // 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()));
 
     // Load a website.
     webEngineViewPointer->setUrl(QUrl(QStringLiteral("https://www.stoutner.com/")));
 }
 
     // Load a website.
     webEngineViewPointer->setUrl(QUrl(QStringLiteral("https://www.stoutner.com/")));
 }
+
+void MainView::loadUrl(const QString &urlFromUser)
+{
+    // Load the URL, adding standard protocol sections if needed.  TODO.  Replace this with logic that prefers HTTPS.
+    webEngineViewPointer->setUrl(QUrl::fromUserInput(urlFromUser));
+}
+
+void MainView::updateUrlLineEdit()
+{
+    // Update the URL line edit.
+    urlLineEditPointer->setText(webEngineViewPointer->url().toString());
+}