1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-11 16:44:05 +02:00

Add configTest to ResolverAccounts

This commit is contained in:
Dominik Schmidt
2014-12-10 19:59:34 +01:00
parent 7550d23431
commit 132c7d4cd2
8 changed files with 127 additions and 12 deletions

View File

@@ -196,6 +196,13 @@ var TomahawkResolver = {
}, },
collection: function () { collection: function () {
return {}; return {};
},
_testConfig: function (config) {
return Promise.resolve(this.testConfig(config)).then(function() {
return { result: Tomahawk.ConfigTestResultType.Success };
});
},
testConfig: function () {
} }
}; };
@@ -638,3 +645,15 @@ Tomahawk.PluginManager = {
}); });
} }
}; };
Tomahawk.ConfigTestResultType = {
Other: 0,
Success: 1,
Logout: 2,
CommunicationError: 3,
InvalidCredentials: 4,
InvalidAccount: 5,
PlayingElsewhere: 6,
AccountExpired: 7
};

View File

@@ -150,6 +150,13 @@ Account::removeFromConfig()
} }
void
Account::testConfig()
{
emit configTestResult( ConfigTestResultSuccess );
}
void void
Account::setTypes( AccountTypes types ) Account::setTypes( AccountTypes types )
{ {

View File

@@ -54,6 +54,19 @@ enum AccountType
StatusPushType = 0x08 StatusPushType = 0x08
}; };
// ATTENTION: keep in sync with tomahawk.js
enum ConfigTestResultType
{
ConfigTestResultOther = 0,
ConfigTestResultSuccess = 1,
ConfigTestResultLogout = 2,
ConfigTestResultCommunicationError = 3,
ConfigTestResultInvalidCredentials = 4,
ConfigTestResultInvalidAccount = 5,
ConfigTestResultPlayingElsewhere = 6,
ConfigTestResultAccountExpired = 7
};
DLLEXPORT QString accountTypeToString( AccountType type ); DLLEXPORT QString accountTypeToString( AccountType type );
Q_DECLARE_FLAGS( AccountTypes, AccountType ) Q_DECLARE_FLAGS( AccountTypes, AccountType )
@@ -143,6 +156,8 @@ public:
*/ */
virtual void removeFromConfig(); virtual void removeFromConfig();
virtual void testConfig();
public slots: public slots:
virtual void authenticate() = 0; virtual void authenticate() = 0;
virtual void deauthenticate() = 0; virtual void deauthenticate() = 0;
@@ -152,6 +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 );
protected: protected:
virtual void loadFromConfig( const QString &accountId ); virtual void loadFromConfig( const QString &accountId );

View File

@@ -19,6 +19,7 @@
#include "Account.h" #include "Account.h"
#include "AccountConfigWidget.h" #include "AccountConfigWidget.h"
#include "../utils/Logger.h"
#include <QMessageBox> #include <QMessageBox>
@@ -74,6 +75,8 @@ 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 ) ) );
} }
@@ -101,10 +104,9 @@ DelegateConfigWrapper::closed( QAbstractButton* b )
if ( buttons->standardButton( b ) == QDialogButtonBox::Help ) if ( buttons->standardButton( b ) == QDialogButtonBox::Help )
return; return;
int doneCode = 0;
if ( buttons->standardButton( b ) == QDialogButtonBox::Ok ) if ( buttons->standardButton( b ) == QDialogButtonBox::Ok )
{ {
// TODO: probably should be hidden behind testConfig() in cpp accounts
m_widget->resetErrors(); m_widget->resetErrors();
m_widget->checkForErrors(); m_widget->checkForErrors();
if( !m_widget->settingsValid() ) if( !m_widget->settingsValid() )
@@ -117,7 +119,7 @@ DelegateConfigWrapper::closed( QAbstractButton* b )
return; return;
} }
doneCode = QDialog::Accepted; m_account->testConfig();
} }
else if ( b == m_deleteButton ) else if ( b == m_deleteButton )
{ {
@@ -128,15 +130,8 @@ DelegateConfigWrapper::closed( QAbstractButton* b )
} }
else else
{ {
doneCode = QDialog::Rejected; closeDialog( QDialog::Rejected );
} }
// let the config widget live to see another day
layout()->removeWidget( m_widget );
m_widget->setParent( 0 );
m_widget->setVisible( false );
done( doneCode );
} }
@@ -179,3 +174,31 @@ DelegateConfigWrapper::aboutClicked( bool )
} }
void
DelegateConfigWrapper::onConfigTestResult( Tomahawk::Accounts::ConfigTestResultType result )
{
tLog() << Q_FUNC_INFO << result;
if( result == Tomahawk::Accounts::ConfigTestResultSuccess )
{
closeDialog( QDialog::Accepted );
}
else
{
// TODO: make this nicer
QMessageBox::critical( this, tr( "Error" ), tr( "Your config is invalid and can't be saved." ) );
}
}
void
DelegateConfigWrapper::closeDialog( QDialog::DialogCode code )
{
// let the config widget live to see another day
layout()->removeWidget( m_widget );
m_widget->setParent( 0 );
m_widget->setVisible( false );
done( code );
}

View File

@@ -54,8 +54,11 @@ signals:
private slots: private slots:
void aboutClicked( bool ); void aboutClicked( bool );
void onConfigTestResult( Tomahawk::Accounts::ConfigTestResultType );
private: private:
void closeDialog( QDialog::DialogCode code );
Tomahawk::Accounts::Account* m_account; Tomahawk::Accounts::Account* m_account;
AccountConfigWidget* m_widget; AccountConfigWidget* m_widget;
QWidget* m_aboutW; QWidget* m_aboutW;

View File

@@ -41,6 +41,12 @@
#include "TomahawkSettings.h" #include "TomahawkSettings.h"
#include "TomahawkVersion.h" #include "TomahawkVersion.h"
// HACK
#include "../resolvers/JSResolver.h"
#include "resolvers/ScriptObject.h"
#include "resolvers/ScriptJob.h"
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QDir> #include <QDir>
@@ -511,6 +517,44 @@ ResolverAccount::removeBundle()
} }
void ResolverAccount::testConfig()
{
// HACK: move to JSAccount once we have that properly
JSResolver* resolver = qobject_cast< Tomahawk::JSResolver* >( m_resolver );
if ( resolver )
{
QVariantMap data = resolver->loadDataFromWidgets();
tLog() << "config data: " << data;
ScriptJob* job = resolver->scriptObject()->invoke( "_testConfig", data );
connect( job, SIGNAL( done( QVariantMap ) ), SLOT( onTestConfig( QVariantMap ) ) );
job->start();
}
else
{
emit configTestResult( Accounts::ConfigTestResultSuccess );
}
}
void
ResolverAccount::onTestConfig( const QVariantMap& result )
{
tLog() << Q_FUNC_INFO << result;
int resultCode = result[ "result" ].toInt();
if ( resultCode == 1 )
{
emit configTestResult( Accounts::ConfigTestResultSuccess );
}
else
{
emit configTestResult( Accounts::ConfigTestResultOther );
}
sender()->deleteLater();
}
/// AtticaResolverAccount /// AtticaResolverAccount
AtticaResolverAccount::AtticaResolverAccount( const QString& accountId ) AtticaResolverAccount::AtticaResolverAccount( const QString& accountId )

View File

@@ -99,8 +99,11 @@ public:
void removeBundle(); void removeBundle();
void testConfig() override;
private slots: private slots:
void resolverChanged(); void resolverChanged();
void onTestConfig( const QVariantMap& result );
protected: protected:
// Created by factory, when user installs a new resolver // Created by factory, when user installs a new resolver

View File

@@ -71,6 +71,7 @@ public:
bool canParseUrl( const QString& url, UrlType type ) override; bool canParseUrl( const QString& url, UrlType type ) override;
QVariantMap loadDataFromWidgets();
public slots: public slots:
void resolve( const Tomahawk::query_ptr& query ) override; void resolve( const Tomahawk::query_ptr& query ) override;
@@ -99,7 +100,6 @@ private:
void loadUi(); void loadUi();
void setWidgetData( const QVariant& value, QWidget* widget, const QString& property ); void setWidgetData( const QVariant& value, QWidget* widget, const QString& property );
QVariant widgetData( QWidget* widget, const QString& property ); QVariant widgetData( QWidget* widget, const QString& property );
QVariantMap loadDataFromWidgets();
void fillDataInWidgets( const QVariantMap& data ); void fillDataInWidgets( const QVariantMap& data );
void onCapabilitiesChanged( Capabilities capabilities ); void onCapabilitiesChanged( Capabilities capabilities );
void loadCollections(); void loadCollections();