• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kopete/libkopete

  • sources
  • kde-4.14
  • kdenetwork
  • kopete
  • libkopete
  • ui
kopetepasswordwidget.cpp
Go to the documentation of this file.
1 /*
2  kopetepasswordwidget.cpp - widget for modifying a Kopete::Password
3 
4  Copyright (c) 2003 by Richard Smith <kde@metafoo.co.uk>
5 
6  Kopete (c) 2003 by the Kopete developers <kopete-devel@kde.org>
7 
8  *************************************************************************
9  * *
10  * This library is free software; you can redistribute it and/or *
11  * modify it under the terms of the GNU Lesser General Public *
12  * License as published by the Free Software Foundation; either *
13  * version 2 of the License, or (at your option) any later version. *
14  * *
15  *************************************************************************
16 */
17 
18 #include "kopetepasswordwidget.h"
19 #include "kopetepassword.h"
20 #include "kopeteprotocol.h"
21 
22 #include <klineedit.h>
23 
24 #include <qcheckbox.h>
25 
26 namespace Kopete
27 {
28  namespace UI
29  {
30  class PasswordWidget::Private
31  {
32  public:
33  Private() : protocol( 0 ) { }
34  Kopete::Protocol * protocol;
35  };
36  } // namespace UI
37 } // namespace Kopete
38 
39 Kopete::UI::PasswordWidget::PasswordWidget( QWidget *parent )
40  : QWidget( parent ), d( new Private )
41 {
42  setupUi( this );
43  mPassword->setPasswordMode(true);
44 }
45 
46 Kopete::UI::PasswordWidget::PasswordWidget( Kopete::Password *from, QWidget *parent )
47  : QWidget( parent ), d( new Private )
48 {
49  setupUi( this );
50  mPassword->setPasswordMode(true);
51 
52  load( from );
53 }
54 
55 Kopete::UI::PasswordWidget::~PasswordWidget()
56 {
57  delete d;
58 }
59 
60 void Kopete::UI::PasswordWidget::setValidationProtocol( Kopete::Protocol * proto )
61 {
62  d->protocol = proto;
63 }
64 
65 void Kopete::UI::PasswordWidget::load( Kopete::Password *source )
66 {
67  disconnect( mRemembered, SIGNAL(stateChanged(int)), this, SLOT(slotRememberChanged()) );
68  disconnect( mPassword, SIGNAL(textChanged(QString)),
69  this, SLOT(passwordTextChanged()) );
70  disconnect( mRemembered, SIGNAL(stateChanged(int)), this, SIGNAL(changed()) );
71 
72  if ( source && source->remembered() )
73  {
74  mRemembered->setTristate();
75  mRemembered->setCheckState( Qt::PartiallyChecked );
76  mPassword->setEnabled( true );
77  source->requestWithoutPrompt( this, SLOT(receivePassword(QString)) );
78  }
79  else
80  {
81  mRemembered->setTristate( false );
82  mRemembered->setCheckState( Qt::Unchecked );
83  mPassword->setEnabled( false );
84  }
85 
86  connect( mRemembered, SIGNAL(stateChanged(int)), this, SLOT(slotRememberChanged()) );
87  connect( mPassword, SIGNAL(textChanged(QString)),
88  this, SLOT(passwordTextChanged()) );
89  connect( mRemembered, SIGNAL(stateChanged(int)), this, SIGNAL(changed()) );
90 
91  emit changed();
92 }
93 
94 void Kopete::UI::PasswordWidget::slotRememberChanged()
95 {
96  mRemembered->setTristate( false );
97  mPassword->setEnabled( mRemembered->isChecked() );
98 }
99 
100 void Kopete::UI::PasswordWidget::receivePassword( const QString &pwd )
101 {
102  // pwd == null could mean user declined to open wallet
103  // don't uncheck the remembered field in this case.
104  if ( !pwd.isNull() && mRemembered->checkState() == Qt::PartiallyChecked )
105  {
106  mRemembered->setChecked( true );
107  setPassword( pwd );
108  }
109 }
110 
111 void Kopete::UI::PasswordWidget::save( Kopete::Password *target )
112 {
113  if ( !target || mRemembered->checkState() == Qt::PartiallyChecked )
114  return;
115 
116  if ( mRemembered->isChecked() )
117  target->set( password() );
118  else
119  target->set();
120 }
121 
122 bool Kopete::UI::PasswordWidget::validate()
123 {
124  // Unchecked means the password should not be remembered, partially checked
125  // we're waiting for kwallet. Let it pass in both cases.
126  if ( mRemembered->checkState() != Qt::Checked )
127  return true;
128 
129  if ( d->protocol ) {
130  return d->protocol->validatePassword( password() );
131  }
132  return true;
133 }
134 
135 QString Kopete::UI::PasswordWidget::password() const
136 {
137  return mPassword->text();
138 }
139 
140 bool Kopete::UI::PasswordWidget::remember() const
141 {
142  return mRemembered->checkState() == Qt::Checked;
143 }
144 
145 void Kopete::UI::PasswordWidget::setPassword( const QString &pass )
146 {
147  // switch out of 'waiting for wallet' mode if we're in it
148  mRemembered->setTristate( false );
149 
150  // fill in the password text
151  mPassword->clear();
152  mPassword->setText( pass );
153  mPassword->setEnabled( remember() );
154 }
155 
156 void Kopete::UI::PasswordWidget::passwordTextChanged()
157 {
158  if ( mRemembered->checkState() == Qt::PartiallyChecked )
159  {
160  disconnect( mRemembered, SIGNAL(stateChanged(int)), this, SIGNAL(changed()) );
161  // switch out of 'waiting for wallet' mode if we're in it
162  mRemembered->setTristate( false );
163  mRemembered->setChecked(true);
164  connect( mRemembered, SIGNAL(stateChanged(int)), this, SIGNAL(changed()) );
165  }
166  emit changed();
167 }
168 
169 #include "kopetepasswordwidget.moc"
170 
171 // vim: set noet ts=4 sts=4 sw=4:
Kopete::Password::set
void set(const QString &pass=QString())
Set the password for this account.
Definition: kopetepassword.cpp:433
QWidget
Kopete::UI::PasswordWidget::PasswordWidget
PasswordWidget(QWidget *parent=0)
Definition: kopetepasswordwidget.cpp:39
QWidget::setupUi
void setupUi(QWidget *widget)
Kopete::UI::PasswordWidget::remember
bool remember() const
Returns a boolean indicating whether the Remember Password checkbox is checked.
Definition: kopetepasswordwidget.cpp:140
Kopete::UI::PasswordWidget::password
QString password() const
Returns the string currently in the input box in the widget.
Definition: kopetepasswordwidget.cpp:135
Kopete::UI::PasswordWidget::validate
bool validate()
Returns true if the information in the widget is valid, false if it is not.
Definition: kopetepasswordwidget.cpp:122
Kopete::UI::PasswordWidget::setValidationProtocol
void setValidationProtocol(Kopete::Protocol *)
Sets a protocol to use to validate entered passwords.
Definition: kopetepasswordwidget.cpp:60
Kopete::Protocol
base class of every protocol.
Definition: kopeteprotocol.h:62
Kopete::UI::PasswordWidget::save
void save(Kopete::Password *target)
Saves the information in the widget into target.
Definition: kopetepasswordwidget.cpp:111
QString::isNull
bool isNull() const
kopeteprotocol.h
kopetepasswordwidget.h
QString
Kopete::Password::requestWithoutPrompt
void requestWithoutPrompt(QObject *receiver, const char *slot)
Start an asynchronous password request without a prompt.
Definition: kopetepassword.cpp:413
Kopete::UI::PasswordWidget::~PasswordWidget
~PasswordWidget()
Definition: kopetepasswordwidget.cpp:55
Kopete::Password
Definition: kopetepassword.h:48
Kopete::UI::PasswordWidget::load
void load(Kopete::Password *source)
Loads the information stored in source into the widget.
Definition: kopetepasswordwidget.cpp:65
kopetepassword.h
Kopete::UI::PasswordWidget::setPassword
void setPassword(const QString &pass)
Set the password stored in the widget.
Definition: kopetepasswordwidget.cpp:145
Kopete::Password::remembered
bool remembered()
Definition: kopetepassword.cpp:454
Kopete::UI::PasswordWidget::receivePassword
void receivePassword(const QString &)
Definition: kopetepasswordwidget.cpp:100
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:29:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/libkopete

Skip menu "kopete/libkopete"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal