File indexing completed on 2024-04-28 16:54:29

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