Changed vkb window title
[groove] / qmaemo5rotator.cpp
1
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>
8
9
10 QMaemo5Rotator::QMaemo5Rotator(RotationBehavior behavior, QWidget *parent)
11     : QObject(parent),
12     isSetUp(false)
13 {
14     setCurrentBehavior(behavior);
15 }
16
17 QMaemo5Rotator::~QMaemo5Rotator()
18 {
19     QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ));
20 }
21
22 const QMaemo5Rotator::RotationBehavior QMaemo5Rotator::currentBehavior()
23 {
24     return _currentBehavior;
25 }
26
27 const QMaemo5Rotator::Orientation QMaemo5Rotator::currentOrientation()
28 {
29     return _currentOrientation;
30 }
31
32 void QMaemo5Rotator::setCurrentBehavior(QMaemo5Rotator::RotationBehavior value)
33 {
34     if (value == _currentBehavior && isSetUp)
35         return;
36
37     isSetUp = true;
38     _currentBehavior = value;
39
40     if (value == QMaemo5Rotator::AutomaticBehavior)
41     {
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)));
44     }
45     else
46     {
47         QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ));
48
49         if (value == QMaemo5Rotator::PortraitBehavior)
50         {
51             setCurrentOrientation(QMaemo5Rotator::PortraitOrientation);
52         }
53         else
54         {
55             setCurrentOrientation(QMaemo5Rotator::LandscapeOrientation);
56         }
57     }
58 }
59
60 void QMaemo5Rotator::setCurrentOrientation(QMaemo5Rotator::Orientation value)
61 {
62     _currentOrientation = value;
63     QWidget *par = (QWidget*)parent();
64
65     switch (value)
66     {
67     case QMaemo5Rotator::PortraitOrientation:
68         if (par != NULL)
69         {
70             par->setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
71             par->setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
72         }
73         orientationChanged(QMaemo5Rotator::PortraitOrientation);
74         break;
75     case QMaemo5Rotator::LandscapeOrientation:
76         if (par != NULL)
77         {
78             par->setAttribute(Qt::WA_Maemo5PortraitOrientation, false);
79             par->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
80         }
81         orientationChanged(QMaemo5Rotator::LandscapeOrientation);
82
83         break;
84     }
85 }
86
87 void QMaemo5Rotator::on_orientation_changed(const QString& newOrientation)
88 {
89     if (newOrientation == QLatin1String(MCE_ORIENTATION_PORTRAIT) || newOrientation == QLatin1String(MCE_ORIENTATION_PORTRAIT_INVERTED))
90     {
91         setCurrentOrientation(QMaemo5Rotator::PortraitOrientation);
92     }
93     else
94     {
95         setCurrentOrientation(QMaemo5Rotator::LandscapeOrientation);
96     }
97     QApplication::desktop()->updateGeometry();
98 }
99 #endif