Commit b3ce5673eb7706241f3f83eed78f15a4bade338a
- Diff rendering mode:
- inline
- side by side
|   | |||
| 3 | 3 | ||
| 4 | 4 | #include <QtCore/qglobal.h> | |
| 5 | 5 | ||
| 6 | |||
| 7 | 6 | #if defined(QHILDONWIDGETCAPABILITIES_LIBRARY) | |
| 8 | 7 | # define QHILDONWIDGETCAPABILITIES_SHARED_EXPORT Q_DECL_EXPORT | |
| 9 | 8 | #else | |
| … | … | ||
| 11 | 11 | ||
| 12 | 12 | //PRIVATE IMPLEMENTATION | |
| 13 | 13 | #define MAEMO_DECLARE_PRIVATE(Class) \ | |
| 14 | private: \ | ||
| 14 | public: \ | ||
| 15 | 15 | inline Class##Private* priv_func() { return reinterpret_cast<Class##Private *>(priv_ptr); } \ | |
| 16 | 16 | inline const Class##Private* priv_func() const { return reinterpret_cast<const Class##Private *>(priv_ptr); } \ | |
| 17 | private: \ | ||
| 17 | 18 | friend class Class##Private; \ | |
| 18 | 19 | void* priv_ptr; | |
| 19 | 20 | ||
| 20 | 21 | #define MAEMO_DECLARE_PUBLIC(Class) \ | |
| 21 | 22 | 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); } \ | ||
| 24 | 25 | private: \ | |
| 25 | 26 | friend class Class; \ | |
| 26 | 27 | void* pub_ptr; |
|   | |||
| 1 | 1 | #include "qorientationcapability.h" | |
| 2 | 2 | #include "qorientationcapability_p.h" | |
| 3 | #include "qxfunctions.h" | ||
| 3 | #include "moc_qorientationcapability.cpp" | ||
| 4 | 4 | ||
| 5 | 5 | #include <QtGui/QWidget> | |
| 6 | |||
| 7 | #include <QtDBus> | ||
| 8 | 6 | #include <QtCore> | |
| 9 | 7 | ||
| 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 | |||
| 16 | 8 | namespace Maemo { | |
| 17 | 9 | ||
| 10 | class QOrientationCapabilityPrivate; | ||
| 11 | |||
| 18 | 12 | QOrientationCapability::QOrientationCapability(QWidget* parent, bool updateCurrentOrientation): | |
| 19 | 13 | QObject(parent) | |
| 20 | 14 | { | |
| … | … | ||
| 20 | 20 | MAEMO_UNINITIALIZE(QOrientationCapability); | |
| 21 | 21 | } | |
| 22 | 22 | ||
| 23 | QOrientationCapability::Orientation QOrientationCapability::orientation() const | ||
| 23 | QOrientation QOrientationCapability::orientation() const | ||
| 24 | 24 | { | |
| 25 | 25 | MAEMO_PRIVATE_CONST(QOrientationCapability); | |
| 26 | 26 | return priv->currentOrientation(); | |
| … | … | ||
| 38 | 38 | priv->setListeningOrientationChanges(enabled); | |
| 39 | 39 | } | |
| 40 | 40 | ||
| 41 | void QOrientationCapability::setOrientation(Orientation orientation) | ||
| 41 | void QOrientationCapability::setOrientation(QOrientation orientation) | ||
| 42 | 42 | { | |
| 43 | 43 | MAEMO_PRIVATE(QOrientationCapability); | |
| 44 | 44 | priv->setOrientation(orientation); | |
| 45 | 45 | } | |
| 46 | |||
| 47 | |||
| 48 | /* begin private class implementation */ | ||
| 49 | |||
| 50 | |||
| 51 | QOrientationCapabilityPrivate::QOrientationCapabilityPrivate() : QObject() | ||
| 52 | { | ||
| 53 | // Set application to support portrait mode | ||
| 54 | Maemo::setIntXProperty(qobject_cast<QWidget *>(parent()), PORTRAIT_MODE_SUPPORT, 1); | ||
| 55 | } | ||
| 56 | |||
| 57 | QOrientationCapabilityPrivate::~QOrientationCapabilityPrivate() | ||
| 58 | { | ||
| 59 | Maemo::setIntXProperty(qobject_cast<QWidget *>(parent()), PORTRAIT_MODE_SUPPORT, 0); | ||
| 60 | } | ||
| 61 | |||
| 62 | void 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 | |||
| 77 | bool QOrientationCapabilityPrivate::islisteningOrientationChanges() const | ||
| 78 | { | ||
| 79 | return m_listenForOrientationChanges; | ||
| 80 | } | ||
| 81 | |||
| 82 | void 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 | |||
| 98 | void 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 | |||
| 110 | void 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 | |||
| 131 | QOrientationCapability::Orientation QOrientationCapabilityPrivate::currentOrientation() const | ||
| 132 | { | ||
| 133 | return m_currentOrientation; | ||
| 134 | } | ||
| 135 | |||
| 136 | 46 | ||
| 137 | 47 | } //Namespace |
|   | |||
| 9 | 9 | ||
| 10 | 10 | namespace Maemo { | |
| 11 | 11 | ||
| 12 | enum QOrientation { | ||
| 13 | Landscape = 0, | ||
| 14 | Portrait | ||
| 15 | }; | ||
| 16 | |||
| 12 | 17 | class QOrientationCapabilityPrivate; | |
| 13 | 18 | ||
| 14 | 19 | class QHILDONWIDGETCAPABILITIES_SHARED_EXPORT QOrientationCapability : public QObject { | |
| 15 | public: | ||
| 20 | Q_OBJECT | ||
| 21 | Q_PROPERTY(bool listensForOrientationChanges READ isListeningOrientationChanges WRITE setListeningForOrientationChanges); | ||
| 16 | 22 | ||
| 17 | enum Orientation { | ||
| 18 | Landscape = 0, | ||
| 19 | Portrait | ||
| 20 | }; | ||
| 23 | MAEMO_DECLARE_PRIVATE(QOrientationCapability); | ||
| 21 | 24 | ||
| 25 | public: | ||
| 26 | |||
| 22 | 27 | QOrientationCapability(QWidget* parent, bool updateCurrentOrientation = false); | |
| 23 | 28 | ~QOrientationCapability(); | |
| 24 | 29 | ||
| 25 | Orientation orientation() const; | ||
| 30 | QOrientation orientation() const; | ||
| 26 | 31 | bool isListeningOrientationChanges() const; | |
| 27 | 32 | ||
| 28 | 33 | signals: | |
| 29 | void orientationChanged(Orientation orientation); | ||
| 34 | void orientationChanged(QOrientation orientation); | ||
| 30 | 35 | ||
| 31 | 36 | public slots: | |
| 32 | 37 | void setListeningForOrientationChanges(bool enabled); | |
| 33 | void setOrientation(Orientation orientation); | ||
| 34 | |||
| 35 | private: | ||
| 36 | MAEMO_DECLARE_PRIVATE(QOrientationCapability); | ||
| 38 | void setOrientation(QOrientation orientation); | ||
| 37 | 39 | }; | |
| 38 | 40 | ||
| 39 | 41 | } //Namespace |
|   | |||
| 1 | 1 | #ifndef QORIENTATIONCAPABILITY_P_H | |
| 2 | 2 | #define QORIENTATIONCAPABILITY_P_H | |
| 3 | 3 | ||
| 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 | |||
| 4 | 12 | #include <QObject> | |
| 5 | 13 | ||
| 14 | const QString PORTRAIT_MODE_REQUEST = "_HILDON_PORTRAIT_MODE_REQUEST"; | ||
| 15 | const QString PORTRAIT_MODE_SUPPORT = "_HILDON_PORTRAIT_MODE_SUPPORT"; | ||
| 16 | |||
| 6 | 17 | class QWidget; | |
| 7 | class QOrientationCapability; | ||
| 8 | 18 | ||
| 9 | 19 | namespace Maemo { | |
| 10 | 20 | ||
| 11 | namespace QOrientationCapability { | ||
| 12 | enum Orientation { | ||
| 13 | Landscape = 0, | ||
| 14 | Portrait | ||
| 15 | }; | ||
| 16 | } | ||
| 21 | class QOrientationCapability; | ||
| 17 | 22 | ||
| 18 | 23 | class QOrientationCapabilityPrivate : public QObject | |
| 19 | 24 | { | |
| 25 | MAEMO_DECLARE_PUBLIC(QOrientationCapability); | ||
| 26 | |||
| 20 | 27 | public: | |
| 21 | QOrientationCapabilityPrivate(); | ||
| 28 | QOrientationCapabilityPrivate(bool updateCurrentOrientation = false); | ||
| 22 | 29 | ~QOrientationCapabilityPrivate(); | |
| 23 | 30 | ||
| 24 | void initOrientationCapability(QWidget *parent, bool listening); | ||
| 25 | |||
| 26 | 31 | inline bool islisteningOrientationChanges() const; | |
| 27 | 32 | void setListeningOrientationChanges(bool listening); | |
| 28 | 33 | ||
| 29 | inline QOrientationCapability::Orientation currentOrientation() const; | ||
| 30 | void setOrientation(QOrientationCapability::Orientation orientation); | ||
| 34 | inline QOrientation currentOrientation() const; | ||
| 35 | void setOrientation(QOrientation orientation); | ||
| 31 | 36 | ||
| 32 | private Q_SLOTS: | ||
| 37 | private: | ||
| 33 | 38 | 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)); | ||
| 34 | 40 | ||
| 35 | 41 | private: | |
| 36 | 42 | 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 | */ | ||
| 43 | QOrientation m_currentOrientation; | ||
| 44 | 44 | }; | |
| 45 | |||
| 46 | /* begin private class implementation */ | ||
| 47 | |||
| 48 | QOrientationCapabilityPrivate::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 | |||
| 66 | QOrientationCapabilityPrivate::~QOrientationCapabilityPrivate() | ||
| 67 | { | ||
| 68 | MAEMO_PUBLIC(QOrientationCapability); | ||
| 69 | Maemo::setIntXProperty(qobject_cast<QWidget *>(pub->parent()), PORTRAIT_MODE_SUPPORT, 0); | ||
| 70 | } | ||
| 71 | |||
| 72 | bool QOrientationCapabilityPrivate::islisteningOrientationChanges() const | ||
| 73 | { | ||
| 74 | return m_listenForOrientationChanges; | ||
| 75 | } | ||
| 76 | |||
| 77 | void 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 | |||
| 95 | void 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 | |||
| 107 | void 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 | |||
| 129 | QOrientation QOrientationCapabilityPrivate::currentOrientation() const | ||
| 130 | { | ||
| 131 | return m_currentOrientation; | ||
| 132 | } | ||
| 133 | |||
| 45 | 134 | ||
| 46 | 135 | } //namespace | |
| 47 | 136 | #endif |

