File indexing completed on 2024-05-12 05:36:20

0001 /*
0002  * SPDX-FileCopyrightText: 2022 by Devin Lin <devin@kde.org>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #pragma once
0008 
0009 #include <QObject>
0010 #include <libudev.h>
0011 
0012 class FlashlightUtil : public QObject
0013 {
0014     Q_OBJECT
0015     Q_PROPERTY(bool torchEnabled READ torchEnabled NOTIFY torchChanged);
0016     Q_PROPERTY(bool available READ isAvailable CONSTANT);
0017 
0018 public:
0019     FlashlightUtil(QObject *parent = nullptr);
0020     ~FlashlightUtil();
0021 
0022     Q_INVOKABLE void toggleTorch();
0023     bool torchEnabled() const;
0024     bool isAvailable() const;
0025 
0026 Q_SIGNALS:
0027     void torchChanged(bool value);
0028 
0029 private:
0030     struct udev_device *m_device{nullptr};
0031     const char *m_maxBrightness{nullptr};
0032     bool m_isAvailable{false};
0033     bool m_torchEnabled{false};
0034 
0035     void findTorchDevice();
0036 };