X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=qmaemo5rotator.cpp;fp=qmaemo5rotator.cpp;h=78cbe6ac797d5b90e12e078975b6f508068830a3;hb=4359db0c4594f697e955c3bcfa5c0f1523682781;hp=0000000000000000000000000000000000000000;hpb=2f9c66b9177f647336c61dda586b1918bcb2f2a3;p=groove diff --git a/qmaemo5rotator.cpp b/qmaemo5rotator.cpp new file mode 100644 index 0000000..78cbe6a --- /dev/null +++ b/qmaemo5rotator.cpp @@ -0,0 +1,106 @@ + +#include "qmaemo5rotator.h" +#if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON) +#include +#include +#include +#include +#endif + +QMaemo5Rotator::QMaemo5Rotator(RotationBehavior behavior, QWidget *parent) + : QObject(parent), + isSetUp(false) +{ + setCurrentBehavior(behavior); +} + +QMaemo5Rotator::~QMaemo5Rotator() +{ +#if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON) + QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ)); +#endif +} + +const QMaemo5Rotator::RotationBehavior QMaemo5Rotator::currentBehavior() +{ + return _currentBehavior; +} + +const QMaemo5Rotator::Orientation QMaemo5Rotator::currentOrientation() +{ + return _currentOrientation; +} + +void QMaemo5Rotator::setCurrentBehavior(QMaemo5Rotator::RotationBehavior value) +{ +#if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON) + if (value == _currentBehavior && isSetUp) + return; + + isSetUp = true; + _currentBehavior = value; + + if (value == QMaemo5Rotator::AutomaticBehavior) + { + QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_ACCELEROMETER_ENABLE_REQ)); + QDBusConnection::systemBus().connect(QString(), MCE_SIGNAL_PATH, MCE_SIGNAL_IF, MCE_DEVICE_ORIENTATION_SIG, this, SLOT(on_orientation_changed(QString))); + } + else + { + QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ)); + + if (value == QMaemo5Rotator::PortraitBehavior) + { + setCurrentOrientation(QMaemo5Rotator::PortraitOrientation); + } + else + { + setCurrentOrientation(QMaemo5Rotator::LandscapeOrientation); + } + } +#endif +} + +void QMaemo5Rotator::setCurrentOrientation(QMaemo5Rotator::Orientation value) +{ + _currentOrientation = value; + QWidget *par = (QWidget*)parent(); + + switch (value) + { + case QMaemo5Rotator::PortraitOrientation: + if (par != NULL) + { +#if defined(Q_WS_MAEMO_5) + par->setAttribute(Qt::WA_Maemo5LandscapeOrientation, false); + par->setAttribute(Qt::WA_Maemo5PortraitOrientation, true); +#endif + } + orientationChanged(QMaemo5Rotator::PortraitOrientation); + break; + case QMaemo5Rotator::LandscapeOrientation: + if (par != NULL) + { +#if defined(Q_WS_MAEMO_5) + par->setAttribute(Qt::WA_Maemo5PortraitOrientation, false); + par->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true); +#endif + } + orientationChanged(QMaemo5Rotator::LandscapeOrientation); + + break; + } +} + +void QMaemo5Rotator::on_orientation_changed(const QString& newOrientation) +{ + if (newOrientation == QLatin1String(MCE_ORIENTATION_PORTRAIT) || newOrientation == QLatin1String(MCE_ORIENTATION_PORTRAIT_INVERTED)) + { + setCurrentOrientation(QMaemo5Rotator::PortraitOrientation); + } + else + { + setCurrentOrientation(QMaemo5Rotator::LandscapeOrientation); + } + QApplication::desktop()->updateGeometry(); +}