#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>
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 *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
+ searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
- // Display the initial user agent.
+ // Populate the combo box labels.
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());
}
}
+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.
// 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;
+ QLabel *searchEngineLabelPointer;
QLabel *userAgentLabelPointer;
};
#endif
main.cpp
MainView.cpp
MouseEventFilter.cpp
- UserAgentHelper.cpp
)
# Add the Qt logging category. This will create the `debug.h` header file.
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})
#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>
// 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()));
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);
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
// 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
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"
</entry>
<entry name="userAgent" type="String">
- <default>PrivacyBrowser/1.0</default>
+ <default>Privacy Browser</default>
</entry>
</group>
<group name="General">
- <entry name="homepage" type="Url">
+ <entry name="homepage" type="String">
<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>
</widget>
</item>
- <!-- Zoom factor. -->
+ <!-- Search engine. -->
<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>
</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>
</item>
- <!-- User Agent. -->
+ <!-- User agent. -->
<item row="1" column="0">
<widget class="QLabel">
<property name="text">
- <string>UserAgent</string>
+ <string>User agent</string>
</property>
</widget>
</item>
<widget class="QComboBox" name="kcfg_userAgent">
<property name="minimumSize">
<size>
- <width>500</width>
<height>0</height>
+ <width>500</width>
</size>
</property>
<property name="toolTip">
- <string>The default is Privacy Browser</string>
+ <string>The default is Privacy Browser.</string>
</property>
<property name="editable">
+++ /dev/null
-/*
- * 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;
- }
-}
+++ /dev/null
-/*
- * 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
--- /dev/null
+# 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
+)
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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