summaryrefslogtreecommitdiff
path: root/qt/tools
diff options
context:
space:
mode:
Diffstat (limited to 'qt/tools')
-rw-r--r--qt/tools/Makefile.am5
-rw-r--r--qt/tools/dbus.cpp397
-rw-r--r--qt/tools/dbuscpp2xml.cpp23
-rw-r--r--qt/tools/dbusidl2cpp.cpp118
4 files changed, 478 insertions, 65 deletions
diff --git a/qt/tools/Makefile.am b/qt/tools/Makefile.am
index a79aafd..4da3870 100644
--- a/qt/tools/Makefile.am
+++ b/qt/tools/Makefile.am
@@ -1,5 +1,5 @@
INCLUDES=-I$(top_srcdir)/qt $(DBUS_CLIENT_CFLAGS) $(DBUS_QT_CFLAGS) -DDBUS_COMPILATION
-bin_PROGRAMS = dbusidl2cpp dbuscpp2xml
+bin_PROGRAMS = dbusidl2cpp dbuscpp2xml dbus
dbusidl2cpp_SOURCES = dbusidl2cpp.cpp
dbusidl2cpp_LDFLAGS = -no-undefined
@@ -8,3 +8,6 @@ dbusidl2cpp_LDADD = $(DBUS_QT_LIBS) ../src/libdbus-qt4-1.la
dbuscpp2xml_SOURCES = dbuscpp2xml.cpp
dbuscpp2xml_LDFLAGS = -no-undefined
dbuscpp2xml_LDADD = $(DBUS_QT_LIBS) ../src/libdbus-qt4-1.la
+
+dbus_SOURCES = dbus.cpp
+dbus_LDADD = $(DBUS_QT_LIBS) ../src/libdbus-qt4-1.la
diff --git a/qt/tools/dbus.cpp b/qt/tools/dbus.cpp
new file mode 100644
index 0000000..b2556ef
--- /dev/null
+++ b/qt/tools/dbus.cpp
@@ -0,0 +1,397 @@
+/* -*- C++ -*-
+ *
+ * Copyright (C) 2006 Trolltech AS. All rights reserved.
+ * Author: Thiago Macieira <thiago.macieira@trolltech.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <dbus/qdbus.h>
+#include <QtCore/QCoreApplication>
+#include <QtCore/QStringList>
+#include <QtCore/qmetaobject.h>
+#include <QtXml/QDomDocument>
+#include <QtXml/QDomElement>
+
+Q_DECLARE_METATYPE(QVariant)
+QDBusConnection *connection;
+
+void listObjects(const QString &service, const QString &path)
+{
+ QDBusInterfacePtr iface(*connection, service, path.isEmpty() ? "/" : path,
+ "org.freedesktop.DBus.Introspectable");
+ if (!iface->isValid()) {
+ QDBusError err(iface->lastError());
+ fprintf(stderr, "Cannot introspect object %s at %s:\n%s (%s)\n",
+ qPrintable(path.isEmpty() ? "/" : path), qPrintable(service),
+ qPrintable(err.name()), qPrintable(err.message()));
+ exit(1);
+ }
+ QDBusReply<QString> xml = iface->call("Introspect");
+
+ if (xml.isError())
+ return; // silently
+
+ QDomDocument doc;
+ doc.setContent(xml);
+ QDomElement node = doc.documentElement();
+ QDomElement child = node.firstChildElement();
+ while (!child.isNull()) {
+ if (child.tagName() == QLatin1String("node")) {
+ QString sub = path + '/' + child.attribute("name");
+ printf("%s\n", qPrintable(sub));
+ listObjects(service, sub);
+ }
+ child = child.nextSiblingElement();
+ }
+}
+
+void listInterface(const QString &service, const QString &path, const QString &interface)
+{
+ QDBusInterfacePtr iface(*connection, service, path, interface);
+ if (!iface->isValid()) {
+ QDBusError err(iface->lastError());
+ fprintf(stderr, "Interface '%s' not available in object %s at %s:\n%s (%s)\n",
+ qPrintable(interface), qPrintable(path), qPrintable(service),
+ qPrintable(err.name()), qPrintable(err.message()));
+ exit(1);
+ }
+ const QMetaObject *mo = iface->metaObject();
+
+ // properties
+ for (int i = mo->propertyOffset(); i < mo->propertyCount(); ++i) {
+ QMetaProperty mp = mo->property(i);
+ printf("property ");
+
+ if (mp.isReadable() && mp.isWritable())
+ printf("readwrite");
+ else if (mp.isReadable())
+ printf("read");
+ else
+ printf("write");
+
+ printf(" %s %s.%s\n", mp.typeName(), qPrintable(interface), mp.name());
+ }
+
+ // methods (signals and slots)
+ for (int i = mo->methodOffset(); i < mo->methodCount(); ++i) {
+ QMetaMethod mm = mo->method(i);
+
+ QByteArray signature = mm.signature();
+ signature.truncate(signature.indexOf('('));
+ printf("%s %s%s%s %s.%s(",
+ mm.methodType() == QMetaMethod::Signal ? "signal" : "method",
+ mm.tag(), *mm.tag() ? " " : "",
+ *mm.typeName() ? mm.typeName() : "void",
+ qPrintable(interface), signature.constData());
+
+ QList<QByteArray> types = mm.parameterTypes();
+ QList<QByteArray> names = mm.parameterNames();
+ bool first = true;
+ for (int i = 0; i < types.count(); ++i) {
+ printf("%s%s",
+ first ? "" : ", ",
+ types.at(i).constData());
+ if (!names.at(i).isEmpty())
+ printf(" %s", names.at(i).constData());
+ first = false;
+ }
+ printf(")\n");
+ }
+}
+
+void listAllInterfaces(const QString &service, const QString &path)
+{
+ QDBusInterfacePtr iface(*connection, service, path, "org.freedesktop.DBus.Introspectable");
+ if (!iface->isValid()) {
+ QDBusError err(iface->lastError());
+ fprintf(stderr, "Cannot introspect object %s at %s:\n%s (%s)\n",
+ qPrintable(path), qPrintable(service),
+ qPrintable(err.name()), qPrintable(err.message()));
+ exit(1);
+ }
+ QDBusReply<QString> xml = iface->call("Introspect");
+
+ if (xml.isError())
+ return; // silently
+
+ QDomDocument doc;
+ doc.setContent(xml);
+ QDomElement node = doc.documentElement();
+ QDomElement child = node.firstChildElement();
+ while (!child.isNull()) {
+ if (child.tagName() == QLatin1String("interface")) {
+ QString ifaceName = child.attribute("name");
+ if (QDBusUtil::isValidInterfaceName(ifaceName))
+ listInterface(service, path, ifaceName);
+ else {
+ qWarning("Invalid D-BUS interface name '%s' found while parsing introspection",
+ qPrintable(ifaceName));
+ }
+ }
+ child = child.nextSiblingElement();
+ }
+}
+
+QStringList readList(int &argc, const char *const *&argv)
+{
+ --argc;
+ ++argv;
+
+ QStringList retval;
+ while (argc && QLatin1String(argv[0]) != ")")
+ retval += QString::fromLocal8Bit(argv[0]);
+
+ return retval;
+}
+
+void placeCall(const QString &service, const QString &path, const QString &interface,
+ const QString &member, int argc, const char *const *argv)
+{
+ QDBusInterfacePtr iface(*connection, service, path, interface);
+ if (!iface->isValid()) {
+ QDBusError err(iface->lastError());
+ fprintf(stderr, "Interface '%s' not available in object %s at %s:\n%s (%s)\n",
+ qPrintable(interface), qPrintable(path), qPrintable(service),
+ qPrintable(err.name()), qPrintable(err.message()));
+ exit(1);
+ }
+
+ const QMetaObject *mo = iface->metaObject();
+ QByteArray match = member.toLatin1();
+ match += '(';
+
+ int midx = -1;
+ for (int i = mo->methodOffset(); i < mo->methodCount(); ++i) {
+ QMetaMethod mm = mo->method(i);
+ QByteArray signature = mm.signature();
+ if (signature.startsWith(match)) {
+ midx = i;
+ break;
+ }
+ }
+
+ if (midx == -1) {
+ fprintf(stderr, "Cannot find '%s.%s' in object %s at %s\n",
+ qPrintable(interface), qPrintable(member), qPrintable(path),
+ qPrintable(service));
+ exit(1);
+ }
+
+ QMetaMethod mm = mo->method(midx);
+ QList<QByteArray> types = mm.parameterTypes();
+
+ QVariantList params;
+ for (int i = 0; argc && i < types.count(); ++i) {
+ int id = QVariant::nameToType(types.at(i));
+ if ((id == QVariant::UserType || id == QVariant::Map) && types.at(i) != "QVariant") {
+ fprintf(stderr, "Sorry, can't pass arg of type %s yet\n",
+ types.at(i).constData());
+ exit(1);
+ }
+ if (id == QVariant::UserType)
+ id = QMetaType::type(types.at(i));
+
+ Q_ASSERT(id);
+
+ QVariant p;
+ if ((id == QVariant::List || id == QVariant::StringList) && QLatin1String("(") == argv[0])
+ p = readList(argc, argv);
+ else
+ p = QString::fromLocal8Bit(argv[0]);
+
+ if (id < int(QVariant::UserType)) {
+ // avoid calling it for QVariant
+ p.convert( QVariant::Type(id) );
+ if (p.type() == QVariant::Invalid) {
+ fprintf(stderr, "Could not convert '%s' to type '%s'.\n",
+ argv[0], types.at(i).constData());
+ exit(1);
+ }
+ } else if (types.at(i) == "QVariant") {
+ QVariant tmp(id, p.constData());
+ p = tmp;
+ }
+ params += p;
+ --argc;
+ ++argv;
+ }
+ if (params.count() != types.count()) {
+ fprintf(stderr, "Invalid number of parameters\n");
+ exit(1);
+ }
+
+ QDBusMessage reply = iface->callWithArgs(member, params);
+ if (reply.type() == QDBusMessage::ErrorMessage) {
+ QDBusError err = reply;
+ printf("Error: %s\n%s\n", qPrintable(err.name()), qPrintable(err.message()));
+ exit(2);
+ } else if (reply.type() != QDBusMessage::ReplyMessage) {
+ fprintf(stderr, "Invalid reply type %d\n", int(reply.type()));
+ exit(1);
+ }
+
+ foreach (QVariant v, reply) {
+ if (v.userType() == QVariant::StringList) {
+ foreach (QString s, v.toStringList())
+ printf("%s\n", qPrintable(s));
+ } else {
+ if (v.userType() == qMetaTypeId<QVariant>())
+ v = qvariant_cast<QVariant>(v);
+ printf("%s\n", qPrintable(v.toString()));
+ }
+ }
+
+ exit(0);
+}
+
+bool splitInterfaceAndName(const QString &interfaceAndName, const char *type,
+ QString &interface, QString &member)
+{
+ interface = interfaceAndName;
+ int pos = interface.lastIndexOf(QLatin1Char('.'));
+ if (pos != -1) {
+ member = interface.mid(pos + 1);
+ interface.truncate(pos);
+ }
+
+ if (!QDBusUtil::isValidInterfaceName(interface)) {
+ fprintf(stderr, "Interface '%s' is not a valid interface name.\n", qPrintable(interface));
+ return false;
+ } else if (!QDBusUtil::isValidMemberName(member)) {
+ fprintf(stderr, "%s name '%s' is not a valid member name.\n", type, qPrintable(member));
+ return false;
+ }
+ return true;
+}
+
+void getProperty(const QString &service, const QString &path, const QString &interfaceAndName)
+{
+ QString property;
+ QString interface;
+ if (!splitInterfaceAndName(interfaceAndName, "Property", interface, property))
+ exit(1);
+
+ QDBusInterfacePtr iface(*connection, service, path, interface);
+ QVariant reply = iface->property(property.toLatin1());
+ if (reply.isNull()) {
+ QDBusError error = iface->lastError();
+ fprintf(stderr, "Could not get property '%s' on interface '%s': %s (%s)\n",
+ qPrintable(property), qPrintable(interface), qPrintable(error.name()),
+ qPrintable(error.message()));
+ exit(1);
+ }
+
+ printf("%s\n", qPrintable(reply.toString()));
+}
+
+void setProperty(const QString &service, const QString &path, const QString &interfaceAndName,
+ const QString &valueStr)
+{
+ QString property;
+ QString interface;
+ if (!splitInterfaceAndName(interfaceAndName, "Property", interface, property))
+ exit(1);
+
+ QDBusInterfacePtr iface(*connection, service, path, interface);
+ iface->setProperty(property.toLatin1(), valueStr);
+}
+
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+ if (argc >= 1 && qstrcmp(argv[1], "--system") == 0) {
+ connection = &QDBus::systemBus();
+ --argc;
+ ++argv;
+ } else
+ connection = &QDBus::sessionBus();
+
+ if (!connection->isConnected()) {
+ fprintf(stderr, "Could not connect to D-Bus server: %s: %s\n",
+ qPrintable(connection->lastError().name()),
+ qPrintable(connection->lastError().message()));
+ return 1;
+ }
+ QDBusBusService *bus = connection->busService();
+
+ if (argc == 1) {
+ QStringList names = bus->ListNames();
+ foreach (QString name, names)
+ printf("%s\n", qPrintable(name));
+ exit(0);
+ }
+
+ QString service = QLatin1String(argv[1]);
+ if (!QDBusUtil::isValidBusName(service)) {
+ fprintf(stderr, "Service '%s' is not a valid name.\n", qPrintable(service));
+ exit(1);
+ }
+ if (!bus->NameHasOwner(service)) {
+ fprintf(stderr, "Service '%s' does not exist.\n", qPrintable(service));
+ exit(1);
+ }
+
+ if (argc == 2) {
+ printf("/\n");
+ listObjects(service, QString());
+ exit(0);
+ }
+
+ QString path = QLatin1String(argv[2]);
+ if (!QDBusUtil::isValidObjectPath(path)) {
+ fprintf(stderr, "Path '%s' is not a valid path name.\n", qPrintable(path));
+ exit(1);
+ }
+ if (argc == 3) {
+ listAllInterfaces(service, path);
+ exit(0);
+ }
+
+ QString interface = QLatin1String(argv[3]);
+ QString member;
+ int pos = interface.lastIndexOf(QLatin1Char('.'));
+ if (pos == -1) {
+ member = interface;
+ interface.clear();
+ } else {
+ member = interface.mid(pos + 1);
+ interface.truncate(pos);
+ }
+ if (!interface.isEmpty() && !QDBusUtil::isValidInterfaceName(interface)) {
+ fprintf(stderr, "Interface '%s' is not a valid interface name.\n", qPrintable(interface));
+ exit(1);
+ }
+ if (!QDBusUtil::isValidMemberName(member)) {
+ fprintf(stderr, "Method name '%s' is not a valid member name.\n", qPrintable(member));
+ exit(1);
+ }
+
+ if (interface.isEmpty()) {
+ if (member.toLower() == QLatin1String("get") && argc == 5) {
+ getProperty(service, path, QLatin1String(argv[4]));
+ return 0;
+ } else if (member.toLower() == QLatin1String("set") && argc == 6) {
+ setProperty(service, path, QLatin1String(argv[4]), QLatin1String(argv[5]));
+ return 0;
+ }
+ }
+ placeCall(service, path, interface, member, argc - 4, argv + 4);
+}
+
diff --git a/qt/tools/dbuscpp2xml.cpp b/qt/tools/dbuscpp2xml.cpp
index dd08b5f..42d7831 100644
--- a/qt/tools/dbuscpp2xml.cpp
+++ b/qt/tools/dbuscpp2xml.cpp
@@ -29,6 +29,7 @@
#include <QRegExp>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
@@ -76,7 +77,7 @@ class MocParser
QIODevice *input;
const char *filename;
- int line;
+ int lineNumber;
public:
~MocParser();
void parse(const char *filename, QIODevice *input, int lineNumber = 0);
@@ -86,13 +87,13 @@ public:
void MocParser::parseError()
{
- fprintf(stderr, PROGRAMNAME ": error parsing input file '%s' line %d \n", filename, line);
+ fprintf(stderr, PROGRAMNAME ": error parsing input file '%s' line %d \n", filename, lineNumber);
exit(1);
}
QByteArray MocParser::readLine()
{
- ++line;
+ ++lineNumber;
return input->readLine();
}
@@ -100,15 +101,15 @@ void MocParser::loadIntData(uint *&data)
{
data = 0; // initialise
QVarLengthArray<uint> array;
- QRegExp rx("(\\d+|0x[0-9abcdef]+)", Qt::CaseInsensitive);
+ QRegExp rx(QLatin1String("(\\d+|0x[0-9abcdef]+)"), Qt::CaseInsensitive);
while (!input->atEnd()) {
QString line = QLatin1String(readLine());
- int pos = line.indexOf("//");
+ int pos = line.indexOf(QLatin1String("//"));
if (pos != -1)
line.truncate(pos); // drop comments
- if (line == "};\n") {
+ if (line == QLatin1String("};\n")) {
// end of data
data = new uint[array.count()];
memcpy(data, array.data(), array.count() * sizeof(*data));
@@ -118,7 +119,7 @@ void MocParser::loadIntData(uint *&data)
pos = 0;
while ((pos = rx.indexIn(line, pos)) != -1) {
QString num = rx.cap(1);
- if (num.startsWith("0x"))
+ if (num.startsWith(QLatin1String("0x")))
array.append(num.mid(2).toUInt(0, 16));
else
array.append(num.toUInt());
@@ -205,7 +206,7 @@ void MocParser::loadStringData(char *&stringdata)
}
} else {
// octal
- QRegExp octal("([0-7]+)");
+ QRegExp octal(QLatin1String("([0-7]+)"));
if (octal.indexIn(QLatin1String(line), start) == -1)
parseError();
array.append(char(octal.cap(1).toInt(0, 8)));
@@ -218,11 +219,11 @@ void MocParser::loadStringData(char *&stringdata)
parseError();
}
-void MocParser::parse(const char *fname, QIODevice *io, int lineNumber)
+void MocParser::parse(const char *fname, QIODevice *io, int lineNum)
{
filename = fname;
input = io;
- line = lineNumber;
+ lineNumber = lineNum;
while (!input->atEnd()) {
QByteArray line = readLine();
@@ -360,7 +361,7 @@ int main(int argc, char **argv)
else {
// run moc on this file
QProcess proc;
- proc.start("moc", QStringList() << QFile::encodeName(argv[i]));
+ proc.start(QLatin1String("moc"), QStringList() << QFile::decodeName(argv[i]));
if (!proc.waitForStarted()) {
fprintf(stderr, PROGRAMNAME ": could not execute moc! Aborting.\n");
diff --git a/qt/tools/dbusidl2cpp.cpp b/qt/tools/dbusidl2cpp.cpp
index 091685b..216c7ce 100644
--- a/qt/tools/dbusidl2cpp.cpp
+++ b/qt/tools/dbusidl2cpp.cpp
@@ -37,7 +37,7 @@
#include "../src/qdbusintrospection_p.h"
#define PROGRAMNAME "dbusidl2cpp"
-#define PROGRAMVERSION "0.4"
+#define PROGRAMVERSION "0.5"
#define PROGRAMCOPYRIGHT "Copyright (C) 2006 Trolltech AS. All rights reserved."
#define ANNOTATION_NO_WAIT "org.freedesktop.DBus.Method.NoReply"
@@ -68,7 +68,9 @@ static const char help[] =
" -V Show the program version and quit.\n"
"\n"
"If the file name given to the options -a and -p does not end in .cpp or .h, the\n"
- "program will automatically append the suffixes and produce both files.\n";
+ "program will automatically append the suffixes and produce both files.\n"
+ "You can also use a colon (:) to separate the header name from the source file\n"
+ "name, as in '-a filename_p.h:filename.cpp'.";
static const char includeList[] =
"#include <QtCore/QByteArray>\n"
@@ -154,7 +156,7 @@ static void parseCmdLine(int argc, char **argv)
static QDBusIntrospection::Interfaces readInput()
{
QFile input(QFile::decodeName(inputFile));
- if (inputFile && QLatin1String("-") != inputFile)
+ if (inputFile && qstrcmp(inputFile, "-") != 0)
input.open(QIODevice::ReadOnly);
else
input.open(stdin, QIODevice::ReadOnly);
@@ -190,9 +192,11 @@ static QString header(const char *name)
if (!name || (name[0] == '-' && name[1] == '\0'))
return QString();
- QString retval = QFile::decodeName(name);
- if (!retval.endsWith(".h") && !retval.endsWith(".cpp") && !retval.endsWith(".cc"))
- retval.append(".h");
+ QStringList parts = QFile::decodeName(name).split(QLatin1Char(':'));
+ QString retval = parts.first();
+ if (!retval.endsWith(QLatin1String(".h")) && !retval.endsWith(QLatin1String(".cpp")) &&
+ !retval.endsWith(QLatin1String(".cc")))
+ retval.append(QLatin1String(".h"));
return retval;
}
@@ -203,9 +207,11 @@ static QString cpp(const char *name)
if (!name || (name[0] == '-' && name[1] == '\0'))
return QString();
- QString retval = QFile::decodeName(name);
- if (!retval.endsWith(".h") && !retval.endsWith(".cpp") && !retval.endsWith(".cc"))
- retval.append(".cpp");
+ QStringList parts = QFile::decodeName(name).split(QLatin1Char(':'));
+ QString retval = parts.last();
+ if (!retval.endsWith(QLatin1String(".h")) && !retval.endsWith(QLatin1String(".cpp")) &&
+ !retval.endsWith(QLatin1String(".cc")))
+ retval.append(QLatin1String(".cpp"));
return retval;
}
@@ -235,7 +241,7 @@ static QString classNameForInterface(const QString &interface, ClassType classTy
if (globalClassName)
return QLatin1String(globalClassName);
- QStringList parts = interface.split('.');
+ QStringList parts = interface.split(QLatin1Char('.'));
QString retval;
if (classType == Proxy)
@@ -249,9 +255,9 @@ static QString classNameForInterface(const QString &interface, ClassType classTy
}
if (classType == Proxy)
- retval += "Interface";
+ retval += QLatin1String("Interface");
else
- retval += "Adaptor";
+ retval += QLatin1String("Adaptor");
return retval;
}
@@ -283,7 +289,7 @@ static QString constRefArg(const QByteArray &arg)
if (!arg.startsWith('Q'))
return QLatin1String(arg + ' ');
else
- return QString("const %1 &").arg( QLatin1String(arg) );
+ return QString( QLatin1String("const %1 &") ).arg( QLatin1String(arg) );
}
static QStringList makeArgNames(const QDBusIntrospection::Arguments &inputArgs,
@@ -295,18 +301,18 @@ static QStringList makeArgNames(const QDBusIntrospection::Arguments &inputArgs,
const QDBusIntrospection::Argument &arg = inputArgs.at(i);
QString name = arg.name;
if (name.isEmpty())
- name = QString("in%1").arg(i);
+ name = QString( QLatin1String("in%1") ).arg(i);
while (retval.contains(name))
- name += "_";
+ name += QLatin1String("_");
retval << name;
}
for (int i = 0; i < outputArgs.count(); ++i) {
const QDBusIntrospection::Argument &arg = outputArgs.at(i);
QString name = arg.name;
if (name.isEmpty())
- name = QString("out%1").arg(i);
+ name = QString( QLatin1String("out%1") ).arg(i);
while (retval.contains(name))
- name += "_";
+ name += QLatin1String("_");
retval << name;
}
return retval;
@@ -346,7 +352,7 @@ static void writeArgList(QTextStream &ts, const QStringList &argNames,
static QString propertyGetter(const QDBusIntrospection::Property &property)
{
- QString getter = property.annotations.value("com.trolltech.QtDBus.propertyGetter");
+ QString getter = property.annotations.value(QLatin1String("com.trolltech.QtDBus.propertyGetter"));
if (getter.isEmpty()) {
getter = property.name;
getter[0] = getter[0].toLower();
@@ -356,9 +362,9 @@ static QString propertyGetter(const QDBusIntrospection::Property &property)
static QString propertySetter(const QDBusIntrospection::Property &property)
{
- QString setter = property.annotations.value("com.trolltech.QtDBus.propertySetter");
+ QString setter = property.annotations.value(QLatin1String("com.trolltech.QtDBus.propertySetter"));
if (setter.isEmpty()) {
- setter = "set" + property.name;
+ setter = QLatin1String("set") + property.name;
setter[3] = setter[3].toUpper();
}
return setter;
@@ -369,21 +375,21 @@ static QString stringify(const QString &data)
QString retval;
int i;
for (i = 0; i < data.length(); ++i) {
- retval += '\"';
- for ( ; i < data.length() && data[i] != QChar('\n'); ++i)
- if (data[i] == '\"')
- retval += "\\\"";
+ retval += QLatin1Char('\"');
+ for ( ; i < data.length() && data[i] != QLatin1Char('\n'); ++i)
+ if (data[i] == QLatin1Char('\"'))
+ retval += QLatin1String("\\\"");
else
retval += data[i];
- retval += "\\n\"\n";
+ retval += QLatin1String("\\n\"\n");
}
return retval;
}
-static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfaces &interfaces)
+static void writeProxy(const char *filename, const QDBusIntrospection::Interfaces &interfaces)
{
// open the file
- QString headerName = header(proxyFile);
+ QString headerName = header(filename);
QFile file(headerName);
if (!headerName.isEmpty())
file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
@@ -391,7 +397,7 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac
file.open(stdout, QIODevice::WriteOnly | QIODevice::Text);
QTextStream hs(&file);
- QString cppName = cpp(proxyFile);
+ QString cppName = cpp(filename);
QByteArray cppData;
QTextStream cs(&cppData);
@@ -401,14 +407,14 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac
// include guards:
QString includeGuard;
if (!headerName.isEmpty()) {
- includeGuard = headerName.toUpper().replace(QChar('.'), QChar('_'));
- int pos = includeGuard.lastIndexOf('/');
+ includeGuard = headerName.toUpper().replace(QLatin1Char('.'), QLatin1Char('_'));
+ int pos = includeGuard.lastIndexOf(QLatin1Char('/'));
if (pos != -1)
includeGuard = includeGuard.mid(pos + 1);
} else {
- includeGuard = QString("QDBUSIDL2CPP_PROXY");
+ includeGuard = QLatin1String("QDBUSIDL2CPP_PROXY");
}
- includeGuard = QString("%1_%2%3")
+ includeGuard = QString(QLatin1String("%1_%2%3"))
.arg(includeGuard)
.arg(getpid())
.arg(QDateTime::currentDateTime().toTime_t());
@@ -512,7 +518,8 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac
// methods:
hs << "public Q_SLOTS: // METHODS" << endl;
foreach (const QDBusIntrospection::Method &method, interface->methods) {
- bool isAsync = method.annotations.value(ANNOTATION_NO_WAIT) == "true";
+ bool isAsync =
+ method.annotations.value(QLatin1String(ANNOTATION_NO_WAIT)) == QLatin1String("true");
if (isAsync && !method.outputArgs.isEmpty()) {
fprintf(stderr, "warning: method %s in interface %s is marked 'async' but has output arguments.\n",
qPrintable(method.name), qPrintable(interface->name));
@@ -521,7 +528,7 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac
hs << " inline ";
- if (method.annotations.value("org.freedesktop.DBus.Deprecated") == "true")
+ if (method.annotations.value(QLatin1String("org.freedesktop.DBus.Deprecated")) == QLatin1String("true"))
hs << "Q_DECL_DEPRECATED ";
if (isAsync)
@@ -548,7 +555,7 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac
hs << " call(NoWaitForReply, QLatin1String(\"";
// rebuild the method input signature:
- QString signature = QChar('.');
+ QString signature = QLatin1String(".");
foreach (const QDBusIntrospection::Argument &arg, method.inputArgs)
signature += arg.type;
if (signature.length() == 1)
@@ -583,7 +590,8 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac
hs << "Q_SIGNALS: // SIGNALS" << endl;
foreach (const QDBusIntrospection::Signal &signal, interface->signals_) {
hs << " ";
- if (signal.annotations.value("org.freedesktop.DBus.Deprecated") == "true")
+ if (signal.annotations.value(QLatin1String("org.freedesktop.DBus.Deprecated")) ==
+ QLatin1String("true"))
hs << "Q_DECL_DEPRECATED ";
hs << "void " << signal.name << "(";
@@ -607,7 +615,7 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac
QStringList current;
QString name;
if (it != interfaces.constEnd()) {
- current = it->constData()->name.split('.');
+ current = it->constData()->name.split(QLatin1Char('.'));
name = current.takeLast();
}
@@ -618,15 +626,15 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac
// i parts matched
// close last.count() - i namespaces:
for (int j = i; j < last.count(); ++j)
- hs << QString((last.count() - j - 1 + i) * 2, ' ') << "}" << endl;
+ hs << QString((last.count() - j - 1 + i) * 2, QLatin1Char(' ')) << "}" << endl;
// open current.count() - i namespaces
for (int j = i; j < current.count(); ++j)
- hs << QString(j * 2, ' ') << "namespace " << current.at(j) << " {" << endl;
+ hs << QString(j * 2, QLatin1Char(' ')) << "namespace " << current.at(j) << " {" << endl;
// add this class:
if (!name.isEmpty()) {
- hs << QString(current.count() * 2, ' ')
+ hs << QString(current.count() * 2, QLatin1Char(' '))
<< "typedef ::" << classNameForInterface(it->constData()->name, Proxy)
<< " " << name << ";" << endl;
}
@@ -643,7 +651,7 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac
if (includeMocs)
cs << endl
- << "#include \"" << proxyFile << ".moc\"" << endl;
+ << "#include \"" << filename << ".moc\"" << endl;
cs.flush();
hs.flush();
@@ -657,10 +665,10 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac
}
}
-static void writeAdaptor(const char *adaptorFile, const QDBusIntrospection::Interfaces &interfaces)
+static void writeAdaptor(const char *filename, const QDBusIntrospection::Interfaces &interfaces)
{
// open the file
- QString headerName = header(adaptorFile);
+ QString headerName = header(filename);
QFile file(headerName);
if (!headerName.isEmpty())
file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
@@ -668,7 +676,7 @@ static void writeAdaptor(const char *adaptorFile, const QDBusIntrospection::Inte
file.open(stdout, QIODevice::WriteOnly | QIODevice::Text);
QTextStream hs(&file);
- QString cppName = cpp(adaptorFile);
+ QString cppName = cpp(filename);
QByteArray cppData;
QTextStream cs(&cppData);
@@ -678,14 +686,14 @@ static void writeAdaptor(const char *adaptorFile, const QDBusIntrospection::Inte
// include guards:
QString includeGuard;
if (!headerName.isEmpty()) {
- includeGuard = headerName.toUpper().replace(QChar('.'), QChar('_'));
- int pos = includeGuard.lastIndexOf('/');
+ includeGuard = headerName.toUpper().replace(QLatin1Char('.'), QLatin1Char('_'));
+ int pos = includeGuard.lastIndexOf(QLatin1Char('/'));
if (pos != -1)
includeGuard = includeGuard.mid(pos + 1);
} else {
- includeGuard = QString("QDBUSIDL2CPP_ADAPTOR");
+ includeGuard = QLatin1String("QDBUSIDL2CPP_ADAPTOR");
}
- includeGuard = QString("%1_%2%3")
+ includeGuard = QString(QLatin1String("%1_%2%3"))
.arg(includeGuard)
.arg(getpid())
.arg(QDateTime::currentDateTime().toTime_t());
@@ -794,7 +802,8 @@ static void writeAdaptor(const char *adaptorFile, const QDBusIntrospection::Inte
hs << "public Q_SLOTS: // METHODS" << endl;
foreach (const QDBusIntrospection::Method &method, interface->methods) {
- bool isAsync = method.annotations.value(ANNOTATION_NO_WAIT) == "true";
+ bool isAsync =
+ method.annotations.value(QLatin1String(ANNOTATION_NO_WAIT)) == QLatin1String("true");
if (isAsync && !method.outputArgs.isEmpty()) {
fprintf(stderr, "warning: method %s in interface %s is marked 'async' but has output arguments.\n",
qPrintable(method.name), qPrintable(interface->name));
@@ -802,7 +811,8 @@ static void writeAdaptor(const char *adaptorFile, const QDBusIntrospection::Inte
}
hs << " ";
- if (method.annotations.value("org.freedesktop.DBus.Deprecated") == "true")
+ if (method.annotations.value(QLatin1String("org.freedesktop.DBus.Deprecated")) ==
+ QLatin1String("true"))
hs << "Q_DECL_DEPRECATED ";
QByteArray returnType;
@@ -888,7 +898,8 @@ static void writeAdaptor(const char *adaptorFile, const QDBusIntrospection::Inte
hs << "Q_SIGNALS: // SIGNALS" << endl;
foreach (const QDBusIntrospection::Signal &signal, interface->signals_) {
hs << " ";
- if (signal.annotations.value("org.freedesktop.DBus.Deprecated") == "true")
+ if (signal.annotations.value(QLatin1String("org.freedesktop.DBus.Deprecated")) ==
+ QLatin1String("true"))
hs << "Q_DECL_DEPRECATED ";
hs << "void " << signal.name << "(";
@@ -909,7 +920,7 @@ static void writeAdaptor(const char *adaptorFile, const QDBusIntrospection::Inte
if (includeMocs)
cs << endl
- << "#include \"" << adaptorFile << ".moc\"" << endl;
+ << "#include \"" << filename << ".moc\"" << endl;
cs.flush();
hs.flush();
@@ -930,7 +941,8 @@ int main(int argc, char **argv)
QDBusIntrospection::Interfaces interfaces = readInput();
cleanInterfaces(interfaces);
- writeProxy(proxyFile, interfaces);
+ if (proxyFile || (!proxyFile && !adaptorFile))
+ writeProxy(proxyFile, interfaces);
if (adaptorFile)
writeAdaptor(adaptorFile, interfaces);