Skip to content

Commit

Permalink
[foilnotes] Made auto-lock configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
monich committed Feb 19, 2023
1 parent f5dc2b8 commit f8920be
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 18 deletions.
17 changes: 15 additions & 2 deletions qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ApplicationWindow {
property bool wasDimmed

onDisplayStatusChanged: {
if (target.displayStatus === HarbourSystemState.MCE_DISPLAY_DIM) {
if (HarbourSystemState.displayStatus === HarbourSystemState.MCE_DISPLAY_DIM) {
wasDimmed = true
} else if (target.displayStatus === HarbourSystemState.MCE_DISPLAY_ON) {
wasDimmed = false
Expand All @@ -69,7 +69,7 @@ ApplicationWindow {

onLockedChanged: {
lockTimer.stop()
if (target.locked) {
if (FoilNotesSettings.autoLock && HarbourSystemState.locked) {
if (wasDimmed) {
// Give the user some time to wake wake up the screen
// and prevent encrypted pictures from being locked
Expand All @@ -81,6 +81,19 @@ ApplicationWindow {
}
}

Connections {
target: FoilNotesSettings

onAutoLockChanged: {
lockTimer.stop()
// It's so unlikely that settings change when the device is locked
// But it's possible!
if (FoilNotesSettings.autoLock && HarbourSystemState.locked) {
FoilAuthModel.lock(false);
}
}
}

Component {
id: encryptedPageComponent

Expand Down
40 changes: 33 additions & 7 deletions src/FoilNotesSettings.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018-2021 Jolla Ltd.
* Copyright (C) 2018-2021 Slava Monich <[email protected]>
* Copyright (C) 2018-2023 Slava Monich <[email protected]>
*
* You may use this file under the terms of the BSD license as follows:
*
Expand Down Expand Up @@ -45,11 +45,13 @@
#define KEY_NEXT_COLOR_INDEX DCONF_KEY("nextColorIndex")
#define KEY_SHARED_KEY_WARNING DCONF_KEY("sharedKeyWarning")
#define KEY_SHARED_KEY_WARNING2 DCONF_KEY("sharedKeyWarning2")
#define KEY_AUTO_LOCK DCONF_KEY("autoLock")
#define KEY_AUTO_LOCK_TIME DCONF_KEY("autoLockTime")
#define KEY_PLAINTEXT_VIEW DCONF_KEY("plaintextView")

#define DEFAULT_NEXT_COLOR_INDEX 0
#define DEFAULT_SHARED_KEY_WARNING true
#define DEFAULT_AUTO_LOCK true
#define DEFAULT_AUTO_LOCK_TIME 15000
#define DEFAULT_PLAINTEXT_VIEW false

Expand All @@ -76,6 +78,7 @@ public Q_SLOTS:
MGConfItem* iNextColorIndex;
MGConfItem* iSharedKeyWarning;
MGConfItem* iSharedKeyWarning2;
MGConfItem* iAutoLock;
MGConfItem* iAutoLockTime;
MGConfItem* iPlainTextView;
const QStringList iDefaultColors;
Expand All @@ -98,6 +101,7 @@ FoilNotesSettings::Private::Private(QObject* aParent) :
iNextColorIndex(new MGConfItem(KEY_NEXT_COLOR_INDEX, aParent)),
iSharedKeyWarning(new MGConfItem(KEY_SHARED_KEY_WARNING, aParent)),
iSharedKeyWarning2(new MGConfItem(KEY_SHARED_KEY_WARNING2, aParent)),
iAutoLock(new MGConfItem(KEY_AUTO_LOCK, aParent)),
iAutoLockTime(new MGConfItem(KEY_AUTO_LOCK_TIME, aParent)),
iPlainTextView(new MGConfItem(KEY_PLAINTEXT_VIEW, aParent)),
iDefaultColors(defaultColors()),
Expand All @@ -112,14 +116,17 @@ FoilNotesSettings::Private::Private(QObject* aParent) :
aParent, SIGNAL(sharedKeyWarningChanged()));
QObject::connect(iSharedKeyWarning2, SIGNAL(valueChanged()),
aParent, SIGNAL(sharedKeyWarning2Changed()));
QObject::connect(iAutoLock, SIGNAL(valueChanged()),
aParent, SIGNAL(autoLockChanged()));
QObject::connect(iAutoLockTime, SIGNAL(valueChanged()),
aParent, SIGNAL(autoLockTimeChanged()));
QObject::connect(iPlainTextView, SIGNAL(valueChanged()),
aParent, SIGNAL(plaintextViewChanged()));
iAvailableColors = availableColors();
}

QStringList FoilNotesSettings::Private::defaultColors()
QStringList
FoilNotesSettings::Private::defaultColors()
{
QStringList colors;
const uint n = sizeof(gAvailableColors)/sizeof(gAvailableColors[0]);
Expand All @@ -130,12 +137,14 @@ QStringList FoilNotesSettings::Private::defaultColors()
return colors;
}

QStringList FoilNotesSettings::Private::availableColors() const
QStringList
FoilNotesSettings::Private::availableColors() const
{
return iAvailableColorsConf->value(iDefaultColors).toStringList();
}

void FoilNotesSettings::Private::onAvailableColorsChanged()
void
FoilNotesSettings::Private::onAvailableColorsChanged()
{
const QStringList newColors(availableColors());
if (iAvailableColors != newColors) {
Expand All @@ -162,8 +171,8 @@ FoilNotesSettings::~FoilNotesSettings()
// Callback for qmlRegisterSingletonType<FoilNotesSettings>
QObject*
FoilNotesSettings::createSingleton(
QQmlEngine* aEngine,
QJSEngine* aScript)
QQmlEngine*,
QJSEngine*)
{
return new FoilNotesSettings();
}
Expand All @@ -184,7 +193,8 @@ FoilNotesSettings::availableColors() const
}

void
FoilNotesSettings::setAvailableColors(QStringList aColors)
FoilNotesSettings::setAvailableColors(
QStringList aColors)
{
iPrivate->iAvailableColorsConf->set(aColors);
if (iPrivate->iAvailableColors != aColors) {
Expand Down Expand Up @@ -256,6 +266,22 @@ FoilNotesSettings::setSharedKeyWarning2(
iPrivate->iSharedKeyWarning2->set(aValue);
}

// autoLock

bool
FoilNotesSettings::autoLock() const
{
return iPrivate->iAutoLock->value(DEFAULT_AUTO_LOCK).toBool();
}

void
FoilNotesSettings::setAutoLock(
bool aValue)
{
HDEBUG(aValue);
iPrivate->iAutoLock->set(aValue);
}

// autoLockTime

int
Expand Down
24 changes: 15 additions & 9 deletions src/FoilNotesSettings.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018-2021 Jolla Ltd.
* Copyright (C) 2018-2021 Slava Monich <[email protected]>
* Copyright (C) 2018-2023 Slava Monich <[email protected]>
*
* You may use this file under the terms of the BSD license as follows:
*
Expand Down Expand Up @@ -40,13 +40,15 @@
class QQmlEngine;
class QJSEngine;

class FoilNotesSettings : public QObject {
class FoilNotesSettings : public QObject
{
Q_OBJECT
Q_PROPERTY(QStringList defaultColors READ defaultColors CONSTANT)
Q_PROPERTY(QStringList availableColors READ availableColors WRITE setAvailableColors NOTIFY availableColorsChanged)
Q_PROPERTY(int nextColorIndex READ nextColorIndex WRITE setNextColorIndex NOTIFY nextColorIndexChanged)
Q_PROPERTY(bool sharedKeyWarning READ sharedKeyWarning WRITE setSharedKeyWarning NOTIFY sharedKeyWarningChanged)
Q_PROPERTY(bool sharedKeyWarning2 READ sharedKeyWarning2 WRITE setSharedKeyWarning2 NOTIFY sharedKeyWarning2Changed)
Q_PROPERTY(bool autoLock READ autoLock WRITE setAutoLock NOTIFY autoLockChanged)
Q_PROPERTY(int autoLockTime READ autoLockTime WRITE setAutoLockTime NOTIFY autoLockTimeChanged)
Q_PROPERTY(bool plaintextView READ plaintextView WRITE setPlaintextView NOTIFY plaintextViewChanged)

Expand All @@ -55,25 +57,28 @@ class FoilNotesSettings : public QObject {
~FoilNotesSettings();

// Callback for qmlRegisterSingletonType<FoilNotesSettings>
static QObject* createSingleton(QQmlEngine* aEngine, QJSEngine* aScript);
static QObject* createSingleton(QQmlEngine*, QJSEngine*);

const QStringList defaultColors() const;
QStringList availableColors() const;
void setAvailableColors(QStringList aColors);
void setAvailableColors(QStringList);

int nextColorIndex() const;
void setNextColorIndex(int aValue);
void setNextColorIndex(int);

bool sharedKeyWarning() const;
bool sharedKeyWarning2() const;
void setSharedKeyWarning(bool aValue);
void setSharedKeyWarning2(bool aValue);
void setSharedKeyWarning(bool);
void setSharedKeyWarning2(bool);

bool autoLock() const;
void setAutoLock(bool);

int autoLockTime() const;
void setAutoLockTime(int aValue);
void setAutoLockTime(int);

bool plaintextView() const;
void setPlaintextView(bool aValue);
void setPlaintextView(bool);

Q_INVOKABLE int pickColorIndex();
Q_INVOKABLE QColor pickColor();
Expand All @@ -83,6 +88,7 @@ class FoilNotesSettings : public QObject {
void nextColorIndexChanged();
void sharedKeyWarningChanged();
void sharedKeyWarning2Changed();
void autoLockChanged();
void autoLockTimeChanged();
void plaintextViewChanged();

Expand Down

0 comments on commit f8920be

Please sign in to comment.