]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Add search engine options.
authorSoren Stoutner <soren@stoutner.com>
Sat, 12 Feb 2022 23:09:35 +0000 (16:09 -0700)
committerSoren Stoutner <soren@stoutner.com>
Sat, 12 Feb 2022 23:09:35 +0000 (16:09 -0700)
14 files changed:
src/BrowserWindow.cpp
src/BrowserWindow.h
src/CMakeLists.txt
src/MainView.cpp
src/Settings.kcfg
src/SettingsGeneral.ui
src/SettingsPrivacy.ui
src/UserAgentHelper.cpp [deleted file]
src/UserAgentHelper.h [deleted file]
src/helpers/CMakeLists.txt [new file with mode: 0644]
src/helpers/SearchEngineHelper.cpp [new file with mode: 0644]
src/helpers/SearchEngineHelper.h [new file with mode: 0644]
src/helpers/UserAgentHelper.cpp [new file with mode: 0644]
src/helpers/UserAgentHelper.h [new file with mode: 0644]

index e2f17bd0d47f4cb5cf9f06c143cd3b260447c76a..29fe4644feb31db29f80f92ea8bdd798e82d7862 100644 (file)
@@ -22,7 +22,8 @@
 #include "Settings.h"
 #include "ui_SettingsPrivacy.h"
 #include "ui_SettingsGeneral.h"
 #include "Settings.h"
 #include "ui_SettingsPrivacy.h"
 #include "ui_SettingsGeneral.h"
-#include "UserAgentHelper.h"
+#include "helpers/SearchEngineHelper.h"
+#include "helpers/UserAgentHelper.h"
 
 // KDE Frameworks headers.
 #include <KActionCollection>
 
 // KDE Frameworks headers.
 #include <KActionCollection>
@@ -77,15 +78,19 @@ void BrowserWindow::settingsConfigure()
         privacySettingsUi.setupUi(privacySettingsWidgetPointer);
         generalSettingsUi.setupUi(generalSettingsWidgetPointer);
 
         privacySettingsUi.setupUi(privacySettingsWidgetPointer);
         generalSettingsUi.setupUi(generalSettingsWidgetPointer);
 
-        // Get handles for the user agent widgets.
+        // Get handles for the widgets.
         QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
         userAgentLabelPointer = privacySettingsUi.userAgentLabel;
         QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
         userAgentLabelPointer = privacySettingsUi.userAgentLabel;
+        QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
+        searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
 
 
-        // Display the initial user agent.
+        // Populate the combo box labels.
         updateUserAgentLabel(userAgentComboBoxPointer->currentText());
         updateUserAgentLabel(userAgentComboBoxPointer->currentText());
+        updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
 
 
-        // Update the user agent when the combo box changes.
-        connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(QString)), this, SLOT(updateUserAgentLabel(QString)));
+        // Update the labels when the combo boxs 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.
         KConfigDialog *configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
 
         // Instantiate a settings config dialog from the settings.kcfg file.
         KConfigDialog *configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
@@ -109,6 +114,12 @@ void BrowserWindow::settingsConfigure()
     }
 }
 
     }
 }
 
+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.
 void BrowserWindow::updateStatusBar(const QString &statusBarMessage) const
 {
     // Display the status bar message.
index 7539099d11384e871d5a28b355c50bb88b4403da..8d65827e1b781a99a8957faead12cfe6dac9e5f2 100644 (file)
@@ -42,12 +42,14 @@ private Q_SLOTS:
     // Define the private slots.
     void fileNew() const;
     void settingsConfigure();
     // Define the private slots.
     void fileNew() const;
     void settingsConfigure();
+    void updateSearchEngineLabel(const QString &searchEngineString) const;
     void updateStatusBar(const QString &statusBarMessage) const;
     void updateUserAgentLabel(const QString &userAgentName) const;
 
 private:
     // Define the private variables.
     MainView *mainViewPointer;
     void updateStatusBar(const QString &statusBarMessage) const;
     void updateUserAgentLabel(const QString &userAgentName) const;
 
 private:
     // Define the private variables.
     MainView *mainViewPointer;
+    QLabel *searchEngineLabelPointer;
     QLabel *userAgentLabelPointer;
 };
 #endif
     QLabel *userAgentLabelPointer;
 };
 #endif
index 8f184ad26ee8ff6a3f9ade1726e2e36390774ec3..79526bf4ea6b772d6dbbc287075b3472458baf3d 100644 (file)
@@ -25,7 +25,6 @@ target_sources(privacy-browser PRIVATE
     main.cpp
     MainView.cpp
     MouseEventFilter.cpp
     main.cpp
     MainView.cpp
     MouseEventFilter.cpp
-    UserAgentHelper.cpp
 )
 
 # Add the Qt logging category.  This will create the `debug.h` header file.
 )
 
 # Add the Qt logging category.  This will create the `debug.h` header file.
@@ -61,6 +60,9 @@ target_link_libraries(privacy-browser
     KF5::XmlGui
 )
 
     KF5::XmlGui
 )
 
+# Add the subdirectories.
+add_subdirectory(helpers)
+
 # Install Privacy Browser using the default KDE arguments.
 install(TARGETS privacy-browser ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
 
 # Install Privacy Browser using the default KDE arguments.
 install(TARGETS privacy-browser ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
 
index 5acb4470ec3a56a5b4223c895d56b9116da034b8..9ddf1fb4524177e07627da213c047bb9d7b6354e 100644 (file)
@@ -23,7 +23,8 @@
 #include "MouseEventFilter.h"
 #include "Settings.h"
 #include "ui_MainView.h"
 #include "MouseEventFilter.h"
 #include "Settings.h"
 #include "ui_MainView.h"
-#include "UserAgentHelper.h"
+#include "helpers/SearchEngineHelper.h"
+#include "helpers/UserAgentHelper.h"
 
 // Qt framework headers.
 #include <QWebEngineProfile>
 
 // Qt framework headers.
 #include <QWebEngineProfile>
@@ -56,8 +57,8 @@ MainView::MainView(QWidget *parent) : QWidget(parent)
 
     // Update the URL line edit form the webengine view.
     connect(webEngineViewPointer, SIGNAL(loadStarted()), this, SLOT(updateInterface()));
 
     // Update the URL line edit form the webengine view.
     connect(webEngineViewPointer, SIGNAL(loadStarted()), this, SLOT(updateInterface()));
-    connect(webEngineViewPointer, SIGNAL(loadProgress(int)), this, SLOT(updateInterface()));
-    connect(webEngineViewPointer, SIGNAL(loadFinished(bool)), 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()));
 
     // Setup the URL bar buttons.
     connect(backButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(back()));
@@ -73,7 +74,7 @@ MainView::MainView(QWidget *parent) : QWidget(parent)
     qApp->installEventFilter(mouseEventFilterPointer);
 
     // Listen for hovered link URLs.
     qApp->installEventFilter(mouseEventFilterPointer);
 
     // Listen for hovered link URLs.
-    connect(webEnginePagePointer, SIGNAL(linkHovered(QString)), this, SLOT(pageLinkHovered(QString)));
+    connect(webEnginePagePointer, SIGNAL(linkHovered(const QString)), this, SLOT(pageLinkHovered(const QString)));
 
     // Disable the cache.
     webEngineProfilePointer->setHttpCacheType(QWebEngineProfile::NoCache);
 
     // Disable the cache.
     webEngineProfilePointer->setHttpCacheType(QWebEngineProfile::NoCache);
@@ -149,7 +150,7 @@ void MainView::applyDomainSettings(bool reloadWebsite) const
 void MainView::goHome() const
 {
     // Load the homepage.
 void MainView::goHome() const
 {
     // Load the homepage.
-    webEngineViewPointer->setUrl(QUrl::fromUserInput(Settings::homepage().toString()));
+    webEngineViewPointer->setUrl(QUrl::fromUserInput(Settings::homepage()));
 }
 
 void MainView::loadUrlFromTextBox(QString urlFromUser) const
 }
 
 void MainView::loadUrlFromTextBox(QString urlFromUser) const
@@ -157,15 +158,24 @@ void MainView::loadUrlFromTextBox(QString urlFromUser) const
     // Remove the focus from the URL line edit.
     urlLineEditPointer->clearFocus();
 
     // Remove the focus from the URL line edit.
     urlLineEditPointer->clearFocus();
 
-    // Check if the URL does not start with a valid protocol.
-    if (!urlFromUser.startsWith("http") && !urlFromUser.startsWith("file://"))
+    // Decide if the text is more likely to be a URL or a search.
+    if (urlFromUser.contains("."))  // The text is likely a URL.
     {
     {
-        // Add `https://` to the beginning of the URL.
-        urlFromUser = "https://" + urlFromUser;
+        // 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(SearchEngineHelper::getSearchUrl(Settings::searchEngine()) + urlFromUser));
     }
     }
-
-    // Load the URL.
-    webEngineViewPointer->setUrl(QUrl::fromUserInput(urlFromUser));
 }
 
 void MainView::pageLinkHovered(const QString &linkUrl) const
 }
 
 void MainView::pageLinkHovered(const QString &linkUrl) const
index fe9b22d6bc351eec2a3816af8d8445fd6faef852..25b12a81a13fa1590f6016febd94684123374e7e 100644 (file)
@@ -18,7 +18,7 @@
   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/>. -->
 
   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/>. -->
 
-  <!-- The options are partially documented at <https://api.kde.org/frameworks/kconfig/html/classKConfigSkeleton.html>. -->
+<!-- The options are partially documented at <https://api.kde.org/frameworks/kconfig/html/classKConfigSkeleton.html>. -->
 <kcfg
     xmlns="http://www.kde.org/standards/kcfg/1.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 <kcfg
     xmlns="http://www.kde.org/standards/kcfg/1.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         </entry>
 
         <entry name="userAgent" type="String">
         </entry>
 
         <entry name="userAgent" type="String">
-            <default>PrivacyBrowser/1.0</default>
+            <default>Privacy Browser</default>
         </entry>
     </group>
 
     <group name="General">
         </entry>
     </group>
 
     <group name="General">
-        <entry name="homepage" type="Url">
+        <entry name="homepage" type="String">
             <default>https://www.mojeek.com/</default>
         </entry>
 
             <default>https://www.mojeek.com/</default>
         </entry>
 
+        <entry name="searchEngine" type="String">
+            <default>Mojeek</default>
+        </entry>
+
         <entry name="zoomFactor" type="Double">
             <default>1.00</default>
         </entry>
         <entry name="zoomFactor" type="Double">
             <default>1.00</default>
         </entry>
index de426968d68fbf0bdacf8386892b5f7b28f7f72e..41b520069058f1c61aacc750270d8eba1c991acd 100644 (file)
                 </widget>
             </item>
 
                 </widget>
             </item>
 
-            <!-- Zoom factor. -->
+            <!-- Search engine. -->
             <item row="1" column="0">
             <item row="1" column="0">
+                <widget class="QLabel">
+                    <property name="text">
+                        <string>Search engine</string>
+                    </property>
+                </widget>
+            </item>
+
+            <item row="1" column="1">
+                <widget class="QComboBox" name="kcfg_searchEngine">
+                    <property name="minimumSize">
+                        <size>
+                            <height>0</height>
+                            <width>500</width>
+                        </size>
+                    </property>
+
+                    <property name="toolTip">
+                        <string>The default is Mojeek.</string>
+                    </property>
+
+                    <property name="editable">
+                        <bool>true</bool>
+                    </property>
+
+                    <item>
+                        <property name="text">
+                            <string>Mojeek</string>
+                        </property>
+                    </item>
+
+                    <item>
+                        <property name="text">
+                            <string>Monocles</string>
+                        </property>
+                    </item>
+
+                    <item>
+                        <property name="text">
+                            <string>MetaGer</string>
+                        </property>
+                    </item>
+
+                    <item>
+                        <property name="text">
+                            <string>Google</string>
+                        </property>
+                    </item>
+
+                    <item>
+                        <property name="text">
+                            <string>Bing</string>
+                        </property>
+                    </item>
+
+                    <item>
+                        <property name="text">
+                            <string>Yahoo</string>
+                        </property>
+                    </item>
+                </widget>
+            </item>
+
+            <item row="2" column="1">
+                <widget class="QLabel" name="searchEngineLabel">
+                    <property name="textInteractionFlags">
+                        <set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+                    </property>
+                </widget>
+            </item>
+
+            <!-- Zoom factor. -->
+            <item row="3" column="0">
                 <widget class="QLabel" name="zoomFactorLabel">
                     <property name="text">
                         <string>Zoom factor</string>
                 <widget class="QLabel" name="zoomFactorLabel">
                     <property name="text">
                         <string>Zoom factor</string>
                 </widget>
             </item>
 
                 </widget>
             </item>
 
-            <item row="1" column="1">
+            <item row="3" column="1">
                 <widget class="QDoubleSpinBox" name="kcfg_zoomFactor">
                     <property name="toolTip">
                         <string>Set the zoom factor between 0.25 and 5.00.  The default is 1.00.</string>
                 <widget class="QDoubleSpinBox" name="kcfg_zoomFactor">
                     <property name="toolTip">
                         <string>Set the zoom factor between 0.25 and 5.00.  The default is 1.00.</string>
index 264ac2da4db5ee34afd25f2425df23c4a1ebe90e..f80022069f325ec771c952834d11a95ec66f13d1 100644 (file)
                 </widget>
             </item>
 
                 </widget>
             </item>
 
-            <!-- User Agent. -->
+            <!-- User agent. -->
             <item row="1" column="0">
                 <widget class="QLabel">
                     <property name="text">
             <item row="1" column="0">
                 <widget class="QLabel">
                     <property name="text">
-                        <string>UserAgent</string>
+                        <string>User agent</string>
                     </property>
                 </widget>
             </item>
                     </property>
                 </widget>
             </item>
                 <widget class="QComboBox" name="kcfg_userAgent">
                     <property name="minimumSize">
                         <size>
                 <widget class="QComboBox" name="kcfg_userAgent">
                     <property name="minimumSize">
                         <size>
-                            <width>500</width>
                             <height>0</height>
                             <height>0</height>
+                            <width>500</width>
                         </size>
                     </property>
 
                     <property name="toolTip">
                         </size>
                     </property>
 
                     <property name="toolTip">
-                        <string>The default is Privacy Browser</string>
+                        <string>The default is Privacy Browser.</string>
                     </property>
 
                     <property name="editable">
                     </property>
 
                     <property name="editable">
diff --git a/src/UserAgentHelper.cpp b/src/UserAgentHelper.cpp
deleted file mode 100644 (file)
index 960305b..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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 "UserAgentHelper.h"
-
-// The default constructor.
-UserAgentHelper::UserAgentHelper() {};
-
-QString UserAgentHelper::getUserAgent(const QString &userAgentName)
-{
-    if (userAgentName == "Privacy Browser")  // Privacy Browser.
-    {
-        return "PrivacyBrowser/1.0";
-    }
-    else if (userAgentName == "Firefox Linux")  // Firefox Linux.
-    {
-        return "Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0";
-    }
-    else if (userAgentName == "Chromium Linux")  // Chromium Linux.
-    {
-        return "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36";
-    }
-    else if (userAgentName == "Firefox Windows")  // Firefox Windows.
-    {
-        return "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0";
-    }
-    else if (userAgentName == "Chrome Windows")  // Chrome Windows.
-    {
-        return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36";
-    }
-    else if (userAgentName == "Edge Windows")  // Edge Windows.
-    {
-        return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.34";
-    }
-    else if (userAgentName == "Safari macOS")  // Safari macOS.
-    {
-        return "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Safari/605.1.15";
-    }
-    else
-    {
-        // Return the custom user agent.
-        return userAgentName;
-    }
-}
diff --git a/src/UserAgentHelper.h b/src/UserAgentHelper.h
deleted file mode 100644 (file)
index f936968..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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 USERAGENTHELPER_H
-#define USERAGENTHELPER_H
-
-// Qt framework headers.
-#include <QString>
-
-class UserAgentHelper
-{
-public:
-    // The default constructor.
-    UserAgentHelper();
-
-    // The public functions.
-    static QString getUserAgent(const QString &userAgentName);
-};
-#endif
diff --git a/src/helpers/CMakeLists.txt b/src/helpers/CMakeLists.txt
new file mode 100644 (file)
index 0000000..042c5c3
--- /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
+    SearchEngineHelper.cpp
+    UserAgentHelper.cpp
+)
diff --git a/src/helpers/SearchEngineHelper.cpp b/src/helpers/SearchEngineHelper.cpp
new file mode 100644 (file)
index 0000000..8291926
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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 "SearchEngineHelper.h"
+
+// The default constructor.
+SearchEngineHelper::SearchEngineHelper() {};
+
+QString SearchEngineHelper::getSearchUrl(const QString &searchEngineName)
+{
+    if (searchEngineName == "Mojeek")  // Mojeek.
+    {
+        return "https://www.mojeek.com/search?q=";
+    }
+    else if (searchEngineName == "Monocles")  // Monocles.
+    {
+        return "https://monocles.de/search?q=";
+    }
+    else if (searchEngineName == "MetaGer")  // MetaGer.
+    {
+        return "https://metager.org/meta/meta.ger3?eingabe=";
+    }
+    else if (searchEngineName == "Google")  // Google.
+    {
+        return "https://www.google.com/search?q=";
+    }
+    else if (searchEngineName == "Bing")  // Bing.
+    {
+        return "https://www.bing.com/search?q=";
+    }
+    else if (searchEngineName == "Yahoo")  // Yahoo.
+    {
+        return "https://search.yahoo.com/search?p=";
+    }
+    else
+    {
+        // Return the custom user agent.
+        return searchEngineName;
+    }
+}
diff --git a/src/helpers/SearchEngineHelper.h b/src/helpers/SearchEngineHelper.h
new file mode 100644 (file)
index 0000000..7eb2b2c
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * 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 SEARCHENGINEHELPER_H
+#define SEARCHENGINEHELPER_H
+
+// Qt framework headers.
+#include <QString>
+
+class SearchEngineHelper
+{
+public:
+    // The default constructor.
+    SearchEngineHelper();
+
+    // The public functions.
+    static QString getSearchUrl(const QString &searchEngineName);
+};
+#endif
diff --git a/src/helpers/UserAgentHelper.cpp b/src/helpers/UserAgentHelper.cpp
new file mode 100644 (file)
index 0000000..960305b
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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 "UserAgentHelper.h"
+
+// The default constructor.
+UserAgentHelper::UserAgentHelper() {};
+
+QString UserAgentHelper::getUserAgent(const QString &userAgentName)
+{
+    if (userAgentName == "Privacy Browser")  // Privacy Browser.
+    {
+        return "PrivacyBrowser/1.0";
+    }
+    else if (userAgentName == "Firefox Linux")  // Firefox Linux.
+    {
+        return "Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0";
+    }
+    else if (userAgentName == "Chromium Linux")  // Chromium Linux.
+    {
+        return "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36";
+    }
+    else if (userAgentName == "Firefox Windows")  // Firefox Windows.
+    {
+        return "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0";
+    }
+    else if (userAgentName == "Chrome Windows")  // Chrome Windows.
+    {
+        return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36";
+    }
+    else if (userAgentName == "Edge Windows")  // Edge Windows.
+    {
+        return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.34";
+    }
+    else if (userAgentName == "Safari macOS")  // Safari macOS.
+    {
+        return "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Safari/605.1.15";
+    }
+    else
+    {
+        // Return the custom user agent.
+        return userAgentName;
+    }
+}
diff --git a/src/helpers/UserAgentHelper.h b/src/helpers/UserAgentHelper.h
new file mode 100644 (file)
index 0000000..f936968
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * 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 USERAGENTHELPER_H
+#define USERAGENTHELPER_H
+
+// Qt framework headers.
+#include <QString>
+
+class UserAgentHelper
+{
+public:
+    // The default constructor.
+    UserAgentHelper();
+
+    // The public functions.
+    static QString getUserAgent(const QString &userAgentName);
+};
+#endif