From f3047a42fa756bb36d4840f40ab7acf83e751b48 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Thu, 27 Jan 2022 17:04:15 -0700 Subject: [PATCH] Add the URL line edit. --- CMakeLists.txt | 1 + src/CMakeLists.txt | 1 + src/icons/sc-apps-privacy-browser.svg | 47 +++++++++++++++++++++++++++ src/mainview.cpp | 31 ++++++++++++++++-- src/mainview.h | 10 ++++-- src/mainview.ui | 16 ++++----- src/mainwindow.cpp | 11 ------- 7 files changed, 94 insertions(+), 23 deletions(-) create mode 100644 src/icons/sc-apps-privacy-browser.svg diff --git a/CMakeLists.txt b/CMakeLists.txt index b32fd18..87b77b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS # Load the KDE Frameworks components. find_package(KF5 ${KDE_FRAMEWORKS_MIN_VERSION} REQUIRED COMPONENTS + Completion ConfigWidgets CoreAddons Crash diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 811cb80..2b5beb1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -45,6 +45,7 @@ ki18n_wrap_ui(privacy-browser # Link the following libraries. target_link_libraries(privacy-browser KF5::ConfigWidgets + KF5::Completion KF5::CoreAddons KF5::Crash KF5::DBusAddons diff --git a/src/icons/sc-apps-privacy-browser.svg b/src/icons/sc-apps-privacy-browser.svg new file mode 100644 index 0000000..428d507 --- /dev/null +++ b/src/icons/sc-apps-privacy-browser.svg @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mainview.cpp b/src/mainview.cpp index 844f930..a1e018b 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -21,17 +21,44 @@ #include "mainview.h" #include "settings.h" +// KDE Framework headers. +#include + // Qt framework headers. #include MainView::MainView(QWidget *parent) : QWidget(parent) { + // Instantiate the mainview UI. + Ui::MainView mainViewUi; + // 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/"))); } + +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()); +} diff --git a/src/mainview.h b/src/mainview.h index 8129eca..9affb38 100644 --- a/src/mainview.h +++ b/src/mainview.h @@ -32,8 +32,14 @@ public: // The default contructor. explicit MainView(QWidget *parent); +private Q_SLOTS: + // Define the private slots. + void loadUrl(const QString &urlFromUser); + void updateUrlLineEdit(); + private: - // Declare the private variables. - Ui::MainView mainViewUi; + // Define the private variables. + KLineEdit *urlLineEditPointer; + QWebEngineView *webEngineViewPointer; }; #endif diff --git a/src/mainview.ui b/src/mainview.ui index 41b9b00..2174544 100644 --- a/src/mainview.ui +++ b/src/mainview.ui @@ -32,7 +32,8 @@ - + + 0 @@ -49,14 +50,13 @@ 0 - - - + + + + + + - - - - diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3564a8e..1f7f346 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -38,17 +38,6 @@ MainWindow::MainWindow() : KXmlGuiWindow() // Get a handle for the action collectoin. KActionCollection *actionCollectionPointer = this->actionCollection(); - // Create a switch colorsaction pointer. - QAction *switchColorsActionPointer; - - // Populate the switch colors action pointer. - switchColorsActionPointer = actionCollectionPointer->addAction(QStringLiteral("switch_action")); - switchColorsActionPointer->setText(i18nc("@action", "Switch Colors")); - switchColorsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("fill-color"))); - - // Connect the signals to the slots. - connect(switchColorsActionPointer, &QAction::triggered, mainViewPointer, &MainView::switchColors); - // Add the standard actions. KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer); KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer); -- 2.45.2