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 (uint failedLogins
62 READ failedLogins
63 WRITE setFailedLogins
64 NOTIFY failedLoginsChanged)
65 Q_PROPERTY (uint failedFingerprintLogins
66 READ failedFingerprintLogins
67 WRITE setFailedFingerprintLogins
68 NOTIFY failedFingerprintLoginsChanged)
69 Q_PROPERTY(QString realName READ realName WRITE setRealName NOTIFY realNameChanged)
70 Q_PROPERTY(QString email READ email WRITE setEmail NOTIFY emailChanged)
71 Q_PROPERTY(QStringList keymaps READ keymaps WRITE setKeymaps NOTIFY keymapsChanged)
72
73public:
74 enum PasswordDisplayHint {
75 Keyboard,
76 Numeric,
77 };
78 Q_ENUM(PasswordDisplayHint)
79
80 explicit AccountsService(QObject *parent = 0, const QString & user = QString());
81 ~AccountsService() = default;
82
83 QString user() const;
84 void setUser(const QString &user);
85 bool demoEdges() const;
86 void setDemoEdges(bool demoEdges);
87 QStringList demoEdgesCompleted() const;
88 Q_INVOKABLE void markDemoEdgeCompleted(const QString &edge);
89 bool enableFingerprintIdentification() const;
90 bool enableLauncherWhileLocked() const;
91 bool enableIndicatorsWhileLocked() const;
92 QString backgroundFile() const;
93 bool statsWelcomeScreen() const;
94 PasswordDisplayHint passwordDisplayHint() const;
95 uint failedLogins() const;
96 void setFailedLogins(uint failedLogins);
97 uint failedFingerprintLogins() const;
98 void setFailedFingerprintLogins(uint failedFingerprintLogins);
99 QString realName() const;
100 void setRealName(const QString &realName);
101 QString email() const;
102 void setEmail(const QString &email);
103 QStringList keymaps() const;
104 void setKeymaps(const QStringList &keymaps);
105
106Q_SIGNALS:
107 void userChanged();
108 void demoEdgesChanged();
109 void demoEdgesCompletedChanged();
110 void enableFingerprintIdentificationChanged();
111 void enableLauncherWhileLockedChanged();
112 void enableIndicatorsWhileLockedChanged();
113 void backgroundFileChanged();
114 void statsWelcomeScreenChanged();
115 void passwordDisplayHintChanged();
116 void failedLoginsChanged();
117 void failedFingerprintLoginsChanged();
118 void realNameChanged();
119 void emailChanged();
120 void keymapsChanged();
121
122private Q_SLOTS:
123 void onPropertiesChanged(const QString &user, const QString &interface, const QStringList &changed);
124 void onMaybeChanged(const QString &user);
125
126private:
127 typedef QVariant (*ProxyConverter)(const QVariant &);
128
129 void refresh(bool async);
130 void registerProperty(const QString &interface, const QString &property, const QString &signal);
131 void registerProxy(const QString &interface, const QString &property, QDBusInterface *iface, const QString &method, ProxyConverter converter = nullptr);
132
133 void updateAllProperties(const QString &interface, bool async);
134 void updateProperty(const QString &interface, const QString &property);
135 void updateCache(const QString &interface, const QString &property, const QVariant &value);
136
137 void setProperty(const QString &interface, const QString &property, const QVariant &value);
138 QVariant getProperty(const QString &interface, const QString &property) const;
139
140 void emitChangedForProperty(const QString &interface, const QString &property);
141
142 struct PropertyInfo {
143 QVariant value{};
144 QString signal{};
145 QDBusInterface *proxyInterface{};
146 QString proxyMethod{};
147 ProxyConverter proxyConverter{};
148 };
149 typedef QHash< QString, QHash<QString, PropertyInfo> > PropertyHash;
150 PropertyHash m_properties;
151 AccountsServiceDBusAdaptor *m_service;
152 QDBusInterface *m_syscompInput;
153 QString m_user;
154};
155
156#endif