diff --git a/libmobileshell/shellutil.cpp b/libmobileshell/shellutil.cpp index 1cc63fef..7755340e 100644 --- a/libmobileshell/shellutil.cpp +++ b/libmobileshell/shellutil.cpp @@ -108,28 +108,6 @@ void ShellUtil::executeCommand(const QString &command) QProcess::startDetached(commandAndArguments.front(), commandAndArguments.mid(1)); } -void ShellUtil::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) { - qWarning() << "Unable to open file %s" << FLASH_SYSFS_PATH; - return; - } - - write(fd, m_running ? "0" : "1", 1); - close(fd); - m_running = !m_running; - Q_EMIT torchChanged(m_running); -} - -bool ShellUtil::torchEnabled() const -{ - return m_running; -} - bool ShellUtil::autoRotate() { QDBusPendingReply reply = m_kscreenInterface->getAutoRotate(); diff --git a/libmobileshell/shellutil.h b/libmobileshell/shellutil.h index 5a4f367a..c08e914a 100644 --- a/libmobileshell/shellutil.h +++ b/libmobileshell/shellutil.h @@ -23,7 +23,6 @@ class MOBILESHELL_EXPORT ShellUtil : public QObject { Q_OBJECT Q_PROPERTY(bool autoRotateEnabled READ autoRotate WRITE setAutoRotate NOTIFY autoRotateChanged); - Q_PROPERTY(bool torchEnabled READ torchEnabled NOTIFY torchChanged); Q_PROPERTY(bool isSystem24HourFormat READ isSystem24HourFormat NOTIFY isSystem24HourFormatChanged); public: @@ -34,23 +33,17 @@ public: public Q_SLOTS: void executeCommand(const QString &command); void launchApp(const QString &app); - void toggleTorch(); bool autoRotate(); void setAutoRotate(bool value); - bool torchEnabled() const; - bool isSystem24HourFormat(); Q_SIGNALS: void autoRotateChanged(bool value); - void torchChanged(bool value); void isSystem24HourFormatChanged(); private: - bool m_running = false; - KConfigWatcher::Ptr m_localeConfigWatcher; KSharedConfig::Ptr m_localeConfig; diff --git a/quicksettings/CMakeLists.txt b/quicksettings/CMakeLists.txt index 4785dbab..06849b72 100644 --- a/quicksettings/CMakeLists.txt +++ b/quicksettings/CMakeLists.txt @@ -6,13 +6,13 @@ plasma_install_package(audio org.kde.plasma.audio quicksettings) plasma_install_package(battery org.kde.plasma.battery quicksettings) plasma_install_package(bluetooth org.kde.plasma.bluetooth quicksettings) plasma_install_package(caffeine org.kde.plasma.caffeine quicksettings) -plasma_install_package(flashlight org.kde.plasma.flashlight quicksettings) plasma_install_package(keyboardtoggle org.kde.plasma.keyboardtoggle quicksettings) plasma_install_package(location org.kde.plasma.location quicksettings) plasma_install_package(mobiledata org.kde.plasma.mobiledata quicksettings) plasma_install_package(screenrotation org.kde.plasma.screenrotation quicksettings) plasma_install_package(settingsapp org.kde.plasma.settingsapp quicksettings) plasma_install_package(wifi org.kde.plasma.wifi quicksettings) +add_subdirectory(flashlight) add_subdirectory(nightcolor) add_subdirectory(powermenu) add_subdirectory(screenshot) diff --git a/quicksettings/flashlight/CMakeLists.txt b/quicksettings/flashlight/CMakeLists.txt new file mode 100644 index 00000000..2e836e6a --- /dev/null +++ b/quicksettings/flashlight/CMakeLists.txt @@ -0,0 +1,37 @@ +# SPDX-FileCopyrightText: 2022 Devin Lin +# SPDX-License-Identifier: GPL-2.0-or-later + +set(flashlightplugin_SRCS + flashlightplugin.cpp + flashlightutil.cpp + ${DBUS_SRCS} +) + +add_library(flashlightplugin ${flashlightplugin_SRCS}) + +find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS + Declarative +) + +target_link_libraries(flashlightplugin + PUBLIC + Qt::Core + PRIVATE + Qt::DBus + KF5::CoreAddons + KF5::QuickAddons + KF5::ConfigCore + KF5::ConfigGui + KF5::I18n + KF5::Notifications +) + +set_property(TARGET flashlightplugin PROPERTY LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/org/kde/plasma/quicksetting/flashlight) +file(COPY qmldir DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/org/kde/plasma/quicksetting/flashlight) + +install(TARGETS flashlightplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/quicksetting/flashlight) +install(FILES qmldir ${qml_SRC} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/quicksetting/flashlight) + +plasma_install_package(package org.kde.plasma.flashlight quicksettings) + + diff --git a/quicksettings/flashlight/flashlightplugin.cpp b/quicksettings/flashlight/flashlightplugin.cpp new file mode 100644 index 00000000..770c42af --- /dev/null +++ b/quicksettings/flashlight/flashlightplugin.cpp @@ -0,0 +1,23 @@ +/* + * SPDX-FileCopyrightText: 2022 by Devin Lin + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "flashlightplugin.h" + +#include +#include + +#include "flashlightutil.h" + +void FlashlightPlugin::registerTypes(const char *uri) +{ + Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.plasma.quicksetting.flashlight")); + + qmlRegisterSingletonType(uri, 1, 0, "FlashlightUtil", [](QQmlEngine *, QJSEngine *) { + return new FlashlightUtil; + }); +} + +//#include "moc_flashlightplugin.cpp" diff --git a/quicksettings/flashlight/flashlightplugin.h b/quicksettings/flashlight/flashlightplugin.h new file mode 100644 index 00000000..7322752a --- /dev/null +++ b/quicksettings/flashlight/flashlightplugin.h @@ -0,0 +1,21 @@ +/* + * SPDX-FileCopyrightText: 2022 by Devin Lin + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#pragma once + +#include + +#include +#include + +class FlashlightPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri) override; +}; diff --git a/quicksettings/flashlight/flashlightutil.cpp b/quicksettings/flashlight/flashlightutil.cpp new file mode 100644 index 00000000..ce0a8bc9 --- /dev/null +++ b/quicksettings/flashlight/flashlightutil.cpp @@ -0,0 +1,39 @@ +/* + * SPDX-FileCopyrightText: 2022 by Devin Lin + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "flashlightutil.h" + +#include +#include + +#include + +FlashlightUtil::FlashlightUtil(QObject *parent) + : 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) { + qWarning() << "Unable to open file %s" << FLASH_SYSFS_PATH; + return; + } + + write(fd, m_torchEnabled ? "0" : "1", 1); + close(fd); + m_torchEnabled = !m_torchEnabled; + Q_EMIT torchChanged(m_torchEnabled); +} + +bool FlashlightUtil::torchEnabled() const +{ + return m_torchEnabled; +} diff --git a/quicksettings/flashlight/flashlightutil.h b/quicksettings/flashlight/flashlightutil.h new file mode 100644 index 00000000..f9c69af0 --- /dev/null +++ b/quicksettings/flashlight/flashlightutil.h @@ -0,0 +1,27 @@ +/* + * SPDX-FileCopyrightText: 2022 by Devin Lin + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#pragma once + +#include + +class FlashlightUtil : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool torchEnabled READ torchEnabled NOTIFY torchChanged); + +public: + FlashlightUtil(QObject *parent = nullptr); + + Q_INVOKABLE void toggleTorch(); + bool torchEnabled() const; + +Q_SIGNALS: + void torchChanged(bool value); + +private: + bool m_torchEnabled; +}; diff --git a/quicksettings/flashlight/contents/ui/main.qml b/quicksettings/flashlight/package/contents/ui/main.qml similarity index 70% rename from quicksettings/flashlight/contents/ui/main.qml rename to quicksettings/flashlight/package/contents/ui/main.qml index df662800..5acc0a9f 100644 --- a/quicksettings/flashlight/contents/ui/main.qml +++ b/quicksettings/flashlight/package/contents/ui/main.qml @@ -4,12 +4,13 @@ import QtQuick 2.15 import org.kde.plasma.private.mobileshell 1.0 as MobileShell +import org.kde.plasma.quicksetting.flashlight 1.0 MobileShell.QuickSetting { text: i18n("Flashlight") icon: "flashlight-on" - enabled: MobileShell.ShellUtil.torchEnabled + enabled: FlashlightUtil.torchEnabled function toggle() { - MobileShell.ShellUtil.toggleTorch() + FlashlightUtil.toggleTorch() } } diff --git a/quicksettings/flashlight/metadata.desktop b/quicksettings/flashlight/package/metadata.desktop similarity index 100% rename from quicksettings/flashlight/metadata.desktop rename to quicksettings/flashlight/package/metadata.desktop diff --git a/quicksettings/flashlight/qmldir b/quicksettings/flashlight/qmldir new file mode 100644 index 00000000..dd5ead61 --- /dev/null +++ b/quicksettings/flashlight/qmldir @@ -0,0 +1,7 @@ +# SPDX-FileCopyrightText: 2022 Devin Lin +# SPDX-License-Identifier: GPL-2.0-or-later + +module org.kde.plasma.quicksetting.flashlight +plugin flashlightplugin +classname FlashlightPlugin + diff --git a/quicksettings/screenshot/screenshotplugin.cpp b/quicksettings/screenshot/screenshotplugin.cpp index 41321e21..28ba3eb3 100644 --- a/quicksettings/screenshot/screenshotplugin.cpp +++ b/quicksettings/screenshot/screenshotplugin.cpp @@ -20,4 +20,4 @@ void ScreenShotPlugin::registerTypes(const char *uri) }); } -//#include "moc_nightcolorplugin.cpp" +//#include "moc_screenshotplugin.cpp"