Disable SailfishOS app cover animation when cover is not visible
#include <QDBusConnection> | |
#include "myclass.h" | |
myclass::myclass(QObject *parent) : | |
QObject(parent), | |
m_coverStatus(0), | |
m_displayStatus("on"), | |
m_deviceLock(0), | |
m_coverVisible(false) | |
{ | |
QDBusConnection::sessionBus().connect("", "/com/jolla/lipstick", "com.jolla.lipstick", "coverstatus", | |
this, SLOT(handleCoverstatus(const QDBusMessage&))); | |
QDBusConnection::systemBus().connect("", "/com/nokia/mce/signal", "com.nokia.mce.signal", "display_status_ind", | |
this, SLOT(handleDisplaystatus(const QDBusMessage&))); | |
QDBusConnection::systemBus().connect("", "/devicelock", "org.nemomobile.lipstick.devicelock", "stateChanged", | |
this, SLOT(handleDeviceLockChange(const QDBusMessage&))); | |
} | |
void myclass::handleCoverstatus(const QDBusMessage& msg) | |
{ | |
QList<QVariant> args = msg.arguments(); | |
m_coverStatus = args.at(0).toInt(); | |
emit coverStatusChanged(); | |
this->handleCovervisible(); | |
} | |
void myclass::handleDisplaystatus(const QDBusMessage& msg) | |
{ | |
QList<QVariant> args = msg.arguments(); | |
m_displayStatus = args.at(0).toString(); | |
emit displayStatusChanged(); | |
this->handleCovervisible(); | |
} | |
void SystemStatus::handleDevicelock(const QDBusMessage& msg) | |
{ | |
QList<QVariant> args = msg.arguments(); | |
m_deviceLock = args.at(0).toInt(); | |
emit deviceLockChanged(); | |
this->handleCovervisible(); | |
} | |
void SystemStatus::handleCovervisible() { | |
bool newCoverVisible = m_coverStatus != 0 && m_displayStatus != "off" && m_deviceLock == 0; | |
if (newCoverVisible != m_coverVisible) { | |
m_coverVisible = newCoverVisible; | |
emit coverVisibleChanged(); | |
} | |
} |
#ifndef MYCLASS_H | |
#define MYCLASS_H | |
#include <QDBusMessage> | |
class myclass : public QObject | |
{ | |
Q_OBJECT | |
public: | |
Q_PROPERTY(int coverStatus READ getCoverStatus NOTIFY coverStatusChanged()) | |
Q_PROPERTY(QString displayStatus READ getDisplayStatus NOTIFY displayStatusChanged()) | |
Q_PROPERTY(int deviceLock READ getDeviceLock NOTIFY deviceLockChanged()) | |
Q_PROPERTY(bool coverVisible READ getCoverVisible NOTIFY coverVisibleChanged()) | |
explicit myclass(QObject *parent = 0); | |
public: | |
int getCoverStatus() { return m_coverStatus; } | |
QString getDisplayStatus() { return m_displayStatus; } | |
int getDeviceLock() { return m_deviceLock; } | |
bool getCoverVisible() { return m_coverVisible; } | |
public slots: | |
void handleCoverstatus(const QDBusMessage& msg); | |
void handleDisplaystatus(const QDBusMessage& msg); | |
void handleDevicelock(const QDBusMessage& msg); | |
private: | |
void handleCovervisible(); | |
signals: | |
void coverStatusChanged(); | |
void displayStatusChanged(); | |
void deviceLockChanged(); | |
void coverVisibleChanged(); | |
private: | |
int m_coverStatus; | |
QString m_displayStatus; | |
int m_deviceLock; | |
bool m_coverVisible; | |
}; | |
#endif // MYCLASS_H |
QT += dbus |
BuildRequires: pkgconfig(Qt5DBus) | |
# ... or in yourapp.yaml: | |
# | |
# PkgConfigBR: | |
# ... | |
# - Qt5DBus |
... | |
import harbour.myapp.myclass 1.0 | |
... | |
myclass { | |
id: myclass | |
} | |
Timer | |
{ | |
id: coverRefreshTimer | |
interval: 500 | |
running: myclass.coverVisible // timer only active when cover is visible | |
repeat: true | |
onTriggered: updateCover() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
coverStatus
displayStatus
deviceLock
coverVisible
- combination of the above properties -coverStatus != 0 && displayStatus != "off" && deviceLock == 0