--- /dev/null
+/*
+ * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+ *
+ * Privacy Browser PC is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Browser PC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * 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/>.
+ */
+
+// Application headers.
+#include "DomainSettingsView.h"
+#include "ui_DomainSettingsView.h"
+#include "helpers/DomainsDatabaseHelper.h"
+
+DomainSettingsView::DomainSettingsView(QWidget *parent) : QWidget(parent)
+{
+ // Instantiate the domain settings view UI.
+ Ui::DomainSettingsView domainSettingsViewUi;
+
+ // Setup the UI.
+ domainSettingsViewUi.setupUi(this);
+
+ // Get handles for the views.
+ domainsListViewPointer = domainSettingsViewUi.domainsListView;
+ domainNameLineEditPointer = domainSettingsViewUi.domainNameLineEdit;
+
+ // Create a table model.
+ domainsTableModelPointer = new QSqlTableModel(0, QSqlDatabase::database(DomainsDatabaseHelper::CONNECTION_NAME));
+
+ // Set the table for the model.
+ domainsTableModelPointer->setTable(DomainsDatabaseHelper::DOMAINS_TABLE);
+
+ // Set the model for the list view.
+ domainsListViewPointer->setModel(domainsTableModelPointer);
+
+ // Set the visible column to be the domain name.
+ domainsListViewPointer->setModelColumn(1);
+
+ // Disable editing of the list view.
+ domainsListViewPointer->setEditTriggers(QAbstractItemView::NoEditTriggers);
+
+ // Handle clicks on the domains.
+ connect(domainsListViewPointer, SIGNAL(activated(QModelIndex)), this, SLOT(domainSelected(QModelIndex)));
+
+ // Read the data from the database and apply it to the table model.
+ domainsTableModelPointer->select();
+
+ // Select the first entry in the list view.
+ domainsListViewPointer->setCurrentIndex(domainsTableModelPointer->index(0, 1));
+
+ // Populate the domain settings.
+ domainSelected(domainsListViewPointer->selectionModel()->currentIndex());
+}
+
+void DomainSettingsView::addDomain()
+{
+ // Insert a row.
+ domainsTableModelPointer->insertRows(domainsTableModelPointer->rowCount(), 1);
+}
+
+void DomainSettingsView::deleteDomain()
+{
+ // Delete the current row.
+ domainsTableModelPointer->removeRow(domainsListViewPointer->selectionModel()->currentIndex().row());
+}
+
+
+void DomainSettingsView::domainSelected(QModelIndex modelIndex)
+{
+ // Populate the domain name line edit pointer.
+ domainNameLineEditPointer->setText(modelIndex.data().toString());
+}