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

0001 /*
0002     SPDX-FileCopyrightText: 2019-2021 Volker Krause <vkrause@kde.org>
0003     SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 import QtQuick
0009 import QtQuick.Layouts
0010 import QtQuick.Controls as QQC2
0011 import org.kde.kirigami as Kirigami
0012 import org.kde.kitemmodels
0013 import org.kde.kpublictransport
0014 import org.kde.itinerary
0015 import org.kde.kirigamiaddons.formcard as FormCard
0016 
0017 Kirigami.ScrollablePage {
0018     id: root
0019 
0020     /** The journey selected by the user on this page. */
0021     property var journey
0022     /** The journey to query for. */
0023     property alias journeyRequest: journeyModel.request
0024     property alias publicTransportManager: journeyModel.manager
0025 
0026     Kirigami.Theme.inherit: false
0027     Kirigami.Theme.colorSet: Kirigami.Theme.Window
0028 
0029 
0030     actions: [
0031         Kirigami.Action {
0032             text: i18n("Earlier")
0033             icon.name: "go-up-symbolic"
0034             onTriggered: journeyModel.queryPrevious()
0035             enabled: journeyModel.canQueryPrevious
0036         },
0037         Kirigami.Action {
0038             text: i18n("Later")
0039             icon.name: "go-down-symbolic"
0040             onTriggered: journeyModel.queryNext()
0041             enabled: journeyModel.canQueryNext
0042         }
0043     ]
0044 
0045     ListView {
0046         id: journeyView
0047 
0048         clip: true
0049 
0050         delegate: FormCard.FormCard {
0051             id: top
0052 
0053             width: ListView.view.width
0054 
0055             required property int index
0056             required property var journey
0057 
0058             JourneyDelegateHeader {
0059                 journey: top.journey
0060             }
0061 
0062             Repeater {
0063                 id: journeyRepeater
0064                 delegate: JourneySectionDelegate {
0065                     Layout.fillWidth: true
0066                     modelLength: journeyRepeater.count - 1
0067                 }
0068                 model: journeyView.currentIndex === top.index ? top.journey.sections : 0
0069             }
0070 
0071             JourneySummaryDelegate {
0072                 id: summaryButton
0073 
0074                 journey: top.journey
0075                 visible: journeyView.currentIndex !== top.index
0076                 onClicked: journeyView.currentIndex = top.index
0077 
0078                 Layout.fillWidth: true
0079             }
0080 
0081             FormCard.FormDelegateSeparator {
0082                 visible: journeyView.currentIndex === top.index
0083                 above: selectButton
0084             }
0085 
0086             FormCard.FormButtonDelegate {
0087                 id: selectButton
0088 
0089                 text: i18n("Select")
0090                 icon.name: "checkmark"
0091                 visible: journeyView.currentIndex === top.index
0092                 enabled: top.journey.disruptionEffect !== Disruption.NoService
0093                 onClicked: root.journey = journey
0094             }
0095         }
0096 
0097         model: KSortFilterProxyModel {
0098             id: sortedJourneyModel
0099 
0100             sourceModel: JourneyQueryModel {
0101                 id: journeyModel
0102             }
0103             sortRole: JourneyQueryModel.ScheduledDepartureTime
0104             dynamicSortFilter: true
0105             Component.onCompleted: Util.sortModel(sortedJourneyModel, 0, Qt.Ascending)
0106         }
0107 
0108         spacing: Kirigami.Units.largeSpacing
0109 
0110         header: VerticalNavigationButton {
0111             visible: journeyModel.canQueryPrevious
0112             width: journeyView.width
0113             text: i18nc("@action:button", "Load earlier connections")
0114             iconName: "go-up-symbolic"
0115             onClicked: journeyModel.queryPrevious()
0116         }
0117 
0118         footer: VerticalNavigationButton {
0119             visible: journeyModel.canQueryNext
0120             width: journeyView.width
0121             iconName: "go-down-symbolic"
0122             text: i18nc("@action:button", "Load later connections")
0123             onClicked: journeyModel.queryNext()
0124 
0125             FormCard.FormCard {
0126                 visible: journeyModel.attributions.length > 0
0127 
0128                 FormCard.FormTextDelegate {
0129                     text: i18n("Data providers:")
0130                     description: PublicTransport.attributionSummary(journeyModel.attributions)
0131                     onLinkActivated: Qt.openUrlExternally(link)
0132                 }
0133             }
0134         }
0135 
0136         QQC2.BusyIndicator {
0137             anchors.centerIn: parent
0138             running: journeyModel.loading && journeyView.count === 0
0139         }
0140 
0141         QQC2.Label {
0142             anchors.centerIn: parent
0143             width: parent.width - Kirigami.Units.gridUnit * 4
0144             text: journeyModel.errorMessage
0145             color: Kirigami.Theme.negativeTextColor
0146             wrapMode: Text.Wrap
0147         }
0148     }
0149 
0150     footer: ColumnLayout {
0151         spacing: 0
0152         height: indicator.running ? layout.implicitHeight : 0
0153         visible: journeyModel.loading && journeyView.count !== 0
0154 
0155         Behavior on height {
0156             NumberAnimation { duration: Kirigami.Units.shortDuration }
0157         }
0158 
0159         Kirigami.Separator {
0160             Layout.fillWidth: true
0161         }
0162 
0163         RowLayout {
0164             id: layout
0165 
0166             QQC2.BusyIndicator {
0167                 id: indicator
0168                 running: journeyModel.loading && journeyView.count !== 0
0169             }
0170 
0171             QQC2.Label {
0172                 text: i18n("Still fetching results…")
0173             }
0174 
0175             Item {
0176                 Layout.fillWidth: true
0177             }
0178         }
0179     }
0180 }