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>
34 #include <QStringList>
44 * This class is internal. Binary compatibility might be broken any time
45 * without notification. Do not use it.
50 class KDEPIM_EXPORT LdapClient
: public QObject
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
; }
74 /*! Emitted when the query is done */
77 /*! Emitted in case of error */
78 void error( const QString
& );
80 /*! Emitted once for each object returned
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
; }
95 * Start the query with filter filter
97 void startQuery( const QString
& filter
);
100 * Abort a running query
105 void slotData( KIO::Job
*, const QByteArray
&data
);
106 void slotInfoMessage( KJob
*, const QString
&info
, const QString
& );
110 void startParseLDIF();
111 void parseLDIF( const QByteArray
& data
);
113 void finishCurrentObject();
115 KLDAP::LdapServer mServer
;
119 QPointer
<KIO::SimpleJob
> mJob
;
122 KLDAP::LdapObject mCurrentObject
;
127 int mCompletionWeight
;
129 // class LdapClientPrivate;
130 // LdapClientPrivate* d;
134 * Structure describing one result returned by a LDAP query
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.
152 class KDEPIM_EXPORT LdapSearch
: public QObject
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
);
165 bool isAvailable() const;
167 QList
< LdapClient
* > clients() const { return mClients
; }
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
& );
179 void slotLDAPResult( const KPIM::LdapClient
& client
, const KLDAP::LdapObject
& );
180 void slotLDAPError( const QString
& );
182 void slotDataTimer();
183 void slotFileChanged( const QString
& );
187 struct ResultObject
{
188 const LdapClient
*client
;
189 KLDAP::LdapObject object
;
194 void makeSearchData( QStringList
& ret
, LdapResultList
& resList
);
195 QList
< LdapClient
* > mClients
;
200 QList
< ResultObject
> mResults
;
204 static KConfig
*s_config
;
205 class LdapSearchPrivate
* d
;
209 #endif // KPIM_LDAPCLIENT_H