Subject: Fix broken KDM layout with fingerprint support
From: Lubos Lunak
Patch-upstream: not yet
Bug: bnc#533189
Relates: kdm-fix-labelcolors.diff, same-pam-generic-classic.diff

--- workspace/kdm/kfrontend/kgreeter.cpp.sav	2010-03-11 13:59:41.000000000 +0100
+++ workspace/kdm/kfrontend/kgreeter.cpp	2010-03-15 15:45:39.000000000 +0100
@@ -915,8 +915,6 @@ KThemedGreeter::KThemedGreeter( KdmTheme
 	timed_label = themer->findNode( "timed-label" );
 
 	KdmItem *itm;
-	if ((itm = themer->findNode( "pam-message" ))) // done via msgboxes
-		itm->setVisible( false );
 	if ((itm = themer->findNode( "language_button" ))) // not implemented yet
 		itm->setVisible( false );
 
--- workspace/kdm/kfrontend/themes/greeter.dtd.sav	2010-03-11 13:59:41.000000000 +0100
+++ workspace/kdm/kfrontend/themes/greeter.dtd	2010-03-15 15:57:51.000000000 +0100
@@ -19,9 +19,9 @@ Items with these IDs get special treatme
 	caps-lock-warning | xauth-warning | pam-error | timed-label |
 	login_button | session_button | system_button
 Items with these IDs might get special treatment by conversation plugins:
-	talker | domain-entry | user-entry | pw-entry
+	talker | domain-entry | user-entry | pw-entry | pam-message | pam-prompt | user-pw-entry
 Items with these IDs are always hidden:
-	pam-message | language_button
+	language_button
 -->
 
 <!ATTLIST item
--- workspace/libs/kdm/kgreet_generic.cpp.sav	2010-03-11 13:59:40.000000000 +0100
+++ workspace/libs/kdm/kgreet_generic.cpp	2010-03-15 16:20:56.000000000 +0100
@@ -41,24 +41,14 @@ extern KDE_EXPORT KGreeterPluginInfo kgr
 
 static int echoMode;
 
-class KDMPasswordEdit : public KLineEdit {
-public:
-	KDMPasswordEdit( QWidget *parent = 0 ) : KLineEdit( parent )
-	{
-		if (::echoMode == -1)
-			setPasswordMode( true );
-		else
-			setEchoMode( ::echoMode ? Password : NoEcho );
-		setContextMenuPolicy( Qt::NoContextMenu );
-	}
-};
-
 KGenericGreeter::KGenericGreeter( KGreeterPluginHandler *_handler,
                                   QWidget *parent,
                                   const QString &_fixedEntity,
                                   Function _func, Context _ctx ) :
 	QObject(),
 	KGreeterPlugin( _handler ),
+	m_label( 0 ),
+	m_messageLabel( 0 ),
 	m_lineEdit( 0 ),
 	fixedUser( _fixedEntity ),
 	func( _func ),
@@ -66,22 +56,55 @@ KGenericGreeter::KGenericGreeter( KGreet
 	exp( -1 ),
 	running( false )
 {
-	m_parentWidget = new QWidget( parent );
-	m_parentWidget->setObjectName( "talker" );
-	// XXX set some minimal size
-	widgetList << m_parentWidget;
-	m_grid = new QGridLayout( m_parentWidget );
-	m_grid->setMargin( 0 );
+	QGridLayout *grid = 0;
+	if (!_handler->gplugHasNode( "pam-prompt" ) ||
+	    !_handler->gplugHasNode( "user-pw-entry" ) ||
+	    !_handler->gplugHasNode( "pam-message" )) {
+		parent = new QWidget( parent );
+		parent->setObjectName( "talker" );
+		widgetList << parent;
+		grid = new QGridLayout( parent );
+		grid->setMargin( 0 );
+	}
 
 	if (ctx == ExUnlock || ctx == ExChangeTok)
 		fixedUser = KUser().loginName();
+
+	m_label = new QLabel( parent );
+	if( grid ) {
+		m_label->setMinimumWidth(
+			m_label->fontMetrics().width( "A username" ) );
+		grid->addWidget( m_label, 0, 0 );
+        } else {
+		m_label->setObjectName( "pam-prompt" );
+		widgetList << m_label;
+	}
+	m_lineEdit = new KLineEdit( parent );
+	m_label->setBuddy( m_lineEdit );
+	if( grid ) {
+		m_lineEdit->setMinimumWidth(
+			m_lineEdit->fontMetrics().width( "This is a long password" ) );
+		grid->addWidget( m_lineEdit, 0, 1 );
+	} else {
+		m_lineEdit->setObjectName( "user-pw-entry" );
+		widgetList << m_lineEdit;
+	}
+	m_messageLabel = new QLabel( parent );
+	if( grid ) {
+		m_messageLabel->setMinimumWidth(
+			m_messageLabel->fontMetrics().width( "Information text" ) );
+		grid->addWidget( m_messageLabel, 1, 0 );
+        } else {
+		m_messageLabel->setObjectName( "pam-message" );
+		widgetList << m_messageLabel;
+	}
 }
 
 // virtual
 KGenericGreeter::~KGenericGreeter()
 {
 	abort();
-	delete m_parentWidget;
+	qDeleteAll( widgetList );
 }
 
 void // virtual
@@ -127,8 +150,7 @@ KGenericGreeter::setEnabled( bool enable
 {
 	// assert( func == Authenticate && ctx == Shutdown );
 	// XXX this is likely to bear some bogosity
-	foreach (QWidget *w, m_children)
-		w->setEnabled( enable );
+	m_lineEdit->setEnabled( enable );
 	if (enable && m_lineEdit)
 		m_lineEdit->setFocus();
 }
@@ -143,9 +165,7 @@ KGenericGreeter::textMessage( const char
 		revive();
 	QString qtext = QString::fromUtf8( text );
 	m_infoMsgs.append( qtext );
-	QLabel *label = new QLabel( qtext, m_parentWidget );
-	m_grid->addWidget( label, m_line++, 0, 1, 2 );
-	m_children.append( label );
+	m_messageLabel->setText( m_infoMsgs.join( "\n" ));
 
 	return true;
 }
@@ -168,15 +188,19 @@ KGenericGreeter::textPrompt( const char
 		revive();
 	else
 		m_infoMsgs.clear();
-
-	QLabel *label = new QLabel( QString::fromUtf8( prompt ).trimmed() );
-	m_grid->addWidget( label, m_line, 0 );
-	m_children.append( label );
 	m_echo = echo;
+
+	m_label->setText( QString::fromUtf8( prompt ).trimmed());
+	m_lineEdit->setContextMenuPolicy( Qt::NoContextMenu );
+	m_lineEdit->setCompletionObject( 0 );
+	m_lineEdit->disconnect( this );
+	m_lineEdit->clear();
+	m_lineEdit->setPasswordMode( false );
+	m_lineEdit->setEchoMode( QLineEdit::Normal );
 	if (echo) {
-		m_lineEdit = new KLineEdit;
-		m_lineEdit->setContextMenuPolicy( Qt::NoContextMenu );
 		if (!exp) {
+			if (m_label->text().isEmpty())
+				m_label->setText( i18n("&Username:"));
 			if (!m_users.isEmpty()) {
 				KCompletion *userNamesCompletion = new KCompletion;
 				userNamesCompletion->setItems( m_users );
@@ -187,20 +211,18 @@ KGenericGreeter::textPrompt( const char
 			if (!curUser.isEmpty()) {
 				m_lineEdit->setText( curUser );
 				m_lineEdit->selectAll();
-				connect( m_lineEdit, SIGNAL(selectionChanged()), SLOT(slotChanged()) );
 			}
 			connect( m_lineEdit, SIGNAL(editingFinished()), SLOT(slotLoginLostFocus()) );
 		}
 		connect( m_lineEdit, SIGNAL(editingFinished()), SLOT(slotChanged()) );
 		connect( m_lineEdit, SIGNAL(textChanged( const QString & )), SLOT(slotChanged()) );
 	} else {
-		m_lineEdit = new KDMPasswordEdit;
+		if (::echoMode == -1)
+			m_lineEdit->setPasswordMode( true );
+		else
+			m_lineEdit->setEchoMode( ::echoMode ? QLineEdit::Password : QLineEdit::NoEcho );
+		connect( m_lineEdit, SIGNAL(editingFinished()), SLOT(slotChanged()) );
 	}
-	m_lineEdit->setMinimumWidth(
-		m_lineEdit->fontMetrics().width( "This is a long password" ) );
-	m_grid->addWidget( m_lineEdit, m_line, 1 );
-	m_children.append( m_lineEdit );
-	m_lineEdit->show();
 	m_lineEdit->setFocus();
 }
 
@@ -235,7 +257,6 @@ KGenericGreeter::next()
 	if (m_lineEdit) {
 		m_lineEdit->setEnabled( false );
 		QString text = m_lineEdit->text();
-		m_lineEdit = 0;
 		handler->gplugReturnText( text.toLocal8Bit(),
 		                          !m_echo ?
 		                             KGreeterPluginHandler::IsSecret :
@@ -272,8 +293,7 @@ KGenericGreeter::failed()
 		revive();
 		handler->gplugMsgBox( QMessageBox::Information, text );
 	} else {
-		foreach (QWidget *w, m_children)
-			w->setEnabled( false );
+		m_lineEdit->setEnabled( false );
 	}
 	exp = -1;
 	running = false;
@@ -283,12 +303,9 @@ void // virtual
 KGenericGreeter::revive()
 {
 	// assert( !running );
-	foreach (QWidget *w, m_children)
-		w->deleteLater();
-	m_children.clear();
 	m_infoMsgs.clear();
-	m_lineEdit = 0;
-	m_line = 0;
+	m_lineEdit->clear();
+	m_lineEdit->setEnabled( true );
 }
 
 void // virtual
--- workspace/libs/kdm/kgreet_generic.h.sav	2010-03-11 13:59:40.000000000 +0100
+++ workspace/libs/kdm/kgreet_generic.h	2010-03-15 16:02:30.000000000 +0100
@@ -33,7 +33,6 @@ Foundation, Inc., 51 Franklin Street, Fi
 
 #include <QObject>
 
-class QGridLayout;
 class QWidget;
 class KLineEdit;
 
@@ -68,11 +67,11 @@ class KGenericGreeter : public QObject,
 	void slotChanged();
 
   private:
-	QGridLayout *m_grid;
 	QList<QWidget *> m_children;
+	QLabel *m_label;
+	QLabel *m_messageLabel;
 	KLineEdit *m_lineEdit;
-	QWidget *m_parentWidget;
-	QList<QString> m_infoMsgs;
+	QStringList m_infoMsgs;
 	QString fixedUser, curUser;
 	QStringList m_users;
 	Function func;
--- workspace/kdm/kfrontend/themes/oxygen-air/oxygen-air.xml.sav	2010-03-09 11:52:01.000000000 +0100
+++ workspace/kdm/kfrontend/themes/oxygen-air/oxygen-air.xml	2010-03-15 15:57:08.000000000 +0100
@@ -27,11 +27,12 @@
 				<stock type="welcome-label"/>
 			</item>
 
-			<item type="rect" id="user-field">
+			<item type="rect" id="talker">
 				<pos anchor="c" x="50%" y="43%" width="400" height="144"/>
 				<box orientation="vertical" spacing="0" homogeneous="true">
 				
-					<item type="pixmap" butoon="true">
+					<item type="pixmap" button="true">
+            					<show type="!plugin-specific-generic"/>
 						<normal file="user-entry.png"/>
 						<prelight file="user-entry-li.png"/>
 						<active file="user-entry-li.png"/>
@@ -39,18 +40,38 @@
 					</item>
 					
 					<item type="entry" id="user-entry">
+            					<show type="!plugin-specific-generic"/>
 						<pos anchor="c" x="52%" y="0%" width="110" height="22"/>
 					</item>
 
 					<item type="pixmap">
+            					<show type="!plugin-specific-generic"/>
 						<normal file="pw-entry.png"/>
 						<prelight file="pw-entry-li.png"/>
 						<pos anchor="c" x="50%" y="100%"/>
 					</item>
 									
 					<item type="entry" id="pw-entry">
+            					<show type="!plugin-specific-generic"/>
 						<pos anchor="c" x="52%" y="0%" width="110" height="22"/>
 					</item>
+
+					<item type="label" id="pam-message">
+            					<show type="plugin-specific-generic"/>
+						<pos anchor="n" x="50%" y="60%" width="90%" height="30%"/>
+				                <text> </text>
+					</item>
+
+					<item type="label" id="pam-prompt">
+            					<show type="plugin-specific-generic"/>
+						<pos anchor="n" x="50%" y="30%" width="90%" height="22"/>
+				                <text> </text>
+					</item>
+
+					<item type="entry" id="user-pw-entry">
+            					<show type="plugin-specific-generic"/>
+						<pos anchor="c" x="50%" y="30%" width="90%" height="22"/>
+					</item>
 					
 				</box>
 			</item>
