Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
Plasma Mobile
Commits
500132e5
Commit
500132e5
authored
Mar 17, 2022
by
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
Changes
12
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
libmobileshell/shellutil.cpp
View file @
500132e5
...
...
@@ -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
();
...
...
libmobileshell/shellutil.h
View file @
500132e5
...
...
@@ -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
;
...
...
quicksettings/CMakeLists.txt
View file @
500132e5
...
...
@@ -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
)
quicksettings/flashlight/CMakeLists.txt
0 → 100644
View file @
500132e5
# 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
)
quicksettings/flashlight/flashlightplugin.cpp
0 → 100644
View file @
500132e5
/*
* 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"
quicksettings/flashlight/flashlightplugin.h
0 → 100644
View file @
500132e5
/*
* 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
;
};
quicksettings/flashlight/flashlightutil.cpp
0 → 100644
View file @
500132e5
/*
* 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
;
}
quicksettings/flashlight/flashlightutil.h
0 → 100644
View file @
500132e5
/*
* 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
;
};
quicksettings/flashlight/contents/ui/main.qml
→
quicksettings/flashlight/
package/
contents/ui/main.qml
View file @
500132e5
...
...
@@ -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
.
Shell
Util
.
torchEnabled
enabled
:
Flashlight
Util
.
torchEnabled
function
toggle
()
{
MobileShell
.
Shell
Util
.
toggleTorch
()
Flashlight
Util
.
toggleTorch
()
}
}
quicksettings/flashlight/metadata.desktop
→
quicksettings/flashlight/
package/
metadata.desktop
View file @
500132e5
File moved
quicksettings/flashlight/qmldir
0 → 100644
View file @
500132e5
# 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
quicksettings/screenshot/screenshotplugin.cpp
View file @
500132e5
...
...
@@ -20,4 +20,4 @@ void ScreenShotPlugin::registerTypes(const char *uri)
});
}
//#include "moc_
nightcolor
plugin.cpp"
//#include "moc_
screenshot
plugin.cpp"
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment