From: Soren Stoutner Date: Thu, 31 Oct 2024 22:36:31 +0000 (-0700) Subject: Add a delete all domains button. https://redmine.stoutner.com/issues/1234 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=ab325d6bd3f4af54d4237273e72c3f63df8f8b1e;p=PrivacyBrowserPC.git Add a delete all domains button. https://redmine.stoutner.com/issues/1234 --- diff --git a/src/dialogs/DomainSettingsDialog.cpp b/src/dialogs/DomainSettingsDialog.cpp index 6c5adf5..dd10f48 100644 --- a/src/dialogs/DomainSettingsDialog.cpp +++ b/src/dialogs/DomainSettingsDialog.cpp @@ -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 . + * along with Privacy Browser PC. If not, see . */ // 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 diff --git a/src/dialogs/DomainSettingsDialog.h b/src/dialogs/DomainSettingsDialog.h index b6a5857..6453044 100644 --- a/src/dialogs/DomainSettingsDialog.h +++ b/src/dialogs/DomainSettingsDialog.h @@ -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 . + * along with Privacy Browser PC. If not, see . */ #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; diff --git a/src/uis/DomainSettingsDialog.ui b/src/uis/DomainSettingsDialog.ui index 8971f5a..2bbcc78 100644 --- a/src/uis/DomainSettingsDialog.ui +++ b/src/uis/DomainSettingsDialog.ui @@ -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 . --> + along with Privacy Browser PC. If not, see . --> DomainSettingsDialog @@ -78,6 +78,15 @@ + + + + + + Delete all domains + + +