Playlist support (basic) and download progress dialogs
[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 #endif
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 #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));
21 #endif
22 }
23
24 const QMaemo5Rotator::RotationBehavior QMaemo5Rotator::currentBehavior()
25 {
26     return _currentBehavior;
27 }
28
29 const QMaemo5Rotator::Orientation QMaemo5Rotator::currentOrientation()
30 {
31     return _currentOrientation;
32 }
33
34 void QMaemo5Rotator::setCurrentBehavior(QMaemo5Rotator::RotationBehavior value)
35 {
36 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
37     if (value == _currentBehavior && isSetUp)
38         return;
39
40     isSetUp = true;
41     _currentBehavior = value;
42
43     if (value == QMaemo5Rotator::AutomaticBehavior)
44     {
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)));
47     }
48     else
49     {
50         QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ));
51
52         if (value == QMaemo5Rotator::PortraitBehavior)
53         {
54             setCurrentOrientation(QMaemo5Rotator::PortraitOrientation);
55         }
56         else
57         {
58             setCurrentOrientation(QMaemo5Rotator::LandscapeOrientation);
59         }
60     }
61 #endif
62 }
63
64 void QMaemo5Rotator::setCurrentOrientation(QMaemo5Rotator::Orientation value)
65 {
66     _currentOrientation = value;
67     QWidget *par = (QWidget*)parent();
68
69     switch (value)
70     {
71     case QMaemo5Rotator::PortraitOrientation:
72         if (par != NULL)
73         {
74 #if defined(Q_WS_MAEMO_5)
75             par->setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
76             par->setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
77 #endif
78         }
79         orientationChanged(QMaemo5Rotator::PortraitOrientation);
80         break;
81     case QMaemo5Rotator::LandscapeOrientation:
82         if (par != NULL)
83         {
84 #if defined(Q_WS_MAEMO_5)
85             par->setAttribute(Qt::WA_Maemo5PortraitOrientation, false);
86             par->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
87 #endif
88         }
89         orientationChanged(QMaemo5Rotator::LandscapeOrientation);
90
91         break;
92     }
93 }
94
95 void QMaemo5Rotator::on_orientation_changed(const QString& newOrientation)
96 {
97     if (newOrientation == QLatin1String(MCE_ORIENTATION_PORTRAIT) || newOrientation == QLatin1String(MCE_ORIENTATION_PORTRAIT_INVERTED))
98     {
99         setCurrentOrientation(QMaemo5Rotator::PortraitOrientation);
100     }
101     else
102     {
103         setCurrentOrientation(QMaemo5Rotator::LandscapeOrientation);
104     }
105     QApplication::desktop()->updateGeometry();
106 }