Skip to content

Commit

Permalink
Actualize dynamic icons on unlock
Browse files Browse the repository at this point in the history
Dynamic icons may become out of date after a long period of device
inactivity, so it's better to force update them after unlock.
  • Loading branch information
dseight committed Aug 30, 2020
1 parent 6c574a2 commit e2dd24b
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
3 changes: 3 additions & 0 deletions dynamic-icons/calendar.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "devicelockstatus.h"
#include "dynamicicon.h"
#include "iconpack.h"
#include "iconpackfactory.h"
Expand Down Expand Up @@ -99,6 +100,7 @@ class CalendarIconProvider : public IconProvider
connect(&m_currentIconPackConf, &MGConfItem::valueChanged,
this, &IconProvider::imageUpdated);
connect(&m_timer, &QTimer::timeout, this, &IconProvider::imageUpdated);
connect(&m_devicelockStatus, &DevicelockStatus::unlocked, this, &IconProvider::imageUpdated);

// Update icon each hour
m_timer.start(60 * 60 * 1000);
Expand All @@ -124,6 +126,7 @@ private slots:

private:
QTimer m_timer;
DevicelockStatus m_devicelockStatus;
MGConfItem m_currentIconPackConf;
QScopedPointer<CalendarIconRenderer> m_renderer;
};
Expand Down
3 changes: 3 additions & 0 deletions dynamic-icons/clock.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "devicelockstatus.h"
#include "dynamicicon.h"
#include "iconpack.h"
#include "iconpackfactory.h"
Expand Down Expand Up @@ -136,6 +137,7 @@ class ClockIconProvider : public IconProvider
connect(&m_currentIconPackConf, &MGConfItem::valueChanged,
this, &IconProvider::imageUpdated);
connect(&m_timer, &QTimer::timeout, this, &IconProvider::imageUpdated);
connect(&m_devicelockStatus, &DevicelockStatus::unlocked, this, &IconProvider::imageUpdated);

// Update icon each minute
// TODO: use timed as source of update events, look at
Expand Down Expand Up @@ -175,6 +177,7 @@ private slots:

private:
QTimer m_timer;
DevicelockStatus m_devicelockStatus;
MGConfItem m_currentIconPackConf;
QScopedPointer<ClockIconRenderer> m_renderer;
};
Expand Down
22 changes: 22 additions & 0 deletions dynamic-icons/devicelockstatus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "devicelockstatus.h"
#include <QDebug>

DevicelockStatus::DevicelockStatus(QObject *parent)
: QObject(parent)
, m_mceInterface("com.nokia.mce",
"/com/nokia/mce/signal",
"com.nokia.mce.signal",
QDBusConnection::systemBus())
{
connect(&m_mceInterface, SIGNAL(tklock_mode_ind(QString)),
this, SLOT(tklockModeChanged(QString)));
}

void DevicelockStatus::tklockModeChanged(const QString &mode)
{
if (mode == QStringLiteral("unlocked")) {
emit unlocked();
} else if (mode == QStringLiteral("locked")) {
emit locked();
}
}
24 changes: 24 additions & 0 deletions dynamic-icons/devicelockstatus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef DEVICELOCKSTATUS_H
#define DEVICELOCKSTATUS_H

#include <QDBusInterface>

class DevicelockStatus : public QObject
{
Q_OBJECT

public:
explicit DevicelockStatus(QObject *parent = nullptr);

signals:
void unlocked();
void locked();

private slots:
void tklockModeChanged(const QString &mode);

private:
QDBusInterface m_mceInterface;
};

#endif // DEVICELOCKSTATUS_H
8 changes: 7 additions & 1 deletion dynamic-icons/dynamic-icons.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
TEMPLATE = lib
TARGET = default-dynamic-icons

QT += dbus

CONFIG += c++14
CONFIG += plugin
CONFIG += no_plugin_name_prefix
Expand All @@ -15,7 +17,11 @@ DEFINES += ASSETS_PATH=\\\"$${ASSETS_PATH}\\\"

SOURCES += \
calendar.cpp \
clock.cpp
clock.cpp \
devicelockstatus.cpp

HEADERS += \
devicelockstatus.h

target.path = /usr/share/clockwork/dynamic-icons

Expand Down

0 comments on commit e2dd24b

Please sign in to comment.