aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Teichmann <daniel.teichmann@das-netzwerkteam.de>2020-07-18 16:45:50 +0200
committerDaniel Teichmann <daniel.teichmann@das-netzwerkteam.de>2020-07-18 16:45:50 +0200
commit7d11099e5afd1f16c811ccbe954a158105be36ab (patch)
tree61f5eb08c7ccd19a6b4947ee1900d49e25fac32e
parentbc375c354abee8132ca1bb585c8c5ca99f7f9eba (diff)
downloadRWA.Support.DesktopApp-7d11099e5afd1f16c811ccbe954a158105be36ab.tar.gz
RWA.Support.DesktopApp-7d11099e5afd1f16c811ccbe954a158105be36ab.tar.bz2
RWA.Support.DesktopApp-7d11099e5afd1f16c811ccbe954a158105be36ab.zip
Add pinChange() function
-rw-r--r--main.cpp33
-rw-r--r--main.qml10
2 files changed, 41 insertions, 2 deletions
diff --git a/main.cpp b/main.cpp
index 6889e8d..091f649 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,8 +1,14 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
+#include <QQmlComponent>
+#include <QQmlProperty>
+#include <QQuickItem>
#include <QTranslator>
#include <QDebug>
+void changePin(QString pin, QQmlApplicationEngine &engine);
+void gen_random(char *s, const int len);
+
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
@@ -25,5 +31,32 @@ int main(int argc, char *argv[])
if (engine.rootObjects().isEmpty())
return -1;
+ #define PIN_LENGTH 5
+ // The char array in which the random pin will be written to
+ char rand_pin[PIN_LENGTH+1];
+ gen_random(rand_pin, PIN_LENGTH);
+ changePin(rand_pin, engine);
+
return app.exec();
}
+
+void changePin(QString pin, QQmlApplicationEngine &engine){
+ QQuickItem *item = engine.rootObjects().at(0)->findChild<QQuickItem*>("pin_text");
+ if (item)
+ item->setProperty("pin", pin);
+}
+
+void gen_random(char *s, const int len) {
+ // Initialize random generator
+ srand( static_cast<unsigned>(time(NULL)));
+
+ static const char alphanum[] =
+ "0123456789"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+ for (int i = 0; i < len; ++i) {
+ s[i] = alphanum[rand() % static_cast<int>(sizeof(alphanum) - 1)];
+ }
+
+ s[len] = 0;
+}
diff --git a/main.qml b/main.qml
index 20a1da6..1e6b242 100644
--- a/main.qml
+++ b/main.qml
@@ -84,8 +84,14 @@ Window {
id: pin_text
x: 235
width: 210
- height: 50
- text: qsTr("0 1 A 2 3 B")
+ height: 28
+ // ':' translation info
+ //: Do not translate!
+ //: This is just the pin which is used to authenticate to remote web app (django) frontend
+ text: qsTr("%1").arg(pin)
+ property string pin: "-----"
+ font.letterSpacing: 10
+ anchors.horizontalCenterOffset: 0
font.pixelSize: 26
anchors.horizontalCenter: your_pin_text.horizontalCenter
anchors.top: your_pin_text.bottom