Commit 35dec9d3 authored by Devin Lin's avatar Devin Lin 🎨
Browse files

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

parent 500132e5
Pipeline #151409 passed with stages
in 1 minute and 5 seconds
......@@ -7,8 +7,7 @@ if (BUILD_TESTING)
add_subdirectory(autotests)
endif()
qt_add_dbus_interfaces(DBUS_SRCS dbus/org.kde.KScreen.xml
${KWIN_VIRTUALKEYBOARD_INTERFACE})
qt_add_dbus_interfaces(DBUS_SRCS ${KWIN_VIRTUALKEYBOARD_INTERFACE})
set(mobileshell_LIB_SRCS
displaysmodel.cpp
......
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<!--
- SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
- SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
-->
<node>
<interface name="org.kde.kwin.Screenshot">
<signal name="screenshotCreated">
<arg name="handle" type="t" direction="out"/>
</signal>
<method name="screenshotForWindow">
<arg name="winid" type="t" direction="in"/>
<arg name="mask" type="i" direction="in"/>
</method>
<method name="screenshotForWindow">
<arg name="winid" type="t" direction="in"/>
</method>
<method name="interactive">
<arg type="s" direction="out"/>
<arg name="mask" type="i" direction="in"/>
</method>
<method name="interactive">
<arg type="s" direction="out"/>
</method>
<method name="interactive">
<arg name="fd" type="h" direction="in"/>
<arg name="mask" type="i" direction="in"/>
</method>
<method name="interactive">
<arg name="fd" type="h" direction="in"/>
</method>
<method name="screenshotWindowUnderCursor">
<arg name="mask" type="i" direction="in"/>
</method>
<method name="screenshotWindowUnderCursor">
</method>
<method name="screenshotFullscreen">
<arg type="s" direction="out"/>
<arg name="captureCursor" type="b" direction="in"/>
</method>
<method name="screenshotFullscreen">
<arg type="s" direction="out"/>
</method>
<method name="screenshotFullscreen">
<arg name="fd" type="h" direction="in"/>
<arg name="captureCursor" type="b" direction="in"/>
<arg name="shouldReturnNativeSize" type="b" direction="in"/>
</method>
<method name="screenshotFullscreen">
<arg name="fd" type="h" direction="in"/>
<arg name="captureCursor" type="b" direction="in"/>
</method>
<method name="screenshotFullscreen">
<arg name="fd" type="h" direction="in"/>
</method>
<method name="screenshotScreen">
<arg type="s" direction="out"/>
<arg name="screen" type="i" direction="in"/>
<arg name="captureCursor" type="b" direction="in"/>
</method>
<method name="screenshotScreen">
<arg type="s" direction="out"/>
<arg name="screen" type="i" direction="in"/>
</method>
<method name="screenshotScreen">
<arg name="fd" type="h" direction="in"/>
<arg name="captureCursor" type="b" direction="in"/>
</method>
<method name="screenshotScreen">
<arg name="fd" type="h" direction="in"/>
</method>
<method name="screenshotArea">
<arg type="s" direction="out"/>
<arg name="x" type="i" direction="in"/>
<arg name="y" type="i" direction="in"/>
<arg name="width" type="i" direction="in"/>
<arg name="height" type="i" direction="in"/>
<arg name="captureCursor" type="b" direction="in"/>
</method>
<method name="screenshotArea">
<arg type="s" direction="out"/>
<arg name="x" type="i" direction="in"/>
<arg name="y" type="i" direction="in"/>
<arg name="width" type="i" direction="in"/>
<arg name="height" type="i" direction="in"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Properties">
<method name="Get">
<arg name="interface_name" type="s" direction="in"/>
<arg name="property_name" type="s" direction="in"/>
<arg name="value" type="v" direction="out"/>
</method>
<method name="Set">
<arg name="interface_name" type="s" direction="in"/>
<arg name="property_name" type="s" direction="in"/>
<arg name="value" type="v" direction="in"/>
</method>
<method name="GetAll">
<arg name="interface_name" type="s" direction="in"/>
<arg name="values" type="a{sv}" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
</method>
<signal name="PropertiesChanged">
<arg name="interface_name" type="s" direction="out"/>
<arg name="changed_properties" type="a{sv}" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/>
<arg name="invalidated_properties" type="as" direction="out"/>
</signal>
</interface>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg name="xml_data" type="s" direction="out"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Peer">
<method name="Ping"/>
<method name="GetMachineId">
<arg name="machine_uuid" type="s" direction="out"/>
</method>
</interface>
</node>
......@@ -31,55 +31,9 @@
using namespace MobileShell;
/* -- Static Helpers --------------------------------------------------------------------------- */
static QImage allocateImage(const QVariantMap &metadata)
{
bool ok;
const uint width = metadata.value(QStringLiteral("width")).toUInt(&ok);
if (!ok) {
return QImage();
}
const uint height = metadata.value(QStringLiteral("height")).toUInt(&ok);
if (!ok) {
return QImage();
}
const uint format = metadata.value(QStringLiteral("format")).toUInt(&ok);
if (!ok) {
return QImage();
}
return QImage(width, height, QImage::Format(format));
}
static QImage readImage(int fileDescriptor, const QVariantMap &metadata)
{
QFile file;
if (!file.open(fileDescriptor, QFileDevice::ReadOnly, QFileDevice::AutoCloseHandle)) {
close(fileDescriptor);
return QImage();
}
QImage result = allocateImage(metadata);
if (result.isNull()) {
return QImage();
}
QDataStream stream(&file);
stream.readRawData(reinterpret_cast<char *>(result.bits()), result.sizeInBytes());
return result;
}
ShellUtil::ShellUtil(QObject *parent)
: QObject{parent}
{
// setHasConfigurationInterface(true);
m_kscreenInterface = new org::kde::KScreen(QStringLiteral("org.kde.kded5"), QStringLiteral("/modules/kscreen"), QDBusConnection::sessionBus(), this);
m_localeConfig = KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::SimpleConfig);
m_localeConfigWatcher = KConfigWatcher::create(m_localeConfig);
......@@ -108,29 +62,6 @@ void ShellUtil::executeCommand(const QString &command)
QProcess::startDetached(commandAndArguments.front(), commandAndArguments.mid(1));
}
bool ShellUtil::autoRotate()
{
QDBusPendingReply<bool> reply = m_kscreenInterface->getAutoRotate();
reply.waitForFinished();
if (reply.isError()) {
qWarning() << "Getting auto rotate failed:" << reply.error().name() << reply.error().message();
return false;
} else {
return reply.value();
}
}
void ShellUtil::setAutoRotate(bool value)
{
QDBusPendingReply<> reply = m_kscreenInterface->setAutoRotate(value);
reply.waitForFinished();
if (reply.isError()) {
qWarning() << "Setting auto rotate failed:" << reply.error().name() << reply.error().message();
} else {
emit autoRotateChanged(value);
}
}
bool ShellUtil::isSystem24HourFormat()
{
KConfigGroup localeSettings = KConfigGroup(m_localeConfig, "Locale");
......
......@@ -12,8 +12,6 @@
#include <KConfigWatcher>
#include <KSharedConfig>
#include "kscreeninterface.h"
#include "mobileshell_export.h"
namespace MobileShell
......@@ -22,7 +20,6 @@ namespace MobileShell
class MOBILESHELL_EXPORT ShellUtil : public QObject
{
Q_OBJECT
Q_PROPERTY(bool autoRotateEnabled READ autoRotate WRITE setAutoRotate NOTIFY autoRotateChanged);
Q_PROPERTY(bool isSystem24HourFormat READ isSystem24HourFormat NOTIFY isSystem24HourFormatChanged);
public:
......@@ -34,20 +31,14 @@ public Q_SLOTS:
void executeCommand(const QString &command);
void launchApp(const QString &app);
bool autoRotate();
void setAutoRotate(bool value);
bool isSystem24HourFormat();
Q_SIGNALS:
void autoRotateChanged(bool value);
void isSystem24HourFormatChanged();
private:
KConfigWatcher::Ptr m_localeConfigWatcher;
KSharedConfig::Ptr m_localeConfig;
org::kde::KScreen *m_kscreenInterface;
};
} // namespace MobileShell
......@@ -9,10 +9,10 @@ plasma_install_package(caffeine org.kde.plasma.caffeine 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)
add_subdirectory(screenrotation)
# SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
# SPDX-License-Identifier: GPL-2.0-or-later
qt_add_dbus_interfaces(DBUS_SRCS dbus/org.kde.KScreen.xml)
set(screenrotationplugin_SRCS
screenrotationplugin.cpp
screenrotationutil.cpp
${DBUS_SRCS}
)
add_library(screenrotationplugin ${screenrotationplugin_SRCS})
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
Declarative
)
target_link_libraries(screenrotationplugin
PUBLIC
Qt::Core
PRIVATE
Qt::DBus
KF5::CoreAddons
KF5::QuickAddons
KF5::ConfigCore
KF5::ConfigGui
KF5::I18n
KF5::Notifications
)
set_property(TARGET screenrotationplugin PROPERTY LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/org/kde/plasma/quicksetting/screenrotation)
file(COPY qmldir DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/org/kde/plasma/quicksetting/screenrotation)
install(TARGETS screenrotationplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/quicksetting/screenrotation)
install(FILES qmldir ${qml_SRC} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/quicksetting/screenrotation)
plasma_install_package(package org.kde.plasma.screenrotation quicksettings)
......@@ -4,13 +4,14 @@
import QtQuick 2.15
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
import org.kde.plasma.quicksetting.screenrotation 1.0
MobileShell.QuickSetting {
text: i18n("Auto-rotate")
icon: "rotation-allowed"
settingsCommand: "plasma-open-settings kcm_kscreen"
enabled: MobileShell.ShellUtil.autoRotateEnabled
enabled: ScreenRotationUtil.screenRotationEnabled
function toggle() {
MobileShell.ShellUtil.autoRotateEnabled = !enabled
ScreenRotationUtil.screenRotationEnabled = !enabled
}
}
# SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
# SPDX-License-Identifier: GPL-2.0-or-later
module org.kde.plasma.quicksetting.screenrotation
plugin screenrotationplugin
classname ScreenRotationPlugin
/*
* SPDX-FileCopyrightText: 2022 by Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "screenrotationplugin.h"
#include <QQmlContext>
#include <QQuickItem>
#include "screenrotationutil.h"
void ScreenRotationPlugin::registerTypes(const char *uri)
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.plasma.quicksetting.screenrotation"));
qmlRegisterSingletonType<ScreenRotationUtil>(uri, 1, 0, "ScreenRotationUtil", [](QQmlEngine *, QJSEngine *) {
return new ScreenRotationUtil;
});
}
//#include "moc_screenrotationplugin.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 ScreenRotationPlugin : 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 "screenrotationutil.h"
#include <fcntl.h>
#include <unistd.h>
#include <QDebug>
ScreenRotationUtil::ScreenRotationUtil(QObject *parent)
: QObject{parent}
{
m_kscreenInterface = new org::kde::KScreen(QStringLiteral("org.kde.kded5"), QStringLiteral("/modules/kscreen"), QDBusConnection::sessionBus(), this);
}
bool ScreenRotationUtil::screenRotation()
{
QDBusPendingReply<bool> reply = m_kscreenInterface->getAutoRotate();
reply.waitForFinished();
if (reply.isError()) {
qWarning() << "Getting auto rotate failed:" << reply.error().name() << reply.error().message();
return false;
} else {
return reply.value();
}
}
void ScreenRotationUtil::setScreenRotation(bool value)
{
QDBusPendingReply<> reply = m_kscreenInterface->setAutoRotate(value);
reply.waitForFinished();
if (reply.isError()) {
qWarning() << "Setting auto rotate failed:" << reply.error().name() << reply.error().message();
} else {
Q_EMIT screenRotationChanged(value);
}
}
/*
* SPDX-FileCopyrightText: 2022 by Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <QObject>
#include "kscreeninterface.h"
class ScreenRotationUtil : public QObject
{
Q_OBJECT
Q_PROPERTY(bool screenRotationEnabled READ screenRotation WRITE setScreenRotation NOTIFY screenRotationChanged);
public:
ScreenRotationUtil(QObject *parent = nullptr);
bool screenRotation();
void setScreenRotation(bool value);
Q_SIGNALS:
void screenRotationChanged(bool value);
private:
org::kde::KScreen *m_kscreenInterface;
};
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