1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/******************************************************************************
* Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#include <QtCore/QString>
#include <QtCore/QObject>
#include "avatar.h"
namespace QMatrixClient
{
class Connection;
class Room;
class RoomMemberEvent;
class User: public QObject
{
Q_OBJECT
Q_PROPERTY(QString id READ id CONSTANT)
Q_PROPERTY(bool isGuest READ isGuest CONSTANT)
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(QString displayName READ displayname NOTIFY nameChanged STORED false)
Q_PROPERTY(QString fullName READ fullName 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);
~User() override;
/** Get unique stable user id
* User id is generated by the server and is not changed ever.
*/
QString id() const;
/** Get the name chosen by the user
* This may be empty if the user didn't choose the name or cleared
* it.
* \sa displayName
*/
QString name(const Room* room = nullptr) const;
/** Get the displayed user name
* This method returns the result of name() if its non-empty;
* otherwise it returns user id. This is convenient to show a user
* name outside of a room context. In a room context, user names
* should be disambiguated.
* \sa name, id, fullName Room::roomMembername
*/
QString displayname(const Room* room = nullptr) const;
/** Get user name and id in one string
* The constructed string follows the format 'name (id)'
* used for users disambiguation in a room context and in other
* places.
* \sa displayName, Room::roomMembername
*/
QString fullName(const Room* room = nullptr) const;
/**
* Returns the name of bridge the user is connected from or empty.
*/
QString bridged() const;
/** Whether the user is a guest
* As of now, the function relies on the convention used in Synapse
* that guests and only guests have all-numeric IDs. This may or
* may not work with non-Synapse servers.
*/
bool isGuest() const;
const Avatar& avatarObject(const Room* room = nullptr) const;
Q_INVOKABLE QImage avatar(int dimension, const Room* room = nullptr);
Q_INVOKABLE QImage avatar(int requestedWidth, int requestedHeight,
const Room* room = nullptr);
QImage avatar(int width, int height, const Room* room,
Avatar::get_callback_t callback);
QString avatarMediaId(const Room* room = nullptr) const;
QUrl avatarUrl(const Room* room = nullptr) const;
void processEvent(RoomMemberEvent* event, const Room* r = nullptr);
public slots:
void rename(const QString& newName);
void rename(const QString& newName, const Room* r);
bool setAvatar(const QString& fileName);
bool setAvatar(QIODevice* source);
signals:
void nameAboutToChange(QString newName, QString oldName,
const Room* roomContext);
void nameChanged(QString newName, QString oldName,
const Room* roomContext);
void avatarChanged(User* user, const Room* roomContext);
private slots:
void updateName(const QString& newName, const Room* room = nullptr);
void updateName(const QString& newName, const QString& oldName,
const Room* room = nullptr);
void updateAvatarUrl(const QUrl& newUrl, const QUrl& oldUrl,
const Room* room = nullptr);
private:
class Private;
QScopedPointer<Private> d;
};
}
Q_DECLARE_METATYPE(QMatrixClient::User*)
|