Commit 88eee532 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Continue to implement it

parent 274ab848
Pipeline #42639 passed with stage
in 13 minutes and 21 seconds
......@@ -6,6 +6,7 @@
#include "restoreldapsettingsjob.h"
#include <KLDAP/LdapClientSearchConfigWriteConfigJob>
#include <KLDAP/LdapClientSearchConfig>
#include <KConfigGroup>
#include <KConfig>
#include <QDebug>
......@@ -29,10 +30,82 @@ void RestoreLdapSettingsJob::start()
Q_EMIT restoreDone();
return;
}
restore();
}
void RestoreLdapSettingsJob::restore()
{
if (mEntry >= 0) {
KConfigGroup group = mConfig->group(QStringLiteral("LDAP"));
const int cSelHosts = group.readEntry(QStringLiteral("NumSelectedHosts"), 0);
const int cHosts = group.readEntry(QStringLiteral("NumHosts"), 0);
QVector<KLDAP::LdapServer> selHosts;
QVector<KLDAP::LdapServer> hosts;
for (int i = 0; i < cSelHosts; ++i) {
if (i != mEntry) {
KLDAP::LdapServer server;
mClientSearchConfig->readConfig(server, group, i, true);
selHosts.append(server);
}
}
hosts.reserve(cHosts);
for (int i = 0; i < cHosts; ++i) {
KLDAP::LdapServer server;
mClientSearchConfig->readConfig(server, group, i, false);
hosts.append(server);
}
mConfig->deleteGroup(QStringLiteral("LDAP"));
group = KConfigGroup(mConfig, QStringLiteral("LDAP"));
for (int i = 0; i < cSelHosts - 1; ++i) {
auto job = new KLDAP::LdapClientSearchConfigWriteConfigJob;
job->setActive(true);
job->setConfig(group);
job->setServer(selHosts.at(i));
job->setServerIndex(i);
job->start();
}
for (int i = 0; i < cHosts; ++i) {
auto job = new KLDAP::LdapClientSearchConfigWriteConfigJob;
job->setActive(false);
job->setConfig(group);
job->setServer(hosts.at(i));
job->setServerIndex(i);
job->start();
}
group.writeEntry(QStringLiteral("NumSelectedHosts"), cSelHosts - 1);
group.writeEntry(QStringLiteral("NumHosts"), cHosts);
mConfig->sync();
Q_EMIT restoreDone();
}
//TODO
deleteLater();
}
KLDAP::LdapClientSearchConfig *RestoreLdapSettingsJob::clientSearchConfig() const
{
return mClientSearchConfig;
}
void RestoreLdapSettingsJob::setClientSearchConfig(KLDAP::LdapClientSearchConfig *clientSearchConfig)
{
mClientSearchConfig = clientSearchConfig;
}
int RestoreLdapSettingsJob::entry() const
{
return mEntry;
}
void RestoreLdapSettingsJob::setEntry(int entry)
{
mEntry = entry;
}
KConfig *RestoreLdapSettingsJob::config() const
{
return mConfig;
......@@ -45,5 +118,5 @@ void RestoreLdapSettingsJob::setConfig(KConfig *config)
bool RestoreLdapSettingsJob::canStart() const
{
return (mConfig != nullptr);
return (mConfig != nullptr) && (mEntry != -1) && mClientSearchConfig;
}
......@@ -10,6 +10,9 @@
#include <QObject>
#include <KLDAP/LdapServer>
class KConfig;
namespace KLDAP {
class LdapClientSearchConfig;
}
class RestoreLdapSettingsJob : public QObject
{
Q_OBJECT
......@@ -21,12 +24,21 @@ public:
KConfig *config() const;
void setConfig(KConfig *config);
Q_REQUIRED_RESULT bool canStart() const;
Q_REQUIRED_RESULT int entry() const;
void setEntry(int entry);
KLDAP::LdapClientSearchConfig *clientSearchConfig() const;
void setClientSearchConfig(KLDAP::LdapClientSearchConfig *clientSearchConfig);
Q_SIGNALS:
void restoreDone();
private:
void restore();
QVector<KLDAP::LdapServer> mSelHosts;
QVector<KLDAP::LdapServer> mHosts;
int mEntry = -1;
KConfig *mConfig = nullptr;
KLDAP::LdapClientSearchConfig *mClientSearchConfig = nullptr;
};
#endif // RESTORELDAPSETTINGSJOB_H
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