File indexing completed on 2024-05-12 15:34:49
0001 /* 0002 SPDX-FileCopyrightText: 2013 Sebastian Kügler <sebas@kde.org> 0003 SPDX-FileCopyrightText: 2014 Alex Richardson <arichardson.kde@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #include "desktoptojson.h" 0009 0010 static void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) 0011 { 0012 auto getFprintfS = [](auto data) { 0013 if (data == nullptr) { 0014 return ""; 0015 } 0016 return data; 0017 }; 0018 0019 QByteArray localMsg = msg.toLocal8Bit(); 0020 0021 switch (type) { 0022 case QtDebugMsg: 0023 fprintf(stdout, "%s\n", getFprintfS(localMsg.constData())); 0024 break; 0025 case QtInfoMsg: 0026 fprintf(stdout, "Info: %s (%s:%u, %s)\n", getFprintfS(localMsg.constData()), getFprintfS(context.file), context.line, getFprintfS(context.function)); 0027 break; 0028 case QtWarningMsg: 0029 fprintf(stderr, "Warning: %s (%s:%u, %s)\n", getFprintfS(localMsg.constData()), getFprintfS(context.file), context.line, getFprintfS(context.function)); 0030 break; 0031 case QtCriticalMsg: 0032 fprintf(stderr, "Error: %s (%s:%u, %s)\n", getFprintfS(localMsg.constData()), getFprintfS(context.file), context.line, getFprintfS(context.function)); 0033 break; 0034 case QtFatalMsg: 0035 fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", getFprintfS(localMsg.constData()), getFprintfS(context.file), context.line, getFprintfS(context.function)); 0036 abort(); 0037 } 0038 } 0039 0040 int main(int argc, char **argv) 0041 { 0042 qInstallMessageHandler(messageOutput); 0043 QCoreApplication app(argc, argv); 0044 0045 const QString description = QStringLiteral("Converts desktop files to json"); 0046 app.setApplicationVersion(QStringLiteral("1.0")); 0047 0048 const auto _i = QStringLiteral("input"); 0049 const auto _o = QStringLiteral("output"); 0050 const auto _n = QStringLiteral("name"); 0051 const auto _c = QStringLiteral("compat"); 0052 const auto _s = QStringLiteral("serviceType"); 0053 0054 QCommandLineOption input = QCommandLineOption(QStringList{QStringLiteral("i"), _i}, QStringLiteral("Read input from file"), _n); 0055 QCommandLineOption output = QCommandLineOption(QStringList{QStringLiteral("o"), _o}, QStringLiteral("Write output to file"), _n); 0056 QCommandLineOption verbose = QCommandLineOption(QStringList{QStringLiteral("verbose")}, QStringLiteral("Enable verbose (debug) output")); 0057 QCommandLineOption compat = QCommandLineOption(QStringList{QStringLiteral("c"), _c}, 0058 QStringLiteral("Generate JSON that is compatible with KPluginInfo instead of the new KPluginMetaData")); 0059 QCommandLineOption serviceTypes = 0060 QCommandLineOption(QStringList{QStringLiteral("s"), _s}, 0061 QStringLiteral("The name or full path of a KServiceType definition .desktop file. Can be passed multiple times"), 0062 _s); 0063 QCommandLineOption genericDataPath = 0064 QCommandLineOption(QStringList{QStringLiteral("generic-data-path")}, 0065 QStringLiteral("Override the default search path for service types (useful when cross-compiling). Can be passed multiple times"), 0066 QStringLiteral("PATH")); 0067 QCommandLineOption strictPathMode = QCommandLineOption(QStringList{QStringLiteral("strict-path-mode")}, 0068 QStringLiteral("Only search for service types in the explicitly listed data directories.")); 0069 0070 QCommandLineParser parser; 0071 parser.addVersionOption(); 0072 parser.setApplicationDescription(description); 0073 parser.addHelpOption(); 0074 parser.addOption(input); 0075 parser.addOption(output); 0076 parser.addOption(verbose); 0077 parser.addOption(compat); 0078 parser.addOption(serviceTypes); 0079 parser.addOption(genericDataPath); 0080 parser.addOption(strictPathMode); 0081 0082 DesktopToJson dtj(&parser, input, output, verbose, compat, serviceTypes, strictPathMode, genericDataPath); 0083 0084 parser.process(app); 0085 return dtj.runMain(); 0086 }