1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-10-31 22:47:05 +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(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
{
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
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
}