[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kopete-devel
Subject:    [kopete-devel] Prevent creating duplicate accounts
From:       Dennis =?iso-8859-1?q?Nienh=FCser?= <earthwings () gentoo ! org>
Date:       2007-11-03 18:55:24
Message-ID: 200711031955.24705.earthwings () gentoo ! org
[Download RAW message or body]

Hi,

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.

Regards,
Dennis


["addaccountwizard-prevent-duplicates.diff" (text/x-diff)]

Index: protocols/yahoo/yahooeditaccount.cpp
===================================================================
--- protocols/yahoo/yahooeditaccount.cpp	(revision 732273)
+++ protocols/yahoo/yahooeditaccount.cpp	(working copy)
@@ -43,6 +43,7 @@
 #include <addcontactpage.h>
 #include <kopeteuiglobal.h>
 #include <avatardialog.h>
+#include <kopeteaccountmanager.cpp>
 
 // Local Includes
 #include "yahooaccount.h"
@@ -100,16 +101,26 @@
 {
 	kDebug(YAHOO_GEN_DEBUG) ;
 
-	if(mScreenName->text().isEmpty())
+	QString userName(mScreenName->text());
+	if(userName.isEmpty())
 	{	KMessageBox::queuedMessageBox(this, KMessageBox::Sorry,
 			i18n("<qt>You must enter a valid screen name.</qt>"), i18n("Yahoo"));
 		return false;
 	}
+
 	if(!mPasswordWidget->validate())
 	{	KMessageBox::queuedMessageBox(this, KMessageBox::Sorry,
 			i18n("<qt>You must enter a valid password.</qt>"), i18n("Yahoo"));
 		return false;
 	}
+
+	if ( Kopete::AccountManager::self()->findAccount( "YahooProtocol", userName ) )
+	{
+		KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18nc( "@info", 
+			"<qt>This account already exists. Please choose a different Yahoo username or use \
the Configure Dialog to change the settings of the <resource>%1</resource> \
account.</qt>", userName), i18n( "Yahoo" ) ); +		return false;
+	}
+
 	return true;
 }
 
Index: protocols/gadu/gadueditaccount.cpp
===================================================================
--- protocols/gadu/gadueditaccount.cpp	(revision 732273)
+++ protocols/gadu/gadueditaccount.cpp	(working copy)
@@ -42,6 +42,7 @@
 #include <kpassworddialog.h>
 
 #include "kopetepasswordwidget.h"
+#include "kopeteaccountmanager.h"
 
 GaduEditAccount::GaduEditAccount( GaduProtocol* proto, Kopete::Account* ident, \
QWidget* parent )  : QWidget( parent ), KopeteEditAccountWidget( ident ), protocol_( \
proto ), rcmd( 0 ) @@ -213,12 +214,13 @@
 GaduEditAccount::validateData()
 {
 
-	if ( loginEdit_->text().isEmpty() ) {
+	QString userName(loginEdit_->text());
+	if ( userName.isEmpty() ) {
 		KMessageBox::sorry( this, i18n( "<b>Enter UIN please.</b>" ), 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( "<b>UIN should be a positive number.</b>" ), i18n( \
"Gadu-Gadu" ) );  return false;
 	}
@@ -228,6 +230,13 @@
 		return false;
 	}
 
+	if ( Kopete::AccountManager::self()->findAccount( "GaduProtocol", userName ) )
+	{
+		KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18nc( "@info", 
+			"<qt>This account already exists. Please choose a different Gadu-Gadu UIN or use \
the Configure Dialog to change the settings of the <resource>%1</resource> \
account.</qt>", userName), i18n( "Gadu-Gadu" ) ); +		return false;
+	}
+
 	return true;
 }
 
Index: protocols/qq/ui/qqeditaccountwidget.cpp
===================================================================
--- protocols/qq/ui/qqeditaccountwidget.cpp	(revision 732273)
+++ 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"
@@ -168,11 +169,20 @@
 bool QQEditAccountWidget::validateData()
 {
 	QString userid = d->ui->m_login->text();
+
+	if ( Kopete::AccountManager::self()->findAccount( "QQProtocol", userid ) )
+	{
+		KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18nc( "@info", 
+			"<qt>This account already exists. Please choose a different QQ ID or use the \
Configure Dialog to change the settings of the <resource>%1</resource> \
account.</qt>", userid), i18n( "QQ" ) ); +		return false;
+	}
+
 	if ( QQProtocol::validContactId( userid ) )
 		return true;
 
 	KMessageBox::queuedMessageBox( Kopete::UI::Global::mainWidget(), \
KMessageBox::Sorry,  i18n( "<qt>You must enter a valid email address.</qt>" ), i18n( \
"QQ Plugin" ) ); +
 	return false;
 }
 
Index: protocols/winpopup/wpeditaccount.cpp
===================================================================
--- protocols/winpopup/wpeditaccount.cpp	(revision 732273)
+++ protocols/winpopup/wpeditaccount.cpp	(working copy)
@@ -35,10 +35,11 @@
 #include <kmessagebox.h>
 #include <kconfig.h>
 #include <kstandarddirs.h>
+#include <kmessagebox.h>
 
-
 // Kopete Includes
 #include <addcontactpage.h>
+#include <kopeteaccountmanager.h>
 
 // Local Includes
 #include "wpaccount.h"
@@ -97,7 +98,8 @@
 {
 	kDebug(14170) << "WPEditAccount::validateData()";
 
-	if(mHostName->text().isEmpty()) {
+	QString hostname(mHostName->text());
+	if(hostname.isEmpty()) {
 		KMessageBox::sorry(this, i18n("<qt>You must enter a valid screen name.</qt>"), \
i18n("WinPopup"));  return false;
 	}
@@ -108,6 +110,13 @@
 		return false;
 	}
 
+	if ( Kopete::AccountManager::self()->findAccount( "WPProtocol", hostname ) )
+	{
+		KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18nc( "@info",
+			"<qt>This account already exists. Please choose a different hostname or use the \
Configure Dialog to change the settings of the <resource>%1</resource> \
account.</qt>", hostname), i18n( "WinPopup" ) ); +		return false;
+	}
+
 	return true;
 }
 
Index: protocols/jabber/ui/jabbereditaccountwidget.cpp
===================================================================
--- protocols/jabber/ui/jabbereditaccountwidget.cpp	(revision 732273)
+++ protocols/jabber/ui/jabbereditaccountwidget.cpp	(working copy)
@@ -32,6 +32,7 @@
 #include <klineedit.h>
 #include <kopetepassword.h>
 #include <kopetepasswordedaccount.h>
+#include <kopeteaccountmanager.h>
 
 #include "kopeteuiglobal.h"
 #include "kopetepasswordwidget.h"
@@ -197,7 +198,8 @@
 bool JabberEditAccountWidget::validateData ()
 {
 
-	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 ( Kopete::AccountManager::self()->findAccount( "JabberProtocol", userId ) )
+	{
+		KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18nc( "@info", 
+			"<qt>This account already exists. Please choose a different Jabber ID or use the \
Configure Dialog to change the settings of the <resource>%1</resource> \
account.</qt>", userId), i18n( "Jabber" ) ); +		return false;
+	}
+
 	return true;
 }
 
Index: protocols/msn/ui/msneditaccountwidget.cpp
===================================================================
--- protocols/msn/ui/msneditaccountwidget.cpp	(revision 732273)
+++ 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"
@@ -216,6 +217,14 @@
 bool MSNEditAccountWidget::validateData()
 {
 	QString userid = d->ui->m_login->text();
+
+	if ( Kopete::AccountManager::self()->findAccount( "MSNProtocol", userid ) )
+	{
+		KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18nc( "@info", 
+			"<qt>This account already exists. Please choose a different MSN Passport ID or \
use the Configure Dialog to change the settings of the <resource>%1</resource> \
account.</qt>", userid), i18n( "MSN Plugin" ) ); +		return false;
+	}
+
 	if ( MSNProtocol::validContactId( userid ) )
 		return true;
 
Index: protocols/sms/smseditaccountwidget.cpp
===================================================================
--- protocols/sms/smseditaccountwidget.cpp	(revision 732273)
+++ protocols/sms/smseditaccountwidget.cpp	(working copy)
@@ -32,6 +32,7 @@
 #include <kconfiggroup.h>
 
 #include "kopeteuiglobal.h"
+#include "kopeteaccountmanager.h"
 
 #include "smseditaccountwidget.h"
 #include "smsactprefs.h"
@@ -92,6 +93,18 @@
 
 bool SMSEditAccountWidget::validateData()
 {
+	QString accountId(preferencesDialog->accountId->text());
+
+	if (accountId.isEmpty())
+		return false;
+
+	if ( Kopete::AccountManager::self()->findAccount( "SMSProtocol", accountId ) )
+	{
+		KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18nc( "@info", 
+			"<qt>This account already exists. Please choose a different account ID or use the \
Configure Dialog to change the settings of the <resource>%1</resource> \
account.</qt>", accountId), i18n( "SMS" ) ); +		return false;
+	}
+
 	return true;
 }
 
Index: protocols/oscar/aim/ui/aimeditaccountwidget.cpp
===================================================================
--- protocols/oscar/aim/ui/aimeditaccountwidget.cpp	(revision 732273)
+++ protocols/oscar/aim/ui/aimeditaccountwidget.cpp	(working copy)
@@ -14,9 +14,11 @@
 #include <ktoolinvocation.h>
 #include <kpassworddialog.h>
 #include <kconfig.h>
+#include <kmessagebox.h>
 
 #include "kopetepassword.h"
 #include "kopetepasswordwidget.h"
+#include "kopeteaccountmanager.h"
 
 #include "aimprotocol.h"
 #include "aimaccount.h"
@@ -220,6 +222,13 @@
 	if ( server.length() < 1 )
 		return false;
 
+	if ( Kopete::AccountManager::self()->findAccount( "AIMProtocol", userName ) )
+	{
+		KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18nc( "@info", 
+			"<qt>This account already exists. Please choose a different AIM screen name or \
use the Configure Dialog to change the settings of the <resource>%1</resource> \
account.</qt>", userName), i18n( "AIM" ) ); +		return false;
+	}
+
 	// Seems good to me
 	//kDebug(14152) << "Account data validated successfully.";
 	return true;
Index: protocols/oscar/icq/ui/icqeditaccountwidget.cpp
===================================================================
--- protocols/oscar/icq/ui/icqeditaccountwidget.cpp	(revision 732273)
+++ 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"
@@ -274,6 +275,13 @@
 		return false;
 	}
 
+	if ( Kopete::AccountManager::self()->findAccount( "ICQProtocol", userId ) )
+	{
+		KMessageBox::queuedMessageBox( this, KMessageBox::Sorry, i18nc( "@info", 
+			"<qt>This account already exists. Please choose a different ICQ UID or use the \
Configure Dialog to change the settings of the <resource>%1</resource> \
account.</qt>", userId), i18n( "ICQ" ) ); +		return false;
+	}
+	
 	// No need to check port, min and max values are properly defined in .ui
 
 	if (mAccountSettings->edtServerAddress->text().isEmpty())
Index: kopete/addaccountwizard/addaccountwizard.cpp
===================================================================
--- kopete/addaccountwizard/addaccountwizard.cpp	(revision 732273)
+++ kopete/addaccountwizard/addaccountwizard.cpp	(working copy)
@@ -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", "<qt>An error occurred during account \
creation.</qt>"));  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", "<qt>This account already \
exists.</qt>")); +		reject();
+		return;
+	}
+
+	// Register account and leave if it doesn't work
+	account = manager->registerAccount(account);
+	if (!account)
+	{
+		KMessageBox::sorry( this, i18nc("@info", "<qt>An error occurred during account \
registration.</qt>")); +		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);



_______________________________________________
kopete-devel mailing list
kopete-devel@kde.org
https://mail.kde.org/mailman/listinfo/kopete-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic