| 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 <QQmlEngine> |
| 13 | #include <QUrl> |
| 14 | |
| 15 | #include <KDirWatch> |
| 16 | #include <KUser> |
| 17 | |
| 18 | /*! |
| 19 | * \qmltype KUser |
| 20 | * \inqmlmodule org.kde.coreaddons |
| 21 | * |
| 22 | * KUser is an object allowing |
| 23 | * read-only access to the user's name, os and version and the configured |
| 24 | * user image. This object can be used to personalize user interfaces. |
| 25 | * |
| 26 | * Example usage: |
| 27 | * \code |
| 28 | * import org.kde.coreaddons as KCoreAddons |
| 29 | * [...] |
| 30 | * |
| 31 | * Item { |
| 32 | * [...] |
| 33 | * KCoreAddons.KUser { |
| 34 | * id: kuser |
| 35 | * } |
| 36 | * |
| 37 | * Image { |
| 38 | * id: faceIcon |
| 39 | * source: kuser.faceIconUrl |
| 40 | * [...] |
| 41 | * } |
| 42 | * |
| 43 | * Text { |
| 44 | * text: kuser.fullName |
| 45 | * [...] |
| 46 | * } |
| 47 | * } |
| 48 | * \endcode |
| 49 | * |
| 50 | * \brief User provides read-only access to the user's personal information. |
| 51 | * \sa KUser |
| 52 | */ |
| 53 | class KUserProxy : public QObject |
| 54 | { |
| 55 | Q_OBJECT |
| 56 | QML_NAMED_ELEMENT(KUser) |
| 57 | |
| 58 | /*! |
| 59 | * \qmlproperty string KUser::fullName |
| 60 | * The user's full name |
| 61 | */ |
| 62 | Q_PROPERTY(QString fullName READ fullName NOTIFY nameChanged) |
| 63 | |
| 64 | /*! |
| 65 | * \qmlproperty string KUser::loginName |
| 66 | * The user's login name |
| 67 | */ |
| 68 | Q_PROPERTY(QString loginName READ loginName NOTIFY nameChanged) |
| 69 | |
| 70 | /*! |
| 71 | * \qmlproperty url KUser::faceIconUrl |
| 72 | * The url of the user's configured image (including file:/) |
| 73 | */ |
| 74 | Q_PROPERTY(QUrl faceIconUrl READ faceIconUrl NOTIFY faceIconUrlChanged) |
| 75 | |
| 76 | /*! |
| 77 | * \qmlproperty string KUser::os |
| 78 | * The pretty name indicating operating system and version |
| 79 | */ |
| 80 | Q_PROPERTY(QString os READ os CONSTANT) |
| 81 | |
| 82 | /*! |
| 83 | * \qmlproperty string KUser::host |
| 84 | * The user's the system's hostname |
| 85 | */ |
| 86 | Q_PROPERTY(QString host READ host CONSTANT) |
| 87 | |
| 88 | public: |
| 89 | KUserProxy(QObject *parent = nullptr); |
| 90 | ~KUserProxy() override; |
| 91 | |
| 92 | QString fullName() const; |
| 93 | |
| 94 | QString loginName() const; |
| 95 | |
| 96 | QUrl faceIconUrl() const; |
| 97 | |
| 98 | QString os(); |
| 99 | |
| 100 | QString host() const; |
| 101 | |
| 102 | Q_SIGNALS: |
| 103 | void nameChanged(); |
| 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 | |