flashlight: Mark itself as unavailable if unavailable

This commit is contained in:
Aleix Pol 2022-07-07 01:15:01 +02:00 committed by Aleix Pol Gonzalez
parent 169cfc6354
commit 05fc50c033
3 changed files with 12 additions and 2 deletions

View file

@ -11,6 +11,10 @@
#include <unistd.h>
#include <QDebug>
#include <QFileInfo>
// FIXME this is hardcoded to the PinePhone for now
static const char *FLASH_SYSFS_PATH = "/sys/devices/platform/led-controller/leds/white:flash/brightness";
FlashlightUtil::FlashlightUtil(QObject *parent)
: QObject{parent}
@ -20,8 +24,6 @@ FlashlightUtil::FlashlightUtil(QObject *parent)
void FlashlightUtil::toggleTorch()
{
// FIXME this is hardcoded to the PinePhone for now
static auto FLASH_SYSFS_PATH = "/sys/devices/platform/led-controller/leds/white:flash/brightness";
int fd = open(FLASH_SYSFS_PATH, O_WRONLY);
if (fd < 0) {
@ -39,3 +41,8 @@ bool FlashlightUtil::torchEnabled() const
{
return m_torchEnabled;
}
bool FlashlightUtil::isAvailable() const
{
return QFileInfo::exists(FLASH_SYSFS_PATH);
}

View file

@ -12,12 +12,14 @@ class FlashlightUtil : public QObject
{
Q_OBJECT
Q_PROPERTY(bool torchEnabled READ torchEnabled NOTIFY torchChanged);
Q_PROPERTY(bool available READ isAvailable CONSTANT);
public:
FlashlightUtil(QObject *parent = nullptr);
Q_INVOKABLE void toggleTorch();
bool torchEnabled() const;
bool isAvailable() const;
Q_SIGNALS:
void torchChanged(bool value);

View file

@ -10,6 +10,7 @@ MobileShell.QuickSetting {
text: i18n("Flashlight")
icon: "flashlight-on"
enabled: FlashlightUtil.torchEnabled
available: FlashlightUtil.available
function toggle() {
FlashlightUtil.toggleTorch()
}