summaryrefslogtreecommitdiff
path: root/qt
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@trolltech.com>2006-06-11 12:16:30 +0000
committerJohn Palmieri <johnp@remedyz.boston.redhat.com>2006-06-28 08:15:18 -0400
commit38e1e06941b5fc0ca4636613085a37373f9a3302 (patch)
tree69c106c2c2c346f3c2e6dcb98c10a15f86b58cb9 /qt
parentb7d95a26759ec2dd0989c33f65114f8bd554d13a (diff)
* qt/tools/dbuscpp2xml.cpp: Compile on Windows. * qt/tools/dbusidl2cpp.cpp: Add missing newline.
* qt/examples/Makefile.am: * qt/examples/chat.h: Use UI-generated files with the ui_*.h form. * qt/src/qdbusmarshall.cpp: Allow sending of QString() and QByteArray() (nulls) over the bus. * qt/src/qdbusabstractinterface.cpp: Use the correct variable, the one that has the signature suffix stripped. * qt/src/qdbusreply.h: Make some methods const.
Diffstat (limited to 'qt')
-rw-r--r--qt/examples/Makefile.am8
-rw-r--r--qt/examples/chat.h4
-rw-r--r--qt/src/qdbusabstractinterface.cpp2
-rw-r--r--qt/src/qdbusmarshall.cpp102
-rw-r--r--qt/src/qdbusreply.h6
-rw-r--r--qt/tools/dbuscpp2xml.cpp1
-rw-r--r--qt/tools/dbusidl2cpp.cpp2
7 files changed, 77 insertions, 48 deletions
diff --git a/qt/examples/Makefile.am b/qt/examples/Makefile.am
index ab56944..5b5e733 100644
--- a/qt/examples/Makefile.am
+++ b/qt/examples/Makefile.am
@@ -5,9 +5,9 @@ if HAVE_QT_GUI
chat_LDADD = $(LDADD) $(DBUS_QT_GUI_LIBS)
dist_chat_SOURCES = chat.cpp chat.h chatadaptor.cpp
nodist_chat_SOURCES = chatinterface.cpp
-chat.o: chatmainwindow.h chatsetnickname.h chatinterface.h chatadaptor.h chat.moc chatadaptor.moc
-chatmainwindow.h: chatmainwindow.ui
-chatsetnickname.h: chatsetnickname.ui
+chat.o: ui_chatmainwindow.h ui_chatsetnickname.h chatinterface.h chatadaptor.h chat.moc chatadaptor.moc
+ui_chatmainwindow.h: chatmainwindow.ui
+ui_chatsetnickname.h: chatsetnickname.ui
chatinterface.cpp chatinterface.h: com.trolltech.ChatInterface.xml
../tools/dbusidl2cpp -m -p chatinterface $?
$(QT_MOC) -o chatinterface.moc chatinterface.h
@@ -37,6 +37,6 @@ CLEANFILES = chat.moc chatadaptor.moc complexping.moc complexpong.moc pong.moc \
%.moc: %.h
$(QT_MOC) $< > $@
-%.h: %.ui
+ui_%.h: %.ui
$(QT_UIC) -o $@ $?
diff --git a/qt/examples/chat.h b/qt/examples/chat.h
index 12c33d4..b0e50a3 100644
--- a/qt/examples/chat.h
+++ b/qt/examples/chat.h
@@ -24,8 +24,8 @@
#include <QtCore/QStringList>
#include <dbus/qdbus.h>
-#include "chatmainwindow.h"
-#include "chatsetnickname.h"
+#include "ui_chatmainwindow.h"
+#include "ui_chatsetnickname.h"
class ChatMainWindow: public QMainWindow, Ui::ChatMainWindow
{
diff --git a/qt/src/qdbusabstractinterface.cpp b/qt/src/qdbusabstractinterface.cpp
index ffe5d67..1b03814 100644
--- a/qt/src/qdbusabstractinterface.cpp
+++ b/qt/src/qdbusabstractinterface.cpp
@@ -220,7 +220,7 @@ QDBusMessage QDBusAbstractInterface::callWithArgs(const QString& method, const Q
// determine if this a sync or async call
mode = NoUseEventLoop;
const QMetaObject *mo = metaObject();
- QByteArray match = method.toLatin1() + '(';
+ QByteArray match = m.toLatin1() + '(';
for (int i = staticMetaObject.methodCount(); i < mo->methodCount(); ++i) {
QMetaMethod mm = mo->method(i);
diff --git a/qt/src/qdbusmarshall.cpp b/qt/src/qdbusmarshall.cpp
index 6209ffb..0d90fcd 100644
--- a/qt/src/qdbusmarshall.cpp
+++ b/qt/src/qdbusmarshall.cpp
@@ -213,7 +213,7 @@ static bool checkType(QVariant &var, QDBusType &type)
if (!type.isValid()) {
// guess it from the variant
type = QDBusType::guessFromVariant(var);
- return true;
+ return type.isValid();
}
int id = var.userType();
@@ -327,10 +327,10 @@ static bool checkType(QVariant &var, QDBusType &type)
return false;
}
-static void qVariantToIteratorInternal(DBusMessageIter *it, const QVariant &var,
+static bool qVariantToIteratorInternal(DBusMessageIter *it, const QVariant &var,
const QDBusType &type);
-static void qListToIterator(DBusMessageIter *it, const QList<QVariant> &list,
+static bool qListToIterator(DBusMessageIter *it, const QList<QVariant> &list,
const QDBusTypeList &typelist);
template<typename T>
@@ -348,9 +348,10 @@ static void qAppendListToMessage(DBusMessageIter *it, const QDBusType &subType,
qIterAppend(it, subType, static_cast<DBusType>(item));
}
-static void qAppendArrayToMessage(DBusMessageIter *it, const QDBusType &subType,
+static bool qAppendArrayToMessage(DBusMessageIter *it, const QDBusType &subType,
const QVariant &var)
{
+ bool ok = false;
DBusMessageIter sub;
dbus_message_iter_open_container(it, DBUS_TYPE_ARRAY, subType.dbusSignature(), &sub);
@@ -360,6 +361,7 @@ static void qAppendArrayToMessage(DBusMessageIter *it, const QDBusType &subType,
const QStringList list = var.toStringList();
foreach (QString str, list)
qIterAppend(&sub, subType, str.toUtf8().constData());
+ ok = true;
break;
}
@@ -367,20 +369,25 @@ static void qAppendArrayToMessage(DBusMessageIter *it, const QDBusType &subType,
const QByteArray array = var.toByteArray();
const char* cdata = array.constData();
dbus_message_iter_append_fixed_array(&sub, DBUS_TYPE_BYTE, &cdata, array.length());
+ ok = true;
break;
}
case QVariant::Map: {
const QVariantMap map = var.toMap();
const QDBusTypeList& subTypes = subType.subTypes();
+
+ ok = true;
for (QMap<QString, QVariant>::const_iterator mit = map.constBegin();
- mit != map.constEnd(); ++mit) {
+ ok && mit != map.constEnd(); ++mit) {
DBusMessageIter itemIterator;
dbus_message_iter_open_container(&sub, DBUS_TYPE_DICT_ENTRY, 0, &itemIterator);
// let the string be converted to QVariant
- qVariantToIteratorInternal(&itemIterator, mit.key(), subTypes[0]);
- qVariantToIteratorInternal(&itemIterator, mit.value(), subTypes[1]);
+ if (!qVariantToIteratorInternal(&itemIterator, mit.key(), subTypes[0]))
+ ok = false;
+ else if (!qVariantToIteratorInternal(&itemIterator, mit.value(), subTypes[1]))
+ ok = false;
dbus_message_iter_close_container(&sub, &itemIterator);
}
@@ -389,13 +396,18 @@ static void qAppendArrayToMessage(DBusMessageIter *it, const QDBusType &subType,
case QVariant::List: {
const QVariantList list = var.toList();
+ ok = true;
foreach (QVariant v, list)
- qVariantToIteratorInternal(&sub, v, subType);
+ if (!qVariantToIteratorInternal(&sub, v, subType)) {
+ ok = false;
+ break;
+ }
break;
}
default: {
int id = var.userType();
+ ok = true;
if (id == QDBusTypeHelper<bool>::listId())
qAppendListToMessage<dbus_bool_t,bool>(&sub, subType, var);
else if (id == QDBusTypeHelper<short>::listId())
@@ -416,25 +428,29 @@ static void qAppendArrayToMessage(DBusMessageIter *it, const QDBusType &subType,
else if (id == QDBusTypeHelper<QVariant>::listId())
qAppendListToMessage<QVariant,QVariant>(&sub, subType, var);
#endif
- else
+ else {
qFatal("qAppendArrayToMessage got unknown type!");
+ ok = false;
+ }
break;
}
}
dbus_message_iter_close_container(it, &sub);
+ return ok;
}
-static void qAppendStructToMessage(DBusMessageIter *it, const QDBusTypeList &typeList,
+static bool qAppendStructToMessage(DBusMessageIter *it, const QDBusTypeList &typeList,
const QVariantList &list)
{
DBusMessageIter sub;
dbus_message_iter_open_container(it, DBUS_TYPE_STRUCT, NULL, &sub);
- qListToIterator(&sub, list, typeList);
+ bool ok = qListToIterator(&sub, list, typeList);
dbus_message_iter_close_container(it, &sub);
+ return ok;
}
-static void qAppendVariantToMessage(DBusMessageIter *it, const QDBusType &type,
+static bool qAppendVariantToMessage(DBusMessageIter *it, const QDBusType &type,
const QVariant &var)
{
Q_UNUSED(type); // type is 'v'
@@ -444,25 +460,32 @@ static void qAppendVariantToMessage(DBusMessageIter *it, const QDBusType &type,
arg = QDBusTypeHelper<QVariant>::fromVariant(var); // extract the inner variant
QDBusType t = QDBusType::guessFromVariant(arg);
+ if (!t.isValid())
+ return false;
// now add this variant
DBusMessageIter sub;
dbus_message_iter_open_container(it, DBUS_TYPE_VARIANT, t.dbusSignature(), &sub);
qVariantToIteratorInternal(&sub, arg, t);
dbus_message_iter_close_container(it, &sub);
+
+ return true; // success
}
-static void qVariantToIterator(DBusMessageIter *it, QVariant var, QDBusType type)
+static bool qVariantToIterator(DBusMessageIter *it, QVariant var, QDBusType type)
{
- if (var.isNull() && !type.isValid())
- return; // cannot add a null like this
+ if (!var.isValid()) {
+ qWarning("QDBusMarshall: invalid QVariant entry found");
+ return false;
+ }
if (!checkType(var, type))
- return; // type checking failed
+ // warning has been printed
+ return false; // type checking failed
- qVariantToIteratorInternal(it, var, type);
+ return qVariantToIteratorInternal(it, var, type);
}
-static void qVariantToIteratorInternal(DBusMessageIter *it, const QVariant &var,
+static bool qVariantToIteratorInternal(DBusMessageIter *it, const QVariant &var,
const QDBusType &type)
{
switch (type.dbusType()) {
@@ -502,42 +525,47 @@ static void qVariantToIteratorInternal(DBusMessageIter *it, const QVariant &var,
// compound types:
case DBUS_TYPE_ARRAY:
// could be many things
- qAppendArrayToMessage( it, type.arrayElement(), var );
- break;
+ return qAppendArrayToMessage( it, type.arrayElement(), var );
case DBUS_TYPE_VARIANT:
- qAppendVariantToMessage( it, type, var );
- break;
+ return qAppendVariantToMessage( it, type, var );
case DBUS_TYPE_STRUCT:
- qAppendStructToMessage( it, type.subTypes(), var.toList() );
- break;
+ return qAppendStructToMessage( it, type.subTypes(), var.toList() );
case DBUS_TYPE_DICT_ENTRY:
qFatal("qVariantToIterator got a DICT_ENTRY!");
- break;
+ return false;
default:
qWarning("Found unknown DBus type '%s'", type.dbusSignature().constData());
- break;
+ return false;
}
+
+ return true;
}
-void qListToIterator(DBusMessageIter *it, const QList<QVariant> &list)
+bool qListToIterator(DBusMessageIter *it, const QList<QVariant> &list)
{
for (int i = 0; i < list.count(); ++i)
- qVariantToIterator(it, list.at(i), QDBusType());
+ if (!qVariantToIterator(it, list.at(i), QDBusType()))
+ return false;
+
+ return true;
}
-void qListToIterator(DBusMessageIter *it, const QList<QVariant> &list, const QDBusTypeList &types)
+bool qListToIterator(DBusMessageIter *it, const QList<QVariant> &list, const QDBusTypeList &types)
{
- int min = qMin(list.count(), types.count());
- for (int i = 0; i < min; ++i)
- qVariantToIterator(it, list.at(i), types.at(i));
+ if (list.count() < types.count()) {
+ qWarning("QDBusMarshall: too few parameters");
+ return false;
+ }
+
+ for (int i = 0; i < types.count(); ++i)
+ if (!qVariantToIterator(it, list.at(i), types.at(i)))
+ return false;
- for (int i = min; i < types.count(); ++i)
- // we're missing a few arguments, so add default parameters
- qVariantToIterator(it, QVariant(), types.at(i));
+ return true;
}
void QDBusMarshall::listToMessage(const QList<QVariant> &list, DBusMessage *msg,
@@ -548,7 +576,7 @@ void QDBusMarshall::listToMessage(const QList<QVariant> &list, DBusMessage *msg,
dbus_message_iter_init_append(msg, &it);
if (signature.isEmpty())
- qListToIterator(&it, list);
+ (void) qListToIterator(&it, list);
else
- qListToIterator(&it, list, QDBusTypeList(signature.toUtf8()));
+ (void) qListToIterator(&it, list, QDBusTypeList(signature.toUtf8()));
}
diff --git a/qt/src/qdbusreply.h b/qt/src/qdbusreply.h
index 2b69cbb..d7e8312 100644
--- a/qt/src/qdbusreply.h
+++ b/qt/src/qdbusreply.h
@@ -76,12 +76,12 @@ public:
inline const QDBusError& error() { return m_error; }
- inline Type value()
+ inline Type value() const
{
return m_data;
}
- inline operator Type ()
+ inline operator Type () const
{
return m_data;
}
@@ -117,7 +117,7 @@ public:
inline QDBusReply(const QDBusError &dbusError)
: m_error(dbusError)
{
- }
+ }
inline bool isError() const { return m_error.isValid(); }
inline bool isSuccess() const { return !m_error.isValid(); }
diff --git a/qt/tools/dbuscpp2xml.cpp b/qt/tools/dbuscpp2xml.cpp
index 42d7831..02e5825 100644
--- a/qt/tools/dbuscpp2xml.cpp
+++ b/qt/tools/dbuscpp2xml.cpp
@@ -33,6 +33,7 @@
#include <string.h>
#include <errno.h>
#include <unistd.h>
+#include <stdlib.h>
#include "../src/qdbusconnection.h" // for the Export* flags
diff --git a/qt/tools/dbusidl2cpp.cpp b/qt/tools/dbusidl2cpp.cpp
index 216c7ce..ab61e67 100644
--- a/qt/tools/dbusidl2cpp.cpp
+++ b/qt/tools/dbusidl2cpp.cpp
@@ -70,7 +70,7 @@ static const char help[] =
"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"
"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'.";
+ "name, as in '-a filename_p.h:filename.cpp'.\n";
static const char includeList[] =
"#include <QtCore/QByteArray>\n"