Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
KLDAP
Commits
c4195941
Commit
c4195941
authored
Nov 24, 2020
by
Laurent Montel
😁
Browse files
Extract save settings as job too
parent
466e8f1c
Pipeline
#41920
passed with stage
in 8 minutes and 35 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/CMakeLists.txt
View file @
c4195941
...
...
@@ -51,6 +51,7 @@ set(kldap_LIB_widgets_SRCS
widgets/ldapclientsearchconfig.cpp
widgets/ldapconfigurewidget.cpp
widgets/ldapclientsearchconfigreadconfigjob.cpp
widgets/ldapclientsearchconfigwriteconfigjob.cpp
)
set
(
kldap_LIB_SRCS
...
...
src/widgets/ldapclientsearchconfigreadconfigjob.cpp
View file @
c4195941
...
...
@@ -31,7 +31,7 @@ bool LdapClientSearchConfigReadConfigJob::canStart() const
return
mServerIndex
!=
-
1
&&
mConfig
.
isValid
();
}
void
LdapClientSearchConfigReadConfigJob
::
s
ea
rch
LdapClientConfigFinished
()
void
LdapClientSearchConfigReadConfigJob
::
r
ea
d
LdapClientConfigFinished
()
{
Q_EMIT
configLoaded
(
mServer
);
deleteLater
();
...
...
@@ -41,7 +41,7 @@ void LdapClientSearchConfigReadConfigJob::start()
{
if
(
!
canStart
())
{
//Failed !
s
ea
rch
LdapClientConfigFinished
();
r
ea
d
LdapClientConfigFinished
();
return
;
}
readConfig
();
...
...
@@ -194,6 +194,6 @@ void LdapClientSearchConfigReadConfigJob::readSieveServerPasswordFinished(QKeych
}
else
{
qCWarning
(
LDAPCLIENT_LOG
)
<<
"We have an error during reading password "
<<
job
->
errorString
();
}
s
ea
rch
LdapClientConfigFinished
();
r
ea
d
LdapClientConfigFinished
();
}
src/widgets/ldapclientsearchconfigreadconfigjob.h
View file @
c4195941
...
...
@@ -38,7 +38,7 @@ Q_SIGNALS:
private:
void
readSieveServerPasswordFinished
(
QKeychain
::
Job
*
baseJob
);
void
s
ea
rch
LdapClientConfigFinished
();
void
r
ea
d
LdapClientConfigFinished
();
void
readConfig
();
int
mServerIndex
=
-
1
;
KConfigGroup
mConfig
;
...
...
src/widgets/ldapclientsearchconfigwriteconfigjob.cpp
0 → 100644
View file @
c4195941
/*
* SPDX-FileCopyrightText: 2020 Laurent Montel <montel@kde.org>
*
* SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "ldapclientsearchconfigwriteconfigjob.h"
#include "ldapclient_debug.h"
#include <KConfig>
#include <KConfigGroup>
#include <KLocalizedString>
#include <kldap/ldapdn.h>
#include <qt5keychain/keychain.h>
using
namespace
QKeychain
;
using
namespace
KLDAP
;
LdapClientSearchConfigWriteConfigJob
::
LdapClientSearchConfigWriteConfigJob
(
QObject
*
parent
)
:
QObject
(
parent
)
{
}
LdapClientSearchConfigWriteConfigJob
::~
LdapClientSearchConfigWriteConfigJob
()
{
}
bool
LdapClientSearchConfigWriteConfigJob
::
canStart
()
const
{
return
mServerIndex
!=
-
1
&&
mConfig
.
isValid
();
}
void
LdapClientSearchConfigWriteConfigJob
::
writeLdapClientConfigFinished
()
{
Q_EMIT
configSaved
();
deleteLater
();
}
void
LdapClientSearchConfigWriteConfigJob
::
start
()
{
if
(
!
canStart
())
{
//Failed !
writeLdapClientConfigFinished
();
return
;
}
writeConfig
();
}
bool
LdapClientSearchConfigWriteConfigJob
::
active
()
const
{
return
mActive
;
}
void
LdapClientSearchConfigWriteConfigJob
::
setActive
(
bool
newActive
)
{
mActive
=
newActive
;
}
int
LdapClientSearchConfigWriteConfigJob
::
serverIndex
()
const
{
return
mServerIndex
;
}
void
LdapClientSearchConfigWriteConfigJob
::
setServerIndex
(
int
newServerIndex
)
{
mServerIndex
=
newServerIndex
;
}
KConfigGroup
LdapClientSearchConfigWriteConfigJob
::
config
()
const
{
return
mConfig
;
}
void
LdapClientSearchConfigWriteConfigJob
::
setConfig
(
const
KConfigGroup
&
newConfig
)
{
mConfig
=
newConfig
;
}
void
LdapClientSearchConfigWriteConfigJob
::
writeConfig
()
{
QString
prefix
;
if
(
mActive
)
{
prefix
=
QStringLiteral
(
"Selected"
);
}
mConfig
.
writeEntry
(
prefix
+
QStringLiteral
(
"Host%1"
).
arg
(
mServerIndex
),
mServer
.
host
());
mConfig
.
writeEntry
(
prefix
+
QStringLiteral
(
"Port%1"
).
arg
(
mServerIndex
),
mServer
.
port
());
mConfig
.
writeEntry
(
prefix
+
QStringLiteral
(
"Base%1"
).
arg
(
mServerIndex
),
mServer
.
baseDn
().
toString
());
mConfig
.
writeEntry
(
prefix
+
QStringLiteral
(
"User%1"
).
arg
(
mServerIndex
),
mServer
.
user
());
mConfig
.
writeEntry
(
prefix
+
QStringLiteral
(
"Bind%1"
).
arg
(
mServerIndex
),
mServer
.
bindDn
());
const
QString
passwordEntry
=
prefix
+
QStringLiteral
(
"PwdBind%1"
).
arg
(
mServerIndex
);
const
QString
password
=
mServer
.
password
();
if
(
!
password
.
isEmpty
())
{
auto
writeJob
=
new
WritePasswordJob
(
QStringLiteral
(
"ldapclient"
),
this
);
connect
(
writeJob
,
&
Job
::
finished
,
this
,
[](
QKeychain
::
Job
*
baseJob
)
{
if
(
baseJob
->
error
())
{
qCWarning
(
LDAPCLIENT_LOG
)
<<
"Error writing password using QKeychain:"
<<
baseJob
->
errorString
();
}
});
writeJob
->
setKey
(
passwordEntry
);
writeJob
->
setTextData
(
password
);
writeJob
->
start
();
}
mConfig
.
writeEntry
(
prefix
+
QStringLiteral
(
"TimeLimit%1"
).
arg
(
mServerIndex
),
mServer
.
timeLimit
());
mConfig
.
writeEntry
(
prefix
+
QStringLiteral
(
"SizeLimit%1"
).
arg
(
mServerIndex
),
mServer
.
sizeLimit
());
mConfig
.
writeEntry
(
prefix
+
QStringLiteral
(
"PageSize%1"
).
arg
(
mServerIndex
),
mServer
.
pageSize
());
mConfig
.
writeEntry
(
prefix
+
QStringLiteral
(
"Version%1"
).
arg
(
mServerIndex
),
mServer
.
version
());
QString
tmp
;
switch
(
mServer
.
security
())
{
case
KLDAP
::
LdapServer
::
TLS
:
tmp
=
QStringLiteral
(
"TLS"
);
break
;
case
KLDAP
::
LdapServer
::
SSL
:
tmp
=
QStringLiteral
(
"SSL"
);
break
;
default:
tmp
=
QStringLiteral
(
"None"
);
}
mConfig
.
writeEntry
(
prefix
+
QStringLiteral
(
"Security%1"
).
arg
(
mServerIndex
),
tmp
);
switch
(
mServer
.
auth
())
{
case
KLDAP
::
LdapServer
::
Simple
:
tmp
=
QStringLiteral
(
"Simple"
);
break
;
case
KLDAP
::
LdapServer
::
SASL
:
tmp
=
QStringLiteral
(
"SASL"
);
break
;
default:
tmp
=
QStringLiteral
(
"Anonymous"
);
}
mConfig
.
writeEntry
(
prefix
+
QStringLiteral
(
"Auth%1"
).
arg
(
mServerIndex
),
tmp
);
mConfig
.
writeEntry
(
prefix
+
QStringLiteral
(
"Mech%1"
).
arg
(
mServerIndex
),
mServer
.
mech
());
mConfig
.
writeEntry
(
prefix
+
QStringLiteral
(
"UserFilter%1"
).
arg
(
mServerIndex
),
mServer
.
filter
().
trimmed
());
if
(
mServer
.
completionWeight
()
>
-
1
)
{
mConfig
.
writeEntry
(
prefix
+
QStringLiteral
(
"CompletionWeight%1"
).
arg
(
mServerIndex
),
mServer
.
completionWeight
());
}
}
src/widgets/ldapclientsearchconfigwriteconfigjob.h
0 → 100644
View file @
c4195941
/*
* SPDX-FileCopyrightText: 2020 Laurent Montel <montel@kde.org>
*
* SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef LDAPCLIENTSEARCHCONFIGWRITECONFIGJOB_H
#define LDAPCLIENTSEARCHCONFIGWRITECONFIGJOB_H
#include <QObject>
#include "kldap_export.h"
#include <KLDAP/LdapServer>
#include <KConfigGroup>
namespace
QKeychain
{
class
Job
;
}
namespace
KLDAP
{
class
KLDAP_EXPORT
LdapClientSearchConfigWriteConfigJob
:
public
QObject
{
Q_OBJECT
public:
explicit
LdapClientSearchConfigWriteConfigJob
(
QObject
*
parent
=
nullptr
);
~
LdapClientSearchConfigWriteConfigJob
()
override
;
Q_REQUIRED_RESULT
bool
canStart
()
const
;
void
start
();
Q_REQUIRED_RESULT
bool
active
()
const
;
void
setActive
(
bool
newActive
);
Q_REQUIRED_RESULT
int
serverIndex
()
const
;
void
setServerIndex
(
int
newServerIndex
);
Q_REQUIRED_RESULT
KConfigGroup
config
()
const
;
void
setConfig
(
const
KConfigGroup
&
newConfig
);
Q_SIGNALS:
void
configSaved
();
private:
void
writeLdapClientConfigFinished
();
void
writeConfig
();
int
mServerIndex
=
-
1
;
KConfigGroup
mConfig
;
bool
mActive
=
false
;
KLDAP
::
LdapServer
mServer
;
};
}
#endif // LDAPCLIENTSEARCHCONFIGWRITECONFIGJOB_H
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment