- some fixes

- new icons
- German translation
- tooltip with number on brightness slider
This commit is contained in:
Dorian Zedler 2020-10-18 01:39:59 +02:00
parent a5521d5bb2
commit 66e5229da0
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
14 changed files with 72 additions and 22 deletions

@ -1 +1 @@
Subproject commit 76e457593e889885fd410fdbcdd659706a1eceb8 Subproject commit 6ad924f42634aa71df54b53f7de98394ad2ce298

View file

@ -3,6 +3,7 @@
#include <QQuickStyle> #include <QQuickStyle>
#include <qbluetoothleuartclient.h> #include <qbluetoothleuartclient.h>
#include <QTranslator> #include <QTranslator>
#include <QFontDatabase>
#include "omobidisplaybackend.h" #include "omobidisplaybackend.h"
#include "omobidisplaytextmodel.h" #include "omobidisplaytextmodel.h"
@ -11,11 +12,14 @@ int main(int argc, char *argv[])
{ {
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setOrganizationName("Itsblue");
QCoreApplication::setOrganizationDomain("itsblue.de");
QCoreApplication::setApplicationName("Itsblue smart display");
QGuiApplication app(argc, argv); QGuiApplication app(argc, argv);
QTranslator translator; QTranslator translator;
translator.load(":/" + QLocale::system().name() + ".qm"); translator.load(":/" + QLocale::system().name() + ".qm");
translator.load(":/de.qm");
app.installTranslator(&translator); app.installTranslator(&translator);
qmlRegisterType<OmobiDisplayBackend>("de.itsblue.omobidisplayapp", 1, 0, "OmobiDisplayBackend"); qmlRegisterType<OmobiDisplayBackend>("de.itsblue.omobidisplayapp", 1, 0, "OmobiDisplayBackend");

View file

@ -9,6 +9,8 @@ OmobiDisplayBackend::OmobiDisplayBackend(QObject *parent) : QObject(parent)
this->displayBrightness = -1; this->displayBrightness = -1;
this->waitingCommands = 0; this->waitingCommands = 0;
this->settings = new QSettings();
this->keepAliveTimer = new QTimer(this); this->keepAliveTimer = new QTimer(this);
this->keepAliveTimer->setInterval(5000); this->keepAliveTimer->setInterval(5000);
this->keepAliveTimer->setSingleShot(false); this->keepAliveTimer->setSingleShot(false);
@ -34,10 +36,15 @@ void OmobiDisplayBackend::startScanning() {
void OmobiDisplayBackend::authenticate(QString code) { void OmobiDisplayBackend::authenticate(QString code) {
// tell display to send over existing model data // tell display to send over existing model data
this->setState(Authenticating); this->setState(Authenticating);
QString combinedCode = this->bleClient->getCurrentDevice()->getAddress().toUpper() + code;
QString secret = QCryptographicHash::hash(combinedCode.toUtf8(), QCryptographicHash::Sha256).toHex();
this->sendBluetoothCommand(AuthorizeSessionCommand, QVariantMap{{"secret", secret}}); if(code.length() == 64)
this->lastDisplaySecret = code;
else if(code.length() == 4) {
QString combinedCode = this->bleClient->getCurrentDevice()->getAddress().toUpper() + code;
this->lastDisplaySecret = QCryptographicHash::hash(combinedCode.toUtf8(), QCryptographicHash::Sha256).toHex();
}
this->sendBluetoothCommand(AuthenticateCommand, QVariantMap{{"secret", this->lastDisplaySecret}});
} }
void OmobiDisplayBackend::handleBluetoothStateChange(QBluetoothLeUartClient::BluetoothLeUartClientState state){ void OmobiDisplayBackend::handleBluetoothStateChange(QBluetoothLeUartClient::BluetoothLeUartClientState state){
@ -79,9 +86,10 @@ void OmobiDisplayBackend::handleBluetoothStateChange(QBluetoothLeUartClient::Blu
} }
void OmobiDisplayBackend::handleBluetoothDeviceConected() { void OmobiDisplayBackend::handleBluetoothDeviceConected() {
if(this->settings->contains(this->bleClient->getCurrentDevice()->getAddress()))
this->authenticate(this->settings->value(this->bleClient->getCurrentDevice()->getAddress()).toString());
else
this->setState(AuthenticationRequired); this->setState(AuthenticationRequired);
this->authenticate("1234");
// TODO: stuff
} }
void OmobiDisplayBackend::handleFoundNewDevice(QBluetoothLeUartDevice* device) { void OmobiDisplayBackend::handleFoundNewDevice(QBluetoothLeUartDevice* device) {
@ -118,7 +126,7 @@ void OmobiDisplayBackend::sendBluetoothCommand(OmobiDisplayCommand command, QVar
QJsonDocument doc = QJsonDocument::fromVariant(commandMap); QJsonDocument doc = QJsonDocument::fromVariant(commandMap);
qDebug() << "Sending command: \n" << qPrintable(doc.toJson(QJsonDocument::Indented)); //qDebug() << "Sending command: \n" << qPrintable(doc.toJson(QJsonDocument::Indented));
this->waitingCommands ++; this->waitingCommands ++;
@ -131,13 +139,13 @@ void OmobiDisplayBackend::sendBluetoothCommand(OmobiDisplayCommand command, QVar
void OmobiDisplayBackend::sendBluetoothKeepAlive() { void OmobiDisplayBackend::sendBluetoothKeepAlive() {
QJsonDocument doc = QJsonDocument::fromVariant(QVariantMap{{"header", KeepAliveCommand}}); QJsonDocument doc = QJsonDocument::fromVariant(QVariantMap{{"header", KeepAliveCommand}});
qDebug() << "Sending keep alive: \n" << qPrintable(doc.toJson(QJsonDocument::Indented)); //qDebug() << "Sending keep alive: \n" << qPrintable(doc.toJson(QJsonDocument::Indented));
this->bleClient->sendData(doc.toJson(QJsonDocument::Compact)); this->bleClient->sendData(doc.toJson(QJsonDocument::Compact));
} }
void OmobiDisplayBackend::handleBluetoothDataReceived(QString s){ void OmobiDisplayBackend::handleBluetoothDataReceived(QString s){
qDebug() << "New data: \n" << qPrintable(s); //qDebug() << "New data: \n" << qPrintable(s);
QJsonParseError parseError; QJsonParseError parseError;
QJsonDocument doc = QJsonDocument::fromJson(s.toUtf8(), &parseError); QJsonDocument doc = QJsonDocument::fromJson(s.toUtf8(), &parseError);
@ -150,12 +158,15 @@ void OmobiDisplayBackend::handleBluetoothDataReceived(QString s){
OmobiDisplayStatusCode status = OmobiDisplayStatusCode(doc.toVariant().toMap()["status"].toInt()); OmobiDisplayStatusCode status = OmobiDisplayStatusCode(doc.toVariant().toMap()["status"].toInt());
switch (header) { switch (header) {
case AuthorizeSessionCommand: { case AuthenticateCommand: {
if(status != Success) { if(status != Success) {
this->setState(AuthenticationRequired); this->setState(AuthenticationRequired);
this->lastDisplaySecret = "";
return; return;
} }
this->settings->setValue(this->bleClient->getCurrentDevice()->getAddress(), this->lastDisplaySecret);
this->waitingCommands = 0; this->waitingCommands = 0;
this->setState(Initing); this->setState(Initing);
this->sendBluetoothCommand(GetAllTextSetsCommand); this->sendBluetoothCommand(GetAllTextSetsCommand);

View file

@ -5,6 +5,7 @@
#include <QTimer> #include <QTimer>
#include <QJsonDocument> #include <QJsonDocument>
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QSettings>
#include <qbluetoothleuartclient.h> #include <qbluetoothleuartclient.h>
#include <omobidisplaytextmodel.h> #include <omobidisplaytextmodel.h>
@ -35,7 +36,7 @@ public:
private: private:
enum OmobiDisplayCommand { enum OmobiDisplayCommand {
AuthorizeSessionCommand = 0, AuthenticateCommand = 0,
KeepAliveCommand = 1, KeepAliveCommand = 1,
GetAllTextSetsCommand = 10, GetAllTextSetsCommand = 10,
GetTextSetParameterCommand = 11, GetTextSetParameterCommand = 11,
@ -59,6 +60,9 @@ private:
QList<QMap<int, QVariant>> textSetsBuffer; QList<QMap<int, QVariant>> textSetsBuffer;
int displayBrightness; int displayBrightness;
QSettings* settings;
QString lastDisplaySecret;
public slots: public slots:
Q_INVOKABLE void startScanning(); Q_INVOKABLE void startScanning();
Q_INVOKABLE void authenticate(QString secret); Q_INVOKABLE void authenticate(QString secret);

View file

@ -9,7 +9,6 @@ OmobiDisplayTextModel::OmobiDisplayTextModel(QObject* parent) : QAbstractListMod
connect(this, &OmobiDisplayTextModel::rowsRemoved, this, &OmobiDisplayTextModel::rowCountChanged); connect(this, &OmobiDisplayTextModel::rowsRemoved, this, &OmobiDisplayTextModel::rowCountChanged);
} }
int OmobiDisplayTextModel::rowCount(const QModelIndex &) const int OmobiDisplayTextModel::rowCount(const QModelIndex &) const
{ {
return this->texts.length(); return this->texts.length();

View file

@ -16,6 +16,11 @@ Page {
title: qsTr("Available displays") title: qsTr("Available displays")
signal opened()
onOpened: {
}
ColumnLayout { ColumnLayout {
id: mainLayout id: mainLayout
anchors { anchors {
@ -114,6 +119,7 @@ Page {
} }
Item { Item {
id: noDisplaysItem
anchors.centerIn: parent anchors.centerIn: parent
width: Math.min(parent.height, parent.width) width: Math.min(parent.height, parent.width)

View file

@ -15,6 +15,8 @@ Page {
title: backend.bleClient.currentDevice === null ? "":backend.bleClient.currentDevice.name title: backend.bleClient.currentDevice === null ? "":backend.bleClient.currentDevice.name
signal opened()
function backButtonClicked() { function backButtonClicked() {
backend.bleClient.disconnectFromDevice() backend.bleClient.disconnectFromDevice()
} }
@ -50,15 +52,17 @@ Page {
Layout.fillHeight: true Layout.fillHeight: true
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
font.pixelSize: parent.height * 0.5 font.pixelSize: parent.height * 0.5
font.family: fontAwesome.name
text: "\uf186" text: "\uf186"
} }
Slider { Slider {
id: brightnessSlider
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
from: 0 from: 0
to: 10 to: 255
stepSize: 1 stepSize: 1
value: backend.displayBrightness value: backend.displayBrightness
@ -67,12 +71,19 @@ Page {
if(!pressed) if(!pressed)
backend.displayBrightness = value backend.displayBrightness = value
} }
ToolTip {
parent: brightnessSlider.handle
visible: brightnessSlider.pressed
text: brightnessSlider.value.toFixed(1)
}
} }
Text { Text {
Layout.fillHeight: true Layout.fillHeight: true
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
font.pixelSize: parent.height * 0.5 font.pixelSize: parent.height * 0.5
font.family: fontAwesome.name
text: "\uf185" text: "\uf185"
} }
} }

View file

@ -8,6 +8,7 @@ ItemDelegate {
property string value: "" property string value: ""
property alias from: spinBox.from property alias from: spinBox.from
property alias to: spinBox.to property alias to: spinBox.to
property bool editable: false
onClicked: { onClicked: {
spinBox.value = control.value spinBox.value = control.value
@ -67,6 +68,7 @@ ItemDelegate {
contentItem: SpinBox { contentItem: SpinBox {
id: spinBox id: spinBox
value: control.value value: control.value
editable: control.editable
} }
onAccepted: { onAccepted: {

View file

@ -82,6 +82,8 @@ Dialog {
SpinBoxDelegate { SpinBoxDelegate {
id: runtimeSpinBox id: runtimeSpinBox
Layout.fillWidth: true Layout.fillWidth: true
editable: true
to: 3600
text: qsTr("Runtime (in s)") text: qsTr("Runtime (in s)")
} }
@ -107,7 +109,7 @@ Dialog {
SpinBoxDelegate { SpinBoxDelegate {
id: scrollSpeedSpinBox id: scrollSpeedSpinBox
Layout.fillWidth: true Layout.fillWidth: true
from: 0 from: 1
to: 10 to: 10
text: qsTr("Scroll speed") text: qsTr("Scroll speed")
} }
@ -116,6 +118,7 @@ Dialog {
id: scrollCountSpinBox id: scrollCountSpinBox
Layout.fillWidth: true Layout.fillWidth: true
from: 0 from: 0
editable: true
text: qsTr("Scroll count") text: qsTr("Scroll count")
} }
} }

View file

@ -46,7 +46,7 @@ ApplicationWindow {
opacity: mainStack.currentItem.backButtonVisible ? 1:0 opacity: mainStack.currentItem.backButtonVisible ? 1:0
font.styleName: fontAwesome.name font.family: fontAwesome.name
font.pixelSize: height * 0.6 font.pixelSize: height * 0.6
Material.foreground: "black" Material.foreground: "black"
@ -63,7 +63,7 @@ ApplicationWindow {
onClicked: mainStack.currentItem.backButtonClicked() onClicked: mainStack.currentItem.backButtonClicked()
} }
Text { Label {
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: true Layout.fillWidth: true
Layout.alignment: Layout.Center Layout.alignment: Layout.Center
@ -71,6 +71,7 @@ ApplicationWindow {
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
color: "black"
text: mainStack.currentItem.title text: mainStack.currentItem.title
} }
@ -82,7 +83,7 @@ ApplicationWindow {
opacity: mainStack.currentItem.actionButtonVisible ? 1:0 opacity: mainStack.currentItem.actionButtonVisible ? 1:0
font.styleName: fontAwesome.name font.family: fontAwesome.name
font.pixelSize: height * 0.4 font.pixelSize: height * 0.4
Material.foreground: "black" Material.foreground: "black"
@ -102,7 +103,11 @@ ApplicationWindow {
FontLoader { FontLoader {
id: fontAwesome id: fontAwesome
source: "qrc:/fa5regular.woff" source: "qrc:/fa5solid.woff"
Component.onCompleted: {
console.log("Font name: " + fontAwesome.name)
}
} }
StackView { StackView {
@ -117,6 +122,10 @@ ApplicationWindow {
mainStack.replace(currentComponent) mainStack.replace(currentComponent)
} }
onCurrentItemChanged: {
currentItem.opened()
}
initialItem: connectedPageComp initialItem: connectedPageComp
replaceEnter: Transition { replaceEnter: Transition {

Binary file not shown.

View file

@ -2,6 +2,6 @@
<qresource prefix="/"> <qresource prefix="/">
<file>omobi.png</file> <file>omobi.png</file>
<file>itsblue.png</file> <file>itsblue.png</file>
<file>fa5regular.woff</file> <file>fa5solid.woff</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -76,7 +76,8 @@
<message> <message>
<source>Display name <source>Display name
(needs restart)</source> (needs restart)</source>
<translation>Displayname\n(neutstart nötig)</translation> <translation>Displayname
(neutstart nötig)</translation>
</message> </message>
<message> <message>
<source>Display code (4 digits)</source> <source>Display code (4 digits)</source>