From 29fba4f4d6a0ea168cef7cc53a992518971b7556 Mon Sep 17 00:00:00 2001 From: Justin Hammond Date: Mon, 25 May 2020 14:11:11 +0800 Subject: [PATCH] Start Work on Dialogs for Controller Commands --- .vscode/c_cpp_properties.json | 21 ++- ozwadmin-main/controllercommands.cpp | 42 ++++++ ozwadmin-main/controllercommands.h | 25 ++++ ozwadmin-main/mainwindow.cpp | 204 +++++++++++---------------- ozwadmin-main/mainwindow.h | 22 ++- ozwadmin-main/mainwindow.ui | 23 +++ ozwadmin-main/nodetablewidget.cpp | 17 +++ ozwadmin-main/nodetablewidget.h | 3 + ozwadmin-main/ozwadmin-main.pro | 2 + ozwadmin-main/ozwcore.cpp | 98 ++++++++++++- ozwadmin-main/ozwcore.h | 20 ++- 11 files changed, 335 insertions(+), 142 deletions(-) create mode 100644 ozwadmin-main/controllercommands.cpp create mode 100644 ozwadmin-main/controllercommands.h diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 494cb0b..4bdc4ff 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -13,7 +13,26 @@ "compilerPath": "/usr/bin/gcc", "cStandard": "c11", "cppStandard": "c++17", - "intelliSenseMode": "clang-x64" + "intelliSenseMode": "clang-x64", + "compileCommands": "${workspaceFolder}/compile_commands.json" + }, + { + "name": "Mac", + "includePath": [ + "${workspaceFolder}/**", + "${workspaceFolder}/../open-zwave/cpp/src/**", + "${workspaceFolder}/../qt-openzwave/qt-openzwave/include/**", + "${workspaceFolder}/../qt-openzwave/qt-openzwavedatabase/include/**" + ], + "macFrameworkPath": [ + "/Users/fish/Qt/5.12.6/clang_64/lib/" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c11", + "cppStandard": "c++17", + "intelliSenseMode": "clang-x64", + "compileCommands": "${workspaceFolder}/compile_commands.json" } ], "version": 4 diff --git a/ozwadmin-main/controllercommands.cpp b/ozwadmin-main/controllercommands.cpp new file mode 100644 index 0000000..f927a98 --- /dev/null +++ b/ozwadmin-main/controllercommands.cpp @@ -0,0 +1,42 @@ +#include +#include "controllercommands.h" + + + +ControllerCommands::ControllerCommands(QMainWindow *parent) : + QObject(parent) +{ + +} + +void ControllerCommands::addNode() { + QMessageBox::StandardButton ret = QMessageBox::question(qobject_cast(this->parent()), "Include Secure?", "Do you wish to include the new device with encryption?", QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel); + if (ret == QMessageBox::Cancel) { + return; + } + this->m_msgBox = new QMessageBox(QMessageBox::Information, "Adding Node", "Starting....", QMessageBox::Cancel, qobject_cast(this->parent())); + this->m_msgBox->setDetailedText("Waiting for the Controller to Enter AddNode Mode..."); + connect(this->m_msgBox, &QMessageBox::rejected, this, &ControllerCommands::cancelCommand); + this->m_msgBox->show(); + if (ret == QMessageBox::Yes) { + OZWCore::get()->getQTOZWManager()->addNode(true); + } else if (ret == QMessageBox::No) { + OZWCore::get()->getQTOZWManager()->addNode(false); + } +} +void ControllerCommands::delNode() { + OZWCore::get()->getQTOZWManager()->removeNode(); +} +void ControllerCommands::healNetwork() { + QMessageBox::StandardButton ret = QMessageBox::information(qobject_cast(this->parent()), "Heal Network", "Healing the Network Should only be performed after Adding/Removing or Physically Moving Mains Powered Devices. Are you sure?", QMessageBox::Ok|QMessageBox::Cancel); + if (ret == QMessageBox::Ok) { + OZWCore::get()->getQTOZWManager()->healNetwork(false); + } +} +void ControllerCommands::cancelCommand() { + QMessageBox::StandardButton ret = QMessageBox::question(qobject_cast(this->parent()), "Cancel Command", "Are you sure you wish to cancel the command?"); + if (ret == QMessageBox::Yes) { + OZWCore::get()->getQTOZWManager()->cancelControllerCommand(); + } +} + diff --git a/ozwadmin-main/controllercommands.h b/ozwadmin-main/controllercommands.h new file mode 100644 index 0000000..6824b6f --- /dev/null +++ b/ozwadmin-main/controllercommands.h @@ -0,0 +1,25 @@ +#ifndef CONTROLLERCOMMANDS_H +#define CONTROLLERCOMMANDS_H + +#include +#include +#include "ozwcore.h" + +class OZWCore; + +class ControllerCommands : public QObject +{ + Q_OBJECT +public: + explicit ControllerCommands(QMainWindow *parent = nullptr); + +public slots: + void addNode(); + void delNode(); + void healNetwork(); + void cancelCommand(); +private: + QMessageBox *m_msgBox; +}; + +#endif // CONTROLLERCOMMANDS_H diff --git a/ozwadmin-main/mainwindow.cpp b/ozwadmin-main/mainwindow.cpp index 91c4160..cd1b43e 100644 --- a/ozwadmin-main/mainwindow.cpp +++ b/ozwadmin-main/mainwindow.cpp @@ -19,11 +19,10 @@ #include #include #include -#include #include #include -#include + #include #include @@ -46,11 +45,6 @@ #include "ozwcore.h" - - - - - MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), @@ -58,9 +52,15 @@ MainWindow::MainWindow(QWidget *parent) : { this->ui->setupUi(this); this->m_DockManager = new ads::CDockManager(this); + this->m_controllerCommands = new ControllerCommands(this); + this->connected(false); + + connect(OZWCore::get(), &OZWCore::raiseCriticalError, this, &MainWindow::openCriticalDialog, Qt::DirectConnection); OZWCore::get()->initilize(); + + DeviceInfo *di = new DeviceInfo(this); NodeStatus *ni = new NodeStatus(this); statusBar()->showMessage(tr("Starting...")); @@ -72,6 +72,11 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->actionDevice_Database, SIGNAL(triggered()), this, SLOT(OpenDeviceDB())); connect(ui->action_Configuration, SIGNAL(triggered()), this, SLOT(openConfigWindow())); connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(openAboutWindow())); + connect(ui->action_AddNode, SIGNAL(triggered()), this, SLOT(addNode())); + connect(ui->action_Delete_Node, SIGNAL(triggered()), this, SLOT(delNode())); + connect(ui->action_Heal_Network, SIGNAL(triggered()), this, SLOT(healNetwork())); + + connect(di, &DeviceInfo::openMetaDataWindow, this, &MainWindow::openMetaDataWindow); this->ntw = new nodeTableWidget(this); @@ -87,6 +92,7 @@ MainWindow::MainWindow(QWidget *parent) : ads::CDockWidget* DeviceInfoDW = new ads::CDockWidget("Node Info"); DeviceInfoDW->setWidget(di); auto RightDockWidget = this->m_DockManager->addDockWidget(ads::RightDockWidgetArea, DeviceInfoDW); + ads::CDockWidget* DeviceStatusDW = new ads::CDockWidget("Node Status"); DeviceStatusDW->setWidget(ni); this->m_DockManager->addDockWidget(ads::CenterDockWidgetArea, DeviceStatusDW, RightDockWidget); @@ -109,100 +115,22 @@ MainWindow::MainWindow(QWidget *parent) : RightDockWidget->setCurrentDockWidget(DeviceInfoDW); - QStringList PossibleDBPaths; - PossibleDBPaths << settings.value("openzwave/ConfigPath", QDir::toNativeSeparators("../../../config/")).toString().append("/"); - PossibleDBPaths << QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); + this->sbMsg.setQTOZWManager(OZWCore::get()->getQTOZWManager()); + + QObject::connect(OZWCore::get()->getQTOZWManager(), &QTOZWManager::ready, this, &MainWindow::QTOZW_Ready); - QString path, dbPath, userPath; - foreach(path, PossibleDBPaths) { - qCDebug(ozwadmin) << "Checking " << QFileInfo(QDir::toNativeSeparators(path + "/config/manufacturer_specific.xml")).absoluteFilePath() << " for manufacturer_specific.xml"; - if (QFileInfo(QDir::toNativeSeparators(path + "/config/manufacturer_specific.xml")).exists()) { - dbPath = QFileInfo(QDir::toNativeSeparators(path + "/config/manufacturer_specific.xml")).absoluteFilePath(); - break; - } - qCDebug(ozwadmin) << "Checking " << QFileInfo(QDir::toNativeSeparators(path + "../config/manufacturer_specific.xml")).absoluteFilePath() << " for manufacturer_specific.xml"; - if (QFile(QDir::toNativeSeparators(path + "/../config/manufacturer_specific.xml")).exists()) { - dbPath = QFileInfo(QDir::toNativeSeparators(path + "/../config/manufacturer_specific.xml")).absoluteFilePath(); - break; - } - } - PossibleDBPaths.clear(); - PossibleDBPaths << settings.value("openzwave/UserPath", QDir::toNativeSeparators("../../../config/")).toString().append("/"); - PossibleDBPaths << QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); - - foreach(path, PossibleDBPaths) { - qCDebug(ozwadmin) << "Checking " << QFileInfo(QDir::toNativeSeparators(path + "/config/Options.xml")).absoluteFilePath() << " for Options.xml"; - if (QFileInfo(QDir::toNativeSeparators(path + "/config/Options.xml")).exists()) { - userPath = QFileInfo(QDir::toNativeSeparators(path + "/config/Options.xml")).absoluteFilePath(); - break; - } - qCDebug(ozwadmin) << "Checking " << QFileInfo(QDir::toNativeSeparators(path + "/../config/Options.xml")).absoluteFilePath() << " for Options.xml"; - if (QFile(QDir::toNativeSeparators(path + "/../config/Options.xml")).exists()) { - userPath = QFileInfo(QDir::toNativeSeparators(path + "/../config/Options.xml")).absoluteFilePath(); - break; - } - } + OZWCore::get()->getQTOZWManager()->initilizeSource(OZWCore::get()->settings.value("StartServer").toBool()); + this->m_logWindow.setModel(OZWCore::get()->getQTOZWManager()->getLogModel()); - qCDebug(ozwadmin) << "DBPath: " << dbPath; - qCDebug(ozwadmin) << "userPath: " << userPath; + userValues->setModel(OZWCore::get()->getQTOZWManager()->getValueModel(), this->ntw->selectionModel()); + systemValues->setModel(OZWCore::get()->getQTOZWManager()->getValueModel(), this->ntw->selectionModel()); + configValues->setModel(OZWCore::get()->getQTOZWManager()->getValueModel(), this->ntw->selectionModel()); - if (dbPath.isEmpty()) { - qCInfo(ozwadmin) << "Deploying OZW Database to " << QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).at(0); - QStringList paths; - paths << "." << "../../qt-openzwave/qt-openzwavedatabase/"; - if (!initConfigDatabase(paths)) { - QMessageBox::critical(this, "Missing qt-openzwavedatabase.rcc Database File", "The qt-openzwavedatabase.rcc file could not be found"); - exit(-1); - } - QString dir = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).at(0); - if (copyConfigDatabase(QDir(dir).absolutePath())) { - qCInfo(ozwadmin) << "Copied Database to " << dir; - } - else { - QMessageBox::critical(this, "Missing qt-openzwavedatabase.rcc Database File", "The qt-openzwavedatabase.rcc file could not be found"); - exit(-1); - } - dbPath = QFileInfo(dir.append("/config/")).absolutePath(); - m_configpath.setPath(dbPath); - settings.setValue("openzwave/ConfigPath", m_configpath.absolutePath()); - qCInfo(ozwadmin) << "m_configPath set to " << m_configpath.absolutePath(); - } - else - { - m_configpath.setPath(QFileInfo(dbPath).absolutePath()); - settings.setValue("openzwave/ConfigPath", m_configpath.absolutePath()); - qCInfo(ozwadmin) << "Found Existing DB Path" << m_configpath.absolutePath(); - } - - if (userPath.isEmpty()) { - userPath = dbPath; - m_userpath.setPath(QFileInfo(userPath).absolutePath()); - settings.setValue("openzwave/UserPath", m_userpath.absolutePath()); - qCInfo(ozwadmin) << "UserPath is Set to DBPath: " << m_userpath.absolutePath(); - } - else { - m_userpath.setPath(QFileInfo(userPath).absolutePath()); - qCInfo(ozwadmin) << "UserPath is Set from Settings" << m_userpath.absolutePath(); - settings.setValue("openzwave/UserPath", m_userpath.absolutePath()); - } - - this->m_openzwave = new QTOpenZwave(this, m_configpath, m_userpath); - this->m_qtozwmanager = this->m_openzwave->GetManager(); - this->sbMsg.setQTOZWManager(this->m_qtozwmanager); - QObject::connect(this->m_qtozwmanager, &QTOZWManager::ready, this, &MainWindow::QTOZW_Ready); - - this->m_qtozwmanager->initilizeSource(this->settings.value("StartServer").toBool()); - this->m_logWindow.setModel(this->m_qtozwmanager->getLogModel()); - userValues->setModel(this->m_qtozwmanager->getValueModel(), this->ntw->selectionModel()); - systemValues->setModel(this->m_qtozwmanager->getValueModel(), this->ntw->selectionModel()); - configValues->setModel(this->m_qtozwmanager->getValueModel(), this->ntw->selectionModel()); + di->setQTOZWManager(OZWCore::get()->getQTOZWManager()); + ni->setQTOZWManager(OZWCore::get()->getQTOZWManager()); - - di->setQTOZWManager(this->m_qtozwmanager); - ni->setQTOZWManager(this->m_qtozwmanager); - - SplashDialog *sw = new SplashDialog(this->m_openzwave, this); + SplashDialog *sw = new SplashDialog(OZWCore::get()->getQTOZW(), this); sw->show(); sw->move(this->geometry().center() - sw->rect().center()); @@ -220,32 +148,30 @@ void MainWindow::QTOZW_Ready() { qCDebug(ozwadmin) << "QTOZW Ready"; /* apply our Local Configuration Options to the OZW Options Class */ - settings.beginGroup("openzwave"); - QStringList optionlist = settings.allKeys(); + OZWCore::get()->settings.beginGroup("openzwave"); + QStringList optionlist = OZWCore::get()->settings.allKeys(); for (int i = 0; i < optionlist.size(); i++) { - qCDebug(ozwadmin) << "Updating Option " << optionlist.at(i) << " to " << settings.value(optionlist.at(i)); - QTOZWOptions *ozwoptions = this->m_qtozwmanager->getOptions(); + qCDebug(ozwadmin) << "Updating Option " << optionlist.at(i) << " to " << OZWCore::get()->settings.value(optionlist.at(i)); + QTOZWOptions *ozwoptions = OZWCore::get()->getQTOZWManager()->getOptions(); QStringList listtypes; listtypes << "SaveLogLevel" << "QueueLogLevel" << "DumpLogLevel"; if (listtypes.contains(optionlist.at(i))) { OptionList list = ozwoptions->property(optionlist.at(i).toLocal8Bit()).value(); if (list.getEnums().size() > 0) - list.setSelected(settings.value(optionlist.at(i)).toString()); + list.setSelected(OZWCore::get()->settings.value(optionlist.at(i)).toString()); } else { - ozwoptions->setProperty(optionlist.at(i).toLocal8Bit(), settings.value(optionlist.at(i))); + ozwoptions->setProperty(optionlist.at(i).toLocal8Bit(), OZWCore::get()->settings.value(optionlist.at(i))); } } - settings.endGroup(); + OZWCore::get()->settings.endGroup(); - this->ntw->setModel(this->m_qtozwmanager->getNodeModel()); + this->ntw->setModel(OZWCore::get()->getQTOZWManager()->getNodeModel()); } void MainWindow::OpenConnection() { - - this->ui->actionOpen->setEnabled(false); - this->ui->action_Close->setEnabled(true); + this->connected(true); Startup su(this); su.setModal(true); @@ -261,37 +187,42 @@ void MainWindow::OpenConnection() { qCDebug(ozwadmin) << "Connecting to " << server; startupprogress *sup = new startupprogress(true, this); sup->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); - sup->setQTOZWManager(this->m_qtozwmanager); + sup->setQTOZWManager(OZWCore::get()->getQTOZWManager()); sup->show(); - this->m_qtozwmanager->setClientAuth(su.getauthKey()); - this->m_qtozwmanager->initilizeReplica(server); - this->settings.setValue("connection/remotehost", su.getremoteHost()); - this->settings.setValue("connection/remoteport", su.getremotePort()); - this->settings.setValue("connection/authKey", su.getauthKey()); + OZWCore::get()->getQTOZWManager()->setClientAuth(su.getauthKey()); + OZWCore::get()->getQTOZWManager()->initilizeReplica(server); + OZWCore::get()->settings.setValue("connection/remotehost", su.getremoteHost()); + OZWCore::get()->settings.setValue("connection/remoteport", su.getremotePort()); + OZWCore::get()->settings.setValue("connection/authKey", su.getauthKey()); return; } else { qCDebug(ozwadmin) << "Doing Local Connection: " << su.getserialPort() << su.getstartServer(); - this->m_serialport = su.getserialPort(); startupprogress *sup = new startupprogress(false, this); - sup->setQTOZWManager(this->m_qtozwmanager); + sup->setQTOZWManager(OZWCore::get()->getQTOZWManager()); sup->show(); - this->m_qtozwmanager->open(this->m_serialport); - this->settings.setValue("connection/serialport", su.getserialPort()); - this->settings.setValue("connection/startserver", su.getstartServer()); + OZWCore::get()->getQTOZWManager()->open(su.getserialPort()); + OZWCore::get()->settings.setValue("connection/serialport", su.getserialPort()); + OZWCore::get()->settings.setValue("connection/startserver", su.getstartServer()); return; } } else { qCDebug(ozwadmin) << "Open Dialog was Canceled" << ret; - this->ui->actionOpen->setEnabled(true); - this->ui->action_Close->setEnabled(false); - + this->connected(false); } } 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); + } else { + QMessageBox::critical(this, "Unknown Connection Type", "Unknown Connection Type"); + } + this->connected(false); } @@ -326,7 +257,7 @@ void MainWindow::openMetaDataWindow() { const QAbstractItemModel *model = index.model(); quint8 node = model->data(model->index(index.row(), QTOZW_Nodes::NodeColumns::NodeID)).value(); MetaDataWindow *mdwin = new MetaDataWindow(this); - mdwin->populate(this->m_qtozwmanager, node); + mdwin->populate(OZWCore::get()->getQTOZWManager(), node); mdwin->setModal(true); mdwin->exec(); } @@ -337,12 +268,35 @@ void MainWindow::OpenDeviceDB() { } void MainWindow::openConfigWindow() { - Configuration *cfg = new Configuration(this->m_qtozwmanager->getOptions(), this); + Configuration *cfg = new Configuration(OZWCore::get()->getQTOZWManager()->getOptions(), this); cfg->show(); } void MainWindow::openAboutWindow() { - SplashDialog *sw = new SplashDialog(this->m_openzwave, this); + SplashDialog *sw = new SplashDialog(OZWCore::get()->getQTOZW(), this); sw->show(); sw->move(this->geometry().center() - sw->rect().center()); +} + +QMessageBox::StandardButton MainWindow::openCriticalDialog(QString title, QString msg) { + return QMessageBox::critical(this, title, msg); +} + + +void MainWindow::addNode() { + this->m_controllerCommands->addNode(); +} +void MainWindow::delNode() { + this->m_controllerCommands->delNode(); +} +void MainWindow::healNetwork() { + this->m_controllerCommands->healNetwork(); +} + +void MainWindow::connected(bool connected) { + this->ui->actionOpen->setEnabled(!connected); + this->ui->action_Close->setEnabled(connected); + this->ui->action_AddNode->setEnabled(connected); + this->ui->action_Delete_Node->setEnabled(connected); + this->ui->action_Heal_Network->setEnabled(connected); } \ No newline at end of file diff --git a/ozwadmin-main/mainwindow.h b/ozwadmin-main/mainwindow.h index f3be7c8..4782ff8 100644 --- a/ozwadmin-main/mainwindow.h +++ b/ozwadmin-main/mainwindow.h @@ -23,14 +23,13 @@ #include #include #include - -#include -#include +#include #include "qt-ads/DockManager.h" #include "logwindow.h" #include "statusbarmessages.h" #include "nodetablewidget.h" +#include "controllercommands.h" namespace Ui { class MainWindow; @@ -42,7 +41,6 @@ class MainWindow : public QMainWindow public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); - Q_PROPERTY(QString SerialPort MEMBER m_serialport) public slots: void OpenConnection(); void CloseConnection(); @@ -52,23 +50,23 @@ public slots: void OpenDeviceDB(); void QTOZW_Ready(); void openAboutWindow(); - void openMetaDataWindow(); void openConfigWindow(); - + void addNode(); + void delNode(); + void healNetwork(); + + QMessageBox::StandardButton openCriticalDialog(QString title, QString msg); private: + void connected(bool); + ControllerCommands *m_controllerCommands; + Ui::MainWindow *ui; - QString m_serialport; - QSettings settings; statusBarMessages sbMsg; nodeTableWidget *ntw; - QTOpenZwave *m_openzwave; - QTOZWManager *m_qtozwmanager; LogWindow m_logWindow; - QDir m_configpath; - QDir m_userpath; ads::CDockManager* m_DockManager; }; diff --git a/ozwadmin-main/mainwindow.ui b/ozwadmin-main/mainwindow.ui index 61fa5b6..a120c90 100644 --- a/ozwadmin-main/mainwindow.ui +++ b/ozwadmin-main/mainwindow.ui @@ -68,6 +68,11 @@ + + + + + @@ -93,6 +98,9 @@ + + false + &Device Database @@ -118,6 +126,21 @@ About + + + &Add Node + + + + + &Delete Node + + + + + &Heal Network + + diff --git a/ozwadmin-main/nodetablewidget.cpp b/ozwadmin-main/nodetablewidget.cpp index 6311cb7..1b21e3f 100644 --- a/ozwadmin-main/nodetablewidget.cpp +++ b/ozwadmin-main/nodetablewidget.cpp @@ -1,3 +1,6 @@ + +#include + #include #include @@ -22,6 +25,9 @@ nodeTableWidget::nodeTableWidget(QWidget *parent) : this->ui->nodeList->horizontalHeader()->setSectionsMovable(true); // this->ui->nodeList->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); // this->ui->nodeList->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); + + this->ui->nodeList->setContextMenuPolicy(Qt::CustomContextMenu); + connect(this->ui->nodeList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(rightClickMenu(QPoint))); } nodeTableWidget::~nodeTableWidget() @@ -55,4 +61,15 @@ QModelIndex nodeTableWidget::currentIndex() QItemSelectionModel *nodeTableWidget::selectionModel() { return this->ui->nodeList->selectionModel(); +} + +void nodeTableWidget::rightClickMenu(QPoint pos) +{ + QModelIndex index=this->ui->nodeList->indexAt(pos); + + QMenu *menu=new QMenu(this); + menu->addAction(new QAction("Action 1", this)); + menu->addAction(new QAction("Action 2", this)); + menu->addAction(new QAction("Action 3", this)); + menu->popup(this->ui->nodeList->viewport()->mapToGlobal(pos)); } \ No newline at end of file diff --git a/ozwadmin-main/nodetablewidget.h b/ozwadmin-main/nodetablewidget.h index 5b7e059..e2b3c84 100644 --- a/ozwadmin-main/nodetablewidget.h +++ b/ozwadmin-main/nodetablewidget.h @@ -2,6 +2,7 @@ #define NODETABLEWIDGET_H #include +#include #include #include @@ -22,6 +23,8 @@ class nodeTableWidget : public QWidget QItemSelectionModel *selectionModel(); Q_SIGNALS: void currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous); +public Q_SLOTS: + void rightClickMenu(QPoint pos); private: Ui::nodeTableWidget *ui; }; diff --git a/ozwadmin-main/ozwadmin-main.pro b/ozwadmin-main/ozwadmin-main.pro index 7a6eb7d..78f1cac 100644 --- a/ozwadmin-main/ozwadmin-main.pro +++ b/ozwadmin-main/ozwadmin-main.pro @@ -20,6 +20,7 @@ DEFINES +=APP_VERSION=$$VERSION SOURCES += main.cpp\ configuration.cpp \ + controllercommands.cpp \ deviceinfo.cpp \ logwindow.cpp \ mainwindow.cpp \ @@ -36,6 +37,7 @@ SOURCES += main.cpp\ HEADERS += mainwindow.h \ configuration.h \ + controllercommands.h \ deviceinfo.h \ logwindow.h \ metadatawindow.h \ diff --git a/ozwadmin-main/ozwcore.cpp b/ozwadmin-main/ozwcore.cpp index 38245b9..fd7699a 100644 --- a/ozwadmin-main/ozwcore.cpp +++ b/ozwadmin-main/ozwcore.cpp @@ -1,11 +1,16 @@ #include +#include + +#include + #include "ozwcore.h" +#include "util.h" Q_GLOBAL_STATIC(OZWCore, globalState) -OZWCore::OZWCore(QObject *parent) : QObject(parent) +OZWCore::OZWCore(QObject *parent) : + QObject(parent) { - qDebug() << "Created"; } OZWCore *OZWCore::get() { @@ -14,5 +19,92 @@ OZWCore *OZWCore::get() { void OZWCore::initilize() { + QStringList PossibleDBPaths; + PossibleDBPaths << settings.value("openzwave/ConfigPath", QDir::toNativeSeparators("../../../config/")).toString().append("/"); + PossibleDBPaths << QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); + + QString path, dbPath, userPath; + foreach(path, PossibleDBPaths) { + qCDebug(ozwadmin) << "Checking " << QFileInfo(QDir::toNativeSeparators(path + "/config/manufacturer_specific.xml")).absoluteFilePath() << " for manufacturer_specific.xml"; + if (QFileInfo(QDir::toNativeSeparators(path + "/config/manufacturer_specific.xml")).exists()) { + dbPath = QFileInfo(QDir::toNativeSeparators(path + "/config/manufacturer_specific.xml")).absoluteFilePath(); + break; + } + qCDebug(ozwadmin) << "Checking " << QFileInfo(QDir::toNativeSeparators(path + "../config/manufacturer_specific.xml")).absoluteFilePath() << " for manufacturer_specific.xml"; + if (QFile(QDir::toNativeSeparators(path + "/../config/manufacturer_specific.xml")).exists()) { + dbPath = QFileInfo(QDir::toNativeSeparators(path + "/../config/manufacturer_specific.xml")).absoluteFilePath(); + break; + } + } + PossibleDBPaths.clear(); + PossibleDBPaths << settings.value("openzwave/UserPath", QDir::toNativeSeparators("../../../config/")).toString().append("/"); + PossibleDBPaths << QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); + + foreach(path, PossibleDBPaths) { + qCDebug(ozwadmin) << "Checking " << QFileInfo(QDir::toNativeSeparators(path + "/config/Options.xml")).absoluteFilePath() << " for Options.xml"; + if (QFileInfo(QDir::toNativeSeparators(path + "/config/Options.xml")).exists()) { + userPath = QFileInfo(QDir::toNativeSeparators(path + "/config/Options.xml")).absoluteFilePath(); + break; + } + qCDebug(ozwadmin) << "Checking " << QFileInfo(QDir::toNativeSeparators(path + "/../config/Options.xml")).absoluteFilePath() << " for Options.xml"; + if (QFile(QDir::toNativeSeparators(path + "/../config/Options.xml")).exists()) { + userPath = QFileInfo(QDir::toNativeSeparators(path + "/../config/Options.xml")).absoluteFilePath(); + break; + } + } + + qCDebug(ozwadmin) << "DBPath: " << dbPath; + qCDebug(ozwadmin) << "userPath: " << userPath; + + if (dbPath.isEmpty()) { + qCInfo(ozwadmin) << "Deploying OZW Database to " << QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).at(0); + QStringList paths; + paths << "." << "../../qt-openzwave/qt-openzwavedatabase/"; + if (!initConfigDatabase(paths)) { + qCWarning(ozwadmin) << "The qt-openzwavedatabase.rcc file could not be found"; + emit raiseCriticalError("Missing qt-openzwavedatabase.rcc Database File", "The qt-openzwavedatabase.rcc file could not be found"); + exit(-1); + } + QString dir = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).at(0); + if (copyConfigDatabase(QDir(dir).absolutePath())) { + qCInfo(ozwadmin) << "Copied Database to " << dir; + } + else { + qCWarning(ozwadmin) << "Copying Config Database Failed"; + emit raiseCriticalError("Copying Config Database Failed", "Copying Config Database Failed"); + exit(-1); + } + dbPath = QFileInfo(dir.append("/config/")).absolutePath(); + m_configpath.setPath(dbPath); + settings.setValue("openzwave/ConfigPath", m_configpath.absolutePath()); + qCInfo(ozwadmin) << "m_configPath set to " << m_configpath.absolutePath(); + } + else + { + m_configpath.setPath(QFileInfo(dbPath).absolutePath()); + settings.setValue("openzwave/ConfigPath", m_configpath.absolutePath()); + qCInfo(ozwadmin) << "Found Existing DB Path" << m_configpath.absolutePath(); + } -} \ No newline at end of file + if (userPath.isEmpty()) { + userPath = dbPath; + m_userpath.setPath(QFileInfo(userPath).absolutePath()); + settings.setValue("openzwave/UserPath", m_userpath.absolutePath()); + qCInfo(ozwadmin) << "UserPath is Set to DBPath: " << m_userpath.absolutePath(); + } + else { + m_userpath.setPath(QFileInfo(userPath).absolutePath()); + qCInfo(ozwadmin) << "UserPath is Set from Settings" << m_userpath.absolutePath(); + settings.setValue("openzwave/UserPath", m_userpath.absolutePath()); + } + + this->m_openzwave = new QTOpenZwave(this, m_configpath, m_userpath); + this->m_qtozwmanager = this->m_openzwave->GetManager(); +} + +QTOpenZwave *OZWCore::getQTOZW() { + return this->m_openzwave; +} +QTOZWManager *OZWCore::getQTOZWManager() { + return this->m_qtozwmanager; +} diff --git a/ozwadmin-main/ozwcore.h b/ozwadmin-main/ozwcore.h index 0f054d5..92fdb63 100644 --- a/ozwadmin-main/ozwcore.h +++ b/ozwadmin-main/ozwcore.h @@ -2,6 +2,13 @@ #define OZWCORE_H #include +#include +#include +#include + +#include "controllercommands.h" + +class ControllerCommands; class OZWCore : public QObject { @@ -10,9 +17,20 @@ class OZWCore : public QObject explicit OZWCore(QObject *parent = nullptr); static OZWCore *get(); void initilize(); -signals: + QTOpenZwave *getQTOZW(); + QTOZWManager *getQTOZWManager(); + QSettings settings; +signals: + QMessageBox::StandardButton raiseCriticalError(QString title, QString message); public slots: + +private: + QTOpenZwave *m_openzwave; + QTOZWManager *m_qtozwmanager; + QString m_serialport; + QDir m_configpath; + QDir m_userpath; };