diff options
-rw-r--r-- | components/kube/contents/ui/Kube.qml | 17 | ||||
-rw-r--r-- | framework/src/frameworkplugin.cpp | 4 | ||||
-rw-r--r-- | framework/src/keyring.cpp | 16 | ||||
-rw-r--r-- | framework/src/keyring.h | 4 |
4 files changed, 32 insertions, 9 deletions
diff --git a/components/kube/contents/ui/Kube.qml b/components/kube/contents/ui/Kube.qml index 603a499f..7625c52c 100644 --- a/components/kube/contents/ui/Kube.qml +++ b/components/kube/contents/ui/Kube.qml | |||
@@ -47,8 +47,11 @@ Controls2.ApplicationWindow { | |||
47 | property variant currentAccount | 47 | property variant currentAccount |
48 | onCurrentAccountChanged: { | 48 | onCurrentAccountChanged: { |
49 | if (!!currentAccount) { | 49 | if (!!currentAccount) { |
50 | console.warn("Syncing account", currentAccount) | 50 | if (kubeViews.currentItem && !Kube.Keyring.isUnlocked(currentAccount)) { |
51 | Kube.Fabric.postMessage(Kube.Messages.synchronize, {"accountId": currentAccount}) | 51 | kubeViews.setLoginView() |
52 | } else { | ||
53 | Kube.Fabric.postMessage(Kube.Messages.synchronize, {"accountId": currentAccount}) | ||
54 | } | ||
52 | } | 55 | } |
53 | } | 56 | } |
54 | 57 | ||
@@ -282,7 +285,9 @@ Controls2.ApplicationWindow { | |||
282 | } | 285 | } |
283 | 286 | ||
284 | function setLoginView() { | 287 | function setLoginView() { |
285 | pushView(loginView, {accountId: currentAccount}) | 288 | if (currentItem != loginView) { |
289 | pushView(loginView, {accountId: currentAccount}) | ||
290 | } | ||
286 | } | 291 | } |
287 | 292 | ||
288 | function openComposer(newMessage, recipients) { | 293 | function openComposer(newMessage, recipients) { |
@@ -301,11 +306,9 @@ Controls2.ApplicationWindow { | |||
301 | 306 | ||
302 | Component.onCompleted: { | 307 | Component.onCompleted: { |
303 | if (!currentItem) { | 308 | if (!currentItem) { |
304 | if (!Kube.Keyring.isUnlocked(app.currentAccount)) { | 309 | setMailView(); |
305 | setMailView(); | 310 | if (!!app.currentAccount && !Kube.Keyring.isUnlocked(app.currentAccount)) { |
306 | setLoginView() | 311 | setLoginView() |
307 | } else { | ||
308 | setMailView(); | ||
309 | } | 312 | } |
310 | } | 313 | } |
311 | } | 314 | } |
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 | |||
60 | { | 60 | { |
61 | Q_UNUSED(engine) | 61 | Q_UNUSED(engine) |
62 | Q_UNUSED(scriptEngine) | 62 | Q_UNUSED(scriptEngine) |
63 | return new Kube::Keyring; | 63 | auto instance = Kube::Keyring::instance(); |
64 | QQmlEngine::setObjectOwnership(instance, QQmlEngine::CppOwnership); | ||
65 | return instance; | ||
64 | } | 66 | } |
65 | 67 | ||
66 | void FrameworkPlugin::registerTypes (const char *uri) | 68 | 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 @@ | |||
20 | 20 | ||
21 | #include <sink/secretstore.h> | 21 | #include <sink/secretstore.h> |
22 | #include <QSettings> | 22 | #include <QSettings> |
23 | #include <QtGlobal> | ||
23 | 24 | ||
24 | using namespace Kube; | 25 | using namespace Kube; |
25 | 26 | ||
27 | Q_GLOBAL_STATIC(Keyring, sKeyring); | ||
28 | |||
26 | Keyring::Keyring() | 29 | Keyring::Keyring() |
27 | : QObject() | 30 | : QObject() |
28 | { | 31 | { |
29 | 32 | ||
30 | } | 33 | } |
31 | 34 | ||
35 | Keyring *Keyring::instance() | ||
36 | { | ||
37 | return sKeyring; | ||
38 | } | ||
39 | |||
32 | bool Keyring::isUnlocked(const QByteArray &accountId) | 40 | bool Keyring::isUnlocked(const QByteArray &accountId) |
33 | { | 41 | { |
34 | return false; | 42 | return mUnlocked.contains(accountId); |
43 | } | ||
44 | |||
45 | void Keyring::unlock(const QByteArray &accountId) | ||
46 | { | ||
47 | mUnlocked.insert(accountId); | ||
35 | } | 48 | } |
36 | 49 | ||
37 | AccountKeyring::AccountKeyring(const QByteArray &accountId, QObject *parent) | 50 | AccountKeyring::AccountKeyring(const QByteArray &accountId, QObject *parent) |
@@ -45,6 +58,7 @@ void AccountKeyring::storePassword(const QByteArray &resourceId, const QString & | |||
45 | QSettings settings{mAccountIdentifier + ".keyring", QSettings::IniFormat}; | 58 | QSettings settings{mAccountIdentifier + ".keyring", QSettings::IniFormat}; |
46 | settings.setValue(resourceId, password); | 59 | settings.setValue(resourceId, password); |
47 | Sink::SecretStore::instance().insert(resourceId, password); | 60 | Sink::SecretStore::instance().insert(resourceId, password); |
61 | Keyring::instance()->unlock(mAccountIdentifier); | ||
48 | } | 62 | } |
49 | 63 | ||
50 | void AccountKeyring::unlock() | 64 | 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 @@ | |||
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <QObject> | 20 | #include <QObject> |
21 | #include <QSet> | ||
21 | 22 | ||
22 | namespace Kube { | 23 | namespace Kube { |
23 | 24 | ||
@@ -25,10 +26,13 @@ class Keyring : public QObject { | |||
25 | Q_OBJECT | 26 | Q_OBJECT |
26 | public: | 27 | public: |
27 | Keyring(); | 28 | Keyring(); |
29 | static Keyring *instance(); | ||
28 | Q_INVOKABLE bool isUnlocked(const QByteArray &accountId); | 30 | Q_INVOKABLE bool isUnlocked(const QByteArray &accountId); |
31 | void unlock(const QByteArray &accountId); | ||
29 | 32 | ||
30 | private: | 33 | private: |
31 | Q_DISABLE_COPY(Keyring); | 34 | Q_DISABLE_COPY(Keyring); |
35 | QSet<QByteArray> mUnlocked; | ||
32 | }; | 36 | }; |
33 | 37 | ||
34 | class AccountKeyring : public QObject { | 38 | class AccountKeyring : public QObject { |