Skip to content

Commit

Permalink
Merge branch 'jb37067' into 'master'
Browse files Browse the repository at this point in the history
[devicelock] Fix watching of the latest save method for device lock settings. Fixes JB#37067

By alternating between two save files and renaming them the watched
file never actually changes when written to.  Instead it simply has
a different name at the end and another file has its name.

See merge request !5
  • Loading branch information
adenexter committed Nov 28, 2016
2 parents f8a95b7 + ddf2f56 commit 88342ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 44 deletions.
54 changes: 10 additions & 44 deletions src/lib/settingswatcher.cpp
Expand Up @@ -70,7 +70,12 @@ SettingsWatcher::SettingsWatcher(QObject *parent)
Q_ASSERT(!sharedInstance);
sharedInstance = this;

watchForSettingsFile();
m_watch = inotify_add_watch(
socket(),
"/usr/share/lipstick/devicelock",
IN_CREATE | IN_MOVED_TO | IN_MOVED_FROM | IN_CLOSE_WRITE | IN_DELETE);

reloadSettings();
}

SettingsWatcher::~SettingsWatcher()
Expand Down Expand Up @@ -103,23 +108,9 @@ bool SettingsWatcher::event(QEvent *event)
for (;at < end; at += sizeof(inotify_event) + pevent->len) {
pevent = reinterpret_cast<inotify_event *>(at);

if (pevent->wd != m_watch) {
continue;
} else if (pevent->mask & IN_CREATE) {
if (QFile::exists(m_settingsPath)) {
const auto watch = m_watch;

watchSettingsFile();

inotify_rm_watch(socket(), watch);
}
} else if (pevent->mask & IN_DELETE_SELF) {
const auto watch = m_watch;

watchForSettingsFile();

inotify_rm_watch(socket(), watch);
} else if (pevent->mask & IN_CLOSE_WRITE) {
if (pevent->wd == m_watch
&& pevent->len > 0
&& QLatin1String(pevent->name) == QLatin1String("devicelock_settings.conf")) {
reloadSettings();
}
}
Expand All @@ -130,31 +121,6 @@ bool SettingsWatcher::event(QEvent *event)
}
}

void SettingsWatcher::watchForSettingsFile()
{
if (QFile::exists(m_settingsPath)) {
watchSettingsFile();
} else {
m_watch = inotify_add_watch(
socket(),
m_settingsPath.mid(0, m_settingsPath.lastIndexOf(QLatin1Char('/'))).toUtf8().constData(),
IN_CREATE);
}

if (m_watch < 0) {
qWarning() << "Unable to follow devicelock configuration file changes";
}
}

void SettingsWatcher::watchSettingsFile()
{
m_watch = inotify_add_watch(
socket(),
m_settingsPath.toUtf8().constData(),
IN_CLOSE_WRITE | IN_DELETE_SELF);
reloadSettings();

}

template <typename T>
static void read(
Expand All @@ -175,7 +141,7 @@ static void read(

void SettingsWatcher::reloadSettings()
{
QSettings settings(QStringLiteral("/usr/share/lipstick/devicelock/devicelock_settings.conf"), QSettings::IniFormat);
QSettings settings(m_settingsPath, QSettings::IniFormat);

read(settings, this, automaticLockingKey, 10, &SettingsWatcher::automaticLocking, &SettingsWatcher::automaticLockingChanged);
read(settings, this, minimumLengthKey, 5, &SettingsWatcher::minimumLength, &SettingsWatcher::minimumLengthChanged);
Expand Down
6 changes: 6 additions & 0 deletions src/plugin/plugin.pro
Expand Up @@ -20,6 +20,12 @@ PKGCONFIG += \
INCLUDEPATH += $$PWD/../lib
LIBS += -L$$OUT_PWD/../lib -lnemodevicelock

DEPENDPATH += \
$$PWD/../lib

PRE_TARGETDEPS += \ \
$$PWD/../lib/libnemodevicelock.a

DEFINES += \
NEMO_DEVICE_LOCK_EMULATE_FINGER_SENSOR

Expand Down

0 comments on commit 88342ae

Please sign in to comment.