2#include "CommandLineParser.hh"
5#include <OpenFlipper/BasePlugin/PluginFunctionsCore.hh>
9CommandLineParseResult parseCommandLine(QCommandLineParser &parser, QString *errorMessage) {
14 int QtVersionMajor, QtVersionMinor, QtVersionPatch;
15 if(sscanf(qVersion(),
"%1d.%1d.%1d",&QtVersionMajor, &QtVersionMinor, &QtVersionPatch) == 3)
17 if(QtVersionMajor == 5 && QtVersionMinor >= 7)
19 if(QtVersionPatch < 2)
21 std::cerr <<
"The used Qt Version does not support stereo mode. Disabling stereo mode." << std::endl;
22 OpenFlipper::Options::stereo(
false);
25 std::cerr <<
"Stereo Mode has not been tested for the used Qt Version." << std::endl;
32 parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
35 QCommandLineOption debugOption(QStringList() <<
"d" <<
"debug",QCoreApplication::translate(
"main",
"Enable debugging mode"));
36 parser.addOption(debugOption);
38 QCommandLineOption stereoOption(
"disable-stereo",QCoreApplication::translate(
"main",
"Disable stereo mode"));
39 parser.addOption(stereoOption);
41 QCommandLineOption batchOption(QStringList() <<
"b" <<
"batch",QCoreApplication::translate(
"main",
"Batch mode, you have to provide a script for execution"));
42 parser.addOption(batchOption);
44 QCommandLineOption logConsoleOption(QStringList() <<
"c" <<
"log-to-console",QCoreApplication::translate(
"main",
"Write logger window contents to console"));
45 parser.addOption(logConsoleOption);
47 QCommandLineOption remoteControlOption(
"remote-control",QCoreApplication::translate(
"main",
"Batch mode accepting remote connections"));
48 parser.addOption(remoteControlOption);
50 QCommandLineOption fulscreenOption(QStringList() <<
"f" <<
"fullscreen",QCoreApplication::translate(
"main",
"Start in fullscreen mode"));
51 parser.addOption(fulscreenOption);
53 QCommandLineOption hideLoggerOption(QStringList() <<
"l" <<
"hide-logger",QCoreApplication::translate(
"main",
"Start with hidden log window"));
54 parser.addOption(hideLoggerOption);
56 QCommandLineOption hideToolboxOption(QStringList() <<
"t" <<
"hide-toolbox",QCoreApplication::translate(
"main",
"Start with hidden toolbox"));
57 parser.addOption(hideToolboxOption);
59 QCommandLineOption noSplashOption(
"no-splash",QCoreApplication::translate(
"main",
"Hide splash screen"));
60 parser.addOption(noSplashOption);
62 QCommandLineOption polyMeshOption(
"p",QCoreApplication::translate(
"main",
"Open files as PolyMeshes"));
63 parser.addOption(polyMeshOption);
65 QCommandLineOption remotePortOption(
"remote-port",QCoreApplication::translate(
"main",
"Remote port"),
"portnumber");
66 parser.addOption(remotePortOption);
68 QCommandLineOption coreProfileOption(
"core-profile",QCoreApplication::translate(
"main",
"OpenGL Core Profile Mode"));
69 parser.addOption(coreProfileOption);
71 QCommandLineOption glVersionOption(
"glVersion",QCoreApplication::translate(
"main",
"Request OpenGL version <major>.<minor> "),QCoreApplication::translate(
"main",
"< 1.0 | 1.1 | ... | 4.6 >"));
72 parser.addOption(glVersionOption);
74 QCommandLineOption samplesOption(
"samples",QCoreApplication::translate(
"main",
"Overwrite multisampling sample count"),QCoreApplication::translate(
"main",
"< 0 | 1 | 2 | ... | 16 >"));
75 parser.addOption(samplesOption);
77 QCommandLineOption glStereoOption(
"glStereo",QCoreApplication::translate(
"main",
"Overwrite OpenGL Stereo setting"),QCoreApplication::translate(
"main",
"< true | false >"));
78 parser.addOption(glStereoOption);
80 QCommandLineOption profileOption(
"profile",QCoreApplication::translate(
"main",
"Request OpenGL context profile <profile> with profile set as compat or core"),QCoreApplication::translate(
"main",
"< compat | core >"));
81 parser.addOption(profileOption);
83 QCommandLineOption pluginOptionsOption(QStringList() <<
"o" <<
"pluginoptions",QCoreApplication::translate(
"main",
"Pass options to plugins"),
"key1=value1;key2=value2;...");
84 parser.addOption(pluginOptionsOption);
86 const QCommandLineOption helpOption = parser.addHelpOption();
87 const QCommandLineOption versionOption = parser.addVersionOption();
91 if (!parser.parse(QCoreApplication::arguments())) {
92 *errorMessage = parser.errorText();
93 return CommandLineError;
96 if (parser.isSet(helpOption))
97 return CommandLineHelpRequested;
99 if (parser.isSet(versionOption))
100 return CommandLineVersionRequested;
102 if (parser.isSet(debugOption)) {
103 OpenFlipper::Options::debug(
true);
106 if (parser.isSet(stereoOption)) {
107 OpenFlipper::Options::stereo(
false);
110 if (parser.isSet(batchOption)) {
111 OpenFlipper::Options::nogui(
true);
114 if (parser.isSet(logConsoleOption)) {
115 OpenFlipper::Options::logToConsole(
true);
118 if (parser.isSet(remoteControlOption)) {
119 OpenFlipper::Options::remoteControl(
true);
122 if (parser.isSet(fulscreenOption)) {
123 OpenFlipperSettings().
setValue(
"Core/Gui/fullscreen",
true);
126 if (parser.isSet(hideLoggerOption)) {
127 OpenFlipper::Options::loggerState(OpenFlipper::Options::Hidden);
130 if (parser.isSet(hideToolboxOption)) {
131 OpenFlipperSettings().
setValue(
"Core/Gui/ToolBoxes/hidden",
true);
134 if (parser.isSet(noSplashOption)) {
135 OpenFlipperSettings().
setValue(
"Core/Gui/splash",
false);
138 if (parser.isSet(polyMeshOption)) {
139 openPolyMeshes =
true;
142 if (parser.isSet(remotePortOption)) {
143 const QString port = parser.value(
"remote-port");
144 std::cerr <<
"Got port option : " << port.toStdString() << std::endl;
145 OpenFlipper::Options::remoteControl(port.toInt());
147 if(parser.isSet(
"samples"))
148 OpenFlipper::Options::samples(parser.value(
"samples").toInt(),
true);
149 if(parser.isSet(
"glVersion"))
151 QStringList values = parser.value(
"glVersion").split(
".");
152 QPair<int,int> version(
155 OpenFlipper::Options::glVersion(version,
true);
158 if(parser.isSet(
"glStereo"))
159 OpenFlipper::Options::glStereo(parser.value(
"glStereo")==
"true");
161 if(parser.value(profileOption)==
"core")
163 OpenFlipper::Options::coreProfile(
true,
true);
167 if(parser.value(profileOption)==
"compat")
169 OpenFlipper::Options::coreProfile(
false,
true);
172 if(parser.isSet(coreProfileOption)) {
173 OpenFlipper::Options::coreProfile(
true,
true);
175 if(parser.isSet(pluginOptionsOption))
177 QStringList poptions = parser.value(pluginOptionsOption).split(
";");
178 QVector<QPair<QString, QString>> pcloptions;
179 for(
auto s : poptions)
181 auto kvp = s.split(
"=");
189 pcloptions.push_back({key, value});
194 return CommandLineOk;
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
void setPluginCommandLineOptions(const QVector< QPair< QString, QString > > &_pluginCommandLineOptions)