[PATCH] Fix KPasswordDialog to show ok button only when passwords match
Ravikiran Rajagopal
ravi at ee.eng.ohio-state.edu
Fri Apr 4 19:13:36 BST 2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello,
The following patch disables the ok button when the two passwords do not
match. We do it at the end anyway, but this is more user-friendly. (Thanks to
Willy for the suggestion.) Is it ok to commit?
Regards,
Ravi
Index: kpassdlg.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kpassdlg.cpp,v
retrieving revision 1.20
diff -u -p -w -r1.20 kpassdlg.cpp
- --- kpassdlg.cpp 27 Feb 2003 22:35:05 -0000 1.20
+++ kpassdlg.cpp 4 Apr 2003 18:09:20 -0000
@@ -46,6 +46,12 @@
* Password line editor.
*/
+class KPasswordDialog::KPasswordDialogPrivate
+{
+public:
+ QLabel *m_MatchLabel;
+};
+
const int KPasswordEdit::PassLen = 100;
KPasswordEdit::KPasswordEdit(QWidget *parent, const char *name)
@@ -208,7 +214,7 @@ KPasswordDialog::KPasswordDialog(Types t
KPasswordDialog::KPasswordDialog(int type, QString prompt, bool enableKeep,
int extraBttn)
: KDialogBase(0L, "Password Dialog", true, "", Ok|Cancel|extraBttn,
- - Ok, true), m_Keep(enableKeep? 1 : 0), m_Type(type)
+ Ok, true), m_Keep(enableKeep? 1 : 0), m_Type(type), d(new
KPasswordDialogPrivate)
{
init();
setPrompt(prompt);
@@ -297,6 +303,17 @@ void KPasswordDialog::init()
m_pEdit2->setMinimumWidth(size.width());
h_lay->addWidget(m_pEdit2, 12);
h_lay->addStretch(4);
+
+ // Row 5: Label saying whether the passwords match
+ m_pGrid->addRowSpacing(10, 10);
+ m_pGrid->setRowStretch(10, 12);
+ d->m_MatchLabel = new QLabel(m_pMain);
+ d->m_MatchLabel->setAlignment(AlignLeft|AlignVCenter|WordBreak);
+ m_pGrid->addMultiCellWidget(d->m_MatchLabel, 11, 11, 0, 2);
+ d->m_MatchLabel->setText(i18n("Passwords do not match"));
+ connect( m_pEdit, SIGNAL(textChanged(const QString&)),
SLOT(enableOkBtn()) );
+ connect( m_pEdit2, SIGNAL(textChanged(const QString&)),
SLOT(enableOkBtn()) );
+ enableOkBtn();
}
erase();
@@ -422,5 +439,15 @@ void KPasswordDialog::disableCoreDumps()
void KPasswordDialog::virtual_hook( int id, void* data )
{ KDialogBase::virtual_hook( id, data ); }
+
+void KPasswordDialog::enableOkBtn()
+{
+ if (m_Type == NewPassword) {
+ bool match = ((strcmp(m_pEdit->password(), m_pEdit2->password()))==0)
+ && (strcmp(m_pEdit->password(), "") != 0);
+ enableButtonOK( match );
+ d->m_MatchLabel->setText( match?QString(i18n("Passwords
match")):QString(i18n("Passwords do not match")) );
+ }
+}
#include "kpassdlg.moc"
Index: kpassdlg.h
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kpassdlg.h,v
retrieving revision 1.19
diff -u -p -w -r1.19 kpassdlg.h
- --- kpassdlg.h 5 Mar 2002 23:13:27 -0000 1.19
+++ kpassdlg.h 4 Apr 2003 18:09:20 -0000
@@ -239,6 +239,9 @@ protected:
* password is valid, @p false otherwise.
*/
virtual bool checkPassword(const char *) { return true; }
+
+private slots:
+ void enableOkBtn();
private:
void init();
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE+jctZbI8Y8y0oVXcRAu8AAJ4+Va49SqHIXEhnpk2+ylCQEhLy8ACdEsp0
bs9YdccxrOC17TANVj/beeQ=
=Tqyd
-----END PGP SIGNATURE-----
More information about the kde-core-devel
mailing list