Unity 8
orientationlock.cpp
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 #include "orientationlock.h"
18 
19 #include <QDBusConnection>
20 #include <QDBusInterface>
21 
22 OrientationLock::OrientationLock(QObject *parent)
23  : QObject(parent)
24  , m_enabled(false)
25  , m_savedOrientation(Qt::PortraitOrientation)
26 {
27  m_systemSettings = g_settings_new("com.ubuntu.touch.system");
28  g_signal_connect(m_systemSettings, "changed::rotation-lock",
29  G_CALLBACK(OrientationLock::onEnabledChangedProxy), this);
30  m_enabled = g_settings_get_boolean(m_systemSettings, "rotation-lock");
31 }
32 
33 OrientationLock::~OrientationLock()
34 {
35  g_signal_handlers_disconnect_by_data(m_systemSettings, this);
36  g_object_unref(m_systemSettings);
37 }
38 
39 bool OrientationLock::enabled() const
40 {
41  return m_enabled;
42 }
43 
44 Qt::ScreenOrientation OrientationLock::savedOrientation() const
45 {
46  return m_savedOrientation;
47 }
48 
49 void OrientationLock::onEnabledChangedProxy(GSettings */*settings*/, const gchar */*key*/, gpointer data)
50 {
51  OrientationLock* _this = static_cast<OrientationLock*>(data);
52  _this->onEnabledChanged();
53 }
54 
55 void OrientationLock::onEnabledChanged()
56 {
57  const bool enabled = g_settings_get_boolean(m_systemSettings, "rotation-lock");
58  if (m_enabled != enabled) {
59  m_enabled = enabled;
60  Q_EMIT enabledChanged();
61  }
62 }
63 
64 void OrientationLock::setSavedOrientation(const Qt::ScreenOrientation orientation)
65 {
66  if (orientation == m_savedOrientation) {
67  return;
68  }
69 
70  m_savedOrientation = orientation;
71 
72  //TODO - save value with dbus to persist over sessions
73  Q_EMIT savedOrientationChanged();
74 }
The OrientationLock class exports orientation lock related properties to QML It has two properties: ...