]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Add a delete all domains button. https://redmine.stoutner.com/issues/1234
authorSoren Stoutner <soren@stoutner.com>
Thu, 31 Oct 2024 22:36:31 +0000 (15:36 -0700)
committerSoren Stoutner <soren@stoutner.com>
Thu, 31 Oct 2024 22:36:31 +0000 (15:36 -0700)
src/dialogs/DomainSettingsDialog.cpp
src/dialogs/DomainSettingsDialog.h
src/uis/DomainSettingsDialog.ui

index 6c5adf53a98e8aa8fbc2b2cb9e2feee5af3d23e0..dd10f484956b44b675b600b435953687e2a5198a 100644 (file)
@@ -14,7 +14,7 @@
  * GNU General Public License for more details.
  *
  * 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/>.
+ * along with Privacy Browser PC.  If not, see <https://www.gnu.org/licenses/>.
  */
 
 // Application headers.
@@ -87,10 +87,14 @@ DomainSettingsDialog::DomainSettingsDialog(QWidget *parentWidgetPointer, const i
     customZoomFactorSpinBoxPointer = domainSettingsDialogUi.customZoomFactorSpinBox;
     QPushButton *addDomainButtonPointer = domainSettingsDialogUi.addDomainButton;
     deleteDomainButtonPointer = domainSettingsDialogUi.deleteDomainButton;
+    deleteAllDomainsButtonPointer = domainSettingsDialogUi.deleteAllDomainsButton;
     QDialogButtonBox *dialogButtonBoxPointer = domainSettingsDialogUi.dialogButtonBox;
     applyButtonPointer = dialogButtonBoxPointer->button(QDialogButtonBox::StandardButton::Apply);
     resetButtonPointer = dialogButtonBoxPointer->button(QDialogButtonBox::StandardButton::Reset);
 
+    // Set the button icons that require a fallback icon.
+    deleteAllDomainsButtonPointer->setIcon(QIcon::fromTheme(QLatin1String("albumfolder-user-trash"), QIcon::fromTheme(QLatin1String("list-remove"))));
+
     // Create a table model.
     domainsTableModelPointer = new QSqlTableModel(nullptr, QSqlDatabase::database(DomainsDatabase::CONNECTION_NAME));
 
@@ -180,6 +184,7 @@ DomainSettingsDialog::DomainSettingsDialog(QWidget *parentWidgetPointer, const i
     // Connect the buttons.
     connect(addDomainButtonPointer, SIGNAL(clicked()), this, SLOT(showAddMessageBox()));
     connect(deleteDomainButtonPointer, SIGNAL(clicked()), this, SLOT(showDeleteMessageBox()));
+    connect(deleteAllDomainsButtonPointer, SIGNAL(clicked()), this, SLOT(showDeleteAllMessageBox()));
     connect(resetButtonPointer, SIGNAL(clicked()), this, SLOT(reset()));
     connect(dialogButtonBoxPointer, SIGNAL(accepted()), this, SLOT(ok()));
     connect(applyButtonPointer, SIGNAL(clicked()), this, SLOT(apply()));
@@ -695,31 +700,77 @@ void DomainSettingsDialog::showAddMessageBox()
     }
 }
 
+void DomainSettingsDialog::showDeleteAllMessageBox() const
+{
+    // Instantiate a delete all message box.
+    QMessageBox deleteAllMessageBox;
+
+    // Set the icon.
+    deleteAllMessageBox.setIcon(QMessageBox::Warning);
+
+    // Set the window title.
+    deleteAllMessageBox.setWindowTitle(i18nc("Delete all domains dialog title", "Delete All Domains"));
+
+    // Set the text.
+    deleteAllMessageBox.setText(i18nc("Delete all domains dialog main message", "Delete all domains?"));
+
+    // Set the informative test.
+    deleteAllMessageBox.setInformativeText(i18nc("Delete all domains dialog secondary message", "This action cannot be undone."));
+
+    // Set the standard buttons.
+    deleteAllMessageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+
+    // Set the default button.
+    deleteAllMessageBox.setDefaultButton(QMessageBox::No);
+
+    // Display the dialog and capture the return value.
+    int returnValue = deleteAllMessageBox.exec();
+
+    // Delete all domains if instructed.
+    if (returnValue == QMessageBox::Yes)
+    {
+        // Get the count of all rows.
+        int rowCount = domainsTableModelPointer->rowCount();
+
+        // Delete all the rows, starting with 0.
+        domainsTableModelPointer->removeRows(0, rowCount);
+
+        // Submit all pending changes.
+        domainsTableModelPointer->submitAll();
+
+        // Update the buttons.
+        updateButtons();
+
+        // Emit the domain settings updated signal.
+        emit domainSettingsUpdated();
+    }
+}
+
 void DomainSettingsDialog::showDeleteMessageBox() const
 {
-    // Instantiate a delete dialog message box.
-    QMessageBox deleteDialogMessageBox;
+    // Instantiate a delete message box.
+    QMessageBox deleteMessageBox;
 
     // Set the icon.
-    deleteDialogMessageBox.setIcon(QMessageBox::Warning);
+    deleteMessageBox.setIcon(QMessageBox::Warning);
 
     // Set the window title.
-    deleteDialogMessageBox.setWindowTitle(i18nc("Delete domain dialog title", "Delete Domain"));
+    deleteMessageBox.setWindowTitle(i18nc("Delete domain dialog title", "Delete Domain"));
 
     // Set the text.
-    deleteDialogMessageBox.setText(i18nc("Delete domain dialog main message", "Delete the current domain?"));
+    deleteMessageBox.setText(i18nc("Delete domain dialog main message", "Delete the current domain?"));
 
     // Set the informative text.
-    deleteDialogMessageBox.setInformativeText(i18nc("Delete domain dialog secondary message", "Doing so will also save any pending changes that have been made to other domains."));
+    deleteMessageBox.setInformativeText(i18nc("Delete domain dialog secondary message", "Doing so will also save any pending changes that have been made to other domains."));
 
     // Set the standard buttons.
-    deleteDialogMessageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+    deleteMessageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
 
     // Set the default button.
-    deleteDialogMessageBox.setDefaultButton(QMessageBox::No);
+    deleteMessageBox.setDefaultButton(QMessageBox::No);
 
     // Display the dialog and capture the return value.
-    int returnValue = deleteDialogMessageBox.exec();
+    int returnValue = deleteMessageBox.exec();
 
     // Delete the domain if instructed.
     if (returnValue == QMessageBox::Yes)
@@ -786,9 +837,15 @@ void DomainSettingsDialog::ultraPrivacyChanged(const int newIndex) const
 
 void DomainSettingsDialog::updateButtons() const
 {
+    // Get
+    bool atLeastOneDomainSettingExists = domainsTableModelPointer->rowCount() > 0;
+
     // Update the delete button status.
     deleteDomainButtonPointer->setEnabled(domainsSelectionModelPointer->hasSelection());
 
+    // Update the delete all button status.
+    deleteAllDomainsButtonPointer->setEnabled(atLeastOneDomainSettingExists);
+
     // Update the reset button status.
     resetButtonPointer->setEnabled(domainsTableModelPointer->isDirty());
 
@@ -796,7 +853,7 @@ void DomainSettingsDialog::updateButtons() const
     applyButtonPointer->setEnabled(domainsTableModelPointer->isDirty());
 
     // Display the domain settings if there is at least one domain.
-    domainSettingsWidgetPointer->setVisible(domainsTableModelPointer->rowCount() > 0);
+    domainSettingsWidgetPointer->setVisible(atLeastOneDomainSettingExists);
 }
 
 void DomainSettingsDialog::updateDomStorageStatus() const
index b6a585752501c2bedc16eaafe86ea1b5da12bdbc..64530442ed902460708b44878e25b0b7ca043881 100644 (file)
@@ -14,7 +14,7 @@
  * GNU General Public License for more details.
  *
  * 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/>.
+ * along with Privacy Browser PC.  If not, see <https://www.gnu.org/licenses/>.
  */
 
 #ifndef DOMAIN_SETTINGS_DIALOG_H
@@ -65,6 +65,7 @@ private Q_SLOTS:
     void ok();
     void reset() const;
     void showAddMessageBox();
+    void showDeleteAllMessageBox() const;
     void showDeleteMessageBox() const;
     void ultraListChanged(const int newIndex) const;
     void ultraPrivacyChanged(const int newIndex) const;
@@ -86,6 +87,7 @@ private:
     QPushButton *applyButtonPointer;
     QDoubleSpinBox *customZoomFactorSpinBoxPointer;
     QPalette defaultPalette;
+    QPushButton *deleteAllDomainsButtonPointer;
     QPushButton *deleteDomainButtonPointer;
     QWidget *domStorageWidgetPointer;
     QComboBox *domStorageComboBoxPointer;
index 8971f5a743d500f98d0c6edf75e9dc16d6d5722c..2bbcc78e4754948d66ee8a3e481dcd5697370b04 100644 (file)
@@ -16,7 +16,7 @@
   GNU General Public License for more details.
 
   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/>. -->
+  along with Privacy Browser PC.  If not, see <https://www.gnu.org/licenses/>. -->
 
 <ui version="4.0">
     <class>DomainSettingsDialog</class>
                                     </property>
                                 </spacer>
                             </item>
+
+                            <!-- Delete all domains button. -->
+                            <item>
+                                <widget class="QPushButton" name="deleteAllDomainsButton">
+                                    <property name="text">
+                                        <string>Delete all domains</string>
+                                    </property>
+                                </widget>
+                            </item>
                         </layout>
                     </item>
                 </layout>