cosmetic fixes to make it validate more, kmcomposerui.rc and karmui.rc still do not...
[kdepim.git] / libkdepim / ldapclient.h
blobe420e284609ecde7d1a75f87425a9a62fd39ceca
1 /* kldapclient.h - LDAP access
2 * Copyright (C) 2002 Klarälvdalens Datakonsult AB
4 * Author: Steffen Hansen <hansen@kde.org>
6 * This file is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This file is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 #ifndef KDEPIM_LDAPCLIENT_H
22 #define KDEPIM_LDAPCLIENT_H
24 #include "kdepim_export.h"
26 #include <kldap/ldif.h>
27 #include <kldap/ldapobject.h>
28 #include <kldap/ldapserver.h>
30 #include <kio/job.h>
32 #include <QObject>
33 #include <QString>
34 #include <QStringList>
35 #include <QPointer>
36 #include <QTimer>
38 class KConfig;
39 class KConfigGroup;
41 namespace KPIM {
43 /**
44 * This class is internal. Binary compatibility might be broken any time
45 * without notification. Do not use it.
47 * We mean it!
50 class KDEPIM_EXPORT LdapClient : public QObject
52 Q_OBJECT
54 public:
55 explicit LdapClient( int clientNumber, QObject* parent = 0, const char* name = 0 );
56 virtual ~LdapClient();
58 /*! returns true if there is a query running */
59 bool isActive() const { return mActive; }
61 int clientNumber() const;
62 int completionWeight() const;
63 void setCompletionWeight( int );
65 const KLDAP::LdapServer& server() const { return mServer; }
66 void setServer( const KLDAP::LdapServer &server ) { mServer = server; }
67 /*! Return the attributes that should be
68 * returned, or an empty list if
69 * all attributes are wanted
71 QStringList attrs() const { return mAttrs; }
73 Q_SIGNALS:
74 /*! Emitted when the query is done */
75 void done();
77 /*! Emitted in case of error */
78 void error( const QString& );
80 /*! Emitted once for each object returned
81 * from the query
83 void result( const KPIM::LdapClient &client, const KLDAP::LdapObject& );
85 public Q_SLOTS: // why are those slots?
86 /*! Set the attributes that should be
87 * returned, or an empty list if
88 * all attributes are wanted
90 void setAttrs( const QStringList& attrs );
92 void setScope( const QString scope ) { mScope = scope; }
94 /*!
95 * Start the query with filter filter
97 void startQuery( const QString& filter );
99 /*!
100 * Abort a running query
102 void cancelQuery();
104 protected Q_SLOTS:
105 void slotData( KIO::Job*, const QByteArray &data );
106 void slotInfoMessage( KJob*, const QString &info, const QString& );
107 void slotDone();
109 protected:
110 void startParseLDIF();
111 void parseLDIF( const QByteArray& data );
112 void endParseLDIF();
113 void finishCurrentObject();
115 KLDAP::LdapServer mServer;
116 QString mScope;
117 QStringList mAttrs;
119 QPointer<KIO::SimpleJob> mJob;
120 bool mActive;
122 KLDAP::LdapObject mCurrentObject;
124 private:
125 KLDAP::Ldif mLdif;
126 int mClientNumber;
127 int mCompletionWeight;
129 // class LdapClientPrivate;
130 // LdapClientPrivate* d;
134 * Structure describing one result returned by a LDAP query
136 struct LdapResult {
137 QString name; ///< full name
138 QStringList email; ///< emails
139 int clientNumber; ///< for sorting in a ldap-only lookup
140 int completionWeight; ///< for sorting in a completion list
142 typedef QList<LdapResult> LdapResultList;
146 * This class is internal. Binary compatibiliy might be broken any time
147 * without notification. Do not use it.
149 * We mean it!
152 class KDEPIM_EXPORT LdapSearch : public QObject
154 Q_OBJECT
156 public:
157 LdapSearch();
159 static KConfig *config();
160 static void readConfig( KLDAP::LdapServer &server, const KConfigGroup &config, int num, bool active );
161 static void writeConfig( const KLDAP::LdapServer &server, KConfigGroup &config, int j, bool active );
163 void startSearch( const QString& txt );
164 void cancelSearch();
165 bool isAvailable() const;
167 QList< LdapClient* > clients() const { return mClients; }
169 Q_SIGNALS:
170 /// Results, assembled as "Full Name <email>"
171 /// (This signal can be emitted many times)
172 void searchData( const QStringList& );
173 /// Another form for the results, with separate fields
174 /// (This signal can be emitted many times)
175 void searchData( const KPIM::LdapResultList& );
176 void searchDone();
178 private Q_SLOTS:
179 void slotLDAPResult( const KPIM::LdapClient& client, const KLDAP::LdapObject& );
180 void slotLDAPError( const QString& );
181 void slotLDAPDone();
182 void slotDataTimer();
183 void slotFileChanged( const QString& );
185 private:
187 struct ResultObject {
188 const LdapClient *client;
189 KLDAP::LdapObject object;
192 void readConfig();
193 void finish();
194 void makeSearchData( QStringList& ret, LdapResultList& resList );
195 QList< LdapClient* > mClients;
196 QString mSearchText;
197 QTimer mDataTimer;
198 int mActiveClients;
199 bool mNoLDAPLookup;
200 QList< ResultObject > mResults;
201 QString mConfigFile;
203 private:
204 static KConfig *s_config;
205 class LdapSearchPrivate* d;
209 #endif // KPIM_LDAPCLIENT_H