diff options
author | Roman Plášil <me@rplasil.name> | 2017-05-19 18:44:29 +0800 |
---|---|---|
committer | Roman Plášil <me@rplasil.name> | 2017-06-07 16:26:29 +0800 |
commit | 41e34a96bf078c4080dd54ed62fa1b1dcc42a17a (patch) | |
tree | ab26e5cf6e988656229125966a4ff5f0131044bb | |
parent | 28ff47e9cc49c81c1521e4b4e8453cbf28384f44 (diff) | |
download | libquotient-41e34a96bf078c4080dd54ed62fa1b1dcc42a17a.tar.gz libquotient-41e34a96bf078c4080dd54ed62fa1b1dcc42a17a.zip |
Split user's bridge (IRC, Gitter) into a separate field in user model object
-rw-r--r-- | user.cpp | 12 | ||||
-rw-r--r-- | user.h | 5 |
2 files changed, 17 insertions, 0 deletions
@@ -27,6 +27,7 @@ #include <QtCore/QTimer> #include <QtCore/QDebug> #include <QtGui/QIcon> +#include <QtCore/QRegularExpression> #include <algorithm> using namespace QMatrixClient; @@ -52,6 +53,7 @@ class User::Private bool avatarValid; bool avatarOngoingRequest; QVector<QPixmap> scaledAvatars; + QString bridged; void requestAvatar(); }; @@ -84,6 +86,10 @@ QString User::displayname() const return d->userId; } +QString User::bridged() const { + return d->bridged; +} + QPixmap User::avatar(int width, int height) { return croppedAvatar(width, height); // FIXME: Return an uncropped avatar; @@ -141,6 +147,12 @@ void User::processEvent(Event* event) { const auto oldName = d->name; d->name = e->displayName(); + QRegularExpression reSuffix(" \\((IRC|Gitter)\\)$"); + auto match = reSuffix.match(d->name); + if (match.hasMatch()) { + d->bridged = match.captured(1); + d->name = d->name.left(match.capturedStart(0)); + } emit nameChanged(this, oldName); } if( d->avatarUrl != e->avatarUrl() ) @@ -47,6 +47,11 @@ namespace QMatrixClient */ Q_INVOKABLE QString displayname() const; + /** + * Returns the name of bridge the user is connected from or empty. + */ + Q_INVOKABLE QString bridged() const; + QPixmap avatar(int requestedWidth, int requestedHeight); QPixmap croppedAvatar(int requestedWidth, int requestedHeight); |