summaryrefslogtreecommitdiffstats
path: root/kopete/libkopete/kopetepasswordedaccount.cpp
blob: 899275c5a944d8b03c2051a9d4e920588db86acf (plain)
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
/*
    kopetepasswordedaccount.cpp - Kopete Account with a password

    Copyright (c) 2004      by Richard Smith         <kde@metafoo.co.uk>
    Kopete    (c) 2002-2004 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 "kopetepasswordedaccount.h"
#include "kopetepassword.h"
#include "kopeteprotocol.h"
#include "kopeteonlinestatus.h"

#include <klocale.h>

#include <tqpixmap.h>

struct Kopete::PasswordedAccount::Private
{
	Private( const TQString &group, uint maxLen, bool allowBlankPassword ) :
		password( group, maxLen, allowBlankPassword, "mPassword" ) {}
	Kopete::Password password;
	Kopete::OnlineStatus initialStatus;
};

Kopete::PasswordedAccount::PasswordedAccount( Kopete::Protocol *parent, const TQString &acctId, uint maxLen, const char *name )
 : Kopete::Account( parent, acctId, name ), d( new Private( TQString::fromLatin1("Account_")+ parent->pluginId() + TQString::fromLatin1("_") + acctId , maxLen, false ) )
{
}

Kopete::PasswordedAccount::PasswordedAccount( Kopete::Protocol *parent, const TQString &acctId, uint maxLen,
	bool allowBlankPassword, const char *name )
 : Kopete::Account( parent, acctId, name ), d( new Private( TQString::fromLatin1("Account_")+ parent->pluginId() + TQString::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;
	TQString cached = password().cachedValue();
	if( !cached.isNull() || d->password.allowBlankPassword() )
	{
		connectWithPassword( cached );
		return;
	}

	TQString prompt = passwordPrompt();
	Kopete::Password::PasswordSource src = password().isWrong() ? Kopete::Password::FromUser : Kopete::Password::FromConfigOrUser;

	password().request( this, TQT_SLOT( connectWithPassword( const TQString & ) ), accountIcon( Kopete::Password::preferredImageSize() ), prompt, src );
}

TQString Kopete::PasswordedAccount::passwordPrompt()
{
	if ( password().isWrong() )
		return i18n( "<b>The password was wrong;</b> please re-enter your password for %1 account <b>%2</b>" ).tqarg( protocol()->displayName(), accountId() );
	else
		return i18n( "Please enter your password for %1 account <b>%2</b>" ).tqarg( protocol()->displayName(), accountId() );
}

Kopete::OnlineStatus Kopete::PasswordedAccount::initialStatus()
{
	return d->initialStatus;
}

bool Kopete::PasswordedAccount::removeAccount()
{
	password().set(TQString());
	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: