2 #include "qmaemo5rotator.h"
3 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
4 #include <mce/dbus-names.h>
5 #include <mce/mode-names.h>
6 #include <QtDBus/QDBusConnection>
7 #include <QtDBus/QDBusMessage>
10 QMaemo5Rotator::QMaemo5Rotator(RotationBehavior behavior, QWidget *parent)
14 setCurrentBehavior(behavior);
17 QMaemo5Rotator::~QMaemo5Rotator()
19 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
20 QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ));
24 const QMaemo5Rotator::RotationBehavior QMaemo5Rotator::currentBehavior()
26 return _currentBehavior;
29 const QMaemo5Rotator::Orientation QMaemo5Rotator::currentOrientation()
31 return _currentOrientation;
34 void QMaemo5Rotator::setCurrentBehavior(QMaemo5Rotator::RotationBehavior value)
36 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
37 if (value == _currentBehavior && isSetUp)
41 _currentBehavior = value;
43 if (value == QMaemo5Rotator::AutomaticBehavior)
45 QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_ACCELEROMETER_ENABLE_REQ));
46 QDBusConnection::systemBus().connect(QString(), MCE_SIGNAL_PATH, MCE_SIGNAL_IF, MCE_DEVICE_ORIENTATION_SIG, this, SLOT(on_orientation_changed(QString)));
50 QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ));
52 if (value == QMaemo5Rotator::PortraitBehavior)
54 setCurrentOrientation(QMaemo5Rotator::PortraitOrientation);
58 setCurrentOrientation(QMaemo5Rotator::LandscapeOrientation);
64 void QMaemo5Rotator::setCurrentOrientation(QMaemo5Rotator::Orientation value)
66 _currentOrientation = value;
67 QWidget *par = (QWidget*)parent();
71 case QMaemo5Rotator::PortraitOrientation:
74 #if defined(Q_WS_MAEMO_5)
75 par->setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
76 par->setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
79 orientationChanged(QMaemo5Rotator::PortraitOrientation);
81 case QMaemo5Rotator::LandscapeOrientation:
84 #if defined(Q_WS_MAEMO_5)
85 par->setAttribute(Qt::WA_Maemo5PortraitOrientation, false);
86 par->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
89 orientationChanged(QMaemo5Rotator::LandscapeOrientation);
95 void QMaemo5Rotator::on_orientation_changed(const QString& newOrientation)
97 if (newOrientation == QLatin1String(MCE_ORIENTATION_PORTRAIT) || newOrientation == QLatin1String(MCE_ORIENTATION_PORTRAIT_INVERTED))
99 setCurrentOrientation(QMaemo5Rotator::PortraitOrientation);
103 setCurrentOrientation(QMaemo5Rotator::LandscapeOrientation);
105 QApplication::desktop()->updateGeometry();