find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
Core
Gui
+ Sql
WebEngineCore
WebEngineWidgets
Widgets
+++ /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 "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>
-#include <KConfigDialog>
-
-// Qt framework headers.
-#include <QInputDialog>
-#include <QStatusBar>
-
-BrowserWindow::BrowserWindow() : KXmlGuiWindow()
-{
- // Instantiate the main view pointer.
- mainViewPointer = new MainView(this);
-
- // Set the main view as the central widget.
- setCentralWidget(mainViewPointer);
-
- // Get a handle for the action collectoin.
- 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 names.
- 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(mainViewPointer, SIGNAL(userAgentUpdated(QString)), this, SLOT(updateOnTheFlyUserAgent(QString)));
- connect(mainViewPointer, SIGNAL(zoomFactorUpdated(double)), this, SLOT(updateOnTheFlyZoomFactor(double)));
- connect(mainViewPointer, SIGNAL(searchEngineUpdated(QString)), this, SLOT(updateOnTheFlySearchEngine(QString)));
-
- // Apply the on-the-fly settings when selected.
- connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), mainViewPointer, SLOT(applyOnTheFlyUserAgent(QAction*)));
- connect(searchEngineActionGroupPointer, SIGNAL(triggered(QAction*)), mainViewPointer, 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(mainViewPointer, SIGNAL(linkHovered(QString)), this, SLOT(updateStatusBar(QString)));
-
- // Setup the GUI based on the privacybrowserui.rc file.
- setupGUI();
-
- // Load the initial webstie.
- mainViewPointer->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.
- mainViewPointer->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")))
- {
- // 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 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());
-
- // 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)), mainViewPointer, SLOT(applyApplicationSettings()));
- connect(configDialogPointer, SIGNAL(settingsChanged(QString)), mainViewPointer, 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));
-}
+++ /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 BROWSERWINDOW_H
-#define BROWSERWINDOW_H
-
-// Application headers.
-#include "MainView.h"
-
-// Qt framework headers.
-#include <QLabel>
-
-// KDE Frameworks headers.
-#include <KXmlGuiWindow>
-
-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.
- MainView *mainViewPointer;
- 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;
-};
-#endif
# 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/>.
-
# Create the executable and add the resources.
add_executable(privacy-browser resources.qrc)
# List the sources to include in the executable.
target_sources(privacy-browser PRIVATE
- BrowserWindow.cpp
main.cpp
- MainView.cpp
MouseEventFilter.cpp
UrlRequestInterceptor.cpp
)
# Use KDE Frameworks to handle internationalization of the following UI files.
ki18n_wrap_ui(privacy-browser
- MainView.ui
+ BrowserView.ui
+ DomainSettingsView.ui
SettingsPrivacy.ui
SettingsGeneral.ui
)
target_link_libraries(privacy-browser
Qt5::Core
Qt5::Gui
+ Qt5::Sql
Qt5::Widgets
Qt5::WebEngineCore
Qt5::WebEngineWidgets
# Add the subdirectories.
add_subdirectory(helpers)
+add_subdirectory(views)
+add_subdirectory(windows)
+add_subdirectory(ui.rc)
# Install Privacy Browser using the default KDE arguments.
install(TARGETS privacy-browser ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
# Install Privacy Browser's metadata file.
install(FILES com.stoutner.privacybrowser.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR})
-# Install Privacy Browser's RC (Runtime Configuration) file.
-install(FILES privacybrowserui.rc DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/privacybrowser)
-
# Install Privacy Browser's icon.
ecm_install_icons(ICONS icons/sc-apps-privacy-browser.svg DESTINATION ${KDE_INSTALL_ICONDIR})
+++ /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 "BrowserWindow.h"
-#include "MainView.h"
-#include "MouseEventFilter.h"
-#include "Settings.h"
-#include "ui_MainView.h"
-#include "UrlRequestInterceptor.h"
-#include "helpers/SearchEngineHelper.h"
-#include "helpers/UserAgentHelper.h"
-
-// Qt framework headers.
-#include <QAction>
-#include <QWebEngineProfile>
-
-MainView::MainView(QWidget *parent) : QWidget(parent)
-{
- // Instantiate the mainview UI.
- Ui::MainView mainViewUi;
-
- // Setup the UI.
- mainViewUi.setupUi(this);
-
- // Get handles for the views.
- backButtonPointer = mainViewUi.backButton;
- forwardButtonPointer = mainViewUi.forwardButton;
- QPushButton *refreshButtonPointer = mainViewUi.refreshButton;
- QPushButton *homeButtonPointer = mainViewUi.homeButton;
- urlLineEditPointer = mainViewUi.urlLineEdit;
- javaScriptButtonPointer = mainViewUi.javaScript;
- webEngineViewPointer = mainViewUi.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()));
-
- // 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 MainView::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 MainView::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 MainView::applyDomainSettingsWithoutReloading() const
-{
- // Apply the domain settings `false` does not reload the website.
- applyDomainSettings(false);
-}
-
-void MainView::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 MainView::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 MainView::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 MainView::applyOnTheFlyZoomFactor(const double &zoomFactor) const
-{
- // Set the zoom factor.
- webEngineViewPointer->setZoomFactor(zoomFactor);
-}
-
-void MainView::goHome() const
-{
- // Load the homepage.
- webEngineViewPointer->setUrl(QUrl::fromUserInput(Settings::homepage()));
-}
-
-void MainView::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 MainView::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 MainView::pageLinkHovered(const QString &linkUrl) const
-{
- // Emit a signal so that the browser window can update the status bar.
- emit linkHovered(linkUrl);
-}
-
-void MainView::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 MainView::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());
-}
+++ /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 MAINVIEW_H
-#define MAINVIEW_H
-
-// Qt framework headers.
-#include <QPushButton>
-#include <QWebEngineHistory>
-#include <QWebEngineSettings>
-#include <QWebEngineView>
-
-// KDE Framework headers.
-#include <KLineEdit>
-
-class MainView : public QWidget
-{
- // Include the Q_OBJECT macro.
- Q_OBJECT
-
-public:
- // The primary contructor.
- explicit MainView(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 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
+++ /dev/null
-<?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>MainView</class>
-
- <widget class="QWidget" name="MainView">
- <!-- TODO. Make this maximized by default. -->
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>315</width>
- <height>233</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">
- <!-- Set the spacing between items to 0. -->
- <property name="spacing">
- <number>0</number>
- </property>
-
- <!-- 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>
- </layout>
- </item>
-
- <!-- WebEngine view. -->
- <item>
- <widget class="QWebEngineView" name="webEngineView" />
- </item>
- </layout>
- </widget>
-</ui>
<string>Safari macOS</string>
</property>
</item>
- -->
</widget>
</item>
# List the sources to include in the executable.
target_sources(privacy-browser PRIVATE
+ DomainsDatabaseHelper.cpp
SearchEngineHelper.cpp
UserAgentHelper.cpp
)
}
else if (userAgentName == "Firefox Linux") // Firefox Linux.
{
- return "Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0";
+ return "Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.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";
+ return "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 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";
+ return "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.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";
+ return "Mozilla/5.0 (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 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";
+ return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36 Edg/98.0.1108.56";
}
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";
+ return "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15";
}
else
{
*/
// Application headers.
-#include "BrowserWindow.h"
+#include "helpers/DomainsDatabaseHelper.h"
+#include "windows/BrowserWindow.h"
// KDE Frameworks headers.
#include <KAboutData>
// Register with D-Bus, allowing multiple instances and allowing the program to run if for some reason the registration fails.
KDBusService appDBusService(KDBusService::Multiple | KDBusService::NoExitOnFailure);
+ // Add the domains database.
+ DomainsDatabaseHelper::addDatabase();
+
// Create the main window.
- BrowserWindow *browserWindowPointer = new BrowserWindow;
+ BrowserWindow *browserWindowPointer = new BrowserWindow();
// Show the main window.
browserWindowPointer->show();
+++ /dev/null
-<?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/>. -->
-
-<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>
-
- <Action name="options_configure" />
- </ToolBar>
-</gui>