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

0001 /*
0002     This file is part of the KDE project.
0003 
0004     SPDX-FileCopyrightText: 2020 Stefano Crocco <posta@stefanocrocco.it>
0005 
0006     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0007 */
0008 
0009 #ifndef WEBENGINECUSTOMIZECACHEABLEFIELDSDLG_H
0010 #define WEBENGINECUSTOMIZECACHEABLEFIELDSDLG_H
0011 
0012 #include <QDialog>
0013 
0014 #include "webenginewallet.h"
0015 
0016 class WebFieldsDataModel;
0017 
0018 namespace Ui {
0019     class WebEngineCustomizeCacheableFieldsDlg;
0020 };
0021 
0022 /**
0023  * @brief Dialog where the user can choose which fields in a web page should be saved in KWallet
0024  *
0025  * The most important part of the dialog is a table which displays information about the fields in the page. Each field has a check box which the user
0026  * can use to select which fields should be cached. The list of fields chosen by the user can be obtained using selectedFields().
0027  *
0028  * The dialog also contains three check box:
0029  * - a check box to toggle displaying details about each field
0030  * - a check box to toggle showing or hiding passwords
0031  * - a check box to request caching fields contents immediately after the dialog has been closed. This choice can be obtained using immediatelyCacheData().
0032  */
0033 class WebEngineCustomizeCacheableFieldsDlg : public QDialog
0034 {
0035     Q_OBJECT
0036 
0037 public:
0038 
0039     typedef QMap<QString, QStringList> OldCustomizationData;
0040     /**
0041      * @brief Constructor
0042      *
0043      * @param forms a list of all the forms in the page
0044      * @param oldCustomization the previous custom configuration. Each key of the map must be the name of one form and the corresponding value must be a list of
0045      * the chosen fields in that form. This is used to decide which fields should be initially checked. If the map is empty, the initially selected fields will be decided automatically
0046      * @param parent the parent widget
0047      */
0048     WebEngineCustomizeCacheableFieldsDlg(const WebEngineWallet::WebFormList &forms, const OldCustomizationData &oldCustomization,  QWidget* parent = nullptr);
0049 
0050     /**
0051      * @brief Destructor
0052      */
0053     ~WebEngineCustomizeCacheableFieldsDlg() override{}
0054 
0055     /**
0056      * @brief The list of fields chosen by the user
0057      *
0058      * @return a list of the fields the user has checked
0059      */
0060     WebEngineWallet::WebFormList selectedFields() const;
0061 
0062     /**
0063      * @brief Whether the user has requested to immediately save the contents of the selected field
0064      *
0065      * If this is @b true, it means that the user has checked the check box asking to cache the fields contents as soon as the dialog is closed.
0066      * The code which created the dialog should take care to do so.
0067      * @return Whether fields contents should be cached immediately or not
0068      */
0069     bool immediatelyCacheData() const;
0070 
0071 private:
0072 
0073     void addChecksToPreviouslyChosenItems(const WebEngineWallet::WebFormList &forms, const OldCustomizationData &data);
0074 
0075     ///@brief The model used by the table
0076     WebFieldsDataModel *m_model;
0077 
0078     ///@brief The ui object
0079     Ui::WebEngineCustomizeCacheableFieldsDlg *m_ui;
0080 };
0081 
0082 #endif // WEBENGINECUSTOMFORMFIELDSWALLETDLG_H