File indexing completed on 2025-01-05 04:55:47

0001 /*
0002     cryptoconfigmodule_p.h
0003 
0004     This file is part of libkleopatra
0005     SPDX-FileCopyrightText: 2004, 2005 Klarälvdalens Datakonsult AB
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 
0012 #include <QList>
0013 #include <QWidget>
0014 
0015 class KLineEdit;
0016 class QSpinBox;
0017 
0018 class QPushButton;
0019 class QGridLayout;
0020 class QLabel;
0021 class QCheckBox;
0022 class QComboBox;
0023 
0024 namespace Kleo
0025 {
0026 class FileNameRequester;
0027 }
0028 
0029 namespace QGpgME
0030 {
0031 class CryptoConfig;
0032 class CryptoConfigComponent;
0033 class CryptoConfigGroup;
0034 class CryptoConfigEntry;
0035 } // namespace QGpgME
0036 
0037 namespace Kleo
0038 {
0039 class CryptoConfigModule;
0040 class CryptoConfigComponentGUI;
0041 class CryptoConfigGroupGUI;
0042 class CryptoConfigEntryGUI;
0043 
0044 /**
0045  * A widget corresponding to a component in the crypto config
0046  */
0047 class CryptoConfigComponentGUI : public QWidget
0048 {
0049     Q_OBJECT
0050 
0051 public:
0052     CryptoConfigComponentGUI(CryptoConfigModule *module, QGpgME::CryptoConfigComponent *component, QWidget *parent = nullptr);
0053 
0054     bool save();
0055     void load();
0056     void defaults();
0057 
0058 private:
0059     QGpgME::CryptoConfigComponent *mComponent = nullptr;
0060     QList<CryptoConfigGroupGUI *> mGroupGUIs;
0061 };
0062 
0063 /**
0064  * A class managing widgets corresponding to a group in the crypto config
0065  */
0066 class CryptoConfigGroupGUI : public QObject
0067 {
0068     Q_OBJECT
0069 
0070 public:
0071     CryptoConfigGroupGUI(CryptoConfigModule *module,
0072                          QGpgME::CryptoConfigGroup *group,
0073                          const std::vector<QGpgME::CryptoConfigEntry *> &entries,
0074                          QGridLayout *layout,
0075                          QWidget *parent = nullptr);
0076 
0077     bool save();
0078     void load();
0079     void defaults();
0080 
0081 private:
0082     QList<CryptoConfigEntryGUI *> mEntryGUIs;
0083 };
0084 
0085 /**
0086  * Factory for CryptoConfigEntryGUI instances
0087  * Not a real factory, but can become one later.
0088  */
0089 class CryptoConfigEntryGUIFactory
0090 {
0091 public:
0092     static CryptoConfigEntryGUI *
0093     createEntryGUI(CryptoConfigModule *module, QGpgME::CryptoConfigEntry *entry, const QString &entryName, QGridLayout *layout, QWidget *widget);
0094 };
0095 
0096 /**
0097  * Base class for the widget managers tied to an entry in the crypto config
0098  */
0099 class CryptoConfigEntryGUI : public QObject
0100 {
0101     Q_OBJECT
0102 public:
0103     CryptoConfigEntryGUI(CryptoConfigModule *module, QGpgME::CryptoConfigEntry *entry, const QString &entryName);
0104 
0105     void load()
0106     {
0107         doLoad();
0108         mChanged = false;
0109     }
0110     void save()
0111     {
0112         Q_ASSERT(mChanged);
0113         doSave();
0114         mChanged = false;
0115     }
0116     void resetToDefault();
0117 
0118     QString description() const;
0119     bool isChanged() const
0120     {
0121         return mChanged;
0122     }
0123 
0124 Q_SIGNALS:
0125     void changed();
0126 
0127 protected Q_SLOTS:
0128     void slotChanged()
0129     {
0130         mChanged = true;
0131         Q_EMIT changed();
0132     }
0133 
0134 protected:
0135     virtual void doSave() = 0;
0136     virtual void doLoad() = 0;
0137 
0138     QGpgME::CryptoConfigEntry *mEntry = nullptr;
0139     QString mName;
0140     bool mChanged = false;
0141 };
0142 
0143 /**
0144  * A widget manager for a string entry in the crypto config
0145  */
0146 class CryptoConfigEntryLineEdit : public CryptoConfigEntryGUI
0147 {
0148     Q_OBJECT
0149 
0150 public:
0151     CryptoConfigEntryLineEdit(CryptoConfigModule *module,
0152                               QGpgME::CryptoConfigEntry *entry,
0153                               const QString &entryName,
0154                               QGridLayout *layout,
0155                               QWidget *parent = nullptr);
0156 
0157     void doSave() override;
0158     void doLoad() override;
0159 
0160 private:
0161     KLineEdit *mLineEdit = nullptr;
0162 };
0163 
0164 /**
0165  * A widget manager for a debug-level entry in the crypto config
0166  */
0167 class CryptoConfigEntryDebugLevel : public CryptoConfigEntryGUI
0168 {
0169     Q_OBJECT
0170 public:
0171     CryptoConfigEntryDebugLevel(CryptoConfigModule *module,
0172                                 QGpgME::CryptoConfigEntry *entry,
0173                                 const QString &entryName,
0174                                 QGridLayout *layout,
0175                                 QWidget *parent = nullptr);
0176 
0177     void doSave() override;
0178     void doLoad() override;
0179 
0180 private:
0181     QComboBox *mComboBox = nullptr;
0182 };
0183 
0184 /**
0185  * A widget manager for a path entry in the crypto config
0186  */
0187 class CryptoConfigEntryPath : public CryptoConfigEntryGUI
0188 {
0189     Q_OBJECT
0190 
0191 public:
0192     CryptoConfigEntryPath(CryptoConfigModule *module,
0193                           QGpgME::CryptoConfigEntry *entry,
0194                           const QString &entryName,
0195                           QGridLayout *layout,
0196                           QWidget *parent = nullptr);
0197 
0198     void doSave() override;
0199     void doLoad() override;
0200 
0201 private:
0202     Kleo::FileNameRequester *mFileNameRequester = nullptr;
0203 };
0204 
0205 /**
0206  * A widget manager for a directory path entry in the crypto config
0207  */
0208 class CryptoConfigEntryDirPath : public CryptoConfigEntryGUI
0209 {
0210     Q_OBJECT
0211 
0212 public:
0213     CryptoConfigEntryDirPath(CryptoConfigModule *module,
0214                              QGpgME::CryptoConfigEntry *entry,
0215                              const QString &entryName,
0216                              QGridLayout *layout,
0217                              QWidget *parent = nullptr);
0218 
0219     void doSave() override;
0220     void doLoad() override;
0221 
0222 private:
0223     Kleo::FileNameRequester *mFileNameRequester = nullptr;
0224 };
0225 
0226 /**
0227  * A widget manager for an int/uint entry in the crypto config
0228  */
0229 class CryptoConfigEntrySpinBox : public CryptoConfigEntryGUI
0230 {
0231     Q_OBJECT
0232 
0233 public:
0234     CryptoConfigEntrySpinBox(CryptoConfigModule *module,
0235                              QGpgME::CryptoConfigEntry *entry,
0236                              const QString &entryName,
0237                              QGridLayout *layout,
0238                              QWidget *parent = nullptr);
0239     void doSave() override;
0240     void doLoad() override;
0241 
0242 private:
0243     enum { Int, UInt, ListOfNone } mKind;
0244     QSpinBox *mNumInput = nullptr;
0245 };
0246 
0247 /**
0248  * A widget manager for a bool entry in the crypto config
0249  */
0250 class CryptoConfigEntryCheckBox : public CryptoConfigEntryGUI
0251 {
0252     Q_OBJECT
0253 
0254 public:
0255     CryptoConfigEntryCheckBox(CryptoConfigModule *module,
0256                               QGpgME::CryptoConfigEntry *entry,
0257                               const QString &entryName,
0258                               QGridLayout *layout,
0259                               QWidget *parent = nullptr);
0260     void doSave() override;
0261     void doLoad() override;
0262 
0263 private:
0264     QCheckBox *mCheckBox = nullptr;
0265 };
0266 
0267 /**
0268  * A widget manager for an LDAP list entry in the crypto config
0269  */
0270 class CryptoConfigEntryLDAPURL : public CryptoConfigEntryGUI
0271 {
0272     Q_OBJECT
0273 
0274 public:
0275     CryptoConfigEntryLDAPURL(CryptoConfigModule *module,
0276                              QGpgME::CryptoConfigEntry *entry,
0277                              const QString &entryName,
0278                              QGridLayout *layout,
0279                              QWidget *parent = nullptr);
0280     void doSave() override;
0281     void doLoad() override;
0282 private Q_SLOTS:
0283     void slotOpenDialog();
0284 
0285 private:
0286     void setURLList(const QList<QUrl> &urlList);
0287     QLabel *mLabel = nullptr;
0288     QPushButton *mPushButton = nullptr;
0289     QList<QUrl> mURLList;
0290 };
0291 
0292 }