From eec3865e536a6c4f95f917eefc2e94c8d0c158b1 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 12 Jan 2018 23:47:08 +0900 Subject: User: Q_PROPERTYs; setAvatar() --- user.h | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'user.h') diff --git a/user.h b/user.h index b7d67fb2..91dfdc09 100644 --- a/user.h +++ b/user.h @@ -29,6 +29,10 @@ namespace QMatrixClient class User: public QObject { Q_OBJECT + Q_PROPERTY(QString id READ id CONSTANT) + Q_PROPERTY(QString name READ name NOTIFY nameChanged) + Q_PROPERTY(QString displayName READ displayname NOTIFY nameChanged STORED false) + Q_PROPERTY(QString bridgeName READ bridged NOTIFY nameChanged STORED false) public: User(QString userId, Connection* connection); ~User() override; @@ -36,40 +40,43 @@ namespace QMatrixClient /** * Returns the id of the user */ - Q_INVOKABLE QString id() const; + QString id() const; /** * Returns the name chosen by the user */ - Q_INVOKABLE QString name() const; + QString name() const; /** * Returns the name that should be used to display the user. */ - Q_INVOKABLE QString displayname() const; + QString displayname() const; /** * Returns the name of bridge the user is connected from or empty. */ - Q_INVOKABLE QString bridged() const; + QString bridged() const; - Avatar& avatarObject(); - QImage avatar(int dimension); - QImage avatar(int requestedWidth, int requestedHeight); + const Avatar& avatarObject(); + Q_INVOKABLE QImage avatar(int dimension); + Q_INVOKABLE QImage avatar(int requestedWidth, int requestedHeight); - QUrl avatarUrl() const; + Q_INVOKABLE QUrl avatarUrl() const; void processEvent(Event* event); public slots: void rename(const QString& newName); + bool setAvatar(const QString& fileName); + bool setAvatar(QIODevice* source); signals: - void nameChanged(User*, QString); + void nameChanged(QString newName, QString oldName); void avatarChanged(User* user); private slots: void updateName(const QString& newName); + void updateAvatarUrl(const QUrl& newUrl); private: class Private; -- cgit v1.2.3 From cb54a2a5f9e83a5076eb501e60e88846a4aa28df Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Thu, 25 Jan 2018 09:43:11 +0900 Subject: Expose avatar URLs of Room and User as Q_PROPERTY This is needed for QML integration. Closes #155. --- user.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'user.h') diff --git a/user.h b/user.h index 91dfdc09..3df188a1 100644 --- a/user.h +++ b/user.h @@ -33,6 +33,7 @@ namespace QMatrixClient Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(QString displayName READ displayname NOTIFY nameChanged STORED false) Q_PROPERTY(QString bridgeName READ bridged NOTIFY nameChanged STORED false) + Q_PROPERTY(QUrl avatarUrl READ avatarUrl NOTIFY avatarChanged) public: User(QString userId, Connection* connection); ~User() override; @@ -61,7 +62,7 @@ namespace QMatrixClient Q_INVOKABLE QImage avatar(int dimension); Q_INVOKABLE QImage avatar(int requestedWidth, int requestedHeight); - Q_INVOKABLE QUrl avatarUrl() const; + QUrl avatarUrl() const; void processEvent(Event* event); -- cgit v1.2.3 From 3a913f33853c675a1051460bc36278be20a4c941 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Thu, 25 Jan 2018 19:45:08 +0900 Subject: Room, User: const-tighten up the code, set QObject names To make debugging (including QML debugging) more convenient. --- user.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'user.h') diff --git a/user.h b/user.h index 3df188a1..4f48f20c 100644 --- a/user.h +++ b/user.h @@ -58,7 +58,7 @@ namespace QMatrixClient */ QString bridged() const; - const Avatar& avatarObject(); + const Avatar& avatarObject() const; Q_INVOKABLE QImage avatar(int dimension); Q_INVOKABLE QImage avatar(int requestedWidth, int requestedHeight); -- cgit v1.2.3 From 80f7e44e1a9056fc55147718dd2812eb93925ec1 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Thu, 25 Jan 2018 19:48:08 +0900 Subject: Room, User: expose avatarMediaId(); declare User for the metatype system To make it easy to use User objects and fetch room and user avatars from QML. Closes #155. --- user.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'user.h') diff --git a/user.h b/user.h index 4f48f20c..8a2c53d9 100644 --- a/user.h +++ b/user.h @@ -33,6 +33,7 @@ namespace QMatrixClient Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(QString displayName READ displayname NOTIFY nameChanged STORED false) Q_PROPERTY(QString bridgeName READ bridged NOTIFY nameChanged STORED false) + Q_PROPERTY(QString avatarMediaId READ avatarMediaId NOTIFY avatarChanged STORED false) Q_PROPERTY(QUrl avatarUrl READ avatarUrl NOTIFY avatarChanged) public: User(QString userId, Connection* connection); @@ -62,6 +63,7 @@ namespace QMatrixClient Q_INVOKABLE QImage avatar(int dimension); Q_INVOKABLE QImage avatar(int requestedWidth, int requestedHeight); + QString avatarMediaId() const; QUrl avatarUrl() const; void processEvent(Event* event); @@ -84,3 +86,4 @@ namespace QMatrixClient Private* d; }; } +Q_DECLARE_METATYPE(QMatrixClient::User*) -- cgit v1.2.3