summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMorten Engvoldsen <morten.engvoldsen@nokia.com>2010-09-07 08:56:37 (GMT)
committerMorten Engvoldsen <morten.engvoldsen@nokia.com>2010-09-07 08:56:37 (GMT)
commit12b26a5e2b61c1c2db52a5a25b2ca940227864df (patch)
treebb6dbaf4326cbd6b1dafe66ec29e46c536a1ac13 /tools
parentcbba0a1ea1e727cca4ca09c216e4f5a306083ba4 (diff)
parent201e4927f9e23150f460e711a2859dbff3e1353c (diff)
downloadQt-12b26a5e2b61c1c2db52a5a25b2ca940227864df.zip
Qt-12b26a5e2b61c1c2db52a5a25b2ca940227864df.tar.gz
Qt-12b26a5e2b61c1c2db52a5a25b2ca940227864df.tar.bz2
Merge branch '4.7' of git@scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.7
Diffstat (limited to 'tools')
-rw-r--r--tools/qml/deviceorientation.cpp5
-rw-r--r--tools/qml/deviceorientation.h3
-rw-r--r--tools/qml/deviceorientation_maemo5.cpp53
-rw-r--r--tools/qml/deviceorientation_symbian.cpp27
-rw-r--r--tools/qml/main.cpp3
-rw-r--r--tools/qml/qmlruntime.cpp2
6 files changed, 74 insertions, 19 deletions
diff --git a/tools/qml/deviceorientation.cpp b/tools/qml/deviceorientation.cpp
index e7c70d5..d3014ad 100644
--- a/tools/qml/deviceorientation.cpp
+++ b/tools/qml/deviceorientation.cpp
@@ -53,6 +53,11 @@ public:
return m_orientation;
}
+ void pauseListening() {
+ }
+ void resumeListening() {
+ }
+
void setOrientation(Orientation o) {
if (o != m_orientation) {
m_orientation = o;
diff --git a/tools/qml/deviceorientation.h b/tools/qml/deviceorientation.h
index 817bfc8..487ebd4 100644
--- a/tools/qml/deviceorientation.h
+++ b/tools/qml/deviceorientation.h
@@ -63,6 +63,9 @@ public:
virtual Orientation orientation() const = 0;
virtual void setOrientation(Orientation) = 0;
+ virtual void pauseListening() = 0;
+ virtual void resumeListening() = 0;
+
static DeviceOrientation *instance();
signals:
diff --git a/tools/qml/deviceorientation_maemo5.cpp b/tools/qml/deviceorientation_maemo5.cpp
index e942579..a324820 100644
--- a/tools/qml/deviceorientation_maemo5.cpp
+++ b/tools/qml/deviceorientation_maemo5.cpp
@@ -50,23 +50,9 @@ class MaemoOrientation : public DeviceOrientation
Q_OBJECT
public:
MaemoOrientation()
- : o(UnknownOrientation)
+ : o(UnknownOrientation), sensorEnabled(false)
{
- // enable the orientation sensor
- QDBusConnection::systemBus().call(
- QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH,
- MCE_REQUEST_IF, MCE_ACCELEROMETER_ENABLE_REQ));
-
- // query the initial orientation
- QDBusMessage reply = QDBusConnection::systemBus().call(
- QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH,
- MCE_REQUEST_IF, MCE_DEVICE_ORIENTATION_GET));
- if (reply.type() == QDBusMessage::ErrorMessage) {
- qWarning("Unable to retrieve device orientation: %s", qPrintable(reply.errorMessage()));
- } else {
- o = toOrientation(reply.arguments().value(0).toString());
- }
-
+ resumeListening();
// connect to the orientation change signal
QDBusConnection::systemBus().connect(QString(), MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
MCE_DEVICE_ORIENTATION_SIG,
@@ -91,6 +77,40 @@ public:
{
}
+ void pauseListening() {
+ if (sensorEnabled) {
+ // disable the orientation sensor
+ QDBusConnection::systemBus().call(
+ QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH,
+ MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ));
+ sensorEnabled = false;
+ }
+ }
+
+ void resumeListening() {
+ if (!sensorEnabled) {
+ // enable the orientation sensor
+ QDBusConnection::systemBus().call(
+ QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH,
+ MCE_REQUEST_IF, MCE_ACCELEROMETER_ENABLE_REQ));
+
+ QDBusMessage reply = QDBusConnection::systemBus().call(
+ QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH,
+ MCE_REQUEST_IF, MCE_DEVICE_ORIENTATION_GET));
+
+ if (reply.type() == QDBusMessage::ErrorMessage) {
+ qWarning("Unable to retrieve device orientation: %s", qPrintable(reply.errorMessage()));
+ } else {
+ Orientation orientation = toOrientation(reply.arguments().value(0).toString());
+ if (o != orientation) {
+ o = orientation;
+ emit orientationChanged();
+ }
+ sensorEnabled = true;
+ }
+ }
+ }
+
private Q_SLOTS:
void deviceOrientationChanged(const QString &newOrientation)
{
@@ -116,6 +136,7 @@ private:
private:
Orientation o;
+ bool sensorEnabled;
};
DeviceOrientation* DeviceOrientation::instance()
diff --git a/tools/qml/deviceorientation_symbian.cpp b/tools/qml/deviceorientation_symbian.cpp
index 307c417..7710cf9 100644
--- a/tools/qml/deviceorientation_symbian.cpp
+++ b/tools/qml/deviceorientation_symbian.cpp
@@ -52,7 +52,7 @@ class SymbianOrientation : public DeviceOrientation, public MSensrvDataListener
Q_OBJECT
public:
SymbianOrientation()
- : DeviceOrientation(), m_current(UnknownOrientation), m_sensorChannel(0)
+ : DeviceOrientation(), m_current(UnknownOrientation), m_sensorChannel(0), m_channelOpen(false)
{
TRAP_IGNORE(initL());
if (!m_sensorChannel)
@@ -84,6 +84,7 @@ public:
TRAP(error, m_sensorChannel->OpenChannelL());
if (!error) {
TRAP(error, m_sensorChannel->StartDataListeningL(this, 1, 1, 0));
+ m_channelOpen = true;
break;
}
if (error) {
@@ -107,6 +108,30 @@ public:
private:
DeviceOrientation::Orientation m_current;
CSensrvChannel *m_sensorChannel;
+ bool m_channelOpen;
+ void pauseListening() {
+ if (m_sensorChannel && m_channelOpen) {
+ m_sensorChannel->StopDataListening();
+ m_sensorChannel->CloseChannel();
+ m_channelOpen = false;
+ }
+ }
+
+ void resumeListening() {
+ if (m_sensorChannel && !m_channelOpen) {
+ TRAPD(error, m_sensorChannel->OpenChannelL());
+ if (!error) {
+ TRAP(error, m_sensorChannel->StartDataListeningL(this, 1, 1, 0));
+ if (!error) {
+ m_channelOpen = true;
+ }
+ }
+ if (error) {
+ delete m_sensorChannel;
+ m_sensorChannel = 0;
+ }
+ }
+ }
void DataReceived(CSensrvChannel &channel, TInt count, TInt dataLost)
{
diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp
index 7421b5e..78cd64d 100644
--- a/tools/qml/main.cpp
+++ b/tools/qml/main.cpp
@@ -441,6 +441,7 @@ static QDeclarativeViewer *createViewer()
QDeclarativeViewer *viewer = new QDeclarativeViewer(0, wflags);
viewer->setAttribute(Qt::WA_DeleteOnClose, true);
+ viewer->setUseGL(opts.useGL);
if (!opts.scriptopts.isEmpty()) {
viewer->setScriptOptions(opts.scriptOptions);
@@ -492,8 +493,6 @@ void showViewer(QDeclarativeViewer *viewer)
viewer->showMaximized();
else
viewer->show();
-
- viewer->setUseGL(opts.useGL);
viewer->raise();
}
diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp
index 321b7fd..b38e80d 100644
--- a/tools/qml/qmlruntime.cpp
+++ b/tools/qml/qmlruntime.cpp
@@ -1208,8 +1208,10 @@ bool QDeclarativeViewer::event(QEvent *event)
{
if (event->type() == QEvent::WindowActivate) {
Runtime::instance()->setActiveWindow(true);
+ DeviceOrientation::instance()->resumeListening();
} else if (event->type() == QEvent::WindowDeactivate) {
Runtime::instance()->setActiveWindow(false);
+ DeviceOrientation::instance()->pauseListening();
}
return QWidget::event(event);
}