Commit a1b3b61b authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Load settings as async

parent 25617b9f
Pipeline #42511 passed with stage
in 7 minutes and 55 seconds
......@@ -22,6 +22,7 @@
#include "ldapclientsearch.h"
#include "ldapclientsearchconfigwriteconfigjob.h"
#include "ldapwidgetitemreadconfigserverjob.h"
#include "ldapclientsearchconfig.h"
#include "ldapwidgetitem_p.h"
#include <kldap/ldapserver.h>
......@@ -77,7 +78,8 @@ void LdapConfigureWidget::slotAddHost()
KLDAP::AddHostDialog dlg(&server, this);
if (dlg.exec() && !server.host().trimmed().isEmpty()) { //krazy:exclude=crashy
new LdapWidgetItem(mHostListView, server);
auto item = new LdapWidgetItem(mHostListView);
item->setServer(server);
Q_EMIT changed(true);
}
......@@ -189,17 +191,26 @@ void LdapConfigureWidget::load()
int count = group.readEntry("NumSelectedHosts", 0);
for (int i = 0; i < count; ++i) {
KLDAP::LdapServer server;
mClientSearchConfig->readConfig(server, group, i, true);
auto *item = new LdapWidgetItem(mHostListView, server, true);
auto *item = new LdapWidgetItem(mHostListView, true);
item->setCheckState(Qt::Checked);
auto job = new LdapWidgetItemReadConfigServerJob(this);
job->setCurrentIndex(i);
job->setActive(true);
job->setConfig(group);
job->setLdapWidgetItem(item);
job->start();
}
count = group.readEntry("NumHosts", 0);
for (int i = 0; i < count; ++i) {
KLDAP::LdapServer server;
mClientSearchConfig->readConfig(server, group, i, false);
new LdapWidgetItem(mHostListView, server);
auto item = new LdapWidgetItem(mHostListView);
auto job = new LdapWidgetItemReadConfigServerJob(this);
job->setCurrentIndex(i);
job->setActive(false);
job->setConfig(group);
job->setLdapWidgetItem(item);
job->start();
}
Q_EMIT changed(false);
......
......@@ -7,20 +7,17 @@
#include "ldapwidgetitem_p.h"
using namespace KLDAP;
LdapWidgetItem::LdapWidgetItem(QListWidget *parent, const KLDAP::LdapServer &server, bool isActive)
LdapWidgetItem::LdapWidgetItem(QListWidget *parent, bool isActive)
: QListWidgetItem(parent, QListWidgetItem::UserType)
, mIsActive(isActive)
{
setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
setCheckState(isActive ? Qt::Checked : Qt::Unchecked);
setServer(server);
}
void LdapWidgetItem::setServer(const KLDAP::LdapServer &server)
{
//TODO load settings here.
mServer = server;
setText(mServer.host());
}
......
......@@ -13,7 +13,7 @@ namespace KLDAP {
class LdapWidgetItem : public QListWidgetItem
{
public:
explicit LdapWidgetItem(QListWidget *parent, const KLDAP::LdapServer &server, bool isActive = false);
explicit LdapWidgetItem(QListWidget *parent, bool isActive = false);
void setServer(const KLDAP::LdapServer &server);
......
......@@ -6,6 +6,7 @@
#include "ldapwidgetitemreadconfigserverjob.h"
#include "ldapwidgetitem_p.h"
#include "ldapclientsearchconfigreadconfigjob.h"
using namespace KLDAP;
LdapWidgetItemReadConfigServerJob::LdapWidgetItemReadConfigServerJob(QObject *parent)
: QObject(parent)
......@@ -18,6 +19,22 @@ LdapWidgetItemReadConfigServerJob::~LdapWidgetItemReadConfigServerJob()
}
void LdapWidgetItemReadConfigServerJob::start()
{
auto job = new LdapClientSearchConfigReadConfigJob(this);
connect(job, &LdapClientSearchConfigReadConfigJob::configLoaded, this, &LdapWidgetItemReadConfigServerJob::slotConfigLoaded);
job->setActive(mActive);
job->setConfig(mConfig);
job->setServerIndex(mCurrentIndex);
job->start();
}
void LdapWidgetItemReadConfigServerJob::slotConfigLoaded(const KLDAP::LdapServer &server)
{
mLdapWidgetItem->setServer(server);
deleteLater();
}
LdapWidgetItem *LdapWidgetItemReadConfigServerJob::ldapWidgetItem() const
{
return mLdapWidgetItem;
......@@ -27,3 +44,33 @@ void LdapWidgetItemReadConfigServerJob::setLdapWidgetItem(LdapWidgetItem *ldapWi
{
mLdapWidgetItem = ldapWidgetItem;
}
int LdapWidgetItemReadConfigServerJob::currentIndex() const
{
return mCurrentIndex;
}
void LdapWidgetItemReadConfigServerJob::setCurrentIndex(int currentIndex)
{
mCurrentIndex = currentIndex;
}
bool LdapWidgetItemReadConfigServerJob::active() const
{
return mActive;
}
void LdapWidgetItemReadConfigServerJob::setActive(bool active)
{
mActive = active;
}
KConfigGroup LdapWidgetItemReadConfigServerJob::config() const
{
return mConfig;
}
void LdapWidgetItemReadConfigServerJob::setConfig(const KConfigGroup &config)
{
mConfig = config;
}
......@@ -8,8 +8,10 @@
#define LDAPWIDGETITEMREADCONFIGSERVERJOB_H
#include <QObject>
#include <KConfigGroup>
namespace KLDAP {
class LdapWidgetItem;
class LdapServer;
class LdapWidgetItemReadConfigServerJob : public QObject
{
Q_OBJECT
......@@ -17,11 +19,26 @@ public:
explicit LdapWidgetItemReadConfigServerJob(QObject *parent = nullptr);
~LdapWidgetItemReadConfigServerJob() override;
void start();
LdapWidgetItem *ldapWidgetItem() const;
void setLdapWidgetItem(LdapWidgetItem *ldapWidgetItem);
Q_REQUIRED_RESULT int currentIndex() const;
void setCurrentIndex(int currentIndex);
Q_REQUIRED_RESULT bool active() const;
void setActive(bool active);
Q_REQUIRED_RESULT KConfigGroup config() const;
void setConfig(const KConfigGroup &config);
private:
void slotConfigLoaded(const KLDAP::LdapServer &server);
LdapWidgetItem *mLdapWidgetItem = nullptr;
KConfigGroup mConfig;
int mCurrentIndex = -1;
bool mActive = false;
};
}
......
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