File indexing completed on 2024-05-05 03:50:35

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2009 Eckhart Wörner <ewoerner@kde.org>
0004 //
0005 
0006 #include "VelocityProvider_p.h"
0007 
0008 #include <QDBusReply>
0009 
0010 
0011 
0012 using namespace GeoCute;
0013 
0014 VelocityProvider::Private::Private(VelocityProvider& parent,
0015     const QString& service, const QString& path)
0016     : interface(service, path, interfaceName), parent(parent)
0017 {
0018     // Get an initial velocity
0019     interface.callWithCallback("GetVelocity", QList<QVariant>(), &parent,
0020         SLOT(velocityChangedCall(QDBusMessage)), 0);
0021     // Stay informed about future velocity changes
0022     interface.connect("VelocityChanged", &parent,
0023         SLOT(velocityChangedCall(QDBusMessage)));
0024 }
0025 
0026 void VelocityProvider::Private::velocityChangedCall(QDBusMessage message)
0027 {
0028     Velocity newVelocity;
0029     newVelocity.fields
0030         = static_cast<VelocityFields>(message.arguments()[0].toInt());
0031     newVelocity.speed = message.arguments()[2].toDouble();
0032     newVelocity.direction = message.arguments()[3].toDouble();
0033     newVelocity.climb = message.arguments()[4].toDouble();
0034     
0035     currentVelocity = newVelocity;
0036     emit parent.velocityChanged(newVelocity);
0037 }
0038 
0039 
0040 
0041 VelocityProvider::VelocityProvider(const QString& service, const QString& path,
0042     QObject* parent)
0043     : Provider(service, path, parent),
0044       d(new Private(*this, service, path))
0045 {
0046 }
0047 
0048 VelocityProvider::~VelocityProvider()
0049 {
0050     delete d;
0051 }
0052 
0053 Velocity VelocityProvider::velocity()
0054 {
0055     return d->currentVelocity;
0056 }
0057 
0058 
0059 
0060 #include "moc_VelocityProvider.cpp"