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

0001 /*
0002     SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 import QtQuick
0008 import QtQuick.Layouts
0009 import QtQuick.Controls as QQC2
0010 import org.kde.kirigami as Kirigami
0011 import org.kde.kitemmodels
0012 import org.kde.kpublictransport
0013 import org.kde.itinerary
0014 import org.kde.kirigamiaddons.formcard as FormCard
0015 
0016 Kirigami.ScrollablePage {
0017     id: root
0018     property var transfer
0019     readonly property var reservation: ReservationManager.reservation(transfer.reservationId)
0020     title: i18n("Select Transfer")
0021 
0022     JourneyQueryModel {
0023         id: journeyModel
0024         manager: LiveDataManager.publicTransportManager
0025     }
0026 
0027     KSortFilterProxyModel {
0028         id: sortedJourneyModel
0029         sourceModel: journeyModel
0030         sortRole: JourneyQueryModel.ScheduledDepartureTime
0031         dynamicSortFilter: true
0032         Component.onCompleted: Util.sortModel(sortedJourneyModel, 0, Qt.Ascending)
0033     }
0034 
0035     background: Rectangle {
0036         Kirigami.Theme.colorSet: Kirigami.Theme.Window
0037         Kirigami.Theme.inherit: false
0038         color: Kirigami.Theme.backgroundColor
0039     }
0040 
0041     actions: [
0042         Kirigami.Action {
0043             text: i18n("Depart Now")
0044             icon.name: "clock"
0045             onTriggered: {
0046                 var req = journeyModel.request;
0047                 req.dateTime = new Date();
0048                 req.dateTimeMode = JourneyRequest.Departure;
0049                 journeyModel.request = req;
0050             }
0051         },
0052         Kirigami.Action {
0053             text: i18n("Discard")
0054             icon.name: "edit-delete"
0055             onTriggered: {
0056                 TransferManager.discardTransfer(root.transfer);
0057                 applicationWindow().pageStack.pop();
0058             }
0059         },
0060         Kirigami.Action {
0061             text: i18n("Earlier")
0062             icon.name: "go-up-symbolic"
0063             onTriggered: journeyModel.queryPrevious()
0064             enabled: journeyModel.canQueryPrevious
0065         },
0066         Kirigami.Action {
0067             text: i18n("Later")
0068             icon.name: "go-down-symbolic"
0069             onTriggered: journeyModel.queryNext()
0070             enabled: journeyModel.canQueryNext
0071         },
0072         Kirigami.Action { separator: true },
0073         Kirigami.Action {
0074             id: bikeAction
0075             text: i18n("Bike")
0076             icon.source: "qrc:///images/bike.svg"
0077             checkable: true
0078             onCheckedChanged: queryJourney()
0079         },
0080         Kirigami.Action {
0081             id: bikeRideAction
0082             text: i18n("Bike & Ride")
0083             icon.source: "qrc:///images/bike.svg"
0084             checkable: true
0085             visible: root.transfer.alignment == Transfer.Before && root.transfer.floatingLocationType == Transfer.FavoriteLocation
0086             onCheckedChanged: queryJourney()
0087         },
0088         Kirigami.Action {
0089             id: bikeSharingAction
0090             text: i18n("Shared Bikes")
0091             icon.source: "qrc:///images/bike.svg"
0092             checkable: true
0093             onCheckedChanged: queryJourney()
0094         },
0095         Kirigami.Action {
0096             id: parkRideAction
0097             text: i18n("Park & Ride")
0098             icon.source: "qrc:///images/car.svg"
0099             checkable: true
0100             visible: root.transfer.alignment == Transfer.Before && root.transfer.floatingLocationType == Transfer.FavoriteLocation
0101             onCheckedChanged: queryJourney()
0102         },
0103 
0104         Kirigami.Action { separator: true },
0105 
0106         Kirigami.Action {
0107             id: longDistanceModeAction
0108             text: i18nc("journey query search constraint, title", "Long distance trains")
0109             icon.source: PublicTransport.lineModeIcon(Line.LongDistanceTrain)
0110             checkable: true
0111             checked: true
0112             onCheckedChanged: queryJourney()
0113         },
0114         Kirigami.Action {
0115             id: localTrainModeAction
0116             text: i18nc("journey query search constraint, title", "Local trains")
0117             icon.source: PublicTransport.lineModeIcon(Line.LocalTrain)
0118             checkable: true
0119             checked: true
0120             onCheckedChanged: queryJourney()
0121         },
0122         Kirigami.Action {
0123             id: rapidTransitModeAction
0124             text: i18nc("journey query search constraint, title", "Rapid transit")
0125             icon.source: PublicTransport.lineModeIcon(Line.Tramway)
0126             checkable: true
0127             checked: true
0128             onCheckedChanged: queryJourney()
0129         },
0130         Kirigami.Action {
0131             id: busModeAction
0132             text: i18nc("journey query search constraint, title", "Bus")
0133             icon.source: PublicTransport.lineModeIcon(Line.Bus)
0134             checkable: true
0135             checked: true
0136             onCheckedChanged: queryJourney()
0137         },
0138         Kirigami.Action {
0139             id: ferryModeAction
0140             text: i18nc("journey query search constraint, title", "Ferry")
0141             icon.source: PublicTransport.lineModeIcon(Line.Ferry)
0142             checkable: true
0143             checked: true
0144             onCheckedChanged: queryJourney()
0145         }
0146     ]
0147 
0148     function allLineModes()
0149     {
0150         for (const s of [longDistanceModeAction, localTrainModeAction, rapidTransitModeAction, busModeAction, ferryModeAction]) {
0151             if (!s.checked) {
0152                 return false;
0153             }
0154         }
0155         return true;
0156     }
0157 
0158     function queryJourney() {
0159         journeyModel.request = TransferManager.journeyRequestForTransfer(transfer);
0160         let lineModes = [];
0161         let accessMode = [];
0162         let egressMode = [];
0163 
0164         if (!allLineModes()) {
0165             if (longDistanceModeAction.checked)
0166                 lineModes.push(Line.LongDistanceTrain, Line.Train);
0167             if (localTrainModeAction.checked)
0168                 lineModes.push(Line.LocalTrain);
0169             if (rapidTransitModeAction.checked)
0170                 lineModes.push(Line.RapidTransit, Line.Metro, Line.Tramway, Line.RailShuttle);
0171             if (busModeAction.checked)
0172                 lineModes.push(Line.Bus, Line.Coach);
0173             if (ferryModeAction.checked)
0174                 lineModes.push(Line.Ferry, Line.Boat);
0175         }
0176 
0177         if (bikeAction.checked) {
0178             accessMode.push({ mode: IndividualTransport.Bike });
0179             egressMode.push({ mode: IndividualTransport.Bike });
0180         }
0181         if (bikeRideAction.checked) {
0182             accessMode.push({ mode: IndividualTransport.Bike, qualifier: IndividualTransport.Park });
0183         }
0184         if (bikeSharingAction.checked) {
0185             accessMode.push({ mode: IndividualTransport.Bike, qualifier: IndividualTransport.Rent });
0186             egressMode.push({ mode: IndividualTransport.Bike, qualifier: IndividualTransport.Rent });
0187         }
0188 
0189         if (parkRideAction.checked) {
0190             accessMode.push({ mode: IndividualTransport.Car, qualifier: IndividualTransport.Park });
0191         }
0192 
0193         journeyModel.request.lineModes = lineModes;
0194         journeyModel.request.accessModes = accessMode;
0195         journeyModel.request.egressModes = egressMode;
0196     }
0197 
0198     Component.onCompleted: {
0199         if (transfer.floatingLocationType == Transfer.FavoriteLocation) {
0200             favLocCombo.currentIndex = favLocCombo.find(transfer.alignment == Transfer.Before ? transfer.fromName : transfer.toName);
0201         }
0202         queryJourney();
0203     }
0204 
0205     Component {
0206         id: journeyDelegate
0207 
0208         FormCard.FormCard {
0209             id: top
0210 
0211             required property int index
0212             required property var journey
0213 
0214             width: ListView.view.width
0215 
0216             JourneyDelegateHeader {
0217                 journey: top.journey
0218             }
0219 
0220             Repeater {
0221                 id: journeyRepeater
0222                 delegate: JourneySectionDelegate{
0223                     Layout.fillWidth: true
0224                     modelLength: journeyRepeater.count - 1
0225 
0226                 }
0227                 model: journeyView.currentIndex === top.index ? top.journey.sections : 0
0228             }
0229 
0230             JourneySummaryDelegate {
0231                 id: summaryButton
0232 
0233                 journey: top.journey
0234                 visible: journeyView.currentIndex !== top.index
0235                 onClicked: journeyView.currentIndex = top.index
0236 
0237                 Layout.fillWidth: true
0238             }
0239 
0240             FormCard.FormDelegateSeparator {
0241                 above: selectButton
0242                 visible: journeyView.currentIndex === top.index
0243             }
0244 
0245             FormCard.FormButtonDelegate {
0246                 id: selectButton
0247 
0248                 text: i18n("Select")
0249                 icon.name: "checkmark"
0250                 visible: journeyView.currentIndex === top.index
0251                 enabled: top.journey.disruptionEffect !== Disruption.NoService
0252                 onClicked: {
0253                     TransferManager.setJourneyForTransfer(root.transfer, top.journey);
0254                     applicationWindow().pageStack.pop();
0255                 }
0256             }
0257         }
0258     }
0259 
0260     header: QQC2.Pane {
0261         Kirigami.Theme.colorSet: Kirigami.Theme.Header
0262         Kirigami.Theme.inherit: false
0263 
0264         contentItem: ColumnLayout {
0265             id: topLayout
0266 
0267             QQC2.Label {
0268                 text: {
0269                     if (!Util.isLocationChange(root.reservation)) {
0270                         return i18n("%1 ends at %2", root.reservation.reservationFor.name, Localizer.formatTime(transfer, "anchorTime"));
0271                     }
0272                     return i18n("Preceding arrival %1 at %2", Localizer.formatTime(transfer, "anchorTime"), transfer.fromName);
0273                 }
0274                 visible: transfer.alignment === Transfer.After
0275                 Layout.fillWidth: true
0276             }
0277 
0278             QQC2.Label {
0279                 Layout.fillWidth: true
0280                 text: {
0281                     if (!Util.isLocationChange(root.reservation)) {
0282                         return i18n("%1 starts at %2", root.reservation.reservationFor.name, Localizer.formatTime(transfer, "anchorTime"));
0283                     }
0284                     return i18n("Following departure %1 from %2", Localizer.formatTime(transfer, "anchorTime"), transfer.toName);
0285                 }
0286                 visible: transfer.alignment === Transfer.Before
0287             }
0288 
0289             QQC2.ComboBox {
0290                 id: favLocCombo
0291                 model: FavoriteLocationModel
0292                 visible: transfer.floatingLocationType === Transfer.FavoriteLocation
0293                 textRole: "display"
0294                 Layout.fillWidth: true
0295                 onActivated: {
0296                     var favLoc = delegateModel.items.get(currentIndex)
0297                     console.log(favLoc.model.favoriteLocation);
0298                     root.transfer = TransferManager.setFavoriteLocationForTransfer(root.transfer, favLoc.model.favoriteLocation);
0299                     queryJourney();
0300                 }
0301             }
0302         }
0303     }
0304 
0305     ListView {
0306         id: journeyView
0307 
0308         clip: true
0309         delegate: journeyDelegate
0310         model: sortedJourneyModel
0311         spacing: Kirigami.Units.largeSpacing
0312 
0313         header: VerticalNavigationButton {
0314             visible: journeyModel.canQueryPrevious
0315             width: journeyView.width
0316             text: i18nc("@action:button", "Load earlier connections")
0317             iconName: "go-up-symbolic"
0318             onClicked: journeyModel.queryPrevious()
0319         }
0320 
0321         footer: VerticalNavigationButton {
0322             visible: journeyModel.canQueryNext
0323             width: journeyView.width
0324             iconName: "go-down-symbolic"
0325             text: i18nc("@action:button", "Load later connections")
0326             onClicked: journeyModel.queryNext()
0327 
0328             FormCard.FormCard {
0329                 visible: journeyModel.attributions.length > 0
0330 
0331                 FormCard.FormTextDelegate {
0332                     text: i18n("Data providers:")
0333                     description: PublicTransport.attributionSummary(journeyModel.attributions)
0334                     onLinkActivated: Qt.openUrlExternally(link)
0335                 }
0336             }
0337         }
0338 
0339         QQC2.BusyIndicator {
0340             anchors.centerIn: parent
0341             running: journeyModel.loading
0342         }
0343 
0344         QQC2.Label {
0345             anchors.centerIn: parent
0346             width: parent.width - Kirigami.Units.gridUnit * 4
0347             text: journeyModel.errorMessage
0348             color: Kirigami.Theme.negativeTextColor
0349             wrapMode: Text.Wrap
0350         }
0351     }
0352 }