Make the Account store the avatar pixmap.

The avatar pixmap is fetched from the server by the Connectionvalidator,
once it has validated the user name, it queries the avatar pixmap.

If the server does not have the avatar route, an empty pixmap is stored.
This commit is contained in:
Klaas Freitag 2017-01-22 13:55:08 +01:00
parent b49dd02e3d
commit e05d6bfcdc
4 changed files with 30 additions and 0 deletions

View file

@ -90,6 +90,16 @@ void Account::setDavUser(const QString &newDavUser)
_davUser = newDavUser;
}
QPixmap Account::avatar() const
{
return _avatarPixmap;
}
void Account::setAvatar(const QPixmap& pixmap)
{
_avatarPixmap = pixmap;
emit accountChangedAvatar();
}
QString Account::displayName() const
{
QString dn = QString("%1@%2").arg(_credentials->user(), _url.host());

View file

@ -26,6 +26,8 @@
#include <QSslCipher>
#include <QSslError>
#include <QSharedPointer>
#include <QPixmap>
#include "utility.h"
#include <memory>
#include "capabilities.h"
@ -78,6 +80,9 @@ public:
QString davUser() const;
void setDavUser(const QString &newDavUser);
QPixmap avatar() const;
void setAvatar(const QPixmap& pixmap);
/// The name of the account as shown in the toolbar
QString displayName() const;
@ -197,6 +202,8 @@ signals:
void serverVersionChanged(Account* account, const QString& newVersion, const QString& oldVersion);
void accountChangedAvatar();
protected Q_SLOTS:
void slotHandleSslErrors(QNetworkReply*,QList<QSslError>);
void slotCredentialsFetched();
@ -209,6 +216,7 @@ private:
QWeakPointer<Account> _sharedThis;
QString _id;
QString _davUser;
QPixmap _avatarPixmap;
QMap<QString, QVariant> _settingsMap;
QUrl _url;
QList<QSslCertificate> _approvedCerts;

View file

@ -15,6 +15,7 @@
#include <QtCore>
#include <QNetworkReply>
#include <QNetworkProxyFactory>
#include <QPixmap>
#include "connectionvalidator.h"
#include "account.h"
@ -252,7 +253,17 @@ void ConnectionValidator::slotUserFetched(const QVariantMap &json)
QString user = json.value("ocs").toMap().value("data").toMap().value("id").toString();
if (!user.isEmpty()) {
_account->setDavUser(user);
AvatarJob *job = new AvatarJob(_account, this);
QObject::connect(job, SIGNAL(avatarPixmap(QPixmap)), this, SLOT(slotAvatarPixmap(QPixmap)));
job->start();
}
}
void ConnectionValidator::slotAvatarPixmap(const QPixmap& pixmap)
{
_account->setAvatar(pixmap);
reportResult(Connected);
}

View file

@ -119,6 +119,7 @@ protected slots:
void slotCapabilitiesRecieved(const QVariantMap&);
void slotUserFetched(const QVariantMap &);
void slotAvatarPixmap(const QPixmap&);
private:
void reportResult(Status status);