summaryrefslogtreecommitdiffhomepage
path: root/facetracknoir/main.cpp
blob: fea76b309191a6e59c476c0c6942e8ec36c3f9fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifdef _WIN32
#   include <stdlib.h>
#endif

#include "ui.h"
#include "opentrack/options.hpp"
using namespace options;
#include <QApplication>
#include <QCommandLineParser>
#include <QStyleFactory>
#include <QStringList>
#include <QMessageBox>
#include <memory>
#include <cstring>

#ifdef _WIN32
// workaround QTBUG-38598, allow for launching from another directory
static void add_program_library_path()
{
    {
        char* p = _pgmptr;
        {
            char path[MAX_PATH];
            strcpy(path, p);
            char* ptr = strrchr(path, '\\');
            if (ptr)
            {
                *ptr = '\0';
                QCoreApplication::addLibraryPath(path);
            }
        }
    }
#endif
}

int main(int argc, char** argv)
{
#ifdef _WIN32
    add_program_library_path();
#endif
    // workaround QTBUG-38598
    QCoreApplication::addLibraryPath(".");

    // qt5 designer-made controls look like shit on 'doze -sh 20140921
#ifdef _WIN32
    {
        const QStringList preferred { "fusion", "windowsvista", "jazzbands'-marijuana", "macintosh", "windowsxp" };
        for (const auto& style_name : preferred)
        {
            QStyle* s = QStyleFactory::create(style_name);
            if (s)
            {
                QApplication::setStyle(s);
                break;
            }
        }
    }
#endif

    QApplication::setAttribute(Qt::AA_X11InitThreads, true);
    QApplication app(argc, argv);

	QCommandLineParser p;
	p.setApplicationDescription("opentrack - Head tracking software for MS Windows, Linux, and Apple OSX");
	p.addHelpOption();
	QCommandLineOption autostartOption(QStringList() << "a" << "autostart", "Load <profile> and start tracking", "profile");
	p.addOption(autostartOption);
	p.process(app);

	QString profile = p.value(autostartOption);
    
    bool use_profile = profile.endsWith(".ini") && QFileInfo(profile).exists() && QFileInfo(profile).isFile();
    if (!profile.isEmpty() && !use_profile)
        QMessageBox::warning(nullptr, "Can't load profile", "Profile " + profile + " specified but can't be opened!",
                             QMessageBox::Ok, QMessageBox::NoButton);
    
	if (use_profile)
        MainWindow::set_profile(profile);
    
    MainWindow w;
    
    if (use_profile)
        w.startTracker();
		
    w.show();
    app.exec();

    return 0;
}