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 --- .../meanwhile/meanwhileeditaccountwidget.cpp | 194 +++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 kopete/protocols/meanwhile/meanwhileeditaccountwidget.cpp (limited to 'kopete/protocols/meanwhile/meanwhileeditaccountwidget.cpp') diff --git a/kopete/protocols/meanwhile/meanwhileeditaccountwidget.cpp b/kopete/protocols/meanwhile/meanwhileeditaccountwidget.cpp new file mode 100644 index 00000000..f3d05710 --- /dev/null +++ b/kopete/protocols/meanwhile/meanwhileeditaccountwidget.cpp @@ -0,0 +1,194 @@ +/* + meanwhileeditaccountwidget.cpp - edit an account + + Copyright (c) 2003-2004 by Sivaram Gottimukkala + + Kopete (c) 2002-2004 by the Kopete developers + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "meanwhileprotocol.h" +#include "meanwhileaccount.h" +#include "meanwhileeditaccountwidget.h" +#include "meanwhilesession.h" + +#define DEFAULT_SERVER "messaging.opensource.ibm.com" +#define DEFAULT_PORT 1533 + +void MeanwhileEditAccountWidget::setupClientList() +{ + const struct MeanwhileClientID *id; + int i = 0; + + for (id = MeanwhileSession::getClientIDs(); id->name; id++, i++) { + QString name = QString("%1 (0x%2)") + .arg(QString(id->name)) + .arg(id->id, 0, 16); + + mClientID->insertItem(name, i); + + if (id->id == mwLogin_MEANWHILE) + mClientID->setCurrentItem(i); + } +} + +void MeanwhileEditAccountWidget::selectClientListItem(int selectedID) +{ + const struct MeanwhileClientID *id; + int i = 0; + + for (id = MeanwhileSession::getClientIDs(); id->name; id++, i++) { + if (id->id == selectedID) { + mClientID->setCurrentItem(i); + break; + } + } +} + +MeanwhileEditAccountWidget::MeanwhileEditAccountWidget( + QWidget* parent, + Kopete::Account* theAccount, + MeanwhileProtocol *theProtocol) + : MeanwhileEditAccountBase(parent), + KopeteEditAccountWidget( theAccount ) +{ + protocol = theProtocol; + + /* setup client identifier combo box */ + setupClientList(); + + if (account()) + { + int clientID, verMajor, verMinor; + bool useCustomID; + + mScreenName->setText(account()->accountId()); + mScreenName->setReadOnly(true); + mScreenName->setDisabled(true); + mPasswordWidget->load(&static_cast(account())->password()); + mAutoConnect->setChecked(account()->excludeConnect()); + + MeanwhileAccount *myAccount = static_cast(account()); + useCustomID = myAccount->getClientIDParams(&clientID, + &verMajor, &verMinor); + + mServerName->setText(myAccount->getServerName()); + mServerPort->setValue(myAccount->getServerPort()); + + if (useCustomID) { + selectClientListItem(clientID); + mClientVersionMajor->setValue(verMajor); + mClientVersionMinor->setValue(verMinor); + chkCustomClientID->setChecked(true); + } + + } + else + { + slotSetServer2Default(); + } + + QObject::connect(btnServerDefaults, SIGNAL(clicked()), + SLOT(slotSetServer2Default())); + + show(); +} + +MeanwhileEditAccountWidget::~MeanwhileEditAccountWidget() +{ +} + + +Kopete::Account* MeanwhileEditAccountWidget::apply() +{ + if(!account()) + setAccount(new MeanwhileAccount(protocol, mScreenName->text())); + + MeanwhileAccount *myAccount = static_cast(account()); + + myAccount->setExcludeConnect(mAutoConnect->isChecked()); + + mPasswordWidget->save(&static_cast(account())->password()); + + myAccount->setServerName(mServerName->text()); + myAccount->setServerPort(mServerPort->value()); + + if (chkCustomClientID->isChecked()) { + const struct MeanwhileClientID *ids = MeanwhileSession::getClientIDs(); + myAccount->setClientID(ids[mClientID->currentItem()].id, + mClientVersionMajor->value(), + mClientVersionMinor->value()); + } else { + myAccount->resetClientID(); + } + + return myAccount; +} + +bool MeanwhileEditAccountWidget::validateData() +{ + if(mScreenName->text().isEmpty()) + { + KMessageBox::queuedMessageBox(this, KMessageBox::Sorry, + i18n("You must enter a valid screen name."), + i18n("Meanwhile Plugin")); + return false; + } + if( !mPasswordWidget->validate() ) + { + KMessageBox::queuedMessageBox(this, KMessageBox::Sorry, + i18n("You must deselect password remembering or enter a valid password."), + i18n("Meanwhile Plugin")); + return false; + } + if (mServerName->text().isEmpty()) + { + KMessageBox::queuedMessageBox(this, KMessageBox::Sorry, + i18n("You must enter the server's hostname/ip address."), + i18n("Meanwhile Plugin")); + return false; + } + if (mServerPort->text() == 0) + { + KMessageBox::queuedMessageBox(this, KMessageBox::Sorry, + i18n("0 is not a valid port number."), + i18n("Meanwhile Plugin")); + return false; + } + return true; +} + +void MeanwhileEditAccountWidget::slotSetServer2Default() +{ + int clientID, verMajor, verMinor; + + MeanwhileSession::getDefaultClientIDParams(&clientID, + &verMajor, &verMinor); + + mServerName->setText(DEFAULT_SERVER); + mServerPort->setValue(DEFAULT_PORT); + chkCustomClientID->setChecked(false); + selectClientListItem(clientID); + mClientVersionMajor->setValue(verMajor); + mClientVersionMinor->setValue(verMinor); +} + +#include "meanwhileeditaccountwidget.moc" -- cgit v1.2.1