Commit b3ce5673eb7706241f3f83eed78f15a4bade338a

Improved private implementation. The private class is still
inherited from QObject. In order to remove the inheritance
dbus connections have to be written so that they don't
depend on the object being a QObject.
  
33
44#include <QtCore/qglobal.h>
55
6
76#if defined(QHILDONWIDGETCAPABILITIES_LIBRARY)
87# define QHILDONWIDGETCAPABILITIES_SHARED_EXPORT Q_DECL_EXPORT
98#else
1111
1212//PRIVATE IMPLEMENTATION
1313#define MAEMO_DECLARE_PRIVATE(Class) \
14 private: \
14 public: \
1515 inline Class##Private* priv_func() { return reinterpret_cast<Class##Private *>(priv_ptr); } \
1616 inline const Class##Private* priv_func() const { return reinterpret_cast<const Class##Private *>(priv_ptr); } \
17 private: \
1718 friend class Class##Private; \
1819 void* priv_ptr;
1920
2021#define MAEMO_DECLARE_PUBLIC(Class) \
2122 public: \
22 inline Class* pub_func() { return reinterpret_cast<Class *>(pub_ptr); } \
23 inline const Class* pub_func() const { return reinterpret_cast<const Class *>(pub_ptr); } \
23 inline Class* pub_func() { return static_cast<Class *>(pub_ptr); } \
24 inline const Class* pub_func() const { return static_cast<const Class *>(pub_ptr); } \
2425 private: \
2526 friend class Class; \
2627 void* pub_ptr;
  
11#include "qorientationcapability.h"
22#include "qorientationcapability_p.h"
3#include "qxfunctions.h"
3#include "moc_qorientationcapability.cpp"
44
55#include <QtGui/QWidget>
6
7#include <QtDBus>
86#include <QtCore>
97
10#include <mce/mode-names.h>
11#include <mce/dbus-names.h>
12
13const QString PORTRAIT_MODE_REQUEST = "_HILDON_PORTRAIT_MODE_REQUEST";
14const QString PORTRAIT_MODE_SUPPORT = "_HILDON_PORTRAIT_MODE_SUPPORT";
15
168namespace Maemo {
179
10class QOrientationCapabilityPrivate;
11
1812QOrientationCapability::QOrientationCapability(QWidget* parent, bool updateCurrentOrientation):
1913 QObject(parent)
2014{
2020 MAEMO_UNINITIALIZE(QOrientationCapability);
2121}
2222
23QOrientationCapability::Orientation QOrientationCapability::orientation() const
23QOrientation QOrientationCapability::orientation() const
2424{
2525 MAEMO_PRIVATE_CONST(QOrientationCapability);
2626 return priv->currentOrientation();
3838 priv->setListeningOrientationChanges(enabled);
3939}
4040
41void QOrientationCapability::setOrientation(Orientation orientation)
41void QOrientationCapability::setOrientation(QOrientation orientation)
4242{
4343 MAEMO_PRIVATE(QOrientationCapability);
4444 priv->setOrientation(orientation);
4545}
46
47
48/* begin private class implementation */
49
50
51QOrientationCapabilityPrivate::QOrientationCapabilityPrivate() : QObject()
52{
53 // Set application to support portrait mode
54 Maemo::setIntXProperty(qobject_cast<QWidget *>(parent()), PORTRAIT_MODE_SUPPORT, 1);
55}
56
57QOrientationCapabilityPrivate::~QOrientationCapabilityPrivate()
58{
59 Maemo::setIntXProperty(qobject_cast<QWidget *>(parent()), PORTRAIT_MODE_SUPPORT, 0);
60}
61
62void QOrientationCapabilityPrivate::initOrientationCapability(QWidget *parent, bool updateCurrentOrientation)
63{
64 //m_parent = parent;
65
66 // Update current orientation to portrait/landscape if desired
67 if (updateCurrentOrientation)
68 {
69 // Query current device orientation to start in correct mode
70 QDBusMessage msg = QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_DEVICE_ORIENTATION_GET);
71
72 // We ignore the last three arguments of the orientation information (x, y and z axis)
73 QDBusConnection::systemBus().callWithCallback(msg, this, SLOT(orientationUpdate(QString, QString, QString)));
74 }
75}
76
77bool QOrientationCapabilityPrivate::islisteningOrientationChanges() const
78{
79 return m_listenForOrientationChanges;
80}
81
82void QOrientationCapabilityPrivate::setListeningOrientationChanges(bool listening)
83{
84 if (listening)
85 {
86 QDBusConnection::systemBus().connect("", MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
87 MCE_DEVICE_ORIENTATION_SIG, this, SLOT(orientationUpdate(QString,QString,QString)));
88 }
89 else
90 {
91 QDBusConnection::systemBus().disconnect("", MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
92 MCE_DEVICE_ORIENTATION_SIG, this, SLOT(orientationUpdate(QString,QString,QString)));
93 }
94
95 m_listenForOrientationChanges = listening;
96}
97
98void QOrientationCapabilityPrivate::orientationUpdate(const QString& orientation, const QString& /* stand */, const QString& /* face */)
99{
100 if (orientation == MCE_ORIENTATION_PORTRAIT)
101 {
102 setOrientation(QOrientationCapability::Portrait);
103 }
104 else if (orientation == MCE_ORIENTATION_LANDSCAPE)
105 {
106 setOrientation(QOrientationCapability::Landscape);
107 }
108}
109
110void QOrientationCapabilityPrivate::setOrientation(QOrientationCapability::Orientation orientation)
111{
112 if (orientation != m_currentOrientation)
113 {
114 if (orientation == QOrientationCapability::Landscape)
115 {
116 Maemo::setIntXProperty(qobject_cast<QWidget *>(parent()), PORTRAIT_MODE_REQUEST, 0);
117 }
118 else
119 {
120 Maemo::setIntXProperty(qobject_cast<QWidget *>(parent()), PORTRAIT_MODE_REQUEST, 1);
121 }
122
123 m_currentOrientation = orientation;
124/*
125 MAEMO_PUBLIC(QOrientationCapability);
126 emit pub->orientationChanged(m_currentOrientation);
127*/
128 }
129}
130
131QOrientationCapability::Orientation QOrientationCapabilityPrivate::currentOrientation() const
132{
133 return m_currentOrientation;
134}
135
13646
13747} //Namespace
  
99
1010namespace Maemo {
1111
12 enum QOrientation {
13 Landscape = 0,
14 Portrait
15 };
16
1217class QOrientationCapabilityPrivate;
1318
1419class QHILDONWIDGETCAPABILITIES_SHARED_EXPORT QOrientationCapability : public QObject {
15public:
20 Q_OBJECT
21 Q_PROPERTY(bool listensForOrientationChanges READ isListeningOrientationChanges WRITE setListeningForOrientationChanges);
1622
17 enum Orientation {
18 Landscape = 0,
19 Portrait
20 };
23 MAEMO_DECLARE_PRIVATE(QOrientationCapability);
2124
25public:
26
2227 QOrientationCapability(QWidget* parent, bool updateCurrentOrientation = false);
2328 ~QOrientationCapability();
2429
25 Orientation orientation() const;
30 QOrientation orientation() const;
2631 bool isListeningOrientationChanges() const;
2732
2833signals:
29 void orientationChanged(Orientation orientation);
34 void orientationChanged(QOrientation orientation);
3035
3136public slots:
3237 void setListeningForOrientationChanges(bool enabled);
33 void setOrientation(Orientation orientation);
34
35private:
36 MAEMO_DECLARE_PRIVATE(QOrientationCapability);
38 void setOrientation(QOrientation orientation);
3739};
3840
3941} //Namespace
  
11#ifndef QORIENTATIONCAPABILITY_P_H
22#define QORIENTATIONCAPABILITY_P_H
33
4#include "qorientationcapability.h"
5#include "qxfunctions.h"
6
7#include <mce/mode-names.h>
8#include <mce/dbus-names.h>
9
10#include <QtDBus>
11
412#include <QObject>
513
14const QString PORTRAIT_MODE_REQUEST = "_HILDON_PORTRAIT_MODE_REQUEST";
15const QString PORTRAIT_MODE_SUPPORT = "_HILDON_PORTRAIT_MODE_SUPPORT";
16
617class QWidget;
7class QOrientationCapability;
818
919namespace Maemo {
1020
11namespace QOrientationCapability {
12 enum Orientation {
13 Landscape = 0,
14 Portrait
15 };
16}
21class QOrientationCapability;
1722
1823class QOrientationCapabilityPrivate : public QObject
1924{
25 MAEMO_DECLARE_PUBLIC(QOrientationCapability);
26
2027public:
21 QOrientationCapabilityPrivate();
28 QOrientationCapabilityPrivate(bool updateCurrentOrientation = false);
2229 ~QOrientationCapabilityPrivate();
2330
24 void initOrientationCapability(QWidget *parent, bool listening);
25
2631 inline bool islisteningOrientationChanges() const;
2732 void setListeningOrientationChanges(bool listening);
2833
29 inline QOrientationCapability::Orientation currentOrientation() const;
30 void setOrientation(QOrientationCapability::Orientation orientation);
34 inline QOrientation currentOrientation() const;
35 void setOrientation(QOrientation orientation);
3136
32private Q_SLOTS:
37private:
3338 void orientationUpdate(const QString& orientation, const QString& stand, const QString& face);
39 Q_PRIVATE_SLOT(this, void orientationUpdate(const QString& orientation, const QString& stand, const QString& face));
3440
3541private:
3642 bool m_listenForOrientationChanges;
37 Maemo::QOrientationCapability::Orientation m_currentOrientation;
38
39public:
40 void* pub_ptr; //temporary fix
41/*
42 MAEMO_DECLARE_PUBLIC(QOrientationCapability);
43*/
43 QOrientation m_currentOrientation;
4444};
45
46/* begin private class implementation */
47
48QOrientationCapabilityPrivate::QOrientationCapabilityPrivate(bool updateCurrentOrientation) : QObject()
49{
50 // Set application to support portrait mode
51 MAEMO_PUBLIC(QOrientationCapability);
52 Maemo::setIntXProperty(qobject_cast<QWidget *>(pub->parent()), PORTRAIT_MODE_SUPPORT, 1);
53
54 // Update current orientation to portrait/landscape if desired
55 if (updateCurrentOrientation)
56 {
57 // Query current device orientation to start in correct mode
58 QDBusMessage msg = QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_DEVICE_ORIENTATION_GET);
59
60 // We ignore the last three arguments of the orientation information (x, y and z axis)
61 //TODO: Doesn't work if class is not inherited from QObject
62 QDBusConnection::systemBus().callWithCallback(msg, this, SLOT(orientationUpdate(QString, QString, QString)));
63 }
64}
65
66QOrientationCapabilityPrivate::~QOrientationCapabilityPrivate()
67{
68 MAEMO_PUBLIC(QOrientationCapability);
69 Maemo::setIntXProperty(qobject_cast<QWidget *>(pub->parent()), PORTRAIT_MODE_SUPPORT, 0);
70}
71
72bool QOrientationCapabilityPrivate::islisteningOrientationChanges() const
73{
74 return m_listenForOrientationChanges;
75}
76
77void QOrientationCapabilityPrivate::setListeningOrientationChanges(bool listening)
78{
79 if (listening)
80 {
81 //TODO: Doesn't work if class is not inherited from QObject
82 QDBusConnection::systemBus().connect("", MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
83 MCE_DEVICE_ORIENTATION_SIG, this, SLOT(orientationUpdate(QString, QString, QString)));
84 }
85 else
86 {
87 //TODO: Doesn't work if class is not inherited from QObject
88 QDBusConnection::systemBus().disconnect("", MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
89 MCE_DEVICE_ORIENTATION_SIG, this, SLOT(orientationUpdate(QString,QString,QString)));
90 }
91
92 m_listenForOrientationChanges = listening;
93}
94
95void QOrientationCapabilityPrivate::orientationUpdate(const QString& orientation, const QString& /* stand */, const QString& /* face */)
96{
97 if (orientation == MCE_ORIENTATION_PORTRAIT)
98 {
99 setOrientation(Portrait);
100 }
101 else if (orientation == MCE_ORIENTATION_LANDSCAPE)
102 {
103 setOrientation(Landscape);
104 }
105}
106
107void QOrientationCapabilityPrivate::setOrientation(QOrientation orientation)
108{
109 if (orientation != m_currentOrientation)
110 {
111 MAEMO_PUBLIC(QOrientationCapability);
112
113 if (orientation == Landscape)
114 {
115 Maemo::setIntXProperty(qobject_cast<QWidget *>(pub->parent()), PORTRAIT_MODE_REQUEST, 0);
116 }
117 else
118 {
119 Maemo::setIntXProperty(qobject_cast<QWidget *>(pub->parent()), PORTRAIT_MODE_REQUEST, 1);
120 }
121
122 m_currentOrientation = orientation;
123
124 emit pub->orientationChanged(m_currentOrientation);
125
126 }
127}
128
129QOrientation QOrientationCapabilityPrivate::currentOrientation() const
130{
131 return m_currentOrientation;
132}
133
45134
46135} //namespace
47136#endif