diff --git a/engine/timetable/CMakeLists.txt b/engine/timetable/CMakeLists.txt index 09087d2..db8d8b8 100644 --- a/engine/timetable/CMakeLists.txt +++ b/engine/timetable/CMakeLists.txt @@ -1,24 +1,27 @@ add_definitions(-DTRANSLATION_DOMAIN=\"plasma_applet_org.kde.plasma.publictransport.timetable\") -set (timetable_SRCS timetableapplet.cpp) +plasma_install_package(plasmoid org.kde.plasma.publictransport.timetable) -add_library (timetable MODULE ${timetable_SRCS}) +set ( timetable_SRCS + plugin/timetableplugin.cpp + plugin/timetablehelper.cpp +) + +install (FILES plugin/qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/publictransport/timetable) + +add_library (timetable SHARED ${timetable_SRCS}) + +kcoreaddons_desktop_to_json(timetable plasmoid/metadata.desktop) target_link_libraries (timetable Qt5::Core Qt5::Qml Qt5::Quick Qt5::Widgets KF5::Plasma KF5::NewStuff KF5::CoreAddons KF5::KDELibs4Support ) -kcoreaddons_desktop_to_json(timetable package/metadata.desktop) - -install (TARGETS timetable DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/publictransport/timetable) -install (FILES package/metadata.desktop DESTINATION ${SERVICES_INSTALL_DIR}) -install (FILES publictransport.knsrc DESTINATION ${CONFIG_INSTALL_DIR}) - -plasma_install_package(package org.kde.plasma.publictransport.timetable) \ No newline at end of file +install (TARGETS timetable DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/publictransport/timetable) diff --git a/engine/timetable/package/contents/ui/CheckServiceproviders.qml b/engine/timetable/plasmoid/contents/ui/CheckServiceproviders.qml similarity index 95% rename from engine/timetable/package/contents/ui/CheckServiceproviders.qml rename to engine/timetable/plasmoid/contents/ui/CheckServiceproviders.qml index 57af9c6..8d3bb2e 100644 --- a/engine/timetable/package/contents/ui/CheckServiceproviders.qml +++ b/engine/timetable/plasmoid/contents/ui/CheckServiceproviders.qml @@ -1,78 +1,75 @@ /*************************************************************************** * Copyright (C) 2016 by R. Harish Navnit * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ import QtQuick 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents Item { id: serviceproviderCheckRoot anchors.fill: parent PlasmaComponents.Label { id: errorLabel anchors { verticalCenter: parent.verticalCenter horizontalCenter: parent.horizontalCenter } verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter text: i18n("Failed to locate any service providers" + "\nPlease download a service provider and try again") - visible: true + visible: false } PlasmaComponents.Button { id: downloadProvidersButton anchors { top: errorLabel.bottom topMargin: 2 horizontalCenter: parent.horizontalCenter } text: i18n("Download") - visible: true + visible: false // TODO: Integrate the applet code with the engine code // Add a Q_INVOKABLE method to show service provider // download dialog. - onClicked: plasmoid.nativeInterface.getNewProviders() + onClicked: plasmoid.nativeInterface.downloadNewProviders() } Loader { id: gtfsImportLoader anchors.fill: parent source: "GtfsService.qml" - active: false - /** active: { var data = mainDataSource.data["ServiceProviders"] if (data == undefined) { // No service providers found // Prompt the user to download new service providers errorLabel.visible = true downloadProvidersButton.visible = true return false } return true } - */ } } diff --git a/engine/timetable/package/contents/ui/GtfsService.qml b/engine/timetable/plasmoid/contents/ui/GtfsService.qml similarity index 100% rename from engine/timetable/package/contents/ui/GtfsService.qml rename to engine/timetable/plasmoid/contents/ui/GtfsService.qml diff --git a/engine/timetable/package/contents/ui/GtfsServiceDelegate.qml b/engine/timetable/plasmoid/contents/ui/GtfsServiceDelegate.qml similarity index 100% rename from engine/timetable/package/contents/ui/GtfsServiceDelegate.qml rename to engine/timetable/plasmoid/contents/ui/GtfsServiceDelegate.qml diff --git a/engine/timetable/package/contents/ui/Timetable.qml b/engine/timetable/plasmoid/contents/ui/Timetable.qml similarity index 100% rename from engine/timetable/package/contents/ui/Timetable.qml rename to engine/timetable/plasmoid/contents/ui/Timetable.qml diff --git a/engine/timetable/package/contents/ui/TimetableDelegate.qml b/engine/timetable/plasmoid/contents/ui/TimetableDelegate.qml similarity index 100% rename from engine/timetable/package/contents/ui/TimetableDelegate.qml rename to engine/timetable/plasmoid/contents/ui/TimetableDelegate.qml diff --git a/engine/timetable/package/contents/ui/main.qml b/engine/timetable/plasmoid/contents/ui/main.qml similarity index 97% rename from engine/timetable/package/contents/ui/main.qml rename to engine/timetable/plasmoid/contents/ui/main.qml index f1245da..ac5d9a5 100644 --- a/engine/timetable/package/contents/ui/main.qml +++ b/engine/timetable/plasmoid/contents/ui/main.qml @@ -1,93 +1,90 @@ /******************************************************************** Copyright (C) 2016 R. Harish Navnit This program is free software; you can redistribute it and/or modify it under the terms of the GNU 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 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 . *********************************************************************/ import QtQuick 2.0 import QtQuick.Layouts 1.1 -import org.kde.plasma.plasmoid 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 + Item { id: timetableApplet Layout.minimumWidth: 300 Layout.minimumHeight: 200 Layout.fillWidth: true Layout.fillHeight: true LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft LayoutMirroring.childrenInherit: true property string gtfsState: mainDataSource.data["ServiceProviders"][defaultProviderId()]["state"] property var defaultProviderId: (function getDefaultServiceProviderId() { var data = mainDataSource.data["ServiceProviders"] var serviceproviders = Object.keys(data) return serviceproviders[0] }) PlasmaCore.DataSource { id: mainDataSource interval: 6000 engine: "publictransport" // At this point we don't know if service providers exist locally // Hence it's not possible to form and connect to a arrival/departure source connectedSources: ["ServiceProviders"] } PlasmaComponents.Button { id: configureButton anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter text: i18n("Configure") - visible: true - /** visible: { var data = mainDataSource.data["ServiceProviders"][defaultProviderId()]["state"] if ( data == undefined) { return true } else if (gtfsState == "gtfs_feed_import_pending") { timetableLoader.active = false return true } else { timetableLoader.active = true return false } } - */ onClicked: { this.visible = false serviceproviderCheckLoader.active = true } } Loader { id: serviceproviderCheckLoader anchors.fill: parent source: "CheckServiceproviders.qml" active: false } Loader { id: timetableLoader anchors.fill: parent source: "Timetable.qml" active: false } } diff --git a/engine/timetable/package/metadata.desktop b/engine/timetable/plasmoid/metadata.desktop similarity index 100% rename from engine/timetable/package/metadata.desktop rename to engine/timetable/plasmoid/metadata.desktop diff --git a/engine/timetable/publictransport.knsrc b/engine/timetable/plugin/publictransport.knsrc similarity index 100% rename from engine/timetable/publictransport.knsrc rename to engine/timetable/plugin/publictransport.knsrc diff --git a/engine/timetable/plugin/qmldir b/engine/timetable/plugin/qmldir new file mode 100644 index 0000000..708444e --- /dev/null +++ b/engine/timetable/plugin/qmldir @@ -0,0 +1,2 @@ +module org.kde.plasma.private.publictransport.timetable +plugin timetable diff --git a/engine/timetable/plugin/timetablehelper.cpp b/engine/timetable/plugin/timetablehelper.cpp new file mode 100644 index 0000000..b1afa4f --- /dev/null +++ b/engine/timetable/plugin/timetablehelper.cpp @@ -0,0 +1,32 @@ +#include "timetablehelper.h" + +#include + +TimetableHelper::TimetableHelper(QWidget* parent) + : KDialog(parent) +{ +} + +TimetableHelper::~TimetableHelper() +{ +} + +void TimetableHelper::displayDownloadDialog() +{ + KNS3::DownloadDialog *dialog = new KNS3::DownloadDialog("publictransport.knsrc", this); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); +} + +TimetableExporter::TimetableExporter(QObject* parent, const QVariantList& data) +: Plasma::Applet(parent, data) +{ +} + +TimetableExporter::~TimetableExporter() +{ +} + +K_EXPORT_PLASMA_APPLET_WITH_JSON(timetableexporter, TimetableExporter, "metadata.json") + +#include "timetablehelper.moc" \ No newline at end of file diff --git a/engine/timetable/plugin/timetablehelper.h b/engine/timetable/plugin/timetablehelper.h new file mode 100644 index 0000000..22e8b78 --- /dev/null +++ b/engine/timetable/plugin/timetablehelper.h @@ -0,0 +1,37 @@ +#ifndef TIMETABLEHELPER_H +#define TIMETABLEHELPER_H + +#include +#include + +#include +#include + +/** + * Class that aims to display the GHNS dialog + * Enables the user to download new service providers + */ +class TimetableHelper : public KDialog +{ + Q_OBJECT + +public: + TimetableHelper(QWidget *parent=0); + ~TimetableHelper(); + + Q_INVOKABLE void displayDownloadDialog(); +}; + +/** + * Class to export the desktop file to json format + */ +class TimetableExporter : public Plasma::Applet +{ + Q_OBJECT + +public: + TimetableExporter(QObject *parent, const QVariantList &data); + ~TimetableExporter() override; +}; + +#endif // TIMETABLEHELPER_H \ No newline at end of file diff --git a/engine/timetable/plugin/timetableplugin.cpp b/engine/timetable/plugin/timetableplugin.cpp new file mode 100644 index 0000000..d55c926 --- /dev/null +++ b/engine/timetable/plugin/timetableplugin.cpp @@ -0,0 +1,10 @@ +#include "timetableplugin.h" +#include "timetablehelper.h" + +#include + +void TimetablePlugin::registerTypes(const char *uri) +{ + Q_ASSERT( uri == QLatin1String("org.kde.plasma.private.publictransport.timetable") ); + qmlRegisterType( uri, 0, 1, "TimetableHelper" ); +} diff --git a/engine/timetable/plugin/timetableplugin.h b/engine/timetable/plugin/timetableplugin.h new file mode 100644 index 0000000..f571221 --- /dev/null +++ b/engine/timetable/plugin/timetableplugin.h @@ -0,0 +1,16 @@ +#ifndef TIMETABLEPLUGIN_H +#define TIMETABLEPLUGIN_H + +#include +#include + +class TimetablePlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface"); + +public: + virtual void registerTypes(const char *uri); +}; + +#endif // TIMETABLEPLUGIN_H \ No newline at end of file diff --git a/engine/timetable/timetableapplet.cpp b/engine/timetable/timetableapplet.cpp deleted file mode 100644 index 0a94177..0000000 --- a/engine/timetable/timetableapplet.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "timetableapplet.h" - -#include - -#include - -TimetableHelper::TimetableHelper(QObject* parent, const QVariantList& data) -: Plasma::Applet(parent, data) -{ -} - -TimetableHelper::~TimetableHelper() -{ -} - -void TimetableHelper::getNewProviders() -{ - KNS3::DownloadDialog *dialog = new KNS3::DownloadDialog(QString::fromLatin1("publictransport.knsrc")); - dialog->setAttribute(Qt::WA_DeleteOnClose); - dialog->show(); -} - -K_EXPORT_PLASMA_APPLET_WITH_JSON(timetablehelper, TimetableHelper, "metadata.json") - -#include "timetableapplet.moc" diff --git a/engine/timetable/timetableapplet.h b/engine/timetable/timetableapplet.h deleted file mode 100644 index 5ba0b51..0000000 --- a/engine/timetable/timetableapplet.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef TIMETABLEAPPLET_H -#define TIMETABLEAPPLET_H - -#include - -#include - -/** - * Class to export the desktop file to json format - * and display GHNS download dialog - */ -class TimetableHelper : public Plasma::Applet -{ - Q_OBJECT - -public: - TimetableHelper(QObject *parent, const QVariantList &data); - ~TimetableHelper(); - -public slots: - Q_INVOKABLE void getNewProviders(); -}; - -#endif // TIMETABLEAPPLET_H