]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/dialogs/DomainSettingsDialog.cpp
Prevent duplicate domain settings entries from being automatically created. https...
[PrivacyBrowserPC.git] / src / dialogs / DomainSettingsDialog.cpp
index ea5558c1fd267491dd8bfd3617bff89642611b86..4aef5ce31e0c1d6ab93d29c3d07387f8e068d48c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
  *
@@ -27,6 +27,7 @@
 #include <QInputDialog>
 #include <QMessageBox>
 #include <QPushButton>
+#include <QTimer>
 
 // 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
@@ -219,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.
@@ -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();
@@ -389,10 +397,10 @@ void DomainSettingsDialog::populateDomStorageLabel() const
             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);
@@ -400,10 +408,10 @@ void DomainSettingsDialog::populateDomStorageLabel() const
             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);
@@ -432,10 +440,10 @@ void DomainSettingsDialog::populateJavaScriptLabel() const
             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);
@@ -443,10 +451,10 @@ void DomainSettingsDialog::populateJavaScriptLabel() const
             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);
@@ -475,10 +483,10 @@ void DomainSettingsDialog::populateLocalStorageLabel() const
             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);
@@ -486,10 +494,10 @@ void DomainSettingsDialog::populateLocalStorageLabel() const
             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);
@@ -608,6 +616,9 @@ void DomainSettingsDialog::showDeleteMessageBox() const
 
         // Update the Ui.
         updateUi();
+
+        // Emit the domain settings updated signal.
+        emit domainSettingsUpdated();
     }
 }