Skip to content

Commit 8a3b527

Browse files
committed
Command Line Connections, and a few fixes here and there
1 parent fafd196 commit 8a3b527

16 files changed

+205
-60
lines changed

ozw-admin.pri

+15-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ unix {
66
}
77
!macx: QMAKE_CXXFLAGS += -Wno-deprecated-copy
88
}
9+
emscripten: {
10+
QMAKE_CXXFLAGS += -Wno-deprecated-copy
11+
QMAKE_LFLAGS += -g --source-map-base "http://localhost:8000/"
12+
}
913

1014
unix {
1115
CONFIG-= no-pkg-config
@@ -39,7 +43,11 @@ unix {
3943
message(" OpenZWave Database Path: $$OZW_DATABASE_PATH")
4044
message(" ")
4145
INCLUDEPATH+=$$OZW_INCLUDE_PATH
42-
LIBS+=$$OZW_LIBS
46+
!emscripten {
47+
LIBS+=$$OZW_LIBS
48+
} else {
49+
message(" Not Adding libopenzwave to LIBS")
50+
}
4351
} else {
4452
exists( $$top_srcdir/../open-zwave/cpp/src/) {
4553
message("Found OZW in $$absolute_path($$top_srcdir/../open-zwave/)")
@@ -56,7 +64,11 @@ unix {
5664
message(" OpenZWave Database Path: $$OZW_DATABASE_PATH")
5765
message(" ")
5866
INCLUDEPATH+=$$OZW_INCLUDE_PATH
59-
LIBS+=$$OZW_LIBS
67+
!emscripten {
68+
LIBS+=$$OZW_LIBS
69+
} else {
70+
message(" Not Adding libopenzwave to LIBS")
71+
}
6072
} else {
6173
packagesExist("libopenzwave") {
6274
PKGCONFIG += libopenzwave
@@ -72,7 +84,7 @@ unix {
7284
error("Can't find OpenZWave Library and Headers");
7385
}
7486
}
75-
}
87+
}
7688

7789
!isEmpty(QTOZW_LIB_PATH) {
7890
!exists($$QTOZW_LIB_PATH/qt-openzwave/libqt-openzwave.so): error("Can't find libqt-openzwave.so")

ozwadmin-main/eventwindow.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44

55
#include "eventwindow.h"
66
#include "ui_eventwindow.h"
7+
#include "util.h"
78

89

910
EventWindow::EventWindow(QWidget *parent) :
1011
QWidget(parent),
1112
ui(new Ui::EventWindow)
1213
{
1314
ui->setupUi(this);
15+
ui->eventTable->verticalHeader()->hide();
1416
ui->eventTable->horizontalHeader()->setStretchLastSection(true);
1517
ui->eventTable->setHorizontalHeaderItem(0, new QTableWidgetItem("Time"));
1618
ui->eventTable->setHorizontalHeaderItem(1, new QTableWidgetItem("Message"));
1719
ui->eventTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
20+
ui->eventTable->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
1821

1922
}
2023

ozwadmin-main/logwindow.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LogWindow::LogWindow(QWidget *parent) :
1111
this->ui->logview->verticalHeader()->hide();
1212
this->ui->logview->horizontalHeader()->setStretchLastSection(true);
1313
this->ui->logview->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
14-
// this->ui->val_system_tbl->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
14+
this->ui->logview->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
1515
// this->ui->logview->resizeColumnsToContents();
1616

1717

ozwadmin-main/logwindow.ui

+17
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,29 @@
22
<ui version="4.0">
33
<class>LogWindow</class>
44
<widget class="QWidget" name="LogWindow">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>280</width>
10+
<height>216</height>
11+
</rect>
12+
</property>
513
<property name="windowTitle">
614
<string>OZW Log</string>
715
</property>
816
<layout class="QVBoxLayout" name="verticalLayout">
917
<item>
1018
<widget class="QTableView" name="logview">
19+
<property name="font">
20+
<font>
21+
<pointsize>8</pointsize>
22+
</font>
23+
</property>
24+
<property name="styleSheet">
25+
<string notr="true">QTableWidget::item { padding: 0px }
26+
QHeaderView::section:horizontal {margin-right: 2; border: 1px solid}</string>
27+
</property>
1128
<property name="frameShape">
1229
<enum>QFrame::NoFrame</enum>
1330
</property>

ozwadmin-main/main.cpp

+40-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int main(int argc, char *argv[])
4141

4242
#if 1
4343
QLoggingCategory::setFilterRules("*.debug=false\n"
44-
"qt.remoteobjects.debug=false\n"
44+
"qt.remoteobjects.debug=true\n"
4545
"qt.remoteobjects.warning=true\n"
4646
"ozw.*.debug=true\n"
4747
"ozw.library.debug=false\n"
@@ -56,7 +56,46 @@ int main(int argc, char *argv[])
5656
QCoreApplication::setApplicationVersion(DEF2STR(APP_VERSION));
5757
QApplication a(argc, argv);
5858

59+
60+
QCommandLineParser parser;
61+
parser.setApplicationDescription("OpenZWave Admin GUI");
62+
parser.addHelpOption();
63+
parser.addVersionOption();
64+
65+
QCommandLineOption serialPort(QStringList() << "s" << "serial-port",
66+
"AutoStart connecting to the Specified Serial Port of the USB Stick",
67+
"serialPort"
68+
);
69+
parser.addOption(serialPort);
70+
71+
QCommandLineOption remoteHost(QStringList() << "host",
72+
"AutoStart connecting to the Specified Remote Host/Port (1983 is default port)",
73+
"host:port"
74+
);
75+
parser.addOption(remoteHost);
76+
77+
QCommandLineOption remoteKey(QStringList() << "password",
78+
"Remote Host Password (optional)",
79+
"password"
80+
);
81+
parser.addOption(remoteKey);
82+
83+
84+
parser.process(a);
85+
5986
MainWindow w;
6087
w.show();
88+
if (parser.isSet(serialPort)) {
89+
w.connectToLocal(parser.value(serialPort));
90+
} else if (parser.isSet(remoteHost)) {
91+
QString key;
92+
if (parser.isSet(remoteKey)) {
93+
key = parser.value(remoteKey);
94+
}
95+
QUrl server = QUrl::fromUserInput(parser.value(remoteHost), "");
96+
server.setScheme("ws");
97+
w.connectToRemote(server, key);
98+
}
99+
61100
return a.exec();
62101
}

ozwadmin-main/mainwindow.cpp

+28-22
Original file line numberDiff line numberDiff line change
@@ -193,41 +193,24 @@ void MainWindow::openDefaultWindows() {
193193
}
194194

195195
void MainWindow::OpenConnection() {
196-
this->connected(true);
197196

198197
Startup su(this);
199198
su.setModal(true);
200199
int ret = su.exec();
201200
if (ret == QDialog::Accepted) {
202201

203202
if (su.getremote() == true) {
204-
qCDebug(ozwadmin) << "Doing Remote Connection:" << su.getremoteHost() << su.getremotePort();
205203
QUrl server;
206204
server.setHost(su.getremoteHost());
207205
server.setPort(su.getremotePort());
208206
server.setScheme("ws");
209-
qCDebug(ozwadmin) << "Connecting to " << server;
210-
startupprogress *sup = new startupprogress(true, this);
211-
sup->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
212-
sup->setQTOZWManager(OZWCore::get()->getQTOZWManager());
213-
sup->show();
214-
OZWCore::get()->getQTOZWManager()->setClientAuth(su.getauthKey());
215-
OZWCore::get()->getQTOZWManager()->initilizeReplica(server);
216-
OZWCore::get()->settings.setValue("connection/remotehost", su.getremoteHost());
217-
OZWCore::get()->settings.setValue("connection/remoteport", su.getremotePort());
218-
OZWCore::get()->settings.setValue("connection/authKey", su.getauthKey());
207+
connectToRemote(server, su.getauthKey());
219208
return;
220209
}
221210
else
222211
{
223-
qCDebug(ozwadmin) << "Doing Local Connection: " << su.getserialPort() << su.getstartServer();
224-
startupprogress *sup = new startupprogress(false, this);
225-
sup->setQTOZWManager(OZWCore::get()->getQTOZWManager());
226-
sup->show();
227-
OZWCore::get()->getQTOZWManager()->initilizeSource(OZWCore::get()->settings.value("StartServer").toBool());
228-
OZWCore::get()->getQTOZWManager()->open(su.getserialPort());
229-
OZWCore::get()->settings.setValue("connection/serialport", su.getserialPort());
230212
OZWCore::get()->settings.setValue("connection/startserver", su.getstartServer());
213+
connectToLocal(su.getserialPort());
231214
return;
232215
}
233216
} else {
@@ -236,6 +219,29 @@ void MainWindow::OpenConnection() {
236219
}
237220

238221
}
222+
223+
void MainWindow::connectToLocal(QString serial) {
224+
this->connected(true);
225+
OZWCore::get()->settings.setValue("connection/serialport", serial);
226+
qCDebug(ozwadmin) << "Doing Local Connection: " << serial << OZWCore::get()->settings.value("StartServer").toBool();
227+
startupprogress *sup = new startupprogress(false, this);
228+
sup->show();
229+
OZWCore::get()->getQTOZWManager()->initilizeSource(OZWCore::get()->settings.value("connection/startserver").toBool());
230+
OZWCore::get()->getQTOZWManager()->open(serial);
231+
}
232+
233+
void MainWindow::connectToRemote(QUrl server, QString key) {
234+
this->connected(true);
235+
OZWCore::get()->settings.setValue("connection/remotehost", server);
236+
OZWCore::get()->settings.setValue("connection/authKey", key);
237+
qCDebug(ozwadmin) << "Doing Remote Connection:" << server;
238+
startupprogress *sup = new startupprogress(true, this);
239+
sup->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
240+
sup->show();
241+
OZWCore::get()->getQTOZWManager()->setClientAuth(key);
242+
OZWCore::get()->getQTOZWManager()->initilizeReplica(server);
243+
}
244+
239245
void MainWindow::CloseConnection() {
240246
if (OZWCore::get()->getQTOZWManager()->getConnectionType() == QTOZWManager::connectionType::Local) {
241247
OZWCore::get()->getQTOZWManager()->close();
@@ -325,13 +331,13 @@ void MainWindow::setStatusBarMsg(QString Msg) {
325331
}
326332

327333
void MainWindow::remoteConnectionStatus(QTOZWManager::connectionStatus status, QAbstractSocket::SocketError error) {
328-
Q_UNUSED(error);
334+
qCDebug(ozwadmin) << "Remote Connection Status: " << status << error;
329335
if (status == QTOZWManager::connectionStatus::ConnectionErrorState) {
330-
openCriticalDialog("Connection Error", "Connection Error");
336+
QString errorstr("Connection Error: %1");
337+
openCriticalDialog("Connection Error", errorstr.arg(SockErrorToString(error)));
331338
CloseConnection();
332339
} else if (status == QTOZWManager::connectionStatus::VersionMisMatchError) {
333340
openCriticalDialog("Version MisMatch", "The ozwdaemon version is not compatible with this version of ozw-admin");
334341
CloseConnection();
335342
}
336-
337343
}

ozwadmin-main/mainwindow.h

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class MainWindow : public QMainWindow
4141
public:
4242
explicit MainWindow(QWidget *parent = nullptr);
4343
~MainWindow();
44+
void connectToLocal(QString serial);
45+
void connectToRemote(QUrl server, QString key);
4446
public slots:
4547
void OpenConnection();
4648
void CloseConnection();

ozwadmin-main/nodetablewidget.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,9 @@ void nodeTableWidget::rightClickMenu(QPoint pos)
7878

7979
void nodeTableWidget::resizeContents() {
8080
this->ui->nodeList->resizeColumnsToContents();
81+
if (!this->ui->nodeList->selectionModel()->hasSelection()) {
82+
if (this->ui->nodeList->model()->rowCount() > 0) {
83+
this->ui->nodeList->selectRow(0);
84+
}
85+
}
8186
}

ozwadmin-main/ozwadmin-main.pro

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#-------------------------------------------------
66

77
QT += core gui widgets xml remoteobjects websockets svg
8-
#CONFIG += silent
8+
CONFIG += silent
99

1010
TARGET = ../ozwadmin
1111
TEMPLATE = app
@@ -90,7 +90,6 @@ windows {
9090

9191
INCLUDEPATH += ../devicedb-lib ../ozwadmin-widgets
9292

93-
9493
macx: {
9594
LIBS += -framework IOKit -framework CoreFoundation
9695
BUNDLE.files = $$OZW_LIB_PATH/libopenzwave-1.6.dylib $$QTOZW_LIB_PATH/libqt-openzwave.1.dylib $$QTOZW_LIB_PATH/../qt-openzwavedatabase/libqt-openzwavedatabase.1.dylib

ozwadmin-main/ozwcore.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ OZWCore *OZWCore::get() {
1919

2020

2121
void OZWCore::initilize() {
22+
#ifndef Q_OS_WASM
2223
QStringList PossibleDBPaths;
2324
PossibleDBPaths << settings.value("openzwave/ConfigPath", QDir::toNativeSeparators("../../../config/")).toString().append("/");
2425
PossibleDBPaths << QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
@@ -97,7 +98,10 @@ void OZWCore::initilize() {
9798
qCInfo(ozwadmin) << "UserPath is Set from Settings" << m_userpath.absolutePath();
9899
settings.setValue("openzwave/UserPath", m_userpath.absolutePath());
99100
}
100-
101+
#else
102+
m_configpath = ".";
103+
m_userpath = ".";
104+
#endif
101105
this->m_openzwave = new QTOpenZwave(this, m_configpath, m_userpath);
102106
this->m_qtozwmanager = this->m_openzwave->GetManager();
103107
}

ozwadmin-main/startup.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#include <QMessageBox>
22
#include <QIntValidator>
33
#include <QSettings>
4+
#include <QUrl>
5+
#include <QDebug>
46

57
#include "startup.h"
68
#include "ui_startup.h"
7-
9+
#include "ozwcore.h"
810

911
Startup::Startup(QWidget *parent) :
1012
QDialog(parent),
@@ -17,18 +19,19 @@ Startup::Startup(QWidget *parent) :
1719
ui->remoteport->setMaximumWidth(w+8);
1820
QObject::connect(ui->startlocal, &QPushButton::clicked, this, &Startup::localPressed);
1921
QObject::connect(ui->startremote, &QPushButton::clicked, this, &Startup::remotePressed);
20-
QSettings settings;
2122
#if defined(Q_OS_MACOS)
22-
ui->serialport->setText(settings.value("connection/serialport", "/dev/cu.SLAB_USBtoUART").toString());
23+
ui->serialport->setText(OZWCore::get()->settings.value("connection/serialport", "/dev/cu.SLAB_USBtoUART").toString());
2324
#elif defined(Q_OS_WIN)
24-
ui->serialport->setText(settings.value("connection/serialport", "COM1").toString());
25+
ui->serialport->setText(OZWCore::get()->settings.value("connection/serialport", "COM1").toString());
2526
#else
26-
ui->serialport->setText(settings.value("connection/serialport", "/dev/ttyUSB0").toString());
27+
ui->serialport->setText(OZWCore::get()->settings.value("connection/serialport", "/dev/ttyUSB0").toString());
2728
#endif
28-
ui->enableserver->setChecked(settings.value("connection/startserver", true).toBool());
29-
ui->remotehost->setText(settings.value("connection/remotehost", "localhost").toString());
30-
ui->remoteport->setText(settings.value("connection/remoteport", "1983").toString());
31-
ui->authKey->setText(settings.value("connection/authKey", "").toString());
29+
ui->enableserver->setChecked(OZWCore::get()->settings.value("connection/startserver", true).toBool());
30+
QUrl server = QUrl::fromUserInput(OZWCore::get()->settings.value("connection/remotehost", "ws://localhost:1983").toString());
31+
qDebug() << server;
32+
ui->remotehost->setText(server.host());
33+
ui->remoteport->setText(QString::number(server.port()));
34+
ui->authKey->setText(OZWCore::get()->settings.value("connection/authKey", "").toString());
3235
}
3336

3437
Startup::~Startup()

0 commit comments

Comments
 (0)