X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=blobdiff_plain;f=src%2Fdialogs%2FDomainSettingsDialog.cpp;h=34ff70e592bf988a8bdc3eb8d69f617361983ad7;hp=6964d37532209b39871968b5cdaaba863d788598;hb=HEAD;hpb=310828788817f6acf54c77138ec38d97c8bdaf3d diff --git a/src/dialogs/DomainSettingsDialog.cpp b/src/dialogs/DomainSettingsDialog.cpp index 6964d37..bbc46fc 100644 --- a/src/dialogs/DomainSettingsDialog.cpp +++ b/src/dialogs/DomainSettingsDialog.cpp @@ -1,7 +1,7 @@ /* - * Copyright 2022-2023 Soren Stoutner . + * Copyright 2022-2024 Soren Stoutner . * - * This file is part of Privacy Browser PC . + * This file is part of Privacy Browser PC . * * Privacy Browser PC is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,14 +27,14 @@ #include #include #include +#include // Define the public static int constants. const int DomainSettingsDialog::SHOW_ALL_DOMAINS = 0; -const int DomainSettingsDialog::ADD_DOMAIN = 1; -const int DomainSettingsDialog::EDIT_DOMAIN = 2; +const int DomainSettingsDialog::EDIT_DOMAIN = 1; // Construct the class. -DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString &domainName) : QDialog(nullptr) +DomainSettingsDialog::DomainSettingsDialog(QWidget *parentWidgetPointer, const int &startType, const QString &domainName) : QDialog(parentWidgetPointer) { // Set the window title. setWindowTitle(i18nc("The domain settings dialog window title", "Domain Settings")); @@ -126,17 +126,6 @@ DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString & // Select the first entry in the list view. domainsListViewPointer->setCurrentIndex(domainsTableModelPointer->index(0, domainsTableModelPointer->fieldIndex(DomainsDatabase::DOMAIN_NAME))); - // Populate the domain settings. - domainSelected(domainsSelectionModelPointer->currentIndex()); - - break; - } - - case ADD_DOMAIN: - { - // Add the new domain. - addDomain(domainName); - break; } @@ -149,13 +138,13 @@ DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString & // Move to the new domain. domainsListViewPointer->setCurrentIndex(newDomainIndex[0]); - // Populate the domain settings. - domainSelected(domainsSelectionModelPointer->currentIndex()); - break; } } + // Populate the domain settings. + domainSelected(domainsSelectionModelPointer->currentIndex()); + // Handle clicks on the domains. connect(domainsListViewPointer, SIGNAL(activated(QModelIndex)), this, SLOT(domainSelected(QModelIndex))); @@ -176,38 +165,8 @@ DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString & connect(applyButtonPointer, SIGNAL(clicked()), this, SLOT(apply())); connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(cancel())); - // Update the UI. - updateUi(); -} - -void DomainSettingsDialog::addDomain(const QString &domainName) const -{ - // Create a new domain record. - QSqlRecord newDomainRecord = QSqlDatabase::database(DomainsDatabase::CONNECTION_NAME).record(DomainsDatabase::DOMAINS_TABLE); - - // 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::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); - newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::CUSTOM_ZOOM_FACTOR), 1.0); - - // Insert the new domain. `-1` appends it to the end. - domainsTableModelPointer->insertRecord(-1, newDomainRecord); - - // Submit all pending changes. - domainsTableModelPointer->submitAll(); - - // Find the index for the new domain. `-1` allows for multiple entries to be returned. - QModelIndexList newDomainIndex = domainsTableModelPointer->match(domainsTableModelPointer->index(0, domainsTableModelPointer->fieldIndex(DomainsDatabase::DOMAIN_NAME)), - Qt::DisplayRole, domainName, -1, Qt::MatchWrap); - - // Move to the new domain. If there are multiple domains with the same name, the new one should be the last in the list. - domainsListViewPointer->setCurrentIndex(newDomainIndex[newDomainIndex.size() - 1]); - - // Populate the domain settings. - domainSelected(domainsSelectionModelPointer->currentIndex()); + // Update the DOM storage status. + updateDomStorageStatus(); // Update the UI. updateUi(); @@ -314,11 +273,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. @@ -342,6 +307,9 @@ void DomainSettingsDialog::javaScriptChanged(const int &newIndex) const // Populate the JavaScript label. populateJavaScriptLabel(); + // Update the DOM storage status. + updateDomStorageStatus(); + // Update the UI. updateUi(); } @@ -351,9 +319,12 @@ 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 DOM storage status. + updateDomStorageStatus(); + // Update the UI. updateUi(); } @@ -364,7 +335,7 @@ void DomainSettingsDialog::ok() domainsTableModelPointer->submitAll(); // Emit the domain settings updated signal. - domainSettingsUpdated(); + emit domainSettingsUpdated(); // Close the dialog. accept(); @@ -546,7 +517,31 @@ void DomainSettingsDialog::showAddMessageBox() QLineEdit::Normal, QString(), &okClicked); // Add the new domain if the user clicked OK. - if (okClicked) addDomain(newDomainName); + if (okClicked) + { + // Add the new domain. + DomainsDatabase::addDomain(newDomainName); + + // Submit all pending changes. This reloads the model from the database, getting the new domain added above. + domainsTableModelPointer->submitAll(); + + + // Find the index for the new domain. `-1` allows for multiple entries to be returned. + QModelIndexList newDomainIndex = domainsTableModelPointer->match(domainsTableModelPointer->index(0, domainsTableModelPointer->fieldIndex(DomainsDatabase::DOMAIN_NAME)), + Qt::DisplayRole, newDomainName, -1, Qt::MatchWrap); + + // Move to the new domain. If there are multiple domains with the same name, the new one should be the last in the list. + domainsListViewPointer->setCurrentIndex(newDomainIndex[newDomainIndex.size() - 1]); + + // Populate the domain settings. + domainSelected(domainsSelectionModelPointer->currentIndex()); + + // Update the UI. + updateUi(); + + // Emit the domain settings updated signal. + emit domainSettingsUpdated(); + } } void DomainSettingsDialog::showDeleteMessageBox() const @@ -608,9 +603,84 @@ void DomainSettingsDialog::showDeleteMessageBox() const // Update the Ui. updateUi(); + + // Emit the domain settings updated signal. + emit domainSettingsUpdated(); } } +void DomainSettingsDialog::updateDomStorageStatus() const +{ + // Instantiate tracking variables. + bool javaScriptEnabled; + bool localStorageEnabled; + + // Populate the JavaScript tracker. + switch (javaScriptComboBoxPointer->currentIndex()) + { + case (DomainsDatabase::SYSTEM_DEFAULT): + { + // Update the tracker according to the system default. + if (Settings::javaScriptEnabled()) + javaScriptEnabled = true; + else + javaScriptEnabled = false; + + break; + } + + case (DomainsDatabase::ENABLED): + { + // Update the tracker. + javaScriptEnabled = true; + + break; + } + + case (DomainsDatabase::DISABLED): + { + // Update the tracker. + javaScriptEnabled = false; + + break; + } + } + + // Populate the local storage tracker. + switch (localStorageComboBoxPointer->currentIndex()) + { + case (DomainsDatabase::SYSTEM_DEFAULT): + { + // Update the tracker according to the system default. + if (Settings::localStorageEnabled()) + localStorageEnabled = true; + else + localStorageEnabled = false; + + break; + } + + case (DomainsDatabase::ENABLED): + { + // Update the tracker. + localStorageEnabled = true; + + break; + } + + case (DomainsDatabase::DISABLED): + { + // Update the tracker. + localStorageEnabled = false; + + break; + } + } + + // Only enable DOM storage if both JavaScript and local storage are enabled. + domStorageComboBoxPointer->setEnabled(javaScriptEnabled && localStorageEnabled); +} + void DomainSettingsDialog::updateUi() const { // Update the delete button status. @@ -661,7 +731,7 @@ void DomainSettingsDialog::zoomFactorComboBoxChanged(const int &newIndex) const // Display the custom zoom factor from the domain settings. customZoomFactorSpinBoxPointer->setValue(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::CUSTOM_ZOOM_FACTOR)).data().toDouble()); - // Set the palette. + // Use the highlighted palette. zoomFactorWidgetPointer->setPalette(highlightedPalette); }