Commit 500132e5 authored by Devin Lin's avatar Devin Lin 🎨
Browse files

quicksettings/flashlight: Move C++ out of ShellUtil into package

parent 7c8b5d60
Pipeline #151164 passed with stages
in 1 minute and 20 seconds
......@@ -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<bool> reply = m_kscreenInterface->getAutoRotate();
......
......@@ -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;
......
......@@ -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)
# SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
# 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)
/*
* SPDX-FileCopyrightText: 2022 by Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "flashlightplugin.h"
#include <QQmlContext>
#include <QQuickItem>
#include "flashlightutil.h"
void FlashlightPlugin::registerTypes(const char *uri)
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.plasma.quicksetting.flashlight"));
qmlRegisterSingletonType<FlashlightUtil>(uri, 1, 0, "FlashlightUtil", [](QQmlEngine *, QJSEngine *) {
return new FlashlightUtil;
});
}
//#include "moc_flashlightplugin.cpp"
/*
* SPDX-FileCopyrightText: 2022 by Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <QUrl>
#include <QQmlEngine>
#include <QQmlExtensionPlugin>
class FlashlightPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
public:
void registerTypes(const char *uri) override;
};
/*
* SPDX-FileCopyrightText: 2022 by Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "flashlightutil.h"
#include <fcntl.h>
#include <unistd.h>
#include <QDebug>
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;
}
/*
* SPDX-FileCopyrightText: 2022 by Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <QObject>
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;
};
......@@ -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()
}
}
# SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
# SPDX-License-Identifier: GPL-2.0-or-later
module org.kde.plasma.quicksetting.flashlight
plugin flashlightplugin
classname FlashlightPlugin
......@@ -20,4 +20,4 @@ void ScreenShotPlugin::registerTypes(const char *uri)
});
}
//#include "moc_nightcolorplugin.cpp"
//#include "moc_screenshotplugin.cpp"
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