From e750ea45a34f083c20978a7d8f761222a244d521 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Wed, 23 Jan 2013 20:01:20 +0100 Subject: [PATCH] Refuse to close config dialogs with OK if settings are invalid --- .../accounts/AccountConfigWidget.cpp | 31 +++++++++++++++-- .../accounts/AccountConfigWidget.h | 9 +++++ .../accounts/DelegateConfigWrapper.cpp | 33 +++++++++++++++---- 3 files changed, 65 insertions(+), 8 deletions(-) diff --git a/src/libtomahawk/accounts/AccountConfigWidget.cpp b/src/libtomahawk/accounts/AccountConfigWidget.cpp index 44794089c..f4e20de54 100644 --- a/src/libtomahawk/accounts/AccountConfigWidget.cpp +++ b/src/libtomahawk/accounts/AccountConfigWidget.cpp @@ -18,7 +18,34 @@ #include "AccountConfigWidget.h" -AccountConfigWidget::AccountConfigWidget(QWidget *parent) : - QWidget(parent) +AccountConfigWidget::AccountConfigWidget(QWidget *parent) + : QWidget(parent) { } + + +void +AccountConfigWidget::checkForErrors() +{ +} + + +const QStringList +AccountConfigWidget::errors() const +{ + return m_errors; +} + + +void +AccountConfigWidget::resetErrors() +{ + m_errors.clear(); +} + + +bool +AccountConfigWidget::settingsValid() const +{ + return m_errors.empty(); +} diff --git a/src/libtomahawk/accounts/AccountConfigWidget.h b/src/libtomahawk/accounts/AccountConfigWidget.h index b809c5761..652100966 100644 --- a/src/libtomahawk/accounts/AccountConfigWidget.h +++ b/src/libtomahawk/accounts/AccountConfigWidget.h @@ -28,6 +28,15 @@ class DLLEXPORT AccountConfigWidget : public QWidget Q_OBJECT public: explicit AccountConfigWidget(QWidget *parent = 0); + + virtual void checkForErrors(); + virtual const QStringList errors() const; + virtual void resetErrors(); + + virtual bool settingsValid() const; + +protected: + QStringList m_errors; }; #endif // ACCOUNTCONFIGWIDGET_H diff --git a/src/libtomahawk/accounts/DelegateConfigWrapper.cpp b/src/libtomahawk/accounts/DelegateConfigWrapper.cpp index a16116914..40e7be1f8 100644 --- a/src/libtomahawk/accounts/DelegateConfigWrapper.cpp +++ b/src/libtomahawk/accounts/DelegateConfigWrapper.cpp @@ -103,21 +103,42 @@ DelegateConfigWrapper::closed( QAbstractButton* b ) if ( buttons->standardButton( b ) == QDialogButtonBox::Help ) return; - // let the config widget live to see another day - layout()->removeWidget( m_widget ); - m_widget->setParent( 0 ); - m_widget->setVisible( false ); + int doneCode = 0; if ( buttons->standardButton( b ) == QDialogButtonBox::Ok ) - done( QDialog::Accepted ); + { + m_widget->resetErrors(); + m_widget->checkForErrors(); + if( !m_widget->settingsValid() ) + { + foreach( const QString& error, m_widget->errors() ) + { + QMessageBox::warning( this, tr( "Config Error" ) , error ); + } + + return; + } + + doneCode = QDialog::Accepted; + } else if ( b == m_deleteButton ) { m_deleted = true; emit closedWithDelete(); reject(); + return; } else - done( QDialog::Rejected ); + { + doneCode = 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 ); }