--Boundary-00=_XPNMHgSTbQP/eIR Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Am Sonntag 04 November 2007 14:25:13 schrieb Will Stephenson: > On Saturday 03 November 2007 19:55:24 Dennis Nienh=FCser wrote: > > please have a look at the attached patch which prevents adding accounts > > more than once. Currently kopete crashes when doing that, the patch > > modifies most plugins such that a friendly message pops up when creating > > a duplicate account in the add account wizard and proceeding to the next > > page is not possible. Additionally, the accept() method of the wizard > > does that check again (e.g. the Testbed protocol doesn't have the > > duplicate check). > > > > If there are no objections, I'll check it in. > > The patch is fine, but as discussed on IRC, this would be a good > opportunity to use Kopete::Password::validate() in validateData(). > > Will Good idea, a new patch is attached with an example implementation for the I= CQ=20 protocol (6-8 characters). I didn't add the check to any other protocols as= I=20 don't know about any other password restrictions in protocols - drop me a=20 line if you do. Changes compared to the previous patch: =2D Implemented validatePassword() for ICQ and use it in validateData() =2D Changed virtual bool validateData() to virtual bool validateData( Kopete::AccountChangeAction=20 changeAction=3DKopete::Create ) in=20 kdenetwork/kopete/libkopete/ui/editaccountwidget.h. This allows to distinguish between adding and editing accounts when validat= ing=20 data =2D Changed this in all protocols - I hope I really got them all. =2D Removed the Apply button in the Account Properties dialog. It wasn't=20 connected. Please have a look at the patch again :) Dennis --Boundary-00=_XPNMHgSTbQP/eIR Content-Type: text/x-diff; charset="iso-8859-15"; name="accountedit-datavalidation.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="accountedit-datavalidation.diff" Index: kdenetwork/kopete/protocols/yahoo/yahooeditaccount.cpp =================================================================== --- kdenetwork/kopete/protocols/yahoo/yahooeditaccount.cpp (revision 733585) +++ kdenetwork/kopete/protocols/yahoo/yahooeditaccount.cpp (working copy) @@ -43,6 +43,7 @@ #include #include #include +#include // Local Includes #include "yahooaccount.h" @@ -96,20 +97,30 @@ show(); } -bool YahooEditAccount::validateData() +bool YahooEditAccount::validateData( Kopete::AccountChangeAction changeAction ) { kDebug(YAHOO_GEN_DEBUG) ; - if(mScreenName->text().isEmpty()) + QString userName(mScreenName->text()); + if(userName.isEmpty()) { KMessageBox::queuedMessageBox(this, KMessageBox::Sorry, i18n("You must enter a valid screen name."), i18n("Yahoo")); return false; } + if(!mPasswordWidget->validate()) { KMessageBox::queuedMessageBox(this, KMessageBox::Sorry, i18n("You must enter a valid password."), i18n("Yahoo")); return false; } + + if ( changeAction == Kopete::Create && Kopete::AccountManager::self()->findAccount( "YahooProtocol", userName ) ) + { + KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18nc( "@info", + "This account already exists. Please choose a different Yahoo username or use the Configure Dialog to change the settings of the %1 account.", userName), i18n( "Yahoo" ) ); + return false; + } + return true; } Index: kdenetwork/kopete/protocols/yahoo/yahooeditaccount.h =================================================================== --- kdenetwork/kopete/protocols/yahoo/yahooeditaccount.h (revision 733585) +++ kdenetwork/kopete/protocols/yahoo/yahooeditaccount.h (working copy) @@ -43,7 +43,7 @@ public: YahooEditAccount(YahooProtocol *protocol, Kopete::Account *theAccount, QWidget *parent = 0); - virtual bool validateData(); + virtual bool validateData( Kopete::AccountChangeAction changeAction=Kopete::Create ); public slots: virtual Kopete::Account *apply(); Index: kdenetwork/kopete/protocols/gadu/gadueditaccount.h =================================================================== --- kdenetwork/kopete/protocols/gadu/gadueditaccount.h (revision 733585) +++ kdenetwork/kopete/protocols/gadu/gadueditaccount.h (working copy) @@ -38,7 +38,7 @@ public: GaduEditAccount( GaduProtocol*, Kopete::Account*, QWidget* parent = 0 ); - virtual bool validateData(); + virtual bool validateData( Kopete::AccountChangeAction changeAction=Kopete::Create ); Kopete::Account* apply(); private slots: Index: kdenetwork/kopete/protocols/gadu/gadueditaccount.cpp =================================================================== --- kdenetwork/kopete/protocols/gadu/gadueditaccount.cpp (revision 733585) +++ kdenetwork/kopete/protocols/gadu/gadueditaccount.cpp (working copy) @@ -42,6 +42,7 @@ #include #include "kopetepasswordwidget.h" +#include "kopeteaccountmanager.h" GaduEditAccount::GaduEditAccount( GaduProtocol* proto, Kopete::Account* ident, QWidget* parent ) : QWidget( parent ), KopeteEditAccountWidget( ident ), protocol_( proto ), rcmd( 0 ) @@ -210,15 +211,16 @@ } bool -GaduEditAccount::validateData() +GaduEditAccount::validateData( Kopete::AccountChangeAction changeAction ) { - if ( loginEdit_->text().isEmpty() ) { + QString userName(loginEdit_->text()); + if ( userName.isEmpty() ) { KMessageBox::sorry( this, i18n( "Enter UIN please." ), i18n( "Gadu-Gadu" ) ); return false; } - if ( loginEdit_->text().toInt() < 0 || loginEdit_->text().toInt() == 0 ) { + if ( userName.toInt() < 0 || userName.toInt() == 0 ) { KMessageBox::sorry( this, i18n( "UIN should be a positive number." ), i18n( "Gadu-Gadu" ) ); return false; } @@ -228,6 +230,13 @@ return false; } + if ( changeAction == Kopete::Create && Kopete::AccountManager::self()->findAccount( "GaduProtocol", userName ) ) + { + KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18nc( "@info", + "This account already exists. Please choose a different Gadu-Gadu UIN or use the Configure Dialog to change the settings of the %1 account.", userName), i18n( "Gadu-Gadu" ) ); + return false; + } + return true; } Index: kdenetwork/kopete/protocols/qq/ui/qqeditaccountwidget.cpp =================================================================== --- kdenetwork/kopete/protocols/qq/ui/qqeditaccountwidget.cpp (revision 733585) +++ kdenetwork/kopete/protocols/qq/ui/qqeditaccountwidget.cpp (working copy) @@ -48,6 +48,7 @@ #include "kopeteglobal.h" #include "kopetepasswordwidget.h" +#include "kopeteaccountmanager.h" #include "qqaccount.h" #include "qqcontact.h" @@ -165,14 +166,23 @@ return account(); } -bool QQEditAccountWidget::validateData() +bool QQEditAccountWidget::validateData( Kopete::AccountChangeAction changeAction ) { QString userid = d->ui->m_login->text(); + + if ( changeAction == Kopete::Create && Kopete::AccountManager::self()->findAccount( "QQProtocol", userid ) ) + { + KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18nc( "@info", + "This account already exists. Please choose a different QQ ID or use the Configure Dialog to change the settings of the %1 account.", userid), i18n( "QQ" ) ); + return false; + } + if ( QQProtocol::validContactId( userid ) ) return true; KMessageBox::queuedMessageBox( Kopete::UI::Global::mainWidget(), KMessageBox::Sorry, i18n( "You must enter a valid email address." ), i18n( "QQ Plugin" ) ); + return false; } Index: kdenetwork/kopete/protocols/qq/ui/qqeditaccountwidget.h =================================================================== --- kdenetwork/kopete/protocols/qq/ui/qqeditaccountwidget.h (revision 733585) +++ kdenetwork/kopete/protocols/qq/ui/qqeditaccountwidget.h (working copy) @@ -42,7 +42,7 @@ /** * Is the data correct? */ - virtual bool validateData(); + virtual bool validateData( Kopete::AccountChangeAction changeAction=Kopete::Create ); private slots: void slotOpenRegister(); Index: kdenetwork/kopete/protocols/winpopup/wpeditaccount.cpp =================================================================== --- kdenetwork/kopete/protocols/winpopup/wpeditaccount.cpp (revision 733585) +++ kdenetwork/kopete/protocols/winpopup/wpeditaccount.cpp (working copy) @@ -36,9 +36,9 @@ #include #include - // Kopete Includes #include +#include // Local Includes #include "wpaccount.h" @@ -93,11 +93,12 @@ mProtocol->installSamba(); } -bool WPEditAccount::validateData() +bool WPEditAccount::validateData( Kopete::AccountChangeAction changeAction ) { kDebug(14170) << "WPEditAccount::validateData()"; - if(mHostName->text().isEmpty()) { + QString hostname(mHostName->text()); + if(hostname.isEmpty()) { KMessageBox::sorry(this, i18n("You must enter a valid screen name."), i18n("WinPopup")); return false; } @@ -108,6 +109,13 @@ return false; } + if ( changeAction == Kopete::Create && Kopete::AccountManager::self()->findAccount( "WPProtocol", hostname ) ) + { + KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18nc( "@info", + "This account already exists. Please choose a different hostname or use the Configure Dialog to change the settings of the %1 account.", hostname), i18n( "WinPopup" ) ); + return false; + } + return true; } Index: kdenetwork/kopete/protocols/winpopup/wpeditaccount.h =================================================================== --- kdenetwork/kopete/protocols/winpopup/wpeditaccount.h (revision 733585) +++ kdenetwork/kopete/protocols/winpopup/wpeditaccount.h (working copy) @@ -43,7 +43,7 @@ public: WPEditAccount(QWidget *parent, Kopete::Account *theAccount); - virtual bool validateData(); + virtual bool validateData( Kopete::AccountChangeAction changeAction=Kopete::Create ); void writeConfig(); public slots: Index: kdenetwork/kopete/protocols/groupwise/ui/gweditaccountwidget.cpp =================================================================== --- kdenetwork/kopete/protocols/groupwise/ui/gweditaccountwidget.cpp (revision 733585) +++ kdenetwork/kopete/protocols/groupwise/ui/gweditaccountwidget.cpp (working copy) @@ -116,7 +116,7 @@ return account(); } -bool GroupWiseEditAccountWidget::validateData() +bool GroupWiseEditAccountWidget::validateData( Kopete::AccountChangeAction changeAction ) { return !( m_preferencesDialog->m_userId->text().isEmpty() || m_preferencesDialog->m_server->text().isEmpty() ); } Index: kdenetwork/kopete/protocols/groupwise/ui/gweditaccountwidget.h =================================================================== --- kdenetwork/kopete/protocols/groupwise/ui/gweditaccountwidget.h (revision 733585) +++ kdenetwork/kopete/protocols/groupwise/ui/gweditaccountwidget.h (working copy) @@ -49,7 +49,7 @@ /** * Is the data correct? */ - virtual bool validateData(); + virtual bool validateData( Kopete::AccountChangeAction changeAction=Kopete::Create ); protected slots: void configChanged(); protected: Index: kdenetwork/kopete/protocols/jabber/ui/jabbereditaccountwidget.cpp =================================================================== --- kdenetwork/kopete/protocols/jabber/ui/jabbereditaccountwidget.cpp (revision 733585) +++ kdenetwork/kopete/protocols/jabber/ui/jabbereditaccountwidget.cpp (working copy) @@ -32,6 +32,7 @@ #include #include #include +#include #include "kopeteuiglobal.h" #include "kopetepasswordwidget.h" @@ -194,10 +195,11 @@ account()->configGroup()->writeEntry("HideSystemInfo", cbHideSystemInfo->isChecked()); } -bool JabberEditAccountWidget::validateData () +bool JabberEditAccountWidget::validateData ( Kopete::AccountChangeAction changeAction ) { - if(!mID->text().contains('@')) + QString userId(mID->text()); + if(!userId.contains('@')) { KMessageBox::sorry(this, i18n("The Jabber ID you have chosen is invalid. " "Please make sure it is in the form user@server.com, like an email address."), @@ -206,6 +208,13 @@ return false; } + if ( changeAction == Kopete::Create && Kopete::AccountManager::self()->findAccount( "JabberProtocol", userId ) ) + { + KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18nc( "@info", + "This account already exists. Please choose a different Jabber ID or use the Configure Dialog to change the settings of the %1 account.", userId), i18n( "Jabber" ) ); + return false; + } + return true; } Index: kdenetwork/kopete/protocols/jabber/ui/jabbereditaccountwidget.h =================================================================== --- kdenetwork/kopete/protocols/jabber/ui/jabbereditaccountwidget.h (revision 733585) +++ kdenetwork/kopete/protocols/jabber/ui/jabbereditaccountwidget.h (working copy) @@ -39,7 +39,7 @@ public: JabberEditAccountWidget (JabberProtocol * proto, JabberAccount *, QWidget * parent = 0); ~JabberEditAccountWidget (); - virtual bool validateData (); + virtual bool validateData ( Kopete::AccountChangeAction changeAction=Kopete::Create ); virtual Kopete::Account *apply (); JabberAccount *account (); Index: kdenetwork/kopete/protocols/testbed/testbededitaccountwidget.cpp =================================================================== --- kdenetwork/kopete/protocols/testbed/testbededitaccountwidget.cpp (revision 733585) +++ kdenetwork/kopete/protocols/testbed/testbededitaccountwidget.cpp (working copy) @@ -58,7 +58,7 @@ return account(); } -bool TestbedEditAccountWidget::validateData() +bool TestbedEditAccountWidget::validateData( Kopete::AccountChangeAction changeAction ) { //return !( m_preferencesWidget->m_acctName->text().isEmpty() ); return true; Index: kdenetwork/kopete/protocols/testbed/testbededitaccountwidget.h =================================================================== --- kdenetwork/kopete/protocols/testbed/testbededitaccountwidget.h (revision 733585) +++ kdenetwork/kopete/protocols/testbed/testbededitaccountwidget.h (working copy) @@ -45,7 +45,7 @@ /** * Is the data correct? */ - virtual bool validateData(); + virtual bool validateData( Kopete::AccountChangeAction changeAction=Kopete::Create ); protected: Kopete::Account *m_account; Ui::TestbedAccountPreferences *m_preferencesWidget; Index: kdenetwork/kopete/protocols/msn/ui/msneditaccountwidget.cpp =================================================================== --- kdenetwork/kopete/protocols/msn/ui/msneditaccountwidget.cpp (revision 733585) +++ kdenetwork/kopete/protocols/msn/ui/msneditaccountwidget.cpp (working copy) @@ -45,6 +45,7 @@ #include "kopeteuiglobal.h" #include "kopeteglobal.h" +#include "kopeteaccountmanager.h" #include "kopetepasswordwidget.h" #include "avatardialog.h" @@ -213,9 +214,17 @@ return account(); } -bool MSNEditAccountWidget::validateData() +bool MSNEditAccountWidget::validateData( Kopete::AccountChangeAction changeAction ) { QString userid = d->ui->m_login->text(); + + if ( changeAction == Kopete::Create && Kopete::AccountManager::self()->findAccount( "MSNProtocol", userid ) ) + { + KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18nc( "@info", + "This account already exists. Please choose a different MSN Passport ID or use the Configure Dialog to change the settings of the %1 account.", userid), i18n( "MSN Plugin" ) ); + return false; + } + if ( MSNProtocol::validContactId( userid ) ) return true; Index: kdenetwork/kopete/protocols/msn/ui/msneditaccountwidget.h =================================================================== --- kdenetwork/kopete/protocols/msn/ui/msneditaccountwidget.h (revision 733585) +++ kdenetwork/kopete/protocols/msn/ui/msneditaccountwidget.h (working copy) @@ -39,7 +39,7 @@ public: MSNEditAccountWidget( MSNProtocol *proto, Kopete::Account *account, QWidget *parent = 0 ); ~MSNEditAccountWidget(); - virtual bool validateData(); + virtual bool validateData( Kopete::AccountChangeAction changeAction=Kopete::Create ); virtual Kopete::Account * apply(); private slots: Index: kdenetwork/kopete/protocols/telepathy/ui/telepathyeditaccountwidget.cpp =================================================================== --- kdenetwork/kopete/protocols/telepathy/ui/telepathyeditaccountwidget.cpp (revision 733585) +++ kdenetwork/kopete/protocols/telepathy/ui/telepathyeditaccountwidget.cpp (working copy) @@ -105,7 +105,7 @@ return static_cast( KopeteEditAccountWidget::account() ); } -bool TelepathyEditAccountWidget::validateData() +bool TelepathyEditAccountWidget::validateData( Kopete::AccountChangeAction changeAction ) { kDebug(TELEPATHY_DEBUG_AREA) ; // You must fill the form to move to the next step Index: kdenetwork/kopete/protocols/telepathy/ui/telepathyeditaccountwidget.h =================================================================== --- kdenetwork/kopete/protocols/telepathy/ui/telepathyeditaccountwidget.h (revision 733585) +++ kdenetwork/kopete/protocols/telepathy/ui/telepathyeditaccountwidget.h (working copy) @@ -42,7 +42,7 @@ explicit TelepathyEditAccountWidget(Kopete::Account *account, QWidget *parent = 0); ~TelepathyEditAccountWidget(); - virtual bool validateData(); + virtual bool validateData( Kopete::AccountChangeAction changeAction=Kopete::Create ); /** * Create a new account if we are in the 'add account wizard', Index: kdenetwork/kopete/protocols/sms/smseditaccountwidget.h =================================================================== --- kdenetwork/kopete/protocols/sms/smseditaccountwidget.h (revision 733585) +++ kdenetwork/kopete/protocols/sms/smseditaccountwidget.h (working copy) @@ -33,7 +33,7 @@ SMSEditAccountWidget(SMSProtocol *protocol, Kopete::Account *theAccount, QWidget *parent = 0); ~SMSEditAccountWidget(); - bool validateData(); + bool validateData( Kopete::AccountChangeAction changeAction=Kopete::Create ); Kopete::Account* apply(); public slots: void setServicePreferences(const QString& serviceName); Index: kdenetwork/kopete/protocols/sms/smseditaccountwidget.cpp =================================================================== --- kdenetwork/kopete/protocols/sms/smseditaccountwidget.cpp (revision 733585) +++ kdenetwork/kopete/protocols/sms/smseditaccountwidget.cpp (working copy) @@ -32,6 +32,7 @@ #include #include "kopeteuiglobal.h" +#include "kopeteaccountmanager.h" #include "smseditaccountwidget.h" #include "smsactprefs.h" @@ -90,8 +91,20 @@ delete service; } -bool SMSEditAccountWidget::validateData() +bool SMSEditAccountWidget::validateData( Kopete::AccountChangeAction changeAction ) { + QString accountId(preferencesDialog->accountId->text()); + + if (accountId.isEmpty()) + return false; + + if ( changeAction == Kopete::Create && Kopete::AccountManager::self()->findAccount( "SMSProtocol", accountId ) ) + { + KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18nc( "@info", + "This account already exists. Please choose a different account ID or use the Configure Dialog to change the settings of the %1 account.", accountId), i18n( "SMS" ) ); + return false; + } + return true; } Index: kdenetwork/kopete/protocols/oscar/aim/ui/aimeditaccountwidget.h =================================================================== --- kdenetwork/kopete/protocols/oscar/aim/ui/aimeditaccountwidget.h (revision 733585) +++ kdenetwork/kopete/protocols/oscar/aim/ui/aimeditaccountwidget.h (working copy) @@ -44,7 +44,7 @@ QWidget *parent=0); virtual ~AIMEditAccountWidget(); - virtual bool validateData(); + virtual bool validateData( Kopete::AccountChangeAction changeAction=Kopete::Create ); virtual Kopete::Account *apply(); private slots: Index: kdenetwork/kopete/protocols/oscar/aim/ui/aimeditaccountwidget.cpp =================================================================== --- kdenetwork/kopete/protocols/oscar/aim/ui/aimeditaccountwidget.cpp (revision 733585) +++ kdenetwork/kopete/protocols/oscar/aim/ui/aimeditaccountwidget.cpp (working copy) @@ -14,9 +14,11 @@ #include #include #include +#include #include "kopetepassword.h" #include "kopetepasswordwidget.h" +#include "kopeteaccountmanager.h" #include "aimprotocol.h" #include "aimaccount.h" @@ -203,7 +205,7 @@ return mAccount; } -bool AIMEditAccountWidget::validateData() +bool AIMEditAccountWidget::validateData( Kopete::AccountChangeAction changeAction ) { //kDebug(14152) << "Called."; @@ -220,6 +222,13 @@ if ( server.length() < 1 ) return false; + if ( changeAction == Kopete::Create && Kopete::AccountManager::self()->findAccount( "AIMProtocol", userName ) ) + { + KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18nc( "@info", + "This account already exists. Please choose a different AIM screen name or use the Configure Dialog to change the settings of the %1 account.", userName), i18n( "AIM" ) ); + return false; + } + // Seems good to me //kDebug(14152) << "Account data validated successfully."; return true; Index: kdenetwork/kopete/protocols/oscar/icq/icqprotocol.cpp =================================================================== --- kdenetwork/kopete/protocols/oscar/icq/icqprotocol.cpp (revision 733585) +++ kdenetwork/kopete/protocols/oscar/icq/icqprotocol.cpp (working copy) @@ -842,6 +842,11 @@ return statusManager_; } +bool ICQProtocol::validatePassword( const QString & password ) const +{ + return password.length() >= 6 && password.length() <= 8; +} + //END class ICQProtocol #include "icqprotocol.moc" Index: kdenetwork/kopete/protocols/oscar/icq/icqprotocol.h =================================================================== --- kdenetwork/kopete/protocols/oscar/icq/icqprotocol.h (revision 733585) +++ kdenetwork/kopete/protocols/oscar/icq/icqprotocol.h (working copy) @@ -76,6 +76,8 @@ void setTZComboValue(QComboBox *combo, const char &tz); char getTZComboValue(QComboBox *combo); */ + virtual bool validatePassword( const QString & password ) const; + private: void initGenders(); void initLang(); Index: kdenetwork/kopete/protocols/oscar/icq/ui/icqeditaccountwidget.cpp =================================================================== --- kdenetwork/kopete/protocols/oscar/icq/ui/icqeditaccountwidget.cpp (revision 733585) +++ kdenetwork/kopete/protocols/oscar/icq/ui/icqeditaccountwidget.cpp (working copy) @@ -38,6 +38,7 @@ #include "kopetepassword.h" #include "kopetepasswordwidget.h" +#include "kopeteaccountmanager.h" #include "icqprotocol.h" #include "icqaccount.h" @@ -68,6 +69,8 @@ QRegExp rx("[0-9]{9}"); QValidator* validator = new QRegExpValidator( rx, this ); mAccountSettings->edtAccountId->setValidator(validator); + + mAccountSettings->mPasswordWidget->setValidationProtocol(protocol); // Read in the settings from the account if it exists if(mAccount) @@ -78,7 +81,7 @@ mAccountSettings->edtAccountId->setReadOnly(true); mAccountSettings->mPasswordWidget->load(&mAccount->password()); mAccountSettings->chkAutoLogin->setChecked(mAccount->excludeConnect()); - + QString serverEntry = mAccount->configGroup()->readEntry("Server", "login.oscar.aol.com"); int portEntry = mAccount->configGroup()->readEntry("Port", 5190); if ( serverEntry != "login.oscar.aol.com" || ( portEntry != 5190) ) @@ -261,7 +264,7 @@ return mAccount; } -bool ICQEditAccountWidget::validateData() +bool ICQEditAccountWidget::validateData( Kopete::AccountChangeAction changeAction ) { kDebug(14153) << "Called."; bool bOk; @@ -274,6 +277,20 @@ return false; } + if ( changeAction == Kopete::Create && Kopete::AccountManager::self()->findAccount( "ICQProtocol", userId ) ) + { + KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18nc( "@info", + "This account already exists. Please choose a different ICQ UID or use the Configure Dialog to change the settings of the %1 account.", userId), i18n( "ICQ" ) ); + return false; + } + + if (!mAccountSettings->mPasswordWidget->validate()) + { + KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18nc( "@info", + "The password entered does not match the ICQ password guidelines: Passwords must be 6-8 characters long."), i18n( "ICQ" ) ); + return false; + } + // No need to check port, min and max values are properly defined in .ui if (mAccountSettings->edtServerAddress->text().isEmpty()) Index: kdenetwork/kopete/protocols/oscar/icq/ui/icqeditaccountwidget.h =================================================================== --- kdenetwork/kopete/protocols/oscar/icq/ui/icqeditaccountwidget.h (revision 733585) +++ kdenetwork/kopete/protocols/oscar/icq/ui/icqeditaccountwidget.h (working copy) @@ -40,7 +40,7 @@ QWidget *parent=0); ~ICQEditAccountWidget(); - virtual bool validateData(); + virtual bool validateData( Kopete::AccountChangeAction changeAction=Kopete::Create ); virtual Kopete::Account *apply(); private slots: Index: kdenetwork/kopete/protocols/meanwhile/meanwhileeditaccountwidget.cpp =================================================================== --- kdenetwork/kopete/protocols/meanwhile/meanwhileeditaccountwidget.cpp (revision 733585) +++ kdenetwork/kopete/protocols/meanwhile/meanwhileeditaccountwidget.cpp (working copy) @@ -83,7 +83,7 @@ return myAccount; } -bool MeanwhileEditAccountWidget::validateData() +bool MeanwhileEditAccountWidget::validateData( Kopete::AccountChangeAction changeAction ) { if(mScreenName->text().isEmpty()) { Index: kdenetwork/kopete/protocols/meanwhile/meanwhileeditaccountwidget.h =================================================================== --- kdenetwork/kopete/protocols/meanwhile/meanwhileeditaccountwidget.h (revision 733585) +++ kdenetwork/kopete/protocols/meanwhile/meanwhileeditaccountwidget.h (working copy) @@ -40,7 +40,7 @@ virtual Kopete::Account* apply(); - virtual bool validateData(); + virtual bool validateData( Kopete::AccountChangeAction changeAction=Kopete::Create ); protected slots: void slotSetServer2Default(); protected: Index: kdenetwork/kopete/protocols/irc/ui/irceditaccountwidget.cpp =================================================================== --- kdenetwork/kopete/protocols/irc/ui/irceditaccountwidget.cpp (revision 733585) +++ kdenetwork/kopete/protocols/irc/ui/irceditaccountwidget.cpp (working copy) @@ -268,7 +268,7 @@ return account(); } -bool IRCEditAccountWidget::validateData() +bool IRCEditAccountWidget::validateData( Kopete::AccountChangeAction changeAction ) { if( nickNames->text().isEmpty() ) KMessageBox::sorry(this, i18n("You must enter a nickname."), i18n("Kopete")); Index: kdenetwork/kopete/protocols/irc/ui/irceditaccountwidget.h =================================================================== --- kdenetwork/kopete/protocols/irc/ui/irceditaccountwidget.h (revision 733585) +++ kdenetwork/kopete/protocols/irc/ui/irceditaccountwidget.h (working copy) @@ -37,7 +37,7 @@ ~IRCEditAccountWidget(); IRCAccount *account(); - virtual bool validateData(); + virtual bool validateData( Kopete::AccountChangeAction changeAction=Kopete::Create ); virtual Kopete::Account *apply(); private slots: Index: kdenetwork/kopete/kopete/addaccountwizard/addaccountwizard.cpp =================================================================== --- kdenetwork/kopete/kopete/addaccountwizard/addaccountwizard.cpp (revision 733585) +++ kdenetwork/kopete/kopete/addaccountwizard/addaccountwizard.cpp (working copy) @@ -179,7 +179,7 @@ else if (currentPage()->widget() == d->accountPageWidget) { // check the data of the page is valid - if (!d->accountPage->validateData()) + if (!d->accountPage->validateData(Kopete::Create)) { return; } @@ -200,17 +200,33 @@ void AddAccountWizard::accept() { - // registeredAccount shouldn't probably be called here. Anyway, if the account is already registered, - // it won't be registered twice Kopete::AccountManager *manager = Kopete::AccountManager::self(); - Kopete::Account *account = manager->registerAccount(d->accountPage->apply()); - // if the account wasn't created correctly then leave + // Have the plugin extract account information + Kopete::Account *account = d->accountPage->apply(); if (!account) { + KMessageBox::sorry( this, i18nc("@info", "An error occurred during account creation.")); return; } + // Check that the account doesn't exist yet, otherwise the account manager would delete it during registration + // This shouldn't be the case as the protocol's account edit page should prevent this, but it's not guaranteed + if (manager->findAccount(account->protocol()->pluginId(), account->accountId())) + { + KMessageBox::sorry( this, i18nc("@info", "This account already exists.")); + reject(); + return; + } + + // Register account and leave if it doesn't work + account = manager->registerAccount(account); + if (!account) + { + KMessageBox::sorry( this, i18nc("@info", "An error occurred during account registration.")); + return; + } + // Make sure the protocol is correctly enabled. This is not really needed, but still good const QString PROTO_NAME = d->proto->pluginId().remove("Protocol").toLower(); Kopete::PluginManager::self()->setPluginEnabled(PROTO_NAME , true); Index: kdenetwork/kopete/kopete/config/accounts/kopeteaccountconfig.cpp =================================================================== --- kdenetwork/kopete/kopete/config/accounts/kopeteaccountconfig.cpp (revision 733585) +++ kdenetwork/kopete/kopete/config/accounts/kopeteaccountconfig.cpp (working copy) @@ -239,6 +239,9 @@ void KopeteAccountConfig::modifyAccount(Kopete::Account *account) { + // FIXME: This function is almost identical to editAccount() in libkopete/kopeteaccount.cpp + // and both should be merged. + Kopete::Protocol *proto = account->protocol(); KDialog editDialog ( this ); @@ -264,7 +267,11 @@ editDialog.setMainWidget( w ); if ( editDialog.exec() == QDialog::Accepted ) { - if( m_accountWidget->validateData() ) + // FIXME: The dialog is hidden at this point, which means that messages + // created in validateData() with "this" as parent won't be shown. It + // should be called earlier such that messages are displayed to the user + // and he gets a chance to know about them and fix them instantly. + if( m_accountWidget->validateData(Kopete::Edit) ) m_accountWidget->apply(); } Index: kdenetwork/kopete/libkopete/kopeteaccount.cpp =================================================================== --- kdenetwork/kopete/libkopete/kopeteaccount.cpp (revision 733585) +++ kdenetwork/kopete/libkopete/kopeteaccount.cpp (working copy) @@ -566,11 +566,11 @@ void Account::editAccount(QWidget *parent) { - KDialog *editDialog = new KDialog( parent ); - editDialog->setCaption( i18n( "Edit Account" ) ); - editDialog->setButtons( KDialog::Ok | KDialog::Apply | KDialog::Cancel ); + KDialog editDialog( parent ); + editDialog.setCaption( i18n( "Edit Account" ) ); + editDialog.setButtons( KDialog::Ok | KDialog::Cancel ); - KopeteEditAccountWidget *m_accountWidget = protocol()->createEditAccountWidget( this, editDialog ); + KopeteEditAccountWidget *m_accountWidget = protocol()->createEditAccountWidget( this, &editDialog ); if ( !m_accountWidget ) return; @@ -584,14 +584,16 @@ if ( !w ) return; - editDialog->setMainWidget( w ); - if ( editDialog->exec() == QDialog::Accepted ) + editDialog.setMainWidget( w ); + if ( editDialog.exec() == QDialog::Accepted ) { - if( m_accountWidget->validateData() ) + // FIXME: The dialog is hidden at this point, which means that messages + // created in validateData() with "this" as parent won't be shown. It + // should be called earlier such that messages are displayed to the user + // and he gets a chance to know about them and fix them instantly. + if( m_accountWidget->validateData(Kopete::Edit) ) m_accountWidget->apply(); } - - editDialog->deleteLater(); } void Account::setCustomIcon( const QString & i) Index: kdenetwork/kopete/libkopete/ui/editaccountwidget.h =================================================================== --- kdenetwork/kopete/libkopete/ui/editaccountwidget.h (revision 733585) +++ kdenetwork/kopete/libkopete/ui/editaccountwidget.h (working copy) @@ -23,7 +23,17 @@ namespace Kopete { -class Account; + class Account; + + /** + * \brief Possible changes to accounts + * @sa @ref KopeteEditAccountWidget::validateData() + */ + enum AccountChangeAction { + Create = 0, ///< New account will be created + Edit = 1 ///< Existing account will be changed + }; + } class KopeteEditAccountWidgetPrivate; @@ -70,9 +80,11 @@ /** * This method must be reimplemented. - * It does the same as @ref AddContactPage::validateData() + * Returns true if all account configuration data filled in by the user is valid, and + * false otherwise, preferably with a message telling what is wrong. + * It is similar to @ref AddContactPage::validateData() */ - virtual bool validateData() = 0; + virtual bool validateData( Kopete::AccountChangeAction changeAction=Kopete::Create ) = 0; /** * Create a new account if we are in the 'add account wizard', --Boundary-00=_XPNMHgSTbQP/eIR Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ kopete-devel mailing list kopete-devel@kde.org https://mail.kde.org/mailman/listinfo/kopete-devel --Boundary-00=_XPNMHgSTbQP/eIR--