mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-07 06:36:55 +02:00
Refuse to close config dialogs with OK if settings are invalid
This commit is contained in:
@@ -18,7 +18,34 @@
|
|||||||
|
|
||||||
#include "AccountConfigWidget.h"
|
#include "AccountConfigWidget.h"
|
||||||
|
|
||||||
AccountConfigWidget::AccountConfigWidget(QWidget *parent) :
|
AccountConfigWidget::AccountConfigWidget(QWidget *parent)
|
||||||
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();
|
||||||
|
}
|
||||||
|
@@ -28,6 +28,15 @@ class DLLEXPORT AccountConfigWidget : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit AccountConfigWidget(QWidget *parent = 0);
|
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
|
#endif // ACCOUNTCONFIGWIDGET_H
|
||||||
|
@@ -103,21 +103,42 @@ DelegateConfigWrapper::closed( QAbstractButton* b )
|
|||||||
if ( buttons->standardButton( b ) == QDialogButtonBox::Help )
|
if ( buttons->standardButton( b ) == QDialogButtonBox::Help )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// let the config widget live to see another day
|
int doneCode = 0;
|
||||||
layout()->removeWidget( m_widget );
|
|
||||||
m_widget->setParent( 0 );
|
|
||||||
m_widget->setVisible( false );
|
|
||||||
|
|
||||||
if ( buttons->standardButton( b ) == QDialogButtonBox::Ok )
|
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 )
|
else if ( b == m_deleteButton )
|
||||||
{
|
{
|
||||||
m_deleted = true;
|
m_deleted = true;
|
||||||
emit closedWithDelete();
|
emit closedWithDelete();
|
||||||
reject();
|
reject();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user