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 #include "onboardstatus.h" 0007 #include "onboardstatusmanager_p.h" 0008 0009 #include <KPublicTransport/Journey> 0010 0011 #include <cmath> 0012 0013 using namespace KPublicTransport; 0014 0015 namespace KPublicTransport { 0016 class OnboardStatusPrivate 0017 { 0018 public: 0019 int positionUpdateInterval = -1; 0020 int journeyUpdateInterval = -1; 0021 }; 0022 } 0023 0024 OnboardStatus::OnboardStatus(QObject *parent) 0025 : QObject(parent) 0026 , d(new OnboardStatusPrivate) 0027 { 0028 auto mgr = OnboardStatusManager::instance(); 0029 connect(mgr, &OnboardStatusManager::statusChanged, this, &OnboardStatus::statusChanged); 0030 connect(mgr, &OnboardStatusManager::positionChanged, this, &OnboardStatus::positionChanged); 0031 connect(mgr, &OnboardStatusManager::supportsPositionChanged, this, &OnboardStatus::supportsPositionChanged); 0032 connect(mgr, &OnboardStatusManager::journeyChanged, this, &OnboardStatus::journeyChanged); 0033 connect(mgr, &OnboardStatusManager::supportsJourneyChanged, this, &OnboardStatus::supportsJourneyChanged); 0034 OnboardStatusManager::instance()->registerFrontend(this); 0035 } 0036 0037 OnboardStatus::~OnboardStatus() 0038 { 0039 OnboardStatusManager::instance()->unregisterFrontend(this); 0040 } 0041 0042 OnboardStatus::Status OnboardStatus::status() const 0043 { 0044 return OnboardStatusManager::instance()->status(); 0045 } 0046 0047 float OnboardStatus::latitude() const 0048 { 0049 return OnboardStatusManager::instance()->currentPosition().latitude; 0050 } 0051 0052 float OnboardStatus::longitude() const 0053 { 0054 return OnboardStatusManager::instance()->currentPosition().longitude; 0055 } 0056 0057 bool OnboardStatus::hasPosition() const 0058 { 0059 return OnboardStatusManager::instance()->currentPosition().hasCoordinate(); 0060 } 0061 0062 bool OnboardStatus::supportsPosition() const 0063 { 0064 return OnboardStatusManager::instance()->supportsPosition(); 0065 } 0066 0067 float OnboardStatus::speed() const 0068 { 0069 return OnboardStatusManager::instance()->currentPosition().speed; 0070 } 0071 0072 bool OnboardStatus::hasSpeed() const 0073 { 0074 return !std::isnan(speed()); 0075 } 0076 0077 float OnboardStatus::heading() const 0078 { 0079 return OnboardStatusManager::instance()->currentPosition().heading; 0080 } 0081 0082 bool OnboardStatus::hasHeading() const 0083 { 0084 return !std::isnan(heading()); 0085 } 0086 0087 float OnboardStatus::altitude() const 0088 { 0089 return OnboardStatusManager::instance()->currentPosition().altitude; 0090 } 0091 0092 bool OnboardStatus::hasAltitude() const 0093 { 0094 return !std::isnan(altitude()); 0095 } 0096 0097 Journey OnboardStatus::journey() const 0098 { 0099 return OnboardStatusManager::instance()->currentJourney(); 0100 } 0101 0102 bool OnboardStatus::hasJourney() const 0103 { 0104 return !OnboardStatusManager::instance()->currentJourney().sections().empty(); 0105 } 0106 0107 bool OnboardStatus::supportsJourney() const 0108 { 0109 return OnboardStatusManager::instance()->supportsJourney(); 0110 } 0111 0112 int OnboardStatus::positionUpdateInterval() const 0113 { 0114 return d->positionUpdateInterval; 0115 } 0116 0117 void OnboardStatus::setPositionUpdateInterval(int interval) 0118 { 0119 if (d->positionUpdateInterval == interval) { 0120 return; 0121 } 0122 0123 d->positionUpdateInterval = interval; 0124 Q_EMIT updateIntervalChanged(); 0125 } 0126 0127 int OnboardStatus::journeyUpdateInterval() const 0128 { 0129 return d->journeyUpdateInterval; 0130 } 0131 0132 void OnboardStatus::setJourneyUpdateInterval(int interval) 0133 { 0134 if (d->journeyUpdateInterval == interval) { 0135 return; 0136 } 0137 0138 d->journeyUpdateInterval = interval; 0139 Q_EMIT updateIntervalChanged(); 0140 } 0141 0142 void OnboardStatus::requestPosition() 0143 { 0144 OnboardStatusManager::instance()->requestPosition(); 0145 } 0146 0147 void OnboardStatus::requestJourney() 0148 { 0149 OnboardStatusManager::instance()->requestJourney(); 0150 } 0151 0152 void OnboardStatus::requestPermissions() 0153 { 0154 OnboardStatusManager::instance()->requestPermissions(); 0155 } 0156 0157 #include "moc_onboardstatus.cpp"