|
|
@ -56,33 +56,6 @@
|
|
|
|
* Password line editor.
|
|
|
|
* Password line editor.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// BCI: Add a real d-pointer and put the int into that
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static TQPtrDict<int>* d_ptr = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void cleanup_d_ptr() {
|
|
|
|
|
|
|
|
delete d_ptr;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int * ourMaxLength( const KPasswordEdit* const e ) {
|
|
|
|
|
|
|
|
if ( !d_ptr ) {
|
|
|
|
|
|
|
|
d_ptr = new TQPtrDict<int>;
|
|
|
|
|
|
|
|
d_ptr->setAutoDelete(true);
|
|
|
|
|
|
|
|
tqAddPostRoutine( cleanup_d_ptr );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int* ret = d_ptr->find( (void*) e );
|
|
|
|
|
|
|
|
if ( ! ret ) {
|
|
|
|
|
|
|
|
ret = new int;
|
|
|
|
|
|
|
|
d_ptr->replace( (void*) e, ret );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void delete_d( const KPasswordEdit* const e ) {
|
|
|
|
|
|
|
|
if ( d_ptr )
|
|
|
|
|
|
|
|
d_ptr->remove( (void*) e );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const int KPasswordEdit::PassLen = 200;
|
|
|
|
const int KPasswordEdit::PassLen = 200;
|
|
|
|
|
|
|
|
|
|
|
|
class KPasswordDialog::KPasswordDialogPrivate
|
|
|
|
class KPasswordDialog::KPasswordDialogPrivate
|
|
|
@ -114,191 +87,92 @@ KPasswordEdit::KPasswordEdit(TQWidget *parent, const char *name)
|
|
|
|
TDEConfigGroupSaver saver(cfg, "Passwords");
|
|
|
|
TDEConfigGroupSaver saver(cfg, "Passwords");
|
|
|
|
|
|
|
|
|
|
|
|
const TQString val = cfg->readEntry("EchoMode", "OneStar");
|
|
|
|
const TQString val = cfg->readEntry("EchoMode", "OneStar");
|
|
|
|
if (val == "ThreeStars")
|
|
|
|
if (val == "ThreeStars") {
|
|
|
|
m_EchoMode = ThreeStars;
|
|
|
|
setEchoMode(PasswordThreeStars);
|
|
|
|
else if (val == "NoEcho")
|
|
|
|
}
|
|
|
|
m_EchoMode = NoEcho;
|
|
|
|
else if (val == "NoEcho") {
|
|
|
|
else
|
|
|
|
setEchoMode(TQLineEdit::NoEcho);
|
|
|
|
m_EchoMode = OneStar;
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
setEchoMode(TQLineEdit::Password);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setInputMethodEnabled( true );
|
|
|
|
setInputMethodEnabled( true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KPasswordEdit::KPasswordEdit(TQWidget *parent, const char *name, int echoMode)
|
|
|
|
KPasswordEdit::KPasswordEdit(TQWidget *parent, const char *name, int echoMode)
|
|
|
|
: TQLineEdit(parent, name), m_EchoMode(echoMode)
|
|
|
|
: TQLineEdit(parent, name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
setEchoMode((TQLineEdit::EchoMode)echoMode);
|
|
|
|
init();
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KPasswordEdit::KPasswordEdit(EchoModes echoMode, TQWidget *parent, const char *name)
|
|
|
|
KPasswordEdit::KPasswordEdit(EchoMode echoMode, TQWidget *parent, const char *name)
|
|
|
|
: TQLineEdit(parent, name), m_EchoMode(echoMode)
|
|
|
|
: TQLineEdit(parent, name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
setEchoMode(echoMode);
|
|
|
|
init();
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KPasswordEdit::KPasswordEdit(EchoMode echoMode, TQWidget *parent, const char *name)
|
|
|
|
KPasswordEdit::KPasswordEdit(EchoModes echoMode, TQWidget *parent, const char *name)
|
|
|
|
: TQLineEdit(parent, name)
|
|
|
|
: TQLineEdit(parent, name)
|
|
|
|
, m_EchoMode( echoMode == TQLineEdit::NoEcho ? NoEcho : OneStar )
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (echoMode == KPasswordEdit::NoEcho) {
|
|
|
|
|
|
|
|
setEchoMode(TQLineEdit::NoEcho);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (echoMode == KPasswordEdit::ThreeStars) {
|
|
|
|
|
|
|
|
setEchoMode(TQLineEdit::PasswordThreeStars);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (echoMode == KPasswordEdit::OneStar) {
|
|
|
|
|
|
|
|
setEchoMode(TQLineEdit::Password);
|
|
|
|
|
|
|
|
}
|
|
|
|
init();
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KPasswordEdit::init()
|
|
|
|
void KPasswordEdit::init()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
setEchoMode(TQLineEdit::Password); // Just in case
|
|
|
|
|
|
|
|
setAcceptDrops(false);
|
|
|
|
setAcceptDrops(false);
|
|
|
|
int* t = ourMaxLength(this);
|
|
|
|
|
|
|
|
*t = (PassLen - 1); // the internal max length
|
|
|
|
|
|
|
|
m_Password = new char[PassLen];
|
|
|
|
|
|
|
|
m_Password[0] = '\000';
|
|
|
|
|
|
|
|
m_Length = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KPasswordEdit::~KPasswordEdit()
|
|
|
|
KPasswordEdit::~KPasswordEdit()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
memset(m_Password, 0, PassLen * sizeof(char));
|
|
|
|
|
|
|
|
delete[] m_Password;
|
|
|
|
|
|
|
|
delete_d(this);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KPasswordEdit::insert(const TQString &txt)
|
|
|
|
const char *KPasswordEdit::password() const {
|
|
|
|
{
|
|
|
|
return text().ascii();
|
|
|
|
const TQCString localTxt = txt.local8Bit();
|
|
|
|
|
|
|
|
const unsigned int lim = localTxt.length();
|
|
|
|
|
|
|
|
const int m_MaxLength = maxPasswordLength();
|
|
|
|
|
|
|
|
for(unsigned int i=0; i < lim; ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
const unsigned char ke = localTxt[i];
|
|
|
|
|
|
|
|
if (m_Length < m_MaxLength)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_Password[m_Length] = ke;
|
|
|
|
|
|
|
|
m_Password[++m_Length] = '\000';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
showPass();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KPasswordEdit::erase()
|
|
|
|
void KPasswordEdit::erase()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_Length = 0;
|
|
|
|
|
|
|
|
memset(m_Password, 0, PassLen * sizeof(char));
|
|
|
|
|
|
|
|
setText("");
|
|
|
|
setText("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KPasswordEdit::focusInEvent(TQFocusEvent *e)
|
|
|
|
void KPasswordEdit::setMaxPasswordLength(int newLength)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const TQString txt = text();
|
|
|
|
setMaxLength(newLength);
|
|
|
|
setUpdatesEnabled(false);
|
|
|
|
|
|
|
|
TQLineEdit::focusInEvent(e);
|
|
|
|
|
|
|
|
setUpdatesEnabled(true);
|
|
|
|
|
|
|
|
setText(txt);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int KPasswordEdit::maxPasswordLength() const
|
|
|
|
void KPasswordEdit::keyPressEvent(TQKeyEvent *e)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
switch (e->key()) {
|
|
|
|
return maxLength();
|
|
|
|
case Key_Return:
|
|
|
|
|
|
|
|
case Key_Enter:
|
|
|
|
|
|
|
|
case Key_Escape:
|
|
|
|
|
|
|
|
e->ignore();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Key_Backspace:
|
|
|
|
|
|
|
|
case Key_Delete:
|
|
|
|
|
|
|
|
case 0x7f: // Delete
|
|
|
|
|
|
|
|
if (e->state() & (ControlButton | AltButton))
|
|
|
|
|
|
|
|
e->ignore();
|
|
|
|
|
|
|
|
else if (m_Length) {
|
|
|
|
|
|
|
|
m_Password[--m_Length] = '\000';
|
|
|
|
|
|
|
|
showPass();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
const unsigned char ke = TQString(e->text()).local8Bit()[0];
|
|
|
|
|
|
|
|
if (ke >= 32) {
|
|
|
|
|
|
|
|
insert(e->text());
|
|
|
|
|
|
|
|
} else
|
|
|
|
|
|
|
|
e->ignore();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KPasswordEdit::event(TQEvent *e) {
|
|
|
|
void KPasswordEdit::insert( const TQString &str) {
|
|
|
|
switch(e->type()) {
|
|
|
|
TQLineEdit::insert(str);
|
|
|
|
|
|
|
|
|
|
|
|
case TQEvent::MouseButtonPress:
|
|
|
|
|
|
|
|
case TQEvent::MouseButtonRelease:
|
|
|
|
|
|
|
|
case TQEvent::MouseButtonDblClick:
|
|
|
|
|
|
|
|
case TQEvent::MouseMove:
|
|
|
|
|
|
|
|
case TQEvent::IMStart:
|
|
|
|
|
|
|
|
case TQEvent::IMCompose:
|
|
|
|
|
|
|
|
return true; //Ignore
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case TQEvent::IMEnd:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
TQIMEvent* const ie = (TQIMEvent*) e;
|
|
|
|
|
|
|
|
if (!ie->text().isEmpty())
|
|
|
|
|
|
|
|
insert( ie->text() );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case TQEvent::AccelOverride:
|
|
|
|
void KPasswordEdit::keyPressEvent(TQKeyEvent *e) {
|
|
|
|
{
|
|
|
|
TQLineEdit::keyPressEvent(e);
|
|
|
|
TQKeyEvent* const k = (TQKeyEvent*) e;
|
|
|
|
|
|
|
|
switch (k->key()) {
|
|
|
|
|
|
|
|
case Key_U:
|
|
|
|
|
|
|
|
if (k->state() & ControlButton) {
|
|
|
|
|
|
|
|
m_Length = 0;
|
|
|
|
|
|
|
|
m_Password[m_Length] = '\000';
|
|
|
|
|
|
|
|
showPass();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true; // stop bubbling
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
void KPasswordEdit::focusInEvent(TQFocusEvent *e) {
|
|
|
|
// Do nothing
|
|
|
|
TQLineEdit::focusInEvent(e);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return TQLineEdit::event(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void KPasswordEdit::showPass()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
TQString tmp;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (m_EchoMode) {
|
|
|
|
|
|
|
|
case OneStar:
|
|
|
|
|
|
|
|
tmp.fill('*', m_Length);
|
|
|
|
|
|
|
|
setText(tmp);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ThreeStars:
|
|
|
|
|
|
|
|
tmp.fill('*', m_Length*3);
|
|
|
|
|
|
|
|
setText(tmp);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NoEcho: default:
|
|
|
|
|
|
|
|
emit textChanged(TQString::null); //To update the password comparison if need be.
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KPasswordEdit::setMaxPasswordLength(int newLength)
|
|
|
|
bool KPasswordEdit::event(TQEvent *e) {
|
|
|
|
{
|
|
|
|
return TQLineEdit::event(e);
|
|
|
|
if (newLength >= PassLen) newLength = PassLen - 1; // belt and braces
|
|
|
|
|
|
|
|
if (newLength < 0) newLength = 0;
|
|
|
|
|
|
|
|
int* t = ourMaxLength(this);
|
|
|
|
|
|
|
|
*t = newLength;
|
|
|
|
|
|
|
|
while (m_Length > newLength) {
|
|
|
|
|
|
|
|
m_Password[m_Length] = '\000';
|
|
|
|
|
|
|
|
--m_Length;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
showPass();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int KPasswordEdit::maxPasswordLength() const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return *(ourMaxLength(this));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Password dialog.
|
|
|
|
* Password dialog.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -306,7 +180,7 @@ int KPasswordEdit::maxPasswordLength() const
|
|
|
|
KPasswordDialog::KPasswordDialog(Types type, bool enableKeep, int extraBttn,
|
|
|
|
KPasswordDialog::KPasswordDialog(Types type, bool enableKeep, int extraBttn,
|
|
|
|
TQWidget *parent, const char *name)
|
|
|
|
TQWidget *parent, const char *name)
|
|
|
|
: KDialogBase(parent, name, true, "", Ok|Cancel|extraBttn,
|
|
|
|
: KDialogBase(parent, name, true, "", Ok|Cancel|extraBttn,
|
|
|
|
Ok, true), m_Keep(enableKeep? 1 : 0), m_keepWarnLbl(0), m_Type(type), d(new KPasswordDialogPrivate)
|
|
|
|
Ok, true), m_Keep(enableKeep? 1 : 0), m_Type(type), m_keepWarnLbl(0), d(new KPasswordDialogPrivate)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
d->iconName = "password";
|
|
|
|
d->iconName = "password";
|
|
|
|
init();
|
|
|
|
init();
|
|
|
@ -315,7 +189,7 @@ KPasswordDialog::KPasswordDialog(Types type, bool enableKeep, int extraBttn,
|
|
|
|
KPasswordDialog::KPasswordDialog(Types type, bool enableKeep, int extraBttn, const TQString& icon,
|
|
|
|
KPasswordDialog::KPasswordDialog(Types type, bool enableKeep, int extraBttn, const TQString& icon,
|
|
|
|
TQWidget *parent, const char *name )
|
|
|
|
TQWidget *parent, const char *name )
|
|
|
|
: KDialogBase(parent, name, true, "", Ok|Cancel|extraBttn,
|
|
|
|
: KDialogBase(parent, name, true, "", Ok|Cancel|extraBttn,
|
|
|
|
Ok, true), m_Keep(enableKeep? 1 : 0), m_keepWarnLbl(0), m_Type(type), d(new KPasswordDialogPrivate)
|
|
|
|
Ok, true), m_Keep(enableKeep? 1 : 0), m_Type(type), m_keepWarnLbl(0), d(new KPasswordDialogPrivate)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ( icon.stripWhiteSpace().isEmpty() )
|
|
|
|
if ( icon.stripWhiteSpace().isEmpty() )
|
|
|
|
d->iconName = "password";
|
|
|
|
d->iconName = "password";
|
|
|
@ -327,7 +201,7 @@ KPasswordDialog::KPasswordDialog(Types type, bool enableKeep, int extraBttn, con
|
|
|
|
KPasswordDialog::KPasswordDialog(int type, TQString prompt, bool enableKeep,
|
|
|
|
KPasswordDialog::KPasswordDialog(int type, TQString prompt, bool enableKeep,
|
|
|
|
int extraBttn)
|
|
|
|
int extraBttn)
|
|
|
|
: KDialogBase(0L, "Password Dialog", true, "", Ok|Cancel|extraBttn,
|
|
|
|
: KDialogBase(0L, "Password Dialog", true, "", Ok|Cancel|extraBttn,
|
|
|
|
Ok, true), m_Keep(enableKeep? 1 : 0), m_keepWarnLbl(0), m_Type(type), d(new KPasswordDialogPrivate)
|
|
|
|
Ok, true), m_Keep(enableKeep? 1 : 0), m_Type(type), m_keepWarnLbl(0), d(new KPasswordDialogPrivate)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
d->iconName = "password";
|
|
|
|
d->iconName = "password";
|
|
|
|
init();
|
|
|
|
init();
|
|
|
|