7#include "addresseelineeditldap.h"
8#include "addresseelineeditmanager.h"
9#include <KLDAPCore/LdapActivitiesAbstract>
10#include <KLDAPCore/LdapClient>
11#include <KLDAPCore/LdapClientSearch>
12#include <KLDAPCore/LdapServer>
13#include <KLocalizedString>
17using namespace std::chrono_literals;
20AddresseeLineEditLdap::AddresseeLineEditLdap(AddresseeLineEditManager *addressLineStatic,
QObject *parent)
22 , mAddressLineStatic(addressLineStatic)
26AddresseeLineEditLdap::~AddresseeLineEditLdap() =
default;
30 if (mLdapActivities != ldapActivities) {
31 mLdapActivities = ldapActivities;
32 connect(mLdapActivities, &KLDAPCore::LdapActivitiesAbstract::activitiesChanged,
this, &AddresseeLineEditLdap::updateLDAPWeights);
37void AddresseeLineEditLdap::updateLDAPWeights()
41 mLdapSearch->updateCompletionWeights();
43 const QList<KLDAPCore::LdapClient *> lstClients = mLdapSearch->clients();
44 for (
const KLDAPCore::LdapClient *client : lstClients) {
45 if (mLdapActivities) {
46 if (mLdapActivities->hasActivitySupport()) {
47 if (client->server().enablePlasmaActivities() && !client->server().activities().contains(mLdapActivities->currentActivity())) {
52 const int sourceIndex = mAddressLineStatic->addCompletionSource(
i18n(
"LDAP server: %1", client->server().host()), client->completionWeight());
53 mLdapClientToCompletionSourceMap.insert(clientIndex, sourceIndex);
58QMap<int, int> AddresseeLineEditLdap::ldapClientToCompletionSourceMap()
const
60 return mLdapClientToCompletionSourceMap;
63int AddresseeLineEditLdap::ldapClientToCompletionSourceValue(
int value)
const
65 return mLdapClientToCompletionSourceMap[value];
68bool AddresseeLineEditLdap::isLdapClientToCompletionSourceMapContains(
int value)
const
70 return mLdapClientToCompletionSourceMap.contains(value);
73KLDAPCore::LdapClientSearch *AddresseeLineEditLdap::ldapSearch()
const
78void AddresseeLineEditLdap::init()
81 mLdapTimer =
new QTimer(
this);
82 mLdapSearch =
new KLDAPCore::LdapClientSearch(
this);
93 mLdapSearch->setFilter(QStringLiteral(
"&(|(objectclass=person)(objectclass=groupOfNames)(mail=*))"
94 "(|(cn=%1*)(mail=%1*)(mail=*@%1*)(givenName=%1*)(sn=%1*))"));
97 mLdapSearch->setFilter(
98 QStringLiteral(
"&(|(objectclass=person)(objectclass=groupOfNames)(mail=*))"
99 "(|(cn=%1*)(mail=%1*)(givenName=%1*)(sn=%1*))"));
103QTimer *AddresseeLineEditLdap::ldapTimer()
const
108QString AddresseeLineEditLdap::ldapText()
const
113void AddresseeLineEditLdap::setLdapText(
const QString &ldapText)
115 mLdapText = ldapText;
118AddresseeLineEdit *AddresseeLineEditLdap::addressLineEdit()
const
120 return mAddressLineEdit;
123void AddresseeLineEditLdap::setAddressLineEdit(AddresseeLineEdit *addressLineEdit)
125 mAddressLineEdit = addressLineEdit;
128void AddresseeLineEditLdap::startLoadingLDAPEntries()
130 QString text(mLdapText);
132 const int index = text.lastIndexOf(QLatin1Char(
','));
134 text = text.mid(index + 1, 255).trimmed();
137 if (text.isEmpty()) {
141 mLdapSearch->startSearch(text);
144void AddresseeLineEditLdap::restartLdap(
const QString &searchString, AddresseeLineEdit *addressLine)
147 if (mLdapText != searchString || mAddressLineEdit != addressLine) {
151 mLdapText = searchString;
152 mAddressLineEdit = addressLine;
153 mLdapTimer->setSingleShot(
true);
154 mLdapTimer->start(500ms);
158void AddresseeLineEditLdap::stopLDAPLookup()
161 mLdapSearch->cancelSearch();
162 setAddressLineEdit(
nullptr);
QString i18n(const char *text, const TYPE &arg...)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)