1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 14:16:32 +02: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 <QDialog>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QPushButton>
class DelegateConfigWrapper : public QDialog class DelegateConfigWrapper : public QDialog
{ {
@@ -39,6 +40,7 @@ public:
v->addWidget( m_widget ); v->addWidget( m_widget );
QDialogButtonBox* buttons = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this ); 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( buttons, SIGNAL( clicked( QAbstractButton*) ), this, SLOT( closed( QAbstractButton* ) ) );
connect( this, SIGNAL( rejected() ), this, SLOT( rejected() ) ); connect( this, SIGNAL( rejected() ), this, SLOT( rejected() ) );
v->addWidget( buttons ); v->addWidget( buttons );
@@ -57,6 +59,11 @@ public:
} }
public slots: 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 ) void closed( QAbstractButton* b )
{ {
// let the config widget live to see another day // let the config widget live to see another day
@@ -90,6 +97,7 @@ public slots:
private: private:
QWidget* m_widget; QWidget* m_widget;
QPushButton* m_okButton;
}; };
#endif #endif

View File

@@ -113,6 +113,8 @@ signals:
void addMenu( QMenu* menu ); void addMenu( QMenu* menu );
void removeMenu( QMenu* menu ); void removeMenu( QMenu* menu );
void dataError( bool );
private slots: private slots:
void onError( int, const QString& ); 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 ); DelegateConfigWrapper* dialog = new DelegateConfigWrapper( p->configWidget(), QString("%1 Config" ).arg( p->friendlyName() ), this, Qt::Sheet );
dialog->setProperty( "sipplugin", QVariant::fromValue< QObject* >( p ) ); dialog->setProperty( "sipplugin", QVariant::fromValue< QObject* >( p ) );
connect( dialog, SIGNAL( finished( int ) ), this, SLOT( sipCreateConfigClosed( int ) ) ); connect( dialog, SIGNAL( finished( int ) ), this, SLOT( sipCreateConfigClosed( int ) ) );
connect( p, SIGNAL( datatError( bool ) ), &dialog, SLOT( toggleOkButton( bool ) ) );
dialog->show(); dialog->show();
#else #else
DelegateConfigWrapper dialog( p->configWidget(), QString("%1 Config" ).arg( p->friendlyName() ), this ); DelegateConfigWrapper dialog( p->configWidget(), QString("%1 Config" ).arg( p->friendlyName() ), this );
QWeakPointer< DelegateConfigWrapper > watcher( &dialog ); QWeakPointer< DelegateConfigWrapper > watcher( &dialog );
connect( p, SIGNAL( dataError( bool ) ), &dialog, SLOT( toggleOkButton( bool ) ) );
int ret = dialog.exec(); int ret = dialog.exec();
if( !watcher.isNull() && ret == QDialog::Accepted ) { if( !watcher.isNull() && ret == QDialog::Accepted ) {
// send changed config to resolver // send changed config to resolver

View File

@@ -6,17 +6,14 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>433</width> <width>451</width>
<height>260</height> <height>335</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Jabber Configuration</string> <string>Jabber Configuration</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="topMargin">
<number>0</number>
</property>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
@@ -185,6 +182,16 @@
</item> </item>
</layout> </layout>
</item> </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> </layout>
</widget> </widget>
</item> </item>

View File

@@ -80,11 +80,13 @@ JabberPlugin::JabberPlugin( const QString& pluginId )
m_ui->jabberPassword->setText( readPassword() ); m_ui->jabberPassword->setText( readPassword() );
m_ui->jabberServer->setText( readServer() ); m_ui->jabberServer->setText( readServer() );
m_ui->jabberPort->setValue( readPort() ); m_ui->jabberPort->setValue( readPort() );
m_ui->jidExistsLabel->hide();
m_currentUsername = accountName(); m_currentUsername = accountName();
m_currentServer = readServer(); m_currentServer = readServer();
m_currentPassword = readPassword(); m_currentPassword = readPassword();
m_currentPort = readPort(); m_currentPort = readPort();
connect( m_ui->jabberUsername, SIGNAL( textChanged( QString ) ), SLOT( onCheckJidExists( QString ) ) );
// setup JID object // setup JID object
Jreen::JID jid = Jreen::JID( accountName() ); Jreen::JID jid = Jreen::JID( accountName() );
@@ -999,6 +1001,33 @@ JabberPlugin::readServer()
return TomahawkSettings::instance()->value( pluginId() + "/server" ).toString(); 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 void
JabberPlugin::saveConfig() JabberPlugin::saveConfig()
{ {

View File

@@ -85,6 +85,7 @@ public:
virtual void deletePlugin(); virtual void deletePlugin();
signals: signals:
void dataError( bool exists );
void jidChanged( const QString& ); void jidChanged( const QString& );
public slots: public slots:
@@ -118,6 +119,7 @@ private slots:
} }
void onNewIq( const Jreen::IQ &iq ); void onNewIq( const Jreen::IQ &iq );
void onNewAvatar( const QString &jid ); void onNewAvatar( const QString &jid );
void onCheckJidExists( QString jid );
private: private:
bool readXmlConsoleEnabled(); bool readXmlConsoleEnabled();