diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ find_package(SharedMimeInfo 1.0 REQUIRED) find_package(ZLIB REQUIRED) set_package_properties("ZLIB" PROPERTIES PURPOSE "Needed for retrieving weather forecast data.") +set_package_properties(KF5Solid PROPERTIES TYPE OPTIONAL TYPE RUNTIME PURPOSE "Used for controlling the screen brightness.") include(ECMQMLModules) ecm_find_qmlmodule(org.kde.prison 1.0) @@ -46,8 +47,9 @@ endif() find_package(OpenSSL REQUIRED) else() - find_package(Qt5 REQUIRED COMPONENTS Widgets Positioning) + find_package(Qt5 REQUIRED COMPONENTS Widgets Positioning DBus) find_package(KF5 REQUIRED COMPONENTS DBusAddons) + find_package(KF5 COMPONENTS Solid) endif() add_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_NO_URL_CAST_FROM_STRING) diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -9,20 +9,24 @@ tripgroup.cpp tripgroupmanager.cpp tripgroupproxymodel.cpp + brightnessmanager.cpp + solidbrightnessbackend.cpp ) ecm_qt_declare_logging_category(itinerary_srcs HEADER logging.h IDENTIFIER Log CATEGORY_NAME org.kde.itinerary ) +qt5_add_dbus_interface(itinerary_srcs org.kde.Solid.PowerManagement.Actions.BrightnessControl.xml brightnesscontroldbusinterface) add_library(itinerary STATIC ${itinerary_srcs}) target_link_libraries(itinerary PUBLIC itinerary-weather KPim::Itinerary KPim::PkPass KF5::I18n Qt5::Network Qt5::Quick + Qt5::DBus ) if (Qt5QuickCompiler_FOUND) @@ -103,7 +107,7 @@ weather-storm ) else () - target_link_libraries(itinerary PRIVATE Qt5::Positioning) + target_link_libraries(itinerary PRIVATE Qt5::Positioning Qt5::DBus) target_link_libraries(itinerary-app PRIVATE KF5::DBusAddons Qt5::Widgets diff --git a/src/app/PkPassBarcode.qml b/src/app/PkPassBarcode.qml --- a/src/app/PkPassBarcode.qml +++ b/src/app/PkPassBarcode.qml @@ -30,6 +30,11 @@ radius: 6 Layout.alignment: Qt.AlignCenter + MouseArea { + anchors.fill: parent + onDoubleClicked: _brightnessManager.maxBrightness(); + } + ColumnLayout { id: barcodeLayout anchors.fill: parent diff --git a/src/app/TicketTokenDelegate.qml b/src/app/TicketTokenDelegate.qml --- a/src/app/TicketTokenDelegate.qml +++ b/src/app/TicketTokenDelegate.qml @@ -62,6 +62,11 @@ implicitHeight: visible ? implicitWidth : 0 visible: barcode.implicitHeight > 0 + MouseArea { + anchors.fill: parent + onDoubleClicked: _brightnessManager.maxBrightness(); + } + Prison.Barcode { id: barcode anchors.fill: background diff --git a/src/app/brightnessmanager.h b/src/app/brightnessmanager.h new file mode 100644 --- /dev/null +++ b/src/app/brightnessmanager.h @@ -0,0 +1,49 @@ +/* + Copyright (C) 2018 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 BRIGHTNESSMANAGER_H +#define BRIGHTNESSMANAGER_H + +#include + +class BrightnessBackend : public QObject +{ +public: + explicit BrightnessBackend(QObject *parent = nullptr) : QObject(parent) {} + virtual ~BrightnessBackend() = default; + +public: + virtual void maxBrightness() = 0; +}; + +class BrightnessManager : public QObject +{ + Q_OBJECT + +public: + explicit BrightnessManager(QObject *parent = nullptr); + ~BrightnessManager(); + +public Q_SLOTS: + void maxBrightness(); + +private: + BrightnessBackend *m_backend; +}; + +#endif // BRIGHTNESSMANAGER_H + diff --git a/src/app/brightnessmanager.cpp b/src/app/brightnessmanager.cpp new file mode 100644 --- /dev/null +++ b/src/app/brightnessmanager.cpp @@ -0,0 +1,41 @@ +/* + Copyright (C) 2018 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 "brightnessmanager.h" + +#include + +#ifdef Q_OS_LINUX +#include "solidbrightnessbackend.h" +#endif + +BrightnessManager::BrightnessManager(QObject *parent) + : QObject(parent) +{ +#ifdef Q_OS_LINUX + m_backend = new SolidBrightnessBackend(this); +#endif +} + +BrightnessManager::~BrightnessManager() = default; + +void BrightnessManager::maxBrightness() +{ + if (m_backend) { + m_backend->maxBrightness(); + } +} diff --git a/src/app/main.cpp b/src/app/main.cpp --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -32,6 +32,7 @@ #include "tripgroupproxymodel.h" #include "util.h" #include "weatherforecastmodel.h" +#include "brightnessmanager.h" #include @@ -131,6 +132,7 @@ ApplicationController appController; appController.setReservationManager(&resMgr); appController.setPkPassManager(&passMgr); + BrightnessManager brightnessManager; #ifndef Q_OS_ANDROID QObject::connect(&service, &KDBusService::activateRequested, [&parser, &appController](const QStringList &args, const QString &workingDir) { qCDebug(Log) << "remote activation" << args << workingDir; @@ -188,6 +190,7 @@ 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.load(QStringLiteral("qrc:/main.qml")); handlePositionalArguments(&appController, parser.positionalArguments()); diff --git a/src/app/org.kde.Solid.PowerManagement.Actions.BrightnessControl.xml b/src/app/org.kde.Solid.PowerManagement.Actions.BrightnessControl.xml new file mode 100644 --- /dev/null +++ b/src/app/org.kde.Solid.PowerManagement.Actions.BrightnessControl.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/app/solidbrightnessbackend.h b/src/app/solidbrightnessbackend.h new file mode 100644 --- /dev/null +++ b/src/app/solidbrightnessbackend.h @@ -0,0 +1,39 @@ +/* + Copyright (C) 2018 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 SOLIDBRIGHTNESSBACKEND_H +#define SOLIDBRIGHTNESSBACKEND_H + +#include +#include "brightnessmanager.h" + +class OrgKdeSolidPowerManagementActionsBrightnessControlInterface; + +class SolidBrightnessBackend : public BrightnessBackend +{ + +public: + explicit SolidBrightnessBackend(QObject *parent = nullptr); + virtual ~SolidBrightnessBackend(); + + virtual void maxBrightness(); + +private: + OrgKdeSolidPowerManagementActionsBrightnessControlInterface *m_iface; +}; + +#endif // SOLIDBRIGHTNESSBACKEND_H diff --git a/src/app/solidbrightnessbackend.cpp b/src/app/solidbrightnessbackend.cpp new file mode 100644 --- /dev/null +++ b/src/app/solidbrightnessbackend.cpp @@ -0,0 +1,40 @@ +/* + Copyright (C) 2018 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 "solidbrightnessbackend.h" + +#include +#include +#include + +SolidBrightnessBackend::SolidBrightnessBackend(QObject *parent) + : BrightnessBackend(parent) +{ + m_iface = new OrgKdeSolidPowerManagementActionsBrightnessControlInterface( + QStringLiteral("org.kde.Solid.PowerManagement"), + QStringLiteral("/org/kde/Solid/PowerManagement/Actions/BrightnessControl"), + QDBusConnection::sessionBus(), this); +} + +SolidBrightnessBackend::~SolidBrightnessBackend() +{ +} + +void SolidBrightnessBackend::maxBrightness() +{ + m_iface->setBrightnessSilent(m_iface->brightnessMax()); +}