File indexing completed on 2024-07-21 05:14:39
0001 /** 0002 * SPDX-FileCopyrightText: 2019 Nicolas Fella <nicolas.fella@gmx.de> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "controller.h" 0008 0009 #include <QDateTime> 0010 #include <QDebug> 0011 #include <QDesktopServices> 0012 #include <QJsonDocument> 0013 #include <QJsonObject> 0014 #include <QStandardPaths> 0015 #include <QUrl> 0016 0017 Controller::Controller(QObject *parent) 0018 : QObject(parent) 0019 , m_start() 0020 , m_destination() 0021 { 0022 m_departureDate = QDate::currentDate(); 0023 m_departureTime = QTime::currentTime(); 0024 } 0025 0026 void Controller::setStart(const KPublicTransport::Location &start) 0027 { 0028 m_start = start; 0029 Q_EMIT startChanged(); 0030 } 0031 0032 KPublicTransport::Location Controller::start() const 0033 { 0034 return m_start; 0035 } 0036 0037 void Controller::setDestination(const KPublicTransport::Location &destination) 0038 { 0039 m_destination = destination; 0040 Q_EMIT destinationChanged(); 0041 } 0042 0043 KPublicTransport::Location Controller::destination() const 0044 { 0045 return m_destination; 0046 } 0047 0048 KPublicTransport::JourneyRequest Controller::createJourneyRequest() 0049 { 0050 KPublicTransport::JourneyRequest req; 0051 req.setFrom(m_start); 0052 req.setTo(m_destination); 0053 req.setDownloadAssets(true); 0054 0055 QDateTime depTime(m_departureDate, m_departureTime); 0056 req.setDepartureTime(depTime); 0057 0058 return req; 0059 } 0060 0061 QDate Controller::departureDate() const 0062 { 0063 return m_departureDate; 0064 } 0065 0066 void Controller::setDepartureDate(const QDate &date) 0067 { 0068 if (m_departureDate != date) { 0069 m_departureDate = date; 0070 Q_EMIT departureDateChanged(); 0071 } 0072 } 0073 0074 QTime Controller::departureTime() const 0075 { 0076 return m_departureTime; 0077 } 0078 0079 void Controller::setDepartureTime(const QTime &time) 0080 { 0081 if (m_departureTime != time) { 0082 m_departureTime = time; 0083 Q_EMIT departureTimeChanged(); 0084 } 0085 } 0086 0087 KPublicTransport::LocationRequest Controller::createLocationRequest(const QString &name) 0088 { 0089 KPublicTransport::LocationRequest req; 0090 req.setName(name); 0091 0092 return req; 0093 } 0094 0095 KPublicTransport::StopoverRequest Controller::createStopoverRequest() 0096 { 0097 KPublicTransport::StopoverRequest req; 0098 req.setStop(m_start); 0099 QDateTime depTime(m_departureDate, m_departureTime); 0100 req.setDateTime(depTime); 0101 return req; 0102 } 0103 0104 void Controller::showOnMap(KPublicTransport::Location location) 0105 { 0106 if (!location.hasCoordinate()) 0107 return; 0108 QUrl url(QLatin1String("geo:") + QString::number(location.latitude()) + QLatin1Char(',') + QString::number(location.longitude())); 0109 QDesktopServices::openUrl(url); 0110 }