From fb2760a23bc59d63c74e18c92628ef03ccd8bf3a Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Tue, 9 Aug 2022 16:39:12 -0700 Subject: [PATCH] Highlight non-default domain settings. --- src/dialogs/DomainSettingsDialog.cpp | 77 +++- src/dialogs/DomainSettingsDialog.h | 7 + src/helpers/UserAgentHelper.cpp | 10 +- src/uis/DomainSettingsDialog.ui | 578 ++++++++++++++++----------- src/uis/TabWidget.ui | 4 - src/widgets/TabWidget.cpp | 4 +- src/windows/BrowserWindow.cpp | 2 +- 7 files changed, 433 insertions(+), 249 deletions(-) diff --git a/src/dialogs/DomainSettingsDialog.cpp b/src/dialogs/DomainSettingsDialog.cpp index c8dc3ea..34ff70e 100644 --- a/src/dialogs/DomainSettingsDialog.cpp +++ b/src/dialogs/DomainSettingsDialog.cpp @@ -53,14 +53,19 @@ DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString & domainsListViewPointer = domainSettingsDialogUi.domainsListView; domainSettingsWidgetPointer = domainSettingsDialogUi.domainSettingsWidget; domainNameLineEditPointer = domainSettingsDialogUi.domainNameLineEdit; + javaScriptWidgetPointer = domainSettingsDialogUi.javaScriptWidget; javaScriptComboBoxPointer = domainSettingsDialogUi.javaScriptComboBox; javaScriptLabelPointer = domainSettingsDialogUi.javaScriptLabel; + localStorageWidgetPointer = domainSettingsDialogUi.localStorageWidget; localStorageComboBoxPointer = domainSettingsDialogUi.localStorageComboBox; localStorageLabelPointer = domainSettingsDialogUi.localStorageLabel; + domStorageWidgetPointer = domainSettingsDialogUi.domStorageWidget; domStorageComboBoxPointer = domainSettingsDialogUi.domStorageComboBox; domStorageLabelPointer = domainSettingsDialogUi.domStorageLabel; + userAgentWidgetPointer = domainSettingsDialogUi.userAgentWidget; userAgentComboBoxPointer = domainSettingsDialogUi.userAgentComboBox; userAgentLabelPointer = domainSettingsDialogUi.userAgentLabel; + zoomFactorWidgetPointer = domainSettingsDialogUi.zoomFactorWidget; zoomFactorComboBoxPointer = domainSettingsDialogUi.zoomFactorComboBox; customZoomFactorSpinBoxPointer = domainSettingsDialogUi.customZoomFactorSpinBox; QPushButton *addDomainButtonPointer = domainSettingsDialogUi.addDomainButton; @@ -96,6 +101,21 @@ DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString & // Read the data from the database and apply it to the table model. domainsTableModelPointer->select(); + // Get the default palette. + defaultPalette = javaScriptWidgetPointer->palette(); + + // Populate the highlighted palette. + highlightedPalette = defaultPalette; + + // Get the default highlight color. + QColor highlightColor = defaultPalette.color(QPalette::Highlight); + + // Set the highlight color to be partially transparent. + highlightColor.setAlpha(64); + + // Set highlighted background color. + highlightedPalette.setColor(QPalette::Window, highlightColor); + // Setup the dialog according to the start type. switch (startType) { @@ -353,30 +373,39 @@ void DomainSettingsDialog::populateDomStorageLabel() const // Populate the label according to the currently selected index. switch (domStorageComboBoxPointer->currentIndex()) { - // Set the text according to the system default. case (DomainsDatabase::SYSTEM_DEFAULT): { + // Set the text according to the system default. if (Settings::domStorageEnabled()) domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label.", "DOM storage enabled")); else domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label.", "DOM storage disabled")); + // Reset the palette. + domStorageWidgetPointer->setPalette(defaultPalette); + break; } - // Set the disabled text in bold. case (DomainsDatabase::DISABLED): { + // Set the disabled text in bold. domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label. The tags should be retained.", "DOM storage disabled")); + // Set the palette. + domStorageWidgetPointer->setPalette(highlightedPalette); + break; } - // Set the enabled text in bold. case (DomainsDatabase::ENABLED): { + // Set the enabled text in bold. domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label. The tags should be retained.", "DOM storage enabled")); + // Set the palette. + domStorageWidgetPointer->setPalette(highlightedPalette); + break; } } @@ -387,30 +416,39 @@ void DomainSettingsDialog::populateJavaScriptLabel() const // Populate the label according to the currently selected index. switch (javaScriptComboBoxPointer->currentIndex()) { - // Set the text according to the system default. case (DomainsDatabase::SYSTEM_DEFAULT): { + // Set the text according to the system default. if (Settings::javaScriptEnabled()) javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label.", "JavaScript enabled")); else javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label.", "JavaScript disabled")); + // Reset the palette. + javaScriptWidgetPointer->setPalette(defaultPalette); + break; } - // Set the disabled text in bold. case (DomainsDatabase::DISABLED): { + // Set the disabled text in bold. javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label. The tags should be retained.", "JavaScript disabled")); + // Set the palette. + javaScriptWidgetPointer->setPalette(highlightedPalette); + break; } - // Set the enabled text in bold. case (DomainsDatabase::ENABLED): { + // Set the enabled text in bold. javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label. The tags should be retained.", "JavaScript enabled")); + // Set the palette. + javaScriptWidgetPointer->setPalette(highlightedPalette); + break; } } @@ -421,30 +459,39 @@ void DomainSettingsDialog::populateLocalStorageLabel() const // Populate the label according to the currently selected index. switch (localStorageComboBoxPointer->currentIndex()) { - // Set the text according to the system default. case (DomainsDatabase::SYSTEM_DEFAULT): { + // Set the text according to the system default. if (Settings::localStorageEnabled()) localStorageLabelPointer->setText(i18nc("Domain settings local storage label.", "Local storage enabled")); else localStorageLabelPointer->setText(i18nc("Domain settings local storage label.", "Local storage disabled")); + // Reset the palette. + localStorageWidgetPointer->setPalette(defaultPalette); + break; } - // Set the disabled text in bold. case (DomainsDatabase::DISABLED): { + // Set the disabled text in bold. localStorageLabelPointer->setText(i18nc("Domain settings local storage label. The tags should be retained.", "Local storage disabled")); + // Set the palette. + localStorageWidgetPointer->setPalette(highlightedPalette); + break; } - // Set the enabled text in bold. case (DomainsDatabase::ENABLED): { + // Set the enabled text in bold. localStorageLabelPointer->setText(i18nc("Domain settings local storage label. The tabs should be retained.", "Local storage enabled")); + // Set the palette. + localStorageWidgetPointer->setPalette(highlightedPalette); + break; } } @@ -458,11 +505,17 @@ void DomainSettingsDialog::populateUserAgentLabel(const QString &userAgentName) { // Display the system default user agent name. userAgentLabelPointer->setText(UserAgentHelper::getTranslatedUserAgentNameFromDatabaseName(Settings::userAgent())); + + // Reset the palette. + userAgentWidgetPointer->setPalette(defaultPalette); } else { // Display the user agent name in bold. userAgentLabelPointer->setText("" + userAgentName + ""); + + // Set the palette. + userAgentWidgetPointer->setPalette(highlightedPalette); } } @@ -597,11 +650,17 @@ void DomainSettingsDialog::zoomFactorComboBoxChanged(const int &newIndex) const { // Display the default zoom factor. customZoomFactorSpinBoxPointer->setValue(Settings::zoomFactor()); + + // Reset the palette. + zoomFactorWidgetPointer->setPalette(defaultPalette); } else // Custom zoom factor is selected. { // Display the custom zoom factor from the domain settings. customZoomFactorSpinBoxPointer->setValue(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::CUSTOM_ZOOM_FACTOR)).data().toDouble()); + + // Set the palette. + zoomFactorWidgetPointer->setPalette(highlightedPalette); } // Update the status of the custom zoom factor spin box. diff --git a/src/dialogs/DomainSettingsDialog.h b/src/dialogs/DomainSettingsDialog.h index fb45902..7680a03 100644 --- a/src/dialogs/DomainSettingsDialog.h +++ b/src/dialogs/DomainSettingsDialog.h @@ -67,7 +67,9 @@ private: // The private variables. QPushButton *applyButtonPointer; QDoubleSpinBox *customZoomFactorSpinBoxPointer; + QPalette defaultPalette; QPushButton *deleteDomainButtonPointer; + QWidget *domStorageWidgetPointer; QComboBox *domStorageComboBoxPointer; QLabel *domStorageLabelPointer; KLineEdit *domainNameLineEditPointer; @@ -75,13 +77,18 @@ private: QListView *domainsListViewPointer; QSqlTableModel *domainsTableModelPointer; QItemSelectionModel *domainsSelectionModelPointer; + QPalette highlightedPalette; + QWidget *javaScriptWidgetPointer; QComboBox *javaScriptComboBoxPointer; QLabel *javaScriptLabelPointer; + QWidget *localStorageWidgetPointer; QComboBox *localStorageComboBoxPointer; QLabel *localStorageLabelPointer; QPushButton *resetButtonPointer; + QWidget *userAgentWidgetPointer; QComboBox *userAgentComboBoxPointer; QLabel *userAgentLabelPointer; + QWidget *zoomFactorWidgetPointer; QComboBox *zoomFactorComboBoxPointer; // The private functions. diff --git a/src/helpers/UserAgentHelper.cpp b/src/helpers/UserAgentHelper.cpp index 9727c31..14a71e2 100644 --- a/src/helpers/UserAgentHelper.cpp +++ b/src/helpers/UserAgentHelper.cpp @@ -50,11 +50,11 @@ const QString UserAgentHelper::SAFARI_MACOS_TRANSLATED = i18n("Safari on macOS") // Define the public user agent constants. const QString UserAgentHelper::PRIVACY_BROWSER_USER_AGENT = QStringLiteral("PrivacyBrowser/1.0"); const QString UserAgentHelper::FIREFOX_LINUX_USER_AGENT = QStringLiteral("Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0"); -const QString UserAgentHelper::CHROMIUM_LINUX_USER_AGENT = QStringLiteral("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36"); -const QString UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT = QStringLiteral("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0"); -const QString UserAgentHelper::CHROME_WINDOWS_USER_AGENT = QStringLiteral("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"); -const QString UserAgentHelper::EDGE_WINDOWS_USER_AGENT = QStringLiteral("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"); -const QString UserAgentHelper::SAFARI_MACOS_USER_AGENT = QStringLiteral("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"); +const QString UserAgentHelper::CHROMIUM_LINUX_USER_AGENT = QStringLiteral("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Safari/537.36"); +const QString UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT = QStringLiteral("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0"); +const QString UserAgentHelper::CHROME_WINDOWS_USER_AGENT = QStringLiteral("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Safari/537.36"); +const QString UserAgentHelper::EDGE_WINDOWS_USER_AGENT = QStringLiteral("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Safari/537.36 Edg/103.0.1264.71"); +const QString UserAgentHelper::SAFARI_MACOS_USER_AGENT = QStringLiteral("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Safari/605.1.15"); // Construct the class. UserAgentHelper::UserAgentHelper() {}; diff --git a/src/uis/DomainSettingsDialog.ui b/src/uis/DomainSettingsDialog.ui index d7eac8e..f089363 100644 --- a/src/uis/DomainSettingsDialog.ui +++ b/src/uis/DomainSettingsDialog.ui @@ -33,6 +33,7 @@ + @@ -82,290 +83,411 @@ + + - - - - - - - Domain name - + - - *. may be prepended to a domain to include all subdomains (eg. *.stoutner.com). - - - + + + + + + + Domain name + + + + *. may be prepended to a domain to include all subdomains (eg. *.stoutner.com). + + + - - + + + + - - - - JavaScript - - - - JavaScript allows websites to run programs (scripts) on the device. + + + + true - - - - - - - System default + + + 10 - - - - - JavaScript disabled + + 10 - - - - - JavaScript enabled + + 10 + + + 10 - - - - - - - Qt::RichText - + + + + JavaScript + + + + JavaScript allows websites to run programs (scripts) on the device. + + + + + + + + + System default + + + + + + JavaScript disabled + + + + + + JavaScript enabled + + + + + + + + + Qt::RichText + + + + - - - - Local storage - - - - Local storage includes cookies, IndexedDB, DOM storage, filesystem API, and service workers. DOM storage also requires a separate control to be enabled. Local storage is disabled by default. + + + + true - - - - - - - System default + + + 10 - - - - - Local storage disabled + + 10 - - - - - Local storage enabled + + 10 + + + 10 - - - - - - - Qt::RichText - + + + + Local storage + + + + Local storage includes cookies, IndexedDB, DOM storage, filesystem API, and service workers. DOM storage also requires a separate control to be enabled. Local storage is disabled by default. + + + + + + + + + System default + + + + + + Local storage disabled + + + + + + Local storage enabled + + + + + + + + + Qt::RichText + + + + - - - - DOM storage - - - - DOM storage, sometimes called web storage, is like cookies on steroids. To function, it requires that both JavaScript and local storage be enabled. + + + + true - - - - - - - System default + + + 10 - - - - - DOM storage disabled + + 10 - - - - - DOM storage enabled + + 10 + + + 10 - - - - - - - Qt::RichText - + + + + DOM storage + + + + DOM storage, sometimes called web storage, is like cookies on steroids. To function, it requires that both JavaScript and local storage be enabled. + + + + + + + + + System default + + + + + + DOM storage disabled + + + + + + DOM storage enabled + + + + + + + + + Qt::RichText + + + + - - - - User agent - - - - The user agent identifies the browser to the web server. It serves no useful purpose, but many web servers refuse to return the web page if they don't see a user agent they like. - - - - - - - - - 0 - 0 - - - - + + + true - - - System default - - - - - - Privacy Browser + + + 10 - - - - - WebEngine default - - - - - - Firefox on Linux - - - - - - Chromium on Linux - - - - - - Firefox on Windows - - - - - - Chrome on Windows + + 10 - - - - - Edge on Windows + + 10 - - - - - Safari on macOS + + 10 - - - - - - - Qt::RichText - + + + + User agent + + + + The user agent identifies the browser to the web server. It serves no useful purpose, but many web servers refuse to return the web page if they don't see a user agent they like. + + + + + + + + + 0 + 0 + + + + + true + + + + + System default + + + + + + Privacy Browser + + + + + + WebEngine default + + + + + + Firefox on Linux + + + + + + Chromium on Linux + + + + + + Firefox on Windows + + + + + + Chrome on Windows + + + + + + Edge on Windows + + + + + + Safari on macOS + + + + + + + + + Qt::RichText + + + + - - - - Zoom factor - - - - Valid values for the zoom factor are between 0.25 and 5.00. + + + + true - - - - - - - System default + + + 10 - - - - - Custom + + 10 + + + 10 + + + 10 - - - - - - - - 0.250000000000000 - - - - 5.000000000000000 - - - 0.250000000000000 - + + + + Zoom factor + + + + Valid values for the zoom factor are between 0.25 and 5.00. + + + + + + + + + System default + + + + + + Custom + + + + + + + + + 0.250000000000000 + + + + 5.000000000000000 + + + + 0.250000000000000 + + + + diff --git a/src/uis/TabWidget.ui b/src/uis/TabWidget.ui index 375f4d5..ad6a5a0 100644 --- a/src/uis/TabWidget.ui +++ b/src/uis/TabWidget.ui @@ -53,10 +53,6 @@ - - true - - true diff --git a/src/widgets/TabWidget.cpp b/src/widgets/TabWidget.cpp index 3b0ce08..59e4243 100644 --- a/src/widgets/TabWidget.cpp +++ b/src/widgets/TabWidget.cpp @@ -449,9 +449,9 @@ void TabWidget::applyDomainSettings(const QString &hostname, const bool reloadWe currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScriptEnabled()); // Set the local storage status. - //currentPrivacyWebEngineViewPointer->localStorageEnabled = Settings::localStorageEnabled(); + currentPrivacyWebEngineViewPointer->localStorageEnabled = Settings::localStorageEnabled(); - // Set DOM storage. + // Set DOM storage. In QWebEngineSettings it is called Local Storage. currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, Settings::domStorageEnabled()); // Set the user agent. diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index 8d24171..acf72db 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -175,7 +175,7 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() zoomFactorActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("zoom"))); domainSettingsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("settings-configure"))); cookiesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("preferences-web-browser-cookies"))); - domStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("view-web-browser-dom-tree"))); + domStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("code-class"))); // Update the on-the-fly menus. connect(tabWidgetPointer, SIGNAL(updateUserAgentActions(QString, bool)), this, SLOT(updateUserAgentActions(QString, bool))); -- 2.43.0