File indexing completed on 2024-10-27 04:58:02
0001 /* 0002 SPDX-FileCopyrightText: 2014 Sandro Knauß <knauss@kolabsys.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 // This code was taken from kmail-account-wizard 0008 0009 #include "setupautoconfigkolabldap.h" 0010 #include "configfile.h" 0011 #include "accounts/ispdb/autoconfigkolabldap.h" 0012 #include "ldap.h" 0013 0014 #include <KLocalizedString> 0015 0016 SetupAutoconfigKolabLdap::SetupAutoconfigKolabLdap(QObject *parent) 0017 : SetupObject(parent) 0018 , mIspdb(new AutoconfigKolabLdap(this)) 0019 { 0020 connect(mIspdb, &AutoconfigKolabLdap::finished, this, &SetupAutoconfigKolabLdap::onIspdbFinished); 0021 } 0022 0023 SetupAutoconfigKolabLdap::~SetupAutoconfigKolabLdap() 0024 { 0025 delete mIspdb; 0026 } 0027 0028 void SetupAutoconfigKolabLdap::fillLdapServer(int i, QObject *o) const 0029 { 0030 const ldapServer isp = mIspdb->ldapServers().values().at(i); 0031 Ldap *ldapRes = qobject_cast<Ldap *>(o); 0032 0033 // TODO: setting filter 0034 0035 ldapRes->setServer(isp.hostname); 0036 ldapRes->setPort(isp.port); 0037 ldapRes->setBaseDn(isp.dn); 0038 ldapRes->setSecurity(isp.socketType); 0039 ldapRes->setVersion(isp.ldapVersion); 0040 ldapRes->setUser(isp.username); 0041 ldapRes->setPassword(isp.password); 0042 ldapRes->setBindDn(isp.bindDn); 0043 0044 ldapRes->setRealm(isp.realm); 0045 ldapRes->setSaslMech(isp.saslMech); 0046 0047 if (isp.pageSize != -1) { 0048 ldapRes->setPageSize(isp.pageSize); 0049 } 0050 0051 if (isp.timeLimit != -1) { 0052 ldapRes->setPageSize(isp.timeLimit); 0053 } 0054 0055 if (isp.sizeLimit != -1) { 0056 ldapRes->setPageSize(isp.sizeLimit); 0057 } 0058 0059 // Anonymous is set by not setting the AuthenticationMethod 0060 if (isp.authentication == KLDAP::LdapServer::SASL) { 0061 ldapRes->setAuthenticationMethod(QStringLiteral("SASL")); 0062 } else if (isp.authentication == KLDAP::LdapServer::Simple) { 0063 ldapRes->setAuthenticationMethod(QStringLiteral("Simple")); 0064 } 0065 } 0066 0067 int SetupAutoconfigKolabLdap::countLdapServers() const 0068 { 0069 return mIspdb->ldapServers().count(); 0070 } 0071 0072 void SetupAutoconfigKolabLdap::start() 0073 { 0074 mIspdb->start(); 0075 Q_EMIT info(i18n("Searching for autoconfiguration...")); 0076 } 0077 0078 void SetupAutoconfigKolabLdap::setEmail(const QString &email) 0079 { 0080 mIspdb->setEmail(email); 0081 } 0082 0083 void SetupAutoconfigKolabLdap::setPassword(const QString &password) 0084 { 0085 mIspdb->setPassword(password); 0086 } 0087 0088 void SetupAutoconfigKolabLdap::create() 0089 { 0090 } 0091 0092 void SetupAutoconfigKolabLdap::destroy() 0093 { 0094 } 0095 0096 void SetupAutoconfigKolabLdap::onIspdbFinished(bool status) 0097 { 0098 Q_EMIT ispdbFinished(status); 0099 if (status) { 0100 Q_EMIT info(i18n("Autoconfiguration found.")); 0101 } else { 0102 Q_EMIT info(i18n("Autoconfiguration failed.")); 0103 } 0104 }