File indexing completed on 2024-05-05 05:38:23

0001 /*
0002     SPDX-FileCopyrightText: 2017 Roman Gilg <subdiff@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #pragma once
0007 
0008 #include <QHash>
0009 #include <QObject>
0010 #include <QString>
0011 #include <QTime>
0012 
0013 #include <qqmlregistration.h>
0014 
0015 #include "colorcorrect_export.h"
0016 #include "colorcorrectconstants.h"
0017 
0018 class QDBusInterface;
0019 
0020 namespace ColorCorrect
0021 {
0022 class COLORCORRECT_EXPORT CompositorAdaptor : public QObject
0023 {
0024     Q_OBJECT
0025     QML_ELEMENT
0026 
0027     Q_PROPERTY(int error READ error NOTIFY errorChanged)
0028     Q_PROPERTY(QString errorText READ errorText NOTIFY errorTextChanged)
0029 
0030     Q_PROPERTY(bool nightColorAvailable READ nightColorAvailable CONSTANT)
0031 
0032 public:
0033     enum class ErrorCode {
0034         // no error
0035         ErrorCodeSuccess = 0,
0036         // couldn't establish connection to compositor
0037         ErrorCodeConnectionFailed,
0038         // rendering backend doesn't support hardware color correction
0039         ErrorCodeBackendNoSupport,
0040     };
0041     Q_ENUMS(ErrorCode)
0042 
0043     explicit CompositorAdaptor(QObject *parent = nullptr);
0044     ~CompositorAdaptor() override = default;
0045 
0046     int error() const
0047     {
0048         return (int)m_error;
0049     }
0050     void setError(ErrorCode error);
0051 
0052     QString errorText() const
0053     {
0054         return m_errorText;
0055     }
0056 
0057     bool nightColorAvailable() const
0058     {
0059         return m_nightColorAvailable;
0060     }
0061 
0062     bool running() const
0063     {
0064         return m_running;
0065     }
0066 
0067     /**
0068      * @brief Send automatic location data.
0069      *
0070      * Updated auto location data is provided by the workspace. This is
0071      * in general already done by the KDE Daemon.
0072      *
0073      * @return void
0074      * @since 5.12
0075      **/
0076     Q_INVOKABLE void sendAutoLocationUpdate(double latitude, double longitude);
0077 
0078     /**
0079      * @brief Preview a color temperature for 15s.
0080      *
0081      * @return void
0082      * @since 5.25
0083      **/
0084     Q_INVOKABLE void preview(int temperature);
0085 
0086     /**
0087      * @brief Stop an ongoing preview.
0088      *
0089      * @return void
0090      * @since 5.25
0091      **/
0092     Q_INVOKABLE void stopPreview();
0093 
0094 Q_SIGNALS:
0095     void errorChanged();
0096     void errorTextChanged();
0097 
0098     void runningChanged();
0099 
0100 private:
0101     void updateProperties(const QVariantMap &properties);
0102 
0103     QDBusInterface *m_iface;
0104 
0105     ErrorCode m_error = ErrorCode::ErrorCodeSuccess;
0106     QString m_errorText;
0107 
0108     bool m_nightColorAvailable = false;
0109 
0110     bool m_running = false;
0111 
0112 private Q_SLOTS:
0113     void handlePropertiesChanged(const QString &interfaceName, const QVariantMap &changedProperties, const QStringList &invalidatedProperties);
0114 };
0115 
0116 }