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 QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ));
22 const QMaemo5Rotator::RotationBehavior QMaemo5Rotator::currentBehavior()
24 return _currentBehavior;
27 const QMaemo5Rotator::Orientation QMaemo5Rotator::currentOrientation()
29 return _currentOrientation;
32 void QMaemo5Rotator::setCurrentBehavior(QMaemo5Rotator::RotationBehavior value)
34 if (value == _currentBehavior && isSetUp)
38 _currentBehavior = value;
40 if (value == QMaemo5Rotator::AutomaticBehavior)
42 QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_ACCELEROMETER_ENABLE_REQ));
43 QDBusConnection::systemBus().connect(QString(), MCE_SIGNAL_PATH, MCE_SIGNAL_IF, MCE_DEVICE_ORIENTATION_SIG, this, SLOT(on_orientation_changed(QString)));
47 QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ));
49 if (value == QMaemo5Rotator::PortraitBehavior)
51 setCurrentOrientation(QMaemo5Rotator::PortraitOrientation);
55 setCurrentOrientation(QMaemo5Rotator::LandscapeOrientation);
60 void QMaemo5Rotator::setCurrentOrientation(QMaemo5Rotator::Orientation value)
62 _currentOrientation = value;
63 QWidget *par = (QWidget*)parent();
67 case QMaemo5Rotator::PortraitOrientation:
70 par->setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
71 par->setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
73 orientationChanged(QMaemo5Rotator::PortraitOrientation);
75 case QMaemo5Rotator::LandscapeOrientation:
78 par->setAttribute(Qt::WA_Maemo5PortraitOrientation, false);
79 par->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
81 orientationChanged(QMaemo5Rotator::LandscapeOrientation);
87 void QMaemo5Rotator::on_orientation_changed(const QString& newOrientation)
89 if (newOrientation == QLatin1String(MCE_ORIENTATION_PORTRAIT) || newOrientation == QLatin1String(MCE_ORIENTATION_PORTRAIT_INVERTED))
91 setCurrentOrientation(QMaemo5Rotator::PortraitOrientation);
95 setCurrentOrientation(QMaemo5Rotator::LandscapeOrientation);
97 QApplication::desktop()->updateGeometry();