Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 8740b4ab authored by Laurent Montel's avatar Laurent Montel 😁

Add code to get pixmap

parent 1d427e91
......@@ -71,8 +71,8 @@ void ScamCheckShortUrl::slotExpandFinished(QNetworkReply *reply)
if (!reply->property("shortUrl").isNull()) {
shortUrl.setUrl(reply->property("shortUrl").toString());
}
reply->deleteLater();
const QString jsonData = QString::fromUtf8(reply->readAll());
reply->deleteLater();
//qDebug() << jsonData;
......
......@@ -22,12 +22,15 @@
#include <QCryptographicHash>
#include <QStringList>
#include <QDebug>
#include <QPixmap>
using namespace PimCommon;
GravatarResolvUrlJob::GravatarResolvUrlJob(QObject *parent)
: QObject(parent),
mSize(80)
mNetworkAccessManager(0),
mSize(80),
mHasGravatar(false)
{
}
......@@ -49,8 +52,7 @@ KUrl GravatarResolvUrlJob::generateGravatarUrl()
bool GravatarResolvUrlJob::hasGravatar() const
{
//TODO
return true;
return mHasGravatar;
}
void GravatarResolvUrlJob::start()
......@@ -58,12 +60,35 @@ void GravatarResolvUrlJob::start()
if (canStart()) {
mCalculatedHash.clear();
const KUrl url = createUrl();
if (!mNetworkAccessManager) {
mNetworkAccessManager = new QNetworkAccessManager(this);
connect(mNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotFinishLoadPixmap(QNetworkReply*)));
}
QNetworkReply *reply = mNetworkAccessManager->get(QNetworkRequest(url));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError)));
} else {
//TODO return message Error.
deleteLater();
}
}
void GravatarResolvUrlJob::slotFinishLoadPixmap(QNetworkReply *reply)
{
if (reply->error() == QNetworkReply::NoError) {
mPixmap.loadFromData(reply->readAll());
qDebug()<<" pix.isnull"<<mPixmap.isNull();
mHasGravatar = true;
}
reply->deleteLater();
}
void GravatarResolvUrlJob::slotError(QNetworkReply::NetworkError error)
{
if (error == QNetworkReply::ContentNotFoundError) {
mHasGravatar = false;
}
}
QString GravatarResolvUrlJob::email() const
{
return mEmail;
......@@ -87,6 +112,11 @@ int GravatarResolvUrlJob::size() const
return mSize;
}
QPixmap GravatarResolvUrlJob::pixmap() const
{
return mPixmap;
}
void GravatarResolvUrlJob::setSize(int size)
{
if (size <= 0) {
......
......@@ -21,7 +21,9 @@
#include "pimcommon_export.h"
#include <QObject>
#include <KUrl>
#include <QPixmap>
#include <QNetworkReply>
class QNetworkAccessManager;
namespace PimCommon {
class PIMCOMMON_EXPORT GravatarResolvUrlJob : public QObject
{
......@@ -46,15 +48,24 @@ public:
int size() const;
QPixmap pixmap() const;
Q_SIGNALS:
void urlResolved(const KUrl &url);
private Q_SLOTS:
void slotFinishLoadPixmap(QNetworkReply *reply);
void slotError(QNetworkReply::NetworkError error);
private:
QPixmap mPixmap;
KUrl createUrl();
QString calculateHash();
QString mEmail;
QString mCalculatedHash;
QNetworkAccessManager *mNetworkAccessManager;
int mSize;
bool mHasGravatar;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment