diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 101 |
1 files changed, 84 insertions, 17 deletions
diff --git a/src/main.cpp b/src/main.cpp index f0c2dba..1493bcd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,23 +1,90 @@ -// Copyright 2013, University of Freiburg, -// Author: Manuel Schneider <ms1144> - -#include <QtWidgets/QApplication> // for Qt5 #include "widget.h" +#include "main.h" +#include "x.h" + +#include <QApplication> +#include <QLibraryInfo> +#include <QTranslator> +#include <QCommandLineParser> + +namespace { +bool _testMode, _autoSetup, _showGui, _backgroundMode; +} + +namespace CommandLine +{ +bool testMode() { return _testMode; } +bool autoSetup() { return _autoSetup; } +bool showGui() { return _showGui; } +bool backgroundMode() { return _backgroundMode; } +} + +static void parseCommandLine(const QApplication &a); int main(int argc, char *argv[]) { - QApplication a(argc, argv); - // System strings - QTranslator *qtTranslator = new QTranslator(&a); - qtTranslator->load(QLocale::system(), "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath)); - a.installTranslator(qtTranslator); - // App specific - QTranslator *translator = new QTranslator(&a); - translator->load(QLocale::system(), ":"); - a.installTranslator(translator); - Widget w(argc == 2 && QString(argv[1]) == QString("--test")); - w.show(); - return a.exec(); + QApplication a(argc, argv); + QCoreApplication::setApplicationName("BeamerGUI XP - Home Edition"); + QCoreApplication::setApplicationVersion("2.0"); + // System strings + QTranslator *qtTranslator = new QTranslator(&a); + qtTranslator->load(QLocale::system(), "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath)); + a.installTranslator(qtTranslator); + // App specific + QTranslator *translator = new QTranslator(&a); + translator->load(QLocale::system(), ":"); + a.installTranslator(translator); + + parseCommandLine(a); + + ScreenMode currentMode; + if (CommandLine::autoSetup()) { + currentMode = ScreenSetup::inst()->setDefaultMode(CommandLine::testMode()); + } else { + currentMode = ScreenSetup::inst()->getCurrentMode(); + } + + bool showNow = (CommandLine::showGui() && currentMode != ScreenMode::Single); + + Widget *w = nullptr; + if (CommandLine::backgroundMode() || showNow) { + w = new Widget(); + if (showNow) { + w->show(); + } + } + if (w == nullptr) + return 0; + return a.exec(); } -//////////////////////////////////////////////////////////////////////////////// +static void parseCommandLine(const QApplication &a) +{ + // Command line + QCommandLineParser parser; + parser.setApplicationDescription("Utility for detecting and configuring screen setup"); + parser.addHelpOption(); + parser.addVersionOption(); + // Option for adding modes and trying to auto-setup + QCommandLineOption oAutoSetup(QStringList() << "a" << "auto", + QCoreApplication::translate("main", "Automatically configure modes and set up screens.")); + parser.addOption(oAutoSetup); + // Show config GUI if more than one screen + QCommandLineOption oShowGui(QStringList() << "g" << "gui", + QCoreApplication::translate("main", "Show config GUI if more than one screen is connected.")); + parser.addOption(oShowGui); + // Keep running and detect screen setup changes + QCommandLineOption oBackground(QStringList() << "b" << "background", + QCoreApplication::translate("main", "Keep running in background and show GUI again when number of screens changes.")); + parser.addOption(oBackground); + // Test mode -- pretend to do setup + QCommandLineOption oTest(QStringList() << "t" << "test", + QCoreApplication::translate("main", "Test mode, don't actually apply any changes.")); + parser.addOption(oTest); + // PARSE + parser.process(a); + _testMode = parser.isSet(oTest); + _autoSetup = parser.isSet(oAutoSetup); + _showGui = parser.isSet(oShowGui); + _backgroundMode = parser.isSet(oBackground); +} |