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/ldapactivitiesabstractplugin.h"
13#include "kldapwidgets/ldapconfigwidget.h"
14#include <KAcceleratorManager>
15#include <KConfigGroup>
16#include <KLocalizedString>
17#include <KPluginFactory>
18#include <KPluginMetaData>
19#include <KSharedConfig>
20#include <KWindowConfig>
21#include <QDialogButtonBox>
22#include <QHBoxLayout>
23#include <QPushButton>
24#include <QTabBar>
25#include <QTabWidget>
26#include <QVBoxLayout>
27#include <QWindow>
28
29using namespace KLDAPWidgets;
30namespace
31{
32static const char myAddHostDialogPrivateGroupName[] = "AddHostDialog";
33}
34class KLDAPWidgets::AddHostDialogPrivate
35{
36public:
37 explicit AddHostDialogPrivate(AddHostDialog *qq)
38 : q(qq)
39 {
40 }
41
42 ~AddHostDialogPrivate()
43 {
44 }
45
46 KLDAPWidgets::LdapConfigWidget *mCfg = nullptr;
47 KLDAPCore::LdapServer *mServer = nullptr;
48 QPushButton *mOkButton = nullptr;
49 AddHostDialog *const q;
50 QTabWidget *mTabWidget = nullptr;
51 KLDAPWidgets::LdapActivitiesAbstractPlugin *mActivitiesPlugin = nullptr;
52};
53
54void AddHostDialog::readConfig()
55{
56 create(); // ensure a window is created
57 windowHandle()->resize(QSize(600, 400));
58 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myAddHostDialogPrivateGroupName));
60 resize(windowHandle()->size()); // workaround for QTBUG-40584
61}
62
63void AddHostDialog::writeConfig()
64{
65 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myAddHostDialogPrivateGroupName));
67 group.sync();
68}
69
70AddHostDialog::AddHostDialog(KLDAPCore::LdapServer *server, QWidget *parent)
71 : QDialog(parent)
72 , d(new KLDAPWidgets::AddHostDialogPrivate(this))
73{
74 setWindowTitle(i18nc("@title:window", "Add Host"));
75 auto mainLayout = new QVBoxLayout(this);
77 d->mOkButton = buttonBox->button(QDialogButtonBox::Ok);
78 d->mOkButton->setDefault(true);
79 d->mOkButton->setShortcut({Qt::CTRL, Qt::Key_Return});
80 connect(buttonBox, &QDialogButtonBox::rejected, this, &AddHostDialog::reject);
81
82 setModal(true);
83
84 d->mServer = server;
85
86 d->mTabWidget = new QTabWidget(this);
87 mainLayout->addWidget(d->mTabWidget);
88 d->mTabWidget->tabBar()->setExpanding(true);
89 d->mTabWidget->setDocumentMode(true);
90 d->mTabWidget->setTabBarAutoHide(true);
91
92 auto page = new QWidget(this);
93 d->mTabWidget->addTab(page, i18n("Configure"));
94
95 const KPluginMetaData editWidgetPlugin(QStringLiteral("pim6/ldapactivities/kldapactivitiesplugin"));
96
97 const auto result = KPluginFactory::instantiatePlugin<KLDAPWidgets::LdapActivitiesAbstractPlugin>(editWidgetPlugin);
98 if (result) {
99 d->mActivitiesPlugin = result.plugin;
100 }
101 if (d->mActivitiesPlugin) {
102 d->mTabWidget->addTab(d->mActivitiesPlugin, i18n("Activities"));
103 KLDAPWidgets::LdapActivitiesAbstractPlugin::ActivitySettings settings{
104 d->mServer->activities(),
105 d->mServer->enablePlasmaActivities(),
106 };
107 d->mActivitiesPlugin->setActivitiesSettings(settings);
108 }
109
110 mainLayout->addWidget(buttonBox);
111 auto layout = new QHBoxLayout(page);
112 layout->setContentsMargins({});
113
114 d->mCfg = new KLDAPWidgets::LdapConfigWidget(
115 KLDAPWidgets::LdapConfigWidget::W_USER | KLDAPWidgets::LdapConfigWidget::W_PASS | KLDAPWidgets::LdapConfigWidget::W_BINDDN
116 | KLDAPWidgets::LdapConfigWidget::W_REALM | KLDAPWidgets::LdapConfigWidget::W_HOST | KLDAPWidgets::LdapConfigWidget::W_PORT
117 | KLDAPWidgets::LdapConfigWidget::W_VER | KLDAPWidgets::LdapConfigWidget::W_TIMELIMIT | KLDAPWidgets::LdapConfigWidget::W_SIZELIMIT
118 | KLDAPWidgets::LdapConfigWidget::W_PAGESIZE | KLDAPWidgets::LdapConfigWidget::W_DN | KLDAPWidgets::LdapConfigWidget::W_FILTER
119 | KLDAPWidgets::LdapConfigWidget::W_SECBOX | KLDAPWidgets::LdapConfigWidget::W_AUTHBOX,
120 page);
121
122 layout->addWidget(d->mCfg);
123 d->mCfg->setHost(d->mServer->host());
124 d->mCfg->setPort(d->mServer->port());
125 d->mCfg->setDn(d->mServer->baseDn());
126 d->mCfg->setUser(d->mServer->user());
127 d->mCfg->setBindDn(d->mServer->bindDn());
128 d->mCfg->setPassword(d->mServer->password());
129 d->mCfg->setTimeLimit(d->mServer->timeLimit());
130 d->mCfg->setSizeLimit(d->mServer->sizeLimit());
131 d->mCfg->setPageSize(d->mServer->pageSize());
132 d->mCfg->setVersion(d->mServer->version());
133 d->mCfg->setFilter(d->mServer->filter());
134 switch (d->mServer->security()) {
135 case KLDAPCore::LdapServer::TLS:
136 d->mCfg->setSecurity(KLDAPWidgets::LdapConfigWidget::TLS);
137 break;
138 case KLDAPCore::LdapServer::SSL:
139 d->mCfg->setSecurity(KLDAPWidgets::LdapConfigWidget::SSL);
140 break;
141 default:
142 d->mCfg->setSecurity(KLDAPWidgets::LdapConfigWidget::None);
143 }
144
145 switch (d->mServer->auth()) {
146 case KLDAPCore::LdapServer::Simple:
147 d->mCfg->setAuth(KLDAPWidgets::LdapConfigWidget::Simple);
148 break;
149 case KLDAPCore::LdapServer::SASL:
150 d->mCfg->setAuth(KLDAPWidgets::LdapConfigWidget::SASL);
151 break;
152 default:
153 d->mCfg->setAuth(KLDAPWidgets::LdapConfigWidget::Anonymous);
154 }
155 d->mCfg->setMech(d->mServer->mech());
156
158 connect(d->mCfg, &KLDAPWidgets::LdapConfigWidget::hostNameChanged, this, &AddHostDialog::slotHostEditChanged);
159 connect(d->mOkButton, &QPushButton::clicked, this, &AddHostDialog::slotOk);
160 d->mOkButton->setEnabled(!d->mServer->host().isEmpty());
161 readConfig();
162}
163
164AddHostDialog::~AddHostDialog()
165{
166 writeConfig();
167}
168
169void AddHostDialog::slotHostEditChanged(const QString &text)
170{
171 d->mOkButton->setEnabled(!text.isEmpty());
172}
173
174void AddHostDialog::slotOk()
175{
176 d->mServer->setHost(d->mCfg->host());
177 d->mServer->setPort(d->mCfg->port());
178 d->mServer->setBaseDn(d->mCfg->dn());
179 d->mServer->setUser(d->mCfg->user());
180 d->mServer->setBindDn(d->mCfg->bindDn());
181 d->mServer->setPassword(d->mCfg->password());
182 d->mServer->setTimeLimit(d->mCfg->timeLimit());
183 d->mServer->setSizeLimit(d->mCfg->sizeLimit());
184 d->mServer->setPageSize(d->mCfg->pageSize());
185 d->mServer->setVersion(d->mCfg->version());
186 d->mServer->setFilter(d->mCfg->filter());
187 switch (d->mCfg->security()) {
188 case KLDAPWidgets::LdapConfigWidget::TLS:
189 d->mServer->setSecurity(KLDAPCore::LdapServer::TLS);
190 break;
191 case KLDAPWidgets::LdapConfigWidget::SSL:
192 d->mServer->setSecurity(KLDAPCore::LdapServer::SSL);
193 break;
194 default:
195 d->mServer->setSecurity(KLDAPCore::LdapServer::None);
196 }
197 switch (d->mCfg->auth()) {
198 case KLDAPWidgets::LdapConfigWidget::Simple:
199 d->mServer->setAuth(KLDAPCore::LdapServer::Simple);
200 break;
201 case KLDAPWidgets::LdapConfigWidget::SASL:
202 d->mServer->setAuth(KLDAPCore::LdapServer::SASL);
203 break;
204 default:
205 d->mServer->setAuth(KLDAPCore::LdapServer::Anonymous);
206 }
207 d->mServer->setMech(d->mCfg->mech());
208 if (d->mActivitiesPlugin) {
209 const KLDAPWidgets::LdapActivitiesAbstractPlugin::ActivitySettings settings = d->mActivitiesPlugin->activitiesSettings();
210 d->mServer->setActivities(settings.activities);
211 d->mServer->setEnablePlasmaActivities(settings.enabled);
212 }
214}
215
216#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...)
QString i18n(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 Fri Dec 20 2024 11:52:23 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.