mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-13 10:32:11 +01:00
Implement a GUI for managing ignored SSL hosts
This commit is contained in:
parent
70b8544f9b
commit
c440437261
116
src/lib/preferences/certificatemanager.cpp
Normal file
116
src/lib/preferences/certificatemanager.cpp
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
/* ============================================================
|
||||||
|
* Falkon - Qt web browser
|
||||||
|
* Copyright (C) 2023 Javier Llorente <javier@opensuse.org>
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* ============================================================ */
|
||||||
|
#include "certificatemanager.h"
|
||||||
|
#include "ui_certificatemanager.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
|
#include "networkmanager.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
|
#include <QFormLayout>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
CertificateManager::CertificateManager(QWidget* parent)
|
||||||
|
: QDialog(parent)
|
||||||
|
, ui(new Ui::CertificateManager)
|
||||||
|
{
|
||||||
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
|
ui->setupUi(this);
|
||||||
|
ui->listWidget->setLayoutDirection(Qt::LeftToRight);
|
||||||
|
|
||||||
|
Settings settings;
|
||||||
|
settings.beginGroup("Web-Browser-Settings");
|
||||||
|
m_ignoredSslHosts = settings.value("IgnoredSslHosts", QStringList()).toStringList();
|
||||||
|
settings.endGroup();
|
||||||
|
ui->listWidget->addItems(m_ignoredSslHosts);
|
||||||
|
|
||||||
|
connect(ui->add, &QAbstractButton::clicked, this, &CertificateManager::addException);
|
||||||
|
connect(ui->remove, &QAbstractButton::clicked, this, &CertificateManager::removeException);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CertificateManager::addException()
|
||||||
|
{
|
||||||
|
auto *dialog = new QDialog(this);
|
||||||
|
auto *layout = new QFormLayout(dialog);
|
||||||
|
auto *lineEdit = new QLineEdit(dialog);
|
||||||
|
|
||||||
|
auto *buttonBox = new QDialogButtonBox(dialog);
|
||||||
|
buttonBox->addButton(QDialogButtonBox::Ok);
|
||||||
|
buttonBox->addButton(QDialogButtonBox::Cancel);
|
||||||
|
|
||||||
|
connect(buttonBox, &QDialogButtonBox::rejected, dialog, &QDialog::reject);
|
||||||
|
connect(buttonBox, &QDialogButtonBox::accepted, dialog, &QDialog::accept);
|
||||||
|
|
||||||
|
layout->addRow(new QLabel(tr("Host: ")), lineEdit);
|
||||||
|
layout->addRow(buttonBox);
|
||||||
|
lineEdit->setFocus();
|
||||||
|
|
||||||
|
dialog->setWindowTitle(tr("Add certificate exception"));
|
||||||
|
dialog->setMinimumSize(400, 100);
|
||||||
|
dialog->setMaximumHeight(100);
|
||||||
|
|
||||||
|
if (dialog->exec()) {
|
||||||
|
QString host = lineEdit->text();
|
||||||
|
if (m_ignoredSslHosts.contains(host)) {
|
||||||
|
QMessageBox msgBox(this);
|
||||||
|
msgBox.setIcon(QMessageBox::Warning);
|
||||||
|
msgBox.setText(tr("Host %1 already in the list").arg(host));
|
||||||
|
if (msgBox.exec()) {
|
||||||
|
addException();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (host.isEmpty()) {
|
||||||
|
QMessageBox msgBox(this);
|
||||||
|
msgBox.setIcon(QMessageBox::Warning);
|
||||||
|
msgBox.setText(tr("Empty host"));
|
||||||
|
if (msgBox.exec()) {
|
||||||
|
addException();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_ignoredSslHosts.append(host);
|
||||||
|
ui->listWidget->addItem(host);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CertificateManager::removeException()
|
||||||
|
{
|
||||||
|
m_ignoredSslHosts.removeOne(ui->listWidget->currentItem()->text());
|
||||||
|
delete ui->listWidget->currentItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CertificateManager::accept()
|
||||||
|
{
|
||||||
|
Settings settings;
|
||||||
|
settings.beginGroup("Web-Browser-Settings");
|
||||||
|
settings.setValue("IgnoredSslHosts", m_ignoredSslHosts);
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
mApp->networkManager()->loadSettings();
|
||||||
|
|
||||||
|
QDialog::close();
|
||||||
|
}
|
||||||
|
|
||||||
|
CertificateManager::~CertificateManager()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
50
src/lib/preferences/certificatemanager.h
Normal file
50
src/lib/preferences/certificatemanager.h
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/* ============================================================
|
||||||
|
* Falkon - Qt web browser
|
||||||
|
* Copyright (C) 2023 Javier Llorente <javier@opensuse.org>
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* ============================================================ */
|
||||||
|
#ifndef CERTIFICATEMANAGER_H
|
||||||
|
#define CERTIFICATEMANAGER_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
#include "qzcommon.h"
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class CertificateManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
class FALKON_EXPORT CertificateManager : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit CertificateManager(QWidget* parent = nullptr);
|
||||||
|
~CertificateManager() override;
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void accept() override;
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void addException();
|
||||||
|
void removeException();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::CertificateManager* ui;
|
||||||
|
QStringList m_ignoredSslHosts;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CERTIFICATEMANAGER_H
|
98
src/lib/preferences/certificatemanager.ui
Normal file
98
src/lib/preferences/certificatemanager.ui
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>CertificateManager</class>
|
||||||
|
<widget class="QDialog" name="CertificateManager">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>415</width>
|
||||||
|
<height>225</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Certificate manager</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QListWidget" name="listWidget"/>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="add">
|
||||||
|
<property name="text">
|
||||||
|
<string>Add</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="remove">
|
||||||
|
<property name="text">
|
||||||
|
<string>Remove</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" colspan="2">
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>CertificateManager</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>CertificateManager</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
Loading…
Reference in New Issue
Block a user