connect(FolderMan::instance(), &FolderMan::folderListChanged, this, &User::hasLocalFolderChanged);
connect(this, &User::guiLog, Logger::instance(), &Logger::guiLog);
+
+ connect(_account->account().data(), &Account::accountChangedAvatar, this, &User::avatarChanged);
}
void User::slotBuildNotificationDisplay(const ActivityList &list)
return serverUrl;
}
-QImage User::avatar(bool whiteBg) const
+QImage User::avatar() const
{
- QImage img = AvatarJob::makeCircularAvatar(_account->account()->avatar());
- if (img.isNull()) {
- QImage image(128, 128, QImage::Format_ARGB32);
- image.fill(Qt::GlobalColor::transparent);
- QPainter painter(&image);
-
- QSvgRenderer renderer(QString(whiteBg ? ":/client/theme/black/user.svg" : ":/client/theme/white/user.svg"));
- renderer.render(&painter);
+ return AvatarJob::makeCircularAvatar(_account->account()->avatar());
+}
- return image;
- } else {
- return img;
+QString User::avatarUrl() const
+{
+ if (avatar().isNull()) {
+ return QString();
}
+
+ return QStringLiteral("image://avatars/") + _account->account()->id();
}
bool User::hasLocalFolder() const
return _users[id]->isConnected();
}
-Q_INVOKABLE QImage UserModel::currentUserAvatar()
-{
- if (!_users.isEmpty()) {
- return _users[_currentUserId]->avatar();
- } else {
- QImage image(128, 128, QImage::Format_ARGB32);
- image.fill(Qt::GlobalColor::transparent);
- QPainter painter(&image);
- QSvgRenderer renderer(QString(":/client/theme/white/user.svg"));
- renderer.render(&painter);
-
- return image;
- }
-}
-
QImage UserModel::avatarById(const int &id)
{
if (_users.isEmpty())
return {};
- return _users[id]->avatar(true);
+ return _users[id]->avatar();
}
Q_INVOKABLE QString UserModel::currentUserServer()
}
if (!containsUser) {
- beginInsertRows(QModelIndex(), rowCount(), rowCount());
- _users << new User(user, isCurrent);
+ int row = rowCount();
+ beginInsertRows(QModelIndex(), row, row);
+
+ User *u = new User(user, isCurrent);
+
+ connect(u, &User::avatarChanged, this, [this, row] {
+ emit dataChanged(index(row, 0), index(row, 0), {UserModel::AvatarRole});
+ });
+
+ _users << u;
if (isCurrent) {
_currentUserId = _users.indexOf(_users.last());
}
+
endInsertRows();
ConfigFile cfg;
_users.last()->setNotificationRefreshInterval(cfg.notificationRefreshInterval());
} else if (role == ServerRole) {
return _users[index.row()]->server();
} else if (role == AvatarRole) {
- return _users[index.row()]->avatar();
+ return _users[index.row()]->avatarUrl();
} else if (role == IsCurrentUserRole) {
return _users[index.row()]->isCurrentUser();
} else if (role == IsConnectedRole) {
Q_UNUSED(size)
Q_UNUSED(requestedSize)
- if (id == "currentUser") {
- return UserModel::instance()->currentUserAvatar();
- } else {
- int uid = id.toInt();
- return UserModel::instance()->avatarById(uid);
+ const auto makeIcon = [](const QString &path) {
+ QImage image(128, 128, QImage::Format_ARGB32);
+ image.fill(Qt::GlobalColor::transparent);
+ QPainter painter(&image);
+ QSvgRenderer renderer(path);
+ renderer.render(&painter);
+ return image;
+ };
+
+ if (id == QLatin1String("fallbackWhite")) {
+ return makeIcon(QStringLiteral(":/client/theme/white/user.svg"));
+ }
+
+ if (id == QLatin1String("fallbackBlack")) {
+ return makeIcon(QStringLiteral(":/client/theme/black/user.svg"));
}
+
+ const int uid = id.toInt();
+ return UserModel::instance()->avatarById(uid);
}
/*-------------------------------------------------------------------------------------*/
Q_PROPERTY(QString server READ server CONSTANT)
Q_PROPERTY(bool hasLocalFolder READ hasLocalFolder NOTIFY hasLocalFolderChanged)
Q_PROPERTY(bool serverHasTalk READ serverHasTalk NOTIFY serverHasTalkChanged)
+ Q_PROPERTY(QString avatar READ avatarUrl NOTIFY avatarChanged)
public:
User(AccountStatePtr &account, const bool &isCurrent = false, QObject* parent = nullptr);
AccountApp *talkApp() const;
bool hasActivities() const;
AccountAppList appList() const;
- QImage avatar(bool whiteBg = false) const;
- QString id() const;
+ QImage avatar() const;
void login() const;
void logout() const;
void removeAccount() const;
+ QString avatarUrl() const;
signals:
void guiLog(const QString &, const QString &);
void nameChanged();
void hasLocalFolderChanged();
void serverHasTalkChanged();
+ void avatarChanged();
public slots:
void slotItemCompleted(const QString &folder, const SyncFileItemPtr &item);
{
Q_OBJECT
Q_PROPERTY(User* currentUser READ currentUser NOTIFY newUserSelected)
+ Q_PROPERTY(int currentUserId READ currentUserId NOTIFY newUserSelected)
public:
static UserModel *instance();
virtual ~UserModel() = default;
Q_INVOKABLE void openCurrentAccountLocalFolder();
Q_INVOKABLE void openCurrentAccountTalk();
Q_INVOKABLE void openCurrentAccountServer();
- Q_INVOKABLE QImage currentUserAvatar();
Q_INVOKABLE int numUsers();
Q_INVOKABLE QString currentUserServer();
Q_INVOKABLE bool currentUserHasActivities();
Q_INVOKABLE bool currentUserHasLocalFolder();
- Q_INVOKABLE int currentUserId() const;
+ int currentUserId() const;
Q_INVOKABLE bool isUserConnected(const int &id);
Q_INVOKABLE void switchCurrentUser(const int &id);
Q_INVOKABLE void login(const int &id);
}\r
\r
onVisibleChanged: {\r
- currentAccountAvatar.source = ""\r
- currentAccountAvatar.source = "image://avatars/currentUser"\r
currentAccountStateIndicator.source = ""\r
- currentAccountStateIndicator.source = UserModel.isUserConnected(UserModel.currentUserId()) ? "qrc:///client/theme/colored/state-ok.svg" : "qrc:///client/theme/colored/state-offline.svg"\r
+ currentAccountStateIndicator.source = UserModel.isUserConnected(UserModel.currentUserId) ? "qrc:///client/theme/colored/state-ok.svg" : "qrc:///client/theme/colored/state-offline.svg"\r
\r
// HACK: reload account Instantiator immediately by restting it - could be done better I guess\r
// see also id:accountMenu below\r
Connections {\r
target: UserModel\r
onRefreshCurrentUserGui: {\r
- currentAccountAvatar.source = ""\r
- currentAccountAvatar.source = "image://avatars/currentUser"\r
currentAccountStateIndicator.source = ""\r
- currentAccountStateIndicator.source = UserModel.isUserConnected(UserModel.currentUserId()) ? "qrc:///client/theme/colored/state-ok.svg" : "qrc:///client/theme/colored/state-offline.svg"\r
+ currentAccountStateIndicator.source = UserModel.isUserConnected(UserModel.currentUserId) ? "qrc:///client/theme/colored/state-ok.svg" : "qrc:///client/theme/colored/state-offline.svg"\r
}\r
onNewUserSelected: {\r
accountMenu.close();\r
Layout.leftMargin: 8\r
verticalAlignment: Qt.AlignCenter\r
cache: false\r
- source: "image://avatars/currentUser"\r
+ source: UserModel.currentUser.avatar != "" ? UserModel.currentUser.avatar : "image://avatars/fallbackWhite"\r
Layout.preferredHeight: Style.accountAvatarSize\r
Layout.preferredWidth: Style.accountAvatarSize\r
\r
\r
Image {\r
id: currentAccountStateIndicator\r
- source: UserModel.isUserConnected(UserModel.currentUserId()) ? "qrc:///client/theme/colored/state-ok.svg" : "qrc:///client/theme/colored/state-offline.svg"\r
+ source: UserModel.isUserConnected(UserModel.currentUserId) ? "qrc:///client/theme/colored/state-ok.svg" : "qrc:///client/theme/colored/state-offline.svg"\r
cache: false\r
x: currentAccountStateIndicatorBackground.x + 1\r
y: currentAccountStateIndicatorBackground.y + 1\r