From 823acbeb2cc27030857f249ab7157d8562e7b7fe Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Fri, 10 Jun 2022 15:04:47 -0700 Subject: [PATCH] Allow toggling of custom On-The-Fly entries. https://redmine.stoutner.com/issues/859 --- src/views/BrowserView.cpp | 10 ++++------ src/views/BrowserView.h | 4 ++-- src/windows/BrowserWindow.cpp | 32 ++++++++++++++++++++------------ src/windows/BrowserWindow.h | 6 ++++-- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/views/BrowserView.cpp b/src/views/BrowserView.cpp index 09afd60..6bdbda6 100644 --- a/src/views/BrowserView.cpp +++ b/src/views/BrowserView.cpp @@ -210,7 +210,7 @@ void BrowserView::applyApplicationSettings() searchEngineUrl = SearchEngineHelper::getSearchUrl(Settings::searchEngine()); // Emit the update search engine actions signal. - emit updateSearchEngineActions(Settings::searchEngine()); + emit updateSearchEngineActions(Settings::searchEngine(), 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. @@ -374,14 +374,12 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload emit updateJavaScriptAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled)); emit updateLocalStorageAction(currentPrivacyWebEnginePointer->localStorageEnabled); emit updateDomStorageAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); - emit updateUserAgentActions(webEngineProfilePointer->httpUserAgent()); + emit updateUserAgentActions(webEngineProfilePointer->httpUserAgent(), true); emit updateZoomFactorAction(webEngineViewPointer->zoomFactor()); // Reload the website if requested. if (reloadWebsite) - { webEngineViewPointer->reload(); - } } void BrowserView::applyOnTheFlySearchEngine(QAction *searchEngineActionPointer) @@ -396,7 +394,7 @@ void BrowserView::applyOnTheFlySearchEngine(QAction *searchEngineActionPointer) searchEngineUrl = SearchEngineHelper::getSearchUrl(searchEngineName); // Update the search engine actionas. - emit updateSearchEngineActions(searchEngineName); + emit updateSearchEngineActions(searchEngineName, false); } void BrowserView::applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const @@ -411,7 +409,7 @@ void BrowserView::applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgentFromTranslatedName(userAgentName)); // Update the user agent actions. - emit updateUserAgentActions(webEngineProfilePointer->httpUserAgent()); + emit updateUserAgentActions(webEngineProfilePointer->httpUserAgent(), false); // Reload the website. webEngineViewPointer->reload(); diff --git a/src/views/BrowserView.h b/src/views/BrowserView.h index 9396632..0aeb6a0 100644 --- a/src/views/BrowserView.h +++ b/src/views/BrowserView.h @@ -69,9 +69,9 @@ signals: void updateForwardAction(const bool &isEnabled) const; void updateJavaScriptAction(const bool &isEnabled) const; void updateLocalStorageAction(const bool &isEnabled) const; - void updateSearchEngineActions(const QString &searchEngine) const; + void updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus) const; void updateUrlLineEdit(const QUrl &newUrl) const; - void updateUserAgentActions(const QString &userAgent) const; + void updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus) const; void updateZoomFactorAction(const double &zoomFactor) const; public Q_SLOTS: diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index 15b683e..4edb35a 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -175,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*))); @@ -620,7 +620,7 @@ 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; @@ -681,18 +681,22 @@ void BrowserWindow::updateSearchEngineActions(const QString &searchEngine) const // 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 { @@ -704,7 +708,7 @@ 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; @@ -782,19 +786,23 @@ void BrowserWindow::updateUserAgentActions(const QString &userAgent) const // 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 { diff --git a/src/windows/BrowserWindow.h b/src/windows/BrowserWindow.h index 9e5ecfe..bfd76c0 100644 --- a/src/windows/BrowserWindow.h +++ b/src/windows/BrowserWindow.h @@ -70,8 +70,8 @@ private Q_SLOTS: void updateDomainSettingsIndicator(const bool &status, const QString &domainSettingsDomain); void updateJavaScriptAction(const bool &isEnabled); void updateLocalStorageAction(const bool &isEnabled); - void updateSearchEngineActions(const QString &searchEngine) const; - void updateUserAgentActions(const QString &userAgent) const; + void updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus); + void updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus); void updateZoomFactorAction(const double &zoomFactor); void updateSearchEngineLabel(const QString &searchEngineString) const; void updateUrlLineEdit(const QUrl &newUrl); @@ -86,6 +86,8 @@ private: QString currentDomainSettingsDomain; QUrl currentUrl; double currentZoomFactor; + bool customSearchEngineEnabled; + bool customUserAgentEnabled; QAction *domStorageActionPointer; QPalette domainSettingsPalette; QAction *javaScriptActionPointer; -- 2.43.0