diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 9e152f3..8430506 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -1,145 +1,150 @@ if (TARGET KF5::Notifications) SET(HAVE_NOTIFICATIONS TRUE) endif() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-itinerary.h.in ${CMAKE_CURRENT_BINARY_DIR}/config-itinerary.h) set(itinerary_srcs applicationcontroller.cpp contenttypeprober.cpp countryinformation.cpp pkpassmanager.cpp pkpassimageprovider.cpp reservationmanager.cpp timelinemodel.cpp tripgroup.cpp tripgroupmanager.cpp tripgroupproxymodel.cpp ) ecm_qt_declare_logging_category(itinerary_srcs HEADER logging.h IDENTIFIER Log CATEGORY_NAME org.kde.itinerary ) add_library(itinerary STATIC ${itinerary_srcs}) target_link_libraries(itinerary PUBLIC itinerary-weather KPim::Itinerary KPim::PkPass KF5::I18n Qt5::Network Qt5::Quick ) if (Qt5QuickCompiler_FOUND) qtquick_compiler_add_resources(qml_srcs qml.qrc) else () set(qml_srcs qml.qrc) endif() set(itinerary_app_srcs main.cpp countrymodel.cpp localizer.cpp settings.cpp tickettokenmodel.cpp util.cpp weatherforecastmodel.cpp ${qml_srcs} brightnessmanager.cpp + lockmanager.cpp livedatamanager.cpp journeyquerymodel.cpp publictransport.cpp ) if (ANDROID) list(APPEND itinerary_app_srcs androidbrightnessbackend.cpp androidcontentfileengine.cpp + androidlockbackend.cpp ) else() - list(APPEND itinerary_app_srcs solidbrightnessbackend.cpp) + list(APPEND itinerary_app_srcs + solidbrightnessbackend.cpp + solidlockbackend.cpp + ) qt5_add_dbus_interface(itinerary_app_srcs org.kde.Solid.PowerManagement.Actions.BrightnessControl.xml brightnesscontroldbusinterface) endif() add_executable(itinerary-app ${itinerary_app_srcs}) target_include_directories(itinerary-app PRIVATE ${CMAKE_BINARY_DIR}) target_link_libraries(itinerary-app PRIVATE itinerary KF5::Contacts KF5::CoreAddons KPublicTransport ) if (TARGET KF5::Notifications) target_link_libraries(itinerary-app PRIVATE KF5::Notifications) endif() if (ANDROID) target_include_directories(itinerary-app PRIVATE ${Qt5Core_PRIVATE_INCLUDE_DIRS}) # explicitly add runtime dependencies and transitive link dependencies, # so androiddeployqt picks them up target_link_libraries(itinerary PUBLIC Qt5::AndroidExtras) target_link_libraries(itinerary-app PRIVATE KF5::Archive KF5::Kirigami2 Qt5::Svg KF5::Prison OpenSSL::SSL ) kirigami_package_breeze_icons(ICONS checkmark clock dialog-cancel document-edit document-open document-save documentinfo edit-delete edit-download edit-paste go-down-symbolic go-home go-next-symbolic go-up-symbolic help-about map-symbolic meeting-attending settings-configure view-calendar-day view-refresh weather-clear weather-clear-night weather-few-clouds weather-few-clouds-night weather-clouds weather-clouds-night weather-showers-day weather-showers-night weather-showers-scattered-day weather-showers-scattered-night weather-snow-scattered-day weather-snow-scattered-night weather-storm-day weather-storm-night weather-many-clouds weather-fog weather-showers weather-showers-scattered weather-hail weather-snow weather-snow-scattered weather-storm ) else () target_link_libraries(itinerary PRIVATE Qt5::Positioning Qt5::DBus) target_link_libraries(itinerary-app PRIVATE KF5::DBusAddons Qt5::Widgets ) set_target_properties(itinerary-app PROPERTIES OUTPUT_NAME "itinerary") endif() install(TARGETS itinerary-app ${INSTALL_TARGETS_DEFAULT_ARGS}) if (NOT ANDROID) install(PROGRAMS org.kde.itinerary.desktop DESTINATION ${KDE_INSTALL_APPDIR}) endif() install(FILES org.kde.itinerary.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR}) diff --git a/src/app/PkPassBarcode.qml b/src/app/PkPassBarcode.qml index 2e11565..d3e78a2 100644 --- a/src/app/PkPassBarcode.qml +++ b/src/app/PkPassBarcode.qml @@ -1,57 +1,60 @@ /* Copyright (C) 2018 Volker Krause 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 . */ import QtQuick 2.5 import QtQuick.Layouts 1.1 import QtQuick.Controls 2.1 as QQC2 import org.kde.pkpass 1.0 as KPkPass import org.kde.prison 1.0 as Prison Rectangle { property var pass implicitHeight: barcodeLayout.implicitHeight implicitWidth: barcodeLayout.implicitWidth color: "white" radius: 6 Layout.alignment: Qt.AlignCenter MouseArea { anchors.fill: parent - onDoubleClicked: _brightnessManager.toggleBrightness(); + onDoubleClicked: { + _brightnessManager.toggleBrightness() + _lockManager.toggleInhibitScreenLock() + } } ColumnLayout { id: barcodeLayout anchors.fill: parent Prison.Barcode { Layout.alignment: Qt.AlignCenter Layout.margins: 4 Layout.preferredWidth: Math.max(implicitWidth, 0.8 * bodyBackground.width) Layout.preferredHeight: Layout.preferredWidth barcodeType: pass.barcodes[0].format == KPkPass.Barcode.QR ? Prison.Barcode.QRCode : Prison.Barcode.Aztec content: pass.barcodes[0].message } QQC2.Label { Layout.alignment: Qt.AlignCenter text: pass.barcodes[0].alternativeText color: "black" visible: text.length > 0 } } } diff --git a/src/app/TicketTokenDelegate.qml b/src/app/TicketTokenDelegate.qml index 1f30208..930fe19 100644 --- a/src/app/TicketTokenDelegate.qml +++ b/src/app/TicketTokenDelegate.qml @@ -1,111 +1,114 @@ /* Copyright (C) 2018 Volker Krause 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 . */ import QtQuick 2.5 import QtQuick.Layouts 1.1 import QtQuick.Controls 2.1 as QQC2 import QtQuick.Window 2.10 import org.kde.kirigami 2.0 as Kirigami import org.kde.prison 1.0 as Prison import org.kde.kitinerary 1.0 import org.kde.itinerary 1.0 import "." as App ColumnLayout { id: root property var resIds readonly property var currentReservationId: ticketModel.reservationIdAt(travelerBox.currentIndex) readonly property var currentTicket: ticketModel.reservationAt(travelerBox.currentIndex).reservedTicket Layout.fillWidth: true TicketTokenModel { id: ticketModel reservationManager: _reservationManager reservationIds: resIds } QQC2.ComboBox { id: travelerBox Layout.alignment: Qt.AlignCenter model: ticketModel textRole: "display" Layout.fillWidth: true // ugly, but rowCount does not trigger binding changes Component.onCompleted: visible = ticketModel.rowCount() >= 1 && root.resIds.length > 1 } Item { id: barcodeContainer Layout.alignment: Qt.AlignCenter Layout.fillWidth: true implicitHeight: childrenRect.height Rectangle { id: background anchors.centerIn: barcodeContainer anchors.top: barcodeContainer.top anchors.bottom: barcodeContainer.bottom color: "white" // aim at 50x50mm for 2d codes, and 25mm height for 1d codes, if we have the space for it property bool is1dCode: currentTicket.ticketTokenType == Ticket.Code128 // if this gets too wide, we need to rotate by 90° property bool showVertical: is1dCode && barcodeTargetWidth > root.width // unrotated barcode sizes property int barcodeTargetWidth: Math.max( (is1dCode ? 2 * barcode.implicitWidth : barcode.implicitWidth) + 2 * barcode.anchors.margins, Screen.pixelDensity * 50) property int barcodeTargetHeight: is1dCode ? Screen.pixelDensity * 25 : barcodeTargetWidth implicitWidth: (showVertical ? barcodeTargetHeight : barcodeTargetWidth) + 2 * Kirigami.Units.smallSpacing implicitHeight: visible ? (showVertical ? barcodeTargetWidth : barcodeTargetHeight) + 2 * Kirigami.Units.smallSpacing : 0 visible: barcode.implicitHeight > 0 MouseArea { anchors.fill: parent - onDoubleClicked: _brightnessManager.toggleBrightness(); + onDoubleClicked: { + _brightnessManager.toggleBrightness() + _lockManager.toggleInhibitScreenLock() + } } Prison.Barcode { id: barcode anchors.centerIn: background width: background.barcodeTargetWidth height: background.barcodeTargetHeight rotation: background.showVertical ? 90 : 0 barcodeType: { if (currentTicket == undefined) return Prison.Barcode.Null; switch (currentTicket.ticketTokenType) { case Ticket.QRCode: return Prison.Barcode.QRCode; case Ticket.AztecCode: return Prison.Barcode.Aztec; case Ticket.Code128: return Prison.Barcode.Code128; } return Prison.Barcode.Null; } content: { if (barcodeType == Prison.Barcode.Null || currentTicket == undefined) return ""; return currentTicket.ticketTokenData; } } } } } diff --git a/src/app/androidlockbackend.cpp b/src/app/androidlockbackend.cpp new file mode 100644 index 0000000..37ddd73 --- /dev/null +++ b/src/app/androidlockbackend.cpp @@ -0,0 +1,41 @@ +/* + Copyright (C) 2019 Nicolas Fella + + 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 . +*/ + +#include "androidlockbackend.h" + +#include +#include +#include + +AndroidLockBackend::AndroidLockBackend(QObject *parent) + : LockBackend(parent) +{ +} + +AndroidLockBackend::~AndroidLockBackend() +{ +} + +void AndroidLockBackend::setInhibitionOff() +{ + QtAndroid::androidActivity().callMethod("setLockInhibitionOff"); +} + +void AndroidLockBackend::setInhibitionOn() +{ + QtAndroid::androidActivity().callMethod("setLockInhibitionOn"); +} diff --git a/src/app/androidlockbackend.h b/src/app/androidlockbackend.h new file mode 100644 index 0000000..0d5cf5f --- /dev/null +++ b/src/app/androidlockbackend.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2019 Nicolas Fella + + 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 . +*/ + +#ifndef ANDROIDLOCKBACKEND_H +#define ANDROIDLOCKBACKEND_H + +#include +#include "lockmanager.h" + + +class AndroidLockBackend : public LockBackend +{ + +public: + explicit AndroidLockBackend(QObject *parent = nullptr); + virtual ~AndroidLockBackend(); + + void setInhibitionOff() override; + void setInhibitionOn() override; +}; + +#endif // ANDROIDBRIGHTNESSBACKEND_H + diff --git a/src/app/lockmanager.cpp b/src/app/lockmanager.cpp new file mode 100644 index 0000000..669e058 --- /dev/null +++ b/src/app/lockmanager.cpp @@ -0,0 +1,52 @@ +/* + Copyright (C) 2019 Nicolas Fella + + 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 . +*/ + +#include "lockmanager.h" + +#include + +#if defined(Q_OS_ANDROID) +#include "androidlockbackend.h" +#elif defined(Q_OS_LINUX) +#include "solidlockbackend.h" +#endif + +LockManager::LockManager(QObject *parent) + : QObject(parent) + , m_inhibit() +{ +#if defined(Q_OS_ANDROID) + m_backend = new AndroidLockBackend(this); +#elif defined(Q_OS_LINUX) + m_backend = new SolidLockBackend(this); +#endif +} + +LockManager::~LockManager() = default; + +void LockManager::toggleInhibitScreenLock() +{ + if (!m_backend) + return; + + if (m_inhibit) { + m_backend->setInhibitionOff(); + } else { + m_backend->setInhibitionOn(); + } + m_inhibit = !m_inhibit; +} diff --git a/src/app/lockmanager.h b/src/app/lockmanager.h new file mode 100644 index 0000000..4db29e1 --- /dev/null +++ b/src/app/lockmanager.h @@ -0,0 +1,50 @@ +/* + Copyright (C) 2019 Nicolas Fella + + 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 . +*/ + +#ifndef LOCKMANAGER_H +#define LOCKMANAGER_H + +#include + +class LockBackend : public QObject +{ +public: + explicit LockBackend(QObject *parent = nullptr) : QObject(parent) + {} + virtual ~LockBackend() = default; + virtual void setInhibitionOn() = 0; + virtual void setInhibitionOff() = 0; +}; + +class LockManager : public QObject +{ + Q_OBJECT + +public: + explicit LockManager(QObject *parent = nullptr); + ~LockManager(); + +public Q_SLOTS: + void toggleInhibitScreenLock(); +private: + LockBackend *m_backend; + bool m_inhibit; +}; + +#endif // LOCKMANAGER_H + + diff --git a/src/app/main.cpp b/src/app/main.cpp index afdc63e..d73172d 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -1,232 +1,235 @@ /* Copyright (C) 2018 Volker Krause 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 . */ #include "itinerary_version.h" #include "logging.h" #include "applicationcontroller.h" #include "brightnessmanager.h" #include "countryinformation.h" #include "countrymodel.h" #include "journeyquerymodel.h" #include "livedatamanager.h" #include "localizer.h" #include "pkpassmanager.h" #include "timelinemodel.h" #include "pkpassimageprovider.h" #include "reservationmanager.h" #include "settings.h" #include "tickettokenmodel.h" #include "tripgroupmanager.h" #include "tripgroupproxymodel.h" #include "util.h" #include "weatherforecastmodel.h" +#include "lockmanager.h" #include #include #include #include #include #include #include #include #include #ifndef Q_OS_ANDROID #include #endif #include #include #include #include #ifdef Q_OS_ANDROID #include "androidcontentfileengine.h" #include #include #else #include #endif #include #include #include #include #include #include void handleViewIntent(ApplicationController *appController) { #ifdef Q_OS_ANDROID // handle opened files const auto activity = QtAndroid::androidActivity(); if (!activity.isValid()) return; const auto intent = activity.callObjectMethod("getIntent", "()Landroid/content/Intent;"); appController->importFromIntent(intent); #else Q_UNUSED(appController); #endif } void handlePositionalArguments(ApplicationController *appController, const QStringList &args) { for (const auto &file : args) { const auto localUrl = QUrl::fromLocalFile(file); if (QFile::exists(localUrl.toLocalFile())) appController->importFromUrl(localUrl); else appController->importFromUrl(QUrl::fromUserInput(file)); } } #ifdef Q_OS_ANDROID Q_DECL_EXPORT #endif int main(int argc, char **argv) { QCoreApplication::setApplicationName(QStringLiteral("itinerary")); QCoreApplication::setOrganizationName(QStringLiteral("KDE")); QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org")); QCoreApplication::setApplicationVersion(QStringLiteral(ITINERARY_VERSION_STRING)); QGuiApplication::setApplicationDisplayName(i18n("KDE Itinerary")); QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); #ifdef Q_OS_ANDROID AndroidContentFileEngineHandler fsEngineHandler; QGuiApplication app(argc, argv); #else QApplication app(argc, argv); // for native file dialogs #endif QGuiApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("map-globe"))); QCommandLineParser parser; parser.addHelpOption(); parser.addVersionOption(); parser.addPositionalArgument(QStringLiteral("file"), i18n("PkPass or JSON-LD file to import.")); parser.process(app); #ifndef Q_OS_ANDROID KDBusService service(KDBusService::Unique); #endif Settings settings; PkPassManager passMgr; ReservationManager resMgr; resMgr.setPkPassManager(&passMgr); TripGroupManager tripGroupMgr; tripGroupMgr.setReservationManager(&resMgr); ApplicationController appController; appController.setReservationManager(&resMgr); appController.setPkPassManager(&passMgr); BrightnessManager brightnessManager; + LockManager lockManager; KPublicTransport::Manager ptMgr; ptMgr.setAllowInsecureBackends(settings.allowInsecureServices()); QObject::connect(&settings, &Settings::allowInsecureServicesChanged, [&ptMgr](bool insec) { ptMgr.setAllowInsecureBackends(insec); }); LiveDataManager liveDataMgr; liveDataMgr.setPublicTransportManager(&ptMgr); liveDataMgr.setPkPassManager(&passMgr); liveDataMgr.setReservationManager(&resMgr); liveDataMgr.setPollingEnabled(settings.queryLiveData()); QObject::connect(&settings, &Settings::queryLiveDataChanged, &liveDataMgr, &LiveDataManager::setPollingEnabled); JourneyQueryModel journeyQueryModel; journeyQueryModel.setReservationManager(&resMgr); journeyQueryModel.setPublicTransportManager(&ptMgr); #ifndef Q_OS_ANDROID QObject::connect(&service, &KDBusService::activateRequested, [&parser, &appController](const QStringList &args, const QString &workingDir) { qCDebug(Log) << "remote activation" << args << workingDir; if (!args.isEmpty()) { QDir::setCurrent(workingDir); parser.parse(args); handlePositionalArguments(&appController, parser.positionalArguments()); } if (!QGuiApplication::allWindows().isEmpty()) { QGuiApplication::allWindows().at(0)->requestActivate(); } }); #endif TimelineModel timelineModel; timelineModel.setHomeCountryIsoCode(settings.homeCountryIsoCode()); timelineModel.setReservationManager(&resMgr); QObject::connect(&settings, &Settings::homeCountryIsoCodeChanged, &timelineModel, &TimelineModel::setHomeCountryIsoCode); QObject::connect(&liveDataMgr, &LiveDataManager::arrivalUpdated, &timelineModel, &TimelineModel::dataChangedForReservation); QObject::connect(&liveDataMgr, &LiveDataManager::departureUpdated, &timelineModel, &TimelineModel::dataChangedForReservation); WeatherForecastManager weatherForecastMgr; weatherForecastMgr.setAllowNetworkAccess(settings.weatherForecastEnabled()); QObject::connect(&settings, &Settings::weatherForecastEnabledChanged, &weatherForecastMgr, &WeatherForecastManager::setAllowNetworkAccess); timelineModel.setWeatherForecastManager(&weatherForecastMgr); timelineModel.setTripGroupManager(&tripGroupMgr); TripGroupProxyModel tripGroupProxy; tripGroupProxy.setSourceModel(&timelineModel); qmlRegisterUncreatableType("org.kde.pkpass", 1, 0, "Barcode", {}); qmlRegisterUncreatableType("org.kde.pkpass", 1, 0, "Field", {}); qmlRegisterUncreatableType("org.kde.pkpass", 1, 0, "Pass", {}); qmlRegisterUncreatableType("org.kde.pkpass", 1, 0, "BoardingPass", {}); qmlRegisterUncreatableType("org.kde.kpublictransport", 1, 0, "Line", {}); qmlRegisterUncreatableType("org.kde.kpublictransport", 1, 0, "JourneySection", {}); qRegisterMetaType(); qmlRegisterUncreatableType("org.kde.kitinerary", 1, 0, "Ticket", {}); qmlRegisterUncreatableMetaObject(KItinerary::KnowledgeDb::staticMetaObject, "org.kde.kitinerary", 1, 0, "KnowledgeDb", {}); qmlRegisterUncreatableType("org.kde.itinerary", 1, 0, "CountryInformation", {}); qmlRegisterType("org.kde.itinerary", 1, 0, "CountryModel"); qmlRegisterSingletonType("org.kde.itinerary", 1, 0, "Localizer", [](QQmlEngine*, QJSEngine *engine) -> QJSValue { return engine->toScriptValue(Localizer()); }); qmlRegisterType("org.kde.itinerary", 1, 0, "TicketTokenModel"); qmlRegisterUncreatableType("org.kde.itinerary", 1, 0, "TimelineModel", {}); qmlRegisterSingletonType("org.kde.itinerary", 1, 0, "Util", [](QQmlEngine*, QJSEngine*) -> QObject*{ return new Util; }); qmlRegisterType("org.kde.itinerary", 1, 0, "WeatherForecastModel"); QQmlApplicationEngine engine; engine.addImageProvider(QStringLiteral("org.kde.pkpass"), new PkPassImageProvider(&passMgr)); engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); engine.rootContext()->setContextProperty(QStringLiteral("_pkpassManager"), &passMgr); engine.rootContext()->setContextProperty(QStringLiteral("_reservationManager"), &resMgr); engine.rootContext()->setContextProperty(QStringLiteral("_timelineModel"), &tripGroupProxy); engine.rootContext()->setContextProperty(QStringLiteral("_appController"), &appController); engine.rootContext()->setContextProperty(QStringLiteral("_settings"), &settings); engine.rootContext()->setContextProperty(QStringLiteral("_weatherForecastManager"), &weatherForecastMgr); engine.rootContext()->setContextProperty(QStringLiteral("_brightnessManager"), &brightnessManager); + engine.rootContext()->setContextProperty(QStringLiteral("_lockManager"), &lockManager); engine.rootContext()->setContextProperty(QStringLiteral("_liveDataManager"), &liveDataMgr); engine.rootContext()->setContextProperty(QStringLiteral("_journeyQueryModel"), &journeyQueryModel); engine.load(QStringLiteral("qrc:/main.qml")); handlePositionalArguments(&appController, parser.positionalArguments()); handleViewIntent(&appController); return app.exec(); } diff --git a/src/app/solidlockbackend.cpp b/src/app/solidlockbackend.cpp new file mode 100644 index 0000000..be49538 --- /dev/null +++ b/src/app/solidlockbackend.cpp @@ -0,0 +1,41 @@ +/* + Copyright (C) 2019 Nicolas Fella + + 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 . +*/ + +#include "solidlockbackend.h" + +#include +#include + +SolidLockBackend::SolidLockBackend(QObject *parent) + : LockBackend(parent) +{ +} + +SolidLockBackend::~SolidLockBackend() +{ +} + +void SolidLockBackend::setInhibitionOff() +{ + qDebug() << "Off"; +} + +void SolidLockBackend::setInhibitionOn() +{ + qDebug() << "ON"; +} + diff --git a/src/app/solidlockbackend.h b/src/app/solidlockbackend.h new file mode 100644 index 0000000..4c4561b --- /dev/null +++ b/src/app/solidlockbackend.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2019 Nicolas Fella + + 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 . +*/ + +#ifndef SOLIDLOCKBACKEND_H +#define SOLIDLOCKBACKEND_H + +#include +#include "lockmanager.h" + +class SolidLockBackend : public LockBackend +{ + +public: + explicit SolidLockBackend(QObject *parent = nullptr); + ~SolidLockBackend() override; + + void setInhibitionOff() override; + void setInhibitionOn() override; +}; + +#endif // SOLIDLOCKBACKEND_H + diff --git a/src/app/src/org/kde/itinerary/Activity.java b/src/app/src/org/kde/itinerary/Activity.java index 837658e..3b67e90 100644 --- a/src/app/src/org/kde/itinerary/Activity.java +++ b/src/app/src/org/kde/itinerary/Activity.java @@ -1,114 +1,122 @@ /* Copyright (C) 2018 Volker Krause 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 . */ package org.kde.itinerary; import org.qtproject.qt5.android.bindings.QtActivity; import net.fortuna.ical4j.model.property.XProperty; import android.content.ContentResolver; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.provider.CalendarContract; import android.util.Log; import android.view.WindowManager; import java.io.*; import java.util.*; public class Activity extends QtActivity { private static final String TAG = "org.kde.itinerary"; public void launchViewIntentFromUri(String uri) { Uri mapIntentUri = Uri.parse(uri); Intent mapIntent = new Intent(Intent.ACTION_VIEW, mapIntentUri); startActivity(mapIntent); } public native void importReservation(String data); public native void importFromIntent(Intent data); /** Check the calendar for with JSON-LD data. * This assumes the custom property serialization format used by DavDroid. */ public void checkCalendar() { Calendar startTime = Calendar.getInstance(); startTime.add(Calendar.DAY_OF_YEAR, -5); Calendar endTime = Calendar.getInstance(); endTime.add(Calendar.MONTH, 6); String[] eventColumns = new String[] { "uid2445", "title", "_id" }; String[] propColumns = new String[] { "name", "value" }; String eventSelection = "(( " + CalendarContract.Events.DTSTART + " >= " + startTime.getTimeInMillis() + " ) AND ( " + CalendarContract.Events.DTSTART + " <= " + endTime.getTimeInMillis() + " ))"; Cursor cursor = getContentResolver().query(CalendarContract.Events.CONTENT_URI, eventColumns, eventSelection, null, null); while (cursor.moveToNext()) { if (cursor.getString(0) == null || !cursor.getString(0).startsWith("KIT-")) { continue; } Log.i(TAG, cursor.getString(1)); String propSelection = "(event_id == " + cursor.getInt(2) + ")"; Cursor propCursor = getContentResolver().query(CalendarContract.ExtendedProperties.CONTENT_URI, propColumns, propSelection, null, null); while (propCursor.moveToNext()) { if (propCursor.getString(0) == null || !propCursor.getString(0).equals("unknown-property") || propCursor.getString(1) == null) { continue; } ByteArrayInputStream bis = new ByteArrayInputStream(android.util.Base64.decode(propCursor.getString(1), android.util.Base64.NO_WRAP)); try { ObjectInputStream ois = new ObjectInputStream(bis); Object prop = ois.readObject(); if (prop instanceof XProperty) { importReservation(((XProperty)prop).getValue()); } } catch (Exception e) { Log.i(TAG, e.toString()); continue; } } } } public void setBrightness(final float brightness) { runOnUiThread(new Runnable() { @Override public void run() { WindowManager.LayoutParams layout = getWindow().getAttributes(); layout.screenBrightness = brightness; getWindow().setAttributes(layout); } }); } public float getBrightness() { return getWindow().getAttributes().screenBrightness; } + public void setLockInhibitionOn() { + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } + + public void setLockInhibitionOff() { + getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } + @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); importFromIntent(intent); } }