1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/*
kopetepasswordwidget.cpp - widget for modifying a Kopete::Password
Copyright (c) 2003 by Richard Smith <kde@metafoo.co.uk>
Kopete (c) 2003 by the Kopete developers <kopete-devel@kde.org>
*************************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
*************************************************************************
*/
#include "kopetepasswordwidget.h"
#include "kopetepassword.h"
#include <kpassdlg.h>
#include <tqcheckbox.h>
class Kopete::UI::PasswordWidget::Private
{
public:
uint maxLength;
};
Kopete::UI::PasswordWidget::PasswordWidget( TQWidget *tqparent, const char *name, Kopete::Password *from )
: KopetePasswordWidgetBase( tqparent, name ), d( new Private )
{
load( from );
}
Kopete::UI::PasswordWidget::~PasswordWidget()
{
delete d;
}
void Kopete::UI::PasswordWidget::load( Kopete::Password *source )
{
disconnect( mRemembered, TQT_SIGNAL( stateChanged( int ) ), this, TQT_SLOT( slotRememberChanged() ) );
disconnect( mPassword, TQT_SIGNAL( textChanged( const TQString & ) ), this, TQT_SIGNAL( changed() ) );
disconnect( mRemembered, TQT_SIGNAL( stateChanged( int ) ), this, TQT_SIGNAL( changed() ) );
if ( source && source->remembered() )
{
mRemembered->setTristate();
mRemembered->setNoChange();
source->requestWithoutPrompt( TQT_TQOBJECT(this), TQT_SLOT( receivePassword( const TQString & ) ) );
}
else
{
mRemembered->setTristate( false );
mRemembered->setChecked( false );
}
if ( source )
d->maxLength = source->maximumLength();
else
d->maxLength = 0;
mPassword->setEnabled( false );
connect( mRemembered, TQT_SIGNAL( stateChanged( int ) ), this, TQT_SLOT( slotRememberChanged() ) );
connect( mPassword, TQT_SIGNAL( textChanged( const TQString & ) ), this, TQT_SIGNAL( changed() ) );
connect( mRemembered, TQT_SIGNAL( stateChanged( int ) ), this, TQT_SIGNAL( changed() ) );
emit changed();
}
void Kopete::UI::PasswordWidget::slotRememberChanged()
{
mRemembered->setTristate( false );
mPassword->setEnabled( mRemembered->isChecked() );
}
void Kopete::UI::PasswordWidget::receivePassword( const TQString &pwd )
{
// pwd == null could mean user declined to open wallet
// don't uncheck the remembered field in this case.
if ( !pwd.isNull() && mRemembered->state() == TQButton::NoChange )
{
mRemembered->setChecked( true );
setPassword( pwd );
}
}
void Kopete::UI::PasswordWidget::save( Kopete::Password *target )
{
if ( !target || mRemembered->state() == TQButton::NoChange )
return;
if ( mRemembered->isChecked() )
target->set( password() );
else
target->set();
}
bool Kopete::UI::PasswordWidget::validate()
{
if ( !mRemembered->isChecked() ) return true;
if ( d->maxLength == 0 ) return true;
return password().length() <= d->maxLength;
}
TQString Kopete::UI::PasswordWidget::password() const
{
return TQString::fromLocal8Bit( mPassword->password() );
}
bool Kopete::UI::PasswordWidget::remember() const
{
return mRemembered->state() == TQButton::On;
}
void Kopete::UI::PasswordWidget::setPassword( const TQString &pass )
{
// switch out of 'waiting for wallet' mode if we're in it
mRemembered->setTristate( false );
// fill in the password text
mPassword->erase();
mPassword->insert( pass );
mPassword->setEnabled( remember() );
}
#include "kopetepasswordwidget.moc"
// vim: set noet ts=4 sts=4 sw=4:
|