File indexing completed on 2024-05-19 05:37:50
0001 /* 0002 SPDX-FileCopyrightText: 2009 Aaron Seigo <aseigo@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QHash> 0010 #include <QObject> 0011 #include <QTimer> 0012 0013 #include <Plasma5Support/DataEngine> 0014 0015 #include "geolocation_export.h" 0016 0017 typedef QHash<QString, int> EntryAccuracy; 0018 0019 class GEOLOCATION_EXPORT GeolocationProvider : public QObject 0020 { 0021 Q_OBJECT 0022 0023 public: 0024 enum UpdateTrigger { 0025 ForcedUpdate = 0, 0026 SourceEvent = 1, 0027 NetworkConnected = 2, 0028 }; 0029 Q_DECLARE_FLAGS(UpdateTriggers, UpdateTrigger) 0030 0031 explicit GeolocationProvider(QObject *parent); 0032 void init(Plasma5Support::DataEngine::Data *data, EntryAccuracy *accuracies); 0033 0034 UpdateTriggers updateTriggers() const; 0035 int accuracy() const; 0036 bool isAvailable() const; 0037 bool requestUpdate(UpdateTriggers trigger); 0038 bool populateSharedData(); 0039 0040 Q_SIGNALS: 0041 void updated(); 0042 void availabilityChanged(GeolocationProvider *provider); 0043 0044 protected: 0045 void setAccuracy(int accuracy); 0046 void setIsAvailable(bool available); 0047 void setUpdateTriggers(UpdateTriggers triggers); 0048 virtual void init(); 0049 virtual void update(); 0050 0051 protected Q_SLOTS: 0052 void setData(const Plasma5Support::DataEngine::Data &data); 0053 void setData(const QString &key, const QVariant &value); 0054 0055 private: 0056 Plasma5Support::DataEngine::Data *m_sharedData; 0057 EntryAccuracy *m_sharedAccuracies; 0058 Plasma5Support::DataEngine::Data m_data; 0059 QTimer m_updateTimer; 0060 int m_accuracy; 0061 UpdateTriggers m_updateTriggers; 0062 bool m_available : 1; 0063 bool m_updating : 1; 0064 }; 0065 0066 Q_DECLARE_OPERATORS_FOR_FLAGS(GeolocationProvider::UpdateTriggers)