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 0012 #include <KLDAPCore/LdapObject> 0013 #include <QObject> 0014 #include <QStringList> 0015 0016 namespace KLDAPWidgets 0017 { 0018 class LdapClient; 0019 0020 /** 0021 * Describes the result returned by an LdapClientSearch query. 0022 * 0023 * @since 4.14 0024 */ 0025 struct LdapResultObject { 0026 using List = QList<LdapResultObject>; 0027 const LdapClient *client = nullptr; 0028 KLDAPCore::LdapObject object; 0029 }; 0030 0031 /** 0032 * Describes the result returned by an LdapClientSearch query. 0033 * 0034 * @since 4.5 0035 */ 0036 struct LdapResult { 0037 /** 0038 * A list of LdapResult objects. 0039 */ 0040 using List = QList<LdapResult>; 0041 0042 KLDAPCore::LdapDN dn; 0043 QString name; ///< The full name of the contact. 0044 QStringList email; ///< The list of emails of the contact. 0045 int clientNumber; ///< The client the contact comes from (used for sorting in a ldap-only lookup). 0046 int completionWeight; ///< The weight of the contact (used for sorting in a completion list). 0047 }; 0048 0049 /** 0050 * @since 4.5 0051 */ 0052 class KLDAPWIDGETS_EXPORT LdapClientSearch : public QObject 0053 { 0054 Q_OBJECT 0055 0056 public: 0057 /** 0058 * Creates a new ldap client search object. 0059 * 0060 * @param parent The parent object. 0061 */ 0062 explicit LdapClientSearch(QObject *parent = nullptr); 0063 0064 /** 0065 * Creates a new ldap client search object. 0066 * 0067 * @param attr The attributes. 0068 * @param parent The parent object. 0069 */ 0070 explicit LdapClientSearch(const QStringList &attr, QObject *parent = nullptr); 0071 0072 /** 0073 * Destroys the ldap client search object. 0074 */ 0075 ~LdapClientSearch() override; 0076 0077 /** 0078 * Starts the LDAP search on all configured LDAP clients with the given search @p query. 0079 */ 0080 void startSearch(const QString &query); 0081 0082 /** 0083 * Cancels the currently running search query. 0084 */ 0085 void cancelSearch(); 0086 0087 /** 0088 * Returns whether LDAP search is possible at all. 0089 * 0090 * @note This method can return @c false if either no LDAP is configured 0091 * or the system does not support the KIO LDAP protocol. 0092 */ 0093 bool isAvailable() const; 0094 0095 /** 0096 * Updates the completion weights for the configured LDAP clients from 0097 * the configuration file. 0098 */ 0099 void updateCompletionWeights(); 0100 0101 /** 0102 * Returns the list of configured LDAP clients. 0103 */ 0104 QList<LdapClient *> clients() const; 0105 0106 /** 0107 * Returns the filter for the Query 0108 * 0109 * @since 4.14 0110 */ 0111 QString filter() const; 0112 0113 /** 0114 * Sets the filter for the Query 0115 * 0116 * @since 4.14 0117 */ 0118 void setFilter(const QString &); 0119 0120 /** 0121 * Returns the attributes, that are queried the LDAP Server. 0122 * 0123 * @since 4.14 0124 */ 0125 QStringList attributes() const; 0126 0127 /** 0128 * Sets the attributes, that are queried the LDAP Server. 0129 * 0130 * @since 4.14 0131 */ 0132 void setAttributes(const QStringList &); 0133 0134 [[nodiscard]] static QStringList defaultAttributes(); 0135 0136 Q_SIGNALS: 0137 /** 0138 * This signal is emitted whenever new contacts have been found 0139 * during the lookup. 0140 * 0141 * @param results The contacts in the form "Full Name <email>" 0142 */ 0143 void searchData(const QStringList &results); 0144 0145 /** 0146 * This signal is emitted whenever new contacts have been found 0147 * during the lookup. 0148 * 0149 * @param results The list of found contacts. 0150 */ 0151 void searchData(const KLDAPWidgets::LdapResult::List &results); 0152 0153 /** 0154 * This signal is emitted whenever new contacts have been found 0155 * during the lookup. 0156 * 0157 * @param results The list of found contacts. 0158 */ 0159 void searchData(const KLDAPWidgets::LdapResultObject::List &results); 0160 0161 /** 0162 * This signal is emitted whenever the lookup is complete or the 0163 * user has canceled the query. 0164 */ 0165 void searchDone(); 0166 0167 private: 0168 //@cond PRIVATE 0169 class LdapClientSearchPrivate; 0170 std::unique_ptr<LdapClientSearchPrivate> const d; 0171 //@endcond 0172 }; 0173 } 0174 Q_DECLARE_TYPEINFO(KLDAPWidgets::LdapResult, Q_RELOCATABLE_TYPE); 0175 Q_DECLARE_TYPEINFO(KLDAPWidgets::LdapResultObject, Q_RELOCATABLE_TYPE);