Files
vehicle-voyage/src/main.cpp

71 lines
2.6 KiB
C++

/*
* Vehicle Voyage
* Copyright (C) 2020 <Kevin Whitaker> <eyecreate@eyecreate.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <KAboutData>
#include <QIcon>
#include <QStandardPaths>
#include <QDir>
#include <QSqlDatabase>
#include <QSqlError>
#include <QDebug>
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
KAboutData aboutData("org.eyecreate.vehiclevoyage", "Vehicle Voyage", "1.0", "Track vehicle service history.",KAboutLicense::GPL_V3);//TODO:i18n
aboutData.setProductName("vehiclevoyage");
aboutData.addAuthor("Kevin Whitaker",QString(),"eyecreate@eyecreate.org","https://www.eyecreate.org");
aboutData.setDesktopFileName("org.eyecreate.vehiclevoyage");
QCoreApplication::setOrganizationName("eyecreate");
QCoreApplication::setOrganizationDomain("eyecreate.org");
QCoreApplication::setApplicationName(aboutData.productName());
QCoreApplication::setApplicationVersion(aboutData.version());
app.setWindowIcon(QIcon::fromTheme("org.eyecreate.vehiclevoyage"));
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("servicerecords.sqlite"));
if(!QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).exists())
{
QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
}
if(!QFile(db.databaseName()).exists())
{
QFile(db.databaseName()).open(QIODevice::ReadWrite);
}
if(!db.open())
{
//Bad db, exit now.
printf("%s",db.lastError().text().toLatin1().data());
return -2;
}
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
if (engine.rootObjects().isEmpty()) {
return -1;
}
return app.exec();
}