Commit 9cbb5374 authored by Luca Weiss's avatar Luca Weiss

Quicksettings: add toggle for enabling/disabling screen rotation

parent 6db9537d
qt5_add_dbus_interfaces(DBUS_SRCS dbus/org.kde.KWin.Screenshot.xml)
qt5_add_dbus_interfaces(DBUS_SRCS dbus/org.kde.KWin.Screenshot.xml
dbus/org.kde.KScreen.xml)
set(phonepanel_SRCS
phonepanel.cpp
......
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.kde.KScreen">
<method name="applyLayoutPreset">
<arg type="s" name="presetName" direction="in" />
</method>
<method name="getAutoRotate">
<arg type="b" direction="out" />
</method>
<method name="setAutoRotate">
<arg type="b" name="value" direction="in" />
</method>
<signal name="outputConnected">
<arg type="s" name="outputName" direction="out" />
</signal>
<signal name="unknownOutputConnected">
<arg type="s" name="outputName" direction="out" />
</signal>
</interface>
</node>
......@@ -60,6 +60,12 @@ Item {
settingsModel.get(2).enabled = !enabledConnections.wwanEnabled
}
function toggleRotation() {
const enable = !plasmoid.nativeInterface.autoRotateEnabled
plasmoid.nativeInterface.autoRotateEnabled = enable
settingsModel.get(8).enabled = enable
}
function requestShutdown() {
print("Shutdown requested, depends on ksmserver running");
var service = pmSource.serviceForSource("PowerDevil");
......@@ -199,6 +205,14 @@ Item {
"toggleFunction": "requestScreenshot",
"applet": null
});
settingsModel.append({
"text": i18n("Auto-rotate"),
"icon": "rotation-allowed",
"enabled": plasmoid.nativeInterface.autoRotateEnabled,
"settingsCommand": "",
"toggleFunction": "toggleRotation",
"applet": null
});
brightnessSlider.moved.connect(function() {
root.screenBrightness = brightnessSlider.value;
......
......@@ -35,6 +35,7 @@ PhonePanel::PhonePanel(QObject *parent, const QVariantList &args)
: Plasma::Containment(parent, args)
{
//setHasConfigurationInterface(true);
m_kscreenInterface = new org::kde::KScreen(QStringLiteral("org.kde.kded5"), QStringLiteral("/modules/kscreen"), QDBusConnection::sessionBus(), this);
m_screenshotInterface = new org::kde::kwin::Screenshot(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QDBusConnection::sessionBus(), this);
}
......@@ -79,6 +80,29 @@ void PhonePanel::toggleTorch()
}
}
bool PhonePanel::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 PhonePanel::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);
}
}
void PhonePanel::takeScreenshot()
{
// wait ~200 ms to wait for rest of animations
......
......@@ -26,11 +26,13 @@
#include <gst/gst.h>
#include "kscreeninterface.h"
#include "screenshotinterface.h"
class PhonePanel : public Plasma::Containment
{
Q_OBJECT
Q_PROPERTY(bool autoRotateEnabled READ autoRotate WRITE setAutoRotate NOTIFY autoRotateChanged);
public:
PhonePanel( QObject *parent, const QVariantList &args );
......@@ -41,12 +43,19 @@ public Q_SLOTS:
void toggleTorch();
void takeScreenshot();
bool autoRotate();
void setAutoRotate(bool value);
signals:
void autoRotateChanged(bool value);
private:
GstElement* m_pipeline;
GstElement* m_sink;
GstElement* m_source;
bool m_running = false;
org::kde::KScreen *m_kscreenInterface;
org::kde::kwin::Screenshot *m_screenshotInterface;
};
......
Markdown is supported
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