summaryrefslogtreecommitdiffstats
path: root/src/tools/qdbuscpp2xml/qdbuscpp2xml.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/qdbuscpp2xml/qdbuscpp2xml.cpp')
-rw-r--r--src/tools/qdbuscpp2xml/qdbuscpp2xml.cpp49
1 files changed, 35 insertions, 14 deletions
diff --git a/src/tools/qdbuscpp2xml/qdbuscpp2xml.cpp b/src/tools/qdbuscpp2xml/qdbuscpp2xml.cpp
index 6a9ea0c81e..3b7d73894b 100644
--- a/src/tools/qdbuscpp2xml/qdbuscpp2xml.cpp
+++ b/src/tools/qdbuscpp2xml/qdbuscpp2xml.cpp
@@ -15,6 +15,7 @@
#include <qdbusconnection.h> // for the Export* flags
#include <private/qdbusconnection_p.h> // for the qDBusCheckAsyncTag
+#include <private/qdbusmetatype_p.h> // for QDBusMetaTypeId::init()
using namespace Qt::StringLiterals;
@@ -37,7 +38,7 @@ static const char docTypeHeader[] =
#define PROGRAMNAME "qdbuscpp2xml"
#define PROGRAMVERSION "0.2"
-#define PROGRAMCOPYRIGHT "Copyright (C) 2022 The Qt Company Ltd."
+#define PROGRAMCOPYRIGHT QT_COPYRIGHT
static QString outputFile;
static int flags;
@@ -110,13 +111,13 @@ static QString addFunction(const FunctionDef &mm, bool isSignal = false) {
qWarning() << qPrintable(errorMsg);
return QString(); // invalid form
}
- if (isSignal && inputCount + 1 != types.count())
+ if (isSignal && inputCount + 1 != types.size())
return QString(); // signal with output arguments?
if (isSignal && types.at(inputCount) == QDBusMetaTypeId::message())
return QString(); // signal with QDBusMessage argument?
bool isScriptable = mm.isScriptable;
- for (qsizetype j = 1; j < types.count(); ++j) {
+ for (qsizetype j = 1; j < types.size(); ++j) {
// input parameter for a slot or output for a signal
if (types.at(j) == QDBusMetaTypeId::message()) {
isScriptable = true;
@@ -184,6 +185,8 @@ static QString generateInterfaceXml(const ClassDef *mo)
access |= 1;
if (!mp.write.isEmpty())
access |= 2;
+ if (!mp.member.isEmpty())
+ access |= 3;
int typeId = QMetaType::fromName(mp.type).id();
if (!typeId) {
@@ -253,7 +256,7 @@ QString qDBusInterfaceFromClassDef(const ClassDef *mo)
if (interface.startsWith("QDBus"_L1)) {
interface.prepend("org.qtproject.QtDBus."_L1);
} else if (interface.startsWith(u'Q') &&
- interface.length() >= 2 && interface.at(1).isUpper()) {
+ interface.size() >= 2 && interface.at(1).isUpper()) {
// assume it's Qt
interface.prepend("local.org.qtproject.Qt."_L1);
} else {
@@ -333,7 +336,7 @@ static std::deque<CustomType> s_customTypes;
static void parseCmdLine(QStringList &arguments)
{
flags = 0;
- for (qsizetype i = 0; i < arguments.count(); ++i) {
+ for (qsizetype i = 0; i < arguments.size(); ++i) {
const QString arg = arguments.at(i);
if (arg == "--help"_L1)
@@ -373,7 +376,7 @@ static void parseCmdLine(QStringList &arguments)
break;
case 't':
- if (arguments.count() < i + 2) {
+ if (arguments.size() < i + 2) {
printf("-t expects a type=dbustype argument\n");
exit(1);
} else {
@@ -394,7 +397,7 @@ static void parseCmdLine(QStringList &arguments)
break;
case 'o':
- if (arguments.count() < i + 2 || arguments.at(i + 1).startsWith(u'-')) {
+ if (arguments.size() < i + 2 || arguments.at(i + 1).startsWith(u'-')) {
printf("-o expects a filename\n");
exit(1);
}
@@ -429,16 +432,30 @@ int main(int argc, char **argv)
args.append(QString::fromLocal8Bit(argv[n]));
parseCmdLine(args);
+ QDBusMetaTypeId::init();
+
QList<ClassDef> classes;
+ if (args.isEmpty())
+ args << u"-"_s;
for (const auto &arg: std::as_const(args)) {
- if (arg.startsWith(u'-'))
+ if (arg.startsWith(u'-') && arg.size() > 1)
continue;
- QFile f(arg);
- if (!f.open(QIODevice::ReadOnly|QIODevice::Text)) {
+ QFile f;
+ bool fileIsOpen;
+ QString fileName;
+ if (arg == u'-') {
+ fileName = "stdin"_L1;
+ fileIsOpen = f.open(stdin, QIODevice::ReadOnly | QIODevice::Text);
+ } else {
+ fileName = arg;
+ f.setFileName(arg);
+ fileIsOpen = f.open(QIODevice::ReadOnly | QIODevice::Text);
+ }
+ if (!fileIsOpen) {
fprintf(stderr, PROGRAMNAME ": could not open '%s': %s\n",
- qPrintable(arg), qPrintable(f.errorString()));
+ qPrintable(fileName), qPrintable(f.errorString()));
return 1;
}
@@ -464,11 +481,15 @@ int main(int argc, char **argv)
QFile output;
if (outputFile.isEmpty()) {
- output.open(stdout, QIODevice::WriteOnly);
+ if (!output.open(stdout, QIODevice::WriteOnly)) {
+ fprintf(stderr, PROGRAMNAME ": could not open standard output: %s\n",
+ qPrintable(output.errorString()));
+ return 1;
+ }
} else {
output.setFileName(outputFile);
if (!output.open(QIODevice::WriteOnly)) {
- fprintf(stderr, PROGRAMNAME ": could not open output file '%s': %s",
+ fprintf(stderr, PROGRAMNAME ": could not open output file '%s': %s\n",
qPrintable(outputFile), qPrintable(output.errorString()));
return 1;
}
@@ -476,7 +497,7 @@ int main(int argc, char **argv)
output.write(docTypeHeader);
output.write("<node>\n");
- for (const ClassDef &cdef : qAsConst(classes)) {
+ for (const ClassDef &cdef : std::as_const(classes)) {
QString xml = qDBusGenerateClassDefXml(&cdef);
output.write(std::move(xml).toLocal8Bit());
}