File indexing completed on 2024-12-01 07:25:48

0001 /*
0002     SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 #ifndef KPUBLICTRANSPORT_ONBOARDSTATUS_H
0007 #define KPUBLICTRANSPORT_ONBOARDSTATUS_H
0008 
0009 #include "kpublictransportonboard_export.h"
0010 
0011 #include <QObject>
0012 
0013 #include <memory>
0014 
0015 namespace KPublicTransport {
0016 class Journey;
0017 class OnboardStatusPrivate;
0018 
0019 /** Access to public transport onboard API.
0020  *
0021  *  Instances of this class act as a lightweight frontend to an internal
0022  *  singleton, for easy integration with QML.
0023  */
0024 class KPUBLICTRANSPORTONBOARD_EXPORT OnboardStatus : public QObject
0025 {
0026     Q_OBJECT
0027     Q_PROPERTY(Status status READ status NOTIFY statusChanged)
0028 
0029     /** Current geographic position, @c NAN if not available. */
0030     Q_PROPERTY(float latitude READ latitude NOTIFY positionChanged)
0031     Q_PROPERTY(float longitude READ longitude NOTIFY positionChanged)
0032     /** Whether the geographic position is currently available. */
0033     Q_PROPERTY(bool hasPosition READ hasPosition NOTIFY positionChanged)
0034     /** Whether the backend supports querying for the geographic position. */
0035     Q_PROPERTY(bool supportsPosition READ supportsPosition NOTIFY supportsPositionChanged)
0036 
0037     /** Current speed in km/h. */
0038     Q_PROPERTY(float speed READ speed NOTIFY positionChanged)
0039     Q_PROPERTY(bool hasSpeed READ hasSpeed NOTIFY positionChanged)
0040 
0041     /** Current heading in degree, NAN if unknown. */
0042     Q_PROPERTY(float heading READ heading NOTIFY positionChanged)
0043     Q_PROPERTY(bool hasHeading READ hasHeading NOTIFY positionChanged)
0044 
0045     /** Current altitude in meters, NAN if unknown. */
0046     Q_PROPERTY(float altitude READ altitude NOTIFY positionChanged)
0047     Q_PROPERTY(bool hasAltitude READ hasAltitude NOTIFY positionChanged)
0048 
0049     /** The current journey. */
0050     Q_PROPERTY(KPublicTransport::Journey journey READ journey NOTIFY journeyChanged)
0051     /** Whether there is journey information available. */
0052     Q_PROPERTY(bool hasJourney READ hasJourney NOTIFY journeyChanged)
0053     /** Whether the backend supports querying for the journey. */
0054     Q_PROPERTY(bool supportsJourney READ supportsJourney NOTIFY supportsJourneyChanged)
0055 
0056     /** Update polling intervals in seconds. */
0057     Q_PROPERTY(int positionUpdateInterval READ positionUpdateInterval WRITE setPositionUpdateInterval NOTIFY updateIntervalChanged)
0058     Q_PROPERTY(int journeyUpdateInterval READ journeyUpdateInterval WRITE setJourneyUpdateInterval NOTIFY updateIntervalChanged)
0059 
0060 public:
0061     explicit OnboardStatus(QObject *parent = nullptr);
0062     ~OnboardStatus();
0063 
0064     enum Status {
0065         NotConnected, ///< Wi-Fi monitoring functional, but currently not connected to an onboard Wi-Fi.
0066         Onboard, ///< currently connected to a known onboard Wi-Fi system.
0067         MissingPermissions, ///< Wi-Fi monitoring not functional due to missing application permissions.
0068         WifiNotEnabled, ///< Wi-Fi monitoring is not possible due to Wi-Fi being disabled.
0069         LocationServiceNotEnabled, ///< Wi-Fi monitoring is not possible due to the location service being disabled (Android only).
0070         NotAvailable, ///< Wi-Fi monitoring is generally not available on this platform.
0071     };
0072     Q_ENUM(Status)
0073     Status status() const;
0074 
0075     float latitude() const;
0076     float longitude() const;
0077     bool hasPosition() const;
0078     bool supportsPosition() const;
0079 
0080     float speed() const;
0081     bool hasSpeed() const;
0082 
0083     float heading() const;
0084     bool hasHeading() const;
0085 
0086     float altitude() const;
0087     bool hasAltitude() const;
0088 
0089     KPublicTransport::Journey journey() const;
0090     bool hasJourney() const;
0091     bool supportsJourney() const;
0092 
0093     int positionUpdateInterval() const;
0094     void setPositionUpdateInterval(int interval);
0095     int journeyUpdateInterval() const;
0096     void setJourneyUpdateInterval(int interval);
0097 
0098     /** Request one time update of the position status.
0099      *  For recurring updates, use the polling interval setting instead.
0100      */
0101     Q_INVOKABLE void requestPosition();
0102     /** Request one time journey data update, if available.
0103      *  For recurring updates, use the polling interval setting instead.
0104      */
0105     Q_INVOKABLE void requestJourney();
0106 
0107     /** Request application permission needed for Wi-Fi montioring.
0108      *  Only relevant on Android, does nothing on other platforms.
0109      *  @see Status::MissingPermissions
0110      */
0111     Q_INVOKABLE void requestPermissions();
0112 
0113 Q_SIGNALS:
0114     void statusChanged();
0115     void positionChanged();
0116     void supportsPositionChanged();
0117     void journeyChanged();
0118     void supportsJourneyChanged();
0119     void updateIntervalChanged();
0120 
0121 private:
0122     std::unique_ptr<OnboardStatusPrivate> d;
0123 };
0124 
0125 }
0126 
0127 #endif // KPUBLICTRANSPORT_ONBOARDSTATUS_H