1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-23 01:09:42 +01:00

Refuse to close config dialogs with OK if settings are invalid

This commit is contained in:
Dominik Schmidt 2013-01-23 20:01:20 +01:00
parent 724f92e776
commit e750ea45a3
3 changed files with 65 additions and 8 deletions

View File

@ -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();
}

View File

@ -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

View File

@ -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 );
}