File indexing completed on 2024-05-05 05:00:07

0001 /*
0002     SPDX-FileCopyrightText: 2002 Leo Savernik <l.savernik@aon.at>
0003     Derived from jsopts.h and javaopts.h, code copied from there is
0004     copyrighted to its respective owners.
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef DOMAINLISTVIEW_H
0010 #define DOMAINLISTVIEW_H
0011 
0012 #include <QGroupBox>
0013 #include <QMap>
0014 
0015 #include <kconfig.h>
0016 #include <ksharedconfig.h>
0017 
0018 class QTreeWidgetItem;
0019 class QPushButton;
0020 
0021 class QTreeWidget;
0022 
0023 class Policies;
0024 class PolicyDialog;
0025 
0026 /**
0027  * @short Provides a list view of domains which policies are attached to.
0028  *
0029  * This class resembles a list view of domain names and some buttons to
0030  * manipulate it. You should use this widget if you need to manage domains
0031  * whose policies are described by (derivatives of) Policies objects.
0032  *
0033  * The contained widgets can be accessed by respective getters for
0034  * fine-tuning/customizing them afterwards.
0035  *
0036  * To use this class you have to derive your own and implement most
0037  * (all) of the protected methods. You need these to customize this widget
0038  * for its special purpose.
0039  *
0040  * @author Leo Savernik
0041  */
0042 class DomainListView : public QGroupBox
0043 {
0044     Q_OBJECT
0045 public:
0046     /** Enumerates the available buttons.
0047       */
0048     enum PushButton {
0049         AddButton, ChangeButton, DeleteButton, ImportButton, ExportButton
0050     };
0051 
0052     /**
0053      * constructor
0054      * @param config configuration to read from and to write to
0055      * @param title title to be used for enclosing group box
0056      * @param parent parent widget
0057      * @param name internal name for debugging
0058      */
0059     DomainListView(KSharedConfig::Ptr config, const QString &title, QWidget *parent);
0060 
0061     ~DomainListView() override;
0062 
0063     /**
0064      * clears the list view.
0065      */
0066 //  void clear();
0067 
0068     /**
0069      * returns the list view displaying the domains
0070      */
0071     QTreeWidget *listView() const
0072     {
0073         return domainSpecificLV;
0074     }
0075 
0076     /**
0077      * returns the add push-button.
0078      *
0079      * Note: The add button already contains a default "what's this" text.
0080      */
0081     QPushButton *addButton() const
0082     {
0083         return addDomainPB;
0084     }
0085 
0086     /**
0087      * returns the change push-button.
0088      *
0089      * Note: The change button already contains a default "what's this" text.
0090      */
0091     QPushButton *changeButton() const
0092     {
0093         return changeDomainPB;
0094     }
0095 
0096     /**
0097      * returns the delete push-button.
0098      *
0099      * Note: The delete button already contains a default "what's this" text.
0100      */
0101     QPushButton *deleteButton() const
0102     {
0103         return deleteDomainPB;
0104     }
0105 
0106     /**
0107      * returns the import push-button.
0108      */
0109     QPushButton *importButton() const
0110     {
0111         return importDomainPB;
0112     }
0113 
0114     /**
0115      * returns the export push-button.
0116      */
0117     QPushButton *exportButton() const
0118     {
0119         return exportDomainPB;
0120     }
0121 
0122     /**
0123      * Initializes the list view with the given list of domains as well
0124      * as the domain policy map.
0125      *
0126      * This method may be called multiple times on a DomainListView instance.
0127      *
0128      * @param domainList given list of domains
0129      */
0130     void initialize(const QStringList &domainList);
0131 
0132     /**
0133      * saves the current state of all domains to the configuration object.
0134      * @param group the group the information is to be saved under
0135      * @param domainListKey the name of the key which the list of domains
0136      *    is stored under.
0137      */
0138     void save(const QString &group, const QString &domainListKey);
0139 
0140 Q_SIGNALS:
0141     /**
0142      * indicates that a configuration has been changed within this list view.
0143      * @param state true if changed, false if not
0144      */
0145     void changed(bool state);
0146 
0147 protected:
0148     /**
0149      * factory method for creating a new domain-specific policies object.
0150      *
0151      * Example:
0152      * <pre>
0153      * JavaPolicies *JavaDomainListView::createPolicies() {
0154      *   return new JavaPolicies(m_pConfig,m_groupname,false);
0155      * }
0156      * </pre>
0157      */
0158     virtual Policies *createPolicies() = 0;
0159 
0160     /**
0161      * factory method for copying a policies object.
0162      *
0163      * Derived classes must interpret the given object as the same type
0164      * as those created by createPolicies and return a copy of this very type.
0165      *
0166      * Example:
0167      * <pre>
0168      * JavaPolicies *JavaDomainListView::copyPolicies(Policies *pol) {
0169      *   return new JavaPolicies(*static_cast<JavaPolicies *>(pol));
0170      * }
0171      * </pre>
0172      * @param pol policies object to be copied
0173      */
0174     virtual Policies *copyPolicies(Policies *pol) = 0;
0175 
0176     /**
0177      * allows derived classes to customize the policy dialog.
0178      *
0179      * The default implementation does nothing.
0180      * @param trigger triggered by which button
0181      * @param pDlg reference to policy dialog
0182      * @param copy policies object this dialog is used for changing. Derived
0183      *    classes can safely cast the @p copy object to the same type they
0184      *    returned in their createPolicies implementation.
0185      */
0186     virtual void setupPolicyDlg(PushButton trigger, PolicyDialog &pDlg,
0187                                 Policies *copy);
0188 
0189 private Q_SLOTS:
0190     void addPressed();
0191     void changePressed();
0192     void deletePressed();
0193     void importPressed();
0194     void exportPressed();
0195     void updateButton();
0196 
0197 protected:
0198 
0199     KSharedConfig::Ptr config;
0200 
0201     QTreeWidget *domainSpecificLV;
0202 
0203     QPushButton *addDomainPB;
0204     QPushButton *changeDomainPB;
0205     QPushButton *deleteDomainPB;
0206     QPushButton *importDomainPB;
0207     QPushButton *exportDomainPB;
0208 
0209     typedef QMap<QTreeWidgetItem *, Policies *> DomainPolicyMap;
0210     DomainPolicyMap domainPolicies;
0211 };
0212 
0213 #endif      // DOMAINLISTVIEW_H
0214