~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kdm/kcm/kdm-conv.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (C) 2000 Oswald Buddenhagen <ossi@kde.org>
 
3
    Based on several other files.
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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.
 
19
*/
 
20
 
 
21
#include "kdm-conv.h"
 
22
 
 
23
#include <KColorScheme>
 
24
#include <KComboBox>
 
25
#include <KDialog>
 
26
#include <KLocale>
 
27
#include <KConfig>
 
28
#include <KConfigGroup>
 
29
 
 
30
#include <QButtonGroup>
 
31
#include <QCheckBox>
 
32
#include <QGroupBox>
 
33
#include <QLabel>
 
34
#include <QListWidget>
 
35
#include <QRadioButton>
 
36
#include <QGridLayout>
 
37
#include <QHBoxLayout>
 
38
#include <QVBoxLayout>
 
39
 
 
40
extern KConfig *config;
 
41
 
 
42
 
 
43
KDMConvenienceWidget::KDMConvenienceWidget(QWidget *parent)
 
44
    : QWidget(parent)
 
45
{
 
46
    QString wtstr;
 
47
 
 
48
    QLabel *paranoia = new QLabel(
 
49
        i18n("<big><b><center>Attention<br/>"
 
50
             "Read help</center></b></big>"), this);
 
51
    QPalette p;
 
52
    p.setBrush(QPalette::WindowText,
 
53
        KColorScheme(QPalette::Active, KColorScheme::Window)
 
54
            .foreground(KColorScheme::NegativeText));
 
55
    paranoia->setPalette(p);
 
56
 
 
57
    QSizePolicy vpref(QSizePolicy::Minimum, QSizePolicy::Fixed);
 
58
 
 
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());
 
64
 
 
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()));
 
69
 
 
70
    userlb = new KComboBox(alGroup);
 
71
 
 
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);
 
79
    hlpl1->addStretch(1);
 
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."));
 
91
 
 
92
    puGroup = new QGroupBox(i18nc("@title:group", "Preselect User"), this);
 
93
 
 
94
    puGroup->setSizePolicy(vpref);
 
95
 
 
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);
 
115
 
 
116
    puserlb = new KComboBox(true, puGroup);
 
117
 
 
118
    connect(puserlb, SIGNAL(editTextChanged(const QString &)), SIGNAL(changed()));
 
119
    wtstr = i18n(
 
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());
 
127
    hlpl->setMargin(0);
 
128
    hlpl->addWidget(spRadio);
 
129
    hlpl->addWidget(puserlb);
 
130
    hlpl->addStretch(1);
 
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()));
 
143
 
 
144
    npGroup = new QGroupBox(i18n("Enable Password-&Less Logins"), this);
 
145
    QVBoxLayout *laygroup3 = new QVBoxLayout(npGroup);
 
146
    laygroup3->setSpacing(KDialog::spacingHint());
 
147
 
 
148
    npGroup->setCheckable(true);
 
149
 
 
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!"));
 
155
 
 
156
    connect(npGroup, SIGNAL(toggled(bool)), SIGNAL(changed()));
 
157
 
 
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."));
 
167
 
 
168
    btGroup = new QGroupBox(i18nc("@title:group", "Miscellaneous"), this);
 
169
    QVBoxLayout *laygroup4 = new QVBoxLayout(btGroup);
 
170
    laygroup4->setSpacing(KDialog::spacingHint());
 
171
 
 
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()));
 
182
 
 
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);
 
193
 
 
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 *)));
 
200
 
 
201
}
 
202
 
 
203
void KDMConvenienceWidget::slotPresChanged()
 
204
{
 
205
    puserlb->setEnabled(spRadio->isChecked());
 
206
    cbjumppw->setEnabled(!npRadio->isChecked());
 
207
}
 
208
 
 
209
void KDMConvenienceWidget::save()
 
210
{
 
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());
 
215
 
 
216
    configGrp = config->group("X-:*-Core");
 
217
    configGrp.writeEntry("NoPassEnable", npGroup->isChecked());
 
218
    configGrp.writeEntry("NoPassUsers", noPassUsers);
 
219
 
 
220
    config->group("X-*-Core").writeEntry("AutoReLogin", cbarlen->isChecked());
 
221
 
 
222
    configGrp = config->group("X-:*-Greeter");
 
223
    configGrp.writeEntry("PreselectUser",
 
224
                         npRadio->isChecked() ? "None" :
 
225
                         ppRadio->isChecked() ? "Previous" :
 
226
                         "Default");
 
227
    configGrp.writeEntry("DefaultUser", puserlb->currentText());
 
228
    configGrp.writeEntry("FocusPasswd", cbjumppw->isChecked());
 
229
}
 
230
 
 
231
 
 
232
void KDMConvenienceWidget::load()
 
233
{
 
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())
 
239
        alenable = false;
 
240
    alGroup->setChecked(alenable);
 
241
 
 
242
    configGrp = config->group("X-:*-Core");
 
243
    npGroup->setChecked(configGrp.readEntry("NoPassEnable", false));
 
244
    noPassUsers = configGrp.readEntry("NoPassUsers", QStringList());
 
245
 
 
246
    cbarlen->setChecked(config->group("X-*-Core").readEntry("AutoReLogin", false));
 
247
 
 
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);
 
254
    else
 
255
        npRadio->setChecked(true);
 
256
    preselUser = configGrp.readEntry("DefaultUser");
 
257
    cbjumppw->setChecked(configGrp.readEntry("FocusPasswd", false));
 
258
 
 
259
    slotPresChanged();
 
260
}
 
261
 
 
262
 
 
263
void KDMConvenienceWidget::defaults()
 
264
{
 
265
    alGroup->setChecked(false);
 
266
    autoLockCheck->setChecked(false);
 
267
    npRadio->setChecked(true);
 
268
    npGroup->setChecked(false);
 
269
    cbarlen->setChecked(false);
 
270
    cbjumppw->setChecked(false);
 
271
    autoUser = "";
 
272
    preselUser = "";
 
273
    noPassUsers.clear();
 
274
 
 
275
    slotPresChanged();
 
276
}
 
277
 
 
278
 
 
279
void KDMConvenienceWidget::slotSetAutoUser(const QString &user)
 
280
{
 
281
    autoUser = user;
 
282
}
 
283
 
 
284
void KDMConvenienceWidget::slotSetPreselUser(const QString &user)
 
285
{
 
286
    preselUser = user;
 
287
}
 
288
 
 
289
void KDMConvenienceWidget::slotUpdateNoPassUser(QListWidgetItem *item)
 
290
{
 
291
    if (!item)
 
292
        return;
 
293
    int ind = noPassUsers.indexOf(item->text());
 
294
    if (item->checkState() == Qt::Checked) {
 
295
        if (ind < 0) {
 
296
            noPassUsers.append(item->text());
 
297
            emit changed();
 
298
        }
 
299
    } else {
 
300
        if (ind >= 0) {
 
301
            noPassUsers.removeAt(ind);
 
302
            emit changed();
 
303
        }
 
304
    }
 
305
}
 
306
 
 
307
void KDMConvenienceWidget::slotClearUsers()
 
308
{
 
309
    userlb->clear();
 
310
    puserlb->clear();
 
311
    npuserlv->clear();
 
312
    if (!autoUser.isEmpty())
 
313
        userlb->addItem(autoUser);
 
314
    if (!preselUser.isEmpty())
 
315
        puserlb->addItem(preselUser);
 
316
}
 
317
 
 
318
void KDMConvenienceWidget::slotAddUsers(const QMap<QString, int> &users)
 
319
{
 
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());
 
327
        }
 
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);
 
334
        }
 
335
    }
 
336
 
 
337
    if (userlb->model())
 
338
        userlb->model()->sort(0);
 
339
 
 
340
    if (puserlb->model())
 
341
        puserlb->model()->sort(0);
 
342
 
 
343
    npuserlv->sortItems();
 
344
 
 
345
    userlb->setCurrentItem(autoUser);
 
346
    puserlb->setCurrentItem(preselUser);
 
347
}
 
348
 
 
349
void KDMConvenienceWidget::slotDelUsers(const QMap<QString, int> &users)
 
350
{
 
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);
 
360
        }
 
361
        if (it.value() != 0)
 
362
            delete npuserlv->findItems(it.key(), Qt::MatchExactly).first();
 
363
    }
 
364
}
 
365
 
 
366
#include "kdm-conv.moc"