2 * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
6 * Privacy Browser PC is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Browser PC is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
20 // Application headers.
21 #include "DomainSettingsView.h"
22 #include "ui_DomainSettingsView.h"
23 #include "helpers/DomainsDatabaseHelper.h"
25 DomainSettingsView::DomainSettingsView(QWidget *parent) : QWidget(parent)
27 // Instantiate the domain settings view UI.
28 Ui::DomainSettingsView domainSettingsViewUi;
31 domainSettingsViewUi.setupUi(this);
33 // Get handles for the views.
34 domainsListViewPointer = domainSettingsViewUi.domainsListView;
35 domainNameLineEditPointer = domainSettingsViewUi.domainNameLineEdit;
37 // Create a table model.
38 domainsTableModelPointer = new QSqlTableModel(0, QSqlDatabase::database(DomainsDatabaseHelper::CONNECTION_NAME));
40 // Set the table for the model.
41 domainsTableModelPointer->setTable(DomainsDatabaseHelper::DOMAINS_TABLE);
43 // Set the model for the list view.
44 domainsListViewPointer->setModel(domainsTableModelPointer);
46 // Set the visible column to be the domain name.
47 domainsListViewPointer->setModelColumn(1);
49 // Disable editing of the list view.
50 domainsListViewPointer->setEditTriggers(QAbstractItemView::NoEditTriggers);
52 // Handle clicks on the domains.
53 connect(domainsListViewPointer, SIGNAL(activated(QModelIndex)), this, SLOT(domainSelected(QModelIndex)));
55 // Read the data from the database and apply it to the table model.
56 domainsTableModelPointer->select();
58 // Select the first entry in the list view.
59 domainsListViewPointer->setCurrentIndex(domainsTableModelPointer->index(0, 1));
61 // Populate the domain settings.
62 domainSelected(domainsListViewPointer->selectionModel()->currentIndex());
65 void DomainSettingsView::addDomain()
68 domainsTableModelPointer->insertRows(domainsTableModelPointer->rowCount(), 1);
71 void DomainSettingsView::deleteDomain()
73 // Delete the current row.
74 domainsTableModelPointer->removeRow(domainsListViewPointer->selectionModel()->currentIndex().row());
78 void DomainSettingsView::domainSelected(QModelIndex modelIndex)
80 // Populate the domain name line edit pointer.
81 domainNameLineEditPointer->setText(modelIndex.data().toString());