Set the widget enabled false and emit an error if we cannot connect to the service

This commit is contained in:
Micke Prag 2011-03-03 14:17:29 +00:00
parent 70194457a9
commit dec6018464
2 changed files with 16 additions and 2 deletions

View file

@ -7,6 +7,7 @@
#include <QMessageBox>
#include <QHeaderView>
#include <QMenu>
#include <QTimer>
#include <QDebug>
@ -28,7 +29,7 @@ DeviceWidget::DeviceWidget(QWidget *parent) :
connect( &deviceView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(listActivated(const QModelIndex &)) );
connect(&model, SIGNAL(showMessage(const QString &, const QString &, const QString &)), this, SIGNAL(showMessage(const QString &, const QString &, const QString &)));
connect(&model, SIGNAL(eventTriggered(const QString &, const QString &)), this, SIGNAL(eventTriggered(const QString &, const QString &)));
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(&deviceView);
@ -68,6 +69,14 @@ DeviceWidget::DeviceWidget(QWidget *parent) :
buttonLayout->addStretch();
layout->addLayout( buttonLayout );
if (model.haveError()) {
//We emit the signal in the next "event loop".
//This to allow the signals to be connected from our parent object
QTimer::singleShot(0, this, SLOT(emitError()));
this->setEnabled( false );
}
}
DeviceWidget::~DeviceWidget()
@ -85,6 +94,10 @@ void DeviceWidget::changeEvent(QEvent *e)
}
}
void DeviceWidget::emitError() {
emit showMessage("", model.errorString(), "");
}
void DeviceWidget::addDevice() {
Device device(0, 0);
@ -102,7 +115,7 @@ void DeviceWidget::addDevice() {
void DeviceWidget::addGroup() {
//Device *device = model.newDevice();
Device device(0, 0);
EditGroupDialog *dialog = new EditGroupDialog(&device, &model);
if (dialog->exec() == QDialog::Accepted) {
device.save();

View file

@ -28,6 +28,7 @@ private slots:
void addGroup();
void deleteDevice();
void editDevice();
void emitError();
private:
DeviceModel model;