From: Soren Stoutner Date: Mon, 6 Jun 2022 21:36:54 +0000 (-0700) Subject: Add the currently selected User Agent and Search Engine to the text of the parent... X-Git-Tag: v0.1~30 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=730c65f4a8c48df65ed0fcd8ddfbbc9bcfda0c1f;p=PrivacyBrowserPC.git Add the currently selected User Agent and Search Engine to the text of the parent menu. https://redmine.stoutner.com/issues/854 --- diff --git a/src/ui.rcs/browser_ui.rc b/src/ui.rcs/browser_ui.rc index 2f77d1c..0526147 100644 --- a/src/ui.rcs/browser_ui.rc +++ b/src/ui.rcs/browser_ui.rc @@ -31,7 +31,7 @@ On-The-Fly Settings - User Agent + @@ -47,7 +47,7 @@ - Search Engine + diff --git a/src/views/BrowserView.cpp b/src/views/BrowserView.cpp index ef69db4..09afd60 100644 --- a/src/views/BrowserView.cpp +++ b/src/views/BrowserView.cpp @@ -394,6 +394,9 @@ void BrowserView::applyOnTheFlySearchEngine(QAction *searchEngineActionPointer) // Store the search engine string. searchEngineUrl = SearchEngineHelper::getSearchUrl(searchEngineName); + + // Update the search engine actionas. + emit updateSearchEngineActions(searchEngineName); } void BrowserView::applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const @@ -407,6 +410,9 @@ void BrowserView::applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const // Apply the user agent. webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgentFromTranslatedName(userAgentName)); + // Update the user agent actions. + emit updateUserAgentActions(webEngineProfilePointer->httpUserAgent()); + // Reload the website. webEngineViewPointer->reload(); } diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index 4a61438..15b683e 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -35,6 +35,7 @@ // Qt toolkit headers. #include #include +#include #include // Construct the class. @@ -202,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")); @@ -610,33 +627,60 @@ void BrowserWindow::updateSearchEngineActions(const QString &searchEngine) const 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 flag. customSearchEngine = true; } @@ -666,19 +710,78 @@ void BrowserWindow::updateUserAgentActions(const QString &userAgent) const 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 flag. customUserAgent = true; } diff --git a/src/windows/BrowserWindow.h b/src/windows/BrowserWindow.h index 0239a4e..9e5ecfe 100644 --- a/src/windows/BrowserWindow.h +++ b/src/windows/BrowserWindow.h @@ -95,6 +95,7 @@ private: QPalette noDomainSettingsPalette; QProgressBar *progressBarPointer; QLabel *searchEngineLabelPointer; + QAction *searchEngineMenuActionPointer; QAction *searchEngineMojeekActionPointer; QAction *searchEngineMonoclesActionPointer; QAction *searchEngineMetagerActionPointer; @@ -103,6 +104,7 @@ private: QAction *searchEngineYahooActionPointer; QAction *searchEngineCustomActionPointer; QLabel *userAgentLabelPointer; + QAction *userAgentMenuActionPointer; QAction *userAgentPrivacyBrowserActionPointer; QAction *userAgentWebEngineDefaultActionPointer; QAction *userAgentFirefoxLinuxActionPointer;