2015-10-05 23:59:18 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2015-09-30 15:26:28 +02:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent) :
|
|
|
|
QWidget(parent),
|
2015-10-11 19:33:19 +02:00
|
|
|
ui(new Ui::MainWindow),
|
2016-04-24 22:02:49 +02:00
|
|
|
_soundLock(Wave(SOUND_LOCK)),
|
|
|
|
_soundUnlock(Wave(SOUND_UNLOCK)),
|
|
|
|
_soundEmergencyUnlock(Wave(SOUND_EMERGENCY_UNLOCK)),
|
|
|
|
_soundZonk(Wave(SOUND_ZONK)),
|
|
|
|
_soundLockButton(Wave(SOUND_LOCK_BUTTON)),
|
|
|
|
_soundUnlockButton(Wave(SOUND_UNLOCK_BUTTON))
|
2015-09-30 15:26:28 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2015-10-06 00:22:35 +02:00
|
|
|
_LED(false);
|
2015-09-30 15:26:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2015-10-02 19:39:47 +02:00
|
|
|
void MainWindow::setClientmessage(const Clientmessage &msg)
|
2015-09-30 15:26:28 +02:00
|
|
|
{
|
2016-07-17 22:44:02 +02:00
|
|
|
ui->qrwidget->setQRData(msg.web_address());
|
|
|
|
ui->address->setText(QString::fromStdString(msg.web_address()));
|
2015-10-11 19:54:42 +02:00
|
|
|
QString statusMessage("");
|
2015-10-05 23:59:18 +02:00
|
|
|
|
2015-10-07 17:42:52 +02:00
|
|
|
const auto &doormsg = msg.doormessage();
|
|
|
|
|
2015-10-06 00:22:35 +02:00
|
|
|
_LED(msg.isOpen());
|
2015-10-07 17:42:52 +02:00
|
|
|
|
2015-10-11 19:38:06 +02:00
|
|
|
if (_oldMessage.isOpen()
|
|
|
|
&& !msg.isOpen()
|
|
|
|
&& !doormsg.isLockButton) {
|
2015-10-11 19:54:42 +02:00
|
|
|
// regular close
|
|
|
|
statusMessage = "Bye bye. See you next time!";
|
2015-10-11 19:33:19 +02:00
|
|
|
_soundLock.playAsync();
|
2015-10-07 17:42:52 +02:00
|
|
|
} else if (!_oldMessage.isOpen() && msg.isOpen()) {
|
|
|
|
// regular open
|
2015-10-11 19:54:42 +02:00
|
|
|
statusMessage = "Come in! Happy hacking!";
|
2015-10-11 19:33:19 +02:00
|
|
|
_soundUnlock.playAsync();
|
2015-10-07 17:42:52 +02:00
|
|
|
} else {
|
|
|
|
// no change
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doormsg.isEmergencyUnlock) {
|
2015-10-11 19:33:19 +02:00
|
|
|
_soundEmergencyUnlock.playAsync();
|
2015-10-11 19:54:42 +02:00
|
|
|
statusMessage = "!! EMERGENCY UNLOCK !!";
|
2015-10-07 17:42:52 +02:00
|
|
|
} else if (doormsg.isLockButton) {
|
2015-10-11 19:33:19 +02:00
|
|
|
_soundLockButton.playAsync();
|
2015-10-11 19:54:42 +02:00
|
|
|
statusMessage = "!! LOCK BUTTON !!";
|
2015-10-07 17:42:52 +02:00
|
|
|
} else if (doormsg.isUnlockButton) {
|
2015-10-11 19:54:42 +02:00
|
|
|
statusMessage = "!! UNLOCK BUTTON !!";
|
2015-10-07 17:42:52 +02:00
|
|
|
if (msg.isOpen()) {
|
2015-10-11 19:33:19 +02:00
|
|
|
_soundZonk.playAsync();
|
2015-10-07 17:42:52 +02:00
|
|
|
} else {
|
2015-10-11 19:33:19 +02:00
|
|
|
_soundUnlockButton.playAsync();
|
2015-10-07 17:42:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-11 19:54:42 +02:00
|
|
|
ui->message->setText(statusMessage);
|
|
|
|
|
2015-10-07 17:42:52 +02:00
|
|
|
_oldMessage = msg;
|
2015-10-05 23:59:18 +02:00
|
|
|
}
|
|
|
|
|
2015-10-06 00:22:35 +02:00
|
|
|
void MainWindow::_LED(const bool on)
|
2015-10-05 23:59:18 +02:00
|
|
|
{
|
|
|
|
if (on)
|
2015-10-07 17:44:45 +02:00
|
|
|
ui->LED->setPixmap(QPixmap(IMAGE_LED_GREEN));
|
2015-10-05 23:59:18 +02:00
|
|
|
else
|
2015-10-07 17:44:45 +02:00
|
|
|
ui->LED->setPixmap(QPixmap(IMAGE_LED_RED));
|
2015-09-30 15:26:28 +02:00
|
|
|
}
|