2018-08-12 20:51:57 +02:00
|
|
|
/*
|
|
|
|
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 <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
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>
|
2018-10-04 18:35:29 +02:00
|
|
|
//#include <QtWebView/QtWebView>
|
2018-07-25 00:32:20 +02:00
|
|
|
|
|
|
|
#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>
|
2018-10-04 18:35:29 +02:00
|
|
|
//#include <QtWebView/QtWebView>
|
2018-07-22 21:08:11 +02:00
|
|
|
#ifdef Q_OS_ANDROID
|
2018-08-12 20:51:57 +02:00
|
|
|
#include <QtAndroidExtras>
|
2018-07-22 21:08:11 +02:00
|
|
|
#endif
|
2018-07-28 23:05:26 +02:00
|
|
|
#include "headers/sqlstoragemodel.h"
|
|
|
|
#include "headers/sqlprofilemodel.h"
|
|
|
|
#include "headers/appsettings.h"
|
2018-09-23 17:54:20 +02:00
|
|
|
#include "headers/baseconn.h"
|
2018-10-04 18:35:29 +02:00
|
|
|
#include "headers/speedtimer.h"
|
2019-03-07 17:18:24 +01:00
|
|
|
#include "headers/climbingrace.h"
|
2019-03-08 18:03:27 +01:00
|
|
|
#include "headers/apptheme.h"
|
2018-08-14 17:07:42 +02:00
|
|
|
#include <QTranslator>
|
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);
|
2018-09-23 17:54:20 +02:00
|
|
|
|
2018-07-22 16:47:55 +02:00
|
|
|
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);
|
|
|
|
|
2018-08-12 20:51:57 +02:00
|
|
|
#ifdef Q_OS_ANDROID
|
2018-07-25 00:32:20 +02:00
|
|
|
//set the standard volume to media
|
2018-08-12 20:51:57 +02:00
|
|
|
QAndroidJniObject jactivity=QtAndroid::androidActivity();
|
|
|
|
if(jactivity.isValid())
|
2018-07-25 00:32:20 +02:00
|
|
|
jactivity.callMethod<void>("setVolumeControlStream","(I)V",3);
|
2018-08-28 23:03:35 +02:00
|
|
|
|
|
|
|
//set statusbar color
|
|
|
|
QtAndroid::runOnAndroidThread([=]()
|
|
|
|
{
|
|
|
|
QAndroidJniObject window = QtAndroid::androidActivity().callObjectMethod("getWindow", "()Landroid/view/Window;");
|
|
|
|
window.callMethod<void>("addFlags", "(I)V", 0x80000000);
|
|
|
|
window.callMethod<void>("clearFlags", "(I)V", 0x04000000);
|
|
|
|
//window.callMethod<void>("setStatusBarColor", "(I)V", 0x202227); // Desired statusbar color
|
|
|
|
//QAndroidJniObject decorView = window.callObjectMethod("getDecorView", "()Landroid/view/View;");
|
|
|
|
//decorView.callMethod<void>("setSystemUiVisibility", "(I)V", 0x00002000);
|
|
|
|
});
|
2018-08-12 20:51:57 +02:00
|
|
|
#endif
|
2018-07-22 16:47:55 +02:00
|
|
|
|
|
|
|
connectToDatabase();
|
2018-10-04 18:35:29 +02:00
|
|
|
|
2019-03-07 17:18:24 +01:00
|
|
|
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");
|
|
|
|
|
2019-09-08 15:08:50 +02:00
|
|
|
// setup speed backend and App themes
|
2019-03-07 17:18:24 +01:00
|
|
|
qmlRegisterType<ClimbingRace>("com.itsblue.speedclimbingstopwatch", 2, 0, "SpeedBackend");
|
2019-03-08 18:03:27 +01:00
|
|
|
qmlRegisterType<AppTheme>("com.itsblue.speedclimbingstopwatch", 2, 0, "AppTheme");
|
2018-09-17 23:06:34 +02:00
|
|
|
|
2018-07-17 19:17:25 +02:00
|
|
|
QQmlApplicationEngine engine;
|
|
|
|
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
2019-03-07 17:18:24 +01:00
|
|
|
|
|
|
|
QQmlContext *context = engine.rootContext();
|
2019-09-08 15:08:50 +02:00
|
|
|
|
|
|
|
// stup app settings
|
2019-03-07 17:18:24 +01:00
|
|
|
context->setContextProperty("_cppAppSettings", pAppSettings);
|
|
|
|
|
2018-07-17 19:17:25 +02:00
|
|
|
if (engine.rootObjects().isEmpty())
|
|
|
|
return -1;
|
|
|
|
|
2018-08-29 18:33:39 +02:00
|
|
|
int iRet = 0;
|
|
|
|
iRet = app.exec();
|
|
|
|
|
|
|
|
return iRet;
|
2018-07-17 19:17:25 +02:00
|
|
|
}
|