From 935592db44d81c1d29ab24965f2e4a85af703a51 Mon Sep 17 00:00:00 2001 From: Jonni Rainisto Date: Thu, 13 Nov 2014 13:39:09 +0000 Subject: [PATCH] [nemo-qml-plugin-systemsettings] enablers for devicelock passcode age --- src/devicelockiface.cpp | 14 ++++++++------ src/devicelockiface.h | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/devicelockiface.cpp b/src/devicelockiface.cpp index 24faf9b..3b62996 100644 --- a/src/devicelockiface.cpp +++ b/src/devicelockiface.cpp @@ -35,26 +35,28 @@ #include #include "devicelockiface.h" -static bool runPlugin(QStringList args) +static int runPlugin(QStringList args) { QSettings s("/usr/share/lipstick/devicelock/devicelock.conf", QSettings::IniFormat); QString pluginName = s.value("DeviceLock/pluginName").toString(); if (pluginName.isEmpty()) { qWarning("DeviceLock: no plugin configuration set in /usr/share/lipstick/devicelock/devicelock.conf"); - return false; + return DeviceLockInterface::Failed; } QProcess p; p.start(pluginName, args); if (!p.waitForFinished()) { qWarning("DeviceLock: plugin did not finish in time"); - return false; + return DeviceLockInterface::Failed; } qDebug() << p.readAllStandardOutput(); qWarning() << p.readAllStandardError(); - return p.exitCode() == 0; + if (p.exitCode() == 0) return DeviceLockInterface::OK; + else if (p.exitCode() == 1) return DeviceLockInterface::Failed; + else return p.exitCode(); // special cases like Expired and InHistory } DeviceLockInterface::DeviceLockInterface(QObject *parent) @@ -67,12 +69,12 @@ DeviceLockInterface::~DeviceLockInterface() { } -bool DeviceLockInterface::checkCode(const QString &code) +int DeviceLockInterface::checkCode(const QString &code) { return runPlugin(QStringList() << "--check-code" << code); } -bool DeviceLockInterface::setCode(const QString &oldCode, const QString &newCode) +int DeviceLockInterface::setCode(const QString &oldCode, const QString &newCode) { bool return_value = runPlugin(QStringList() << "--set-code" << oldCode << newCode); if (return_value) { diff --git a/src/devicelockiface.h b/src/devicelockiface.h index 870bc35..617bfba 100644 --- a/src/devicelockiface.h +++ b/src/devicelockiface.h @@ -39,14 +39,25 @@ class DeviceLockInterface : public QObject { Q_OBJECT + Q_ENUMS(ReturnValue) Q_PROPERTY(bool isSet READ isSet NOTIFY isSetChanged) public: explicit DeviceLockInterface(QObject *parent = 0); virtual ~DeviceLockInterface(); - Q_INVOKABLE bool checkCode(const QString &code); - Q_INVOKABLE bool setCode(const QString &oldCode, const QString &newCode); + + /*!< note: encryption binary returns 0==OK and 1==Failed, switching is done in runPlugin for the QML */ + enum ReturnValue + { + Failed = 0, /*!< Failed - syscall returned with default error */ + OK, /*!< OK - syscall returned without errors */ + Expired, /*!< Expired - lockcode creation date is over the settings limit */ + InHistory /*!< InHistory - lockcode was found in history file. */ + }; + + Q_INVOKABLE int checkCode(const QString &code); + Q_INVOKABLE int setCode(const QString &oldCode, const QString &newCode); Q_INVOKABLE bool clearCode(const QString ¤tCode); Q_INVOKABLE bool isSet(); Q_INVOKABLE void refresh();