diff --git a/content/post/kde_contribution/index.md b/content/post/kde_contribution/index.md index 59d3434..aa2977e 100644 --- a/content/post/kde_contribution/index.md +++ b/content/post/kde_contribution/index.md @@ -217,157 +217,8 @@ Ensuite, je change la luminosité udev_device_set_sysattr_value(m_device, "brightness", nouvelle_valeur_en_char_*); ``` -### Fichier final +Si vous le souhaitez, vous pouvez retrouver le fichier dans son intégralité [ici](https://invent.kde.org/plasma/plasma-mobile/-/blob/d162f96a63600d5b45bb8294afdb84efd85833f9/quicksettings/flashlight/flashlightutil.cpp) -[Source](https://invent.kde.org/plasma/plasma-mobile/-/blob/d162f96a63600d5b45bb8294afdb84efd85833f9/quicksettings/flashlight/flashlightutil.cpp) -```cpp -/* - * SPDX-FileCopyrightText: 2020 Han Young - * SPDX-FileCopyrightText: 2022 by Devin Lin - * - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -#include "flashlightutil.h" - -#include -#include -#include -#include - -#include -#include - -#define TORCH_SUBSYSTEM "leds" - -FlashlightUtil::FlashlightUtil(QObject *parent) - : QObject{parent} - , m_device{nullptr} - , m_isAvailable{false} -{ - findTorchDevice(); -} - -FlashlightUtil::~FlashlightUtil() -{ - if (m_device != nullptr) { - udev_device_unref(m_device); - } -} - -void FlashlightUtil::toggleTorch() -{ - if (!isAvailable()) { - qWarning() << "Flashlight not available"; - return; - } - - int ret = udev_device_set_sysattr_value(m_device, "brightness", const_cast(m_torchEnabled ? "0" : m_maxBrightness)); - if (ret < 0) { - qWarning() << "Flashlight can't be toggled"; - return; - } - - m_torchEnabled = !m_torchEnabled; - Q_EMIT torchChanged(m_torchEnabled); -} - -bool FlashlightUtil::torchEnabled() const -{ - return m_torchEnabled; -} - -bool FlashlightUtil::isAvailable() const -{ - return m_isAvailable; -} - -void FlashlightUtil::findTorchDevice() -{ - if (m_device != nullptr) { - udev_device_unref(m_device); - } - m_device = nullptr; - m_isAvailable = false; - - struct udev *udev = udev_new(); - struct udev_enumerate *enumerate = udev_enumerate_new(udev); - - udev_enumerate_add_match_subsystem(enumerate, TORCH_SUBSYSTEM); - udev_enumerate_add_match_sysname(enumerate, "*:torch"); - udev_enumerate_add_match_sysname(enumerate, "*:flash"); - udev_enumerate_scan_devices(enumerate); - - struct udev_list_entry *devices = udev_enumerate_get_list_entry(enumerate); - struct udev_list_entry *entry = nullptr; - - struct udev_device *device = nullptr; - - udev_list_entry_foreach(entry, devices) - { - const char *path = udev_list_entry_get_name(entry); - - if (path == nullptr) { - continue; - } - - if (device != nullptr) { - udev_device_unref(device); // Use to free memory from previous loop iteration - } - - device = udev_device_new_from_syspath(udev, path); - - if (device == nullptr) { - continue; - } - - qInfo() << "Found flashlight device : " << path; - - const char *color = udev_device_get_sysattr_value(device, "color"); - - if (color == nullptr) { - continue; - } - - qInfo() << "Flash color : " << color; - - if (std::strcmp(color, "white") == 0) { - break; - } - } - - if (device == nullptr) { - qWarning() << "No flashlight device found"; - return; - } - - const char *maxBrightness = udev_device_get_sysattr_value(device, "max_brightness"); - - if (maxBrightness == nullptr) { - qWarning() << "Failed to read max_brightness from udev device"; - return; - } - - qInfo() << "Flash maxBrightness : " << maxBrightness; - - const char *brightness = udev_device_get_sysattr_value(device, "brightness"); - - if (brightness == nullptr) { - qWarning() << "Failed to read brightness from udev device"; - return; - } - - qInfo() << "Flash brightness : " << brightness; - - m_maxBrightness = maxBrightness; - m_device = device; - m_isAvailable = true; - m_torchEnabled = std::strcmp(brightness, "0") != 0; - - udev_enumerate_unref(enumerate); - udev_unref(udev); -} -``` ### Info utile pour débugger KDE Plama Mobile depuis Postmarket OS