on xenial help sign in
Provide com.canonical.Unity.Shell service to publish the rotation angle

camera-app needs this information in order to counter rotate the view finder feed.

commit9f964060a30a99a7573602b4809129d610c5aeb3 authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateWed 11 Jun 2014, 19:06 (12 years ago) parentb30d791
8 files changed+186
plugins/Unity/CMakeLists.txt+1 plugins/Unity/Shell/CMakeLists.txt+13 plugins/Unity/Shell/DBusUnityShellService.cpp+59 plugins/Unity/Shell/DBusUnityShellService.h+44 plugins/Unity/Shell/plugin.cpp+28 plugins/Unity/Shell/plugin.h+33 plugins/Unity/Shell/qmldir+3 qml/OrientedShell.qml+5
plugins/Unity/CMakeLists.txt+1
@@ -1,2 +1,3 @@
11add_subdirectory(Indicators)
22add_subdirectory(Launcher)
3+add_subdirectory(Shell)
plugins/Unity/Shell/CMakeLists.txtnew file+13
@@ -0,0 +1,13 @@
1+include_directories(
2+ ${CMAKE_CURRENT_SOURCE_DIR}
3+)
4+
5+add_library(UnityShell-qml MODULE
6+ plugin.cpp
7+ DBusUnityShellService.cpp
8+ )
9+
10+qt5_use_modules(UnityShell-qml DBus Qml)
11+
12+# export the qmldir and qmltypes files
13+add_unity8_plugin(Unity.Shell 0.1 Unity/Shell TARGETS UnityShell-qml)
plugins/Unity/Shell/DBusUnityShellService.cppnew file+59
@@ -0,0 +1,59 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+// local
18+#include "DBusUnityShellService.h"
19+
20+// Qt
21+#include <QDBusConnection>
22+
23+DBusUnityShellService::DBusUnityShellService() : QObject()
24+{
25+ QDBusConnection connection = QDBusConnection::sessionBus();
26+ bool ok;
27+
28+ connection.registerService("com.canonical.Unity.Shell");
29+
30+ ok = connection.registerObject("/com/canonical/Unity/Shell", this,
31+ QDBusConnection::ExportScriptableSignals
32+ | QDBusConnection::ExportScriptableSlots
33+ | QDBusConnection::ExportScriptableInvokables);
34+ if (!ok) {
35+ qWarning("Failed to register /com/canonical/Unity/Shell D-Bus object.");
36+ }
37+
38+ m_rotationAngle = 0;
39+}
40+
41+DBusUnityShellService::~DBusUnityShellService()
42+{
43+ QDBusConnection connection = QDBusConnection::sessionBus();
44+ connection.unregisterService("com.canonical.Unity.Shell");
45+ connection.unregisterObject("/com/canonical/Unity/Shell");
46+}
47+
48+void DBusUnityShellService::setRotationAngle(int angle)
49+{
50+ if (angle != m_rotationAngle) {
51+ m_rotationAngle = angle;
52+ Q_EMIT RotationAngleChanged(angle);
53+ }
54+}
55+
56+int DBusUnityShellService::GetRotationAngle()
57+{
58+ return m_rotationAngle;
59+}
plugins/Unity/Shell/DBusUnityShellService.hnew file+44
@@ -0,0 +1,44 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef DBUSUNITYSHELLSERVICE_H
18+#define DBUSUNITYSHELLSERVICE_H
19+
20+#include <QObject>
21+
22+class DBusUnityShellService : public QObject
23+{
24+ Q_OBJECT
25+ Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.Shell")
26+ Q_PROPERTY(int rotationAngle READ GetRotationAngle WRITE setRotationAngle NOTIFY RotationAngleChanged)
27+
28+public:
29+ DBusUnityShellService();
30+ ~DBusUnityShellService();
31+
32+ void setRotationAngle(int angle);
33+
34+Q_SIGNALS:
35+ Q_SCRIPTABLE void RotationAngleChanged(int angle);
36+
37+public Q_SLOTS:
38+ Q_SCRIPTABLE int GetRotationAngle();
39+
40+private:
41+ int m_rotationAngle;
42+};
43+
44+#endif // DBUSUNITYSHELLSERVICE_H
plugins/Unity/Shell/plugin.cppnew file+28
@@ -0,0 +1,28 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ */
17+
18+#include "plugin.h"
19+#include "DBusUnityShellService.h"
20+
21+#include <QtQml/qqml.h>
22+
23+void UnityShellPlugin::registerTypes(const char *uri)
24+{
25+ Q_ASSERT(uri == QLatin1String("Unity.Shell"));
26+
27+ qmlRegisterType<DBusUnityShellService>(uri, 0, 1, "DBusUnityShellService");
28+}
plugins/Unity/Shell/plugin.hnew file+33
@@ -0,0 +1,33 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ */
17+
18+#ifndef UNITY_SHELL_PLUGIN_H
19+#define UNITY_SHELL_PLUGIN_H
20+
21+#include <QtQml/QQmlEngine>
22+#include <QtQml/QQmlExtensionPlugin>
23+
24+class UnityShellPlugin : public QQmlExtensionPlugin
25+{
26+ Q_OBJECT
27+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
28+
29+public:
30+ void registerTypes(const char *uri);
31+};
32+
33+#endif // UNITY_SHELL_PLUGIN_H
plugins/Unity/Shell/qmldirnew file+3
@@ -0,0 +1,3 @@
1+module Unity.Shell
2+plugin UnityShell-qml
3+typeinfo Shell.qmltypes
qml/OrientedShell.qml+5
@@ -17,6 +17,7 @@
1717import QtQuick 2.0
1818import QtQuick.Window 2.0
1919import Ubuntu.Components 0.1
20+import Unity.Shell 0.1
2021import "Components"
2122
2223Rectangle {
@@ -87,6 +88,10 @@ Rectangle {
8788 return Screen.angleBetween(Screen.primaryOrientation, acceptedOrientation);
8889 }
8990
91+ DBusUnityShellService {
92+ rotationAngle: acceptedOrientationAngle
93+ }
94+
9095 state: acceptedOrientationAngle.toString()
9196 states: [
9297 State {