Lomiri
AccountsService.h
1/*
2 * Copyright (C) 2013-2016 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef LOMIRI_ACCOUNTSSERVICE_H
18#define LOMIRI_ACCOUNTSSERVICE_H
19
20#include <QHash>
21#include <QObject>
22#include <QString>
23#include <QStringList>
24#include <QVariant>
25
26class AccountsServiceDBusAdaptor;
27class QDBusInterface;
28
29class AccountsService: public QObject
30{
31 Q_OBJECT
32 Q_PROPERTY (QString user
33 READ user
34 WRITE setUser
35 NOTIFY userChanged)
36 Q_PROPERTY (bool demoEdges
37 READ demoEdges
38 WRITE setDemoEdges
39 NOTIFY demoEdgesChanged)
40 Q_PROPERTY (QStringList demoEdgesCompleted
41 READ demoEdgesCompleted
42 NOTIFY demoEdgesCompletedChanged)
43 Q_PROPERTY (bool enableFingerprintIdentification
44 READ enableFingerprintIdentification
45 NOTIFY enableFingerprintIdentificationChanged)
46 Q_PROPERTY (bool enableLauncherWhileLocked
47 READ enableLauncherWhileLocked
48 NOTIFY enableLauncherWhileLockedChanged)
49 Q_PROPERTY (bool enableIndicatorsWhileLocked
50 READ enableIndicatorsWhileLocked
51 NOTIFY enableIndicatorsWhileLockedChanged)
52 Q_PROPERTY (QString backgroundFile
53 READ backgroundFile
54 NOTIFY backgroundFileChanged)
55 Q_PROPERTY (bool statsWelcomeScreen
56 READ statsWelcomeScreen
57 NOTIFY statsWelcomeScreenChanged)
58 Q_PROPERTY (PasswordDisplayHint passwordDisplayHint
59 READ passwordDisplayHint
60 NOTIFY passwordDisplayHintChanged)
61 Q_PROPERTY(QString pinCodePromptManager READ pinCodePromptManager NOTIFY pinCodePromptManagerChanged)
62 Q_PROPERTY(QString defaultPinCodePromptManager READ defaultPinCodePromptManager CONSTANT)
63 Q_PROPERTY (uint failedLogins
64 READ failedLogins
65 WRITE setFailedLogins
66 NOTIFY failedLoginsChanged)
67 Q_PROPERTY (uint failedFingerprintLogins
68 READ failedFingerprintLogins
69 WRITE setFailedFingerprintLogins
70 NOTIFY failedFingerprintLoginsChanged)
71 Q_PROPERTY(QString realName READ realName WRITE setRealName NOTIFY realNameChanged)
72 Q_PROPERTY(QString email READ email WRITE setEmail NOTIFY emailChanged)
73 Q_PROPERTY(QStringList keymaps READ keymaps WRITE setKeymaps NOTIFY keymapsChanged)
74
75public:
76 enum PasswordDisplayHint {
77 Keyboard,
78 Numeric,
79 };
80 Q_ENUM(PasswordDisplayHint)
81
82 explicit AccountsService(QObject *parent = 0, const QString & user = QString());
83 ~AccountsService() = default;
84
85 QString user() const;
86 void setUser(const QString &user);
87 bool demoEdges() const;
88 void setDemoEdges(bool demoEdges);
89 QStringList demoEdgesCompleted() const;
90 Q_INVOKABLE void markDemoEdgeCompleted(const QString &edge);
91 bool enableFingerprintIdentification() const;
92 bool enableLauncherWhileLocked() const;
93 bool enableIndicatorsWhileLocked() const;
94 QString backgroundFile() const;
95 bool statsWelcomeScreen() const;
96 PasswordDisplayHint passwordDisplayHint() const;
97 QString pinCodePromptManager() const;
98 QString defaultPinCodePromptManager() const;
99 uint failedLogins() const;
100 void setFailedLogins(uint failedLogins);
101 uint failedFingerprintLogins() const;
102 void setFailedFingerprintLogins(uint failedFingerprintLogins);
103 QString realName() const;
104 void setRealName(const QString &realName);
105 QString email() const;
106 void setEmail(const QString &email);
107 QStringList keymaps() const;
108 void setKeymaps(const QStringList &keymaps);
109
110Q_SIGNALS:
111 void userChanged();
112 void demoEdgesChanged();
113 void demoEdgesCompletedChanged();
114 void enableFingerprintIdentificationChanged();
115 void enableLauncherWhileLockedChanged();
116 void enableIndicatorsWhileLockedChanged();
117 void backgroundFileChanged();
118 void statsWelcomeScreenChanged();
119 void passwordDisplayHintChanged();
120 void failedLoginsChanged();
121 void failedFingerprintLoginsChanged();
122 void realNameChanged();
123 void emailChanged();
124 void keymapsChanged();
125 void pinCodePromptManagerChanged();
126
127private Q_SLOTS:
128 void onPropertiesChanged(const QString &user, const QString &interface, const QStringList &changed);
129 void onMaybeChanged(const QString &user);
130
131private:
132 typedef QVariant (*ProxyConverter)(const QVariant &);
133
134 void refresh(bool async);
135 void registerProperty(const QString &interface, const QString &property, const QString &signal);
136 void registerProxy(const QString &interface, const QString &property, QDBusInterface *iface, const QString &method, ProxyConverter converter = nullptr);
137
138 void updateAllProperties(const QString &interface, bool async);
139 void updateProperty(const QString &interface, const QString &property);
140 void updateCache(const QString &interface, const QString &property, const QVariant &value);
141
142 void setProperty(const QString &interface, const QString &property, const QVariant &value);
143 QVariant getProperty(const QString &interface, const QString &property) const;
144
145 void emitChangedForProperty(const QString &interface, const QString &property);
146
147 struct PropertyInfo {
148 QVariant value{};
149 QString signal{};
150 QDBusInterface *proxyInterface{};
151 QString proxyMethod{};
152 ProxyConverter proxyConverter{};
153 };
154 typedef QHash< QString, QHash<QString, PropertyInfo> > PropertyHash;
155 QString m_defaultPinPromptManager;
156 PropertyHash m_properties;
157 AccountsServiceDBusAdaptor *m_service;
158 QDBusInterface *m_syscompInput;
159 QString m_user;
160};
161
162#endif