diff options
author | Thomas McGuire <thomas.mcguire.qnx@kdab.com> | 2012-07-24 16:47:29 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-25 15:04:41 +0200 |
commit | c7fd6aeefc60a9ac81b0e4565f2bdea8c5c66512 (patch) | |
tree | 750ee2fd18771096ca91408c333a8a9bf2a27757 /src/plugins/sensors/blackberry/bbguihelper.cpp | |
parent | 4c7c6511513ade8a6e3a26dbbc095bef8bbbe68a (diff) |
Blackberry: Improve detecting whether the application is active
Previously, we simply assumed to be active. Now, we read the state
from the navigator PPS file instead.
Also move reading of the orientation into its own function for
consistency.
Change-Id: Icc1789bd942e8fa5a9d5451de4c2ab9f3ffb54e4
Reviewed-by: Lorn Potter <lorn.potter@nokia.com>
Reviewed-by: Kevin Ottens <kevin.ottens.qnx@kdab.com>
Diffstat (limited to 'src/plugins/sensors/blackberry/bbguihelper.cpp')
-rw-r--r-- | src/plugins/sensors/blackberry/bbguihelper.cpp | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/src/plugins/sensors/blackberry/bbguihelper.cpp b/src/plugins/sensors/blackberry/bbguihelper.cpp index b074901c..99260473 100644 --- a/src/plugins/sensors/blackberry/bbguihelper.cpp +++ b/src/plugins/sensors/blackberry/bbguihelper.cpp @@ -42,6 +42,8 @@ #include <QtCore/QAbstractEventDispatcher> #include <QtCore/QCoreApplication> +#include <QtCore/QFile> +#include <QtCore/QTextStream> #include <bps/navigator.h> BbGuiHelper::BbGuiHelper(QObject *parent) @@ -49,14 +51,8 @@ BbGuiHelper::BbGuiHelper(QObject *parent) m_currentOrientation(0), m_applicationActive(true) { - // There is no API to get the current orientation or application active state at the moment. - // Therefore, we assume the application is active when this is called, and that the inital - // orientation that is set in the environment variable hasn't changed yet. - // These assumptions don't always hold, but it is the best we got so far. - // The navigator will at least inform us about updates. - const QByteArray orientationText = qgetenv("ORIENTATION"); - if (!orientationText.isEmpty()) - m_currentOrientation = orientationText.toInt(); + readApplicationActiveState(); + readOrientation(); QCoreApplication::eventDispatcher()->installNativeEventFilter(this); } @@ -102,3 +98,45 @@ bool BbGuiHelper::nativeEventFilter(const QByteArray &eventType, void *message, return false; } + +void BbGuiHelper::readApplicationActiveState() +{ + const QLatin1String fileName("/pps/services/navigator/state"); + QFile navigatorState(fileName); + if (!navigatorState.open(QFile::ReadOnly)) + return; + + const QString separator(QLatin1String("::")); + QTextStream stream(&navigatorState); + Q_FOREVER { + const QString line = stream.readLine(); + if (line.isNull()) + break; + + const int separatorPos = line.indexOf(separator); + if (separatorPos != -1) { + const QString key = line.left(separatorPos); + const QString value = line.mid(separatorPos + separator.length()); + + if (key.endsWith(QLatin1String("fullscreen"))) { + bool ok = false; + const int fullscreenPid = value.toInt(&ok); + if (ok) + m_applicationActive = (fullscreenPid == QCoreApplication::applicationPid()); + break; + } + } + } +} + +void BbGuiHelper::readOrientation() +{ + // There is no API to get the current orientation at the moment. + // Therefore, we assume that the inital orientation that is set in the environment variable + // hasn't changed yet. + // This assumptions don't always hold, but it is the best we got so far. + // The navigator will at least inform us about updates. + const QByteArray orientationText = qgetenv("ORIENTATION"); + if (!orientationText.isEmpty()) + m_currentOrientation = orientationText.toInt(); +} |