From fffe3cbf1f70865aefc48855495ebfc624799f9e Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Wed, 10 Dec 2014 22:36:30 +0100 Subject: [PATCH] Allow saving of invalid config on second try --- .../accounts/DelegateConfigWrapper.cpp | 28 +++++++++++++++++-- .../accounts/DelegateConfigWrapper.h | 1 + 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/accounts/DelegateConfigWrapper.cpp b/src/libtomahawk/accounts/DelegateConfigWrapper.cpp index fbb151f20..8048c1b23 100644 --- a/src/libtomahawk/accounts/DelegateConfigWrapper.cpp +++ b/src/libtomahawk/accounts/DelegateConfigWrapper.cpp @@ -188,12 +188,35 @@ DelegateConfigWrapper::onConfigTestResult( Tomahawk::Accounts::ConfigTestResultT if( result == Tomahawk::Accounts::ConfigTestResultSuccess ) { - m_errorLabel->setText( "" ); + m_invalidData = QVariantMap(); closeDialog( QDialog::Accepted ); } else { - // TODO: make this nicer + const QVariantMap newData = m_widget->readData(); + + // check if user tried to save the same config for the second time + bool configChangedSinceLastTry = false; + if ( !m_invalidData.isEmpty() ) + { + foreach( const QString& key, m_invalidData.keys() ) + { + if ( m_invalidData[ key ] != newData[ key ] ) + { + configChangedSinceLastTry = true; + break; + } + } + + if ( !configChangedSinceLastTry ) + { + closeDialog( QDialog::Accepted ); + } + } + + m_invalidData = m_widget->readData(); + + // TODO: generate message based on status code m_errorLabel->setText( QString( "%1" ).arg( tr( "Your config is invalid." ) ) ); } } @@ -206,6 +229,7 @@ DelegateConfigWrapper::closeDialog( QDialog::DialogCode code ) layout()->removeWidget( m_widget ); m_widget->setParent( 0 ); m_widget->setVisible( false ); + m_errorLabel->setText( "" ); done( code ); } diff --git a/src/libtomahawk/accounts/DelegateConfigWrapper.h b/src/libtomahawk/accounts/DelegateConfigWrapper.h index af9f3fc71..0e56de1a5 100644 --- a/src/libtomahawk/accounts/DelegateConfigWrapper.h +++ b/src/libtomahawk/accounts/DelegateConfigWrapper.h @@ -69,6 +69,7 @@ private: QPushButton *m_okButton, *m_deleteButton; QLabel* m_errorLabel; bool m_deleted; + QVariantMap m_invalidData; }; #endif