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"
26 #include "themer/kdmthemer.h"
27 #include "themer/kdmitem.h"
31 #include <klineedit.h>
40 class KDMPasswordEdit
: public KLineEdit
{
42 KDMPasswordEdit( QWidget
*parent
) : KLineEdit( parent
)
45 setPasswordMode(true);
47 setEchoMode( ::echoMode
? Password
: NoEcho
);
48 setContextMenuPolicy( Qt::NoContextMenu
);
52 KClassicGreeter::KClassicGreeter( KGreeterPluginHandler
*_handler
,
54 const QString
&_fixedEntity
,
55 Function _func
, Context _ctx
) :
57 KGreeterPlugin( _handler
),
58 fixedUser( _fixedEntity
),
65 QGridLayout
*grid
= 0;
68 if (!_handler
->gplugHasNode( "user-entry" ) ||
69 !_handler
->gplugHasNode( "pw-entry" ))
71 parent
= new QWidget( parent
);
72 parent
->setObjectName( "talker" );
74 grid
= new QGridLayout( parent
);
78 loginLabel
= passwdLabel
= passwd1Label
= passwd2Label
= 0;
80 passwdEdit
= passwd1Edit
= passwd2Edit
= 0;
81 if (ctx
== ExUnlock
|| ctx
== ExChangeTok
)
82 fixedUser
= KUser().loginName();
83 if (func
!= ChAuthTok
) {
84 if (fixedUser
.isEmpty()) {
85 loginEdit
= new KLineEdit( parent
);
86 loginEdit
->setContextMenuPolicy( Qt::NoContextMenu
);
87 connect( loginEdit
, SIGNAL(editingFinished()), SLOT(slotLoginLostFocus()) );
88 connect( loginEdit
, SIGNAL(editingFinished()), SLOT(slotChanged()) );
89 connect( loginEdit
, SIGNAL(textChanged( const QString
& )), SLOT(slotChanged()) );
90 connect( loginEdit
, SIGNAL(selectionChanged()), SLOT(slotChanged()) );
92 loginEdit
->setObjectName( "user-entry" );
93 widgetList
<< loginEdit
;
95 loginLabel
= new QLabel( i18n("&Username:"), parent
);
96 loginLabel
->setBuddy( loginEdit
);
97 grid
->addWidget( loginLabel
, line
, 0 );
98 grid
->addWidget( loginEdit
, line
++, 1 );
100 } else if (ctx
!= Login
&& ctx
!= Shutdown
&& grid
) {
101 loginLabel
= new QLabel( i18n("Username:"), parent
);
102 grid
->addWidget( loginLabel
, line
, 0 );
103 grid
->addWidget( new QLabel( fixedUser
, parent
), line
++, 1 );
105 passwdEdit
= new KDMPasswordEdit( parent
);
106 connect( passwdEdit
, SIGNAL(textChanged( const QString
& )),
107 SLOT(slotChanged()) );
108 connect( passwdEdit
, SIGNAL(editingFinished()), SLOT(slotChanged()) );
110 passwdEdit
->setObjectName( "pw-entry" );
111 widgetList
<< passwdEdit
;
113 passwdLabel
= new QLabel( func
== Authenticate
?
115 i18n("Current &password:"),
117 passwdLabel
->setBuddy( passwdEdit
);
118 grid
->addWidget( passwdLabel
, line
, 0 );
119 grid
->addWidget( passwdEdit
, line
++, 1 );
122 loginEdit
->setFocus();
124 passwdEdit
->setFocus();
126 if (func
!= Authenticate
) {
127 passwd1Edit
= new KDMPasswordEdit( parent
);
128 passwd1Label
= new QLabel( i18n("&New password:"), parent
);
129 passwd1Label
->setBuddy( passwd1Edit
);
130 passwd2Edit
= new KDMPasswordEdit( parent
);
131 passwd2Label
= new QLabel( i18n("Con&firm password:"), parent
);
132 passwd2Label
->setBuddy( passwd2Edit
);
134 grid
->addWidget( passwd1Label
, line
, 0 );
135 grid
->addWidget( passwd1Edit
, line
++, 1 );
136 grid
->addWidget( passwd2Label
, line
, 0 );
137 grid
->addWidget( passwd2Edit
, line
, 1 );
140 passwd1Edit
->setFocus();
145 KClassicGreeter::~KClassicGreeter()
148 qDeleteAll( widgetList
);
152 KClassicGreeter::loadUsers( const QStringList
&users
)
154 KCompletion
*userNamesCompletion
= new KCompletion
;
155 userNamesCompletion
->setItems( users
);
156 loginEdit
->setCompletionObject( userNamesCompletion
);
157 loginEdit
->setAutoDeleteCompletionObject( true );
158 loginEdit
->setCompletionMode( KGlobalSettings::CompletionAuto
);
162 KClassicGreeter::presetEntity( const QString
&entity
, int field
)
164 loginEdit
->setText( entity
);
166 passwdEdit
->setFocus();
168 loginEdit
->setFocus();
169 loginEdit
->selectAll();
171 passwdEdit
->setText( " " );
172 passwdEdit
->setEnabled( false );
180 KClassicGreeter::getEntity() const
182 return fixedUser
.isEmpty() ? loginEdit
->text() : fixedUser
;
186 KClassicGreeter::setUser( const QString
&user
)
188 // assert( fixedUser.isEmpty() );
190 loginEdit
->setText( user
);
191 passwdEdit
->setFocus();
192 passwdEdit
->selectAll();
196 KClassicGreeter::setEnabled( bool enable
)
198 // assert( !passwd1Label );
199 // assert( func == Authenticate && ctx == Shutdown );
201 // loginLabel->setEnabled( enable );
202 passwdLabel
->setEnabled( enable
);
205 passwdEdit
->setFocus();
209 KClassicGreeter::returnData()
213 handler
->gplugReturnText( (loginEdit
? loginEdit
->text() :
214 fixedUser
).toLocal8Bit(),
215 KGreeterPluginHandler::IsUser
);
218 Q_ASSERT(passwdEdit
);
219 handler
->gplugReturnText( passwdEdit
->text().toLocal8Bit() ,
220 KGreeterPluginHandler::IsPassword
|
221 KGreeterPluginHandler::IsSecret
);
224 Q_ASSERT(passwd1Edit
);
225 handler
->gplugReturnText( passwd1Edit
->text().toLocal8Bit(),
226 KGreeterPluginHandler::IsSecret
);
229 Q_ASSERT(passwd2Edit
);
230 handler
->gplugReturnText( passwd2Edit
->text().toLocal8Bit(),
231 KGreeterPluginHandler::IsNewPassword
|
232 KGreeterPluginHandler::IsSecret
);
238 KClassicGreeter::textMessage( const char *text
, bool err
)
241 QString( text
).indexOf( QRegExp( "^Changing password for [^ ]+$" ) ) >= 0)
247 KClassicGreeter::textPrompt( const char *prompt
, bool echo
, bool nonBlocking
)
255 QString
pr( prompt
);
256 if (pr
.indexOf( QRegExp( "\\bpassword\\b", Qt::CaseInsensitive
) ) >= 0) {
257 if (pr
.indexOf( QRegExp( "\\b(re-?(enter|type)|again|confirm|repeat)\\b",
258 Qt::CaseInsensitive
) ) >= 0)
260 else if (pr
.indexOf( QRegExp( "\\bnew\\b", Qt::CaseInsensitive
) ) >= 0)
262 else { // QRegExp( "\\b(old|current)\\b", Qt::CaseInsensitive ) is too strict
263 handler
->gplugReturnText( "",
264 KGreeterPluginHandler::IsOldPassword
|
265 KGreeterPluginHandler::IsSecret
);
269 handler
->gplugMsgBox( QMessageBox::Critical
,
270 i18n("Unrecognized prompt \"%1\"",
272 handler
->gplugReturnText( 0, 0 );
278 if (pExp
>= 0 && pExp
>= exp
) {
283 if (has
>= exp
|| nonBlocking
)
288 KClassicGreeter::binaryPrompt( const char *, bool )
290 // this simply cannot happen ... :}
295 KClassicGreeter::start()
297 authTok
= !(passwdEdit
&& passwdEdit
->isEnabled());
303 KClassicGreeter::suspend()
308 KClassicGreeter::resume()
313 KClassicGreeter::next()
315 // assert( running );
316 if (loginEdit
&& loginEdit
->hasFocus()) {
317 passwdEdit
->setFocus(); // will cancel running login if necessary
319 } else if (passwdEdit
&& passwdEdit
->hasFocus()) {
321 passwd1Edit
->setFocus();
323 } else if (passwd1Edit
) {
324 if (passwd1Edit
->hasFocus()) {
325 passwd2Edit
->setFocus();
332 handler
->gplugStart();
338 KClassicGreeter::abort()
343 handler
->gplugReturnText( 0, 0 );
348 KClassicGreeter::succeeded()
350 // assert( running || timed_login );
364 KClassicGreeter::failed()
366 // assert( running || timed_login );
374 KClassicGreeter::revive()
376 // assert( !running );
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();
413 KClassicGreeter::setActive( bool enable
)
416 loginEdit
->setEnabled( enable
);
418 passwdEdit
->setEnabled( enable
);
422 KClassicGreeter::setActive2( bool enable
)
425 passwd1Edit
->setEnabled( enable
);
426 passwd2Edit
->setEnabled( enable
);
431 KClassicGreeter::slotLoginLostFocus()
435 loginEdit
->setText( loginEdit
->text().trimmed() );
437 if (curUser
== loginEdit
->text())
440 handler
->gplugReturnText( 0, 0 );
442 curUser
= loginEdit
->text();
443 handler
->gplugSetUser( curUser
);
447 KClassicGreeter::slotChanged()
450 handler
->gplugChanged();
455 static bool init( const QString
&,
456 QVariant (*getConf
)( void *, const char *, const QVariant
& ),
459 echoMode
= getConf( ctx
, "EchoPasswd", QVariant( -1 ) ).toInt();
460 KGlobal::locale()->insertCatalog( "kgreet_classic" );
464 static void done( void )
466 KGlobal::locale()->removeCatalog( "kgreet_classic" );
469 static KGreeterPlugin
*
470 create( KGreeterPluginHandler
*handler
,
472 const QString
&fixedEntity
,
473 KGreeterPlugin::Function func
,
474 KGreeterPlugin::Context ctx
)
476 return new KClassicGreeter( handler
, parent
, fixedEntity
, func
, ctx
);
479 KDE_EXPORT KGreeterPluginInfo kgreeterplugin_info
= {
480 I18N_NOOP2("@item:inmenu authentication method", "Username + password (classic)"), "classic",
481 KGreeterPluginInfo::Local
| KGreeterPluginInfo::Presettable
,
485 #include "kgreet_classic.moc"