diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 091f649..0000000 --- a/main.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#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); - - QGuiApplication app(argc, argv); - - - QTranslator translator; - - qDebug() << "Im about to load: :/locales/bin/" + QLocale::system().name() + " locale!"; - if(translator.load(":/locales/bin/" + QLocale::system().name())) { - app.installTranslator(&translator); - qDebug() << "Loaded: " + QLocale::system().name() + " locale!"; - } else { - qDebug() << "Unable to load translation"; - } - - QQmlApplicationEngine engine; - engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); - 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; -} |