@@ -0,0 +1,74 @@
2+ * Copyright (C) 2014 Canonical, Ltd.
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.
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.
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/>.
17+#include "orientationlock.h"
19+#include <QDBusConnection>
20+#include <QDBusInterface>
22+OrientationLock::OrientationLock(QObject *parent)
25+ , m_savedOrientation(Qt::PortraitOrientation)
27+ systemSettings = g_settings_new("com.ubuntu.touch.system");
28+ g_signal_connect(systemSettings, "changed::rotation-lock",
29+ G_CALLBACK(OrientationLock::onEnabledChangedProxy), this);
30+ m_enabled = g_settings_get_boolean(systemSettings, "rotation-lock");
33+OrientationLock::~OrientationLock()
35+ g_signal_handlers_disconnect_by_data(systemSettings, this);
36+ g_object_unref(systemSettings);
39+bool OrientationLock::enabled() const
44+Qt::ScreenOrientation OrientationLock::savedOrientation() const
46+ return m_savedOrientation;
49+void OrientationLock::onEnabledChangedProxy(GSettings */*settings*/, const gchar */*key*/, gpointer data)
51+ OrientationLock* _this = static_cast<OrientationLock*>(data);
52+ _this->onEnabledChanged();
55+void OrientationLock::onEnabledChanged()
57+ const bool enabled = g_settings_get_boolean(systemSettings, "rotation-lock");
58+ if (m_enabled != enabled) {
60+ Q_EMIT enabledChanged();
64+void OrientationLock::setSavedOrientation(const Qt::ScreenOrientation orientation)
66+ if (orientation == m_savedOrientation) {
70+ m_savedOrientation = orientation;
72+ //TODO - save value with dbus to persist over sessions
73+ Q_EMIT savedOrientationChanged();