diff --git a/data/js/tomahawk.js b/data/js/tomahawk.js index 9cfdf7e22..4b31b499f 100644 --- a/data/js/tomahawk.js +++ b/data/js/tomahawk.js @@ -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; }); } }; diff --git a/src/libtomahawk/accounts/Account.cpp b/src/libtomahawk/accounts/Account.cpp index 9b2ee15be..3c3851a33 100644 --- a/src/libtomahawk/accounts/Account.cpp +++ b/src/libtomahawk/accounts/Account.cpp @@ -153,7 +153,7 @@ Account::removeFromConfig() void Account::testConfig() { - emit configTestResult( ConfigTestResultSuccess ); + emit configTestResult( ConfigTestResultSuccess, "" ); } diff --git a/src/libtomahawk/accounts/Account.h b/src/libtomahawk/accounts/Account.h index 502a97b81..ec1006fa8 100644 --- a/src/libtomahawk/accounts/Account.h +++ b/src/libtomahawk/accounts/Account.h @@ -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 ); diff --git a/src/libtomahawk/accounts/DelegateConfigWrapper.cpp b/src/libtomahawk/accounts/DelegateConfigWrapper.cpp index 4a25f504a..6c7650bb1 100644 --- a/src/libtomahawk/accounts/DelegateConfigWrapper.cpp +++ b/src/libtomahawk/accounts/DelegateConfigWrapper.cpp @@ -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( "%1" ).arg( tr( "Your config is invalid." ) ) ); + QString msg; + if (message.isEmpty()){ + msg = getTestConfigMessage(code); + } else { + msg = message; + } + m_errorLabel->setText( QString( "%1" ).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." ); } } diff --git a/src/libtomahawk/accounts/DelegateConfigWrapper.h b/src/libtomahawk/accounts/DelegateConfigWrapper.h index 2eddf9ed8..8b90f5166 100644 --- a/src/libtomahawk/accounts/DelegateConfigWrapper.h +++ b/src/libtomahawk/accounts/DelegateConfigWrapper.h @@ -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; diff --git a/src/libtomahawk/accounts/ResolverAccount.cpp b/src/libtomahawk/accounts/ResolverAccount.cpp index 00e56bb74..f7d5036a8 100644 --- a/src/libtomahawk/accounts/ResolverAccount.cpp +++ b/src/libtomahawk/accounts/ResolverAccount.cpp @@ -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(); diff --git a/src/libtomahawk/accounts/ResolverAccount.h b/src/libtomahawk/accounts/ResolverAccount.h index d57d4c6ce..d1130d7e8 100644 --- a/src/libtomahawk/accounts/ResolverAccount.h +++ b/src/libtomahawk/accounts/ResolverAccount.h @@ -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 diff --git a/src/libtomahawk/resolvers/ScriptAccount.cpp b/src/libtomahawk/resolvers/ScriptAccount.cpp index 11156b210..cf718ea5b 100644 --- a/src/libtomahawk/resolvers/ScriptAccount.cpp +++ b/src/libtomahawk/resolvers/ScriptAccount.cpp @@ -157,9 +157,15 @@ ScriptAccount::reportScriptJobResult( const QVariantMap& result ) // got a successful job result if ( result[ "error"].isNull() ) { - const QVariantMap data = result[ "data" ].toMap(); - - job->reportResults( data ); + if (result[ "data" ].type() == QMetaType::QVariantMap) + { + const QVariantMap data = result[ "data" ].toMap(); + job->reportResultsMap( data ); + } + else + { + job->reportResults( result[ "data" ] ); + } } else { diff --git a/src/libtomahawk/resolvers/ScriptJob.cpp b/src/libtomahawk/resolvers/ScriptJob.cpp index 3e52ca0da..7738fa2da 100644 --- a/src/libtomahawk/resolvers/ScriptJob.cpp +++ b/src/libtomahawk/resolvers/ScriptJob.cpp @@ -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() ); } diff --git a/src/libtomahawk/resolvers/ScriptJob.h b/src/libtomahawk/resolvers/ScriptJob.h index 588085759..8f500aff8 100644 --- a/src/libtomahawk/resolvers/ScriptJob.h +++ b/src/libtomahawk/resolvers/ScriptJob.h @@ -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; }; diff --git a/src/libtomahawk/resolvers/SyncScriptJob.cpp b/src/libtomahawk/resolvers/SyncScriptJob.cpp index 0aedab67e..3eb2163a3 100644 --- a/src/libtomahawk/resolvers/SyncScriptJob.cpp +++ b/src/libtomahawk/resolvers/SyncScriptJob.cpp @@ -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 ) ); }