Commit 6bf68ccb5809a7fac60cb2edcc4695ccab1c848c

QOrientationCapability implementation (not yet fully functional)
  
1#ifndef QHILDONWIDGETCAPABILITIES_GLOBAL_H
2#define QHILDONWIDGETCAPABILITIES_GLOBAL_H
3
4#include <QtCore/qglobal.h>
5
6
7#if defined(QHILDONWIDGETCAPABILITIES_LIBRARY)
8# define QHILDONWIDGETCAPABILITIES_SHARED_EXPORT Q_DECL_EXPORT
9#else
10# define QHILDONWIDGETCAPABILITIES_SHARED_EXPORT Q_DECL_IMPORT
11#endif
12
13//PRIVATE IMPLEMENTATION
14#define MAEMO_DECLARE_PRIVATE(Class) \
15 private: \
16 inline Class##Private* priv_func() { return reinterpret_cast<Class##Private *>(priv_ptr); } \
17 inline const Class##Private* priv_func() const { return reinterpret_cast<const Class##Private *>(priv_ptr); } \
18 friend class Class##Private; \
19 void* priv_ptr;
20
21#define MAEMO_DECLARE_PUBLIC(Class) \
22 public: \
23 inline Class* pub_func() { return reinterpret_cast<Class *>(pub_ptr); } \
24 inline const Class* pub_func() const { return reinterpret_cast<const Class *>(pub_ptr); } \
25 private: \
26 friend class Class; \
27 void* pub_ptr;
28
29#define MAEMO_PRIVATE(Class) Class##Private * const priv = priv_func();
30#define MAEMO_PRIVATE_CONST(Class) const Class##Private * const priv = priv_func();
31#define MAEMO_PUBLIC(Class) Class * const pub = pub_func();
32
33#define MAEMO_INITIALIZE(Class) \
34 priv_ptr = new Class##Private(); \
35 MAEMO_PRIVATE(Class); \
36 priv->pub_ptr = this;
37
38#define MAEMO_UNINITIALIZE(Class) do { MAEMO_PRIVATE(Class); delete priv; } while(0)
39
40#define compilation_assert(const_expr) do {switch(0){case 0: case const_expr: ; }} while(0)
41
42#endif // QHILDONWIDGETCAPABILITIES_GLOBAL_H
  
11#include "qorientationcapability.h"
2#include "qorientationcapability_p.h"
3#include "qxfunctions.h"
24
5#include <QtGui/QWidget>
6
7#include <QtDBus>
8#include <QtCore>
9
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
316namespace Maemo {
417
5QMaemoWidgetCapabilities::QMaemoWidgetCapabilities()
18QOrientationCapability::QOrientationCapability(QWidget* parent, bool updateCurrentOrientation):
19 QObject(parent)
620{
21 MAEMO_INITIALIZE(QOrientationCapability);
722}
23
24QOrientationCapability::~QOrientationCapability()
25{
26 MAEMO_UNINITIALIZE(QOrientationCapability);
27}
28
29QOrientationCapability::Orientation QOrientationCapability::orientation() const
30{
31 MAEMO_PRIVATE_CONST(QOrientationCapability);
32 return priv->currentOrientation();
33}
34
35bool QOrientationCapability::isListeningOrientationChanges() const
36{
37 MAEMO_PRIVATE_CONST(QOrientationCapability);
38 return priv->islisteningOrientationChanges();
39}
40
41void QOrientationCapability::setListeningForOrientationChanges(bool enabled)
42{
43 MAEMO_PRIVATE(QOrientationCapability);
44 priv->setListeningOrientationChanges(enabled);
45}
46
47void QOrientationCapability::setOrientation(Orientation orientation)
48{
49 MAEMO_PRIVATE(QOrientationCapability);
50 priv->setOrientation(orientation);
51}
52
53
54/* begin private class implementation */
55
56
57QOrientationCapabilityPrivate::QOrientationCapabilityPrivate() : QObject()
58{
59 // Set application to support portrait mode
60 Maemo::setIntXProperty(qobject_cast<QWidget *>(parent()), PORTRAIT_MODE_SUPPORT, 1);
61}
62
63QOrientationCapabilityPrivate::~QOrientationCapabilityPrivate()
64{
65 Maemo::setIntXProperty(qobject_cast<QWidget *>(parent()), PORTRAIT_MODE_SUPPORT, 0);
66}
67
68void QOrientationCapabilityPrivate::initOrientationCapability(QWidget *parent, bool updateCurrentOrientation)
69{
70 //m_parent = parent;
71
72 // Update current orientation to portrait/landscape if desired
73 if (updateCurrentOrientation)
74 {
75 // Query current device orientation to start in correct mode
76 QDBusMessage msg = QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_DEVICE_ORIENTATION_GET);
77
78 // We ignore the last three arguments of the orientation information (x, y and z axis)
79 QDBusConnection::systemBus().callWithCallback(msg, this, SLOT(orientationUpdate(QString, QString, QString)));
80 }
81}
82
83bool QOrientationCapabilityPrivate::islisteningOrientationChanges() const
84{
85 return m_listenForOrientationChanges;
86}
87
88void QOrientationCapabilityPrivate::setListeningOrientationChanges(bool listening)
89{
90 if (listening)
91 {
92 QDBusConnection::systemBus().connect("", MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
93 MCE_DEVICE_ORIENTATION_SIG, this, SLOT(orientationUpdate(QString,QString,QString)));
94 }
95 else
96 {
97 QDBusConnection::systemBus().disconnect("", MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
98 MCE_DEVICE_ORIENTATION_SIG, this, SLOT(orientationUpdate(QString,QString,QString)));
99 }
100
101 m_listenForOrientationChanges = listening;
102}
103
104void QOrientationCapabilityPrivate::orientationUpdate(const QString& orientation, const QString& /* stand */, const QString& /* face */)
105{
106 if (orientation == MCE_ORIENTATION_PORTRAIT)
107 {
108 setOrientation(QOrientationCapability::Portrait);
109 }
110 else if (orientation == MCE_ORIENTATION_LANDSCAPE)
111 {
112 setOrientation(QOrientationCapability::Landscape);
113 }
114}
115
116void QOrientationCapabilityPrivate::setOrientation(QOrientationCapability::Orientation orientation)
117{
118 if (orientation != m_currentOrientation)
119 {
120 if (orientation == QOrientationCapability::Landscape)
121 {
122 Maemo::setIntXProperty(qobject_cast<QWidget *>(parent()), PORTRAIT_MODE_REQUEST, 0);
123 }
124 else
125 {
126 Maemo::setIntXProperty(qobject_cast<QWidget *>(parent()), PORTRAIT_MODE_REQUEST, 1);
127 }
128
129 m_currentOrientation = orientation;
130/*
131 MAEMO_PUBLIC(QOrientationCapability);
132 emit pub->orientationChanged(m_currentOrientation);
133*/
134 }
135}
136
137QOrientationCapability::Orientation QOrientationCapabilityPrivate::currentOrientation() const
138{
139 return m_currentOrientation;
140}
141
8142
9143} //Namespace
  
11#ifndef QORIENTATIONCAPABILITY_H
22#define QORIENTATIONCAPABILITY_H
33
4#include "../global/global.h"
4#include "global.h"
55
6#include <QObject>
7#include <QtCore>
8#include <QtGui/QWidget>
9
610namespace Maemo {
711
8class QHILDONWIDGETCAPABILITIES_SHARED_EXPORT QMaemoWidgetCapabilities {
12class QOrientationCapabilityPrivate;
13
14class QHILDONWIDGETCAPABILITIES_SHARED_EXPORT QOrientationCapability : public QObject {
915public:
10 QMaemoWidgetCapabilities();
16
17 enum Orientation {
18 Landscape = 0,
19 Portrait
20 };
21
22 QOrientationCapability(QWidget* parent, bool updateCurrentOrientation = false);
23 ~QOrientationCapability();
24
25 Orientation orientation() const;
26 bool isListeningOrientationChanges() const;
27
28signals:
29 void orientationChanged(Orientation orientation);
30
31public slots:
32 void setListeningForOrientationChanges(bool enabled);
33 void setOrientation(Orientation orientation);
34
35private:
36 MAEMO_DECLARE_PRIVATE(QOrientationCapability);
1137};
1238
1339} //Namespace
  
1#ifndef QORIENTATIONCAPABILITY_P_H
2#define QORIENTATIONCAPABILITY_P_H
3
4#include <QObject>
5
6class QWidget;
7class QOrientationCapability;
8
9namespace Maemo {
10
11namespace QOrientationCapability {
12 enum Orientation {
13 Landscape = 0,
14 Portrait
15 };
16}
17
18class QOrientationCapabilityPrivate : public QObject
19{
20public:
21 QOrientationCapabilityPrivate();
22 ~QOrientationCapabilityPrivate();
23
24 void initOrientationCapability(QWidget *parent, bool listening);
25
26 inline bool islisteningOrientationChanges() const;
27 void setListeningOrientationChanges(bool listening);
28
29 inline QOrientationCapability::Orientation currentOrientation() const;
30 void setOrientation(QOrientationCapability::Orientation orientation);
31
32private Q_SLOTS:
33 void orientationUpdate(const QString& orientation, const QString& stand, const QString& face);
34
35private:
36 bool m_listenForOrientationChanges;
37 Maemo::QOrientationCapability::Orientation m_currentOrientation;
38
39public:
40 void* pub_ptr; //temporary fix
41/*
42 MAEMO_DECLARE_PUBLIC(QOrientationCapability);
43*/
44};
45
46} //namespace
47#endif
  
77#include <X11/Xlib.h>
88#include <X11/Xatom.h>
99#include <QtGui/QX11Info>
10#include <QtGui/QWidget>
11#include <QtCore>
1012
1113namespace Maemo {
1214
  
88
99SOURCES += qorientationcapability.cpp
1010
11HEADERS += qorientationcapability.h\
12 ../global/global.h
11HEADERS += qorientationcapability.h \
12 qorientationcapability_p.h \
13 qxfunctions.h \
14 global.h