/* Speed Climbing Stopwatch - Simple Stopwatch for Climbers Copyright (C) 2018 Itsblue Development - Dorian Zeder This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ #include #include #include #include #include #include #include #include //#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #ifdef Q_OS_ANDROID #include #endif #include "headers/sqlstoragemodel.h" #include "headers/sqlprofilemodel.h" #include "headers/buzzerconn.h" #include "headers/appsettings.h" #include "headers/baseconn.h" #include "headers/speedtimer.h" #include static void connectToDatabase() { QSqlDatabase database = QSqlDatabase::database(); if (!database.isValid()) { database = QSqlDatabase::addDatabase("QSQLITE"); if (!database.isValid()) qFatal("Cannot add database: %s", qPrintable(database.lastError().text())); } const QDir writeDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); if (!writeDir.mkpath(".")) qFatal("Failed to create writable directory at %s", qPrintable(writeDir.absolutePath())); // Ensure that we have a writable location on all devices. const QString fileName = writeDir.absolutePath() + "/chat-database.sqlite3"; //QFile::remove(fileName); // When using the SQLite driver, open() will create the SQLite database if it doesn't exist. database.setDatabaseName(fileName); if (!database.open()) { QFile::remove(fileName); qFatal("Cannot open database: %s", qPrintable(database.lastError().text())); } } int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); #ifdef Q_OS_ANDROID //set the standard volume to media QAndroidJniObject jactivity=QtAndroid::androidActivity(); if(jactivity.isValid()) jactivity.callMethod("setVolumeControlStream","(I)V",3); //set statusbar color QtAndroid::runOnAndroidThread([=]() { QAndroidJniObject window = QtAndroid::androidActivity().callObjectMethod("getWindow", "()Landroid/view/Window;"); window.callMethod("addFlags", "(I)V", 0x80000000); window.callMethod("clearFlags", "(I)V", 0x04000000); //window.callMethod("setStatusBarColor", "(I)V", 0x202227); // Desired statusbar color //QAndroidJniObject decorView = window.callObjectMethod("getDecorView", "()Landroid/view/View;"); //decorView.callMethod("setSystemUiVisibility", "(I)V", 0x00002000); }); #endif connectToDatabase(); //BuzzerConn * pBuzzerConn = new BuzzerConn(nullptr, "192.168.4.10", 80); //BuzzerConn * pStartpadConn = new BuzzerConn(nullptr, "192.168.4.11", 80); AppSettings * pAppSettings = new AppSettings(); pGlobalAppSettings = pAppSettings; SpeedTimer * pSpeedTimer = new SpeedTimer(); pGlobalSpeedTimer = pSpeedTimer; //setup the sql storage model as a qml model qmlRegisterType("com.itsblue.speedclimbingstopwatch", 1, 0, "SqlProfileModel"); qmlRegisterType("com.itsblue.speedclimbingstopwatch", 1, 0, "SqlStorageModel"); //setup the startpad and buzzer conn qml objects qmlRegisterType("com.itsblue.speedclimbingstopwatch", 1, 0, "BuzzerConn"); qmlRegisterType("com.itsblue.speedclimbingstopwatch", 1, 0, "StartpadConn"); qmlRegisterType("com.itsblue.speedclimbingstopwatch", 1, 0, "BaseStationConn"); //setup translation engine //to the language of the system //if the system language is not found the language is set to english QTranslator translator; translator.load(":/translations/"+QLocale::system().name()+".qm"); app.installTranslator(&translator); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; engine.rootContext()->setContextProperty("_cppAppSettings", pAppSettings); engine.rootContext()->setContextProperty("_cppSpeedTimer", pSpeedTimer); int iRet = 0; iRet = app.exec(); //call the destructors of all objects delete pAppSettings; return iRet; }