1 | /* |
2 | SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org> |
3 | SPDX-FileCopyrightText: 2014 Sebastian Kügler <sebas@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
6 | */ |
7 | |
8 | #ifndef KUSERPROXY_H |
9 | #define KUSERPROXY_H |
10 | |
11 | #include <QObject> |
12 | #include <QUrl> |
13 | |
14 | #include <KDirWatch> |
15 | #include <KUser> |
16 | |
17 | /** |
18 | * KUserProxy (exposed as KUser to the QML runtime) is an object allowing |
19 | * read-only access to the user's name, os and version and the configured |
20 | * user image. This object can be used to personalize user interfaces. |
21 | * |
22 | * Example usage: |
23 | * @code |
24 | import org.kde.coreaddons as KCoreAddons |
25 | [...] |
26 | |
27 | Item { |
28 | [...] |
29 | KCoreAddons.KUser { |
30 | id: kuser |
31 | } |
32 | |
33 | Image { |
34 | id: faceIcon |
35 | source: kuser.faceIconUrl |
36 | [...] |
37 | } |
38 | |
39 | Text { |
40 | text: kuser.fullName |
41 | [...] |
42 | } |
43 | } |
44 | @endcode |
45 | |
46 | * @short KUser provides read-only access to the user's personal information |
47 | * @see KUser |
48 | */ |
49 | class KUserProxy : public QObject |
50 | { |
51 | Q_OBJECT |
52 | |
53 | Q_PROPERTY(QString fullName READ fullName NOTIFY nameChanged) |
54 | Q_PROPERTY(QString loginName READ loginName NOTIFY nameChanged) |
55 | Q_PROPERTY(QUrl faceIconUrl READ faceIconUrl NOTIFY faceIconUrlChanged) |
56 | Q_PROPERTY(QString os READ os CONSTANT) |
57 | Q_PROPERTY(QString host READ host CONSTANT) |
58 | |
59 | public: |
60 | KUserProxy(QObject *parent = nullptr); |
61 | ~KUserProxy() override; |
62 | |
63 | /** |
64 | * @return the full name of the user |
65 | * @see nameChanged |
66 | */ |
67 | QString fullName() const; |
68 | |
69 | /** |
70 | * @return the user's login name |
71 | * @see nameChanged |
72 | * |
73 | */ |
74 | QString loginName() const; |
75 | |
76 | /** |
77 | * @return the url of the user's configured image (including file:/) |
78 | * @see faceIconUrlChanged |
79 | */ |
80 | QUrl faceIconUrl() const; |
81 | |
82 | /** |
83 | * @return pretty name indicating operating system and version |
84 | * @see nameChanged |
85 | */ |
86 | QString os(); |
87 | |
88 | /** |
89 | * @return the system's hostname |
90 | * @see nameChanged |
91 | */ |
92 | QString host() const; |
93 | |
94 | Q_SIGNALS: |
95 | /** |
96 | * signal that the user's name or login name changed |
97 | * @see fullName |
98 | * @see loginName |
99 | */ |
100 | void nameChanged(); |
101 | /** |
102 | * signal that the user image changed |
103 | * @see faceIconUrl |
104 | */ |
105 | void faceIconUrlChanged(); |
106 | |
107 | private: |
108 | void update(const QString &path); |
109 | KDirWatch m_dirWatch; |
110 | KUser m_user; |
111 | QString m_os; |
112 | bool m_temporaryEmptyFaceIconPath; |
113 | }; |
114 | |
115 | #endif // KUSERPROXY_H |
116 | |