This repository has been archived on 2024-06-03. You can view files and clone it, but cannot push or open issues or pull requests.
app/sources/main.cpp

96 lines
3 KiB
C++
Raw Normal View History

2018-07-17 19:17:25 +02:00
#include <QGuiApplication>
#include <QQmlApplicationEngine>
2018-07-22 16:47:55 +02:00
#include <QSqlDatabase>
#include <QSqlError>
#include <QDebug>
#include <QFile>
#include <QDir>
#include <QStandardPaths>
#include <QtWebView/QtWebView>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QGuiApplication>
#include <QQuickView>
#include <QStandardPaths>
#include <QtQml>
#include <QtNetwork>
#include <QQmlApplicationEngine>
#include <QFile>
#include <QDesktopServices>
#include <QtCore/QUrl>
#include <QtCore/QCommandLineOption>
#include <QtCore/QCommandLineParser>
#include <QGuiApplication>
#include <QStyleHints>
#include <QScreen>
#include <QQmlApplicationEngine>
#include <QtQml/QQmlContext>
#include <QtWebView/QtWebView>
2018-07-22 21:08:11 +02:00
#ifdef Q_OS_ANDROID
#include <QtAndroidExtras>
#endif
2018-07-28 23:05:26 +02:00
#include "headers/sqlstoragemodel.h"
#include "headers/sqlprofilemodel.h"
#include "headers/buzzerconn.h"
#include "headers/appsettings.h"
2018-07-22 16:47:55 +02:00
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);
qDebug() << writeDir;
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()));
}
}
2018-07-17 19:17:25 +02:00
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<void>("setVolumeControlStream","(I)V",3);
#endif
2018-07-22 16:47:55 +02:00
connectToDatabase();
BuzzerConn * pBuzzerConn = new BuzzerConn;
AppSettings * pAppSettings = new AppSettings();
2018-07-22 16:47:55 +02:00
//setup the sql storage model as a qml model
qmlRegisterType<SqlProfileModel>("com.itsblue.speedclimbingstopwatch", 1, 0, "SqlProfileModel");
qmlRegisterType<SqlStorageModel>("com.itsblue.speedclimbingstopwatch", 1, 0, "SqlStorageModel");
2018-07-17 19:17:25 +02:00
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
engine.rootContext()->setContextProperty("_cppBuzzerConn", pBuzzerConn);
engine.rootContext()->setContextProperty("_cppAppSettings", pAppSettings);
2018-07-17 19:17:25 +02:00
return app.exec();
}