Commit 05fc50c0 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧 Committed by Aleix Pol Gonzalez
Browse files

flashlight: Mark itself as unavailable if unavailable

parent 169cfc63
Pipeline #201126 passed with stage
in 1 minute and 45 seconds
......@@ -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);
}
......@@ -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);
......
......@@ -10,6 +10,7 @@ MobileShell.QuickSetting {
text: i18n("Flashlight")
icon: "flashlight-on"
enabled: FlashlightUtil.torchEnabled
available: FlashlightUtil.available
function toggle() {
FlashlightUtil.toggleTorch()
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment