mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-15 02:24:50 +02:00
Make testConfig great again!
This commit is contained in:
@@ -300,8 +300,9 @@ Tomahawk.Resolver = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_adapter_testConfig: function (config) {
|
_adapter_testConfig: function (config) {
|
||||||
return RSVP.Promise.resolve(this.testConfig(config)).then(function () {
|
return RSVP.Promise.resolve(this.testConfig(config)).then(function (results) {
|
||||||
return {result: Tomahawk.ConfigTestResultType.Success};
|
results = results || Tomahawk.ConfigTestResultType.Success;
|
||||||
|
return results;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -153,7 +153,7 @@ Account::removeFromConfig()
|
|||||||
void
|
void
|
||||||
Account::testConfig()
|
Account::testConfig()
|
||||||
{
|
{
|
||||||
emit configTestResult( ConfigTestResultSuccess );
|
emit configTestResult( ConfigTestResultSuccess, "" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -167,7 +167,7 @@ signals:
|
|||||||
void connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState state );
|
void connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState state );
|
||||||
|
|
||||||
void configurationChanged();
|
void configurationChanged();
|
||||||
void configTestResult( Tomahawk::Accounts::ConfigTestResultType );
|
void configTestResult( int, const QString& );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void loadFromConfig( const QString &accountId );
|
virtual void loadFromConfig( const QString &accountId );
|
||||||
|
@@ -82,7 +82,7 @@ DelegateConfigWrapper::DelegateConfigWrapper( Tomahawk::Accounts::Account* accou
|
|||||||
if ( m_widget->metaObject()->indexOfSignal( "sizeHintChanged()" ) > -1 )
|
if ( m_widget->metaObject()->indexOfSignal( "sizeHintChanged()" ) > -1 )
|
||||||
connect( m_widget, SIGNAL( sizeHintChanged() ), this, SLOT( updateSizeHint() ) );
|
connect( m_widget, SIGNAL( sizeHintChanged() ), this, SLOT( updateSizeHint() ) );
|
||||||
|
|
||||||
connect( m_account, SIGNAL( configTestResult( Tomahawk::Accounts::ConfigTestResultType ) ), SLOT( onConfigTestResult( Tomahawk::Accounts::ConfigTestResultType ) ) );
|
connect( m_account, SIGNAL( configTestResult( int, const QString& ) ), SLOT( onConfigTestResult( int, const QString& ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -193,11 +193,11 @@ DelegateConfigWrapper::aboutClicked( bool )
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DelegateConfigWrapper::onConfigTestResult( Tomahawk::Accounts::ConfigTestResultType result )
|
DelegateConfigWrapper::onConfigTestResult( int code, const QString& message )
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << result;
|
tLog() << Q_FUNC_INFO << code << ": " << message;
|
||||||
|
|
||||||
if( result == Tomahawk::Accounts::ConfigTestResultSuccess )
|
if( code == Tomahawk::Accounts::ConfigTestResultSuccess )
|
||||||
{
|
{
|
||||||
m_invalidData = QVariantMap();
|
m_invalidData = QVariantMap();
|
||||||
closeDialog( QDialog::Accepted );
|
closeDialog( QDialog::Accepted );
|
||||||
@@ -227,8 +227,30 @@ DelegateConfigWrapper::onConfigTestResult( Tomahawk::Accounts::ConfigTestResultT
|
|||||||
|
|
||||||
m_invalidData = m_widget->readData();
|
m_invalidData = m_widget->readData();
|
||||||
|
|
||||||
// TODO: generate message based on status code
|
QString msg;
|
||||||
m_errorLabel->setText( QString( "<font color='red'>%1</font>" ).arg( tr( "Your config is invalid." ) ) );
|
if (message.isEmpty()){
|
||||||
|
msg = getTestConfigMessage(code);
|
||||||
|
} else {
|
||||||
|
msg = message;
|
||||||
|
}
|
||||||
|
m_errorLabel->setText( QString( "<font color='red'>%1</font>" ).arg( msg ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
DelegateConfigWrapper::getTestConfigMessage( int code )
|
||||||
|
{
|
||||||
|
switch(code) {
|
||||||
|
case Tomahawk::Accounts::ConfigTestResultCommunicationError:
|
||||||
|
return QObject::tr( "Unable to authenticate. Please check your connection." );
|
||||||
|
case Tomahawk::Accounts::ConfigTestResultInvalidCredentials:
|
||||||
|
return QObject::tr( "Username or password incorrect." );
|
||||||
|
case Tomahawk::Accounts::ConfigTestResultInvalidAccount:
|
||||||
|
return QObject::tr( "Account rejected by server." );
|
||||||
|
case Tomahawk::Accounts::ConfigTestResultPlayingElsewhere:
|
||||||
|
return QObject::tr( "Action not allowed, account is in use elsewhere." );
|
||||||
|
case Tomahawk::Accounts::ConfigTestResultAccountExpired:
|
||||||
|
return QObject::tr( "Your account has expired." );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -60,10 +60,11 @@ protected:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void aboutClicked( bool );
|
void aboutClicked( bool );
|
||||||
void onConfigTestResult( Tomahawk::Accounts::ConfigTestResultType );
|
void onConfigTestResult( int, const QString& );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void closeDialog( QDialog::DialogCode code );
|
void closeDialog( QDialog::DialogCode code );
|
||||||
|
QString getTestConfigMessage( int code );
|
||||||
|
|
||||||
Tomahawk::Accounts::Account* m_account;
|
Tomahawk::Accounts::Account* m_account;
|
||||||
AccountConfigWidget* m_widget;
|
AccountConfigWidget* m_widget;
|
||||||
|
@@ -542,12 +542,12 @@ ResolverAccount::testConfig()
|
|||||||
{
|
{
|
||||||
QVariantMap data = resolver->loadDataFromWidgets();
|
QVariantMap data = resolver->loadDataFromWidgets();
|
||||||
ScriptJob* job = resolver->scriptObject()->invoke( "testConfig", data );
|
ScriptJob* job = resolver->scriptObject()->invoke( "testConfig", data );
|
||||||
connect( job, SIGNAL( done( QVariantMap ) ), SLOT( onTestConfig( QVariantMap ) ) );
|
connect( job, SIGNAL( done( QVariant ) ), SLOT( onTestConfig( QVariant ) ) );
|
||||||
job->start();
|
job->start();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
emit configTestResult( Accounts::ConfigTestResultSuccess );
|
emit configTestResult( Accounts::ConfigTestResultSuccess, "" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -560,18 +560,17 @@ ResolverAccount::resolver() const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ResolverAccount::onTestConfig( const QVariantMap& result )
|
ResolverAccount::onTestConfig( const QVariant& result )
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << result;
|
tLog() << Q_FUNC_INFO << result;
|
||||||
|
|
||||||
int resultCode = result[ "result" ].toInt();
|
if (result.type() == QMetaType::QString)
|
||||||
if ( resultCode == 1 )
|
|
||||||
{
|
{
|
||||||
emit configTestResult( Accounts::ConfigTestResultSuccess );
|
emit configTestResult( Accounts::ConfigTestResultOther, result.toString() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
emit configTestResult( Accounts::ConfigTestResultOther );
|
emit configTestResult( result.toInt(), "" );
|
||||||
}
|
}
|
||||||
|
|
||||||
sender()->deleteLater();
|
sender()->deleteLater();
|
||||||
|
@@ -110,7 +110,7 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void resolverChanged();
|
void resolverChanged();
|
||||||
void onTestConfig( const QVariantMap& result );
|
void onTestConfig( const QVariant& result );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Created by factory, when user installs a new resolver
|
// Created by factory, when user installs a new resolver
|
||||||
|
@@ -157,9 +157,15 @@ ScriptAccount::reportScriptJobResult( const QVariantMap& result )
|
|||||||
// got a successful job result
|
// got a successful job result
|
||||||
if ( result[ "error"].isNull() )
|
if ( result[ "error"].isNull() )
|
||||||
{
|
{
|
||||||
const QVariantMap data = result[ "data" ].toMap();
|
if (result[ "data" ].type() == QMetaType::QVariantMap)
|
||||||
|
{
|
||||||
job->reportResults( data );
|
const QVariantMap data = result[ "data" ].toMap();
|
||||||
|
job->reportResultsMap( data );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
job->reportResults( result[ "data" ] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -82,17 +82,25 @@ ScriptJob::arguments() const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScriptJob::reportResults( const QVariantMap& data )
|
ScriptJob::reportResultsMap( const QVariantMap& data )
|
||||||
{
|
{
|
||||||
m_data = data;
|
m_data = data;
|
||||||
emit done( data );
|
emit done( data );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptJob::reportResults( const QVariant& data )
|
||||||
|
{
|
||||||
|
m_data_primitive = data;
|
||||||
|
emit done( data );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScriptJob::reportFailure( const QString& errorMessage )
|
ScriptJob::reportFailure( const QString& errorMessage )
|
||||||
{
|
{
|
||||||
emit error( errorMessage );
|
emit error( errorMessage );
|
||||||
|
|
||||||
reportResults( QVariantMap() );
|
reportResultsMap( QVariantMap() );
|
||||||
}
|
}
|
||||||
|
@@ -49,11 +49,13 @@ public:
|
|||||||
QVariantMap arguments() const;
|
QVariantMap arguments() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void reportResults( const QVariantMap& data = QVariantMap() );
|
void reportResultsMap( const QVariantMap& data = QVariantMap() );
|
||||||
|
void reportResults( const QVariant& data = QVariant() );
|
||||||
void reportFailure( const QString& errorMessage );
|
void reportFailure( const QString& errorMessage );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void done( const QVariantMap& result );
|
void done( const QVariantMap& result );
|
||||||
|
void done( const QVariant& result );
|
||||||
void error( const QString& errorMessage );
|
void error( const QString& errorMessage );
|
||||||
|
|
||||||
void destroyed( const QString& id );
|
void destroyed( const QString& id );
|
||||||
@@ -64,6 +66,7 @@ protected:
|
|||||||
QString m_id;
|
QString m_id;
|
||||||
scriptobject_ptr m_scriptObject;
|
scriptobject_ptr m_scriptObject;
|
||||||
QVariantMap m_data;
|
QVariantMap m_data;
|
||||||
|
QVariant m_data_primitive;
|
||||||
QString m_methodName;
|
QString m_methodName;
|
||||||
QVariantMap m_arguments;
|
QVariantMap m_arguments;
|
||||||
};
|
};
|
||||||
|
@@ -30,5 +30,5 @@ Tomahawk::SyncScriptJob::SyncScriptJob( const QVariantMap& resultData )
|
|||||||
void
|
void
|
||||||
Tomahawk::SyncScriptJob::start()
|
Tomahawk::SyncScriptJob::start()
|
||||||
{
|
{
|
||||||
QMetaObject::invokeMethod( this, "reportResults", Qt::QueuedConnection, Q_ARG( QVariantMap, m_data ) );
|
QMetaObject::invokeMethod( this, "reportResultsMap", Qt::QueuedConnection, Q_ARG( QVariantMap, m_data ) );
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user