From 8f52378069b5b638dd832d1435e58e1596cc9798 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Fri, 11 Mar 2022 16:04:41 -0700 Subject: [PATCH] Begin implementing Domain Settings using KXmlGuiWindow. --- CMakeLists.txt | 1 + src/BrowserWindow.cpp | 373 -------------------------------- src/BrowserWindow.h | 76 ------- src/CMakeLists.txt | 13 +- src/MainView.cpp | 280 ------------------------ src/MainView.h | 83 ------- src/MainView.ui | 176 --------------- src/SettingsPrivacy.ui | 1 - src/helpers/CMakeLists.txt | 1 + src/helpers/UserAgentHelper.cpp | 12 +- src/main.cpp | 8 +- src/privacybrowserui.rc | 62 ------ 12 files changed, 20 insertions(+), 1066 deletions(-) delete mode 100644 src/BrowserWindow.cpp delete mode 100644 src/BrowserWindow.h delete mode 100644 src/MainView.cpp delete mode 100644 src/MainView.h delete mode 100644 src/MainView.ui delete mode 100644 src/privacybrowserui.rc diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a9c81b..d6408ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ include(FeatureSummary) find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Gui + Sql WebEngineCore WebEngineWidgets Widgets diff --git a/src/BrowserWindow.cpp b/src/BrowserWindow.cpp deleted file mode 100644 index 7e908a3..0000000 --- a/src/BrowserWindow.cpp +++ /dev/null @@ -1,373 +0,0 @@ -/* - * Copyright © 2022 Soren Stoutner . - * - * This file is part of 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 . - */ - -// 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 -#include - -// Qt framework headers. -#include -#include - -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)); -} diff --git a/src/BrowserWindow.h b/src/BrowserWindow.h deleted file mode 100644 index 14ef8cc..0000000 --- a/src/BrowserWindow.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright © 2022 Soren Stoutner . - * - * This file is part of 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 . - */ - -#ifndef BROWSERWINDOW_H -#define BROWSERWINDOW_H - -// Application headers. -#include "MainView.h" - -// Qt framework headers. -#include - -// KDE Frameworks headers. -#include - -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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d63efaf..d9f46da 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,15 +15,12 @@ # You should have received a copy of the GNU General Public License # along with Privacy Browser PC. If not, see . - # 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 ) @@ -40,7 +37,8 @@ kconfig_add_kcfg_files(privacy-browser Settings.kcfgc) # 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 ) @@ -49,6 +47,7 @@ ki18n_wrap_ui(privacy-browser target_link_libraries(privacy-browser Qt5::Core Qt5::Gui + Qt5::Sql Qt5::Widgets Qt5::WebEngineCore Qt5::WebEngineWidgets @@ -64,6 +63,9 @@ target_link_libraries(privacy-browser # 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}) @@ -74,8 +76,5 @@ install(PROGRAMS com.stoutner.privacybrowser.desktop DESTINATION ${KDE_INSTALL_A # 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}) diff --git a/src/MainView.cpp b/src/MainView.cpp deleted file mode 100644 index 3893f2b..0000000 --- a/src/MainView.cpp +++ /dev/null @@ -1,280 +0,0 @@ -/* - * Copyright © 2022 Soren Stoutner . - * - * This file is part of 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 . - */ - -// 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 -#include - -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. - webEngineViewPointer->setZoomFactor(Settings::zoomFactor()); -} diff --git a/src/MainView.h b/src/MainView.h deleted file mode 100644 index dba6914..0000000 --- a/src/MainView.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright © 2022 Soren Stoutner . - * - * This file is part of 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 . - */ - -#ifndef MAINVIEW_H -#define MAINVIEW_H - -// Qt framework headers. -#include -#include -#include -#include - -// KDE Framework headers. -#include - -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 diff --git a/src/MainView.ui b/src/MainView.ui deleted file mode 100644 index 632ae6f..0000000 --- a/src/MainView.ui +++ /dev/null @@ -1,176 +0,0 @@ - - - - - - MainView - - - - - - 0 - 0 - 315 - 233 - - - - - - - - 0 - - - - - 0 - - - - 0 - - - - 0 - - - - 0 - - - - - - - - 0 - - - - - - - - - - - - 24 - 24 - - - - - true - - - - - - - - - - - - - - 24 - 24 - - - - - true - - - - - - - - - - - - - - 24 - 24 - - - - - true - - - - - - - - - - - - - - 24 - 24 - - - - - true - - - - - - - - - - - - - - - 24 - 24 - - - - - true - - - - - - - - - - - - - diff --git a/src/SettingsPrivacy.ui b/src/SettingsPrivacy.ui index f800220..8c701d8 100644 --- a/src/SettingsPrivacy.ui +++ b/src/SettingsPrivacy.ui @@ -104,7 +104,6 @@ Safari macOS - --> diff --git a/src/helpers/CMakeLists.txt b/src/helpers/CMakeLists.txt index 042c5c3..df368ac 100644 --- a/src/helpers/CMakeLists.txt +++ b/src/helpers/CMakeLists.txt @@ -18,6 +18,7 @@ # List the sources to include in the executable. target_sources(privacy-browser PRIVATE + DomainsDatabaseHelper.cpp SearchEngineHelper.cpp UserAgentHelper.cpp ) diff --git a/src/helpers/UserAgentHelper.cpp b/src/helpers/UserAgentHelper.cpp index 960305b..4b1fd85 100644 --- a/src/helpers/UserAgentHelper.cpp +++ b/src/helpers/UserAgentHelper.cpp @@ -31,27 +31,27 @@ QString UserAgentHelper::getUserAgent(const QString &userAgentName) } 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 { diff --git a/src/main.cpp b/src/main.cpp index bf2e23f..ad23101 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,8 @@ */ // Application headers. -#include "BrowserWindow.h" +#include "helpers/DomainsDatabaseHelper.h" +#include "windows/BrowserWindow.h" // KDE Frameworks headers. #include @@ -78,8 +79,11 @@ int main(int argc, char *argv[]) // 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(); diff --git a/src/privacybrowserui.rc b/src/privacybrowserui.rc deleted file mode 100644 index c15b154..0000000 --- a/src/privacybrowserui.rc +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - On-The-Fly Settings - User Agent - - - - - - - - - - - - - - - Search Engine - - - - - - - - - - - - - Main Toolbar - - - - -- 2.45.2