Falkon Develop
Cross-platform Qt-based web browser
certificatemanager.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2023 Javier Llorente <javier@opensuse.org>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "certificatemanager.h"
19#include "ui_certificatemanager.h"
20#include "mainapplication.h"
21#include "networkmanager.h"
22#include "settings.h"
23
24#include <QFormLayout>
25#include <QLineEdit>
26#include <QLabel>
27#include <QMessageBox>
28
30 : QDialog(parent)
31 , ui(new Ui::CertificateManager)
32{
33 setAttribute(Qt::WA_DeleteOnClose);
34
35 ui->setupUi(this);
36 ui->listWidget->setLayoutDirection(Qt::LeftToRight);
37
38 Settings settings;
39 settings.beginGroup(QSL("Web-Browser-Settings"));
40 m_ignoredSslHosts = settings.value(QSL("IgnoredSslHosts"), QStringList()).toStringList();
41 settings.endGroup();
42 ui->listWidget->addItems(m_ignoredSslHosts);
43
44 connect(ui->add, &QAbstractButton::clicked, this, &CertificateManager::addException);
45 connect(ui->remove, &QAbstractButton::clicked, this, &CertificateManager::removeException);
46}
47
48void CertificateManager::addException()
49{
50 auto *dialog = new QDialog(this);
51 auto *layout = new QFormLayout(dialog);
52 auto *lineEdit = new QLineEdit(dialog);
53
54 auto *buttonBox = new QDialogButtonBox(dialog);
55 buttonBox->addButton(QDialogButtonBox::Ok);
56 buttonBox->addButton(QDialogButtonBox::Cancel);
57
58 connect(buttonBox, &QDialogButtonBox::rejected, dialog, &QDialog::reject);
59 connect(buttonBox, &QDialogButtonBox::accepted, dialog, &QDialog::accept);
60
61 layout->addRow(new QLabel(tr("Host: ")), lineEdit);
62 layout->addRow(buttonBox);
63 lineEdit->setFocus();
64
65 dialog->setWindowTitle(tr("Add certificate exception"));
66 dialog->setMinimumSize(400, 100);
67 dialog->setMaximumHeight(100);
68
69 if (dialog->exec()) {
70 QString host = lineEdit->text();
71 if (m_ignoredSslHosts.contains(host)) {
72 QMessageBox msgBox(this);
73 msgBox.setIcon(QMessageBox::Warning);
74 msgBox.setText(tr("Host %1 already in the list").arg(host));
75 if (msgBox.exec()) {
76 addException();
77 }
78 return;
79 }
80 if (host.isEmpty()) {
81 QMessageBox msgBox(this);
82 msgBox.setIcon(QMessageBox::Warning);
83 msgBox.setText(tr("Empty host"));
84 if (msgBox.exec()) {
85 addException();
86 }
87 return;
88 }
89
90 m_ignoredSslHosts.append(host);
91 ui->listWidget->addItem(host);
92 }
93}
94
95void CertificateManager::removeException()
96{
97 m_ignoredSslHosts.removeOne(ui->listWidget->currentItem()->text());
98 delete ui->listWidget->currentItem();
99}
100
102{
103 Settings settings;
104 settings.beginGroup(QSL("Web-Browser-Settings"));
105 settings.setValue(QSL("IgnoredSslHosts"), m_ignoredSslHosts);
106 settings.endGroup();
107
108 mApp->networkManager()->loadSettings();
109
110 QDialog::close();
111}
112
114{
115 delete ui;
116}
CertificateManager(QWidget *parent=nullptr)
void beginGroup(const QString &prefix)
Definition: settings.cpp:79
void endGroup()
Definition: settings.cpp:84
QVariant value(const QString &key, const QVariant &defaultValue=QVariant())
Definition: settings.cpp:74
void setValue(const QString &key, const QVariant &defaultValue=QVariant())
Definition: settings.cpp:69
#define mApp
#define QSL(x)
Definition: qzcommon.h:40