1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-22 18:34:25 +01:00
doorlockd-mirror/doorlockd/client/mainwindow.cpp

76 lines
1.9 KiB
C++
Raw Normal View History

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),
ui(new Ui::MainWindow),
_soundLock(Wave::fromFile(SOUND_LOCK)),
_soundUnlock(Wave::fromFile(SOUND_UNLOCK)),
_soundEmergencyUnlock(Wave::fromFile(SOUND_EMERGENCY_UNLOCK)),
_soundZonk(Wave::fromFile(SOUND_ZONK)),
_soundLockButton(Wave::fromFile(SOUND_LOCK_BUTTON)),
_soundUnlockButton(Wave::fromFile(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
{
2015-10-02 19:39:47 +02:00
ui->qrwidget->setQRData(msg.token());
ui->tokenLabel->setText(QString::fromStdString(msg.token()));
2015-10-11 19:54:42 +02:00
QString statusMessage("");
2015-10-05 23:59:18 +02:00
const auto &doormsg = msg.doormessage();
2015-10-06 00:22:35 +02:00
_LED(msg.isOpen());
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!";
_soundLock.playAsync();
} else if (!_oldMessage.isOpen() && msg.isOpen()) {
// regular open
2015-10-11 19:54:42 +02:00
statusMessage = "Come in! Happy hacking!";
_soundUnlock.playAsync();
} else {
// no change
}
if (doormsg.isEmergencyUnlock) {
_soundEmergencyUnlock.playAsync();
2015-10-11 19:54:42 +02:00
statusMessage = "!! EMERGENCY UNLOCK !!";
} else if (doormsg.isLockButton) {
_soundLockButton.playAsync();
2015-10-11 19:54:42 +02:00
statusMessage = "!! LOCK BUTTON !!";
} else if (doormsg.isUnlockButton) {
2015-10-11 19:54:42 +02:00
statusMessage = "!! UNLOCK BUTTON !!";
if (msg.isOpen()) {
_soundZonk.playAsync();
} else {
_soundUnlockButton.playAsync();
}
}
2015-10-11 19:54:42 +02:00
ui->message->setText(statusMessage);
_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
}