File indexing completed on 2024-05-19 05:01:22

0001 /*
0002  * This file is part of the KDE project.
0003  *
0004  * Copyright 2021  Stefano Crocco <posta@stefanocrocco.it>
0005  *
0006  * This program is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU General Public License as
0008  * published by the Free Software Foundation; either version 2 of
0009  * the License or (at your option) version 3 or any later version
0010  * accepted by the membership of KDE e.V. (or its successor approved
0011  * by the membership of KDE e.V.), which shall act as a proxy
0012  * defined in Section 14 of version 3 of the license.
0013  *
0014  * This program is distributed in the hope that it will be useful,
0015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017  * GNU General Public License for more details.
0018  *
0019  * You should have received a copy of the GNU General Public License
0020  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021  */
0022 
0023 #ifndef WEBENGINEPARTCERTIFICATEERRORDLG_H
0024 #define WEBENGINEPARTCERTIFICATEERRORDLG_H
0025 
0026 #include "webenginepage.h"
0027 
0028 #include <QDialog>
0029 #include <QWebEngineCertificateError>
0030 
0031 class QAbstractButton;
0032 
0033 namespace Ui
0034 {
0035 class WebEnginePartCertificateErrorDlg;
0036 }
0037 
0038 namespace KonqWebEnginePart {
0039 
0040     /**
0041     * @brief Dialog which asks the user whether to ignore a SSL certificate error or not.
0042     *
0043     * The user can choose to ignore the error only once, forever or to not ignore it
0044     */
0045     class WebEnginePartCertificateErrorDlg : public QDialog
0046     {
0047         Q_OBJECT
0048 
0049     public:
0050 
0051         /**
0052         * @brief Constructor
0053         * @param error the certificate error the dialog is about
0054         * @param parent the parent widget
0055         */
0056         WebEnginePartCertificateErrorDlg(const QWebEngineCertificateError& error, WebEnginePage* page, QWidget* parent);
0057 
0058         /**
0059         * @brief Destructor
0060         */
0061         ~WebEnginePartCertificateErrorDlg();
0062 
0063         /**
0064         * @brief Enum which describes the possible user choices
0065         */
0066         enum class UserChoice{DontIgnoreError, IgnoreErrorOnce, IgnoreErrorForever};
0067 
0068         /**
0069         * @brief The choice made by the user
0070         * @return the choice made by the user
0071         * @warning This method should only be called *after* the user closed the dialog
0072         * using one of the three buttons. In all other situations, the returned value is
0073         * undefined.
0074         */
0075         UserChoice userChoice() const;
0076 
0077         /**
0078         * @return The certificate error the dialog is about
0079         */
0080         QWebEngineCertificateError certificateError() const;
0081 
0082     private slots:
0083         /**
0084         * @brief Displays information about a certificate in the certificate chain
0085         * @param idx the index of the certificate in the certificate chain
0086         */
0087         void displayCertificate(int idx);
0088 
0089 
0090         /**
0091         * @brief Sets the variable containing the user's choice when he presses one of the dialog buttons
0092         *
0093         * @param btn the button pressed by the user
0094         */
0095         void updateUserChoice(QAbstractButton *btn);
0096 
0097     private:
0098 
0099         /**
0100         * @brief The Ui object
0101         */
0102         Ui::WebEnginePartCertificateErrorDlg *m_ui;
0103 
0104         /**
0105         * @brief The error the dialog is about
0106         */
0107         QWebEngineCertificateError m_error;
0108 
0109         /**
0110         * @brief The choice made by the user
0111         *
0112         * @warning The value contained in this variable is undefined until the user closed the dialog
0113         * using one of the three buttons
0114         */
0115         UserChoice m_choice;
0116     };
0117 }
0118 
0119 #endif // WEBENGINEPARTCERTIFICATEERRORDLG_H