diff --git a/libmobileshell/CMakeLists.txt b/libmobileshell/CMakeLists.txt
index 0c61d732..ea6f8272 100644
--- a/libmobileshell/CMakeLists.txt
+++ b/libmobileshell/CMakeLists.txt
@@ -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
diff --git a/libmobileshell/dbus/org.kde.KWin.Screenshot.xml b/libmobileshell/dbus/org.kde.KWin.Screenshot.xml
deleted file mode 100644
index 80b099ed..00000000
--- a/libmobileshell/dbus/org.kde.KWin.Screenshot.xml
+++ /dev/null
@@ -1,124 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/libmobileshell/shellutil.cpp b/libmobileshell/shellutil.cpp
index 7755340e..745c66c7 100644
--- a/libmobileshell/shellutil.cpp
+++ b/libmobileshell/shellutil.cpp
@@ -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(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 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");
diff --git a/libmobileshell/shellutil.h b/libmobileshell/shellutil.h
index c08e914a..bb22d37a 100644
--- a/libmobileshell/shellutil.h
+++ b/libmobileshell/shellutil.h
@@ -12,8 +12,6 @@
#include
#include
-#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
diff --git a/quicksettings/CMakeLists.txt b/quicksettings/CMakeLists.txt
index 06849b72..d74384ae 100644
--- a/quicksettings/CMakeLists.txt
+++ b/quicksettings/CMakeLists.txt
@@ -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)
diff --git a/quicksettings/screenrotation/CMakeLists.txt b/quicksettings/screenrotation/CMakeLists.txt
new file mode 100644
index 00000000..cc1f4c3b
--- /dev/null
+++ b/quicksettings/screenrotation/CMakeLists.txt
@@ -0,0 +1,39 @@
+# SPDX-FileCopyrightText: 2022 Devin Lin
+# 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)
+
+
diff --git a/libmobileshell/dbus/org.kde.KScreen.xml b/quicksettings/screenrotation/dbus/org.kde.KScreen.xml
similarity index 100%
rename from libmobileshell/dbus/org.kde.KScreen.xml
rename to quicksettings/screenrotation/dbus/org.kde.KScreen.xml
diff --git a/quicksettings/screenrotation/contents/ui/main.qml b/quicksettings/screenrotation/package/contents/ui/main.qml
similarity index 68%
rename from quicksettings/screenrotation/contents/ui/main.qml
rename to quicksettings/screenrotation/package/contents/ui/main.qml
index bab8ca21..cb6b776c 100644
--- a/quicksettings/screenrotation/contents/ui/main.qml
+++ b/quicksettings/screenrotation/package/contents/ui/main.qml
@@ -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
}
}
diff --git a/quicksettings/screenrotation/metadata.desktop b/quicksettings/screenrotation/package/metadata.desktop
similarity index 100%
rename from quicksettings/screenrotation/metadata.desktop
rename to quicksettings/screenrotation/package/metadata.desktop
diff --git a/quicksettings/screenrotation/qmldir b/quicksettings/screenrotation/qmldir
new file mode 100644
index 00000000..f10da1ae
--- /dev/null
+++ b/quicksettings/screenrotation/qmldir
@@ -0,0 +1,7 @@
+# SPDX-FileCopyrightText: 2022 Devin Lin
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+module org.kde.plasma.quicksetting.screenrotation
+plugin screenrotationplugin
+classname ScreenRotationPlugin
+
diff --git a/quicksettings/screenrotation/screenrotationplugin.cpp b/quicksettings/screenrotation/screenrotationplugin.cpp
new file mode 100644
index 00000000..7580c04a
--- /dev/null
+++ b/quicksettings/screenrotation/screenrotationplugin.cpp
@@ -0,0 +1,23 @@
+/*
+ * SPDX-FileCopyrightText: 2022 by Devin Lin
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "screenrotationplugin.h"
+
+#include
+#include
+
+#include "screenrotationutil.h"
+
+void ScreenRotationPlugin::registerTypes(const char *uri)
+{
+ Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.plasma.quicksetting.screenrotation"));
+
+ qmlRegisterSingletonType(uri, 1, 0, "ScreenRotationUtil", [](QQmlEngine *, QJSEngine *) {
+ return new ScreenRotationUtil;
+ });
+}
+
+//#include "moc_screenrotationplugin.cpp"
diff --git a/quicksettings/screenrotation/screenrotationplugin.h b/quicksettings/screenrotation/screenrotationplugin.h
new file mode 100644
index 00000000..4be1a452
--- /dev/null
+++ b/quicksettings/screenrotation/screenrotationplugin.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 ScreenRotationPlugin : public QQmlExtensionPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
+
+public:
+ void registerTypes(const char *uri) override;
+};
diff --git a/quicksettings/screenrotation/screenrotationutil.cpp b/quicksettings/screenrotation/screenrotationutil.cpp
new file mode 100644
index 00000000..72a33876
--- /dev/null
+++ b/quicksettings/screenrotation/screenrotationutil.cpp
@@ -0,0 +1,41 @@
+/*
+ * SPDX-FileCopyrightText: 2022 by Devin Lin
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "screenrotationutil.h"
+
+#include
+#include
+
+#include
+
+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 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);
+ }
+}
diff --git a/quicksettings/screenrotation/screenrotationutil.h b/quicksettings/screenrotation/screenrotationutil.h
new file mode 100644
index 00000000..1d9fe28b
--- /dev/null
+++ b/quicksettings/screenrotation/screenrotationutil.h
@@ -0,0 +1,29 @@
+/*
+ * SPDX-FileCopyrightText: 2022 by Devin Lin
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#pragma once
+
+#include
+
+#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;
+};