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 70c9120e authored by Laurent Montel's avatar Laurent Montel 😁

Show gravatar in header

CCBUG: 347441

It added kmail gravatar support
I will add more gravatar support in kaddressbook after that
parent b6c1a3ad
......@@ -17,18 +17,20 @@
*/
#include "contactdisplaymessagememento.h"
#include "pimcommon/gravatar/gravatarresolvurljob.h"
#include "settings/globalsettings.h"
#include <Akonadi/Contact/ContactSearchJob>
using namespace MessageViewer;
ContactDisplayMessageMemento::ContactDisplayMessageMemento( const QString &emailAddress )
: QObject( 0 ),
mForceDisplayTo( Viewer::UseGlobalSetting ),
mEmailAddress(emailAddress),
mFinished( false ),
mMailAllowToRemoteContent( false ),
mForceDisplayTo( Viewer::UseGlobalSetting )
mMailAllowToRemoteContent( false )
{
if( !emailAddress.isEmpty() ) {
if( !mEmailAddress.isEmpty() ) {
Akonadi::ContactSearchJob *searchJob = new Akonadi::ContactSearchJob();
searchJob->setQuery( Akonadi::ContactSearchJob::Email, emailAddress.toLower(), Akonadi::ContactSearchJob::ExactMatch );
connect( searchJob, SIGNAL(result(KJob*)),
......@@ -54,12 +56,23 @@ void ContactDisplayMessageMemento::slotSearchJobFinished( KJob *job )
const int contactSize( searchJob->contacts().size() );
if ( contactSize >= 1 ) {
searchPhoto(searchJob->contacts());
KABC::Addressee addressee = searchJob->contacts().first();
processAddress( addressee );
emit update( Viewer::Delayed );
if (contactSize>1)
kDebug()<<" more than 1 contact was found we return first contact";
const KABC::Addressee addressee = searchJob->contacts().at(0);
processAddress( addressee );
searchPhoto(searchJob->contacts());
emit update( Viewer::Delayed );
}
if (mPhoto.isEmpty() && mPhoto.url().isEmpty()) {
// No url, no photo => search gravatar
if (GlobalSettings::self()->gravatarSupportEnabled()) {
PimCommon::GravatarResolvUrlJob *job = new PimCommon::GravatarResolvUrlJob(this);
job->setEmail(mEmailAddress);
// Debug job->setUseDefaultPixmap(true);
connect(job, SIGNAL(finished(PimCommon::GravatarResolvUrlJob*)), this, SLOT(slotGravatarResolvUrlFinished(PimCommon::GravatarResolvUrlJob*)));
job->start();
}
}
}
......@@ -79,16 +92,24 @@ bool ContactDisplayMessageMemento::allowToRemoteContent() const
return mMailAllowToRemoteContent;
}
void ContactDisplayMessageMemento::searchPhoto(const KABC::AddresseeList &list)
bool ContactDisplayMessageMemento::searchPhoto(const KABC::AddresseeList &list)
{
bool foundPhoto = false;
Q_FOREACH (const KABC::Addressee &addressee, list) {
if (!addressee.photo().isEmpty()) {
mPhoto = addressee.photo();
foundPhoto = true;
break;
}
}
return foundPhoto;
}
QPixmap ContactDisplayMessageMemento::gravatar() const
{
return mGravatar;
}
void ContactDisplayMessageMemento::processAddress( const KABC::Addressee& addressee )
{
const QStringList customs = addressee.customs();
......@@ -115,4 +136,10 @@ KABC::Picture ContactDisplayMessageMemento::photo() const
return mPhoto;
}
void ContactDisplayMessageMemento::slotGravatarResolvUrlFinished(PimCommon::GravatarResolvUrlJob *job)
{
if (job && job->hasGravatar()) {
mGravatar = job->pixmap();
emit update( Viewer::Delayed );
}
}
......@@ -28,6 +28,9 @@
#include <QObject>
class KJob;
namespace PimCommon {
class GravatarResolvUrlJob;
}
namespace MessageViewer
{
......@@ -46,6 +49,8 @@ public:
void detach();
QPixmap gravatar() const;
signals:
// TODO: Factor our update and detach into base class
void update( MessageViewer::Viewer::UpdateMode );
......@@ -54,12 +59,15 @@ signals:
private Q_SLOTS:
void slotSearchJobFinished( KJob *job );
void slotGravatarResolvUrlFinished(PimCommon::GravatarResolvUrlJob *);
private:
void searchPhoto(const KABC::AddresseeList &list);
bool mFinished;
bool mMailAllowToRemoteContent;
bool searchPhoto(const KABC::AddresseeList &list);
Viewer::DisplayFormatMessage mForceDisplayTo;
KABC::Picture mPhoto;
QPixmap mGravatar;
QString mEmailAddress;
bool mFinished;
bool mMailAllowToRemoteContent;
};
}
......
......@@ -302,10 +302,24 @@ xfaceSettings xface(const MessageViewer::HeaderStyle *style, KMime::Message *mes
}
settings.photoURL = MessageViewer::HeaderStyleUtil::imgToDataUrl( photo );
}
} else {
} else if (!photoMemento->photo().url().isEmpty()){
settings.photoURL = photoMemento->photo().url();
if ( settings.photoURL.startsWith(QLatin1Char('/')) )
settings.photoURL.prepend( QLatin1String("file:") );
} else if (!photoMemento->gravatar().isNull()) {
QImage photo = photoMemento->gravatar().toImage();
if ( !photo.isNull() ) {
settings.photoWidth = photo.width();
settings.photoHeight = photo.height();
// scale below 60, otherwise it can get way too large
if ( settings.photoHeight > 60 ) {
double ratio = ( double )settings.photoHeight / ( double )settings.photoWidth;
settings.photoHeight = 60;
settings.photoWidth = (int)( 60 / ratio );
photo = photo.scaled( settings.photoWidth, settings.photoHeight, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
}
settings.photoURL = MessageViewer::HeaderStyleUtil::imgToDataUrl( photo );
}
}
} else {
// if the memento is not finished yet, use other photo sources instead
......
......@@ -191,7 +191,7 @@ xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 http://www.kde.org/sta
</entry>
<entry name="GravatarSupportEnabled" type="Bool">
<default>false</default>
<default>true</default>
</entry>
</group>
......
#include "gravatardownloadpixmapdialogtest.h"
GravatarDownloadPixmapDialogTest::GravatarDownloadPixmapDialogTest(QObject *parent) : QObject(parent)
{
}
#ifndef GRAVATARDOWNLOADPIXMAPDIALOGTEST_H
#define GRAVATARDOWNLOADPIXMAPDIALOGTEST_H
#include <QObject>
class GravatarDownloadPixmapDialogTest : public QObject
{
Q_OBJECT
public:
explicit GravatarDownloadPixmapDialogTest(QObject *parent = 0);
signals:
public slots:
};
#endif // GRAVATARDOWNLOADPIXMAPDIALOGTEST_H
#include "gravatardownloadpixmapdialog.h"
GravatarDownloadPixmapDialog::GravatarDownloadPixmapDialog()
{
}
#ifndef GRAVATARDOWNLOADPIXMAPDIALOG_H
#define GRAVATARDOWNLOADPIXMAPDIALOG_H
class GravatarDownloadPixmapDialog
{
public:
GravatarDownloadPixmapDialog();
};
#endif // GRAVATARDOWNLOADPIXMAPDIALOG_H
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