* parseCommandLine - Setup options and parse command line arguments. * * @param parser parser instance to use for parse the arguments * @param errorMessage argument parse error message * * @return integer, representing the requested argument */
| 55 | * @return integer, representing the requested argument |
| 56 | */ |
| 57 | CommandLineParseResults parseCommandLine(QCommandLineParser &parser, QString *errorMessage) { |
| 58 | // setup parser to interpret -abc as -a -b -c |
| 59 | parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsCompactedShortOptions); |
| 60 | |
| 61 | /* add command line options */ |
| 62 | // add -v, --version |
| 63 | const QCommandLineOption versionOption = parser.addVersionOption(); |
| 64 | // add -h, --help (/? on windows) |
| 65 | const QCommandLineOption helpOption = parser.addHelpOption(); |
| 66 | // add -b, --background |
| 67 | const QCommandLineOption backgroundOption(QStringList() << "b" << "background", |
| 68 | QObject::tr("Starts in background, without displaying the main window.")); |
| 69 | parser.addOption(backgroundOption); |
| 70 | |
| 71 | // add -c, --close |
| 72 | const QCommandLineOption closeOption(QStringList() << "c" << "close", |
| 73 | QObject::tr("Causes already running instance (if any) to exit.")); |
| 74 | parser.addOption(closeOption); |
| 75 | |
| 76 | const QCommandLineOption switchToProfileOption(QStringList() << "p" << "profile", QObject::tr("Switches to the profile with the specified name on all devices."), "profile-name"); |
| 77 | parser.addOption(switchToProfileOption); |
| 78 | |
| 79 | const QCommandLineOption switchToModeOption(QStringList() << "m" << "mode", QObject::tr("Switches to the mode either in the current profile, or in the one specified by --profile"), "mode-name"); |
| 80 | parser.addOption(switchToModeOption); |
| 81 | |
| 82 | QCommandLineOption delayOption(QStringList() << "d" << "delay", QObject::tr("Delays application start for 5 seconds")); |
| 83 | QCommandLineOption silentOption(QStringList() << "s" << "silent", QObject::tr("Disables the daemon not running popup")); |
| 84 | |
| 85 | // Sigh |
| 86 | #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) |
| 87 | delayOption.setFlags(QCommandLineOption::HiddenFromHelp); |
| 88 | silentOption.setFlags(QCommandLineOption::HiddenFromHelp); |
| 89 | #elif QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) |
| 90 | delayOption.setHidden(true); |
| 91 | silentOption.setHidden(true); |
| 92 | #endif |
| 93 | parser.addOption(delayOption); |
| 94 | parser.addOption(silentOption); |
| 95 | |
| 96 | #ifndef QT_NO_DEBUG |
| 97 | QCommandLineOption kwdebugOption("kwdebug", QObject::tr("Enables the KeyWidget debug window")); |
| 98 | parser.addOption(kwdebugOption); |
| 99 | #endif |
| 100 | |
| 101 | /* parse arguments */ |
| 102 | if (!parser.parse(QCoreApplication::arguments())) { |
| 103 | // set error, if there already are some |
| 104 | *errorMessage = parser.errorText(); |
| 105 | return CommandLineError; |
| 106 | } |
| 107 | |
| 108 | /* return requested operation/setup */ |
| 109 | if (parser.isSet(versionOption)) { |
| 110 | // print version and exit |
| 111 | return CommandLineVersionRequested; |
| 112 | } |
| 113 | |
| 114 | if (parser.isSet(helpOption)) { |