KLdap

addhostdialog.cpp
1/*
2 This file is part of libkldap.
3
4 SPDX-FileCopyrightText: 2002-2010 Tobias Koenig <tokoe@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "addhostdialog.h"
10
11#include "kldapcore/ldapserver.h"
12#include "kldapwidgets/ldapconfigwidget.h"
13#include <KAcceleratorManager>
14#include <KConfigGroup>
15#include <KLocalizedString>
16#include <KSharedConfig>
17#include <KWindowConfig>
18#include <QDialogButtonBox>
19#include <QHBoxLayout>
20#include <QPushButton>
21#include <QVBoxLayout>
22#include <QWindow>
23
24using namespace KLDAPWidgets;
25namespace
26{
27static const char myAddHostDialogPrivateGroupName[] = "AddHostDialog";
28}
29class KLDAPWidgets::AddHostDialogPrivate
30{
31public:
32 explicit AddHostDialogPrivate(AddHostDialog *qq)
33 : q(qq)
34 {
35 }
36
37 ~AddHostDialogPrivate()
38 {
39 }
40
41 KLDAPWidgets::LdapConfigWidget *mCfg = nullptr;
42 KLDAPCore::LdapServer *mServer = nullptr;
43 QPushButton *mOkButton = nullptr;
44 AddHostDialog *const q;
45};
46
47void AddHostDialog::readConfig()
48{
49 create(); // ensure a window is created
50 windowHandle()->resize(QSize(600, 400));
51 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myAddHostDialogPrivateGroupName));
53 resize(windowHandle()->size()); // workaround for QTBUG-40584
54}
55
56void AddHostDialog::writeConfig()
57{
58 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myAddHostDialogPrivateGroupName));
60 group.sync();
61}
62
63AddHostDialog::AddHostDialog(KLDAPCore::LdapServer *server, QWidget *parent)
64 : QDialog(parent)
65 , d(new KLDAPWidgets::AddHostDialogPrivate(this))
66{
67 setWindowTitle(i18nc("@title:window", "Add Host"));
68 auto mainLayout = new QVBoxLayout(this);
70 d->mOkButton = buttonBox->button(QDialogButtonBox::Ok);
71 d->mOkButton->setDefault(true);
72 d->mOkButton->setShortcut({Qt::CTRL, Qt::Key_Return});
73 connect(buttonBox, &QDialogButtonBox::rejected, this, &AddHostDialog::reject);
74
75 setModal(true);
76
77 d->mServer = server;
78
79 auto page = new QWidget(this);
80 mainLayout->addWidget(page);
81 mainLayout->addWidget(buttonBox);
82 auto layout = new QHBoxLayout(page);
83 layout->setContentsMargins(0, 0, 0, 0);
84
86 KLDAPWidgets::LdapConfigWidget::W_USER | KLDAPWidgets::LdapConfigWidget::W_PASS | KLDAPWidgets::LdapConfigWidget::W_BINDDN
87 | KLDAPWidgets::LdapConfigWidget::W_REALM | KLDAPWidgets::LdapConfigWidget::W_HOST | KLDAPWidgets::LdapConfigWidget::W_PORT
88 | KLDAPWidgets::LdapConfigWidget::W_VER | KLDAPWidgets::LdapConfigWidget::W_TIMELIMIT | KLDAPWidgets::LdapConfigWidget::W_SIZELIMIT
89 | KLDAPWidgets::LdapConfigWidget::W_PAGESIZE | KLDAPWidgets::LdapConfigWidget::W_DN | KLDAPWidgets::LdapConfigWidget::W_FILTER
90 | KLDAPWidgets::LdapConfigWidget::W_SECBOX | KLDAPWidgets::LdapConfigWidget::W_AUTHBOX,
91 page);
92
93 layout->addWidget(d->mCfg);
94 d->mCfg->setHost(d->mServer->host());
95 d->mCfg->setPort(d->mServer->port());
96 d->mCfg->setDn(d->mServer->baseDn());
97 d->mCfg->setUser(d->mServer->user());
98 d->mCfg->setBindDn(d->mServer->bindDn());
99 d->mCfg->setPassword(d->mServer->password());
100 d->mCfg->setTimeLimit(d->mServer->timeLimit());
101 d->mCfg->setSizeLimit(d->mServer->sizeLimit());
102 d->mCfg->setPageSize(d->mServer->pageSize());
103 d->mCfg->setVersion(d->mServer->version());
104 d->mCfg->setFilter(d->mServer->filter());
105 switch (d->mServer->security()) {
106 case KLDAPCore::LdapServer::TLS:
107 d->mCfg->setSecurity(KLDAPWidgets::LdapConfigWidget::TLS);
108 break;
109 case KLDAPCore::LdapServer::SSL:
110 d->mCfg->setSecurity(KLDAPWidgets::LdapConfigWidget::SSL);
111 break;
112 default:
113 d->mCfg->setSecurity(KLDAPWidgets::LdapConfigWidget::None);
114 }
115
116 switch (d->mServer->auth()) {
117 case KLDAPCore::LdapServer::Simple:
118 d->mCfg->setAuth(KLDAPWidgets::LdapConfigWidget::Simple);
119 break;
120 case KLDAPCore::LdapServer::SASL:
121 d->mCfg->setAuth(KLDAPWidgets::LdapConfigWidget::SASL);
122 break;
123 default:
124 d->mCfg->setAuth(KLDAPWidgets::LdapConfigWidget::Anonymous);
125 }
126 d->mCfg->setMech(d->mServer->mech());
127
129 connect(d->mCfg, &KLDAPWidgets::LdapConfigWidget::hostNameChanged, this, &AddHostDialog::slotHostEditChanged);
130 connect(d->mOkButton, &QPushButton::clicked, this, &AddHostDialog::slotOk);
131 d->mOkButton->setEnabled(!d->mServer->host().isEmpty());
132 readConfig();
133}
134
135AddHostDialog::~AddHostDialog()
136{
137 writeConfig();
138}
139
140void AddHostDialog::slotHostEditChanged(const QString &text)
141{
142 d->mOkButton->setEnabled(!text.isEmpty());
143}
144
145void AddHostDialog::slotOk()
146{
147 d->mServer->setHost(d->mCfg->host());
148 d->mServer->setPort(d->mCfg->port());
149 d->mServer->setBaseDn(d->mCfg->dn());
150 d->mServer->setUser(d->mCfg->user());
151 d->mServer->setBindDn(d->mCfg->bindDn());
152 d->mServer->setPassword(d->mCfg->password());
153 d->mServer->setTimeLimit(d->mCfg->timeLimit());
154 d->mServer->setSizeLimit(d->mCfg->sizeLimit());
155 d->mServer->setPageSize(d->mCfg->pageSize());
156 d->mServer->setVersion(d->mCfg->version());
157 d->mServer->setFilter(d->mCfg->filter());
158 switch (d->mCfg->security()) {
159 case KLDAPWidgets::LdapConfigWidget::TLS:
160 d->mServer->setSecurity(KLDAPCore::LdapServer::TLS);
161 break;
162 case KLDAPWidgets::LdapConfigWidget::SSL:
163 d->mServer->setSecurity(KLDAPCore::LdapServer::SSL);
164 break;
165 default:
166 d->mServer->setSecurity(KLDAPCore::LdapServer::None);
167 }
168 switch (d->mCfg->auth()) {
169 case KLDAPWidgets::LdapConfigWidget::Simple:
170 d->mServer->setAuth(KLDAPCore::LdapServer::Simple);
171 break;
172 case KLDAPWidgets::LdapConfigWidget::SASL:
173 d->mServer->setAuth(KLDAPCore::LdapServer::SASL);
174 break;
175 default:
176 d->mServer->setAuth(KLDAPCore::LdapServer::Anonymous);
177 }
178 d->mServer->setMech(d->mCfg->mech());
180}
181
182#include "moc_addhostdialog.cpp"
static void manage(QWidget *widget, bool programmers_mode=false)
A class that contains LDAP server connection settings.
Definition ldapserver.h:27
The AddHostDialog class.
LDAP Configuration widget.
void hostNameChanged(const QString &)
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
QString i18nc(const char *context, const char *text, const TYPE &arg...)
KCONFIGGUI_EXPORT void saveWindowSize(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options=KConfigGroup::Normal)
KCONFIGGUI_EXPORT void restoreWindowSize(QWindow *window, const KConfigGroup &config)
void clicked(bool checked)
virtual void accept()
bool isEmpty() const const
Key_Return
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void create(WId window, bool initializeWindow, bool destroyOldWindow)
void resize(const QSize &)
QWindow * windowHandle() const const
void resize(const QSize &newSize)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:34:09 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.