1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-22 16:59:58 +01:00

Do not allow same jabber credentials more than once.

This commit is contained in:
Christopher Reichert 2011-07-01 21:03:27 -05:00
parent 11c0519165
commit 40fb61b9a9
6 changed files with 55 additions and 5 deletions

View File

@ -21,6 +21,7 @@
#include <QDialog>
#include <QDialogButtonBox>
#include <QVBoxLayout>
#include <QPushButton>
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

View File

@ -113,6 +113,8 @@ signals:
void addMenu( QMenu* menu );
void removeMenu( QMenu* menu );
void dataError( bool );
private slots:
void onError( int, const QString& );

View File

@ -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

View File

@ -6,17 +6,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>433</width>
<height>260</height>
<width>451</width>
<height>335</height>
</rect>
</property>
<property name="windowTitle">
<string>Jabber Configuration</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="topMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
@ -185,6 +182,16 @@
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="jidExistsLabel">
<property name="text">
<string>An account with this name already exists!</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -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; i<TomahawkSettings::instance()->sipPlugins().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()
{

View File

@ -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();