diff options
Diffstat (limited to 'src/dbus/qdbusargument.cpp')
-rw-r--r-- | src/dbus/qdbusargument.cpp | 60 |
1 files changed, 40 insertions, 20 deletions
diff --git a/src/dbus/qdbusargument.cpp b/src/dbus/qdbusargument.cpp index 86ce83b324..99e60244da 100644 --- a/src/dbus/qdbusargument.cpp +++ b/src/dbus/qdbusargument.cpp @@ -6,14 +6,15 @@ #include <qatomic.h> #include <qbytearray.h> +#include <qdatetime.h> +#include <qline.h> #include <qlist.h> #include <qmap.h> #include <qstring.h> #include <qstringlist.h> -#include <qvariant.h> -#include <qdatetime.h> #include <qrect.h> -#include <qline.h> +#include <qtimezone.h> +#include <qvariant.h> #include "qdbusmetatype_p.h" #include "qdbusutil_p.h" @@ -30,17 +31,17 @@ QDBusArgumentPrivate::~QDBusArgumentPrivate() q_dbus_message_unref(message); } -QByteArray QDBusArgumentPrivate::createSignature(int id) +QByteArray QDBusArgumentPrivate::createSignature(QMetaType type) { if (!qdbus_loadLibDBus()) return ""; QByteArray signature; - QDBusMarshaller *marshaller = new QDBusMarshaller(0); + QDBusMarshaller *marshaller = new QDBusMarshaller; marshaller->ba = &signature; // run it - QVariant v{QMetaType(id)}; + QVariant v{type}; QDBusArgument arg(marshaller); QDBusMetaType::marshall(arg, v.metaType(), v.constData()); arg.d = nullptr; @@ -50,18 +51,16 @@ QByteArray QDBusArgumentPrivate::createSignature(int id) delete marshaller; if (signature.isEmpty() || !ok || !QDBusUtil::isValidSingleSignature(QString::fromLatin1(signature))) { - qWarning("QDBusMarshaller: type `%s' produces invalid D-BUS signature `%s' " + qWarning("QDBusMarshaller: type '%s' produces invalid D-Bus signature '%s' " "(Did you forget to call beginStructure() ?)", - QMetaType(id).name(), - signature.isEmpty() ? "<empty>" : signature.constData()); + type.name(), signature.isEmpty() ? "<empty>" : signature.constData()); return ""; } else if ((signature.at(0) != DBUS_TYPE_ARRAY && signature.at(0) != DBUS_STRUCT_BEGIN_CHAR) || (signature.at(0) == DBUS_TYPE_ARRAY && (signature.at(1) == DBUS_TYPE_BYTE || signature.at(1) == DBUS_TYPE_STRING))) { - qWarning("QDBusMarshaller: type `%s' attempts to redefine basic D-BUS type '%s' (%s) " + qWarning("QDBusMarshaller: type '%s' attempts to redefine basic D-Bus type '%s' (%s) " "(Did you forget to call beginStructure() ?)", - QMetaType(id).name(), - signature.constData(), + type.name(), signature.constData(), QDBusMetaType::signatureToMetaType(signature).name()); return ""; } @@ -72,7 +71,7 @@ bool QDBusArgumentPrivate::checkWrite(QDBusArgumentPrivate *&d) { if (!d) return false; - if (d->direction == Marshalling) { + if (d->direction == Direction::Marshalling) { if (!d->marshaller()->ok) return false; @@ -100,7 +99,7 @@ bool QDBusArgumentPrivate::checkRead(QDBusArgumentPrivate *d) { if (!d) return false; - if (d->direction == Demarshalling) + if (d->direction == Direction::Demarshalling) return true; #ifdef QT_DEBUG @@ -261,7 +260,7 @@ QDBusArgument::QDBusArgument() return; } - QDBusMarshaller *dd = new QDBusMarshaller(0); + QDBusMarshaller *dd = new QDBusMarshaller; d = dd; // create a new message with any type, we won't sent it anyways @@ -538,7 +537,7 @@ QString QDBusArgument::currentSignature() const { if (!d) return QString(); - if (d->direction == QDBusArgumentPrivate::Demarshalling) + if (d->direction == QDBusArgumentPrivate::Direction::Demarshalling) return d->demarshaller()->currentSignature(); else return d->marshaller()->currentSignature(); @@ -557,14 +556,14 @@ QDBusArgument::ElementType QDBusArgument::currentType() const { if (!d) return UnknownType; - if (d->direction == QDBusArgumentPrivate::Demarshalling) + if (d->direction == QDBusArgumentPrivate::Direction::Demarshalling) return d->demarshaller()->currentType(); return UnknownType; } /*! - Extracts one D-BUS primitive argument of type \c{BYTE} from the - D-BUS stream and puts it into \a arg. + Extracts one D-Bus primitive argument of type \c{BYTE} from the + D-Bus stream and puts it into \a arg. */ const QDBusArgument &QDBusArgument::operator>>(uchar &arg) const { @@ -1171,12 +1170,33 @@ const QDBusArgument &operator>>(const QDBusArgument &a, QDateTime &dt) a >> date >> time >> timespec; a.endStructure(); - dt = QDateTime(date, time, Qt::TimeSpec(timespec)); + switch (Qt::TimeSpec(timespec)) { + case Qt::TimeZone: + qWarning("Restoring zoned date-time without zone info"); + Q_FALLTHROUGH(); // Treat as local time. + case Qt::LocalTime: + dt = QDateTime(date, time); + break; + case Qt::OffsetFromUTC: + qWarning("Restoring date-time without its offset"); + Q_FALLTHROUGH(); // Use zero offset + case Qt::UTC: + dt = QDateTime(date, time, QTimeZone::UTC); + break; + } return a; } QDBusArgument &operator<<(QDBusArgument &a, const QDateTime &dt) { + // TODO: Only viable for UTC and LocalTime + if (Q_UNLIKELY(dt.timeSpec() != Qt::UTC && dt.timeSpec() != Qt::LocalTime)) { + qWarning() << "Serializing a date-time with unsupported time-spec" << dt.timeSpec(); + // Coerce to a supported timespec. When a time-zone is the current + // system zone, local time is suitable; so map all time-zones to local, + // plain offsets to UTC. + return a << (dt.timeSpec() == Qt::OffsetFromUTC ? dt.toUTC() : dt.toLocalTime()); + } a.beginStructure(); a << dt.date() << dt.time() << int(dt.timeSpec()); a.endStructure(); |