diff --git a/engine/engineplasmoid/plasmoid/contents/ui/Timetable.qml b/engine/engineplasmoid/plasmoid/contents/ui/Timetable.qml new file mode 100644 index 0000000..601b1aa --- /dev/null +++ b/engine/engineplasmoid/plasmoid/contents/ui/Timetable.qml @@ -0,0 +1,85 @@ +import QtQuick 2.0 + +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.extras 2.0 as PlasmaExtras +import org.kde.plasma.components 2.0 as PlasmaComponents + +// TODO: import org.kde.plasma.publictransport.engine 1.0 + +Column { + id: timetableRoot + width: parent.width + + property var alternativeSourceExists: false + property var testArrivalSource: "Arrivals no_ruter|stop=Oslo Bussterminal" + property var testDepartureSource: "Departures no_ruter|stop=Oslo Bussterminal" + + property var arrivalSource: ( function isArrivalSource(source) { + return source.contains("Arrivals") + }) + property var departureSource: ( function isDepartureSource(source) { + return source.contains("Departures") + }) + property var testSource: ( function connectToTestSource(sourceType) { + arrivalSource(sourceType) + ? timetableSource.connectSource(testArrivalSource) + : timetableSource.connectSource(testDepartureSource) + }) + + ListModel { + id: timetableData + } + + PlasmaCore.DataSource { + id: timetableSource + + engine: "publictransport" + interval: 0 + + onSourceAdded: { + if (arrivalSource(source) || departureSource(source)) { + console.log("Connecting to new timetable source") + } + connectSource(source) + timetableData.append({name: source}) + } + + onSourceRemoved: { + // Remove source from model + for (var i = 0; i < timetableData.count; i++) { + if (timetableData.get(i).name === source) { + timetableData.remove(); + break; + } + } + + // Check if any valid sources exist + for (var i = 0; i < sources.count; i++) { + if (arrivalSource(sources[i]) || departureSource(sources[i]) ) { + alternativeSourceExists: true + } + } + + if (!alternativeSourceExists) { + console.error("No timetable sources found !") + } + } + + onNewData: { + // TODO + } + + onDataChanged: { + // TODO + } + + Component.onCompleted: { + connectedSources = sources + } + } + + Repeater { + model: timetableData + delegate: TimetableDelegate {} + } +} \ No newline at end of file diff --git a/engine/engineplasmoid/plasmoid/contents/ui/TimetableDelegate.qml b/engine/engineplasmoid/plasmoid/contents/ui/TimetableDelegate.qml new file mode 100644 index 0000000..d21ddba --- /dev/null +++ b/engine/engineplasmoid/plasmoid/contents/ui/TimetableDelegate.qml @@ -0,0 +1,28 @@ +import QtQuick 2.0 +import QtQuick.Layouts 1.1 + +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.extras 2.0 as PlasmaExtras +import org.kde.plasma.components 2.0 as PlasmaComponents + +Column { + id: timetableListView + + width: parent.width + height: parent.height + anchors.fill: parent + + readonly property string startStop: getModelData(timetableData.data, "StartStop", "Oslo Bussterminal") + readonly property string targetStop: getModelData(timetableData.data, "Target", "Unknown") + readonly property var stopDateTime: getModelData(timetableData.data, "DepartureDateTime", "00:00") + readonly property var routeStops: getModelData(timetableData.data, "RouteStops", "") + + function getModelData(data, key, defaultValue) { + var source = model.name + return data[source] ? ( data[source][key] ? data[source][key] : defaultValue ) : defaultValue + } + + PlasmaComponents.Label { + Text: targetStop + } +} \ No newline at end of file diff --git a/engine/engineplasmoid/plasmoid/contents/ui/main.qml b/engine/engineplasmoid/plasmoid/contents/ui/main.qml index 8b13789..8fb1a5f 100644 --- a/engine/engineplasmoid/plasmoid/contents/ui/main.qml +++ b/engine/engineplasmoid/plasmoid/contents/ui/main.qml @@ -1 +1,56 @@ +import QtQuick 2.0 +import QtQuick.Layouts 1.1 +import org.kde.plasmoid 2.0 +import org.kde.plasma.core as PlasmaCore 2.0 +import org.kde.plasma.components as PlasmaComponents 2.0 +import org.kde.plasma.extras as PlasmaExtras 2.0 + + +Item { + id: timetableApplet + + Layout.minimumWidth: 256 + Layout.minimumHeight: 256 + Layout.fillWidth: true + Layout.fillHeight: true + LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft + LayoutMirroring.childrenInherit: true + + property Item timetable: timetableLoader.item + + PlasmaExtras.Heading { + id: appletHeader + width: parent.width + visible: true + text: i18n("Stops list"); + } + + PlasmaExtras.ScrollArea { + id: mainScrollArea + anchors.fill: parent + + height: parent.height + width: parent.width + + Flickable { + id: timetableView + anchors.fill: parent + + contentWidth: width + contentHeight: contentsColumn.height + + Column { + id: contentsColumn + width: timetableView.width + + Loader { + id: timetableLoader + width: parent.width + source: "Timetable.qml" + active: true + } + } + } + } +} diff --git a/engine/engineplasmoid/plugin/enginehelper.cpp b/engine/engineplasmoid/plugin/enginehelper.cpp new file mode 100644 index 0000000..3d8591b --- /dev/null +++ b/engine/engineplasmoid/plugin/enginehelper.cpp @@ -0,0 +1,21 @@ +#include "enginehelper.h" + +EngineHelper::EngineHelper(QObject* parent) +{ + +} + +EngineHelper::~EngineHelper() +{ + +} + +bool EngineHelper::isArrivalSource() +{ + return false; +} + +bool EngineHelper::isDepartureSource() +{ + return false; +} \ No newline at end of file diff --git a/engine/engineplasmoid/plugin/enginehelper.h b/engine/engineplasmoid/plugin/enginehelper.h new file mode 100644 index 0000000..f974356 --- /dev/null +++ b/engine/engineplasmoid/plugin/enginehelper.h @@ -0,0 +1,20 @@ +#ifndef ENGINEHELPER_H +#define ENGINEHELPER_H + +#include +#include +#include + +class EngineHelper : public QObject +{ + Q_OBJECT + +public: + EngineHelper(QObject *parent=0); + ~EngineHelper(); + + Q_INVOKABLE bool isArrivalSource(); + Q_INVOKABLE bool isDepartureSource(); +}; + +#endif // ENGINEHELPER_H \ No newline at end of file diff --git a/engine/engineplasmoid/plugin/engineplugin.cpp b/engine/engineplasmoid/plugin/engineplugin.cpp index 2c91032..5d09d60 100644 --- a/engine/engineplasmoid/plugin/engineplugin.cpp +++ b/engine/engineplasmoid/plugin/engineplugin.cpp @@ -1,14 +1,14 @@ #include "backend.h" #include "engineplugin.h" #include -void EngiePlugin::registerTypes(const char *uri) +void EnginePlugin::registerTypes(const char *uri) { Q_ASSERT( uri == QLatin1String("org.kde.plasma.engineplugin") ); - qmlRegisterType( uri, 0, 1, "Backend" ); - qmlRegisterType( uri, 0, 1, "PublicTransportInfo"); - qmlRegisterType( uri, 0, 1, "DepartureInfo"); - qmlRegisterType( uri, 0, 1, "StopInfo" ); - qmlRegisterType( uri, 0, 1, "JourneyInfo" ); + qmlRegisterType( uri, 0, 1, "PublicTransportEngine"); } + +//void EnginePlugin::initializeEngine(QQmlEngine *engine, const char *uri) +//{ +//} diff --git a/engine/engineplasmoid/plugin/engineplugin.h b/engine/engineplasmoid/plugin/engineplugin.h index 3d71fa5..3888fab 100644 --- a/engine/engineplasmoid/plugin/engineplugin.h +++ b/engine/engineplasmoid/plugin/engineplugin.h @@ -1,16 +1,17 @@ #ifndef ENGINEPLUGIN_H #define ENGINEPLUGIN_H #include #include class EnginePlugin : public QQmlExtensionPlugin { Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionPlugin"); + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface"); public: virtual void registerTypes(const char *uri); + //virtual void initializeEngine(QQmlEngine *engine, const char *uri); }; #endif // ENGINEPLUGIN_H