Commit 714842bf authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add new api for avoiding to call twice readConfig when we change

attribute when we create a new ldapclientsearch
parent 5276ae61
Pipeline #42967 passed with stage
in 9 minutes and 4 seconds
cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.16.42")
set(PIM_VERSION "5.16.43")
project(KLdap VERSION ${PIM_VERSION})
......
......@@ -55,6 +55,7 @@ public:
void slotLDAPDone();
void slotDataTimer();
void slotFileChanged(const QString &);
void init(const QStringList &attributes);
LdapClientSearch *const q;
QList<LdapClient *> mClients;
......@@ -71,36 +72,49 @@ public:
LdapClientSearch::LdapClientSearch(QObject *parent)
: QObject(parent)
, d(new Private(this))
{
const QStringList attr{ QStringLiteral("cn")
, QStringLiteral("mail")
, QStringLiteral("givenname")
, QStringLiteral("sn")};
d->init(attr);
}
LdapClientSearch::LdapClientSearch(const QStringList &attr, QObject *parent)
: QObject(parent)
, d(new Private(this))
{
d->init(attr);
}
LdapClientSearch::~LdapClientSearch()
{
delete d;
}
void LdapClientSearch::Private::init(const QStringList &attributes)
{
Kdelibs4ConfigMigrator migrate(QStringLiteral("ldapsettings"));
migrate.setConfigFiles(QStringList() << QStringLiteral("kabldaprc"));
migrate.migrate();
if (!KProtocolInfo::isKnownProtocol(QUrl(QStringLiteral("ldap://localhost")))) {
d->mNoLDAPLookup = true;
mNoLDAPLookup = true;
return;
}
d->mAttributes << QStringLiteral("cn")
<< QStringLiteral("mail")
<< QStringLiteral("givenname")
<< QStringLiteral("sn");
mAttributes = attributes;
// Set the filter, to make sure old usage (before 4.14) of this object still works.
d->mFilter = QStringLiteral("&(|(objectclass=person)(objectclass=groupOfNames)(mail=*))"
mFilter = QStringLiteral("&(|(objectclass=person)(objectclass=groupOfNames)(mail=*))"
"(|(cn=%1*)(mail=%1*)(givenName=%1*)(sn=%1*))");
d->readConfig();
connect(KDirWatch::self(), &KDirWatch::dirty, this, [this](const QString &filename) {
d->slotFileChanged(filename);
readConfig();
q->connect(KDirWatch::self(), &KDirWatch::dirty, q, [this](const QString &filename) {
slotFileChanged(filename);
});
}
LdapClientSearch::~LdapClientSearch()
{
delete d;
}
void LdapClientSearch::Private::readWeighForClient(LdapClient *client, const KConfigGroup &config, int clientNumber)
{
const int completionWeight = config.readEntry(QStringLiteral("SelectedCompletionWeight%1").arg(clientNumber), -1);
......
......@@ -61,10 +61,18 @@ public:
*/
explicit LdapClientSearch(QObject *parent = nullptr);
/**
* Creates a new ldap client search object.
*
* @param attr The attributes.
* @param parent The parent object.
*/
explicit LdapClientSearch(const QStringList &attr, QObject *parent = nullptr);
/**
* Destroys the ldap client search object.
*/
~LdapClientSearch();
~LdapClientSearch() override;
/**
* Starts the LDAP search on all configured LDAP clients with the given search @p query.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment