Plasma5Support

geolocationprovider.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Aaron Seigo <aseigo@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "geolocationprovider.h"
8
9GeolocationProvider::GeolocationProvider(QObject *parent)
10 : QObject(parent)
11 , m_sharedData(nullptr)
12 , m_sharedAccuracies(nullptr)
13 , m_accuracy(1000)
14 , m_updateTriggers(SourceEvent)
15 , m_available(true)
16 , m_updating(false)
17{
18 m_updateTimer.setSingleShot(true);
19 m_updateTimer.setInterval(0);
20 qRegisterMetaType<Plasma5Support::DataEngine::Data>("Plasma5Support::DataEngine::Data");
21 connect(&m_updateTimer, &QTimer::timeout, this, &GeolocationProvider::updated);
22}
23
24void GeolocationProvider::init(Plasma5Support::DataEngine::Data *data, EntryAccuracy *accuracies)
25{
26 m_sharedData = data;
27 m_sharedAccuracies = accuracies;
28 init();
29}
30
31int GeolocationProvider::accuracy() const
32{
33 return m_accuracy;
34}
35
36bool GeolocationProvider::isAvailable() const
37{
38 return m_available;
39}
40
41bool GeolocationProvider::requestUpdate(GeolocationProvider::UpdateTriggers triggers)
42{
43 if (m_available && !m_updating && (triggers == ForcedUpdate || triggers & m_updateTriggers)) {
44 m_updating = true;
45 update();
46 return true;
47 }
48
49 return false;
50}
51
52GeolocationProvider::UpdateTriggers GeolocationProvider::updateTriggers() const
53{
54 return m_updateTriggers;
55}
56
57bool GeolocationProvider::populateSharedData()
58{
60 bool changed = false;
61
62 while (it != m_data.constEnd()) {
63 if (!m_sharedData->contains(it.key()) || m_sharedAccuracies->value(it.key()) < m_accuracy) {
64 m_sharedData->insert(it.key(), it.value());
65 m_sharedAccuracies->insert(it.key(), m_accuracy);
66 changed = true;
67 }
68
69 ++it;
70 }
71
72 return changed;
73}
74
75void GeolocationProvider::setAccuracy(int accuracy)
76{
77 m_accuracy = accuracy;
78}
79
80void GeolocationProvider::setIsAvailable(bool available)
81{
82 if (m_available == available) {
83 return;
84 }
85
86 m_available = available;
87 Q_EMIT availabilityChanged(this);
88}
89
90void GeolocationProvider::setData(const Plasma5Support::DataEngine::Data &data)
91{
92 m_updating = false;
93 m_data = data;
94 if (populateSharedData()) {
95 m_updateTimer.start();
96 }
97}
98
99void GeolocationProvider::setData(const QString &key, const QVariant &value)
100{
101 m_updating = false;
102 m_data.insert(key, value);
103
104 if (!m_sharedData->contains(key) || m_sharedAccuracies->value(QStringLiteral("key")) < m_accuracy) {
105 m_sharedData->insert(key, value);
106 m_sharedAccuracies->insert(key, accuracy());
107 m_updateTimer.start();
108 }
109}
110
111void GeolocationProvider::setUpdateTriggers(UpdateTriggers triggers)
112{
113 m_updateTriggers = triggers;
114}
115
116void GeolocationProvider::init()
117{
118}
119
120void GeolocationProvider::update()
121{
122}
iterator insert(const Key &key, const T &value)
T value(const Key &key) const const
const_iterator constBegin() const const
const_iterator constEnd() const const
bool contains(const Key &key) const const
iterator insert(const Key &key, const T &value)
Q_EMITQ_EMIT
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void start()
void timeout()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:57 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.