File indexing completed on 2025-01-26 04:52:15

0001 /* kldapclient.h - LDAP access
0002  * SPDX-FileCopyrightText: 2002 Klarälvdalens Datakonsult AB
0003  * SPDX-FileContributor: Steffen Hansen <hansen@kde.org>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.0-or-later
0006  */
0007 
0008 #pragma once
0009 
0010 #include "kldapwidgets_export.h"
0011 #include <QObject>
0012 #include <QStringList>
0013 #include <memory>
0014 
0015 namespace KLDAPCore
0016 {
0017 class LdapObject;
0018 class LdapServer;
0019 }
0020 
0021 namespace KLDAPWidgets
0022 {
0023 
0024 /**
0025  * @short An object that represents a configured LDAP server.
0026  *
0027  * This class represents a client that to an LDAP server that
0028  * can be used for LDAP lookups. Every client is identified by
0029  * a unique numeric id.
0030  *
0031  * @since 4.5
0032  */
0033 class KLDAPWIDGETS_EXPORT LdapClient : public QObject
0034 {
0035     Q_OBJECT
0036 
0037 public:
0038     /**
0039      * Creates a new ldap client.
0040      *
0041      * @param clientNumber The unique number of this client.
0042      * @param parent The parent object.
0043      */
0044     explicit LdapClient(int clientNumber, QObject *parent = nullptr);
0045 
0046     /**
0047      * Destroys the ldap client.
0048      */
0049     ~LdapClient() override;
0050 
0051     /**
0052      * Returns the number of this client.
0053      */
0054     int clientNumber() const;
0055 
0056     /**
0057      * Returns whether this client is currently running
0058      * a search query.
0059      */
0060     bool isActive() const;
0061 
0062     /**
0063      * Sets the completion @p weight of this client.
0064      *
0065      * This value will be used to sort the results of this
0066      * client when used for auto completion.
0067      */
0068     void setCompletionWeight(int weight);
0069 
0070     /**
0071      * Returns the completion weight of this client.
0072      */
0073     int completionWeight() const;
0074 
0075     /**
0076      * Sets the LDAP @p server information that shall be
0077      * used by this client.
0078      */
0079     void setServer(const KLDAPCore::LdapServer &server);
0080 
0081     /**
0082      * Returns the ldap server information that are used
0083      * by this client.
0084      */
0085     const KLDAPCore::LdapServer server() const;
0086 
0087     /**
0088      * Sets the LDAP @p attributes that should be returned
0089      * in the query result.
0090      *
0091      * Pass an empty list to include all available attributes.
0092      */
0093     void setAttributes(const QStringList &attributes);
0094 
0095     /**
0096      * Returns the LDAP attributes that should be returned
0097      * in the query result.
0098      */
0099     QStringList attributes() const;
0100 
0101     /**
0102      * Sets the @p scope of the LDAP query.
0103      *
0104      * Valid values are 'one' or 'sub'.
0105      */
0106     void setScope(const QString &scope);
0107 
0108     /**
0109      * Starts the query with the given @p filter.
0110      */
0111     void startQuery(const QString &filter);
0112 
0113     /**
0114      * Cancels a running query.
0115      */
0116     void cancelQuery();
0117 
0118 Q_SIGNALS:
0119     /**
0120      * This signal is emitted when the query has finished.
0121      */
0122     void done();
0123 
0124     /**
0125      * This signal is emitted in case of an error.
0126      *
0127      * @param message A message that describes the error.
0128      */
0129     void error(const QString &message);
0130 
0131     /**
0132      * This signal is emitted once for each object that is
0133      * returned from the query
0134      */
0135     void result(const KLDAPWidgets::LdapClient &client, const KLDAPCore::LdapObject &);
0136 
0137 private:
0138     //@cond PRIVATE
0139     class LdapClientPrivate;
0140     std::unique_ptr<LdapClientPrivate> const d;
0141     //@endcond
0142 };
0143 }