2
Copyright (C) 2000 Oswald Buddenhagen <ossi@kde.org>
3
Based on several other files.
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
Boston, MA 02110-1301, USA.
23
#include <KColorScheme>
28
#include <KConfigGroup>
30
#include <QButtonGroup>
34
#include <QListWidget>
35
#include <QRadioButton>
36
#include <QGridLayout>
37
#include <QHBoxLayout>
38
#include <QVBoxLayout>
40
extern KConfig *config;
43
KDMConvenienceWidget::KDMConvenienceWidget(QWidget *parent)
48
QLabel *paranoia = new QLabel(
49
i18n("<big><b><center>Attention<br/>"
50
"Read help</center></b></big>"), this);
52
p.setBrush(QPalette::WindowText,
53
KColorScheme(QPalette::Active, KColorScheme::Window)
54
.foreground(KColorScheme::NegativeText));
55
paranoia->setPalette(p);
57
QSizePolicy vpref(QSizePolicy::Minimum, QSizePolicy::Fixed);
59
alGroup = new QGroupBox(i18n("Enable Au&to-Login"), this);
60
alGroup->setCheckable(true);
61
alGroup->setSizePolicy(vpref);
62
QVBoxLayout *laygroup2 = new QVBoxLayout(alGroup);
63
laygroup2->setSpacing(KDialog::spacingHint());
65
alGroup->setWhatsThis(i18n("Turn on the auto-login feature."
66
" This applies only to KDM's graphical login."
67
" Think twice before enabling this!"));
68
connect(alGroup, SIGNAL(toggled(bool)), SIGNAL(changed()));
70
userlb = new KComboBox(alGroup);
72
QLabel *u_label = new QLabel(i18n("Use&r:"), alGroup);
73
u_label->setBuddy(userlb);
74
QHBoxLayout *hlpl1 = new QHBoxLayout();
75
laygroup2->addItem(hlpl1);
76
hlpl1->setSpacing(KDialog::spacingHint());
77
hlpl1->addWidget(u_label);
78
hlpl1->addWidget(userlb);
80
connect(userlb, SIGNAL(highlighted(int)), SIGNAL(changed()));
81
wtstr = i18n("Select the user to be logged in automatically.");
82
u_label->setWhatsThis(wtstr);
83
userlb->setWhatsThis(wtstr);
84
autoLockCheck = new QCheckBox(i18n("Loc&k session"), alGroup);
85
laygroup2->addWidget(autoLockCheck);
86
connect(autoLockCheck, SIGNAL(toggled(bool)), SIGNAL(changed()));
87
autoLockCheck->setWhatsThis(i18n(
88
"The automatically started session "
89
"will be locked immediately (provided it is a KDE session). This can "
90
"be used to obtain a super-fast login restricted to one user."));
92
puGroup = new QGroupBox(i18nc("@title:group", "Preselect User"), this);
94
puGroup->setSizePolicy(vpref);
96
npRadio = new QRadioButton(i18nc("@option:radio preselected user", "&None"), puGroup);
97
ppRadio = new QRadioButton(i18nc("@option:radio preselected user", "Prev&ious"), puGroup);
98
ppRadio->setWhatsThis(i18n(
99
"Preselect the user that logged in previously. "
100
"Use this if this computer is usually used several consecutive times by one user."));
101
spRadio = new QRadioButton(i18nc("@option:radio preselected user", "Specifi&ed:"), puGroup);
102
spRadio->setWhatsThis(i18n(
103
"Preselect the user specified in the combo box to the right. "
104
"Use this if this computer is predominantly used by a certain user."));
105
QButtonGroup *buttonGroup = new QButtonGroup(puGroup);
106
connect(buttonGroup, SIGNAL(buttonClicked(int)), SLOT(slotPresChanged()));
107
connect(buttonGroup, SIGNAL(buttonClicked(int)), SIGNAL(changed()));
108
buttonGroup->addButton(npRadio);
109
buttonGroup->addButton(ppRadio);
110
buttonGroup->addButton(spRadio);
111
QVBoxLayout *laygroup5 = new QVBoxLayout(puGroup);
112
laygroup5->setSpacing(KDialog::spacingHint());
113
laygroup5->addWidget(npRadio);
114
laygroup5->addWidget(ppRadio);
116
puserlb = new KComboBox(true, puGroup);
118
connect(puserlb, SIGNAL(editTextChanged(const QString &)), SIGNAL(changed()));
120
"Select the user to be preselected for login. "
121
"This box is editable, so you can specify an arbitrary non-existent "
122
"user to mislead possible attackers.");
123
puserlb->setWhatsThis(wtstr);
124
QBoxLayout *hlpl = new QHBoxLayout();
125
laygroup5->addItem(hlpl);
126
hlpl->setSpacing(KDialog::spacingHint());
128
hlpl->addWidget(spRadio);
129
hlpl->addWidget(puserlb);
131
// This is needed before the abuse below to ensure the combo is enabled in time
132
connect(spRadio, SIGNAL(clicked(bool)), SLOT(slotPresChanged()));
133
// Abuse the radio button text as a label for the combo
134
connect(spRadio, SIGNAL(clicked(bool)), puserlb, SLOT(setFocus()));
135
cbjumppw = new QCheckBox(i18nc("@option:check action", "Focus pass&word"), puGroup);
136
laygroup5->addWidget(cbjumppw);
137
cbjumppw->setWhatsThis(i18n(
138
"When this option is on, KDM will place the cursor "
139
"in the password field instead of the user field after preselecting a user. "
140
"Use this to save one key press per login, if the preselection usually "
141
"does not need to be changed."));
142
connect(cbjumppw, SIGNAL(toggled(bool)), SIGNAL(changed()));
144
npGroup = new QGroupBox(i18n("Enable Password-&Less Logins"), this);
145
QVBoxLayout *laygroup3 = new QVBoxLayout(npGroup);
146
laygroup3->setSpacing(KDialog::spacingHint());
148
npGroup->setCheckable(true);
150
npGroup->setWhatsThis(i18n(
151
"When this option is checked, the checked users from "
152
"the list below will be allowed to log in without entering their "
153
"password. This applies only to KDM's graphical login. "
154
"Think twice before enabling this!"));
156
connect(npGroup, SIGNAL(toggled(bool)), SIGNAL(changed()));
158
QLabel *pl_label = new QLabel(i18n("No password re&quired for:"), npGroup);
159
laygroup3->addWidget(pl_label);
160
npuserlv = new QListWidget(npGroup);
161
laygroup3->addWidget(npuserlv);
162
pl_label->setBuddy(npuserlv);
163
npuserlv->setWhatsThis(i18n(
164
"Check all users you want to allow a password-less login for. "
165
"Entries denoted with '@' are user groups. Checking a group is like "
166
"checking all users in that group."));
168
btGroup = new QGroupBox(i18nc("@title:group", "Miscellaneous"), this);
169
QVBoxLayout *laygroup4 = new QVBoxLayout(btGroup);
170
laygroup4->setSpacing(KDialog::spacingHint());
172
cbarlen = new QCheckBox(i18n("Automatically log in again after &X server crash"), btGroup);
173
cbarlen->setWhatsThis(i18n(
174
"When this option is on, a user will be "
175
"logged in again automatically when their session is interrupted by an "
176
"X server crash; note that this can open a security hole: if you use "
177
"a screen locker than KDE's integrated one, this will make "
178
"circumventing a password-secured screen lock possible."));
179
//TODO a screen locker _other_ than
180
laygroup4->addWidget(cbarlen);
181
connect(cbarlen, SIGNAL(toggled(bool)), SIGNAL(changed()));
183
QGridLayout *main = new QGridLayout(this);
184
main->setSpacing(10);
185
main->addWidget(paranoia, 0, 0);
186
main->addWidget(alGroup, 1, 0);
187
main->addWidget(puGroup, 2, 0);
188
main->addWidget(npGroup, 0, 1, 4, 1);
189
main->addWidget(btGroup, 4, 0, 1, 2);
190
main->setColumnStretch(0, 1);
191
main->setColumnStretch(1, 2);
192
main->setRowStretch(3, 1);
194
connect(userlb, SIGNAL(activated(const QString &)),
195
SLOT(slotSetAutoUser(const QString &)));
196
connect(puserlb, SIGNAL(editTextChanged(const QString &)),
197
SLOT(slotSetPreselUser(const QString &)));
198
connect(npuserlv, SIGNAL(itemClicked(QListWidgetItem *)),
199
SLOT(slotUpdateNoPassUser(QListWidgetItem *)));
203
void KDMConvenienceWidget::slotPresChanged()
205
puserlb->setEnabled(spRadio->isChecked());
206
cbjumppw->setEnabled(!npRadio->isChecked());
209
void KDMConvenienceWidget::save()
211
KConfigGroup configGrp = config->group("X-:0-Core");
212
configGrp.writeEntry("AutoLoginEnable", alGroup->isChecked());
213
configGrp.writeEntry("AutoLoginUser", userlb->currentText());
214
configGrp.writeEntry("AutoLoginLocked", autoLockCheck->isChecked());
216
configGrp = config->group("X-:*-Core");
217
configGrp.writeEntry("NoPassEnable", npGroup->isChecked());
218
configGrp.writeEntry("NoPassUsers", noPassUsers);
220
config->group("X-*-Core").writeEntry("AutoReLogin", cbarlen->isChecked());
222
configGrp = config->group("X-:*-Greeter");
223
configGrp.writeEntry("PreselectUser",
224
npRadio->isChecked() ? "None" :
225
ppRadio->isChecked() ? "Previous" :
227
configGrp.writeEntry("DefaultUser", puserlb->currentText());
228
configGrp.writeEntry("FocusPasswd", cbjumppw->isChecked());
232
void KDMConvenienceWidget::load()
234
KConfigGroup configGrp = config->group("X-:0-Core");
235
bool alenable = configGrp.readEntry("AutoLoginEnable", false);
236
autoUser = configGrp.readEntry("AutoLoginUser");
237
autoLockCheck->setChecked(configGrp.readEntry("AutoLoginLocked", false));
238
if (autoUser.isEmpty())
240
alGroup->setChecked(alenable);
242
configGrp = config->group("X-:*-Core");
243
npGroup->setChecked(configGrp.readEntry("NoPassEnable", false));
244
noPassUsers = configGrp.readEntry("NoPassUsers", QStringList());
246
cbarlen->setChecked(config->group("X-*-Core").readEntry("AutoReLogin", false));
248
configGrp = config->group("X-:*-Greeter");
249
QString presstr = configGrp.readEntry("PreselectUser", "None");
250
if (presstr == "Previous")
251
ppRadio->setChecked(true);
252
else if (presstr == "Default")
253
spRadio->setChecked(true);
255
npRadio->setChecked(true);
256
preselUser = configGrp.readEntry("DefaultUser");
257
cbjumppw->setChecked(configGrp.readEntry("FocusPasswd", false));
263
void KDMConvenienceWidget::defaults()
265
alGroup->setChecked(false);
266
autoLockCheck->setChecked(false);
267
npRadio->setChecked(true);
268
npGroup->setChecked(false);
269
cbarlen->setChecked(false);
270
cbjumppw->setChecked(false);
279
void KDMConvenienceWidget::slotSetAutoUser(const QString &user)
284
void KDMConvenienceWidget::slotSetPreselUser(const QString &user)
289
void KDMConvenienceWidget::slotUpdateNoPassUser(QListWidgetItem *item)
293
int ind = noPassUsers.indexOf(item->text());
294
if (item->checkState() == Qt::Checked) {
296
noPassUsers.append(item->text());
301
noPassUsers.removeAt(ind);
307
void KDMConvenienceWidget::slotClearUsers()
312
if (!autoUser.isEmpty())
313
userlb->addItem(autoUser);
314
if (!preselUser.isEmpty())
315
puserlb->addItem(preselUser);
318
void KDMConvenienceWidget::slotAddUsers(const QMap<QString, int> &users)
320
QMap<QString, int>::const_iterator it;
321
for (it = users.begin(); it != users.end(); ++it) {
322
if (it.value() > 0) {
323
if (it.key() != autoUser)
324
userlb->addItem(it.key());
325
if (it.key() != preselUser)
326
puserlb->addItem(it.key());
328
if (it.value() != 0) {
329
QListWidgetItem *item = new QListWidgetItem(it.key(), npuserlv);
330
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled |
331
Qt::ItemIsUserCheckable);
332
item->setCheckState(noPassUsers.contains(it.key()) ?
333
Qt::Checked : Qt::Unchecked);
338
userlb->model()->sort(0);
340
if (puserlb->model())
341
puserlb->model()->sort(0);
343
npuserlv->sortItems();
345
userlb->setCurrentItem(autoUser);
346
puserlb->setCurrentItem(preselUser);
349
void KDMConvenienceWidget::slotDelUsers(const QMap<QString, int> &users)
351
QMap<QString, int>::const_iterator it;
352
for (it = users.begin(); it != users.end(); ++it) {
353
if (it.value() > 0) {
354
int idx = userlb->findText(it.key());
355
if (it.key() != autoUser && idx != -1)
356
userlb->removeItem(idx);
357
idx = puserlb->findText(it.key());
358
if (it.key() != preselUser && idx != -1)
359
puserlb->removeItem(idx);
362
delete npuserlv->findItems(it.key(), Qt::MatchExactly).first();
366
#include "kdm-conv.moc"