From 6a4af266d064e144822e46dc193f6d8c27ea6eb5 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Thu, 15 Jun 2023 15:29:10 -0700 Subject: [PATCH] Prevent duplicate domain settings entries from being automatically created. https://redmine.stoutner.com/issues/1018 --- src/dialogs/DomainSettingsDialog.cpp | 15 +++++++++++++-- src/widgets/TabWidget.cpp | 13 +++++++++++-- src/windows/BrowserWindow.cpp | 16 +++++----------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/dialogs/DomainSettingsDialog.cpp b/src/dialogs/DomainSettingsDialog.cpp index 6964d37..4aef5ce 100644 --- a/src/dialogs/DomainSettingsDialog.cpp +++ b/src/dialogs/DomainSettingsDialog.cpp @@ -27,6 +27,7 @@ #include #include #include +#include // Define the public static int constants. const int DomainSettingsDialog::SHOW_ALL_DOMAINS = 0; @@ -137,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; } @@ -188,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); @@ -211,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 @@ -351,7 +359,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. @@ -364,7 +372,7 @@ void DomainSettingsDialog::ok() domainsTableModelPointer->submitAll(); // Emit the domain settings updated signal. - domainSettingsUpdated(); + emit domainSettingsUpdated(); // Close the dialog. accept(); @@ -608,6 +616,9 @@ void DomainSettingsDialog::showDeleteMessageBox() const // Update the Ui. updateUi(); + + // Emit the domain settings updated signal. + emit domainSettingsUpdated(); } } diff --git a/src/widgets/TabWidget.cpp b/src/widgets/TabWidget.cpp index 7ca5434..f8044e2 100644 --- a/src/widgets/TabWidget.cpp +++ b/src/widgets/TabWidget.cpp @@ -487,8 +487,17 @@ void TabWidget::applyApplicationSettings() void TabWidget::applyDomainSettingsAndReload() { - // Apply the domain settings. `true` reloads the website. - currentPrivacyWebEngineViewPointer->applyDomainSettings(currentPrivacyWebEngineViewPointer->url().host(), true); + // Get the number of tabs. + int numberOfTabs = qTabWidgetPointer->count(); + + // Apply the domain settings to each WebEngine. + for (int i = 0; i < numberOfTabs; ++i) { + // Get the WebEngine view pointer. + PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast(qTabWidgetPointer->widget(i)); + + // Apply the spatial navigation settings to each page. + privacyWebEngineViewPointer->applyDomainSettings(privacyWebEngineViewPointer->url().host(), true); + } } void TabWidget::applyOnTheFlySearchEngine(QAction *searchEngineActionPointer) diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index fac3235..de6c6b1 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -464,17 +464,11 @@ void BrowserWindow::addOrEditDomainSettings() const domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsName); } - // Set the dialog window title. - domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings")); - - // Set the modality. - domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);; + // Reload the tabs when domain settings are updated. + connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload())); // Show the dialog. domainSettingsDialogPointer->show(); - - // Reload the tabs when domain settings are updated. - connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload())); } void BrowserWindow::back() const @@ -700,11 +694,11 @@ void BrowserWindow::showDomainSettingsDialog() const // Instantiate the domain settings dialog. DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog(); - // Show the dialog. - domainSettingsDialogPointer->show(); - // Reload the tabs when domain settings are updated. connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload())); + + // Show the dialog. + domainSettingsDialogPointer->show(); } void BrowserWindow::showFindTextActions() const -- 2.45.2