From 40fb61b9a920cb23912085f9745dd6e3f7e12b61 Mon Sep 17 00:00:00 2001 From: Christopher Reichert Date: Fri, 1 Jul 2011 21:03:27 -0500 Subject: [PATCH] Do not allow same jabber credentials more than once. --- src/delegateconfigwrapper.h | 8 ++++++++ src/libtomahawk/sip/SipPlugin.h | 2 ++ src/settingsdialog.cpp | 2 ++ src/sip/jabber/configwidget.ui | 17 ++++++++++++----- src/sip/jabber/jabber.cpp | 29 +++++++++++++++++++++++++++++ src/sip/jabber/jabber.h | 2 ++ 6 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/delegateconfigwrapper.h b/src/delegateconfigwrapper.h index 9155c2cd4..e0a354e2d 100644 --- a/src/delegateconfigwrapper.h +++ b/src/delegateconfigwrapper.h @@ -21,6 +21,7 @@ #include #include #include +#include class DelegateConfigWrapper : public QDialog { @@ -39,6 +40,7 @@ public: v->addWidget( m_widget ); QDialogButtonBox* buttons = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this ); + m_okButton = buttons->button( QDialogButtonBox::Ok ); connect( buttons, SIGNAL( clicked( QAbstractButton*) ), this, SLOT( closed( QAbstractButton* ) ) ); connect( this, SIGNAL( rejected() ), this, SLOT( rejected() ) ); v->addWidget( buttons ); @@ -57,6 +59,11 @@ public: } public slots: + void toggleOkButton( bool dataError ) + { + // if dataError is True we want to set the button enabled to false + m_okButton->setEnabled( !dataError ); + } void closed( QAbstractButton* b ) { // let the config widget live to see another day @@ -90,6 +97,7 @@ public slots: private: QWidget* m_widget; + QPushButton* m_okButton; }; #endif diff --git a/src/libtomahawk/sip/SipPlugin.h b/src/libtomahawk/sip/SipPlugin.h index 6e803c154..ae8ce58b7 100644 --- a/src/libtomahawk/sip/SipPlugin.h +++ b/src/libtomahawk/sip/SipPlugin.h @@ -113,6 +113,8 @@ signals: void addMenu( QMenu* menu ); void removeMenu( QMenu* menu ); + + void dataError( bool ); private slots: void onError( int, const QString& ); diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 4ce763879..1639a1a24 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -598,11 +598,13 @@ SettingsDialog::sipFactoryClicked( SipPluginFactory* factory ) DelegateConfigWrapper* dialog = new DelegateConfigWrapper( p->configWidget(), QString("%1 Config" ).arg( p->friendlyName() ), this, Qt::Sheet ); dialog->setProperty( "sipplugin", QVariant::fromValue< QObject* >( p ) ); connect( dialog, SIGNAL( finished( int ) ), this, SLOT( sipCreateConfigClosed( int ) ) ); + connect( p, SIGNAL( datatError( bool ) ), &dialog, SLOT( toggleOkButton( bool ) ) ); dialog->show(); #else DelegateConfigWrapper dialog( p->configWidget(), QString("%1 Config" ).arg( p->friendlyName() ), this ); QWeakPointer< DelegateConfigWrapper > watcher( &dialog ); + connect( p, SIGNAL( dataError( bool ) ), &dialog, SLOT( toggleOkButton( bool ) ) ); int ret = dialog.exec(); if( !watcher.isNull() && ret == QDialog::Accepted ) { // send changed config to resolver diff --git a/src/sip/jabber/configwidget.ui b/src/sip/jabber/configwidget.ui index 456f19255..cd5fd72b1 100644 --- a/src/sip/jabber/configwidget.ui +++ b/src/sip/jabber/configwidget.ui @@ -6,17 +6,14 @@ 0 0 - 433 - 260 + 451 + 335 Jabber Configuration - - 0 - @@ -185,6 +182,16 @@ + + + + An account with this name already exists! + + + Qt::AlignCenter + + + diff --git a/src/sip/jabber/jabber.cpp b/src/sip/jabber/jabber.cpp index e1b239536..0575651ea 100644 --- a/src/sip/jabber/jabber.cpp +++ b/src/sip/jabber/jabber.cpp @@ -80,11 +80,13 @@ JabberPlugin::JabberPlugin( const QString& pluginId ) m_ui->jabberPassword->setText( readPassword() ); m_ui->jabberServer->setText( readServer() ); m_ui->jabberPort->setValue( readPort() ); + m_ui->jidExistsLabel->hide(); m_currentUsername = accountName(); m_currentServer = readServer(); m_currentPassword = readPassword(); m_currentPort = readPort(); + connect( m_ui->jabberUsername, SIGNAL( textChanged( QString ) ), SLOT( onCheckJidExists( QString ) ) ); // setup JID object Jreen::JID jid = Jreen::JID( accountName() ); @@ -999,6 +1001,33 @@ JabberPlugin::readServer() return TomahawkSettings::instance()->value( pluginId() + "/server" ).toString(); } + +void +JabberPlugin::onCheckJidExists( QString jid ) +{ + for ( int i=0; isipPlugins().count(); i++ ) + { + QString savedUsername = TomahawkSettings::instance()->value( + TomahawkSettings::instance()->sipPlugins().at( i ) + "/username" ).toString(); + QStringList splitUserName = TomahawkSettings::instance()->value( + TomahawkSettings::instance()->sipPlugins().at( i ) + "/username" ).toString().split("@"); + QString server = TomahawkSettings::instance()->value( + TomahawkSettings::instance()->sipPlugins().at( i ) + "/server" ).toString(); + + if ( ( savedUsername == jid || splitUserName.contains( jid ) ) && + server == m_ui->jabberServer->text() && !jid.trimmed().isEmpty() ) + { + m_ui->jidExistsLabel->show(); + // the already jid exists + emit dataError( true ); + return; + } + } + m_ui->jidExistsLabel->hide(); + emit dataError( false ); +} + + void JabberPlugin::saveConfig() { diff --git a/src/sip/jabber/jabber.h b/src/sip/jabber/jabber.h index 8462b1092..d71bcdd5f 100644 --- a/src/sip/jabber/jabber.h +++ b/src/sip/jabber/jabber.h @@ -85,6 +85,7 @@ public: virtual void deletePlugin(); signals: + void dataError( bool exists ); void jidChanged( const QString& ); public slots: @@ -118,6 +119,7 @@ private slots: } void onNewIq( const Jreen::IQ &iq ); void onNewAvatar( const QString &jid ); + void onCheckJidExists( QString jid ); private: bool readXmlConsoleEnabled();