~ubuntu-branches/ubuntu/saucy/kopete/saucy-proposed

« back to all changes in this revision

Viewing changes to libkopete/kopetepasswordedaccount.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-06-21 02:22:39 UTC
  • Revision ID: package-import@ubuntu.com-20130621022239-63l3zc8p0nf26pt6
Tags: upstream-4.10.80
ImportĀ upstreamĀ versionĀ 4.10.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    kopetepasswordedaccount.cpp - Kopete Account with a password
 
3
 
 
4
    Copyright (c) 2004      by Richard Smith         <kde@metafoo.co.uk>
 
5
    Kopete    (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
 
6
 
 
7
    *************************************************************************
 
8
    *                                                                       *
 
9
    * This library is free software; you can redistribute it and/or         *
 
10
    * modify it under the terms of the GNU Lesser General Public            *
 
11
    * License as published by the Free Software Foundation; either          *
 
12
    * version 2 of the License, or (at your option) any later version.      *
 
13
    *                                                                       *
 
14
    *************************************************************************
 
15
*/
 
16
 
 
17
#include "kopetepasswordedaccount.h"
 
18
#include "kopetepassword.h"
 
19
#include "kopeteprotocol.h"
 
20
#include "kopeteonlinestatus.h"
 
21
 
 
22
#include <klocale.h>
 
23
 
 
24
#include <qpixmap.h>
 
25
 
 
26
struct Kopete::PasswordedAccount::Private
 
27
{
 
28
        Private( const QString &group, bool allowBlankPassword ) :
 
29
                password( group, allowBlankPassword ) {}
 
30
        Kopete::Password password;
 
31
        Kopete::OnlineStatus initialStatus;
 
32
};
 
33
 
 
34
Kopete::PasswordedAccount::PasswordedAccount( Kopete::Protocol *parent, const QString &acctId, bool allowBlankPassword )
 
35
 : Kopete::Account( parent, acctId ), d( new Private( QString::fromLatin1("Account_")+ parent->pluginId() + QString::fromLatin1("_") + acctId , allowBlankPassword  ) )
 
36
{
 
37
}
 
38
 
 
39
Kopete::PasswordedAccount::~PasswordedAccount()
 
40
{
 
41
        delete d;
 
42
}
 
43
 
 
44
Kopete::Password &Kopete::PasswordedAccount::password()
 
45
{
 
46
        return d->password;
 
47
}
 
48
 
 
49
void Kopete::PasswordedAccount::connect( )
 
50
{
 
51
        Kopete::OnlineStatus s(Kopete::OnlineStatus::Online);
 
52
        connect( s );
 
53
}
 
54
 
 
55
void Kopete::PasswordedAccount::connect( const Kopete::OnlineStatus& initialStatus )
 
56
{
 
57
        // warn user somewhere
 
58
        d->initialStatus = initialStatus;
 
59
        QString cached = password().cachedValue();
 
60
        if( !cached.isNull() || d->password.allowBlankPassword() )
 
61
        {
 
62
                connectWithPassword( cached );
 
63
                return;
 
64
        }
 
65
 
 
66
        QString prompt = passwordPrompt();
 
67
        Kopete::Password::PasswordSource src = password().isWrong() ? Kopete::Password::FromUser : Kopete::Password::FromConfigOrUser;
 
68
 
 
69
        password().request( this, SLOT(connectWithPassword(QString)), accountIcon( Kopete::Password::preferredImageSize() ), prompt, src );
 
70
}
 
71
 
 
72
QString Kopete::PasswordedAccount::passwordPrompt()
 
73
{
 
74
        if ( password().isWrong() )
 
75
                return i18n( "<qt><b>The password was wrong.</b> Please re-enter your password for %1 account <b>%2</b></qt>", protocol()->displayName(), accountId() );
 
76
        else
 
77
                return i18n( "<qt>Please enter your password for %1 account <b>%2</b></qt>", protocol()->displayName(), accountId() );
 
78
}
 
79
 
 
80
Kopete::OnlineStatus Kopete::PasswordedAccount::initialStatus()
 
81
{
 
82
        return d->initialStatus;
 
83
}
 
84
 
 
85
bool Kopete::PasswordedAccount::removeAccount()
 
86
{
 
87
        password().set(QString::null);  //krazy:exclude=nullstrassign for old broken gcc
 
88
        return Kopete::Account::removeAccount();
 
89
}
 
90
 
 
91
void Kopete::PasswordedAccount::disconnected( Kopete::Account::DisconnectReason reason )
 
92
{
 
93
        if(reason==Kopete::Account::BadPassword || reason==Kopete::Account::BadUserName)
 
94
        {
 
95
                password().setWrong(true);
 
96
        }
 
97
        Kopete::Account::disconnected(reason);
 
98
}
 
99
 
 
100
 
 
101
#include "kopetepasswordedaccount.moc"
 
102
 
 
103
// vim: set noet ts=4 sts=4 sw=4: