Commit 6bf68ccb5809a7fac60cb2edcc4695ccab1c848c
- Diff rendering mode:
- inline
- side by side
|   | |||
| 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 |
|   | |||
| 1 | 1 | #include "qorientationcapability.h" | |
| 2 | #include "qorientationcapability_p.h" | ||
| 3 | #include "qxfunctions.h" | ||
| 2 | 4 | ||
| 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 | |||
| 13 | const QString PORTRAIT_MODE_REQUEST = "_HILDON_PORTRAIT_MODE_REQUEST"; | ||
| 14 | const QString PORTRAIT_MODE_SUPPORT = "_HILDON_PORTRAIT_MODE_SUPPORT"; | ||
| 15 | |||
| 3 | 16 | namespace Maemo { | |
| 4 | 17 | ||
| 5 | QMaemoWidgetCapabilities::QMaemoWidgetCapabilities() | ||
| 18 | QOrientationCapability::QOrientationCapability(QWidget* parent, bool updateCurrentOrientation): | ||
| 19 | QObject(parent) | ||
| 6 | 20 | { | |
| 21 | MAEMO_INITIALIZE(QOrientationCapability); | ||
| 7 | 22 | } | |
| 23 | |||
| 24 | QOrientationCapability::~QOrientationCapability() | ||
| 25 | { | ||
| 26 | MAEMO_UNINITIALIZE(QOrientationCapability); | ||
| 27 | } | ||
| 28 | |||
| 29 | QOrientationCapability::Orientation QOrientationCapability::orientation() const | ||
| 30 | { | ||
| 31 | MAEMO_PRIVATE_CONST(QOrientationCapability); | ||
| 32 | return priv->currentOrientation(); | ||
| 33 | } | ||
| 34 | |||
| 35 | bool QOrientationCapability::isListeningOrientationChanges() const | ||
| 36 | { | ||
| 37 | MAEMO_PRIVATE_CONST(QOrientationCapability); | ||
| 38 | return priv->islisteningOrientationChanges(); | ||
| 39 | } | ||
| 40 | |||
| 41 | void QOrientationCapability::setListeningForOrientationChanges(bool enabled) | ||
| 42 | { | ||
| 43 | MAEMO_PRIVATE(QOrientationCapability); | ||
| 44 | priv->setListeningOrientationChanges(enabled); | ||
| 45 | } | ||
| 46 | |||
| 47 | void QOrientationCapability::setOrientation(Orientation orientation) | ||
| 48 | { | ||
| 49 | MAEMO_PRIVATE(QOrientationCapability); | ||
| 50 | priv->setOrientation(orientation); | ||
| 51 | } | ||
| 52 | |||
| 53 | |||
| 54 | /* begin private class implementation */ | ||
| 55 | |||
| 56 | |||
| 57 | QOrientationCapabilityPrivate::QOrientationCapabilityPrivate() : QObject() | ||
| 58 | { | ||
| 59 | // Set application to support portrait mode | ||
| 60 | Maemo::setIntXProperty(qobject_cast<QWidget *>(parent()), PORTRAIT_MODE_SUPPORT, 1); | ||
| 61 | } | ||
| 62 | |||
| 63 | QOrientationCapabilityPrivate::~QOrientationCapabilityPrivate() | ||
| 64 | { | ||
| 65 | Maemo::setIntXProperty(qobject_cast<QWidget *>(parent()), PORTRAIT_MODE_SUPPORT, 0); | ||
| 66 | } | ||
| 67 | |||
| 68 | void 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 | |||
| 83 | bool QOrientationCapabilityPrivate::islisteningOrientationChanges() const | ||
| 84 | { | ||
| 85 | return m_listenForOrientationChanges; | ||
| 86 | } | ||
| 87 | |||
| 88 | void 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 | |||
| 104 | void 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 | |||
| 116 | void 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 | |||
| 137 | QOrientationCapability::Orientation QOrientationCapabilityPrivate::currentOrientation() const | ||
| 138 | { | ||
| 139 | return m_currentOrientation; | ||
| 140 | } | ||
| 141 | |||
| 8 | 142 | ||
| 9 | 143 | } //Namespace |
|   | |||
| 1 | 1 | #ifndef QORIENTATIONCAPABILITY_H | |
| 2 | 2 | #define QORIENTATIONCAPABILITY_H | |
| 3 | 3 | ||
| 4 | #include "../global/global.h" | ||
| 4 | #include "global.h" | ||
| 5 | 5 | ||
| 6 | #include <QObject> | ||
| 7 | #include <QtCore> | ||
| 8 | #include <QtGui/QWidget> | ||
| 9 | |||
| 6 | 10 | namespace Maemo { | |
| 7 | 11 | ||
| 8 | class QHILDONWIDGETCAPABILITIES_SHARED_EXPORT QMaemoWidgetCapabilities { | ||
| 12 | class QOrientationCapabilityPrivate; | ||
| 13 | |||
| 14 | class QHILDONWIDGETCAPABILITIES_SHARED_EXPORT QOrientationCapability : public QObject { | ||
| 9 | 15 | public: | |
| 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 | |||
| 28 | signals: | ||
| 29 | void orientationChanged(Orientation orientation); | ||
| 30 | |||
| 31 | public slots: | ||
| 32 | void setListeningForOrientationChanges(bool enabled); | ||
| 33 | void setOrientation(Orientation orientation); | ||
| 34 | |||
| 35 | private: | ||
| 36 | MAEMO_DECLARE_PRIVATE(QOrientationCapability); | ||
| 11 | 37 | }; | |
| 12 | 38 | ||
| 13 | 39 | } //Namespace |
|   | |||
| 1 | #ifndef QORIENTATIONCAPABILITY_P_H | ||
| 2 | #define QORIENTATIONCAPABILITY_P_H | ||
| 3 | |||
| 4 | #include <QObject> | ||
| 5 | |||
| 6 | class QWidget; | ||
| 7 | class QOrientationCapability; | ||
| 8 | |||
| 9 | namespace Maemo { | ||
| 10 | |||
| 11 | namespace QOrientationCapability { | ||
| 12 | enum Orientation { | ||
| 13 | Landscape = 0, | ||
| 14 | Portrait | ||
| 15 | }; | ||
| 16 | } | ||
| 17 | |||
| 18 | class QOrientationCapabilityPrivate : public QObject | ||
| 19 | { | ||
| 20 | public: | ||
| 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 | |||
| 32 | private Q_SLOTS: | ||
| 33 | void orientationUpdate(const QString& orientation, const QString& stand, const QString& face); | ||
| 34 | |||
| 35 | private: | ||
| 36 | bool m_listenForOrientationChanges; | ||
| 37 | Maemo::QOrientationCapability::Orientation m_currentOrientation; | ||
| 38 | |||
| 39 | public: | ||
| 40 | void* pub_ptr; //temporary fix | ||
| 41 | /* | ||
| 42 | MAEMO_DECLARE_PUBLIC(QOrientationCapability); | ||
| 43 | */ | ||
| 44 | }; | ||
| 45 | |||
| 46 | } //namespace | ||
| 47 | #endif |
|   | |||
| 7 | 7 | #include <X11/Xlib.h> | |
| 8 | 8 | #include <X11/Xatom.h> | |
| 9 | 9 | #include <QtGui/QX11Info> | |
| 10 | #include <QtGui/QWidget> | ||
| 11 | #include <QtCore> | ||
| 10 | 12 | ||
| 11 | 13 | namespace Maemo { | |
| 12 | 14 |
|   | |||
| 8 | 8 | ||
| 9 | 9 | SOURCES += qorientationcapability.cpp | |
| 10 | 10 | ||
| 11 | HEADERS += qorientationcapability.h\ | ||
| 12 | ../global/global.h | ||
| 11 | HEADERS += qorientationcapability.h \ | ||
| 12 | qorientationcapability_p.h \ | ||
| 13 | qxfunctions.h \ | ||
| 14 | global.h |

