Warning, /pim/itinerary/src/app/JourneyRequestPage.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 import QtQuick
0007 import QtQuick.Layouts
0008 import QtQuick.Controls as QQC2
0009 import org.kde.kirigami as Kirigami
0010 import org.kde.kirigamiaddons.formcard as FormCard
0011 import org.kde.kirigamiaddons.dateandtime as Addon
0012 import org.kde.kpublictransport
0013 import org.kde.itinerary
0014 import "./components" as Components
0015 
0016 FormCard.FormCardPage {
0017     id: root
0018 
0019     objectName: "JourneyRequestPage"
0020 
0021     property var publicTransportManager
0022 
0023     /**
0024      * Pre-selected country in the location pickers.
0025      * If not specified the country from the current locale is used.
0026      */
0027     property string initialCountry
0028     /** Pre-selected departure time. */
0029     property date initialDateTime: new Date()
0030 
0031     Kirigami.Theme.inherit: false
0032     Kirigami.Theme.colorSet: Kirigami.Theme.Window
0033 
0034     property var departureStop
0035     property var arrivalStop
0036 
0037     title: i18n("Select Journey")
0038 
0039     data: [
0040         Component {
0041             id: departurePicker
0042             StopPickerPage {
0043                 title: i18nc("departure train station", "Select Departure Stop")
0044                 publicTransportManager: root.publicTransportManager
0045                 initialCountry: root.initialCountry
0046                 // force a deep copy, otherwise this breaks as soon as the other stop picker page is shown...
0047                 onLocationChanged: root.departureStop = PublicTransport.copyLocation(location);
0048             }
0049         },
0050         Component {
0051             id: arrivalPicker
0052             StopPickerPage {
0053                 title: i18nc("arrival train station", "Select Arrival Stop")
0054                 publicTransportManager: root.publicTransportManager
0055                 initialCountry: root.initialCountry
0056                 onLocationChanged: root.arrivalStop = PublicTransport.copyLocation(location)
0057             }
0058         },
0059         Component {
0060             id: journeyQueryPage
0061             JourneyQueryPage {
0062                 publicTransportManager: root.publicTransportManager
0063                 title: i18n("Select Journey")
0064                 onJourneyChanged: {
0065                     for (const section of journey.sections) {
0066                         if (section.mode != JourneySection.PublicTransport) {
0067                             continue;
0068                         }
0069                         const res = PublicTransport.reservationFromJourneySection(section);
0070                         const resId = ReservationManager.addReservation(res);
0071                         LiveDataManager.setJourney(resId, section);
0072                     }
0073                     pageStack.clear()
0074                     pageStack.push(pagepool.loadPage(Qt.resolvedUrl("TimelinePage.qml")))
0075                 }
0076             }
0077         }
0078     ]
0079 
0080     // either true/false if all mode switches are in that position, undefined otherwise
0081     function fullModeSwitchState()
0082     {
0083         let state = longDistanceSwitch.checked;
0084         for (const s of [localTrainSwitch, rapidTransitSwitch, busSwitch, ferrySwitch]) {
0085             if (s.checked != state) {
0086                 return undefined;
0087             }
0088         }
0089         return state;
0090     }
0091 
0092     FormCard.FormCard {
0093         id: requestCard
0094         Layout.topMargin: Kirigami.Units.largeSpacing
0095 
0096         FormCard.FormButtonDelegate {
0097             id: fromButton
0098 
0099             text: i18nc("departure train station", "From:")
0100             description: departureStop ? departureStop.name : i18nc("departure train station", "Select Departure Stop")
0101             onClicked: applicationWindow().pageStack.push(departurePicker)
0102         }
0103 
0104 
0105         FormCard.FormDelegateSeparator {
0106             below: fromButton
0107             above: toButton
0108         }
0109 
0110         FormCard.FormButtonDelegate {
0111             id: toButton
0112 
0113             text: i18nc("arrival train station", "To:")
0114             description: arrivalStop ? arrivalStop.name : i18nc("arrival train station", "Select Arrival Stop")
0115             onClicked: applicationWindow().pageStack.push(arrivalPicker)
0116         }
0117         Item{
0118             width:parent.width
0119             height: 0
0120             QQC2.RoundButton{
0121                 icon.name: "reverse"
0122                 y: -fromButton.height - height/2
0123                 z: toButton.z + 10000
0124                 x: fromButton.width - width/2 - Kirigami.Units.gridUnit *3
0125                 onClicked:{
0126                     var oldDepartureStop = departureStop
0127                     departureStop = arrivalStop
0128                     arrivalStop = oldDepartureStop
0129                 }
0130 
0131                 Accessible.name: i18n("Swap departure and arrival")
0132             }
0133         }
0134         FormCard.FormDelegateSeparator {
0135             below: toButton
0136             above: timeSelector
0137         }
0138 
0139         FormCard.AbstractFormDelegate {
0140             id: timeSelector
0141             contentItem: ColumnLayout {
0142                 Components.RadioSelector{
0143                     id: departureArrivalSelector
0144 
0145                     Layout.fillWidth: true
0146                     Layout.alignment: Qt.AlignHCenter
0147                     Layout.maximumWidth: Kirigami.Units.gridUnit * 20
0148                     consistentWidth: true
0149 
0150                     actions: [
0151                         Kirigami.Action {
0152                             text: i18nc("train or bus departure", "Departure")
0153                         },
0154                         Kirigami.Action {
0155                             text: i18nc("train or bus arrival", "Arrival")
0156                         }
0157                     ]
0158                 }
0159             }
0160         }
0161         FormCard.FormDateTimeDelegate {
0162             id: dateTimeInput
0163             value: root.initialDateTime
0164             Accessible.name: departureArrivalSelector.selectedIndex === 0 ? i18nc("train or bus departure", "Departure time") : i18nc("train or bus arrival", "Arrival time")
0165         }
0166 
0167         FormCard.FormDelegateSeparator {
0168             below: timeSelector
0169             above: searchButton
0170         }
0171 
0172         FormCard.FormButtonDelegate {
0173             id: searchButton
0174             icon.name: "search"
0175             text: i18n("Search Journey")
0176             enabled: root.departureStop != undefined && root.arrivalStop != undefined && root.fullModeSwitchState() !== false
0177             onClicked: {
0178                 applicationWindow().pageStack.push(journeyQueryPage);
0179                 const req = applicationWindow().pageStack.currentItem.journeyRequest;
0180                 req.from = root.departureStop;
0181                 req.to = root.arrivalStop;
0182 
0183                 console.log(dateTimeInput.value);
0184                 req.dateTime = dateTimeInput.value;
0185                 req.maximumResults = 6;
0186                 req.downloadAssets = true;
0187                 req.includePaths = true;
0188 
0189                 let lineModes = [];
0190                 if (root.fullModeSwitchState() == undefined) {
0191                     if (longDistanceSwitch.checked)
0192                         lineModes.push(Line.LongDistanceTrain, Line.Train);
0193                     if (localTrainSwitch.checked)
0194                         lineModes.push(Line.LocalTrain);
0195                     if (rapidTransitSwitch.checked)
0196                         lineModes.push(Line.RapidTransit, Line.Metro, Line.Tramway, Line.RailShuttle);
0197                     if (busSwitch.checked)
0198                         lineModes.push(Line.Bus, Line.Coach);
0199                     if (ferrySwitch.checked)
0200                         lineModes.push(Line.Ferry, Line.Boat);
0201                 }
0202                 req.lineModes = lineModes;
0203 
0204                 if (departureArrivalSelector.selectedIndex === 0) {
0205                     req.dateTimeMode = JourneyRequest.Departure
0206                 } else if (departureArrivalSelector.selectedIndex === 1) {
0207                     req.dateTimeMode = JourneyRequest.Arrival
0208                 }
0209 
0210                 console.log(req);
0211                 applicationWindow().pageStack.currentItem.journeyRequest = req;
0212             }
0213         }
0214     }
0215 
0216     FormCard.FormCard {
0217         Layout.topMargin: Kirigami.Units.largeSpacing
0218 
0219         FormCard.FormSwitchDelegate {
0220             id: longDistanceSwitch
0221             text: i18nc("journey query search constraint, title", "Long distance trains")
0222             description: i18nc("journey query search constraint, description", "High speed or intercity trains")
0223             checked: true
0224             leading: Kirigami.Icon {
0225                 source: PublicTransport.lineModeIcon(Line.LongDistanceTrain)
0226                 isMask: true
0227             }
0228         }
0229         FormCard.FormSwitchDelegate {
0230             id: localTrainSwitch
0231             text: i18nc("journey query search constraint, title", "Local trains")
0232             description: i18nc("journey query search constraint, description", "Regional or local trains")
0233             checked: true
0234             leading: Kirigami.Icon {
0235                 source: PublicTransport.lineModeIcon(Line.LocalTrain)
0236                 isMask: true
0237             }
0238         }
0239         FormCard.FormSwitchDelegate {
0240             id: rapidTransitSwitch
0241             text: i18nc("journey query search constraint, title", "Rapid transit")
0242             description: i18nc("journey query search constraint, description", "Rapid transit, metro, trams")
0243             checked: true
0244             leading: Kirigami.Icon {
0245                 source: PublicTransport.lineModeIcon(Line.Tramway)
0246                 isMask: true
0247             }
0248         }
0249         FormCard.FormSwitchDelegate {
0250             id: busSwitch
0251             text: i18nc("journey query search constraint, title", "Bus")
0252             description: i18nc("journey query search constraint, description", "Local or regional bus services")
0253             checked: true
0254             leading: Kirigami.Icon {
0255                 source: PublicTransport.lineModeIcon(Line.Bus)
0256                 isMask: true
0257             }
0258         }
0259         FormCard.FormSwitchDelegate {
0260             id: ferrySwitch
0261             text: i18nc("journey query search constraint, title", "Ferry")
0262             description: i18nc("journey query search constraint, description", "Boats or ferries")
0263             checked: true
0264             leading: Kirigami.Icon {
0265                 source: PublicTransport.lineModeIcon(Line.Ferry)
0266                 isMask: true
0267             }
0268         }
0269     }
0270 
0271     Item {
0272         Layout.fillHeight: true
0273     }
0274 }