X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=src%2Fviews%2FDomainSettingsView.cpp;fp=src%2Fviews%2FDomainSettingsView.cpp;h=ff1131f817494ce84a3e570a6b3b67a3ec376f13;hb=0a7bcc3ab2d2a1015f29293fc9c527c1448a86cf;hp=0000000000000000000000000000000000000000;hpb=8f52378069b5b638dd832d1435e58e1596cc9798;p=PrivacyBrowserPC.git diff --git a/src/views/DomainSettingsView.cpp b/src/views/DomainSettingsView.cpp new file mode 100644 index 0000000..ff1131f --- /dev/null +++ b/src/views/DomainSettingsView.cpp @@ -0,0 +1,82 @@ +/* + * Copyright © 2022 Soren Stoutner . + * + * This file is part of 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 . + */ + +// 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()); +}