From bcb704366cb5e333a626c18c308c7e0448a8e69f Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kopete/libkopete/kopetepasswordedaccount.cpp | 111 +++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 kopete/libkopete/kopetepasswordedaccount.cpp (limited to 'kopete/libkopete/kopetepasswordedaccount.cpp') diff --git a/kopete/libkopete/kopetepasswordedaccount.cpp b/kopete/libkopete/kopetepasswordedaccount.cpp new file mode 100644 index 00000000..9fea5c66 --- /dev/null +++ b/kopete/libkopete/kopetepasswordedaccount.cpp @@ -0,0 +1,111 @@ +/* + kopetepasswordedaccount.cpp - Kopete Account with a password + + Copyright (c) 2004 by Richard Smith + Kopete (c) 2002-2004 by the Kopete developers + + ************************************************************************* + * * + * 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 "kopetepasswordedaccount.h" +#include "kopetepassword.h" +#include "kopeteprotocol.h" +#include "kopeteonlinestatus.h" + +#include + +#include + +struct Kopete::PasswordedAccount::Private +{ + Private( const QString &group, uint maxLen, bool allowBlankPassword ) : + password( group, maxLen, allowBlankPassword, "mPassword" ) {} + Kopete::Password password; + Kopete::OnlineStatus initialStatus; +}; + +Kopete::PasswordedAccount::PasswordedAccount( Kopete::Protocol *parent, const QString &acctId, uint maxLen, const char *name ) + : Kopete::Account( parent, acctId, name ), d( new Private( QString::fromLatin1("Account_")+ parent->pluginId() + QString::fromLatin1("_") + acctId , maxLen, false ) ) +{ +} + +Kopete::PasswordedAccount::PasswordedAccount( Kopete::Protocol *parent, const QString &acctId, uint maxLen, + bool allowBlankPassword, const char *name ) + : Kopete::Account( parent, acctId, name ), d( new Private( QString::fromLatin1("Account_")+ parent->pluginId() + QString::fromLatin1("_") + acctId , maxLen, allowBlankPassword ) ) +{ +} + +Kopete::PasswordedAccount::~PasswordedAccount() +{ + delete d; +} + +Kopete::Password &Kopete::PasswordedAccount::password() +{ + return d->password; +} + +void Kopete::PasswordedAccount::connect( ) +{ + Kopete::OnlineStatus s(Kopete::OnlineStatus::Online); + connect( s ); +} + +void Kopete::PasswordedAccount::connect( const Kopete::OnlineStatus& initialStatus ) +{ + // check that the networkstatus is up + + // warn user somewhere + d->initialStatus = initialStatus; + QString cached = password().cachedValue(); + if( !cached.isNull() || d->password.allowBlankPassword() ) + { + connectWithPassword( cached ); + return; + } + + QString prompt = passwordPrompt(); + Kopete::Password::PasswordSource src = password().isWrong() ? Kopete::Password::FromUser : Kopete::Password::FromConfigOrUser; + + password().request( this, SLOT( connectWithPassword( const QString & ) ), accountIcon( Kopete::Password::preferredImageSize() ), prompt, src ); +} + +QString Kopete::PasswordedAccount::passwordPrompt() +{ + if ( password().isWrong() ) + return i18n( "The password was wrong; please re-enter your password for %1 account %2" ).arg( protocol()->displayName(), accountId() ); + else + return i18n( "Please enter your password for %1 account %2" ).arg( protocol()->displayName(), accountId() ); +} + +Kopete::OnlineStatus Kopete::PasswordedAccount::initialStatus() +{ + return d->initialStatus; +} + +bool Kopete::PasswordedAccount::removeAccount() +{ + password().set(QString::null); + return Kopete::Account::removeAccount(); +} + +void Kopete::PasswordedAccount::disconnected( Kopete::Account::DisconnectReason reason ) +{ + if(reason==Kopete::Account::BadPassword || reason==Kopete::Account::BadUserName) + { + password().setWrong(true); + } + Kopete::Account::disconnected(reason); +} + + +#include "kopetepasswordedaccount.moc" + +// vim: set noet ts=4 sts=4 sw=4: -- cgit v1.2.1