3 Shell for kdm conversation plugins
5 Copyright (C) 1997, 1998, 2000 Steffen Hansen <hansen@kde.org>
6 Copyright (C) 2000-2004 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 <config-workspace.h>
28 #include "kdmconfig.h"
29 #include "kdm_greet.h"
31 #include "themer/kdmthemer.h"
32 #include "themer/kdmitem.h"
34 #include <KColorScheme>
38 #include <kpushbutton.h>
40 #include <kseparator.h>
41 #include <KStandardGuiItem>
44 #include <QApplication>
51 #include <X11/Xlib.h> // for updateLockStatus()
52 #include <fixx11h.h> // ... and make eventFilter() work again
54 #define FULL_GREET_TO 40 // normal inactivity timeout
55 #define TIMED_GREET_TO 20 // inactivity timeout when persisting timed login
56 #define MIN_TIMED_TO 5 // minimal timed login delay
57 #define DEAD_TIMED_TO 2 // <enter> dead time after re-activating timed login
58 #define SECONDS 1000 // reduce to 100 to speed up testing
60 void KGVerifyHandler::verifyClear()
64 void KGVerifyHandler::updateStatus( bool, bool, int )
68 KGVerify::KGVerify( KGVerifyHandler
*_handler
,
69 QWidget
*_parent
, QWidget
*_predecessor
,
70 const QString
&_fixedUser
,
71 const PluginList
&_pluginList
,
72 KGreeterPlugin::Function _func
,
73 KGreeterPlugin::Context _ctx
)
76 , fixedEntity( _fixedUser
)
77 , pluginList( _pluginList
)
80 , predecessor( _predecessor
)
92 connect( &timer
, SIGNAL(timeout()), SLOT(slotTimeout()) );
93 connect( qApp
, SIGNAL(activity()), SLOT(slotActivity()) );
95 _parent
->installEventFilter( this );
100 debug( "delete %s\n", pName
.data() );
105 KGVerify::getPlugMenu()
109 uint np
= pluginList
.count();
111 plugMenu
= new QMenu( parent
);
112 QActionGroup
*plugGroup
= new QActionGroup( parent
);
113 connect( plugMenu
, SIGNAL(triggered( QAction
* )),
114 SLOT(slotPluginSelected( QAction
* )) );
115 for (uint i
= 0; i
< np
; i
++) {
116 int pid
= pluginList
[i
];
117 greetPlugins
[pid
].action
= plugGroup
->addAction(
118 i18nc("@item:inmenu authentication method",
119 greetPlugins
[pid
].info
->name
) );
120 greetPlugins
[pid
].action
->setData( i
);
121 greetPlugins
[pid
].action
->setCheckable( true );
123 plugMenu
->addActions( plugGroup
->actions() );
130 KGVerify::entitiesLocal() const
132 return greetPlugins
[pluginList
[curPlugin
]].info
->flags
& KGreeterPluginInfo::Local
;
136 KGVerify::entitiesFielded() const
138 return greetPlugins
[pluginList
[curPlugin
]].info
->flags
& KGreeterPluginInfo::Fielded
;
142 KGVerify::entityPresettable() const
144 return greetPlugins
[pluginList
[curPlugin
]].info
->flags
& KGreeterPluginInfo::Presettable
;
148 KGVerify::isClassic() const
150 return !strcmp( greetPlugins
[pluginList
[curPlugin
]].info
->method
, "classic" );
154 KGVerify::pluginName() const
156 QString
name( greetPlugins
[pluginList
[curPlugin
]].library
->fileName() );
157 uint st
= name
.lastIndexOf( '/' ) + 1;
158 uint en
= name
.indexOf( '.', st
);
159 if (en
- st
> 7 && QString::fromRawData( name
.unicode() + st
, 7 ) == QLatin1String("kgreet_"))
161 return name
.mid( st
, en
- st
);
165 setTabOrder( QWidget
*&pred
, const QObjectList
&list
)
167 foreach (QObject
*o
, list
)
168 if (QWidget
*w
= qobject_cast
<QWidget
*>(o
)) {
169 if (w
->focusPolicy() & Qt::TabFocus
) {
170 QWidget::setTabOrder( pred
, w
);
173 setTabOrder( pred
, o
->children() );
178 KGVerify::selectPlugin( int id
)
180 if (pluginList
.isEmpty()) {
181 msgBox( errorbox
, i18n("No greeter widget plugin loaded. Check the configuration.") );
182 ::exit( EX_UNMANAGE_DPY
);
186 greetPlugins
[pluginList
[id
]].action
->setChecked( true );
187 pName
= ("greet_" + pluginName()).toLatin1();
188 debug( "new %s\n", pName
.data() );
189 greet
= greetPlugins
[pluginList
[id
]].info
->create( this, parent
, fixedEntity
, func
, ctx
);
190 if (QWidget
*pred
= predecessor
)
191 setTabOrder( pred
, *(const QObjectList
*)&greet
->getWidgets() );
192 timeable
= _autoLoginDelay
&& entityPresettable() && isClassic();
196 KGVerify::slotPluginSelected( QAction
*action
)
200 int id
= action
->data().toInt();
201 if (id
!= curPlugin
) {
202 parent
->setUpdatesEnabled( false );
203 debug( "delete %s\n", pName
.data() );
206 handler
->verifyPluginChanged( id
);
209 parent
->setUpdatesEnabled( true );
214 KGVerify::loadUsers( const QStringList
&users
)
216 debug( "%s->loadUsers(...)\n", pName
.data() );
217 greet
->loadUsers( users
);
221 KGVerify::presetEntity( const QString
&entity
, int field
)
228 KGVerify::applyPreset()
230 if (!presEnt
.isEmpty()) {
231 debug( "%s->presetEntity(%\"s, %d)\n", pName
.data(),
232 qPrintable( presEnt
), presFld
);
233 greet
->presetEntity( presEnt
, presFld
);
234 if (entitiesLocal()) {
236 handler
->verifySetUser( presEnt
);
244 KGVerify::scheduleAutoLogin( bool initial
)
247 debug( "%s->presetEntity(%\"s, -1)\n", pName
.data(),
248 qPrintable( _autoLoginUser
), -1 );
249 greet
->presetEntity( _autoLoginUser
, -1 );
250 curUser
= _autoLoginUser
;
251 handler
->verifySetUser( _autoLoginUser
);
254 timedLeft
= _autoLoginDelay
;
257 timedLeft
= qMax( _autoLoginDelay
- TIMED_GREET_TO
, MIN_TIMED_TO
);
258 deadTicks
= DEAD_TIMED_TO
;
269 KGVerify::performAutoLogin()
272 gSendInt( G_AutoLogin
);
277 KGVerify::getEntity() const
279 debug( "%s->getEntity()\n", pName
.data() );
280 QString ent
= greet
->getEntity();
281 debug( " entity: %s\n", qPrintable( ent
) );
286 KGVerify::setUser( const QString
&user
)
288 // assert( fixedEntity.isEmpty() );
290 debug( "%s->setUser(%\"s)\n", pName
.data(), qPrintable( user
) );
291 greet
->setUser( user
);
298 authTok
= (func
== KGreeterPlugin::ChAuthTok
);
300 if (func
== KGreeterPlugin::Authenticate
&& ctx
== KGreeterPlugin::Login
) {
301 if (scheduleAutoLogin( true )) {
302 if (!_autoLoginAgain
)
303 _autoLoginDelay
= 0, timeable
= false;
309 if (!(func
== KGreeterPlugin::Authenticate
||
310 ctx
== KGreeterPlugin::ChangeTok
||
311 ctx
== KGreeterPlugin::ExChangeTok
))
315 debug( "%s->start()\n", pName
.data() );
324 debug( "%s->abort()\n", pName
.data() );
334 debug( "%s->abort()\n", pName
.data() );
349 debug( "%s->start()\n", pName
.data() );
351 } else if (delayed
) {
354 debug( "%s->start()\n", pName
.data() );
359 void // not a slot - called manually by greeter
362 debug( "%s->next()\n", pName
.data() );
367 KGVerify::doReject( bool initial
)
371 debug( "%s->abort()\n", pName
.data() );
374 handler
->verifyClear();
375 debug( "%s->clear()\n", pName
.data() );
378 if (!scheduleAutoLogin( initial
)) {
379 isClear
= !(isClear
&& applyPreset());
381 debug( "%s->start()\n", pName
.data() );
389 void // not a slot - called manually by greeter
396 KGVerify::setEnabled( bool on
)
398 debug( "%s->setEnabled(%s)\n", pName
.data(), on
? "true" : "false" );
399 greet
->setEnabled( on
);
405 KGVerify::slotTimeout()
410 debug( "%s->revive()\n", pName
.data() );
412 handler
->verifyRetry();
417 debug( "%s->start()\n", pName
.data() );
424 } else if (timedLeft
) {
432 // assert( ctx == Login );
439 KGVerify::slotActivity()
442 // timed login countdown running. cancel and reschedule it.
443 debug( "%s->revive()\n", pName
.data() );
445 debug( "%s->start()\n", pName
.data() );
450 timer
.start( TIMED_GREET_TO
* SECONDS
);
452 // timed login is possible and thus scheduled. reschedule it.
453 timer
.start( TIMED_GREET_TO
* SECONDS
);
457 void // private static
458 KGVerify::vrfMsgBox( QWidget
*parent
, const QString
&user
,
459 QMessageBox::Icon type
, const QString
&mesg
)
461 KFMsgBox::box( parent
, type
, user
.isEmpty() ?
462 mesg
: i18n("Logging in %1...\n\n", user
) + mesg
);
465 static const char *msgs
[]= {
466 I18N_NOOP( "You are required to change your password immediately (password aged)." ),
467 I18N_NOOP( "You are required to change your password immediately (root enforced)." ),
468 I18N_NOOP( "You are not allowed to login at the moment." ),
469 I18N_NOOP( "Home folder not available." ),
470 I18N_NOOP( "Logins are not allowed at the moment.\nTry again later." ),
471 I18N_NOOP( "Your login shell is not listed in /etc/shells." ),
472 I18N_NOOP( "Root logins are not allowed." ),
473 I18N_NOOP( "Your account has expired; please contact your system administrator." )
476 void // private static
477 KGVerify::vrfErrBox( QWidget
*parent
, const QString
&user
, const char *msg
)
479 QMessageBox::Icon icon
;
483 mesg
= i18n("A critical error occurred.\n"
484 "Please look at KDM's logfile(s) for more information\n"
485 "or contact your system administrator.");
488 mesg
= QString::fromLocal8Bit( msg
);
489 QString mesg1
= mesg
+ '.';
490 for (uint i
= 0; i
< as(msgs
); i
++)
491 if (mesg1
== msgs
[i
]) {
492 mesg
= i18n(msgs
[i
]);
497 vrfMsgBox( parent
, user
, icon
, mesg
);
500 void // private static
501 KGVerify::vrfInfoBox( QWidget
*parent
, const QString
&user
, const char *msg
)
503 QString mesg
= QString::fromLocal8Bit( msg
);
504 QRegExp
rx( "^Warning: your account will expire in (\\d+) day" );
505 if (rx
.indexIn( mesg
) >= 0) {
506 int expire
= rx
.cap( 1 ).toInt();
508 i18np("Your account expires tomorrow.",
509 "Your account expires in %1 days.", expire
) :
510 i18n("Your account expires today.");
512 rx
.setPattern( "^Warning: your password will expire in (\\d+) day" );
513 if (rx
.indexIn( mesg
) >= 0) {
514 int expire
= rx
.cap( 1 ).toInt();
516 i18np("Your password expires tomorrow.",
517 "Your password expires in %1 days.", expire
) :
518 i18n("Your password expires today.");
521 vrfMsgBox( parent
, user
, infobox
, mesg
);
524 bool // public static
525 KGVerify::handleFailVerify( QWidget
*parent
, bool showUser
)
530 debug( "handleFailVerify ...\n" );
534 user
= QString::fromLocal8Bit( msg
);
539 int ret
= gRecvInt();
541 // non-terminal status
543 /* case V_PUT_USER: cannot happen - we are in "classic" mode */
544 /* case V_PRE_OK: cannot happen - not in ChTok dialog */
545 /* case V_CHTOK: cannot happen - called by non-interactive verify */
547 debug( " V_CHTOK_AUTH\n" );
549 QStringList
pgs( _pluginsLogin
);
550 pgs
+= _pluginsShutdown
;
551 foreach (const QString
& pg
, pgs
)
552 if (pg
== "classic" || pg
== "modern") {
553 pgs
= QStringList( pg
);
555 } else if (pg
== "generic") {
556 pgs
= QStringList( "modern" );
559 pgs
= QStringList( "classic" );
561 KGChTok
chtok( parent
, user
, init( pgs
), 0,
562 KGreeterPlugin::AuthChAuthTok
,
563 KGreeterPlugin::Login
);
567 debug( " V_MSG_ERR\n" );
569 debug( " message %\"s\n", msg
);
570 vrfErrBox( parent
, user
, msg
);
575 case V_MSG_INFO_AUTH
: // should not happen
577 debug( " V_MSG_INFO\n" );
579 debug( " message %\"s\n", msg
);
580 vrfInfoBox( parent
, user
, msg
);
592 debug( " V_AUTH\n" );
593 vrfMsgBox( parent
, user
, sorrybox
, i18n("Authentication failed") );
596 debug( " V_FAIL\n" );
599 logPanic( "Unknown V_xxx code %d from core\n", ret
);
605 KGVerify::handleVerify()
609 debug( "handleVerify ...\n" );
612 int ret
, echo
, ndelay
;
613 KGreeterPlugin::Function nfunc
;
621 debug( " V_GET_TEXT\n" );
623 debug( " prompt %\"s\n", msg
);
625 debug( " echo = %d\n", echo
);
627 debug( " ndelay = %d\n%s->textPrompt(...)\n", ndelay
, pName
.data() );
628 greet
->textPrompt( msg
, echo
, ndelay
);
633 debug( " V_GET_BINARY\n" );
634 msg
= gRecvArr( &ret
);
635 debug( " %d bytes prompt\n", ret
);
637 debug( " ndelay = %d\n%s->binaryPrompt(...)\n", ndelay
, pName
.data() );
638 greet
->binaryPrompt( msg
, ndelay
);
644 // non-terminal status
648 debug( " V_PUT_USER\n" );
650 curUser
= user
= QString::fromLocal8Bit( msg
);
651 // greet needs this to be able to return something useful from
652 // getEntity(). but the backend is still unable to tell a domain ...
653 debug( " %s->setUser(%\"s)\n", pName
.data(), qPrintable( user
) );
654 greet
->setUser( curUser
);
655 handler
->verifySetUser( curUser
);
659 case V_PRE_OK
: // this is only for func == AuthChAuthTok
660 debug( " V_PRE_OK\n" );
661 // With the "classic" method, the wrong user simply cannot be
662 // authenticated, even with the generic plugin. Other methods
663 // could do so, but this applies only to ctx == ChangeTok, which
664 // is not implemented yet.
667 debug( "%s->succeeded()\n", pName
.data() );
671 debug( " V_CHTOK_AUTH\n" );
672 nfunc
= KGreeterPlugin::AuthChAuthTok
;
676 debug( " V_CHTOK\n" );
677 nfunc
= KGreeterPlugin::ChAuthTok
;
682 debug( "%s->succeeded()\n", pName
.data() );
684 KGChTok
chtok( parent
, user
, pluginList
, curPlugin
, nfunc
, KGreeterPlugin::Login
);
691 debug( " V_MSG_ERR\n" );
693 debug( " %s->textMessage(%\"s, true)\n", pName
.data(), msg
);
694 if (!greet
->textMessage( msg
, true )) { // XXX little point in filtering
695 debug( " message passed\n" );
696 vrfErrBox( parent
, user
, msg
);
698 debug( " message swallowed\n" );
703 case V_MSG_INFO_AUTH
:
704 debug( " V_MSG_INFO_AUTH\n" );
706 debug( " %s->textMessage(%\"s, false)\n", pName
.data(), msg
);
707 if (!greet
->textMessage( msg
, false )) {
708 debug( " message passed\n" );
709 vrfInfoBox( parent
, user
, msg
);
711 debug( " message swallowed\n" );
716 debug( " V_MSG_INFO\n" );
718 debug( " display %\"s\n", msg
);
719 vrfInfoBox( parent
, user
, msg
);
732 if (!fixedEntity
.isEmpty()) {
733 debug( " %s->getEntity()\n", pName
.data() );
734 QString ent
= greet
->getEntity();
735 debug( " entity %\"s\n", qPrintable( ent
) );
736 if (ent
!= fixedEntity
) {
737 debug( "%s->failed()\n", pName
.data() );
740 i18n("Authenticated user (%1) does not match requested user (%2).\n",
741 ent
, fixedEntity
) );
745 debug( "%s->succeeded()\n", pName
.data() );
751 debug( "%s->failed()\n", pName
.data() );
755 debug( " V_AUTH\n" );
758 handler
->verifyFailed();
759 timer
.start( 1500 + KRandom::random()/(RAND_MAX
/1000) );
763 logPanic( "Unknown V_xxx code %d from core\n", ret
);
764 debug( " V_FAIL\n" );
766 debug( "%s->revive()\n", pName
.data() );
769 debug( "%s->start()\n", pName
.data() );
778 KGVerify::gplugReturnText( const char *text
, int tag
)
780 debug( "%s: gplugReturnText(%\"s, %d)\n", pName
.data(),
781 tag
& V_IS_SECRET
? "<masked>" : text
, tag
);
791 KGVerify::gplugReturnBinary( const char *data
)
794 unsigned const char *up
= (unsigned const char *)data
;
795 int len
= up
[3] | (up
[2] << 8) | (up
[1] << 16) | (up
[0] << 24);
796 debug( "%s: gplugReturnBinary(%d bytes)\n", pName
.data(), len
);
797 gSendArr( len
, data
);
800 debug( "%s: gplugReturnBinary(NULL)\n", pName
.data() );
807 KGVerify::gplugSetUser( const QString
&user
)
809 debug( "%s: gplugSetUser(%\"s)\n", pName
.data(), qPrintable( user
) );
811 handler
->verifySetUser( user
);
815 KGVerify::gplugStart()
817 // XXX handle func != Authenticate
820 debug( "%s: gplugStart()\n", pName
.data() );
821 gSendInt( ctx
== KGreeterPlugin::Shutdown
? G_VerifyRootOK
: G_Verify
);
822 gSendStr( greetPlugins
[pluginList
[curPlugin
]].info
->method
);
827 KGVerify::gplugChanged()
829 debug( "%s: gplugChanged()\n", pName
.data() );
830 if (func
== KGreeterPlugin::Authenticate
&&
831 ctx
== KGreeterPlugin::Login
)
835 timer
.start( FULL_GREET_TO
* SECONDS
);
840 KGVerify::gplugActivity()
842 debug( "%s: gplugActivity()\n", pName
.data() );
847 KGVerify::gplugMsgBox( QMessageBox::Icon type
, const QString
&text
)
849 debug( "%s: gplugMsgBox(%d, %\"s)\n", pName
.data(), type
, qPrintable( text
) );
850 msgBox( type
, text
);
854 KGVerify::eventFilter( QObject
*o
, QEvent
*e
)
857 case QEvent::KeyPress
:
859 QKeyEvent
*ke
= (QKeyEvent
*)e
;
860 if (ke
->key() == Qt::Key_Return
|| ke
->key() == Qt::Key_Enter
) {
861 if (deadTicks
<= 0) {
869 case QEvent::KeyRelease
:
875 return inherited::eventFilter( o
, e
);
879 KGVerify::updateLockStatus()
882 Window dummy1
, dummy2
;
883 int dummy3
, dummy4
, dummy5
, dummy6
;
884 XQueryPointer( QX11Info::display(), DefaultRootWindow( QX11Info::display() ),
885 &dummy1
, &dummy2
, &dummy3
, &dummy4
, &dummy5
, &dummy6
,
887 capsLocked
= lmask
& LockMask
;
892 KGVerify::msgBox( QMessageBox::Icon typ
, const QString
&msg
)
895 KFMsgBox::box( parent
, typ
, msg
);
900 QVariant
// public static
901 KGVerify::getConf( void *, const char *key
, const QVariant
&dflt
)
903 if (!qstrcmp( key
, "EchoPasswd" ))
904 return QVariant( _echoPasswd
);
906 QString fkey
= QString::fromLatin1( key
) + '=';
907 foreach (const QString
& pgo
, _pluginOptions
)
908 if (pgo
.startsWith( fkey
))
909 return pgo
.mid( fkey
.length() );
914 QVector
<GreeterPluginHandle
> KGVerify::greetPlugins
;
917 KGVerify::init( const QStringList
&plugins
)
919 PluginList pluginList
;
921 foreach (const QString
& pg
, plugins
) {
922 GreeterPluginHandle plugin
;
923 KLibrary
*lib
= new KLibrary( pg
[0] == '/' ? pg
: "kgreet_" + pg
);
924 if (lib
->fileName().isEmpty()) {
925 logError( "GreeterPlugin %s does not exist\n", qPrintable( pg
) );
929 uint i
, np
= greetPlugins
.count();
930 for (i
= 0; i
< np
; i
++)
931 if (greetPlugins
[i
].library
->fileName() == lib
->fileName()) {
936 logError( "Cannot load GreeterPlugin %s (%s)\n",
937 qPrintable( pg
), qPrintable( lib
->fileName() ) );
941 plugin
.library
= lib
;
942 plugin
.info
= (KGreeterPluginInfo
*)lib
->resolveSymbol( "kgreeterplugin_info" );
944 logError( "GreeterPlugin %s (%s) is no valid greet widget plugin\n",
945 qPrintable( pg
), qPrintable( lib
->fileName() ) );
951 if (!plugin
.info
->init( QString(), getConf
, 0 )) {
952 logError( "GreeterPlugin %s (%s) refuses to serve\n",
953 qPrintable( pg
), qPrintable( lib
->fileName() ) );
958 debug( "GreeterPlugin %s (%s) loaded\n", qPrintable( pg
), plugin
.info
->name
);
959 greetPlugins
.append( plugin
);
961 pluginList
.append( i
);
969 for (int i
= 0; i
< greetPlugins
.count(); i
++) {
970 if (greetPlugins
[i
].info
->done
)
971 greetPlugins
[i
].info
->done();
972 greetPlugins
[i
].library
->unload();
977 KGStdVerify::KGStdVerify( KGVerifyHandler
*_handler
, QWidget
*_parent
,
978 QWidget
*_predecessor
, const QString
&_fixedUser
,
979 const PluginList
&_pluginList
,
980 KGreeterPlugin::Function _func
,
981 KGreeterPlugin::Context _ctx
)
982 : inherited( _handler
, _parent
, _predecessor
, _fixedUser
,
983 _pluginList
, _func
, _ctx
)
984 , failedLabelState( 0 )
986 grid
= new QGridLayout
;
987 grid
->setAlignment( Qt::AlignCenter
);
989 failedLabel
= new QLabel( parent
);
990 failedLabel
->setFont( *_failFont
);
991 grid
->addWidget( failedLabel
, 1, 0, Qt::AlignCenter
);
996 KGStdVerify::~KGStdVerify()
1001 KGStdVerify::gplugHasNode( const QString
& )
1007 KGStdVerify::selectPlugin( int id
)
1009 inherited::selectPlugin( id
);
1010 QWidget
*w
= greet
->getWidgets().first();
1011 grid
->addWidget( w
, 0, 0 );
1016 KGStdVerify::updateStatus()
1026 else if (!suspended
&& capsLocked
)
1031 if (failedLabelState
!= nfls
) {
1032 failedLabelState
= nfls
;
1035 failedLabel
->setText( i18np( "Automatic login in 1 second...",
1036 "Automatic login in %1 seconds...",
1041 failedLabel
->clear();
1044 p
.setBrush( QPalette::WindowText
,
1045 KColorScheme( QPalette::Active
, KColorScheme::Window
)
1046 .foreground( KColorScheme::NegativeText
) );
1047 failedLabel
->setText( i18n("Warning: Caps Lock is on") );
1050 failedLabel
->setText( authTok
?
1051 i18n("Change failed") :
1052 fixedEntity
.isEmpty() ?
1053 i18n("Login failed") :
1054 i18n("Authentication failed") );
1058 failedLabel
->setPalette( p
);
1062 KGThemedVerify::KGThemedVerify( KGVerifyHandler
*_handler
,
1064 QWidget
*_parent
, QWidget
*_predecessor
,
1065 const QString
&_fixedUser
,
1066 const PluginList
&_pluginList
,
1067 KGreeterPlugin::Function _func
,
1068 KGreeterPlugin::Context _ctx
)
1069 : inherited( _handler
, _parent
, _predecessor
, _fixedUser
,
1070 _pluginList
, _func
, _ctx
)
1076 KGThemedVerify::~KGThemedVerify()
1081 KGThemedVerify::gplugHasNode( const QString
&id
)
1083 return themer
->findNode( id
) != 0;
1087 KGThemedVerify::selectPlugin( int id
)
1089 if (curPlugin
!= -1)
1090 themer
->setTypeVisible( QString( "plugin-specific-" ).append( pluginName() ), false );
1091 inherited::selectPlugin( id
);
1092 themer
->setTypeVisible( QString( "plugin-specific-" ).append( pluginName() ), true );
1093 QSet
<QString
> oldTypes
= showTypes
;
1095 foreach (QWidget
*w
, greet
->getWidgets())
1096 if (KdmItem
*n
= themer
->findNode( w
->objectName() )) {
1097 QString
tn( QString( "plugin-" ).append( w
->objectName() ) );
1098 themer
->setTypeVisible( tn
, true );
1099 showTypes
.insert( tn
);
1100 oldTypes
.remove( tn
);
1104 i18n( "Theme not usable with authentication method '%1'.",
1105 i18n( greetPlugins
[pluginList
[id
]].info
->name
) ) );
1108 foreach (const QString
& t
, oldTypes
)
1109 themer
->setTypeVisible( t
, false );
1113 KGThemedVerify::updateStatus()
1115 handler
->updateStatus( enabled
&& failed
,
1116 enabled
&& !suspended
&& capsLocked
,
1121 KGChTok::KGChTok( QWidget
*_parent
, const QString
&user
,
1122 const PluginList
&pluginList
, int curPlugin
,
1123 KGreeterPlugin::Function func
,
1124 KGreeterPlugin::Context ctx
)
1125 : inherited( _parent
)
1128 QSizePolicy
fp( QSizePolicy::Fixed
, QSizePolicy::Fixed
);
1129 okButton
= new KPushButton( KStandardGuiItem::ok(), this );
1130 okButton
->setSizePolicy( fp
);
1131 okButton
->setDefault( true );
1132 cancelButton
= new KPushButton( KStandardGuiItem::cancel(), this );
1133 cancelButton
->setSizePolicy( fp
);
1135 verify
= new KGStdVerify( this, this, cancelButton
, user
, pluginList
, func
, ctx
);
1136 verify
->selectPlugin( curPlugin
);
1138 QVBoxLayout
*box
= new QVBoxLayout( this );
1140 box
->addWidget( new QLabel( i18nc("@title:window",
1141 "<qt><b>Changing authentication token</b></qt>"),
1142 this ), 0, Qt::AlignHCenter
|Qt::AlignTop
);
1144 box
->addLayout( verify
->getLayout() );
1146 box
->addWidget( new KSeparator( Qt::Horizontal
, this ) );
1148 QHBoxLayout
*hlay
= new QHBoxLayout();
1149 box
->addLayout( hlay
);
1150 hlay
->addStretch( 1 );
1151 hlay
->addWidget( okButton
);
1152 hlay
->addStretch( 1 );
1153 hlay
->addWidget( cancelButton
);
1154 hlay
->addStretch( 1 );
1156 connect( okButton
, SIGNAL(clicked()), SLOT(accept()) );
1157 connect( cancelButton
, SIGNAL(clicked()), SLOT(reject()) );
1159 QTimer::singleShot( 0, verify
, SLOT(start()) );
1175 KGChTok::verifyPluginChanged( int )
1183 inherited::accept();
1187 KGChTok::verifyFailed()
1189 okButton
->setEnabled( false );
1190 cancelButton
->setEnabled( false );
1194 KGChTok::verifyRetry()
1196 okButton
->setEnabled( true );
1197 cancelButton
->setEnabled( true );
1201 KGChTok::verifySetUser( const QString
& )
1207 ////// helper class, nuke when qtimer supports suspend()/resume()
1213 connect( &timer
, SIGNAL(timeout()), SLOT(slotTimeout()) );
1217 QXTimer::start( int msec
)
1220 timer
.setSingleShot( true );
1221 timer
.start( left
);
1222 gettimeofday( &stv
, 0 );
1235 if (timer
.isActive()) {
1238 gettimeofday( &tv
, 0 );
1239 left
-= (tv
.tv_sec
- stv
.tv_sec
) * 1000 + (tv
.tv_usec
- stv
.tv_usec
) / 1000;
1248 if (left
>= 0 && !timer
.isActive()) {
1249 timer
.setSingleShot( true );
1250 timer
.start( left
);
1251 gettimeofday( &stv
, 0 );
1256 QXTimer::slotTimeout()
1263 #include "kgverify.moc"