KCoreAddons

main.cpp
1 /*
2  SPDX-FileCopyrightText: 2013 Sebastian K├╝gler <[email protected]>
3  SPDX-FileCopyrightText: 2014 Alex Richardson <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7 
8 #include "desktoptojson.h"
9 
10 
11 static void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
12 {
13  QByteArray localMsg = msg.toLocal8Bit();
14  switch (type) {
15  case QtDebugMsg:
16  fprintf(stdout, "%s\n", localMsg.constData());
17  break;
18  case QtInfoMsg:
19  fprintf(stdout, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
20  break;
21  case QtWarningMsg:
22  fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
23  break;
24  case QtCriticalMsg:
25  fprintf(stderr, "Error: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
26  break;
27  case QtFatalMsg:
28  fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
29  abort();
30  }
31 }
32 
33 
34 int main(int argc, char** argv) {
35  qInstallMessageHandler(messageOutput);
36  QCoreApplication app(argc, argv);
37 
38  const QString description = QStringLiteral("Converts desktop files to json");
39  app.setApplicationVersion(QStringLiteral("1.0"));
40 
41  const auto _i = QStringLiteral("input");
42  const auto _o = QStringLiteral("output");
43  const auto _n = QStringLiteral("name");
44  const auto _c = QStringLiteral("compat");
45  const auto _s = QStringLiteral("serviceType");
46 
47  QCommandLineOption input = QCommandLineOption(QStringList { QStringLiteral("i"), _i },
48  QStringLiteral("Read input from file"), _n);
49  QCommandLineOption output = QCommandLineOption(QStringList { QStringLiteral("o"), _o },
50  QStringLiteral("Write output to file"), _n);
51  QCommandLineOption verbose = QCommandLineOption(QStringList { QStringLiteral("verbose") },
52  QStringLiteral("Enable verbose (debug) output"));
53  QCommandLineOption compat = QCommandLineOption(QStringList { QStringLiteral("c"), _c },
54  QStringLiteral("Generate JSON that is compatible with KPluginInfo instead of the new KPluginMetaData"));
55  QCommandLineOption serviceTypes = QCommandLineOption(QStringList { QStringLiteral("s"), _s },
56  QStringLiteral("The name or full path of a KServiceType definition .desktop file. Can be passed multiple times"), _s);
57 
58  QCommandLineParser parser;
59  parser.addVersionOption();
60  parser.setApplicationDescription(description);
61  parser.addHelpOption();
62  parser.addOption(input);
63  parser.addOption(output);
64  parser.addOption(verbose);
65  parser.addOption(compat);
66  parser.addOption(serviceTypes);
67 
68  DesktopToJson dtj(&parser, input, output, verbose, compat, serviceTypes);
69 
70  parser.process(app);
71  return dtj.runMain();
72 }
QCommandLineOption addVersionOption()
const char * constData() const const
QByteArray toLocal8Bit() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 30 2020 23:10:51 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.