From 2a60a0723257cfd6855233b9af27dc9735915435 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 22 Sep 2017 10:23:44 +0200 Subject: Keyring fixes * Avoid double free * track unlocked state * Ensure we bring up the login screen on startup and after saving the configuration. --- framework/src/frameworkplugin.cpp | 4 +++- framework/src/keyring.cpp | 16 +++++++++++++++- framework/src/keyring.h | 4 ++++ 3 files changed, 22 insertions(+), 2 deletions(-) (limited to 'framework/src') diff --git a/framework/src/frameworkplugin.cpp b/framework/src/frameworkplugin.cpp index 1e1a169e..c4f7e85d 100644 --- a/framework/src/frameworkplugin.cpp +++ b/framework/src/frameworkplugin.cpp @@ -60,7 +60,9 @@ static QObject *keyring_singletontype_provider(QQmlEngine *engine, QJSEngine *sc { Q_UNUSED(engine) Q_UNUSED(scriptEngine) - return new Kube::Keyring; + auto instance = Kube::Keyring::instance(); + QQmlEngine::setObjectOwnership(instance, QQmlEngine::CppOwnership); + return instance; } void FrameworkPlugin::registerTypes (const char *uri) diff --git a/framework/src/keyring.cpp b/framework/src/keyring.cpp index e3fdb1cb..7bd406c0 100644 --- a/framework/src/keyring.cpp +++ b/framework/src/keyring.cpp @@ -20,18 +20,31 @@ #include #include +#include using namespace Kube; +Q_GLOBAL_STATIC(Keyring, sKeyring); + Keyring::Keyring() : QObject() { } +Keyring *Keyring::instance() +{ + return sKeyring; +} + bool Keyring::isUnlocked(const QByteArray &accountId) { - return false; + return mUnlocked.contains(accountId); +} + +void Keyring::unlock(const QByteArray &accountId) +{ + mUnlocked.insert(accountId); } AccountKeyring::AccountKeyring(const QByteArray &accountId, QObject *parent) @@ -45,6 +58,7 @@ void AccountKeyring::storePassword(const QByteArray &resourceId, const QString & QSettings settings{mAccountIdentifier + ".keyring", QSettings::IniFormat}; settings.setValue(resourceId, password); Sink::SecretStore::instance().insert(resourceId, password); + Keyring::instance()->unlock(mAccountIdentifier); } void AccountKeyring::unlock() diff --git a/framework/src/keyring.h b/framework/src/keyring.h index ce4e137d..df25dbff 100644 --- a/framework/src/keyring.h +++ b/framework/src/keyring.h @@ -18,6 +18,7 @@ */ #include +#include namespace Kube { @@ -25,10 +26,13 @@ class Keyring : public QObject { Q_OBJECT public: Keyring(); + static Keyring *instance(); Q_INVOKABLE bool isUnlocked(const QByteArray &accountId); + void unlock(const QByteArray &accountId); private: Q_DISABLE_COPY(Keyring); + QSet mUnlocked; }; class AccountKeyring : public QObject { -- cgit v1.2.3