X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=src%2Fdialogs%2FDomainSettingsDialog.cpp;h=82f0f64b890af85781c3187a5f3ecf7902d04f2a;hb=425fed98271cd951cddef9904e5e271f0fb76fc1;hp=76477ecf8ccceab21f23aad2005282f5d064ada2;hpb=cd1c3d0483b9026736fdcb151d90dda872d8a400;p=PrivacyBrowserPC.git diff --git a/src/dialogs/DomainSettingsDialog.cpp b/src/dialogs/DomainSettingsDialog.cpp index 76477ec..82f0f64 100644 --- a/src/dialogs/DomainSettingsDialog.cpp +++ b/src/dialogs/DomainSettingsDialog.cpp @@ -1,5 +1,5 @@ /* - * Copyright © 2022 Soren Stoutner . + * Copyright 2022-2023 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -15,19 +15,19 @@ * * You should have received a copy of the GNU General Public License * along with Privacy Browser PC. If not, see . - */ + // */ // Application headers. #include "DomainSettingsDialog.h" #include "Settings.h" #include "ui_DomainSettingsDialog.h" #include "databases/DomainsDatabase.h" -#include "helpers/UserAgentHelper.h" // Qt toolkit headers. #include #include #include +#include // Define the public static int constants. const int DomainSettingsDialog::SHOW_ALL_DOMAINS = 0; @@ -41,7 +41,10 @@ DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString & setWindowTitle(i18nc("The domain settings dialog window title", "Domain Settings")); // Set the window modality. - setWindowModality(Qt::WindowModality::ApplicationModal);; + setWindowModality(Qt::WindowModality::ApplicationModal); + + // Instantiate the user agent helper. + userAgentHelperPointer = new UserAgentHelper(); // Instantiate the domain settings dialog UI. Ui::DomainSettingsDialog domainSettingsDialogUi; @@ -53,14 +56,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 +104,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) { @@ -115,6 +138,9 @@ DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString & // Add the new domain. addDomain(domainName); + // Emit the domain settings updated signal after 100 milliseconds. This is necessary because the browser window takes time to process the connect command to receive the signal. + QTimer::singleShot(100, [this] () { emit domainSettingsUpdated();}); + break; } @@ -166,6 +192,7 @@ void DomainSettingsDialog::addDomain(const QString &domainName) const // Set the values for the new domain. newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::DOMAIN_NAME), domainName); newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::JAVASCRIPT), DomainsDatabase::SYSTEM_DEFAULT); + newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::LOCAL_STORAGE), DomainsDatabase::SYSTEM_DEFAULT); newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::DOM_STORAGE), DomainsDatabase::SYSTEM_DEFAULT); newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::USER_AGENT), UserAgentHelper::SYSTEM_DEFAULT_DATABASE); newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::ZOOM_FACTOR), DomainsDatabase::SYSTEM_DEFAULT); @@ -189,6 +216,9 @@ void DomainSettingsDialog::addDomain(const QString &domainName) const // Update the UI. updateUi(); + + // Emit the domain settings updated signal. + emit domainSettingsUpdated(); } void DomainSettingsDialog::apply() const @@ -197,13 +227,13 @@ void DomainSettingsDialog::apply() const QModelIndex currentIndex = domainsListViewPointer->currentIndex(); // Get the ID of the current index row. - QVariant currentId = currentIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::_ID)).data(); + QVariant currentId = currentIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::ID)).data(); // Submit all pending changes. domainsTableModelPointer->submitAll(); // Find the new index for the selected id. The `1` keeps searching after the first match. - QModelIndexList newIndexList = domainsTableModelPointer->match(currentIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::_ID)), Qt::DisplayRole, currentId, + QModelIndexList newIndexList = domainsTableModelPointer->match(currentIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::ID)), Qt::DisplayRole, currentId, 1, Qt::MatchWrap); // Select the new index. @@ -292,11 +322,17 @@ void DomainSettingsDialog::domainSelected(const QModelIndex &modelIndex) const { // Display the default zoom factor. customZoomFactorSpinBoxPointer->setValue(Settings::zoomFactor()); + + // Use the default 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()); + + // Use the highlighted palette. + zoomFactorWidgetPointer->setPalette(highlightedPalette); } // Set the initial status of the custom zoom factor spin box. @@ -329,7 +365,7 @@ void DomainSettingsDialog::localStorageChanged(const int &newIndex) const // Update the domains table model. domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::LOCAL_STORAGE)), newIndex); - // Poplate the local storage label. + // Populate the local storage label. populateLocalStorageLabel(); // Update the UI. @@ -342,7 +378,7 @@ void DomainSettingsDialog::ok() domainsTableModelPointer->submitAll(); // Emit the domain settings updated signal. - domainSettingsUpdated(); + emit domainSettingsUpdated(); // Close the dialog. accept(); @@ -353,29 +389,38 @@ 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): + case (DomainsDatabase::ENABLED): { - domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label. The tags should be retained.", "DOM storage disabled")); + // 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; } - // Set the enabled text in bold. - case (DomainsDatabase::ENABLED): + case (DomainsDatabase::DISABLED): { - domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label. The tags should be retained.", "DOM storage enabled")); + // 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; } @@ -387,29 +432,38 @@ 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): + case (DomainsDatabase::ENABLED): { - javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label. The tags should be retained.", "JavaScript disabled")); + // 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; } - // Set the enabled text in bold. - case (DomainsDatabase::ENABLED): + case (DomainsDatabase::DISABLED): { - javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label. The tags should be retained.", "JavaScript enabled")); + // 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; } @@ -421,29 +475,38 @@ 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): + case (DomainsDatabase::ENABLED): { - localStorageLabelPointer->setText(i18nc("Domain settings local storage label. The tags should be retained.", "Local storage disabled")); + // 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; } - // Set the enabled text in bold. - case (DomainsDatabase::ENABLED): + case (DomainsDatabase::DISABLED): { - localStorageLabelPointer->setText(i18nc("Domain settings local storage label. The tabs should be retained.", "Local storage enabled")); + // 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; } @@ -454,15 +517,21 @@ void DomainSettingsDialog::populateLocalStorageLabel() const void DomainSettingsDialog::populateUserAgentLabel(const QString &userAgentName) const { // Populate the label according to the type. - if (userAgentName == UserAgentHelper::SYSTEM_DEFAULT_TRANSLATED) + if (userAgentName == userAgentHelperPointer->SYSTEM_DEFAULT_TRANSLATED) { // Display the system default user agent name. - userAgentLabelPointer->setText(UserAgentHelper::getTranslatedUserAgentNameFromDatabaseName(Settings::userAgent())); + userAgentLabelPointer->setText(userAgentHelperPointer->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); } } @@ -553,6 +622,9 @@ void DomainSettingsDialog::showDeleteMessageBox() const // Update the Ui. updateUi(); + + // Emit the domain settings updated signal. + emit domainSettingsUpdated(); } } @@ -561,12 +633,12 @@ void DomainSettingsDialog::updateUi() const // Update the delete button status. deleteDomainButtonPointer->setEnabled(domainsSelectionModelPointer->hasSelection()); - // Update the apply button status. - applyButtonPointer->setEnabled(domainsTableModelPointer->isDirty()); - // Update the reset button status. resetButtonPointer->setEnabled(domainsTableModelPointer->isDirty()); + // Update the apply button status. + applyButtonPointer->setEnabled(domainsTableModelPointer->isDirty()); + // Display the domain settings if there is at least one domain. domainSettingsWidgetPointer->setVisible(domainsTableModelPointer->rowCount() > 0); } @@ -575,7 +647,7 @@ void DomainSettingsDialog::userAgentChanged(const QString &updatedUserAgent) con { // Update the domains table model. domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::USER_AGENT)), - UserAgentHelper::getDatabaseUserAgentNameFromTranslatedName(updatedUserAgent)); + userAgentHelperPointer->getDatabaseUserAgentNameFromTranslatedName(updatedUserAgent)); // Populate the user agent label. populateUserAgentLabel(updatedUserAgent); @@ -597,11 +669,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()); + + // Use the highlighted palette. + zoomFactorWidgetPointer->setPalette(highlightedPalette); } // Update the status of the custom zoom factor spin box.