mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
flashlight: Mark itself as unavailable if unavailable
This commit is contained in:
parent
169cfc6354
commit
05fc50c033
3 changed files with 12 additions and 2 deletions
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue