]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Begin implementing Domain Settings using KXmlGuiWindow part 2.
authorSoren Stoutner <soren@stoutner.com>
Fri, 11 Mar 2022 23:06:19 +0000 (16:06 -0700)
committerSoren Stoutner <soren@stoutner.com>
Fri, 11 Mar 2022 23:06:19 +0000 (16:06 -0700)
17 files changed:
src/BrowserView.ui [new file with mode: 0644]
src/DomainSettingsView.ui [new file with mode: 0644]
src/helpers/DomainsDatabaseHelper.cpp [new file with mode: 0644]
src/helpers/DomainsDatabaseHelper.h [new file with mode: 0644]
src/ui.rc/CMakeLists.txt [new file with mode: 0644]
src/ui.rc/browser_ui.rc [new file with mode: 0644]
src/ui.rc/domain_settings_ui.rc [new file with mode: 0644]
src/views/BrowserView.cpp [new file with mode: 0644]
src/views/BrowserView.h [new file with mode: 0644]
src/views/CMakeLists.txt [new file with mode: 0644]
src/views/DomainSettingsView.cpp [new file with mode: 0644]
src/views/DomainSettingsView.h [new file with mode: 0644]
src/windows/BrowserWindow.cpp [new file with mode: 0644]
src/windows/BrowserWindow.h [new file with mode: 0644]
src/windows/CMakeLists.txt [new file with mode: 0644]
src/windows/DomainSettingsWindow.cpp [new file with mode: 0644]
src/windows/DomainSettingsWindow.h [new file with mode: 0644]

diff --git a/src/BrowserView.ui b/src/BrowserView.ui
new file mode 100644 (file)
index 0000000..43b9589
--- /dev/null
@@ -0,0 +1,191 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+
+  This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-android>.
+
+  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/>. -->
+
+<ui version="4.0">
+    <class>BrowserView</class>
+
+    <widget class="QWidget" name="BrowserView">
+        <!-- TODO.  Make this maximized by default. -->
+        <property name="geometry">
+            <rect>
+                <x>0</x>
+                <y>0</y>
+                <width>700</width>
+                <height>500</height>
+            </rect>
+        </property>
+
+        <!-- Main widget. -->
+        <layout class="QVBoxLayout">
+            <!-- Set the spacing between items to 0. -->
+            <property name="spacing">
+                <number>0</number>
+            </property>
+
+            <!-- Set the margins to 0. -->
+            <property name="topMargin">
+                <number>0</number>
+            </property>
+
+            <property name="bottomMargin">
+                <number>0</number>
+            </property>
+
+            <property name="leftMargin">
+                <number>0</number>
+            </property>
+
+            <property name="rightMargin">
+                <number>0</number>
+            </property>
+
+            <!-- URL bar. -->
+            <item>
+                <layout class="QHBoxLayout">
+                    <!-- Back button. -->
+                    <item>
+                        <widget class="QPushButton" name="backButton">
+                            <property name="icon">
+                                <iconset theme="arrow-left" />
+                            </property>
+
+                            <property name="iconSize">
+                                <size>
+                                    <height>24</height>
+                                    <width>24</width>
+                                </size>
+                            </property>
+
+                            <property name="flat">
+                                <bool>true</bool>
+                            </property>
+                        </widget>
+                    </item>
+
+                    <!-- Forward button. -->
+                    <item>
+                        <widget class="QPushButton" name="forwardButton">
+                            <property name="icon">
+                                <iconset theme="arrow-right" />
+                            </property>
+
+                            <property name="iconSize">
+                                <size>
+                                    <height>24</height>
+                                    <width>24</width>
+                                </size>
+                            </property>
+
+                            <property name="flat">
+                                <bool>true</bool>
+                            </property>
+                        </widget>
+                    </item>
+
+                    <!-- Refresh button. -->
+                    <item>
+                        <widget class="QPushButton" name="refreshButton">
+                            <property name="icon">
+                                <iconset theme="view-refresh" />
+                            </property>
+
+                            <property name="iconSize">
+                                <size>
+                                    <height>24</height>
+                                    <width>24</width>
+                                </size>
+                            </property>
+
+                            <property name="flat">
+                                <bool>true</bool>
+                            </property>
+                        </widget>
+                    </item>
+
+                    <!-- Home button. -->
+                    <item>
+                        <widget class="QPushButton" name="homeButton">
+                            <property name="icon">
+                                <iconset theme="home" />
+                            </property>
+
+                            <property name="iconSize">
+                                <size>
+                                    <height>24</height>
+                                    <width>24</width>
+                                </size>
+                            </property>
+
+                            <property name="flat">
+                                <bool>true</bool>
+                            </property>
+                        </widget>
+                    </item>
+
+                    <!-- URL line edit. -->
+                    <item>
+                        <widget class="KLineEdit" name="urlLineEdit" />
+                    </item>
+
+                    <!-- JavaScript. -->
+                    <item>
+                        <widget class="QPushButton" name="javaScript">
+                            <property name="iconSize">
+                                <size>
+                                    <height>24</height>
+                                    <width>24</width>
+                                </size>
+                            </property>
+
+                            <property name="flat">
+                                <bool>true</bool>
+                            </property>
+                        </widget>
+                    </item>
+
+                    <!-- Domain Settings. -->
+                    <item>
+                        <widget class="QPushButton" name="domainSettingsButton">
+                            <property name="icon">
+                                <iconset theme="network-server-symbolic" />
+                            </property>
+
+                            <property name="iconSize">
+                                <size>
+                                    <height>24</height>
+                                    <width>24</width>
+                                </size>
+                            </property>
+
+                            <property name="flat">
+                                <bool>true</bool>
+                            </property>
+                        </widget>
+                    </item>
+                </layout>
+            </item>
+
+            <!-- WebEngine view. -->
+            <item>
+                <widget class="QWebEngineView" name="webEngineView" />
+            </item>
+        </layout>
+    </widget>
+</ui>
diff --git a/src/DomainSettingsView.ui b/src/DomainSettingsView.ui
new file mode 100644 (file)
index 0000000..f847f3c
--- /dev/null
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+
+  This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-android>.
+
+  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/>. -->
+
+<ui version="4.0">
+    <class>DomainSettingsView</class>
+
+    <widget class="QWidget" name="DomainSettingsView">
+        <!-- TODO.  Make this maximized by default. -->
+        <property name="geometry">
+            <rect>
+                <x>0</x>
+                <y>0</y>
+                <width>700</width>
+                <height>500</height>
+            </rect>
+        </property>
+
+        <!-- Main widget. -->
+        <layout class="QHBoxLayout">
+            <!-- Set the spacing between items to 0. -->
+            <property name="spacing">
+                <number>0</number>
+            </property>
+
+            <!-- Set the margins to 0. -->
+            <property name="topMargin">
+                <number>0</number>
+            </property>
+
+            <property name="bottomMargin">
+                <number>0</number>
+            </property>
+
+            <property name="leftMargin">
+                <number>0</number>
+            </property>
+
+            <property name="rightMargin">
+                <number>0</number>
+            </property>
+
+            <!-- Domains list view. -->
+            <item>
+                <widget class="QListView" name="domainsListView"/>
+            </item>
+
+            <!-- Domain settings form layout. -->
+            <item>
+                <layout class="QFormLayout">
+                    <!-- Domain name. -->
+                    <item row="0" column="0">
+                        <widget class="QLabel" name="domainNameLabel">
+                            <property name="text">
+                                <string>Domain name</string>
+                            </property>
+                        </widget>
+                    </item>
+
+                    <item row="0" column="1">
+                        <widget class="KLineEdit" name="domainNameLineEdit">
+                            <property name="toolTip">
+                                <string>*. may be prepended to a domain to include all subdomains (eg. *.stoutner.com).</string>
+                            </property>
+                        </widget>
+                    </item>
+
+                    <!-- JavaScript. -->
+                    <item row="1" column="0">
+                        <widget class="QLabel">
+                            <property name="text">
+                                <string>JavaScript</string>
+                            </property>
+                        </widget>
+                    </item>
+
+                    <item row="1" column="1">
+                        <widget class="QComboBox" name="javaScriptComboBox">
+                            <property name="toolTip">
+                                <string>JavaScript allows websites to run programs (scripts) on the device.</string>
+                            </property>
+
+                            <item>
+                                <property name="text">
+                                    <string>System default</string>
+                                </property>
+                            </item>
+
+                            <item>
+                                <property name="text">
+                                    <string>JavaScript disabled</string>
+                                </property>
+                            </item>
+
+                            <item>
+                                <property name="text">
+                                    <string>JavaScript enabled</string>
+                                </property>
+                            </item>
+                        </widget>
+                    </item>
+                </layout>
+            </item>
+        </layout>
+    </widget>
+</ui>
diff --git a/src/helpers/DomainsDatabaseHelper.cpp b/src/helpers/DomainsDatabaseHelper.cpp
new file mode 100644 (file)
index 0000000..8d127cf
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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/>.
+ */
+
+// Application headers.
+#include "DomainsDatabaseHelper.h"
+
+// Qt framework headers.
+#include <QtSql>
+
+// Define the static constants.
+const QString DomainsDatabaseHelper::CONNECTION_NAME = "domains_database";
+const QString DomainsDatabaseHelper::DOMAINS_TABLE = "domains";
+
+// The default constructor.
+DomainsDatabaseHelper::DomainsDatabaseHelper() {}
+
+void DomainsDatabaseHelper::addDatabase()
+{
+    // Add the domain settings database.
+    QSqlDatabase domainsDatabase = QSqlDatabase::addDatabase("QSQLITE", CONNECTION_NAME);
+
+    // Set the database name.
+    domainsDatabase.setDatabaseName(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/domains.db");
+
+    // Open the database.
+    if (domainsDatabase.open())  // Opening the database succeeded.
+    {
+        // Check to see if the domains table already exists.
+        if (domainsDatabase.tables().contains(DOMAINS_TABLE))
+        {
+            // Run schema update code.
+        }
+        else
+        {
+            // Instantiate a create table query.
+            QSqlQuery createTableQuery(domainsDatabase);
+
+            // Prepare the create table query.
+            createTableQuery.prepare("CREATE TABLE " + DOMAINS_TABLE + "("
+                "_id INTEGER PRIMARY KEY, "
+                "domain_name TEXT)"
+            );
+
+            // Execute the query.
+            if (!createTableQuery.exec())
+            {
+                // Log any errors.
+                qDebug().noquote().nospace() << "Error creating table:  " << domainsDatabase.lastError();
+            }
+        }
+    }
+    else  // Opening the database failed.
+    {
+        // Write the last database error message to the debug output.
+        qDebug().noquote().nospace() << "Error opening database:  " << domainsDatabase.lastError();
+    }
+};
diff --git a/src/helpers/DomainsDatabaseHelper.h b/src/helpers/DomainsDatabaseHelper.h
new file mode 100644 (file)
index 0000000..9faa4c9
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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/>.
+ */
+
+#ifndef DOMAINSDATABASEHELPER_H
+#define DOMAINSDATABASEHELPER_H
+
+// Qt framework headers.
+#include <QtSql>
+
+class DomainsDatabaseHelper
+{
+public:
+    // The default constructor.
+    DomainsDatabaseHelper();
+
+    // The public functions.
+    static void addDatabase();
+
+    // The public constants.
+    static const QString CONNECTION_NAME;
+    static const QString DOMAINS_TABLE;
+};
+#endif
diff --git a/src/ui.rc/CMakeLists.txt b/src/ui.rc/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c3ebd72
--- /dev/null
@@ -0,0 +1,23 @@
+# 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/>.
+
+
+# Install Privacy Browser's RC (Runtime Configuration) files.
+install(FILES
+    browser_ui.rc
+    domain_settings_ui.rc
+    DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/privacybrowser)
diff --git a/src/ui.rc/browser_ui.rc b/src/ui.rc/browser_ui.rc
new file mode 100644 (file)
index 0000000..3b086cf
--- /dev/null
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+
+  This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-android>.
+
+  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/>. -->
+
+<!-- Documentation at <https://techbase.kde.org/Development/Architecture/KDE4/XMLGUI_Technology>. -->
+<gui
+    name="privacybrowser"
+    version="1"
+    xmlns="http://www.kde.org/standards/kxmlgui/1.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://www.kde.org/standards/kxmlgui/1.0 http://www.kde.org/standards/kxmlgui/1.0/kxmlgui.xsd" >
+
+    <MenuBar>
+        <Menu name="on_the_fly_settings"> <text>On-The-Fly Settings</text>
+            <Menu name="user_agent"> <text>User Agent</text>
+                <Action name="user_agent_privacy_browser" />
+                <Action name="user_agent_firefox_linux" />
+                <Action name="user_agent_chromium_linux" />
+                <Action name="user_agent_firefox_windows" />
+                <Action name="user_agent_chrome_windows" />
+                <Action name="user_agent_edge_windows" />
+                <Action name="user_agent_safari_macos" />
+                <Action name="user_agent_custom" />
+            </Menu>
+
+            <Action name="zoom_factor" />
+
+            <Separator />
+
+            <Menu name="search_engine"> <text>Search Engine</text>
+                <Action name="search_engine_mojeek" />
+                <Action name="search_engine_monocles" />
+                <Action name="search_engine_metager" />
+                <Action name="search_engine_google" />
+                <Action name="search_engine_bing" />
+                <Action name="search_engine_yahoo" />
+                <Action name="search_engine_custom" />
+            </Menu>
+        </Menu>
+    </MenuBar>
+
+    <ToolBar name="mainToolBar" noMerge="1">
+        <text>Main Toolbar</text>
+    </ToolBar>
+</gui>
diff --git a/src/ui.rc/domain_settings_ui.rc b/src/ui.rc/domain_settings_ui.rc
new file mode 100644 (file)
index 0000000..ca64ac0
--- /dev/null
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+
+  This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-android>.
+
+  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/>. -->
+
+<!-- Documentation at <https://techbase.kde.org/Development/Architecture/KDE4/XMLGUI_Technology>. -->
+<gui
+    name="domain_settings"
+    version="1"
+    xmlns="http://www.kde.org/standards/kxmlgui/1.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://www.kde.org/standards/kxmlgui/1.0 http://www.kde.org/standards/kxmlgui/1.0/kxmlgui.xsd" >
+
+    <ToolBar name="mainToolBar" noMerge="1">
+        <text>Main Toolbar</text>
+
+        <Action name="add_domain" />
+        <Action name="delete_domain" />
+    </ToolBar>
+
+    <ToolBar name="applyToolBar">
+        <text>Apply Toolbar</text>
+
+        <action name="ok" />
+        <action name="apply" />
+        <action name="cancel" />
+    </ToolBar>
+</gui>
diff --git a/src/views/BrowserView.cpp b/src/views/BrowserView.cpp
new file mode 100644 (file)
index 0000000..44c170a
--- /dev/null
@@ -0,0 +1,326 @@
+/*
+ * 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/>.
+ */
+
+// Application headers.
+#include "BrowserView.h"
+#include "MouseEventFilter.h"
+#include "Settings.h"
+#include "ui_BrowserView.h"
+#include "UrlRequestInterceptor.h"
+#include "helpers/SearchEngineHelper.h"
+#include "helpers/UserAgentHelper.h"
+#include "windows/BrowserWindow.h"
+#include "windows/DomainSettingsWindow.h"
+
+// Qt framework headers.
+#include <QAction>
+#include <QWebEngineProfile>
+
+BrowserView::BrowserView(QWidget *parent) : QWidget(parent)
+{
+    // Instantiate the browser view UI.
+    Ui::BrowserView browserViewUi;
+
+    // Setup the UI.
+    browserViewUi.setupUi(this);
+
+    // Get handles for the views.
+    backButtonPointer = browserViewUi.backButton;
+    forwardButtonPointer = browserViewUi.forwardButton;
+    QPushButton *refreshButtonPointer = browserViewUi.refreshButton;
+    QPushButton *homeButtonPointer = browserViewUi.homeButton;
+    urlLineEditPointer = browserViewUi.urlLineEdit;
+    javaScriptButtonPointer = browserViewUi.javaScript;
+    QPushButton *domainSettingsButtonPointer = browserViewUi.domainSettingsButton;
+    webEngineViewPointer = browserViewUi.webEngineView;
+
+    // Get handles for the aspects of the WebEngine.
+    QWebEnginePage *webEnginePagePointer = webEngineViewPointer->page();
+    webEngineHistoryPointer = webEnginePagePointer->history();
+    webEngineProfilePointer = webEnginePagePointer->profile();
+    webEngineSettingsPointer = webEngineViewPointer->settings();
+
+    // Update the webengine view from the URL line edit.
+    connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromTextBox(const QString)));
+
+    // Update the URL line edit form the webengine view.
+    connect(webEngineViewPointer, SIGNAL(loadStarted()), this, SLOT(updateInterface()));
+    connect(webEngineViewPointer, SIGNAL(loadProgress(const int)), this, SLOT(updateInterface()));
+    connect(webEngineViewPointer, SIGNAL(loadFinished(const bool)), this, SLOT(updateInterface()));
+
+    // Setup the URL bar buttons.
+    connect(backButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(back()));
+    connect(forwardButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(forward()));
+    connect(refreshButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(reload()));
+    connect(homeButtonPointer, SIGNAL(clicked()), this, SLOT(goHome()));
+    connect(javaScriptButtonPointer, SIGNAL(clicked()), this, SLOT(toggleJavaScript()));
+    connect(domainSettingsButtonPointer, SIGNAL(clicked()), this, SLOT(openDomainSettings()));
+
+    // Instantiate the mouse event pointer.
+    MouseEventFilter *mouseEventFilterPointer = new MouseEventFilter(webEngineViewPointer);
+
+    // Install the mouse event filter.
+    qApp->installEventFilter(mouseEventFilterPointer);
+
+    // Listen for hovered link URLs.
+    connect(webEnginePagePointer, SIGNAL(linkHovered(const QString)), this, SLOT(pageLinkHovered(const QString)));
+
+    // Instantiate the URL request interceptor.
+    UrlRequestInterceptor *urlRequestInterceptorPointer = new UrlRequestInterceptor();
+
+    // Set the URL request interceptor.
+    webEngineProfilePointer->setUrlRequestInterceptor(urlRequestInterceptorPointer);
+
+    // Reapply the domain settings when the host changes.
+    connect(urlRequestInterceptorPointer, SIGNAL(applyDomainSettings()), this, SLOT(applyDomainSettingsWithoutReloading()));
+
+    // Disable the cache.
+    webEngineProfilePointer->setHttpCacheType(QWebEngineProfile::NoCache);
+
+    // Don't allow JavaScript to open windows.
+    webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, false);
+
+    // Set the focus on the WebEngine view.
+    webEngineViewPointer->setFocus();
+}
+
+void BrowserView::applyApplicationSettings()
+{
+    // Set the search engine URL.
+    searchEngineUrl = SearchEngineHelper::getSearchUrl(Settings::searchEngine());
+
+    // Emit the search engine updated signal, which causes the on-the-fly menu to be updated.
+    emit searchEngineUpdated(Settings::searchEngine());
+}
+
+// This exists as a separate function from `applyDomainSettings()` so it can be listed as a slot and function without the need for a boolean argument.
+void BrowserView::applyDomainSettingsAndReload() const
+{
+    // Apply the domain settings.  `true` reloads the website.
+    applyDomainSettings(true);
+}
+
+// This exists as a separate function from `applyDomainSettings()` so it can be listed as a slot and function without the need for a boolean argument.
+void BrowserView::applyDomainSettingsWithoutReloading() const
+{
+    // Apply the domain settings  `false` does not reload the website.
+    applyDomainSettings(false);
+}
+
+void BrowserView::applyDomainSettings(bool reloadWebsite) const
+{
+    // Set the JavaScript status.
+    webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScript());
+
+    // Update the JavaScript button.
+    if (Settings::javaScript())
+    {
+        javaScriptButtonPointer->setIcon(QIcon(":/icons/javascript-warning"));
+    }
+    else
+    {
+        javaScriptButtonPointer->setIcon(QIcon(":/icons/privacy-mode"));
+    }
+
+    // Apply the user agent.
+    webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgent(Settings::userAgent()));
+
+    // Set the zoom factor.
+    webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
+
+    // Emit the on-the-fly menu update signals.
+    emit userAgentUpdated(Settings::userAgent());
+    emit zoomFactorUpdated(Settings::zoomFactor());
+
+    // Reload the website if requested.
+    if (reloadWebsite)
+    {
+        webEngineViewPointer->reload();
+    }
+}
+
+void BrowserView::applyOnTheFlySearchEngine(QAction *searchEngineActionPointer)
+{
+    // Store the search engine name.
+    QString searchEngineName = searchEngineActionPointer->text();
+
+    // Strip out any `&` characters.
+    searchEngineName.remove('&');
+
+    // Store the search engine string.
+    searchEngineUrl = SearchEngineHelper::getSearchUrl(searchEngineName);
+}
+
+void BrowserView::applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const
+{
+    // Get the user agent name.
+    QString userAgentName = userAgentActionPointer->text();
+
+    // Strip out any `&` characters.
+    userAgentName.remove('&');
+
+    // Apply the user agent.
+    webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgent(userAgentName));
+
+    // Reload the website.
+    webEngineViewPointer->reload();
+}
+
+void BrowserView::applyOnTheFlyZoomFactor(const double &zoomFactor) const
+{
+    // Set the zoom factor.
+    webEngineViewPointer->setZoomFactor(zoomFactor);
+}
+
+void BrowserView::goHome() const
+{
+    // Load the homepage.
+    webEngineViewPointer->setUrl(QUrl::fromUserInput(Settings::homepage()));
+}
+
+void BrowserView::loadInitialWebsite()
+{
+    // Apply the application settings.
+    applyApplicationSettings();
+
+    // Get the arguments.
+    QStringList argumentsStringList = qApp->arguments();
+
+    // Check to see if the arguments lists contains a URL.
+    if (argumentsStringList.size() > 1)
+    {
+        // Load the URL from the arguments list.
+        webEngineViewPointer->setUrl(QUrl::fromUserInput(argumentsStringList.at(1)));
+    }
+    else
+    {
+        // Load the homepage.
+        goHome();
+    }
+}
+
+void BrowserView::loadUrlFromTextBox(QString urlFromUser) const
+{
+    // Remove the focus from the URL line edit.
+    urlLineEditPointer->clearFocus();
+
+    // Decide if the text is more likely to be a URL or a search.
+    if (urlFromUser.contains("."))  // The text is likely a URL.
+    {
+        // Check if the URL does not start with a valid protocol.
+        if (!urlFromUser.startsWith("http") && !urlFromUser.startsWith("file://"))
+        {
+            // Add `https://` to the beginning of the URL.
+            urlFromUser = "https://" + urlFromUser;
+        }
+
+        // Load the URL.
+        webEngineViewPointer->setUrl(QUrl::fromUserInput(urlFromUser));
+    }
+    else  // The text is likely a search.
+    {
+        // Load the search.
+        webEngineViewPointer->setUrl(QUrl::fromUserInput(searchEngineUrl + urlFromUser));
+    }
+}
+
+void BrowserView::openDomainSettings() const
+{
+    // Get a list of the top level widgets.
+    const QWidgetList topLevelWidgets = QApplication::topLevelWidgets();
+
+    // Initialize a domain settings window exists boolean.
+    bool domainSettingsWindowExists = false;
+
+    // Iterate through the top level widgets.
+    for (QWidget *widgetPointer : topLevelWidgets)
+    {
+        // Check for an existing domain settings window.
+        if (widgetPointer->objectName() == QStringLiteral("domain_settings"))
+        {
+            // Show the existing domain settings window if it is hidden.
+            widgetPointer->show();
+
+            // Raise the existing domain settings window if it is below other windows.
+            widgetPointer->raise();
+
+            // Restore the existing domain settings window if it has been minimized.
+            if (widgetPointer->isMinimized()) {
+                widgetPointer->showNormal();
+            }
+
+            // Activate the existing domain settings window, which brings its virtual desktop into focus.
+            widgetPointer->activateWindow();
+
+            // Update the domain settings window exists boolean.
+            domainSettingsWindowExists = true;
+        }
+    }
+
+    if (!domainSettingsWindowExists)
+    {
+        // Instantiate the domain settings window.
+        DomainSettingsWindow *domainSettingsWindowPointer = new DomainSettingsWindow();
+
+        // Show the window.
+        domainSettingsWindowPointer->show();
+    }
+}
+
+void BrowserView::pageLinkHovered(const QString &linkUrl) const
+{
+    // Emit a signal so that the browser window can update the status bar.
+    emit linkHovered(linkUrl);
+}
+
+void BrowserView::toggleJavaScript() const
+{
+    // Toggle JavaScript.
+    webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, !webEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled));
+
+    // Update the JavaScript button.
+    if (webEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled))
+    {
+        javaScriptButtonPointer->setIcon(QIcon(":/icons/javascript-warning"));
+    }
+    else
+    {
+        javaScriptButtonPointer->setIcon(QIcon(":/icons/privacy-mode"));
+    }
+
+    // Reload the website.
+    webEngineViewPointer->reload();
+}
+
+void BrowserView::updateInterface() const
+{
+    // Update the URL line edit if it does not have focus.
+    if (!urlLineEditPointer->hasFocus())
+    {
+        // Update the URL line edit.
+        urlLineEditPointer->setText(webEngineViewPointer->url().toString());
+    }
+
+    // Update the status of the forward and back buttons.
+    backButtonPointer->setEnabled(webEngineHistoryPointer->canGoBack());
+    forwardButtonPointer->setEnabled(webEngineHistoryPointer->canGoForward());
+
+    // 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());
+}
diff --git a/src/views/BrowserView.h b/src/views/BrowserView.h
new file mode 100644 (file)
index 0000000..2804783
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * 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/>.
+ */
+
+#ifndef BROWSERVIEW_H
+#define BROWSERVIEW_H
+
+// Qt framework headers.
+#include <QPushButton>
+#include <QWebEngineHistory>
+#include <QWebEngineSettings>
+#include <QWebEngineView>
+
+// KDE Framework headers.
+#include <KLineEdit>
+
+class BrowserView : public QWidget
+{
+    // Include the Q_OBJECT macro.
+    Q_OBJECT
+
+public:
+    // The primary contructor.
+    explicit BrowserView(QWidget *parent);
+
+    // The public functions.
+    void applyOnTheFlyZoomFactor(const double &zoomFactor) const;
+    void loadInitialWebsite();
+
+signals:
+    // The signals.
+    void linkHovered(const QString &linkUrl) const;
+    void userAgentUpdated(const QString &userAgent) const;
+    void searchEngineUpdated(const QString &searchEngine) const;
+    void zoomFactorUpdated(const double &zoomFactor) const;
+
+public Q_SLOTS:
+    // The public slots.
+    void applyApplicationSettings();
+    void applyDomainSettingsAndReload() const;
+    void applyDomainSettingsWithoutReloading() const;
+    void applyOnTheFlySearchEngine(QAction *searchEngineActionPointer);
+    void applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const;
+
+private Q_SLOTS:
+    // The private slots.
+    void goHome() const;
+    void loadUrlFromTextBox(QString urlFromUser) const;
+    void pageLinkHovered(const QString &linkUrl) const;
+    void toggleJavaScript() const;
+    void openDomainSettings() const;
+    void updateInterface() const;
+
+private:
+    // The private variables.
+    QPushButton *backButtonPointer;
+    QPushButton *forwardButtonPointer;
+    QPushButton *javaScriptButtonPointer;
+    QString searchEngineUrl;
+    KLineEdit *urlLineEditPointer;
+    QWebEngineHistory *webEngineHistoryPointer;
+    QWebEngineProfile *webEngineProfilePointer;
+    QWebEngineSettings *webEngineSettingsPointer;
+    QWebEngineView *webEngineViewPointer;
+
+    // The private functions.
+    void applyDomainSettings(bool reloadWebsite) const;
+};
+#endif
diff --git a/src/views/CMakeLists.txt b/src/views/CMakeLists.txt
new file mode 100644 (file)
index 0000000..cd64952
--- /dev/null
@@ -0,0 +1,23 @@
+# 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/>.
+
+
+# List the sources to include in the executable.
+target_sources(privacy-browser PRIVATE
+    BrowserView.cpp
+    DomainSettingsView.cpp
+)
diff --git a/src/views/DomainSettingsView.cpp b/src/views/DomainSettingsView.cpp
new file mode 100644 (file)
index 0000000..ff1131f
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * 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/>.
+ */
+
+// Application headers.
+#include "DomainSettingsView.h"
+#include "ui_DomainSettingsView.h"
+#include "helpers/DomainsDatabaseHelper.h"
+
+DomainSettingsView::DomainSettingsView(QWidget *parent) : QWidget(parent)
+{
+    // Instantiate the domain settings view UI.
+    Ui::DomainSettingsView domainSettingsViewUi;
+
+    // Setup the UI.
+    domainSettingsViewUi.setupUi(this);
+
+    // Get handles for the views.
+    domainsListViewPointer = domainSettingsViewUi.domainsListView;
+    domainNameLineEditPointer = domainSettingsViewUi.domainNameLineEdit;
+
+    // Create a table model.
+    domainsTableModelPointer = new QSqlTableModel(0, QSqlDatabase::database(DomainsDatabaseHelper::CONNECTION_NAME));
+
+    // Set the table for the model.
+    domainsTableModelPointer->setTable(DomainsDatabaseHelper::DOMAINS_TABLE);
+
+    // Set the model for the list view.
+    domainsListViewPointer->setModel(domainsTableModelPointer);
+
+    // Set the visible column to be the domain name.
+    domainsListViewPointer->setModelColumn(1);
+
+    // Disable editing of the list view.
+    domainsListViewPointer->setEditTriggers(QAbstractItemView::NoEditTriggers);
+
+    // Handle clicks on the domains.
+    connect(domainsListViewPointer, SIGNAL(activated(QModelIndex)), this, SLOT(domainSelected(QModelIndex)));
+
+    // Read the data from the database and apply it to the table model.
+    domainsTableModelPointer->select();
+
+    // Select the first entry in the list view.
+    domainsListViewPointer->setCurrentIndex(domainsTableModelPointer->index(0, 1));
+
+    // Populate the domain settings.
+    domainSelected(domainsListViewPointer->selectionModel()->currentIndex());
+}
+
+void DomainSettingsView::addDomain()
+{
+    // Insert a row.
+    domainsTableModelPointer->insertRows(domainsTableModelPointer->rowCount(), 1);
+}
+
+void DomainSettingsView::deleteDomain()
+{
+    // Delete the current row.
+    domainsTableModelPointer->removeRow(domainsListViewPointer->selectionModel()->currentIndex().row());
+}
+
+
+void DomainSettingsView::domainSelected(QModelIndex modelIndex)
+{
+    // Populate the domain name line edit pointer.
+    domainNameLineEditPointer->setText(modelIndex.data().toString());
+}
diff --git a/src/views/DomainSettingsView.h b/src/views/DomainSettingsView.h
new file mode 100644 (file)
index 0000000..04b2a2c
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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/>.
+ */
+
+#ifndef DOMAINSETTINGSVIEW_H
+#define DOMAINSETTINGSVIEW_H
+
+// Qt framework headers.
+#include <QtSql>
+#include <QWidget>
+
+// KDE Framework headers.
+#include <KLineEdit>
+
+class DomainSettingsView : public QWidget
+{
+    // Include the Q_OBJECT macro.
+    Q_OBJECT
+
+public:
+    // The primary constructor.
+    explicit DomainSettingsView(QWidget *parent);
+
+public Q_SLOTS:
+    // The public slots.
+    void addDomain();
+    void deleteDomain();
+
+private Q_SLOTS:
+    // The private slots.
+    void domainSelected(QModelIndex modelIndex);
+
+private:
+    // The private variables.
+    QListView *domainsListViewPointer;
+    KLineEdit *domainNameLineEditPointer;
+    QSqlTableModel *domainsTableModelPointer;
+};
+#endif
diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp
new file mode 100644 (file)
index 0000000..e7bb620
--- /dev/null
@@ -0,0 +1,388 @@
+/*
+ * 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/>.
+ */
+
+// Application headers.
+#include "BrowserWindow.h"
+#include "Settings.h"
+#include "ui_SettingsPrivacy.h"
+#include "ui_SettingsGeneral.h"
+#include "helpers/SearchEngineHelper.h"
+#include "helpers/UserAgentHelper.h"
+
+// KDE Frameworks headers.
+#include <KActionCollection>
+
+// Qt toolkit headers.
+#include <QInputDialog>
+#include <QStatusBar>
+
+BrowserWindow::BrowserWindow() : KXmlGuiWindow()
+{
+    // Instantiate the main view pointer.
+    browserViewPointer = new BrowserView(this);
+
+    // Set the main view as the central widget.
+    setCentralWidget(browserViewPointer);
+
+    // Get a handle for the action collection.
+    KActionCollection *actionCollectionPointer = this->actionCollection();
+
+    // Add the standard actions.
+    KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer);
+    KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer);
+    KStandardAction::preferences(this, SLOT(settingsConfigure()), actionCollectionPointer);
+
+    // Add the custom actions.
+    userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_privacy_browser"));
+    userAgentFirefoxLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_linux"));
+    userAgentChromiumLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chromium_linux"));
+    userAgentFirefoxWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_windows"));
+    userAgentChromeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chrome_windows"));
+    userAgentEdgeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_edge_windows"));
+    userAgentSafariMacosActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_safari_macos"));
+    userAgentCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_custom"));
+    zoomFactorActionPointer = actionCollectionPointer->addAction(QStringLiteral("zoom_factor"));
+    searchEngineMojeekActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_mojeek"));
+    searchEngineMonoclesActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_monocles"));
+    searchEngineMetagerActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_metager"));
+    searchEngineGoogleActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_google"));
+    searchEngineBingActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_bing"));
+    searchEngineYahooActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_yahoo"));
+    searchEngineCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_custom"));
+
+    // Create the action groups
+    QActionGroup *userAgentActionGroupPointer = new QActionGroup(this);
+    QActionGroup *searchEngineActionGroupPointer = new QActionGroup(this);
+
+    // Add the actions to the groups.
+    userAgentActionGroupPointer->addAction(userAgentPrivacyBrowserActionPointer);
+    userAgentActionGroupPointer->addAction(userAgentFirefoxLinuxActionPointer);
+    userAgentActionGroupPointer->addAction(userAgentChromiumLinuxActionPointer);
+    userAgentActionGroupPointer->addAction(userAgentFirefoxWindowsActionPointer);
+    userAgentActionGroupPointer->addAction(userAgentChromeWindowsActionPointer);
+    userAgentActionGroupPointer->addAction(userAgentEdgeWindowsActionPointer);
+    userAgentActionGroupPointer->addAction(userAgentSafariMacosActionPointer);
+    userAgentActionGroupPointer->addAction(userAgentCustomActionPointer);
+    searchEngineActionGroupPointer->addAction(searchEngineMojeekActionPointer);
+    searchEngineActionGroupPointer->addAction(searchEngineMonoclesActionPointer);
+    searchEngineActionGroupPointer->addAction(searchEngineMetagerActionPointer);
+    searchEngineActionGroupPointer->addAction(searchEngineGoogleActionPointer);
+    searchEngineActionGroupPointer->addAction(searchEngineBingActionPointer);
+    searchEngineActionGroupPointer->addAction(searchEngineYahooActionPointer);
+    searchEngineActionGroupPointer->addAction(searchEngineCustomActionPointer);
+
+    // Set some actions to be checkable.
+    userAgentPrivacyBrowserActionPointer->setCheckable(true);
+    userAgentFirefoxLinuxActionPointer->setCheckable(true);
+    userAgentChromiumLinuxActionPointer->setCheckable(true);
+    userAgentFirefoxWindowsActionPointer->setCheckable(true);
+    userAgentChromeWindowsActionPointer->setCheckable(true);
+    userAgentEdgeWindowsActionPointer->setCheckable(true);
+    userAgentSafariMacosActionPointer->setCheckable(true);
+    userAgentCustomActionPointer->setCheckable(true);
+    searchEngineMojeekActionPointer->setCheckable(true);
+    searchEngineMonoclesActionPointer->setCheckable(true);
+    searchEngineMetagerActionPointer->setCheckable(true);
+    searchEngineGoogleActionPointer->setCheckable(true);
+    searchEngineBingActionPointer->setCheckable(true);
+    searchEngineYahooActionPointer->setCheckable(true);
+    searchEngineCustomActionPointer->setCheckable(true);
+
+    // Set the non-mutable action text.
+    userAgentPrivacyBrowserActionPointer->setText(i18nc("@action", "Privacy Browser"));
+    userAgentFirefoxLinuxActionPointer->setText(i18nc("@action", "Firefox Linux"));
+    userAgentChromiumLinuxActionPointer->setText(i18nc("@action", "Chromium Linux"));
+    userAgentFirefoxWindowsActionPointer->setText(i18nc("@action", "Firefox Windows"));
+    userAgentChromeWindowsActionPointer->setText(i18nc("@action", "Chrome Windows"));
+    userAgentEdgeWindowsActionPointer->setText(i18nc("@action", "Edge Windows"));
+    userAgentSafariMacosActionPointer->setText(i18nc("@action", "Safari macOS"));
+    searchEngineMojeekActionPointer->setText(i18nc("@action", "Mojeek"));
+    searchEngineMonoclesActionPointer->setText(i18nc("@action", "Monocles"));
+    searchEngineMetagerActionPointer->setText(i18nc("@action", "MetaGer"));
+    searchEngineGoogleActionPointer->setText(i18nc("@action", "Google"));
+    searchEngineBingActionPointer->setText(i18nc("@action", "Bing"));
+    searchEngineYahooActionPointer->setText(i18nc("@action", "Yahoo"));
+
+    // Update the on-the-fly menus.
+    connect(browserViewPointer, SIGNAL(userAgentUpdated(QString)), this, SLOT(updateOnTheFlyUserAgent(QString)));
+    connect(browserViewPointer, SIGNAL(zoomFactorUpdated(double)), this, SLOT(updateOnTheFlyZoomFactor(double)));
+    connect(browserViewPointer, SIGNAL(searchEngineUpdated(QString)), this, SLOT(updateOnTheFlySearchEngine(QString)));
+
+    // Apply the on-the-fly settings when selected.
+    connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlyUserAgent(QAction*)));
+    connect(searchEngineActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlySearchEngine(QAction*)));
+
+    // Display dialogs.
+    connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
+
+    // Update the status bar with the URL when a link is hovered.
+    connect(browserViewPointer, SIGNAL(linkHovered(QString)), this, SLOT(updateStatusBar(QString)));
+
+    // Setup the GUI based on the browser_ui.rc file.
+    setupGUI(StandardWindowOption::Default, ("browser_ui.rc"));
+
+    // Load the initial webstie.
+    browserViewPointer->loadInitialWebsite();
+}
+
+void BrowserWindow::fileNew() const
+{
+    // Display a new instance of Privacy Browser.
+    (new BrowserWindow)->show();
+}
+
+void BrowserWindow::getZoomFactorFromUser()
+{
+    // Create an OK flag.
+    bool okClicked;
+
+    // Display a dialog to get the new zoom factor from the user.  Format the double to display two decimals and have a 0.25 step.
+    double newZoomFactor = QInputDialog::getDouble(this, i18nc("The tile of the on-the-fly zoom factor dialog", "On-The-Fly Zoom Factor"),
+                                                   i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"),
+                                                   currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25);
+
+    if (okClicked)
+    {
+        // Update the current zoom factor.
+        currentZoomFactor = newZoomFactor;
+
+        // Set the new zoom factor.
+        browserViewPointer->applyOnTheFlyZoomFactor(newZoomFactor);
+
+        // Update the on-the-fly action text.
+        updateOnTheFlyZoomFactor(newZoomFactor);
+    }
+}
+
+void BrowserWindow::settingsConfigure()
+{
+    // Check to make sure the dialog box isn't already displayed.
+    if (KConfigDialog::exists(QStringLiteral("settings")))
+    {
+        // Show the existing config dialog if it is hidden.
+        configDialogPointer->show();
+
+        // Raise the existing config dialog if it is below other windows.
+        configDialogPointer->raise();
+
+        // Restore the existing config dialog if it has been minimized.
+        if (configDialogPointer->isMinimized()) {
+            configDialogPointer->showNormal();
+        }
+
+        // Activate the existing config dialog, which brings its virtual desktop into focus.
+        configDialogPointer->activateWindow();
+    }
+    else
+    {
+        // Create the settings widgets.
+        QWidget *privacySettingsWidgetPointer = new QWidget;
+        QWidget *generalSettingsWidgetPointer = new QWidget;
+
+        // Instantiate the settings UI.
+        Ui::PrivacySettings privacySettingsUi;
+        Ui::GeneralSettings generalSettingsUi;
+
+        // Setup the UI to display the settings widgets.
+        privacySettingsUi.setupUi(privacySettingsWidgetPointer);
+        generalSettingsUi.setupUi(generalSettingsWidgetPointer);
+
+        // Get handles for the widgets.
+        QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
+        userAgentLabelPointer = privacySettingsUi.userAgentLabel;
+        QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
+        searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
+
+        // Populate the combo box labels.
+        updateUserAgentLabel(userAgentComboBoxPointer->currentText());
+        updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
+
+        // Update the labels when the combo boxes change.
+        connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
+        connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
+
+        // Instantiate a settings config dialog from the settings.kcfg file.
+        configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
+
+        // Add the settings widgets as config dialog pages.
+        configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("@title:tab", "Privacy"), QStringLiteral("privacy-browser"));
+        configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings"));
+
+        // Delete the config dialog when it is closed.
+        configDialogPointer->setAttribute(Qt::WA_DeleteOnClose);
+
+        // Make it so.
+        configDialogPointer->show();
+
+        // Expand the config dialog.
+        configDialogPointer->resize(1000, 500);
+
+        // Apply the settings when they are updated.
+        connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyApplicationSettings()));
+        connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
+    }
+}
+
+void BrowserWindow::updateOnTheFlySearchEngine(const QString &searchEngine) const
+{
+    // Initialize the custom search engine flag.
+    bool customSearchEngine = false;
+
+    if (searchEngine == "Mojeek")  // Mojeek.
+    {
+        searchEngineMojeekActionPointer->setChecked(true);
+    }
+    else if (searchEngine == "Monocles")  // Monocles.
+    {
+        searchEngineMonoclesActionPointer->setChecked(true);
+    }
+    else if (searchEngine == "MetaGer")  // MetaGer.
+    {
+        searchEngineMetagerActionPointer->setChecked(true);
+    }
+    else if (searchEngine == "Google")  // Google.
+    {
+        searchEngineGoogleActionPointer->setChecked(true);
+    }
+    else if (searchEngine == "Bing")  // Bing.
+    {
+        searchEngineBingActionPointer->setChecked(true);
+    }
+    else if (searchEngine == "Yahoo")  // Yahoo.
+    {
+        searchEngineYahooActionPointer->setChecked(true);
+    }
+    else  // Custom search engine.
+    {
+        // Check the user agent.
+        searchEngineCustomActionPointer->setChecked(true);
+
+        // Set the custom search engine flag.
+        customSearchEngine = true;
+    }
+
+
+    // Format the custom search engine.
+    if (customSearchEngine)
+    {
+        // Enable the custom search engine.
+        searchEngineCustomActionPointer->setEnabled(true);
+
+        // Set the custom search engine text.
+        searchEngineCustomActionPointer->setText(searchEngine);
+    }
+    else
+    {
+        // Disable the custom search engine.
+        searchEngineCustomActionPointer->setEnabled(false);
+
+        // Reset the custom search engine text.
+        searchEngineCustomActionPointer->setText(i18nc("@action", "Custom"));
+    }
+}
+
+void BrowserWindow::updateOnTheFlyUserAgent(const QString &userAgent) const
+{
+    // Initialize the custom user agent flag.
+    bool customUserAgent = false;
+
+    // Check the indicated on-the-fly user agent.
+    if (userAgent == "Privacy Browser")  // Privacy Browser.
+    {
+        userAgentPrivacyBrowserActionPointer->setChecked(true);
+    }
+    else if (userAgent == "Firefox Linux")  // Firefox Linux.
+    {
+        userAgentFirefoxLinuxActionPointer->setChecked(true);
+    }
+    else if (userAgent == "Chromium Linux")  // Chromium Linux.
+    {
+        userAgentChromiumLinuxActionPointer->setChecked(true);
+    }
+    else if (userAgent == "Firefox Windows")  // Firefox Windows.
+    {
+        userAgentFirefoxWindowsActionPointer->setChecked(true);
+    }
+    else if (userAgent == "Chrome Windows")  // Chrome Windows.
+    {
+        userAgentChromeWindowsActionPointer->setChecked(true);
+    }
+    else if (userAgent == "Edge Windows")  // Edge Windows.
+    {
+        userAgentEdgeWindowsActionPointer->setChecked(true);
+    }
+    else if (userAgent == "Safari macOS")  // Safari macOS.
+    {
+        userAgentSafariMacosActionPointer->setChecked(true);
+    }
+    else  // Custom user agent.
+    {
+        // Check the user agent.
+        userAgentCustomActionPointer->setChecked(true);
+
+        // Set the custom user agent flag.
+        customUserAgent = true;
+    }
+
+
+    // Format the custom user agent.
+    if (customUserAgent)
+    {
+        // Enable the custom user agent.
+        userAgentCustomActionPointer->setEnabled(true);
+
+        // Set the custom user agent text.
+        userAgentCustomActionPointer->setText(userAgent);
+    }
+    else
+    {
+        // Disable the custom user agent.
+        userAgentCustomActionPointer->setEnabled(false);
+
+        // Reset the custom user agent text.
+        userAgentCustomActionPointer->setText(i18nc("@action", "Custom"));
+    }
+}
+
+void BrowserWindow::updateOnTheFlyZoomFactor(const double &zoomFactor)
+{
+    // Set the current zoom factor.
+    currentZoomFactor = Settings::zoomFactor();
+
+    // Update the zoom factor action text, formatting the double with 2 decimal places.
+    zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
+}
+
+void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
+{
+    // Update the search engine label.
+    searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
+}
+
+void BrowserWindow::updateStatusBar(const QString &statusBarMessage) const
+{
+    // Display the status bar message.
+    statusBar()->showMessage(statusBarMessage);
+}
+
+void BrowserWindow::updateUserAgentLabel(const QString &userAgentName) const
+{
+    // Update the user agent label.
+    userAgentLabelPointer->setText(UserAgentHelper::getUserAgent(userAgentName));
+}
diff --git a/src/windows/BrowserWindow.h b/src/windows/BrowserWindow.h
new file mode 100644 (file)
index 0000000..7b64a96
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * 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/>.
+ */
+
+#ifndef BROWSERWINDOW_H
+#define BROWSERWINDOW_H
+
+// Application headers.
+#include "views/BrowserView.h"
+
+// KDE Frameworks headers.
+#include <KConfigDialog>
+#include <KXmlGuiWindow>
+
+// Qt toolkit headers.
+#include <QLabel>
+
+class BrowserWindow : public KXmlGuiWindow
+{
+    // Include the Q_OBJECT macro.
+    Q_OBJECT
+
+public:
+    // The default constructor.
+    BrowserWindow();
+
+private Q_SLOTS:
+    // The private slots.
+    void fileNew() const;
+    void getZoomFactorFromUser();
+    void settingsConfigure();
+    void updateOnTheFlySearchEngine(const QString &searchEngine) const;
+    void updateOnTheFlyUserAgent(const QString &userAgent) const;
+    void updateOnTheFlyZoomFactor(const double &zoomFactor);
+    void updateSearchEngineLabel(const QString &searchEngineString) const;
+    void updateStatusBar(const QString &statusBarMessage) const;
+    void updateUserAgentLabel(const QString &userAgentName) const;
+
+private:
+    // The private variables.
+    BrowserView *browserViewPointer;
+    double currentZoomFactor;
+    QLabel *searchEngineLabelPointer;
+    QAction *searchEngineMojeekActionPointer;
+    QAction *searchEngineMonoclesActionPointer;
+    QAction *searchEngineMetagerActionPointer;
+    QAction *searchEngineGoogleActionPointer;
+    QAction *searchEngineBingActionPointer;
+    QAction *searchEngineYahooActionPointer;
+    QAction *searchEngineCustomActionPointer;
+    QLabel *userAgentLabelPointer;
+    QAction *userAgentPrivacyBrowserActionPointer;
+    QAction *userAgentFirefoxLinuxActionPointer;
+    QAction *userAgentChromiumLinuxActionPointer;
+    QAction *userAgentFirefoxWindowsActionPointer;
+    QAction *userAgentChromeWindowsActionPointer;
+    QAction *userAgentEdgeWindowsActionPointer;
+    QAction *userAgentSafariMacosActionPointer;
+    QAction *userAgentCustomActionPointer;
+    QAction *zoomFactorActionPointer;
+    KConfigDialog *configDialogPointer;
+};
+#endif
diff --git a/src/windows/CMakeLists.txt b/src/windows/CMakeLists.txt
new file mode 100644 (file)
index 0000000..7f3cbf0
--- /dev/null
@@ -0,0 +1,23 @@
+# 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/>.
+
+
+# List the sources to include in the executable.
+target_sources(privacy-browser PRIVATE
+    BrowserWindow.cpp
+    DomainSettingsWindow.cpp
+)
diff --git a/src/windows/DomainSettingsWindow.cpp b/src/windows/DomainSettingsWindow.cpp
new file mode 100644 (file)
index 0000000..af4b3e7
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * 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/>.
+ */
+
+// Application headers.
+#include "DomainSettingsWindow.h"
+#include "views/DomainSettingsView.h"
+
+// KDE Frameworks headers.
+#include <KActionCollection>
+#include <KLocalizedString>
+
+DomainSettingsWindow::DomainSettingsWindow() : KXmlGuiWindow()
+{
+    // Instantiate the domain settings view pointer.
+    DomainSettingsView *domainSettingsViewPointer = new DomainSettingsView(this);
+
+    // Set the domain settings view as the central widget.
+    setCentralWidget(domainSettingsViewPointer);
+
+    // Set the object name.
+    this->setObjectName(QStringLiteral("domain_settings"));
+
+    // Set the window title.
+    setCaption(i18nc("The Domain Settings window title", "Domain Settings"));
+
+    // Get a handle for the action collection.
+    KActionCollection *actionCollectionPointer = this->actionCollection();
+
+    // Add the custom actions.
+    QAction *addDomainActionPointer = actionCollectionPointer->addAction(QStringLiteral("add_domain"));
+    QAction *deleteDomainActionPointer = actionCollectionPointer->addAction(QStringLiteral("delete_domain"));
+    QAction *okActionPointer = actionCollectionPointer->addAction(QStringLiteral("ok"));
+    QAction *applyActionPointer = actionCollectionPointer->addAction(QStringLiteral("apply"));
+    QAction *cancelActionPointer = actionCollectionPointer->addAction(QStringLiteral("cancel"));
+
+    // Set the action text.
+    addDomainActionPointer->setText(i18nc("Add domain toolbar button", "Add Domain"));
+    deleteDomainActionPointer->setText(i18nc("Delete domain toolbar button", "Delete Domain"));
+    okActionPointer->setText(i18nc("OK toolbar button", "OK"));
+    applyActionPointer->setText(i18nc("Apply toolbar button", "Apply"));
+    cancelActionPointer->setText(i18nc("Cancel toolbar button", "Cancel"));
+
+    // Set the action icons.
+    addDomainActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
+    deleteDomainActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("delete")));
+    okActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("dialog-ok")));
+    applyActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("dialog-ok-apply")));
+    cancelActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("dialog-cancel")));
+
+    // Connect the button signals.
+    connect(addDomainActionPointer, SIGNAL(triggered()), domainSettingsViewPointer, SLOT(addDomain()));
+    connect(deleteDomainActionPointer, SIGNAL(triggered()), domainSettingsViewPointer, SLOT(deleteDomain()));
+
+    // Setup the GUI without a status bar based on the domain_settings_ui.rc file.
+    setupGUI(StandardWindowOption::ToolBar | StandardWindowOption::Keys | StandardWindowOption::Save | StandardWindowOption::Create, ("domain_settings_ui.rc"));
+}
diff --git a/src/windows/DomainSettingsWindow.h b/src/windows/DomainSettingsWindow.h
new file mode 100644 (file)
index 0000000..2301951
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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/>.
+ */
+
+#ifndef DOMAINSETTINGSWINDOW_H
+#define DOMAINSETTINGSWINDOW_H
+
+// KDE Frameworks headers.
+#include <KXmlGuiWindow>
+
+// Qt toolkit headers.
+#include <QWidget>
+
+class DomainSettingsWindow : public KXmlGuiWindow
+{
+    // Include the Q_OBJECT macro.
+    Q_OBJECT
+
+public:
+    // The default constructor.
+    DomainSettingsWindow();
+};
+#endif