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"
|
|
|
|
|
2015-10-07 17:42:52 +02:00
|
|
|
#define PLAY(file) \
|
|
|
|
system("play -q " file " &")
|
|
|
|
|
2015-09-30 15:26:28 +02:00
|
|
|
MainWindow::MainWindow(QWidget *parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
ui(new Ui::MainWindow)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2015-10-05 23:59:18 +02:00
|
|
|
|
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
|
|
|
{
|
2015-10-02 19:39:47 +02:00
|
|
|
ui->qrwidget->setQRData(msg.token());
|
|
|
|
ui->tokenLabel->setText(QString::fromStdString(msg.token()));
|
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
|
|
|
|
|
|
|
if (_oldMessage.isOpen() && !msg.isOpen()) {
|
|
|
|
// regular close
|
|
|
|
PLAY(SOUND_LOCK);
|
|
|
|
} else if (!_oldMessage.isOpen() && msg.isOpen()) {
|
|
|
|
// regular open
|
|
|
|
PLAY(SOUND_UNLOCK);
|
|
|
|
} else {
|
|
|
|
// no change
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doormsg.isEmergencyUnlock) {
|
|
|
|
PLAY(SOUND_EMERGENCY_UNLOCK);
|
|
|
|
} else if (doormsg.isLockButton) {
|
|
|
|
PLAY(SOUND_LOCK_BUTTON);
|
|
|
|
} else if (doormsg.isUnlockButton) {
|
|
|
|
if (msg.isOpen()) {
|
|
|
|
PLAY(SOUND_ZONK);
|
|
|
|
} else {
|
|
|
|
PLAY(SOUND_UNLOCK_BUTTON);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_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
|
|
|
}
|