Files
OpenVR-AdvancedSettings-frame/src/main.cpp
T
Vasily 5b9e94869c Move application strings into separate namespace
Them being in the overlay controller required them to be static, which
forces the compiler to give them a memory location at compile time. They
also don't really fit into the overlaycontroller.
2019-03-11 11:24:57 +01:00

106 lines
3.8 KiB
C++

#include "utils/setup.h"
INITIALIZE_EASYLOGGINGPP
int main( int argc, char* argv[] )
{
setUpLogging();
MyQApplication mainEventLoop( argc, argv );
mainEventLoop.setOrganizationName(
application_strings::applicationOrganizationName );
mainEventLoop.setApplicationName( application_strings::applicationName );
mainEventLoop.setApplicationDisplayName(
application_strings::applicationDisplayName );
mainEventLoop.setApplicationVersion(
application_strings::applicationVersionString );
qInstallMessageHandler( mainQtMessageHandler );
const auto commandLineArgs
= argument::returnCommandLineParser( mainEventLoop );
// It is important that either install_manifest or remove_manifest are true,
// otherwise the handleManifests function will not behave properly.
if ( commandLineArgs.forceInstallManifest
|| commandLineArgs.forceRemoveManifest )
{
manifest::handleManifests( commandLineArgs.forceInstallManifest,
commandLineArgs.forceRemoveManifest );
}
openvr_init::initializeOpenVR(
openvr_init::OpenVrInitializationType::Overlay );
try
{
QSettings appSettings( QSettings::IniFormat,
QSettings::UserScope,
mainEventLoop.organizationName(),
mainEventLoop.applicationName() );
advsettings::OverlayController::setAppSettings( &appSettings );
LOG( INFO ) << "Settings File: "
<< appSettings.fileName().toStdString();
QQmlEngine qmlEngine;
advsettings::OverlayController controller( commandLineArgs.desktopMode,
commandLineArgs.forceNoSound,
qmlEngine );
QString path = QStandardPaths::locate(
QStandardPaths::AppDataLocation,
QStringLiteral( "res/qml/common/mainwidget.qml" ) );
QQmlComponent component( &qmlEngine, QUrl::fromLocalFile( path ) );
auto errors = component.errors();
for ( auto& e : errors )
{
LOG( ERROR ) << "QML Error: " << e.toString().toStdString()
<< std::endl;
}
auto quickObj = component.create();
controller.SetWidget( qobject_cast<QQuickItem*>( quickObj ),
application_strings::applicationDisplayName,
application_strings::applicationKey );
// Attempts to install the application manifest on all "regular" starts.
if ( !commandLineArgs.desktopMode && !commandLineArgs.forceNoManifest )
{
try
{
const auto manifestPath = QDir::cleanPath(
QDir( QCoreApplication::applicationDirPath() )
.absoluteFilePath( manifest::kVRManifestName ) );
manifest::installApplicationManifest( manifestPath );
}
catch ( std::exception& e )
{
LOG( ERROR ) << e.what();
}
}
if ( commandLineArgs.desktopMode )
{
auto m_pWindow = new QQuickWindow();
qobject_cast<QQuickItem*>( quickObj )
->setParentItem( m_pWindow->contentItem() );
m_pWindow->setGeometry(
0,
0,
static_cast<int>(
qobject_cast<QQuickItem*>( quickObj )->width() ),
static_cast<int>(
qobject_cast<QQuickItem*>( quickObj )->height() ) );
m_pWindow->show();
}
return mainEventLoop.exec();
}
catch ( const std::exception& e )
{
LOG( FATAL ) << e.what();
return ReturnErrorCode::GENERAL_FAILURE;
}
}