Unity 8
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 UNITY_ACCOUNTSSERVICE_H
18 #define UNITY_ACCOUNTSSERVICE_H
19 
20 #include <QHash>
21 #include <QObject>
22 #include <QString>
23 #include <QStringList>
24 #include <QVariant>
25 
26 class AccountsServiceDBusAdaptor;
27 class QDBusInterface;
28 
29 class AccountsService: public QObject
30 {
31  Q_OBJECT
32  Q_ENUMS(PasswordDisplayHint)
33  Q_PROPERTY (QString user
34  READ user
35  WRITE setUser
36  NOTIFY userChanged)
37  Q_PROPERTY (bool demoEdges
38  READ demoEdges
39  WRITE setDemoEdges
40  NOTIFY demoEdgesChanged)
41  Q_PROPERTY (QStringList demoEdgesCompleted
42  READ demoEdgesCompleted
43  NOTIFY demoEdgesCompletedChanged)
44  Q_PROPERTY (bool enableFingerprintIdentification
45  READ enableFingerprintIdentification
46  NOTIFY enableFingerprintIdentificationChanged)
47  Q_PROPERTY (bool enableLauncherWhileLocked
48  READ enableLauncherWhileLocked
49  NOTIFY enableLauncherWhileLockedChanged)
50  Q_PROPERTY (bool enableIndicatorsWhileLocked
51  READ enableIndicatorsWhileLocked
52  NOTIFY enableIndicatorsWhileLockedChanged)
53  Q_PROPERTY (QString backgroundFile
54  READ backgroundFile
55  NOTIFY backgroundFileChanged)
56  Q_PROPERTY (bool statsWelcomeScreen
57  READ statsWelcomeScreen
58  NOTIFY statsWelcomeScreenChanged)
59  Q_PROPERTY (PasswordDisplayHint passwordDisplayHint
60  READ passwordDisplayHint
61  NOTIFY passwordDisplayHintChanged)
62  Q_PROPERTY (uint failedLogins
63  READ failedLogins
64  WRITE setFailedLogins
65  NOTIFY failedLoginsChanged)
66  Q_PROPERTY (uint failedFingerprintLogins
67  READ failedFingerprintLogins
68  WRITE setFailedFingerprintLogins
69  NOTIFY failedFingerprintLoginsChanged)
70  Q_PROPERTY(bool hereEnabled
71  READ hereEnabled
72  WRITE setHereEnabled
73  NOTIFY hereEnabledChanged)
74  Q_PROPERTY(QString hereLicensePath
75  READ hereLicensePath
76  NOTIFY hereLicensePathChanged)
77  Q_PROPERTY(bool hereLicensePathValid // qml sees a null string as "", so we use proxy setting for that
78  READ hereLicensePathValid
79  NOTIFY hereLicensePathChanged)
80  Q_PROPERTY(QString realName READ realName WRITE setRealName NOTIFY realNameChanged)
81  Q_PROPERTY(QString email READ email WRITE setEmail NOTIFY emailChanged)
82  Q_PROPERTY(QStringList keymaps
83  READ keymaps
84  NOTIFY keymapsChanged)
85 
86 public:
87  enum PasswordDisplayHint {
88  Keyboard,
89  Numeric,
90  };
91 
92  explicit AccountsService(QObject *parent = 0, const QString & user = QString());
93  ~AccountsService() = default;
94 
95  QString user() const;
96  void setUser(const QString &user);
97  bool demoEdges() const;
98  void setDemoEdges(bool demoEdges);
99  QStringList demoEdgesCompleted() const;
100  Q_INVOKABLE void markDemoEdgeCompleted(const QString &edge);
101  bool enableFingerprintIdentification() const;
102  bool enableLauncherWhileLocked() const;
103  bool enableIndicatorsWhileLocked() const;
104  QString backgroundFile() const;
105  bool statsWelcomeScreen() const;
106  PasswordDisplayHint passwordDisplayHint() const;
107  uint failedLogins() const;
108  void setFailedLogins(uint failedLogins);
109  uint failedFingerprintLogins() const;
110  void setFailedFingerprintLogins(uint failedFingerprintLogins);
111  bool hereEnabled() const;
112  void setHereEnabled(bool enabled);
113  QString hereLicensePath() const;
114  bool hereLicensePathValid() const;
115  QString realName() const;
116  void setRealName(const QString &realName);
117  QString email() const;
118  void setEmail(const QString &email);
119  QStringList keymaps() const;
120 
121 Q_SIGNALS:
122  void userChanged();
123  void demoEdgesChanged();
124  void demoEdgesCompletedChanged();
125  void enableFingerprintIdentificationChanged();
126  void enableLauncherWhileLockedChanged();
127  void enableIndicatorsWhileLockedChanged();
128  void backgroundFileChanged();
129  void statsWelcomeScreenChanged();
130  void passwordDisplayHintChanged();
131  void failedLoginsChanged();
132  void failedFingerprintLoginsChanged();
133  void hereEnabledChanged();
134  void hereLicensePathChanged();
135  void realNameChanged();
136  void emailChanged();
137  void keymapsChanged();
138 
139 private Q_SLOTS:
140  void onPropertiesChanged(const QString &user, const QString &interface, const QStringList &changed);
141  void onMaybeChanged(const QString &user);
142 
143 private:
144  typedef QVariant (*ProxyConverter)(const QVariant &);
145 
146  void refresh(bool async);
147  void registerProperty(const QString &interface, const QString &property, const QString &signal);
148  void registerProxy(const QString &interface, const QString &property, QDBusInterface *iface, const QString &method, ProxyConverter converter = nullptr);
149 
150  void updateAllProperties(const QString &interface, bool async);
151  void updateProperty(const QString &interface, const QString &property);
152  void updateCache(const QString &interface, const QString &property, const QVariant &value);
153 
154  void setProperty(const QString &interface, const QString &property, const QVariant &value);
155  QVariant getProperty(const QString &interface, const QString &property) const;
156 
157  void emitChangedForProperty(const QString &interface, const QString &property);
158 
159  struct PropertyInfo {
160  QVariant value{};
161  QString signal{};
162  QDBusInterface *proxyInterface{};
163  QString proxyMethod{};
164  ProxyConverter proxyConverter{};
165  };
166  typedef QHash< QString, QHash<QString, PropertyInfo> > PropertyHash;
167  PropertyHash m_properties;
168  AccountsServiceDBusAdaptor *m_service;
169  QDBusInterface *m_unityInput;
170  QString m_user;
171 };
172 
173 #endif