File indexing completed on 2024-04-28 05:11:37

0001 /*
0002  * SPDX-FileCopyrightText: 2014 Sandro Knauß <knauss@kolabsys.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  *
0006  */
0007 
0008 #pragma once
0009 
0010 #include <KLDAPWidgets/LdapClient>
0011 
0012 #include <KLDAPCore/LdapObject>
0013 
0014 #include <QList>
0015 #include <QSharedPointer>
0016 #include <QStringList>
0017 #include <QVariant>
0018 
0019 namespace IncidenceEditorNG
0020 {
0021 class ResourceItem : public QObject
0022 {
0023     Q_OBJECT
0024 public:
0025     /* Copied from https://doc.qt.io/qt-5/qtwidgets-itemviews-editabletreemodel-example.html:
0026      * Editable Tree Model Example
0027      */
0028 
0029     /**
0030       A shared pointer to an ResourceItem object.
0031     */
0032     using Ptr = QSharedPointer<ResourceItem>;
0033 
0034     ResourceItem(const KLDAPCore::LdapDN &dn,
0035                  const QStringList &attrs,
0036                  const KLDAPWidgets::LdapClient &ldapClient,
0037                  const ResourceItem::Ptr &parent = ResourceItem::Ptr());
0038     ~ResourceItem() override;
0039 
0040     [[nodiscard]] ResourceItem::Ptr child(int number);
0041     [[nodiscard]] int childCount() const;
0042     [[nodiscard]] int columnCount() const;
0043     [[nodiscard]] QVariant data(int column) const;
0044     [[nodiscard]] QVariant data(const QString &column) const;
0045     [[nodiscard]] bool insertChild(int position, const ResourceItem::Ptr &item);
0046     [[nodiscard]] ResourceItem::Ptr parent();
0047     [[nodiscard]] bool removeChildren(int position, int count);
0048     [[nodiscard]] int childNumber() const;
0049 
0050 private:
0051     QList<ResourceItem::Ptr> childItems;
0052     QList<QVariant> itemData;
0053     ResourceItem::Ptr parentItem;
0054 
0055 Q_SIGNALS:
0056     void searchFinished();
0057 
0058 public:
0059     /* Returns the attributes of the requested ldapObject.
0060      *
0061      */
0062     const QStringList &attributes() const;
0063 
0064     /* Returns the ldapObject, that is used as data source.
0065      *
0066      */
0067     const KLDAPCore::LdapObject &ldapObject() const;
0068 
0069     /* Set the ldapObject, either directly via this function
0070      * or use startSearch to request the ldapServer for the ldapObject
0071      * with the dn specified via the constructor.
0072      *
0073      */
0074     void setLdapObject(const KLDAPCore::LdapObject &);
0075 
0076     /* The used ldapClient.
0077      *
0078      */
0079     const KLDAPWidgets::LdapClient &ldapClient() const;
0080 
0081     /* Start querying the ldapServer for a object that name is dn
0082      *
0083      */
0084     void startSearch();
0085 
0086 private:
0087     /* data source
0088      *
0089      */
0090     KLDAPCore::LdapObject mLdapObject;
0091 
0092     /* dn of the ldapObject
0093      *
0094      */
0095     const KLDAPCore::LdapDN dn;
0096 
0097     /* Attributes of the ldapObject to request and the header of the Item
0098      *
0099      */
0100     QStringList mAttrs;
0101 
0102     /* ldapClient to request
0103      *
0104      */
0105     KLDAPWidgets::LdapClient mLdapClient;
0106 
0107 private:
0108     /* Answer of the LdapServer for the given dn
0109      *
0110      */
0111     void slotLDAPResult(const KLDAPWidgets::LdapClient &, const KLDAPCore::LdapObject &);
0112 };
0113 }
0114 
0115 //@cond PRIVATE
0116 Q_DECLARE_TYPEINFO(IncidenceEditorNG::ResourceItem::Ptr, Q_RELOCATABLE_TYPE);
0117 Q_DECLARE_METATYPE(IncidenceEditorNG::ResourceItem::Ptr)
0118 //@endcond