Skip to content

Commit

Permalink
[displaysettings] Handle MCE settings asynchronously. Fixes JB#34813
Browse files Browse the repository at this point in the history
Each instantiation of display settings object blocks until it can finish
13 sequential blocking method calls to get current values of mce settings.

Use expected-by-default values in constructor, then update to currently
used values via a single asynchronous get_config_all mce dbus method call.

The com.nokia.mce.request.get_config_all is available in mce >= 1.83.0.
  • Loading branch information
spiiroin committed Nov 10, 2016
1 parent f834484 commit 40284e6
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 60 deletions.
1 change: 1 addition & 0 deletions rpm/nemo-qml-plugin-systemsettings.spec
Expand Up @@ -12,6 +12,7 @@ Requires: connman
Requires: openvpn
Requires: openconnect
Requires: vpnc
Requires: mce >= 1.83.0
BuildRequires: pkgconfig(Qt5Qml)
BuildRequires: pkgconfig(Qt5SystemInfo)
BuildRequires: pkgconfig(Qt5Test)
Expand Down
116 changes: 56 additions & 60 deletions src/displaysettings.cpp
Expand Up @@ -55,57 +55,48 @@ DisplaySettings::DisplaySettings(QObject *parent)
m_orientationLock = new MGConfItem("/lipstick/orientationLock", this);
connect(m_orientationLock, SIGNAL(valueChanged()), SIGNAL(orientationLockChanged()));

m_mceIface = new ComNokiaMceRequestInterface(MCE_SERVICE, MCE_REQUEST_PATH, QDBusConnection::systemBus(), this);
QDBusPendingReply<QDBusVariant> result = m_mceIface->get_config(QDBusObjectPath(MceDisplayBrightness));
result.waitForFinished();
m_brightness = result.value().variant().toInt();

result = m_mceIface->get_config(QDBusObjectPath(MceDisplayDimTimeout));
result.waitForFinished();
m_dimTimeout = result.value().variant().toInt();

result = m_mceIface->get_config(QDBusObjectPath(MceDisplayBlankTimeout));
result.waitForFinished();
m_blankTimeout = result.value().variant().toInt();

result = m_mceIface->get_config(QDBusObjectPath(MceDisplayInhibitMode));
result.waitForFinished();
m_inhibitMode = static_cast<InhibitMode>(result.value().variant().toInt());

result = m_mceIface->get_config(QDBusObjectPath(MceDisplayUseAdaptiveDimming));
result.waitForFinished();
m_adaptiveDimmingEnabled = result.value().variant().toBool();

result = m_mceIface->get_config(QDBusObjectPath(MceDisplayUseLowPowerMode));
result.waitForFinished();
m_lowPowerModeEnabled = result.value().variant().toBool();

result = m_mceIface->get_config(QDBusObjectPath(MceDisplayUseAmbientLightSensor));
result.waitForFinished();
m_ambientLightSensorEnabled = result.value().variant().toBool();

result = m_mceIface->get_config(QDBusObjectPath(MceDisplayAutoBrightnessEnabled));
result.waitForFinished();
m_autoBrightnessEnabled = result.value().variant().toBool();

result = m_mceIface->get_config(QDBusObjectPath(MceDoubleTapMode));
result.waitForFinished();
m_doubleTapMode = result.value().variant().toInt();

result = m_mceIface->get_config(QDBusObjectPath(MceLidSensorEnabled));
result.waitForFinished();
m_lidSensorEnabled = result.value().variant().toBool();
/* Initialize to defaults */
m_autoBrightnessEnabled = true;
m_ambientLightSensorEnabled = true;
m_blankTimeout = 3;
m_brightness = 60;
m_dimTimeout = 30;
m_flipoverGestureEnabled = true;
m_inhibitMode = InhibitOff;
m_adaptiveDimmingEnabled = true;
m_lowPowerModeEnabled = false;
m_doubleTapMode = true;
m_lidSensorFilteringEnabled = true;
m_lidSensorEnabled = true;

/* Setup change listener & get current values via async query */
m_mceSignalIface = new ComNokiaMceSignalInterface(MCE_SERVICE, MCE_SIGNAL_PATH, QDBusConnection::systemBus(), this);
connect(m_mceSignalIface, SIGNAL(config_change_ind(QString,QDBusVariant)), this, SLOT(configChange(QString,QDBusVariant)));

result = m_mceIface->get_config(QDBusObjectPath(MceLidSensorFilteringEnabled));
result.waitForFinished();
m_lidSensorFilteringEnabled = result.value().variant().toBool();
m_mceIface = new ComNokiaMceRequestInterface(MCE_SERVICE, MCE_REQUEST_PATH, QDBusConnection::systemBus(), this);
QDBusPendingReply<QVariantMap> call = m_mceIface->get_config_all();
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher *)),
this, SLOT(configReply(QDBusPendingCallWatcher *)));
}

result = m_mceIface->get_config(QDBusObjectPath(MceFlipOverGestureEnabled));
result.waitForFinished();
m_flipoverGestureEnabled = result.value().variant().toBool();
void DisplaySettings::configReply(QDBusPendingCallWatcher *watcher)
{
QDBusPendingReply<QVariantMap> reply = *watcher;

if (reply.isError()) {
qWarning("Could not retrieve mce settings: '%s'",
reply.error().message().toStdString().c_str());
} else {
QVariantMap map = reply.value();
QMapIterator<QString, QVariant> i(map);
while (i.hasNext()) {
i.next();
updateConfig(i.key(), i.value());
}
}

m_mceSignalIface = new ComNokiaMceSignalInterface(MCE_SERVICE, MCE_SIGNAL_PATH, QDBusConnection::systemBus(), this);
connect(m_mceSignalIface, SIGNAL(config_change_ind(QString,QDBusVariant)), this, SLOT(configChange(QString,QDBusVariant)));
watcher->deleteLater();
}

int DisplaySettings::brightness() const
Expand Down Expand Up @@ -294,75 +285,80 @@ void DisplaySettings::setFlipoverGestureEnabled(bool enabled)
}

void DisplaySettings::configChange(const QString &key, const QDBusVariant &value)
{
updateConfig(key, value.variant());
}

void DisplaySettings::updateConfig(const QString &key, const QVariant &value)
{
if (key == MceDisplayBrightness) {
int val = value.variant().toInt();
int val = value.toInt();
if (val != m_brightness) {
m_brightness = val;
emit brightnessChanged();
}
} else if (key == MceDisplayDimTimeout) {
int val = value.variant().toInt();
int val = value.toInt();
if (val != m_dimTimeout) {
m_dimTimeout = val;
emit dimTimeoutChanged();
}
} else if (key == MceDisplayBlankTimeout) {
int val = value.variant().toInt();
int val = value.toInt();
if (val != m_blankTimeout) {
m_blankTimeout = val;
emit blankTimeoutChanged();
}
} else if (key == MceDisplayInhibitMode) {
InhibitMode val = static_cast<InhibitMode>(value.variant().toInt());
InhibitMode val = static_cast<InhibitMode>(value.toInt());
if (val != m_inhibitMode) {
m_inhibitMode = val;
emit inhibitModeChanged();
}
} else if (key == MceDisplayUseAdaptiveDimming) {
bool val = value.variant().toBool();
bool val = value.toBool();
if (val != m_adaptiveDimmingEnabled) {
m_adaptiveDimmingEnabled = val;
emit adaptiveDimmingEnabledChanged();
}
} else if (key == MceDisplayUseLowPowerMode) {
bool val = value.variant().toBool();
bool val = value.toBool();
if (val != m_lowPowerModeEnabled) {
m_lowPowerModeEnabled = val;
emit lowPowerModeEnabledChanged();
}
} else if (key == MceDisplayUseAmbientLightSensor) {
bool val = value.variant().toBool();
bool val = value.toBool();
if (val != m_ambientLightSensorEnabled) {
m_ambientLightSensorEnabled = val;
emit ambientLightSensorEnabledChanged();
}
} else if (key == MceDisplayAutoBrightnessEnabled) {
bool val = value.variant().toBool();
bool val = value.toBool();
if (val != m_autoBrightnessEnabled) {
m_autoBrightnessEnabled = val;
emit autoBrightnessEnabledChanged();
}
} else if (key == MceDoubleTapMode) {
int val = value.variant().toInt();
int val = value.toInt();
if (val != m_doubleTapMode) {
m_doubleTapMode = val;
emit doubleTapModeChanged();
}
} else if (key == MceLidSensorEnabled) {
bool val = value.variant().toBool();
bool val = value.toBool();
if (val != m_lidSensorEnabled) {
m_lidSensorEnabled = val;
emit lidSensorEnabledChanged();
}
} else if (key == MceLidSensorFilteringEnabled) {
bool val = value.variant().toBool();
bool val = value.toBool();
if (val != m_lidSensorFilteringEnabled) {
m_lidSensorFilteringEnabled = val;
emit lidSensorFilteringEnabledChanged();
}
} else if (key == MceFlipOverGestureEnabled) {
bool val = value.variant().toBool();
bool val = value.toBool();
if (val != m_flipoverGestureEnabled) {
m_flipoverGestureEnabled = val;
emit flipoverGestureEnabledChanged();
Expand Down
4 changes: 4 additions & 0 deletions src/displaysettings.h
Expand Up @@ -34,6 +34,7 @@

#include <QObject>
#include <QtQml>
#include <QDBusPendingCallWatcher>

class ComNokiaMceRequestInterface;
class ComNokiaMceSignalInterface;
Expand Down Expand Up @@ -143,8 +144,11 @@ class SYSTEMSETTINGS_EXPORT DisplaySettings: public QObject

private slots:
void configChange(const QString &key, const QDBusVariant &value);
void configReply(QDBusPendingCallWatcher *watcher);


private:
void updateConfig(const QString &key, const QVariant &value);
ComNokiaMceRequestInterface *m_mceIface;
ComNokiaMceSignalInterface *m_mceSignalIface;
MGConfItem *m_orientationLock;
Expand Down
4 changes: 4 additions & 0 deletions src/mce.xml
Expand Up @@ -18,6 +18,10 @@
<arg name="value" direction="in" type="v"/>
<arg direction="out" type="b"/>
</method>
<method name="get_config_all">
<arg direction="out" name="values" type="a{sv}"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
</method>
</interface>
<interface name="com.nokia.mce.signal">
<signal name="radio_states_ind">
Expand Down

0 comments on commit 40284e6

Please sign in to comment.