3
Conversation widget for kdm greeter
5
Copyright (C) 1997, 1998, 2000 Steffen Hansen <hansen@kde.org>
6
Copyright (C) 2000-2003 Oswald Buddenhagen <ossi@kde.org>
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
#include "kgreet_classic.h"
29
#include <klineedit.h>
38
class KDMPasswordEdit : public KLineEdit {
40
KDMPasswordEdit(QWidget *parent) : KLineEdit(parent)
43
setPasswordMode(true);
45
setEchoMode(::echoMode ? Password : NoEcho);
46
setContextMenuPolicy(Qt::NoContextMenu);
50
KClassicGreeter::KClassicGreeter(KGreeterPluginHandler *_handler,
52
const QString &_fixedEntity,
53
Function _func, Context _ctx) :
55
KGreeterPlugin(_handler),
56
fixedUser(_fixedEntity),
63
QGridLayout *grid = 0;
66
if (!_handler->gplugHasNode("user-entry") ||
67
!_handler->gplugHasNode("pw-entry"))
69
parent = new QWidget(parent);
70
parent->setObjectName("talker");
72
grid = new QGridLayout(parent);
76
loginLabel = passwdLabel = passwd1Label = passwd2Label = 0;
78
passwdEdit = passwd1Edit = passwd2Edit = 0;
79
if (ctx == ExUnlock || ctx == ExChangeTok)
80
fixedUser = KUser().loginName();
81
if (func != ChAuthTok) {
82
if (fixedUser.isEmpty()) {
83
loginEdit = new KLineEdit(parent);
84
loginEdit->setContextMenuPolicy(Qt::NoContextMenu);
85
connect(loginEdit, SIGNAL(editingFinished()), SLOT(slotLoginLostFocus()));
86
connect(loginEdit, SIGNAL(editingFinished()), SLOT(slotChanged()));
87
connect(loginEdit, SIGNAL(textChanged(const QString &)), SLOT(slotChanged()));
88
connect(loginEdit, SIGNAL(selectionChanged()), SLOT(slotChanged()));
90
loginEdit->setObjectName("user-entry");
91
widgetList << loginEdit;
93
loginLabel = new QLabel(i18n("&Username:"), parent);
94
loginLabel->setBuddy(loginEdit);
95
grid->addWidget(loginLabel, line, 0);
96
grid->addWidget(loginEdit, line++, 1);
98
} else if (ctx != Login && ctx != Shutdown && grid) {
99
loginLabel = new QLabel(i18n("Username:"), parent);
100
grid->addWidget(loginLabel, line, 0);
101
grid->addWidget(new QLabel(fixedUser, parent), line++, 1);
103
passwdEdit = new KDMPasswordEdit(parent);
104
connect(passwdEdit, SIGNAL(textChanged(const QString &)),
105
SLOT(slotChanged()));
106
connect(passwdEdit, SIGNAL(editingFinished()), SLOT(slotChanged()));
108
passwdEdit->setObjectName("pw-entry");
109
widgetList << passwdEdit;
111
passwdLabel = new QLabel(func == Authenticate ?
113
i18n("Current &password:"),
115
passwdLabel->setBuddy(passwdEdit);
116
grid->addWidget(passwdLabel, line, 0);
117
grid->addWidget(passwdEdit, line++, 1);
120
loginEdit->setFocus();
122
passwdEdit->setFocus();
124
if (func != Authenticate) {
125
passwd1Edit = new KDMPasswordEdit(parent);
126
passwd1Label = new QLabel(i18n("&New password:"), parent);
127
passwd1Label->setBuddy(passwd1Edit);
128
passwd2Edit = new KDMPasswordEdit(parent);
129
passwd2Label = new QLabel(i18n("Con&firm password:"), parent);
130
passwd2Label->setBuddy(passwd2Edit);
132
grid->addWidget(passwd1Label, line, 0);
133
grid->addWidget(passwd1Edit, line++, 1);
134
grid->addWidget(passwd2Label, line, 0);
135
grid->addWidget(passwd2Edit, line, 1);
138
passwd1Edit->setFocus();
143
KClassicGreeter::~KClassicGreeter()
146
qDeleteAll(widgetList);
150
KClassicGreeter::loadUsers(const QStringList &users)
152
KCompletion *userNamesCompletion = new KCompletion;
153
userNamesCompletion->setItems(users);
154
loginEdit->setCompletionObject(userNamesCompletion);
155
loginEdit->setAutoDeleteCompletionObject(true);
156
loginEdit->setCompletionMode(KGlobalSettings::CompletionAuto);
160
KClassicGreeter::presetEntity(const QString &entity, int field)
162
loginEdit->setText(entity);
164
passwdEdit->setFocus();
166
loginEdit->setFocus();
167
loginEdit->selectAll();
169
passwdEdit->setText(" ");
170
passwdEdit->setEnabled(false);
178
KClassicGreeter::getEntity() const
180
return fixedUser.isEmpty() ? loginEdit->text() : fixedUser;
184
KClassicGreeter::setUser(const QString &user)
186
// assert(fixedUser.isEmpty());
188
loginEdit->setText(user);
189
passwdEdit->setFocus();
190
passwdEdit->selectAll();
194
KClassicGreeter::setEnabled(bool enable)
196
// assert(!passwd1Label);
197
// assert(func == Authenticate && ctx == Shutdown);
199
// loginLabel->setEnabled(enable);
200
passwdLabel->setEnabled(enable);
203
passwdEdit->setFocus();
207
KClassicGreeter::returnData()
211
handler->gplugReturnText((loginEdit ? loginEdit->text() :
212
fixedUser).toLocal8Bit(),
213
KGreeterPluginHandler::IsUser);
216
Q_ASSERT(passwdEdit);
217
handler->gplugReturnText(passwdEdit->text().toLocal8Bit() ,
218
KGreeterPluginHandler::IsPassword |
219
KGreeterPluginHandler::IsSecret);
222
Q_ASSERT(passwd1Edit);
223
handler->gplugReturnText(passwd1Edit->text().toLocal8Bit(),
224
KGreeterPluginHandler::IsSecret);
227
Q_ASSERT(passwd2Edit);
228
handler->gplugReturnText(passwd2Edit->text().toLocal8Bit(),
229
KGreeterPluginHandler::IsNewPassword |
230
KGreeterPluginHandler::IsSecret);
236
KClassicGreeter::textMessage(const char *text, bool err)
239
QString(text).indexOf(QRegExp("^Changing password for [^ ]+$")) >= 0)
245
KClassicGreeter::textPrompt(const char *prompt, bool echo, bool nonBlocking)
250
} else if (!authTok) {
254
if (pr.indexOf(QRegExp("\\bpassword\\b", Qt::CaseInsensitive)) >= 0) {
255
if (pr.indexOf(QRegExp("\\b(re-?(enter|type)|again|confirm|repeat)\\b",
256
Qt::CaseInsensitive)) >= 0) {
258
} else if (pr.indexOf(QRegExp("\\bnew\\b", Qt::CaseInsensitive)) >= 0) {
260
} else { // QRegExp("\\b(old|current)\\b", Qt::CaseInsensitive) is too strict
261
handler->gplugReturnText("", KGreeterPluginHandler::IsOldPassword |
262
KGreeterPluginHandler::IsSecret);
266
handler->gplugMsgBox(QMessageBox::Critical,
267
i18n("Unrecognized prompt \"%1\"", prompt));
268
handler->gplugReturnText(0, 0);
274
if (pExp >= 0 && pExp >= exp) {
279
if (has >= exp || nonBlocking)
284
KClassicGreeter::binaryPrompt(const char *, bool)
286
// this simply cannot happen ... :}
291
KClassicGreeter::start()
293
authTok = !(passwdEdit && passwdEdit->isEnabled());
299
KClassicGreeter::suspend()
304
KClassicGreeter::resume()
309
KClassicGreeter::next()
313
if (loginEdit && loginEdit->hasFocus()) {
314
passwdEdit->setFocus(); // will cancel running login if necessary
316
} else if (passwdEdit && passwdEdit->hasFocus()) {
318
passwd1Edit->setFocus();
320
} else if (passwd1Edit) {
321
if (passwd1Edit->hasFocus()) {
322
passwd2Edit->setFocus();
331
handler->gplugStart();
332
else if (has >= exp && has > pHas)
337
KClassicGreeter::abort()
342
handler->gplugReturnText(0, 0);
347
KClassicGreeter::succeeded()
349
// assert(running || timed_login);
364
KClassicGreeter::failed()
366
// assert(running || timed_login);
374
KClassicGreeter::revive()
379
passwd1Edit->clear();
380
passwd2Edit->clear();
381
passwd1Edit->setFocus();
384
if (loginEdit && loginEdit->isEnabled()) {
385
passwdEdit->setEnabled(true);
388
if (loginEdit && loginEdit->text().isEmpty())
389
loginEdit->setFocus();
391
passwdEdit->setFocus();
397
KClassicGreeter::clear()
399
// assert(!running && !passwd1Edit);
403
loginEdit->setFocus();
406
passwdEdit->setFocus();
414
KClassicGreeter::setActive(bool enable)
417
loginEdit->setEnabled(enable);
419
passwdEdit->setEnabled(enable);
423
KClassicGreeter::setActive2(bool enable)
426
passwd1Edit->setEnabled(enable);
427
passwd2Edit->setEnabled(enable);
432
KClassicGreeter::slotLoginLostFocus()
436
loginEdit->setText(loginEdit->text().trimmed());
438
if (curUser == loginEdit->text())
441
handler->gplugReturnText(0, 0);
443
curUser = loginEdit->text();
444
handler->gplugSetUser(curUser);
448
KClassicGreeter::slotChanged()
451
handler->gplugChanged();
456
static bool init(const QString &,
457
QVariant(*getConf)(void *, const char *, const QVariant &),
460
echoMode = getConf(ctx, "EchoPasswd", QVariant(-1)).toInt();
461
KGlobal::locale()->insertCatalog("kgreet_classic");
465
static void done(void)
467
KGlobal::locale()->removeCatalog("kgreet_classic");
470
static KGreeterPlugin *
471
create(KGreeterPluginHandler *handler,
473
const QString &fixedEntity,
474
KGreeterPlugin::Function func,
475
KGreeterPlugin::Context ctx)
477
return new KClassicGreeter(handler, parent, fixedEntity, func, ctx);
480
KDE_EXPORT KGreeterPluginInfo kgreeterplugin_info = {
481
I18N_NOOP2("@item:inmenu authentication method", "Username + password (classic)"), "classic",
482
KGreeterPluginInfo::Local | KGreeterPluginInfo::Presettable,
486
#include "kgreet_classic.moc"