Commit 416c7103 authored by Nicolas Fella's avatar Nicolas Fella

Add backend configuration

parent 296907c8
......@@ -15,7 +15,7 @@ include(KDECMakeSettings)
include(KDEClangFormat)
find_package(Qt5 REQUIRED COMPONENTS Gui Qml Quick)
find_package(KF5 REQUIRED COMPONENTS I18n ItemModels)
find_package(KF5 REQUIRED COMPONENTS I18n ItemModels Config)
if (ANDROID)
# runtime dependencies are build-time dependencies on Android
......
......@@ -8,12 +8,14 @@ set(ktrip_SRCS
resources.qrc
)
kconfig_add_kcfg_files(ktrip_SRCS ktripsettings.kcfgc GENERATE_MOC)
if (ANDROID)
list(APPEND ktrip_SRCS androidutils.cpp)
endif()
add_executable(ktrip ${ktrip_SRCS})
target_link_libraries(ktrip PRIVATE Qt5::Qml Qt5::Gui KF5::I18n KPublicTransport)
target_link_libraries(ktrip PRIVATE Qt5::Qml Qt5::Gui KF5::I18n KF5::ConfigGui KPublicTransport)
if (ANDROID)
target_link_libraries(ktrip PRIVATE
......
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="ktriprc" />
<group name="Backends">
<entry name="EnabledBackends" type="StringList">
<label>Enabled backends</label>
<default></default>
</entry>
<entry name="DisabledBackends" type="StringList">
<label>Disabled backends</label>
<default>at_6_vvst,be_sncb,ch_sbb,pl_pkp,railteam</default>
</entry>
</group>
</kcfg>
File=ktripsettings.kcfg
ClassName=KTripSettings
Mutators=true
DefaultValueGetters=true
GenerateProperties=true
ParentInConstructor=true
......@@ -22,6 +22,7 @@
#include "formatter.h"
#include "locationcache.h"
#include "querycontroller.h"
#include "ktripsettings.h"
#include <QQmlApplicationEngine>
#include <QQmlContext>
......@@ -70,8 +71,19 @@ int main(int argc, char *argv[])
engine.rootContext()->setContextProperty(QStringLiteral("_locationCache"), &locationCache);
KPublicTransport::Manager manager;
manager.setAllowInsecureBackends(true);
engine.rootContext()->setContextProperty(QStringLiteral("_manager"), &manager);
KTripSettings settings;
manager.setDisabledBackends(settings.disabledBackends());
manager.setEnabledBackends(settings.enabledBackends());
QObject::connect(&manager, &KPublicTransport::Manager::configurationChanged, &settings, [&settings, &manager]{
settings.setEnabledBackends(manager.enabledBackends());
settings.setDisabledBackends(manager.disabledBackends());
settings.save();
});
Formatter formatter;
engine.rootContext()->setContextProperty(QStringLiteral("_formatter"), &formatter);
......
/*
Copyright (C) 2019 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick 2.5
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
import org.kde.kirigami 2.4 as Kirigami
import org.kde.kpublictransport 1.0 as KPublicTransport
Kirigami.ScrollablePage {
id: root
title: i18n("Providers")
header: Kirigami.InlineMessage {
text: i18n("Select the providers relevant for your area")
visible: true
}
KPublicTransport.BackendModel {
id: backendModel
manager: _manager
}
Component {
id: backendDelegate
Kirigami.AbstractListItem {
highlighted: false
enabled: model.itemEnabled
GridLayout {
columns: 3
rows: 2
QQC2.Label {
text: model.name
Layout.fillWidth: true
}
Kirigami.Icon {
source: model.isSecure ? "channel-secure-symbolic" : "channel-insecure-symbolic"
color: model.isSecure ? Kirigami.Theme.positiveTextColor : Kirigami.Theme.negativeTextColor
width: height
height: Kirigami.Units.gridUnit
}
QQC2.Switch {
id: toggle
checked: model.backendEnabled
Layout.rowSpan: 2
onToggled: model.backendEnabled = checked;
}
QQC2.Label {
Layout.columnSpan: 2
Layout.fillWidth: true
text: model.description
font.italic: true
}
}
onClicked: {
toggle.toggle(); // does not trigger the signal handler for toggled...
model.backendEnabled = toggle.checked;
}
}
}
ListView {
model: backendModel
delegate: backendDelegate
}
}
......@@ -39,6 +39,10 @@ Kirigami.ApplicationWindow
Kirigami.Action {
text: i18n("Departures")
onTriggered: window.pageStack.initialPage = Qt.resolvedUrl("DepartureQueryPage.qml")
},
Kirigami.Action {
text: i18n("Providers")
onTriggered: window.pageStack.initialPage = Qt.resolvedUrl("BackendPage.qml")
}
]
}
......
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>qml/main.qml</file>
<file>qml/BackendPage.qml</file>
<file>qml/JourneyQueryPage.qml</file>
<file>qml/ConnectionsPage.qml</file>
<file>qml/LocationQueryPage.qml</file>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment