mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-27 23:17:13 +03:00
New network job AvatarJob: GETs the account avatar from server.
This commit is contained in:
parent
d6fdda8efa
commit
b49dd02e3d
2 changed files with 67 additions and 0 deletions
|
@ -27,6 +27,7 @@
|
|||
#include <QMutex>
|
||||
#include <QDebug>
|
||||
#include <QCoreApplication>
|
||||
#include <QPixmap>
|
||||
|
||||
#include "json.h"
|
||||
|
||||
|
@ -589,6 +590,42 @@ bool PropfindJob::finished()
|
|||
|
||||
/*********************************************************************************************/
|
||||
|
||||
AvatarJob::AvatarJob(AccountPtr account, QObject *parent)
|
||||
: AbstractNetworkJob(account, QString(), parent)
|
||||
{
|
||||
_avatarUrl = Utility::concatUrlPath(account->url(), QString("remote.php/dav/avatars/%1/128.png").arg(account->davUser()));
|
||||
}
|
||||
|
||||
void AvatarJob::start()
|
||||
{
|
||||
QNetworkRequest req;
|
||||
setReply(davRequest("GET", _avatarUrl, req));
|
||||
setupConnections(reply());
|
||||
AbstractNetworkJob::start();
|
||||
}
|
||||
|
||||
bool AvatarJob::finished()
|
||||
{
|
||||
int http_result_code = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
|
||||
QPixmap avPixmap;
|
||||
|
||||
if (http_result_code == 200) {
|
||||
|
||||
QByteArray pngData = reply()->readAll();
|
||||
if( pngData.size() ) {
|
||||
|
||||
if( avPixmap.loadFromData(pngData) ) {
|
||||
qDebug() << "Retrieved Avatar pixmap!";
|
||||
}
|
||||
}
|
||||
}
|
||||
emit(avatarPixmap(avPixmap));
|
||||
return true;
|
||||
}
|
||||
|
||||
/*********************************************************************************************/
|
||||
|
||||
ProppatchJob::ProppatchJob(AccountPtr account, const QString &path, QObject *parent)
|
||||
: AbstractNetworkJob(account, path, parent)
|
||||
{
|
||||
|
|
|
@ -129,6 +129,36 @@ private:
|
|||
QList<QByteArray> _properties;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief The AvatarJob class
|
||||
*
|
||||
* Retrieves the account users avatar from the server using a GET request.
|
||||
*
|
||||
* If the server does not have the avatar, the result Pixmap is empty.
|
||||
*
|
||||
* @ingroup libsync
|
||||
*/
|
||||
class OWNCLOUDSYNC_EXPORT AvatarJob : public AbstractNetworkJob {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AvatarJob(AccountPtr account, QObject *parent = 0);
|
||||
void start() Q_DECL_OVERRIDE;
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief avatarPixmap - returns either a valid pixmap or not.
|
||||
*/
|
||||
|
||||
void avatarPixmap(QPixmap);
|
||||
|
||||
private slots:
|
||||
virtual bool finished() Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
QUrl _avatarUrl;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Send a Proppatch request
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue