Skip to content

Commit

Permalink
Handle QTOZW Ready States
Browse files Browse the repository at this point in the history
  • Loading branch information
Fishwaldo committed Jun 2, 2020
1 parent 8a3b527 commit 4ed702d
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 35 deletions.
25 changes: 13 additions & 12 deletions ozwadmin-main/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ MainWindow::MainWindow(QWidget *parent) :
this->statusBar()->showMessage(tr("Starting..."));
this->connected(false);

connect(OZWCore::get(), &OZWCore::raiseCriticalError, this, &MainWindow::openCriticalDialog, Qt::DirectConnection);
connect(OZWCore::get(), &OZWCore::raiseCriticalError, this, &MainWindow::openCriticalDialog);

OZWCore::get()->initilize();

this->sbMsg = new statusBarMessages(this);
Expand All @@ -75,7 +76,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(ui->action_Heal_Network, SIGNAL(triggered()), this, SLOT(healNetwork()));
connect(this->sbMsg, &statusBarMessages::newMessage, this, &MainWindow::setStatusBarMsg);
connect(OZWCore::get()->getQTOZWManager(), &QTOZWManager::remoteConnectionStatus, this, &MainWindow::remoteConnectionStatus);
connect(OZWCore::get()->getQTOZWManager(), &QTOZWManager::ready, this, &MainWindow::QTOZW_Ready);
connect(OZWCore::get()->getQTOZWManager(), &QTOZWManager::readyChanged, this, &MainWindow::QTOZW_Ready);

SplashDialog *sw = new SplashDialog(this);
sw->show();
Expand All @@ -89,7 +90,9 @@ MainWindow::~MainWindow()
delete ui;
}

void MainWindow::QTOZW_Ready() {
void MainWindow::QTOZW_Ready(bool ready) {
// TODO: Close Windows if they are open on Non-Ready Status
if (!ready) return;
qCDebug(ozwadmin) << "QTOZW Ready";

/* apply our Local Configuration Options to the OZW Options Class */
Expand All @@ -111,10 +114,7 @@ void MainWindow::QTOZW_Ready() {
}
}
OZWCore::get()->settings.endGroup();

openDefaultWindows();


}
void MainWindow::openDefaultWindows() {

Expand Down Expand Up @@ -188,7 +188,6 @@ void MainWindow::openDefaultWindows() {
lw->setModel(OZWCore::get()->getQTOZWManager()->getLogModel());

di->setQTOZWManager(OZWCore::get()->getQTOZWManager());
ni->setQTOZWManager(OZWCore::get()->getQTOZWManager());
this->m_WindowsSetup = true;
}

Expand Down Expand Up @@ -246,10 +245,10 @@ void MainWindow::CloseConnection() {
if (OZWCore::get()->getQTOZWManager()->getConnectionType() == QTOZWManager::connectionType::Local) {
OZWCore::get()->getQTOZWManager()->close();
} else if (OZWCore::get()->getQTOZWManager()->getConnectionType() == QTOZWManager::connectionType::Remote) {
QMessageBox::critical(this, "Close Connection", "TODO: Please restart the application for now");
exit(1);
//QMessageBox::critical(this, "Close Connection", "TODO: Please restart the application for now");
//exit(1);
} else {
QMessageBox::critical(this, "Unknown Connection Type", "Unknown Connection Type");
//QMessageBox::critical(this, "Unknown Connection Type", "Unknown Connection Type");
}
this->connected(false);
}
Expand Down Expand Up @@ -303,8 +302,10 @@ void MainWindow::openAboutWindow() {
sw->move(this->geometry().center() - sw->rect().center());
}

QMessageBox::StandardButton MainWindow::openCriticalDialog(QString title, QString msg) {
return QMessageBox::critical(this, title, msg);
void MainWindow::openCriticalDialog(QString title, QString msg) {
QMessageBox *msgBox = new QMessageBox(QMessageBox::Critical, title, msg, QMessageBox::Ok, this);
msgBox->exec();
return;
}


Expand Down
7 changes: 3 additions & 4 deletions ozwadmin-main/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public slots:
void resizeColumns();
void NodeSelected(QModelIndex,QModelIndex);
void OpenDeviceDB();
void QTOZW_Ready();
void QTOZW_Ready(bool ready);
void openAboutWindow();
void openMetaDataWindow();
void openConfigWindow();
Expand All @@ -58,9 +58,8 @@ public slots:
void healNetwork();
void setStatusBarMsg(QString);
void remoteConnectionStatus(QTOZWManager::connectionStatus status, QAbstractSocket::SocketError error);

QMessageBox::StandardButton openCriticalDialog(QString title, QString msg);

private slots:
void openCriticalDialog(QString title, QString msg);
private:
void connected(bool);
void openDefaultWindows();
Expand Down
23 changes: 13 additions & 10 deletions ozwadmin-main/nodestatus.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "nodestatus.h"
#include "ui_nodestatus.h"
#include <qt-openzwave/qtopenzwave.h>
#include <qt-openzwave/qtozwmanager.h>
#include "nodestatus.h"
#include "ui_nodestatus.h"
#include "ozwcore.h"

NodeStatus::NodeStatus(QWidget *parent) :
QWidget(parent),
Expand All @@ -17,16 +18,20 @@ NodeStatus::~NodeStatus()
delete ui;
}

void NodeStatus::setQTOZWManager(QTOZWManager *manager) {
this->m_qtozwmanager = manager;
void NodeStatus::updateNodeStats() {

if (OZWCore::get()->getQTOZWManager()->isReady()) {
if (!this->m_statTimer.isActive())
this->m_statTimer.start(1000);
} else {
this->m_statTimer.stop();
}

}

void NodeStatus::updateNodeStats() {
const QAbstractItemModel * model = this->currentNode.model();
quint8 node = model->data(model->index(this->currentNode.row(), QTOZW_Nodes::NodeColumns::NodeID)).value<quint8>();
QBitArray flags = model->data(model->index(this->currentNode.row(), QTOZW_Nodes::NodeColumns::NodeFlags)).value<QBitArray>();
this->ui->ns_querystage->setText(this->m_qtozwmanager->GetNodeQueryStage(node));
this->ui->ns_querystage->setText(OZWCore::get()->getQTOZWManager()->GetNodeQueryStage(node));
this->ui->ns_sleeping->setChecked(!flags.at(QTOZW_Nodes::nodeFlags::isAwake));

if (flags.at(QTOZW_Nodes::nodeFlags::isFailed)) {
Expand All @@ -39,7 +44,7 @@ void NodeStatus::updateNodeStats() {
this->ui->ns_status->setText("Awake");
}

NodeStatistics ns = this->m_qtozwmanager->GetNodeStatistics(node);
NodeStatistics ns = OZWCore::get()->getQTOZWManager()->GetNodeStatistics(node);
this->ui->ns_lastseen->setText(ns.lastReceivedTimeStamp.toString());
this->ui->ns_lreqrtt->setText(QVariant::fromValue<quint32>(ns.lastRequestRTT).toString());
this->ui->ns_quality->setText(QVariant::fromValue<quint32>(ns.quality).toString());
Expand Down Expand Up @@ -74,8 +79,6 @@ void NodeStatus::updateNodeStats() {
this->ui->ens_routeSpeed->setText(ns.routeSpeed);
this->ui->ens_routeScheme->setText(ns.routeScheme);

if (!this->m_statTimer.isActive())
this->m_statTimer.start(1000);
}

void NodeStatus::NodeSelected(QModelIndex current, QModelIndex previous) {
Expand Down
2 changes: 0 additions & 2 deletions ozwadmin-main/nodestatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class NodeStatus : public QWidget
explicit NodeStatus(QWidget *parent = nullptr);
~NodeStatus();

void setQTOZWManager(QTOZWManager *manager);
public Q_SLOTS:
void NodeSelected(QModelIndex, QModelIndex);

Expand All @@ -29,7 +28,6 @@ public Q_SLOTS:


Ui::NodeStatus *ui;
QTOZWManager *m_qtozwmanager;
QTimer m_statTimer;
QModelIndex currentNode;
};
Expand Down
5 changes: 3 additions & 2 deletions ozwadmin-main/startupprogress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ startupprogress::startupprogress(bool remote, QWidget *parent) :

/* connect the signals */
QObject::connect(OZWCore::get()->getQTOZWManager(), &QTOZWManager::manufacturerSpecificDBReady, this, &startupprogress::manufacturerSpecificDBReady);
QObject::connect(OZWCore::get()->getQTOZWManager(), &QTOZWManager::ready, this, &startupprogress::ready);
QObject::connect(OZWCore::get()->getQTOZWManager(), &QTOZWManager::readyChanged, this, &startupprogress::ready);
QObject::connect(OZWCore::get()->getQTOZWManager(), &QTOZWManager::starting, this, &startupprogress::starting);
QObject::connect(OZWCore::get()->getQTOZWManager(), &QTOZWManager::started, this, &startupprogress::started);
QObject::connect(OZWCore::get()->getQTOZWManager(), &QTOZWManager::driverReady, this, &startupprogress::driverReady);
Expand Down Expand Up @@ -45,7 +45,8 @@ void startupprogress::manufacturerSpecificDBReady() {
ui->label->setText("Manufacturer Specific Database Ready");
}

void startupprogress::ready() {
void startupprogress::ready(bool ready) {
if (!ready) return;
ui->label->setText("OpenZWave Ready");
this->close();
}
Expand Down
2 changes: 1 addition & 1 deletion ozwadmin-main/startupprogress.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class startupprogress : public QDialog

public Q_SLOTS:
void manufacturerSpecificDBReady();
void ready();
void ready(bool ready);
void starting();
void started(quint32 homeID);
void driverReady(quint32 homeID);
Expand Down
6 changes: 3 additions & 3 deletions ozwadmin-main/statusbarmessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ statusBarMessages::statusBarMessages(QObject *parent) : QObject(parent)
{
QTOZWManager *qtozwm = OZWCore::get()->getQTOZWManager();
QObject::connect(qtozwm, &QTOZWManager::manufacturerSpecificDBReady, this, &statusBarMessages::manufacturerSpecificDBReady);
QObject::connect(qtozwm, &QTOZWManager::ready, this, &statusBarMessages::ready);
QObject::connect(qtozwm, &QTOZWManager::readyChanged, this, &statusBarMessages::ready);
QObject::connect(qtozwm, &QTOZWManager::starting, this, &statusBarMessages::starting);
QObject::connect(qtozwm, &QTOZWManager::started, this, &statusBarMessages::started);
QObject::connect(qtozwm, &QTOZWManager::valueAdded, this, &statusBarMessages::valueAdded);
Expand Down Expand Up @@ -38,8 +38,8 @@ statusBarMessages::statusBarMessages(QObject *parent) : QObject(parent)
QObject::connect(qtozwm, &QTOZWManager::manufacturerSpecificDBReady, this, &statusBarMessages::manufacturerSpecificDBReady);
}

void statusBarMessages::ready() {
emit newMessage("OpenZwave Ready");
void statusBarMessages::ready(bool ready) {
if (ready) emit newMessage("OpenZwave Ready");
}
void statusBarMessages::valueAdded(quint64 vidKey) {
emit newMessage(QString("Value Added: %1").arg(vidKeyDetails(vidKey)));
Expand Down
2 changes: 1 addition & 1 deletion ozwadmin-main/statusbarmessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class statusBarMessages : public QObject
signals:
void newMessage(QString);
public slots:
void ready();
void ready(bool ready);
void valueAdded(quint64 vidKey);
void valueRemoved(quint64 vidKey);
void valueChanged(quint64 vidKey);
Expand Down

0 comments on commit 4ed702d

Please sign in to comment.