You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.5 KiB
77 lines
1.5 KiB
7 years ago
|
#include "coreapp.h"
|
||
|
#include "coreapp_p.h"
|
||
|
|
||
|
#include <QtCore/QCommandLineParser>
|
||
|
|
||
|
#include <QtGui/QGuiApplication>
|
||
|
|
||
|
using namespace QtMvvm;
|
||
|
|
||
|
CoreApp::CoreApp(QObject *parent) :
|
||
|
QObject(parent),
|
||
|
d(new CoreAppPrivate())
|
||
|
{}
|
||
|
|
||
|
CoreApp::~CoreApp() {}
|
||
|
|
||
|
CoreApp *CoreApp::instance()
|
||
|
{
|
||
|
return CoreAppPrivate::instance;
|
||
|
}
|
||
|
|
||
|
void CoreApp::disableAutoBoot()
|
||
|
{
|
||
|
CoreAppPrivate::bootEnabled = false;
|
||
|
}
|
||
|
|
||
|
void CoreApp::registerApp()
|
||
|
{
|
||
|
//register metatypes
|
||
|
setParent(qApp);
|
||
|
CoreAppPrivate::instance = this;
|
||
|
if(CoreAppPrivate::bootEnabled)
|
||
|
QMetaObject::invokeMethod(this, "bootApp", Qt::QueuedConnection);
|
||
|
}
|
||
|
|
||
|
void CoreApp::bootApp()
|
||
|
{
|
||
|
auto res = startApp(QCoreApplication::arguments());
|
||
|
if(res == EXIT_SUCCESS) {
|
||
|
connect(qApp, &QCoreApplication::aboutToQuit,
|
||
|
this, &CoreApp::closeApp);
|
||
|
} else
|
||
|
qApp->exit(res);
|
||
|
}
|
||
|
|
||
|
void CoreApp::closeApp() {}
|
||
|
|
||
|
bool CoreApp::autoParse(QCommandLineParser &parser, const QStringList &arguments)
|
||
|
{
|
||
|
if(parser.parse(arguments)) {
|
||
|
if(parser.isSet(QStringLiteral("help"))) {
|
||
|
Q_UNIMPLEMENTED();
|
||
|
return false;
|
||
|
} else if(parser.isSet(QStringLiteral("version"))) {
|
||
|
auto text = QGuiApplication::applicationDisplayName() +
|
||
|
QLatin1Char(' ') +
|
||
|
QCoreApplication::applicationVersion();
|
||
|
Q_UNIMPLEMENTED();
|
||
|
return false;
|
||
|
} else
|
||
|
return true;
|
||
|
} else {
|
||
|
Q_UNIMPLEMENTED();
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ------------- Private Implementation -------------
|
||
|
|
||
|
bool CoreAppPrivate::bootEnabled = true;
|
||
|
QPointer<CoreApp> CoreAppPrivate::instance = nullptr;
|
||
|
|
||
|
CoreAppPrivate::CoreAppPrivate()
|
||
|
{
|
||
|
|
||
|
}
|