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 "PositionProvider_p.h" 0007 0008 #include <QList> 0009 #include <QVariant> 0010 #include <QDBusReply> 0011 0012 #include "MasterClient.h" 0013 0014 0015 0016 using namespace GeoCute; 0017 0018 PositionProvider::Private::Private(PositionProvider& parent, 0019 const QString& service, const QString& path) 0020 : interface(service, path, interfaceName), parent(parent) 0021 { 0022 // Get an initial position 0023 interface.callWithCallback("GetPosition", QList<QVariant>(), &parent, 0024 SLOT(positionChangedCall(QDBusMessage)), 0); 0025 // Stay informed about future position changes 0026 interface.connect("PositionChanged", &parent, 0027 SLOT(positionChangedCall(QDBusMessage))); 0028 } 0029 0030 void PositionProvider::Private::positionChangedCall(QDBusMessage message) 0031 { 0032 // FIXME: Check the number of arguments 0033 // FIXME: Make sure all result members are actually filled 0034 Position result; 0035 result.fields 0036 = static_cast<PositionFields>(message.arguments()[0].toInt()); 0037 result.timestamp.setTime_t(message.arguments()[1].toInt()); 0038 result.latitude = message.arguments()[2].toDouble(); 0039 result.longitude = message.arguments()[3].toDouble(); 0040 result.altitude = message.arguments()[4].toDouble(); 0041 currentPosition = result; 0042 if (result.fields != PositionFieldNone) 0043 emit parent.positionChanged(result); 0044 } 0045 0046 0047 0048 PositionProvider::PositionProvider(const QString& service, const QString& path, 0049 QObject* parent) 0050 : Provider(service, path, parent), d(new Private(*this, service, path)) 0051 { 0052 } 0053 0054 PositionProvider::~PositionProvider() 0055 { 0056 delete d; 0057 } 0058 0059 PositionProvider* PositionProvider::detailed() 0060 { 0061 // FIXME: The following code has been replaced for the moment 0062 // because it leads to a crash in geoclue-master 0063 MasterClient mc; 0064 mc.setRequirements(GeoCute::AccuracyLevelNone, 0, 0065 GeoCute::SignallingRequired, GeoCute::ResourceAll); 0066 return mc.positionProvider(); 0067 // Return a specific GeoClue provider 0068 // return new PositionProvider("example.provider.hostip", "/"); 0069 } 0070 0071 Position PositionProvider::position() const 0072 { 0073 return d->currentPosition; 0074 } 0075 0076 0077 0078 #include "moc_PositionProvider.cpp"