summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2015-05-12 07:43:28 +0200
committerMontel Laurent <[email protected]>2015-05-12 07:43:28 +0200
commit8740b4ab3f35bc166600eaeb3639b5e5e230175b (patch)
treecd720864d61ad83f0237effdcbfc5116614cf7a6
parent1d427e91bc1e608515781a334c896fc4f73c97f9 (diff)
Add code to get pixmap
-rw-r--r--messageviewer/scamdetection/scamcheckshorturl.cpp2
-rw-r--r--pimcommon/gravatar/gravatarresolvurljob.cpp36
-rw-r--r--pimcommon/gravatar/gravatarresolvurljob.h13
3 files changed, 46 insertions, 5 deletions
diff --git a/messageviewer/scamdetection/scamcheckshorturl.cpp b/messageviewer/scamdetection/scamcheckshorturl.cpp
index aea2c81..2ba0dd7 100644
--- a/messageviewer/scamdetection/scamcheckshorturl.cpp
+++ b/messageviewer/scamdetection/scamcheckshorturl.cpp
@@ -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;
diff --git a/pimcommon/gravatar/gravatarresolvurljob.cpp b/pimcommon/gravatar/gravatarresolvurljob.cpp
index 0779078..cf3b33b 100644
--- a/pimcommon/gravatar/gravatarresolvurljob.cpp
+++ b/pimcommon/gravatar/gravatarresolvurljob.cpp
@@ -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) {
diff --git a/pimcommon/gravatar/gravatarresolvurljob.h b/pimcommon/gravatar/gravatarresolvurljob.h
index 8adeaca..0ac13a8 100644
--- a/pimcommon/gravatar/gravatarresolvurljob.h
+++ b/pimcommon/gravatar/gravatarresolvurljob.h
@@ -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;
};
}