/*
- * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2024 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
*
*
* You should have received a copy of the GNU General Public License
* along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
- */
+ // */
// Application headers.
#include "DomainSettingsDialog.h"
#include <QInputDialog>
#include <QMessageBox>
#include <QPushButton>
+#include <QTimer>
// 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)
break;
}
- case ADD_DOMAIN:
- {
- // Add the new domain.
- addDomain(domainName);
-
- break;
- }
-
case EDIT_DOMAIN:
{
// Find the index for the new domain. `1` returns the first match.
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 UI.
- updateUi();
-}
-
void DomainSettingsDialog::apply() const
{
// Get the current index.
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.
{
// 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.
// 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.
domainsTableModelPointer->submitAll();
// Emit the domain settings updated signal.
- domainSettingsUpdated();
+ emit domainSettingsUpdated();
// Close the dialog.
accept();
break;
}
- case (DomainsDatabase::DISABLED):
+ case (DomainsDatabase::ENABLED):
{
- // Set the disabled text in bold.
- domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label. The <b> tags should be retained.", "<b>DOM storage disabled</b>"));
+ // Set the enabled text in bold.
+ domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label. The <b> tags should be retained.", "<b>DOM storage enabled</b>"));
// Set the palette.
domStorageWidgetPointer->setPalette(highlightedPalette);
break;
}
- case (DomainsDatabase::ENABLED):
+ case (DomainsDatabase::DISABLED):
{
- // Set the enabled text in bold.
- domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label. The <b> tags should be retained.", "<b>DOM storage enabled</b>"));
+ // Set the disabled text in bold.
+ domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label. The <b> tags should be retained.", "<b>DOM storage disabled</b>"));
// Set the palette.
domStorageWidgetPointer->setPalette(highlightedPalette);
break;
}
- case (DomainsDatabase::DISABLED):
+ case (DomainsDatabase::ENABLED):
{
- // Set the disabled text in bold.
- javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label. The <b> tags should be retained.", "<b>JavaScript disabled</b>"));
+ // Set the enabled text in bold.
+ javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label. The <b> tags should be retained.", "<b>JavaScript enabled</b>"));
// Set the palette.
javaScriptWidgetPointer->setPalette(highlightedPalette);
break;
}
- case (DomainsDatabase::ENABLED):
+ case (DomainsDatabase::DISABLED):
{
- // Set the enabled text in bold.
- javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label. The <b> tags should be retained.", "<b>JavaScript enabled</b>"));
+ // Set the disabled text in bold.
+ javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label. The <b> tags should be retained.", "<b>JavaScript disabled</b>"));
// Set the palette.
javaScriptWidgetPointer->setPalette(highlightedPalette);
break;
}
- case (DomainsDatabase::DISABLED):
+ case (DomainsDatabase::ENABLED):
{
- // Set the disabled text in bold.
- localStorageLabelPointer->setText(i18nc("Domain settings local storage label. The <b> tags should be retained.", "<b>Local storage disabled</b>"));
+ // Set the enabled text in bold.
+ localStorageLabelPointer->setText(i18nc("Domain settings local storage label. The <b> tabs should be retained.", "<b>Local storage enabled</b>"));
// Set the palette.
localStorageWidgetPointer->setPalette(highlightedPalette);
break;
}
- case (DomainsDatabase::ENABLED):
+ case (DomainsDatabase::DISABLED):
{
- // Set the enabled text in bold.
- localStorageLabelPointer->setText(i18nc("Domain settings local storage label. The <b> tabs should be retained.", "<b>Local storage enabled</b>"));
+ // Set the disabled text in bold.
+ localStorageLabelPointer->setText(i18nc("Domain settings local storage label. The <b> tags should be retained.", "<b>Local storage disabled</b>"));
// Set the palette.
localStorageWidgetPointer->setPalette(highlightedPalette);
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
// Update the Ui.
updateUi();
+
+ // Emit the domain settings updated signal.
+ emit domainSettingsUpdated();
}
}
// 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);
}