mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-13 17:43:59 +02:00
Make testConfig great again!
This commit is contained in:
@@ -300,8 +300,9 @@ Tomahawk.Resolver = {
|
||||
},
|
||||
|
||||
_adapter_testConfig: function (config) {
|
||||
return RSVP.Promise.resolve(this.testConfig(config)).then(function () {
|
||||
return {result: Tomahawk.ConfigTestResultType.Success};
|
||||
return RSVP.Promise.resolve(this.testConfig(config)).then(function (results) {
|
||||
results = results || Tomahawk.ConfigTestResultType.Success;
|
||||
return results;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@@ -153,7 +153,7 @@ Account::removeFromConfig()
|
||||
void
|
||||
Account::testConfig()
|
||||
{
|
||||
emit configTestResult( ConfigTestResultSuccess );
|
||||
emit configTestResult( ConfigTestResultSuccess, "" );
|
||||
}
|
||||
|
||||
|
||||
|
@@ -167,7 +167,7 @@ signals:
|
||||
void connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState state );
|
||||
|
||||
void configurationChanged();
|
||||
void configTestResult( Tomahawk::Accounts::ConfigTestResultType );
|
||||
void configTestResult( int, const QString& );
|
||||
|
||||
protected:
|
||||
virtual void loadFromConfig( const QString &accountId );
|
||||
|
@@ -82,7 +82,7 @@ DelegateConfigWrapper::DelegateConfigWrapper( Tomahawk::Accounts::Account* accou
|
||||
if ( m_widget->metaObject()->indexOfSignal( "sizeHintChanged()" ) > -1 )
|
||||
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
|
||||
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();
|
||||
closeDialog( QDialog::Accepted );
|
||||
@@ -227,8 +227,30 @@ DelegateConfigWrapper::onConfigTestResult( Tomahawk::Accounts::ConfigTestResultT
|
||||
|
||||
m_invalidData = m_widget->readData();
|
||||
|
||||
// TODO: generate message based on status code
|
||||
m_errorLabel->setText( QString( "<font color='red'>%1</font>" ).arg( tr( "Your config is invalid." ) ) );
|
||||
QString msg;
|
||||
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:
|
||||
void aboutClicked( bool );
|
||||
void onConfigTestResult( Tomahawk::Accounts::ConfigTestResultType );
|
||||
void onConfigTestResult( int, const QString& );
|
||||
|
||||
private:
|
||||
void closeDialog( QDialog::DialogCode code );
|
||||
QString getTestConfigMessage( int code );
|
||||
|
||||
Tomahawk::Accounts::Account* m_account;
|
||||
AccountConfigWidget* m_widget;
|
||||
|
@@ -542,12 +542,12 @@ ResolverAccount::testConfig()
|
||||
{
|
||||
QVariantMap data = resolver->loadDataFromWidgets();
|
||||
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();
|
||||
}
|
||||
else
|
||||
{
|
||||
emit configTestResult( Accounts::ConfigTestResultSuccess );
|
||||
emit configTestResult( Accounts::ConfigTestResultSuccess, "" );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -560,18 +560,17 @@ ResolverAccount::resolver() const
|
||||
|
||||
|
||||
void
|
||||
ResolverAccount::onTestConfig( const QVariantMap& result )
|
||||
ResolverAccount::onTestConfig( const QVariant& result )
|
||||
{
|
||||
tLog() << Q_FUNC_INFO << result;
|
||||
|
||||
int resultCode = result[ "result" ].toInt();
|
||||
if ( resultCode == 1 )
|
||||
if (result.type() == QMetaType::QString)
|
||||
{
|
||||
emit configTestResult( Accounts::ConfigTestResultSuccess );
|
||||
emit configTestResult( Accounts::ConfigTestResultOther, result.toString() );
|
||||
}
|
||||
else
|
||||
{
|
||||
emit configTestResult( Accounts::ConfigTestResultOther );
|
||||
emit configTestResult( result.toInt(), "" );
|
||||
}
|
||||
|
||||
sender()->deleteLater();
|
||||
|
@@ -110,7 +110,7 @@ public:
|
||||
|
||||
private slots:
|
||||
void resolverChanged();
|
||||
void onTestConfig( const QVariantMap& result );
|
||||
void onTestConfig( const QVariant& result );
|
||||
|
||||
protected:
|
||||
// Created by factory, when user installs a new resolver
|
||||
|
@@ -156,10 +156,16 @@ ScriptAccount::reportScriptJobResult( const QVariantMap& result )
|
||||
|
||||
// got a successful job result
|
||||
if ( result[ "error"].isNull() )
|
||||
{
|
||||
if (result[ "data" ].type() == QMetaType::QVariantMap)
|
||||
{
|
||||
const QVariantMap data = result[ "data" ].toMap();
|
||||
|
||||
job->reportResults( data );
|
||||
job->reportResultsMap( data );
|
||||
}
|
||||
else
|
||||
{
|
||||
job->reportResults( result[ "data" ] );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -82,17 +82,25 @@ ScriptJob::arguments() const
|
||||
|
||||
|
||||
void
|
||||
ScriptJob::reportResults( const QVariantMap& data )
|
||||
ScriptJob::reportResultsMap( const QVariantMap& data )
|
||||
{
|
||||
m_data = data;
|
||||
emit done( data );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptJob::reportResults( const QVariant& data )
|
||||
{
|
||||
m_data_primitive = data;
|
||||
emit done( data );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptJob::reportFailure( const QString& errorMessage )
|
||||
{
|
||||
emit error( errorMessage );
|
||||
|
||||
reportResults( QVariantMap() );
|
||||
reportResultsMap( QVariantMap() );
|
||||
}
|
||||
|
@@ -49,11 +49,13 @@ public:
|
||||
QVariantMap arguments() const;
|
||||
|
||||
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 );
|
||||
|
||||
signals:
|
||||
void done( const QVariantMap& result );
|
||||
void done( const QVariant& result );
|
||||
void error( const QString& errorMessage );
|
||||
|
||||
void destroyed( const QString& id );
|
||||
@@ -64,6 +66,7 @@ protected:
|
||||
QString m_id;
|
||||
scriptobject_ptr m_scriptObject;
|
||||
QVariantMap m_data;
|
||||
QVariant m_data_primitive;
|
||||
QString m_methodName;
|
||||
QVariantMap m_arguments;
|
||||
};
|
||||
|
@@ -30,5 +30,5 @@ Tomahawk::SyncScriptJob::SyncScriptJob( const QVariantMap& resultData )
|
||||
void
|
||||
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