mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-08-03 10:14:45 +00:00
quicksettings/flashlight: Move C++ out of ShellUtil into package
This commit is contained in:
parent
7c8b5d60c4
commit
500132e56b
12 changed files with 159 additions and 33 deletions
|
|
@ -108,28 +108,6 @@ void ShellUtil::executeCommand(const QString &command)
|
||||||
QProcess::startDetached(commandAndArguments.front(), commandAndArguments.mid(1));
|
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()
|
bool ShellUtil::autoRotate()
|
||||||
{
|
{
|
||||||
QDBusPendingReply<bool> reply = m_kscreenInterface->getAutoRotate();
|
QDBusPendingReply<bool> reply = m_kscreenInterface->getAutoRotate();
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ class MOBILESHELL_EXPORT ShellUtil : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(bool autoRotateEnabled READ autoRotate WRITE setAutoRotate NOTIFY autoRotateChanged);
|
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);
|
Q_PROPERTY(bool isSystem24HourFormat READ isSystem24HourFormat NOTIFY isSystem24HourFormatChanged);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -34,23 +33,17 @@ public:
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void executeCommand(const QString &command);
|
void executeCommand(const QString &command);
|
||||||
void launchApp(const QString &app);
|
void launchApp(const QString &app);
|
||||||
void toggleTorch();
|
|
||||||
|
|
||||||
bool autoRotate();
|
bool autoRotate();
|
||||||
void setAutoRotate(bool value);
|
void setAutoRotate(bool value);
|
||||||
|
|
||||||
bool torchEnabled() const;
|
|
||||||
|
|
||||||
bool isSystem24HourFormat();
|
bool isSystem24HourFormat();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void autoRotateChanged(bool value);
|
void autoRotateChanged(bool value);
|
||||||
void torchChanged(bool value);
|
|
||||||
void isSystem24HourFormatChanged();
|
void isSystem24HourFormatChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_running = false;
|
|
||||||
|
|
||||||
KConfigWatcher::Ptr m_localeConfigWatcher;
|
KConfigWatcher::Ptr m_localeConfigWatcher;
|
||||||
KSharedConfig::Ptr m_localeConfig;
|
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(battery org.kde.plasma.battery quicksettings)
|
||||||
plasma_install_package(bluetooth org.kde.plasma.bluetooth quicksettings)
|
plasma_install_package(bluetooth org.kde.plasma.bluetooth quicksettings)
|
||||||
plasma_install_package(caffeine org.kde.plasma.caffeine 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(keyboardtoggle org.kde.plasma.keyboardtoggle quicksettings)
|
||||||
plasma_install_package(location org.kde.plasma.location quicksettings)
|
plasma_install_package(location org.kde.plasma.location quicksettings)
|
||||||
plasma_install_package(mobiledata org.kde.plasma.mobiledata quicksettings)
|
plasma_install_package(mobiledata org.kde.plasma.mobiledata quicksettings)
|
||||||
plasma_install_package(screenrotation org.kde.plasma.screenrotation quicksettings)
|
plasma_install_package(screenrotation org.kde.plasma.screenrotation quicksettings)
|
||||||
plasma_install_package(settingsapp org.kde.plasma.settingsapp quicksettings)
|
plasma_install_package(settingsapp org.kde.plasma.settingsapp quicksettings)
|
||||||
plasma_install_package(wifi org.kde.plasma.wifi quicksettings)
|
plasma_install_package(wifi org.kde.plasma.wifi quicksettings)
|
||||||
|
add_subdirectory(flashlight)
|
||||||
add_subdirectory(nightcolor)
|
add_subdirectory(nightcolor)
|
||||||
add_subdirectory(powermenu)
|
add_subdirectory(powermenu)
|
||||||
add_subdirectory(screenshot)
|
add_subdirectory(screenshot)
|
||||||
|
|
|
||||||
37
quicksettings/flashlight/CMakeLists.txt
Normal file
37
quicksettings/flashlight/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
|
||||||
23
quicksettings/flashlight/flashlightplugin.cpp
Normal file
23
quicksettings/flashlight/flashlightplugin.cpp
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* 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"
|
||||||
21
quicksettings/flashlight/flashlightplugin.h
Normal file
21
quicksettings/flashlight/flashlightplugin.h
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
};
|
||||||
39
quicksettings/flashlight/flashlightutil.cpp
Normal file
39
quicksettings/flashlight/flashlightutil.cpp
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
27
quicksettings/flashlight/flashlightutil.h
Normal file
27
quicksettings/flashlight/flashlightutil.h
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* 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 QtQuick 2.15
|
||||||
|
|
||||||
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
|
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
|
||||||
|
import org.kde.plasma.quicksetting.flashlight 1.0
|
||||||
|
|
||||||
MobileShell.QuickSetting {
|
MobileShell.QuickSetting {
|
||||||
text: i18n("Flashlight")
|
text: i18n("Flashlight")
|
||||||
icon: "flashlight-on"
|
icon: "flashlight-on"
|
||||||
enabled: MobileShell.ShellUtil.torchEnabled
|
enabled: FlashlightUtil.torchEnabled
|
||||||
function toggle() {
|
function toggle() {
|
||||||
MobileShell.ShellUtil.toggleTorch()
|
FlashlightUtil.toggleTorch()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
7
quicksettings/flashlight/qmldir
Normal file
7
quicksettings/flashlight/qmldir
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
# 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"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue