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

« back to all changes in this revision

Viewing changes to protocols/yahoo/yahooeditaccount.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
    yahooeditaccount.cpp - UI Page to edit a Yahoo account
 
3
 
 
4
    Copyright (c) 2003 by Matt Rogers <mattrogers@sbcglobal.net>
 
5
    Copyright (c) 2002 by Gav Wood <gav@kde.org>
 
6
 
 
7
    Copyright (c) 2002 by the Kopete developers  <kopete-devel@kde.org>
 
8
 
 
9
    *************************************************************************
 
10
    *                                                                       *
 
11
    * This program is free software; you can redistribute it and/or modify  *
 
12
    * it under the terms of the GNU General Public License as published by  *
 
13
    * the Free Software Foundation; either version 2 of the License, or     *
 
14
    * (at your option) any later version.                                   *
 
15
    *                                                                       *
 
16
    *************************************************************************
 
17
*/
 
18
 
 
19
// QT Includes
 
20
#include <QCheckBox>
 
21
#include <QImage>
 
22
#include <QLabel>
 
23
#include <QLayout>
 
24
#include <QLineEdit>
 
25
#include <QPushButton>
 
26
#include <QSpinBox>
 
27
#include <QPixmap>
 
28
#include <QLatin1String>
 
29
 
 
30
// KDE Includes
 
31
#include <klocale.h>
 
32
#include <kdebug.h>
 
33
#include <kmessagebox.h>
 
34
#include <krun.h>
 
35
#include <kurl.h>
 
36
#include <kfiledialog.h>
 
37
#include <kpassworddialog.h>
 
38
#include <kconfig.h>
 
39
#include <kstandarddirs.h>
 
40
#include <ktoolinvocation.h>
 
41
 
 
42
// Kopete Includes
 
43
#include <addcontactpage.h>
 
44
#include <kopeteuiglobal.h>
 
45
#include <avatardialog.h>
 
46
 
 
47
// Local Includes
 
48
#include "yahooaccount.h"
 
49
#include "yahoocontact.h"
 
50
#include "yahooeditaccount.h"
 
51
 
 
52
// Yahoo Add Contact page
 
53
YahooEditAccount::YahooEditAccount(YahooProtocol *protocol, Kopete::Account *theAccount, QWidget *parent): QWidget(parent), KopeteEditAccountWidget(theAccount)
 
54
{
 
55
        setupUi(this);
 
56
        kDebug(YAHOO_GEN_DEBUG) ;
 
57
 
 
58
        theProtocol = protocol;
 
59
 
 
60
        if(YahooAccount *acct = dynamic_cast<YahooAccount*>(account()))
 
61
        {       mScreenName->setText(acct->accountId());
 
62
                mScreenName->setReadOnly(true); //the accountId is Constant FIXME: remove soon!
 
63
                mAutoConnect->setChecked(acct->excludeConnect());
 
64
                mPasswordWidget->load( &acct->password() );
 
65
 
 
66
                QString pagerServer = account()->configGroup()->readEntry("Server", "scsa.msg.yahoo.com");
 
67
                int pagerPort = account()->configGroup()->readEntry("Port", 5050);
 
68
                if( pagerServer != "scsa.msg.yahoo.com" || pagerPort != 5050 )
 
69
                        optionOverrideServer->setChecked( true );
 
70
                else
 
71
                        optionOverrideServer->setChecked( false );
 
72
                editServerAddress->setText( pagerServer );
 
73
                sbxServerPort->setValue( pagerPort );
 
74
 
 
75
                QString iconUrl = account()->configGroup()->readEntry("pictureUrl", "");
 
76
                bool sendPicture = account()->configGroup()->readEntry("sendPicture", false);
 
77
                optionSendBuddyIcon->setChecked( sendPicture );
 
78
                buttonSelectPicture->setEnabled( sendPicture );  
 
79
                connect( optionSendBuddyIcon, SIGNAL(toggled(bool)), buttonSelectPicture, SLOT(setEnabled(bool)) ); 
 
80
                m_photoPath = iconUrl;
 
81
                if( !iconUrl.isEmpty() )
 
82
                        m_Picture->setPixmap( iconUrl );
 
83
                groupBox->hide();
 
84
        }
 
85
 
 
86
        QObject::connect(buttonRegister, SIGNAL(clicked()), this, SLOT(slotOpenRegister()));
 
87
        QObject::connect(buttonSelectPicture, SIGNAL(clicked()), this, SLOT(slotSelectPicture()));
 
88
 
 
89
        optionSendBuddyIcon->setEnabled( account() );
 
90
 
 
91
        /* Set tab order to password custom widget correctly */
 
92
        QWidget::setTabOrder( mScreenName, mPasswordWidget->mRemembered );
 
93
        QWidget::setTabOrder( mPasswordWidget->mRemembered, mPasswordWidget->mPassword );
 
94
        QWidget::setTabOrder( mPasswordWidget->mPassword, mAutoConnect );
 
95
 
 
96
        show();
 
97
}
 
98
 
 
99
bool YahooEditAccount::validateData()
 
100
{
 
101
        kDebug(YAHOO_GEN_DEBUG) ;
 
102
 
 
103
        if(mScreenName->text().isEmpty())
 
104
        {       KMessageBox::queuedMessageBox(this, KMessageBox::Sorry,
 
105
                        i18n("<qt>You must enter a valid screen name.</qt>"), i18n("Yahoo"));
 
106
                return false;
 
107
        }
 
108
        if(!mPasswordWidget->validate())
 
109
        {       KMessageBox::queuedMessageBox(this, KMessageBox::Sorry,
 
110
                        i18n("<qt>You must enter a valid password.</qt>"), i18n("Yahoo"));
 
111
                return false;
 
112
        }
 
113
        return true;
 
114
}
 
115
 
 
116
Kopete::Account *YahooEditAccount::apply()
 
117
{
 
118
        kDebug(YAHOO_GEN_DEBUG) ;
 
119
 
 
120
        if ( !account() )
 
121
                setAccount( new YahooAccount( theProtocol, mScreenName->text().toLower() ) );
 
122
 
 
123
        YahooAccount *yahooAccount = static_cast<YahooAccount *>( account() );
 
124
 
 
125
        yahooAccount->setExcludeConnect( mAutoConnect->isChecked() );
 
126
 
 
127
        mPasswordWidget->save( &yahooAccount->password() );
 
128
 
 
129
        if ( optionOverrideServer->isChecked() )
 
130
        {
 
131
                yahooAccount->setServer( editServerAddress->text().trimmed() );
 
132
                yahooAccount->setPort( sbxServerPort->value() );
 
133
        }
 
134
        else
 
135
        {
 
136
                yahooAccount->setServer( "scsa.msg.yahoo.com" );
 
137
                yahooAccount->setPort( 5050 );
 
138
        }
 
139
 
 
140
        account()->configGroup()->writeEntry("pictureUrl", m_photoPath );
 
141
        account()->configGroup()->writeEntry("sendPicture", optionSendBuddyIcon->isChecked() );
 
142
        if ( optionSendBuddyIcon->isChecked() )
 
143
        {
 
144
                yahooAccount->setBuddyIcon( m_photoPath );
 
145
        }
 
146
        else
 
147
        {
 
148
                yahooAccount->setBuddyIcon( KUrl() );
 
149
        }
 
150
        
 
151
        return yahooAccount;
 
152
}
 
153
 
 
154
void YahooEditAccount::slotOpenRegister()
 
155
{
 
156
        KToolInvocation::invokeBrowser( QLatin1String("http://edit.yahoo.com/config/eval_register?new=1") );
 
157
}
 
158
 
 
159
void YahooEditAccount::slotSelectPicture()
 
160
{
 
161
        QString file = Kopete::UI::AvatarDialog::getAvatar( this, m_photoPath );
 
162
 
 
163
        QPixmap pix(file);
 
164
        if( !pix.isNull() )
 
165
        {
 
166
                m_photoPath =  file;
 
167
                m_Picture->setPixmap( pix );
 
168
        }
 
169
        else
 
170
        {
 
171
                KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18n( "<qt>The selected buddy icon could not be opened. <br />Please set a new buddy icon.</qt>" ), i18n( "Yahoo Plugin" ) );
 
172
                return;
 
173
        }
 
174
}
 
175
 
 
176
#include "yahooeditaccount.moc"
 
177
 
 
178
// vim: set noet ts=4 sts=4 sw=4:
 
179