7#include "ldapclientsearchconfigwriteconfigjob.h"
8#include "ldap_core_debug.h"
10#include "kldapcore/ldapdn.h"
11#include <qt6keychain/keychain.h>
12using namespace QKeychain;
14using namespace KLDAPCore;
15LdapClientSearchConfigWriteConfigJob::LdapClientSearchConfigWriteConfigJob(
QObject *parent)
20LdapClientSearchConfigWriteConfigJob::~LdapClientSearchConfigWriteConfigJob() =
default;
22bool LdapClientSearchConfigWriteConfigJob::canStart()
const
24 return mServerIndex != -1 && mConfig.isValid();
27void LdapClientSearchConfigWriteConfigJob::writeLdapClientConfigFinished()
33void LdapClientSearchConfigWriteConfigJob::start()
37 writeLdapClientConfigFinished();
43bool LdapClientSearchConfigWriteConfigJob::active()
const
48void LdapClientSearchConfigWriteConfigJob::setActive(
bool newActive)
53int LdapClientSearchConfigWriteConfigJob::serverIndex()
const
58void LdapClientSearchConfigWriteConfigJob::setServerIndex(
int newServerIndex)
60 mServerIndex = newServerIndex;
63KConfigGroup LdapClientSearchConfigWriteConfigJob::config()
const
68void LdapClientSearchConfigWriteConfigJob::setConfig(
const KConfigGroup &newConfig)
73void LdapClientSearchConfigWriteConfigJob::writeConfig()
77 prefix = QStringLiteral(
"Selected");
80 mConfig.
writeEntry(prefix + QStringLiteral(
"Host%1").arg(mServerIndex), mServer.host());
81 mConfig.writeEntry(prefix + QStringLiteral(
"Port%1").arg(mServerIndex), mServer.port());
82 mConfig.writeEntry(prefix + QStringLiteral(
"Base%1").arg(mServerIndex), mServer.baseDn().toString());
83 mConfig.writeEntry(prefix + QStringLiteral(
"User%1").arg(mServerIndex), mServer.user());
84 mConfig.writeEntry(prefix + QStringLiteral(
"Bind%1").arg(mServerIndex), mServer.bindDn());
86 const QString passwordEntry = prefix + QStringLiteral(
"PwdBind%1").
arg(mServerIndex);
87 const QString password = mServer.password();
89 auto writeJob =
new WritePasswordJob(QStringLiteral(
"ldapclient"),
this);
90 connect(writeJob, &Job::finished,
this, [](QKeychain::Job *baseJob) {
91 if (baseJob->error()) {
92 qCWarning(LDAP_CORE_LOG) <<
"Error writing password using QKeychain:" << baseJob->errorString();
95 writeJob->setKey(passwordEntry);
96 writeJob->setTextData(password);
100 mConfig.writeEntry(prefix + QStringLiteral(
"TimeLimit%1").arg(mServerIndex), mServer.timeLimit());
101 mConfig.writeEntry(prefix + QStringLiteral(
"SizeLimit%1").arg(mServerIndex), mServer.sizeLimit());
102 mConfig.writeEntry(prefix + QStringLiteral(
"PageSize%1").arg(mServerIndex), mServer.pageSize());
103 mConfig.writeEntry(prefix + QStringLiteral(
"Version%1").arg(mServerIndex), mServer.version());
104 mConfig.writeEntry(prefix + QStringLiteral(
"Activities%1").arg(mServerIndex), mServer.activities());
105 mConfig.writeEntry(prefix + QStringLiteral(
"EnabledActivities%1").arg(mServerIndex), mServer.enablePlasmaActivities());
108 switch (mServer.security()) {
109 case KLDAPCore::LdapServer::TLS:
110 tmp = QStringLiteral(
"TLS");
112 case KLDAPCore::LdapServer::SSL:
113 tmp = QStringLiteral(
"SSL");
116 tmp = QStringLiteral(
"None");
118 mConfig.writeEntry(prefix + QStringLiteral(
"Security%1").arg(mServerIndex), tmp);
119 switch (mServer.auth()) {
120 case KLDAPCore::LdapServer::Simple:
121 tmp = QStringLiteral(
"Simple");
123 case KLDAPCore::LdapServer::SASL:
124 tmp = QStringLiteral(
"SASL");
127 tmp = QStringLiteral(
"Anonymous");
129 mConfig.writeEntry(prefix + QStringLiteral(
"Auth%1").arg(mServerIndex), tmp);
130 mConfig.writeEntry(prefix + QStringLiteral(
"Mech%1").arg(mServerIndex), mServer.mech());
131 mConfig.writeEntry(prefix + QStringLiteral(
"UserFilter%1").arg(mServerIndex), mServer.filter().trimmed());
132 if (mServer.completionWeight() > -1) {
133 mConfig.writeEntry(prefix + QStringLiteral(
"CompletionWeight%1").arg(mServerIndex), mServer.completionWeight());
137KLDAPCore::LdapServer LdapClientSearchConfigWriteConfigJob::server()
const
142void LdapClientSearchConfigWriteConfigJob::setServer(
const KLDAPCore::LdapServer &server)
147#include "moc_ldapclientsearchconfigwriteconfigjob.cpp"
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString arg(Args &&... args) const const
bool isEmpty() const const