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 static void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
11 {
12  auto getFprintfS = [](auto data) {
13  if (data == nullptr)
14  return "";
15  return data;
16  };
17 
18  QByteArray localMsg = msg.toLocal8Bit();
19 
20  switch (type) {
21  case QtDebugMsg:
22  fprintf(stdout, "%s\n", getFprintfS(localMsg.constData()));
23  break;
24  case QtInfoMsg:
25  fprintf(stdout, "Info: %s (%s:%u, %s)\n", getFprintfS(localMsg.constData()), getFprintfS(context.file), context.line, getFprintfS(context.function));
26  break;
27  case QtWarningMsg:
28  fprintf(stderr, "Warning: %s (%s:%u, %s)\n", getFprintfS(localMsg.constData()), getFprintfS(context.file), context.line, getFprintfS(context.function));
29  break;
30  case QtCriticalMsg:
31  fprintf(stderr, "Error: %s (%s:%u, %s)\n", getFprintfS(localMsg.constData()), getFprintfS(context.file), context.line, getFprintfS(context.function));
32  break;
33  case QtFatalMsg:
34  fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", getFprintfS(localMsg.constData()), getFprintfS(context.file), context.line, getFprintfS(context.function));
35  abort();
36  }
37 }
38 
39 int main(int argc, char **argv)
40 {
41  qInstallMessageHandler(messageOutput);
42  QCoreApplication app(argc, argv);
43 
44  const QString description = QStringLiteral("Converts desktop files to json");
45  app.setApplicationVersion(QStringLiteral("1.0"));
46 
47  const auto _i = QStringLiteral("input");
48  const auto _o = QStringLiteral("output");
49  const auto _n = QStringLiteral("name");
50  const auto _c = QStringLiteral("compat");
51  const auto _s = QStringLiteral("serviceType");
52 
53  QCommandLineOption input = QCommandLineOption(QStringList{QStringLiteral("i"), _i}, QStringLiteral("Read input from file"), _n);
54  QCommandLineOption output = QCommandLineOption(QStringList{QStringLiteral("o"), _o}, QStringLiteral("Write output to file"), _n);
55  QCommandLineOption verbose = QCommandLineOption(QStringList{QStringLiteral("verbose")}, QStringLiteral("Enable verbose (debug) output"));
56  QCommandLineOption compat = QCommandLineOption(QStringList{QStringLiteral("c"), _c},
57  QStringLiteral("Generate JSON that is compatible with KPluginInfo instead of the new KPluginMetaData"));
58  QCommandLineOption serviceTypes =
59  QCommandLineOption(QStringList{QStringLiteral("s"), _s},
60  QStringLiteral("The name or full path of a KServiceType definition .desktop file. Can be passed multiple times"),
61  _s);
62 
63  QCommandLineParser parser;
64  parser.addVersionOption();
65  parser.setApplicationDescription(description);
66  parser.addHelpOption();
67  parser.addOption(input);
68  parser.addOption(output);
69  parser.addOption(verbose);
70  parser.addOption(compat);
71  parser.addOption(serviceTypes);
72 
73  DesktopToJson dtj(&parser, input, output, verbose, compat, serviceTypes);
74 
75  parser.process(app);
76  return dtj.runMain();
77 }
QCommandLineOption addVersionOption()
const char * constData() const const
QByteArray toLocal8Bit() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Apr 21 2021 23:01:58 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.