File indexing completed on 2024-05-12 03:55:02
0001 /* 0002 SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org> 0003 SPDX-FileCopyrightText: 2014 Sebastian Kügler <sebas@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #ifndef KUSERPROXY_H 0009 #define KUSERPROXY_H 0010 0011 #include <QObject> 0012 #include <QUrl> 0013 0014 #include <KDirWatch> 0015 #include <KUser> 0016 0017 /** 0018 * KUserProxy (exposed as KUser to the QML runtime) is an object allowing 0019 * read-only access to the user's name, os and version and the configured 0020 * user image. This object can be used to personalize user interfaces. 0021 * 0022 * Example usage: 0023 * @code 0024 import org.kde.coreaddons as KCoreAddons 0025 [...] 0026 0027 Item { 0028 [...] 0029 KCoreAddons.KUser { 0030 id: kuser 0031 } 0032 0033 Image { 0034 id: faceIcon 0035 source: kuser.faceIconUrl 0036 [...] 0037 } 0038 0039 Text { 0040 text: kuser.fullName 0041 [...] 0042 } 0043 } 0044 @endcode 0045 0046 * @short KUser provides read-only access to the user's personal information 0047 * @see KUser 0048 */ 0049 class KUserProxy : public QObject 0050 { 0051 Q_OBJECT 0052 0053 Q_PROPERTY(QString fullName READ fullName NOTIFY nameChanged) 0054 Q_PROPERTY(QString loginName READ loginName NOTIFY nameChanged) 0055 Q_PROPERTY(QUrl faceIconUrl READ faceIconUrl NOTIFY faceIconUrlChanged) 0056 Q_PROPERTY(QString os READ os CONSTANT) 0057 Q_PROPERTY(QString host READ host CONSTANT) 0058 0059 public: 0060 KUserProxy(QObject *parent = nullptr); 0061 ~KUserProxy() override; 0062 0063 /** 0064 * @return the full name of the user 0065 * @see nameChanged 0066 */ 0067 QString fullName() const; 0068 0069 /** 0070 * @return the user's login name 0071 * @see nameChanged 0072 * 0073 */ 0074 QString loginName() const; 0075 0076 /** 0077 * @return the url of the user's configured image (including file:/) 0078 * @see faceIconUrlChanged 0079 */ 0080 QUrl faceIconUrl() const; 0081 0082 /** 0083 * @return pretty name indicating operating system and version 0084 * @see nameChanged 0085 */ 0086 QString os(); 0087 0088 /** 0089 * @return the system's hostname 0090 * @see nameChanged 0091 */ 0092 QString host() const; 0093 0094 Q_SIGNALS: 0095 /** 0096 * signal that the user's name or login name changed 0097 * @see fullName 0098 * @see loginName 0099 */ 0100 void nameChanged(); 0101 /** 0102 * signal that the user image changed 0103 * @see faceIconUrl 0104 */ 0105 void faceIconUrlChanged(); 0106 0107 private: 0108 void update(const QString &path); 0109 KDirWatch m_dirWatch; 0110 KUser m_user; 0111 QString m_os; 0112 bool m_temporaryEmptyFaceIconPath; 0113 }; 0114 0115 #endif // KUSERPROXY_H