X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=src%2Fwindows%2FBrowserWindow.cpp;h=4edb35ac4613bdfd771cc876aaa0c574d63fa2f1;hb=823acbeb2cc27030857f249ab7157d8562e7b7fe;hp=60ddaa4d6e2f31ca8fe62a1ad3778c76537e31b3;hpb=588db73b94af7b596b0e532f4557aa8b6c41f5c3;p=PrivacyBrowserPC.git diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index 60ddaa4..4edb35a 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -22,6 +22,7 @@ #include "Settings.h" #include "ui_SettingsPrivacy.h" #include "ui_SettingsGeneral.h" +#include "databases/CookiesDatabase.h" #include "dialogs/CookiesDialog.h" #include "dialogs/DomainSettingsDialog.h" #include "helpers/SearchEngineHelper.h" @@ -34,6 +35,7 @@ // Qt toolkit headers. #include #include +#include #include // Construct the class. @@ -173,9 +175,9 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() domStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("view-web-browser-dom-tree"))); // Update the on-the-fly menus. - connect(browserViewPointer, SIGNAL(updateUserAgentActions(QString)), this, SLOT(updateUserAgentActions(QString))); + connect(browserViewPointer, SIGNAL(updateUserAgentActions(QString, bool)), this, SLOT(updateUserAgentActions(QString, bool))); connect(browserViewPointer, SIGNAL(updateZoomFactorAction(double)), this, SLOT(updateZoomFactorAction(double))); - connect(browserViewPointer, SIGNAL(updateSearchEngineActions(QString)), this, SLOT(updateSearchEngineActions(QString))); + connect(browserViewPointer, SIGNAL(updateSearchEngineActions(QString, bool)), this, SLOT(updateSearchEngineActions(QString, bool))); // Apply the on-the-fly settings when selected. connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlyUserAgent(QAction*))); @@ -201,6 +203,22 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() // Setup the GUI based on the browser_ui.rc file. setupGUI(StandardWindowOption::Default, ("browser_ui.rc")); + // Get lists of the actions' associated widgets. + QList userAgentAssociatedWidgetsPointerList = userAgentPrivacyBrowserActionPointer->associatedWidgets(); + QList searchEngineAssociatedWidgetsPointerList = searchEngineMojeekActionPointer->associatedWidgets(); + + // Get the menu widget pointers. It is the second entry, after the main window. + QWidget *userAgentMenuWidgetPointer = userAgentAssociatedWidgetsPointerList[1]; + QWidget *searchEngineMenuWidgetPointer = searchEngineAssociatedWidgetsPointerList[1]; + + // Get the menu pointers. + QMenu *userAgentMenuPointer = qobject_cast(userAgentMenuWidgetPointer); + QMenu *searchEngineMenuPointer = qobject_cast(searchEngineMenuWidgetPointer); + + // Get the menu actions. + userAgentMenuActionPointer = userAgentMenuPointer->menuAction(); + searchEngineMenuActionPointer = searchEngineMenuPointer->menuAction(); + // Get a handle for the URL toolbar. KToolBar *urlToolBarPointer = toolBar(QStringLiteral("url_toolbar")); @@ -268,6 +286,10 @@ void BrowserWindow::addCookieToList(const QNetworkCookie &newCookie) const // Update the action text. cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", cookieListPointer->size())); + + // Update the cookie if it is durable and has new data. + if (CookiesDatabase::isUpdate(newCookie)) + CookiesDatabase::updateCookie(newCookie); } void BrowserWindow::addOrEditDomainSettings() const @@ -598,52 +620,83 @@ void BrowserWindow::updateLocalStorageAction(const bool &isEnabled) domStorageActionPointer->setEnabled(localStorageEnabled & javaScriptEnabled); } -void BrowserWindow::updateSearchEngineActions(const QString &searchEngine) const +void BrowserWindow::updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus) { // Initialize the custom search engine flag. bool customSearchEngine = false; if (searchEngine == "Mojeek") // Mojeek. { + // Check the Mojeek user agent action. searchEngineMojeekActionPointer->setChecked(true); + + // Update the search engine menu action text. + searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Mojeek")); } else if (searchEngine == "Monocles") // Monocles. { + // Check the Monocles user agent action. searchEngineMonoclesActionPointer->setChecked(true); + + // Update the search engine menu action text. + searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Monocles")); } else if (searchEngine == "MetaGer") // MetaGer. { + // Check the MetaGer user agent action. searchEngineMetagerActionPointer->setChecked(true); + + // Update the search engine menu action text. + searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - MetaGer")); } else if (searchEngine == "Google") // Google. { + // Check the Google user agent action. searchEngineGoogleActionPointer->setChecked(true); + + // Update the search engine menu action text. + searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Google")); } else if (searchEngine == "Bing") // Bing. { + // Check the Bing user agent action. searchEngineBingActionPointer->setChecked(true); + + // Update the search engine menu action text. + searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Bing")); } else if (searchEngine == "Yahoo") // Yahoo. { + // Check the Yahoo user agent action. searchEngineYahooActionPointer->setChecked(true); + + // Update the search engine menu action text. + searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Yahoo")); } else // Custom search engine. { // Check the user agent. searchEngineCustomActionPointer->setChecked(true); + // Update the search engine menu action text. + searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Custom")); + + // Set the custom search engine text. + searchEngineCustomActionPointer->setText(searchEngine); + // Set the custom search engine flag. customSearchEngine = true; } + // Update the custom search engine enabled boolean. + if (updateCustomSearchEngineStatus) + customSearchEngineEnabled = customSearchEngine; + // Format the custom search engine. - if (customSearchEngine) + if (customSearchEngineEnabled) { // Enable the custom search engine. searchEngineCustomActionPointer->setEnabled(true); - - // Set the custom search engine text. - searchEngineCustomActionPointer->setText(searchEngine); } else { @@ -655,38 +708,101 @@ void BrowserWindow::updateSearchEngineActions(const QString &searchEngine) const } } -void BrowserWindow::updateUserAgentActions(const QString &userAgent) const +void BrowserWindow::updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus) { // Initialize the custom user agent flag. bool customUserAgent = false; // Check the indicated on-the-fly user agent. - if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) userAgentPrivacyBrowserActionPointer->setChecked(true); // Privacy Browser. - else if (userAgent == BrowserView::webEngineDefaultUserAgent) userAgentWebEngineDefaultActionPointer->setChecked(true); // WebEngine default. - else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT) userAgentFirefoxLinuxActionPointer->setChecked(true); // Firefox Linux. - else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT) userAgentChromiumLinuxActionPointer->setChecked(true); // Chromium Linux. - else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT) userAgentFirefoxWindowsActionPointer->setChecked(true); // Firefox Windows. - else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT) userAgentChromeWindowsActionPointer->setChecked(true); // Chrome Windows. - else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT) userAgentEdgeWindowsActionPointer->setChecked(true); // Edge Windows. - else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT) userAgentSafariMacosActionPointer->setChecked(true); // Safara macOS. + if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) // Privacy Browser. + { + // Check the Privacy Browser user agent action. + userAgentPrivacyBrowserActionPointer->setChecked(true); + + // Update the user agent menu action text. + userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Privacy Browser")); + } + else if (userAgent == BrowserView::webEngineDefaultUserAgent) // WebEngine default. + { + // check the WebEngine default user agent action. + userAgentWebEngineDefaultActionPointer->setChecked(true); + + // Update the user agent menu action text. + userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - WebEngine default")); + } + else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT) // Firefox on Linux. + { + // Check the Firefox on Linux user agent action. + userAgentFirefoxLinuxActionPointer->setChecked(true); + + // Update the user agent menu action text. + userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Firefox on Linux")); + } + else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT) // Chromium on Linux. + { + // Check the Chromium on Linux user agent action. + userAgentChromiumLinuxActionPointer->setChecked(true); + + // Update the user agent menu action text. + userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Chromium on Linux")); + } + else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT) // Firefox on Windows. + { + // Check the Firefox on Windows user agent action. + userAgentFirefoxWindowsActionPointer->setChecked(true); + + // Update the user agent menu action text. + userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Firefox on Windows")); + } + else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT) // Chrome on Windows. + { + // Check the Chrome on Windows user agent action. + userAgentChromeWindowsActionPointer->setChecked(true); + + // Update the user agent menu action text. + userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Chrome on Windows")); + } + else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT) // Edge on Windows. + { + // Check the Edge on Windows user agent action. + userAgentEdgeWindowsActionPointer->setChecked(true); + + // Update the user agent menu action text. + userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Edge on Windows")); + } + else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT) // Safari on macOS. + { + // Check the Safari on macOS user agent action. + userAgentSafariMacosActionPointer->setChecked(true); + + // Update the user agent menu action text. + userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Safari on macOS")); + } else // Custom user agent. { // Check the user agent. userAgentCustomActionPointer->setChecked(true); + // Update the user agent menu action text. + userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Custom")); + + // Set the custom user agent text. + userAgentCustomActionPointer->setText(userAgent); + // Set the custom user agent flag. customUserAgent = true; } + // Update the custom user agent enabled boolean. + if (updateCustomUserAgentStatus) + customUserAgentEnabled = customUserAgent; + // Format the custom user agent. - if (customUserAgent) + if (customUserAgentEnabled) { // Enable the custom user agent. userAgentCustomActionPointer->setEnabled(true); - - // Set the custom user agent text. - userAgentCustomActionPointer->setText(userAgent); } else {