diff options
Diffstat (limited to 'src/dbus/qdbusargument.cpp')
-rw-r--r-- | src/dbus/qdbusargument.cpp | 104 |
1 files changed, 45 insertions, 59 deletions
diff --git a/src/dbus/qdbusargument.cpp b/src/dbus/qdbusargument.cpp index e17b40e58c..99e60244da 100644 --- a/src/dbus/qdbusargument.cpp +++ b/src/dbus/qdbusargument.cpp @@ -1,55 +1,20 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtDBus module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qdbusargument.h" #include "qdbusargument_p.h" #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" @@ -58,23 +23,25 @@ QT_BEGIN_NAMESPACE +QT_IMPL_METATYPE_EXTERN(QDBusArgument) + QDBusArgumentPrivate::~QDBusArgumentPrivate() { if (message) 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; @@ -84,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 ""; } @@ -106,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; @@ -134,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 @@ -295,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 @@ -572,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(); @@ -591,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 { @@ -710,7 +675,7 @@ const QDBusArgument &QDBusArgument::operator>>(qulonglong &arg) const /*! \overload Extracts one D-Bus primitive argument of type \c{DOUBLE} - (double-precision floating pount) from the D-Bus stream. + (double-precision floating point) from the D-Bus stream. */ const QDBusArgument &QDBusArgument::operator>>(double &arg) const { @@ -1205,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(); |