on 62d1763 help sign in
unity8/plugins/AccountsService/AccountsService.h
149 lines 5.4 kB history raw
1/*
2 * Copyright (C) 2013, 2015 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 */
17#ifndef UNITY_ACCOUNTSSERVICE_H
18#define UNITY_ACCOUNTSSERVICE_H
20#include <QHash>
21#include <QObject>
22#include <QString>
23#include <QVariant>
25class AccountsServiceDBusAdaptor;
26class QDBusInterface;
28class AccountsService: public QObject
30 Q_OBJECT
31 Q_ENUMS(PasswordDisplayHint)
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 (bool enableLauncherWhileLocked
41 READ enableLauncherWhileLocked
42 NOTIFY enableLauncherWhileLockedChanged)
43 Q_PROPERTY (bool enableIndicatorsWhileLocked
44 READ enableIndicatorsWhileLocked
45 NOTIFY enableIndicatorsWhileLockedChanged)
46 Q_PROPERTY (QString backgroundFile
47 READ backgroundFile
48 NOTIFY backgroundFileChanged)
49 Q_PROPERTY (bool statsWelcomeScreen
50 READ statsWelcomeScreen
51 NOTIFY statsWelcomeScreenChanged)
52 Q_PROPERTY (PasswordDisplayHint passwordDisplayHint
53 READ passwordDisplayHint
54 NOTIFY passwordDisplayHintChanged)
55 Q_PROPERTY (uint failedLogins
56 READ failedLogins
57 WRITE setFailedLogins
58 NOTIFY failedLoginsChanged)
59 Q_PROPERTY(bool hereEnabled
60 READ hereEnabled
61 WRITE setHereEnabled
62 NOTIFY hereEnabledChanged)
63 Q_PROPERTY(QString hereLicensePath
64 READ hereLicensePath
65 NOTIFY hereLicensePathChanged)
66 Q_PROPERTY(bool hereLicensePathValid // qml sees a null string as "", so we use proxy setting for that
67 READ hereLicensePathValid
68 NOTIFY hereLicensePathChanged)
69 Q_PROPERTY(QString realName READ realName WRITE setRealName NOTIFY realNameChanged)
70 Q_PROPERTY(QString email READ email WRITE setEmail NOTIFY emailChanged)
72public:
73 enum PasswordDisplayHint {
74 Keyboard,
75 Numeric,
76 };
78 explicit AccountsService(QObject *parent = 0, const QString & user = QString());
79 ~AccountsService() = default;
81 QString user() const;
82 void setUser(const QString &user);
83 bool demoEdges() const;
84 void setDemoEdges(bool demoEdges);
85 bool enableLauncherWhileLocked() const;
86 bool enableIndicatorsWhileLocked() const;
87 QString backgroundFile() const;
88 bool statsWelcomeScreen() const;
89 PasswordDisplayHint passwordDisplayHint() const;
90 uint failedLogins() const;
91 void setFailedLogins(uint failedLogins);
92 bool hereEnabled() const;
93 void setHereEnabled(bool enabled);
94 QString hereLicensePath() const;
95 bool hereLicensePathValid() const;
96 QString realName() const;
97 void setRealName(const QString &realName);
98 QString email() const;
99 void setEmail(const QString &email);
101Q_SIGNALS:
102 void userChanged();
103 void demoEdgesChanged();
104 void enableLauncherWhileLockedChanged();
105 void enableIndicatorsWhileLockedChanged();
106 void backgroundFileChanged();
107 void statsWelcomeScreenChanged();
108 void passwordDisplayHintChanged();
109 void failedLoginsChanged();
110 void hereEnabledChanged();
111 void hereLicensePathChanged();
112 void realNameChanged();
113 void emailChanged();
115private Q_SLOTS:
116 void onPropertiesChanged(const QString &user, const QString &interface, const QStringList &changed);
117 void onMaybeChanged(const QString &user);
119private:
120 typedef QVariant (*ProxyConverter)(const QVariant &);
122 void refresh(bool async);
123 void registerProperty(const QString &interface, const QString &property, const QString &signal);
124 void registerProxy(const QString &interface, const QString &property, QDBusInterface *iface, const QString &method, ProxyConverter converter = nullptr);
126 void updateAllProperties(const QString &interface, bool async);
127 void updateProperty(const QString &interface, const QString &property);
128 void updateCache(const QString &interface, const QString &property, const QVariant &value);
130 void setProperty(const QString &interface, const QString &property, const QVariant &value);
131 QVariant getProperty(const QString &interface, const QString &property) const;
133 void emitChangedForProperty(const QString &interface, const QString &property);
135 struct PropertyInfo {
136 QVariant value{};
137 QString signal{};
138 QDBusInterface *proxyInterface{};
139 QString proxyMethod{};
140 ProxyConverter proxyConverter{};
141 };
142 typedef QHash< QString, QHash<QString, PropertyInfo> > PropertyHash;
143 PropertyHash m_properties;
144 AccountsServiceDBusAdaptor *m_service;
145 QDBusInterface *m_unityInput;
146 QString m_user;
147};
149#endif