summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2015-07-31 07:02:34 +0200
committerMontel Laurent <[email protected]>2015-07-31 07:02:34 +0200
commit5a2ce131d1445bd73a671e88cb690f84861d9213 (patch)
treef0d495eded7b8e0f8da3be9b664cf2ffaba63102
parent5b8e54fbaddf86ac9154d497889334d3dd1b4d7d (diff)
Make load image from url
-rw-r--r--messageviewer/header/contactdisplaymessagememento.cpp37
-rw-r--r--messageviewer/header/contactdisplaymessagememento.h3
-rw-r--r--messageviewer/header/headerstyle_util.cpp2
3 files changed, 41 insertions, 1 deletions
diff --git a/messageviewer/header/contactdisplaymessagememento.cpp b/messageviewer/header/contactdisplaymessagememento.cpp
index 17b3db0..f56dd39 100644
--- a/messageviewer/header/contactdisplaymessagememento.cpp
+++ b/messageviewer/header/contactdisplaymessagememento.cpp
@@ -22,6 +22,7 @@
#include "pimcommon/util/networkutil.h"
#include "settings/globalsettings.h"
#include <Akonadi/Contact/ContactSearchJob>
+#include <kio/transferjob.h>
using namespace MessageViewer;
@@ -65,7 +66,36 @@ void ContactDisplayMessageMemento::slotSearchJobFinished(KJob *job)
processAddress(addressee);
searchPhoto(searchJob->contacts());
if (!mPhoto.isEmpty()) {
- emit update(Viewer::Delayed);
+ //We have a data raw => we can update message
+ if (mPhoto.isIntern()) {
+ emit update(Viewer::Delayed);
+ } else {
+ QUrl url = QUrl(mPhoto.url());
+ QImage image;
+ bool ok = false;
+
+ if (url.isLocalFile()) {
+ if (image.load(url.toLocalFile())) {
+ ok = true;
+ }
+ } else {
+ QByteArray imageData;
+ KIO::TransferJob *job = KIO::get(url, KIO::NoReload);
+ QObject::connect(job, &KIO::TransferJob::data,
+ [&imageData](KIO::Job *, const QByteArray &data) {
+ imageData.append(data);
+ });
+ if (job->exec()) {
+ if (image.loadFromData(imageData)) {
+ ok = true;
+ }
+ }
+ }
+ if (ok) {
+ mImageFromUrl = image;
+ Q_EMIT update(Viewer::Delayed);
+ }
+ }
}
}
if (!PimCommon::NetworkUtil::self()->lowBandwidth()) {
@@ -118,6 +148,11 @@ bool ContactDisplayMessageMemento::searchPhoto(const KContacts::AddresseeList &l
return foundPhoto;
}
+QImage ContactDisplayMessageMemento::imageFromUrl() const
+{
+ return mImageFromUrl;
+}
+
QPixmap ContactDisplayMessageMemento::gravatarPixmap() const
{
return mGravatarPixmap;
diff --git a/messageviewer/header/contactdisplaymessagememento.h b/messageviewer/header/contactdisplaymessagememento.h
index baa6209..0e93d19 100644
--- a/messageviewer/header/contactdisplaymessagememento.h
+++ b/messageviewer/header/contactdisplaymessagememento.h
@@ -52,6 +52,8 @@ public:
QPixmap gravatarPixmap() const;
+ QImage imageFromUrl() const;
+
Q_SIGNALS:
// TODO: Factor our update and detach into base class
void update(MessageViewer::Viewer::UpdateMode);
@@ -66,6 +68,7 @@ private:
Viewer::DisplayFormatMessage mForceDisplayTo;
KContacts::Picture mPhoto;
QPixmap mGravatarPixmap;
+ QImage mImageFromUrl;
QString mEmailAddress;
bool mFinished;
bool mMailAllowToRemoteContent;
diff --git a/messageviewer/header/headerstyle_util.cpp b/messageviewer/header/headerstyle_util.cpp
index 4abee44..5c58451 100644
--- a/messageviewer/header/headerstyle_util.cpp
+++ b/messageviewer/header/headerstyle_util.cpp
@@ -313,6 +313,8 @@ xfaceSettings xface(const MessageViewer::HeaderStyle *style, KMime::Message *mes
// get photo data and convert to data: url
const QImage photo = photoMemento->photo().data();
updateXFaceSettings(photo, settings);
+ } else if (!photoMemento->imageFromUrl().isNull()) {
+ updateXFaceSettings(photoMemento->imageFromUrl(), settings);
} else if (!photoMemento->photo().url().isEmpty()) {
settings.photoURL = photoMemento->photo().url();
if (settings.photoURL.startsWith(QLatin1Char('/'))) {