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

improve gravatar support

parent d761c47b
......@@ -6,5 +6,5 @@ include(AkonadiMacros)
set(KDEPIMLIBS_RUN_ISOLATED_TESTS TRUE)
set(KDEPIMLIBS_RUN_SQLITE_ISOLATED_TESTS TRUE)
add_akonadi_isolated_test_advanced( gravatarcreatejobtest.cpp "../gravatarcreatejob.cpp" "kaddressbookprivate")
add_akonadi_isolated_test_advanced( gravatarupdatejobtest.cpp "../gravatarupdatejob.cpp" "kaddressbookprivate")
add_akonadi_isolated_test_advanced( gravatarcreatejobtest.cpp "../gravatarcreatejob.cpp" "kaddressbookprivate;pimcommon")
add_akonadi_isolated_test_advanced( gravatarupdatejobtest.cpp "../gravatarupdatejob.cpp" "kaddressbookprivate;pimcommon")
......@@ -19,6 +19,7 @@
*/
#include "gravatarcreatejob.h"
#include "pimcommon/gravatar/gravatarresolvurljob.h"
using namespace KABGravatar;
......@@ -40,7 +41,15 @@ bool GravatarCreateJob::canStart()
void GravatarCreateJob::start()
{
if (canStart()) {
PimCommon::GravatarResolvUrlJob *job = new PimCommon::GravatarResolvUrlJob(this);
job->setEmail(mEmail);
connect(job, SIGNAL(finished(PimCommon::GravatarResolvUrlJob*)), this, SLOT(slotGravatarResolvUrlFinished(PimCommon::GravatarResolvUrlJob*)));
connect(job, SIGNAL(resolvUrl(KUrl)), this, SIGNAL(resolvedUrl(KUrl)));
job->start();
} else {
deleteLater();
}
}
QString GravatarCreateJob::email() const
......@@ -53,4 +62,10 @@ void GravatarCreateJob::setEmail(const QString &email)
mEmail = email;
}
void GravatarCreateJob::slotGravatarResolvUrlFinished(PimCommon::GravatarResolvUrlJob *job)
{
if (job) {
Q_EMIT gravatarPixmap(job->pixmap());
}
deleteLater();
}
......@@ -22,7 +22,11 @@
#define GRAVATARCREATEJOB_H
#include <QObject>
#include <QUrl>
#include <KUrl>
namespace PimCommon {
class GravatarResolvUrlJob;
}
namespace KABGravatar {
class GravatarCreateJob : public QObject
......@@ -38,8 +42,13 @@ public:
QString email() const;
void setEmail(const QString &email);
Q_SIGNALS:
void resolvedUrl(const QUrl &url);
void resolvedUrl(const KUrl &url);
void gravatarPixmap(const QPixmap &pix);
private Q_SLOTS:
void slotGravatarResolvUrlFinished(PimCommon::GravatarResolvUrlJob *);
private:
QString mEmail;
......
......@@ -21,6 +21,8 @@
#include "gravatarupdatejob.h"
#include <gravatar/gravatarresolvurljob.h>
using namespace KABGravatar;
GravatarUpdateJob::GravatarUpdateJob(QObject *parent)
......@@ -36,6 +38,15 @@ GravatarUpdateJob::~GravatarUpdateJob()
void GravatarUpdateJob::start()
{
if (canStart()) {
PimCommon::GravatarResolvUrlJob *job = new PimCommon::GravatarResolvUrlJob(this);
job->setEmail(mEmail);
connect(job, SIGNAL(finished(PimCommon::GravatarResolvUrlJob*)), this, SLOT(slotGravatarResolvUrlFinished(PimCommon::GravatarResolvUrlJob*)));
connect(job, SIGNAL(resolvUrl(KUrl)), this, SIGNAL(resolvedUrl(KUrl)));
job->start();
} else {
deleteLater();
}
}
......@@ -64,3 +75,11 @@ void GravatarUpdateJob::setItem(const Akonadi::Item &item)
mItem = item;
}
void GravatarUpdateJob::slotGravatarResolvUrlFinished(PimCommon::GravatarResolvUrlJob *job)
{
if (job) {
Q_EMIT gravatarPixmap(job->pixmap());
}
deleteLater();
}
......@@ -24,7 +24,9 @@
#include <QObject>
#include <Akonadi/Item>
namespace PimCommon {
class GravatarResolvUrlJob;
}
namespace KABGravatar {
class GravatarUpdateJob : public QObject
{
......@@ -42,6 +44,13 @@ public:
Akonadi::Item item() const;
void setItem(const Akonadi::Item &item);
Q_SIGNALS:
void resolvedUrl(const KUrl &url);
void gravatarPixmap(const QPixmap &pix);
private Q_SLOTS:
void slotGravatarResolvUrlFinished(PimCommon::GravatarResolvUrlJob *job);
private:
QString mEmail;
Akonadi::Item mItem;
......
......@@ -72,6 +72,8 @@ using KMime::DateFormatter;
#include <QButtonGroup>
#include <QSpinBox>
#include <QLabel>
#include <widgets/gravatarconfigwidget.h>
using namespace MailCommon;
QString AppearancePage::helpAnchor() const
......@@ -917,17 +919,22 @@ AppearancePageReaderTab::AppearancePageReaderTab( QWidget * parent )
this, SLOT(slotEmitChanged()) );
topLayout->addWidget( mViewerSettings );
mGravatarConfigWidget = new MessageViewer::GravatarConfigWidget;
connect(mGravatarConfigWidget, SIGNAL(configChanged(bool)), this, SLOT(slotEmitChanged()));
topLayout->addWidget( mGravatarConfigWidget );
topLayout->addStretch( 100 ); // spacer
}
void AppearancePage::ReaderTab::doResetToDefaultsOther()
{
mGravatarConfigWidget->doResetToDefaultsOther();
}
void AppearancePage::ReaderTab::doLoadOther()
{
loadWidget( mCloseAfterReplyOrForwardCheck, GlobalSettings::self()->closeAfterReplyOrForwardItem() );
mViewerSettings->readConfig();
mGravatarConfigWidget->doLoadFromGlobalSettings();
}
......@@ -935,6 +942,7 @@ void AppearancePage::ReaderTab::save()
{
saveCheckBox( mCloseAfterReplyOrForwardCheck, GlobalSettings::self()->closeAfterReplyOrForwardItem() );
mViewerSettings->writeConfig();
mGravatarConfigWidget->save();
}
QString AppearancePage::SystemTrayTab::helpAnchor() const
......
......@@ -35,6 +35,7 @@ class KLineEdit;
class QModelIndex;
namespace MessageViewer {
class ConfigureWidget;
class GravatarConfigWidget;
}
namespace MessageList {
......@@ -170,6 +171,7 @@ private:
private: // data
QCheckBox *mCloseAfterReplyOrForwardCheck;
MessageViewer::ConfigureWidget *mViewerSettings;
MessageViewer::GravatarConfigWidget *mGravatarConfigWidget;
};
......
......@@ -69,7 +69,7 @@ void ContactDisplayMessageMemento::slotSearchJobFinished( KJob *job )
if (GlobalSettings::self()->gravatarSupportEnabled()) {
PimCommon::GravatarResolvUrlJob *job = new PimCommon::GravatarResolvUrlJob(this);
job->setEmail(mEmailAddress);
// Debug job->setUseDefaultPixmap(true);
job->setUseDefaultPixmap(GlobalSettings::self()->gravatarUseDefaultImage());
connect(job, SIGNAL(finished(PimCommon::GravatarResolvUrlJob*)), this, SLOT(slotGravatarResolvUrlFinished(PimCommon::GravatarResolvUrlJob*)));
job->start();
}
......@@ -104,9 +104,9 @@ bool ContactDisplayMessageMemento::searchPhoto(const KABC::AddresseeList &list)
}
return foundPhoto;
}
QPixmap ContactDisplayMessageMemento::gravatar() const
QPixmap ContactDisplayMessageMemento::gravatarPixmap() const
{
return mGravatar;
return mGravatarPixmap;
}
......@@ -139,7 +139,7 @@ KABC::Picture ContactDisplayMessageMemento::photo() const
void ContactDisplayMessageMemento::slotGravatarResolvUrlFinished(PimCommon::GravatarResolvUrlJob *job)
{
if (job && job->hasGravatar()) {
mGravatar = job->pixmap();
mGravatarPixmap = job->pixmap();
emit update( Viewer::Delayed );
}
}
......@@ -49,7 +49,7 @@ public:
void detach();
QPixmap gravatar() const;
QPixmap gravatarPixmap() const;
signals:
// TODO: Factor our update and detach into base class
......@@ -64,7 +64,7 @@ private:
bool searchPhoto(const KABC::AddresseeList &list);
Viewer::DisplayFormatMessage mForceDisplayTo;
KABC::Picture mPhoto;
QPixmap mGravatar;
QPixmap mGravatarPixmap;
QString mEmailAddress;
bool mFinished;
bool mMailAllowToRemoteContent;
......
......@@ -260,6 +260,22 @@ QList<KMime::Types::Mailbox> resentToList(KMime::Message *message)
return resentTo;
}
void updateXFaceSettings(QImage photo, xfaceSettings &settings)
{
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 );
}
}
xfaceSettings xface(const MessageViewer::HeaderStyle *style, KMime::Message *message)
{
......@@ -290,36 +306,14 @@ xfaceSettings xface(const MessageViewer::HeaderStyle *style, KMime::Message *mes
if ( photoMemento->photo().isIntern() ) {
// get photo data and convert to data: url
QImage photo = photoMemento->photo().data();
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 );
}
updateXFaceSettings(photo, settings);
} 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 (!photoMemento->gravatarPixmap().isNull()) {
QImage photo = photoMemento->gravatarPixmap().toImage();
updateXFaceSettings(photo, settings);
}
} else {
// if the memento is not finished yet, use other photo sources instead
......
......@@ -60,9 +60,9 @@ QList<KMime::Types::Mailbox> resentToList(KMime::Message *message);
struct xfaceSettings {
xfaceSettings()
: photoWidth(60),
photoHeight(60)
{
photoWidth = 60;
photoHeight = 60;
}
QString photoURL;
......@@ -71,6 +71,7 @@ struct xfaceSettings {
};
xfaceSettings xface(const HeaderStyle *style, KMime::Message *message);
void updateXFaceSettings(QImage photo, xfaceSettings &settings);
}
}
......
......@@ -193,6 +193,9 @@ xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 http://www.kde.org/sta
<entry name="GravatarSupportEnabled" type="Bool">
<default>true</default>
</entry>
<entry name="GravatarUseDefaultImage" type="Bool">
<default>false</default>
</entry>
</group>
<group name="TextIndex">
......
......@@ -36,6 +36,10 @@ void GravatarConfigWidgetTest::shouldHaveDefaultValue()
MessageViewer::GravatarConfigWidget w;
QCheckBox *checkBox = qFindChild<QCheckBox *>(&w, QLatin1String("gravatarcheckbox"));
QVERIFY(checkBox);
QCheckBox *useDefaultImage = qFindChild<QCheckBox *>(&w, QLatin1String("usedefaultimage"));
QVERIFY(useDefaultImage);
}
QTEST_KDEMAIN(GravatarConfigWidgetTest, GUI)
......@@ -38,6 +38,13 @@ GravatarConfigWidget::GravatarConfigWidget(QWidget *parent)
mEnableGravatarSupport->setObjectName(QLatin1String("gravatarcheckbox"));
mainLayout->addWidget(mEnableGravatarSupport);
//KF5 add i18n
mUseDefaultPixmap = new QCheckBox(QLatin1String("Use Default Image"));
mUseDefaultPixmap->setObjectName(QLatin1String("usedefaultimage"));
mainLayout->addWidget(mUseDefaultPixmap);
connect(mUseDefaultPixmap, SIGNAL(clicked(bool)), SIGNAL(configChanged(bool)));
connect(mEnableGravatarSupport, SIGNAL(clicked(bool)), SIGNAL(configChanged(bool)));
}
GravatarConfigWidget::~GravatarConfigWidget()
......@@ -48,18 +55,19 @@ GravatarConfigWidget::~GravatarConfigWidget()
void GravatarConfigWidget::save()
{
saveCheckBox(mEnableGravatarSupport, MessageViewer::GlobalSettings::self()->gravatarSupportEnabledItem());
saveCheckBox(mUseDefaultPixmap, MessageViewer::GlobalSettings::self()->gravatarUseDefaultImageItem());
}
void GravatarConfigWidget::doLoadFromGlobalSettings()
{
loadWidget(mEnableGravatarSupport, MessageViewer::GlobalSettings::self()->gravatarSupportEnabledItem());
loadWidget(mUseDefaultPixmap, MessageViewer::GlobalSettings::self()->gravatarUseDefaultImageItem());
}
void GravatarConfigWidget::doResetToDefaultsOther()
{
const bool bUseDefaults = MessageViewer::GlobalSettings::self()->useDefaults( true );
loadWidget(mEnableGravatarSupport, MessageViewer::GlobalSettings::self()->gravatarSupportEnabledItem());
doLoadFromGlobalSettings();
GlobalSettings::self()->useDefaults( bUseDefaults );
}
......@@ -32,8 +32,13 @@ public:
void save();
void doLoadFromGlobalSettings();
void doResetToDefaultsOther();
Q_SIGNALS:
void configChanged(bool);
private:
QCheckBox *mEnableGravatarSupport;
QCheckBox *mUseDefaultPixmap;
};
}
......
......@@ -61,6 +61,7 @@ void GravatarResolvUrlJob::start()
if (canStart()) {
mCalculatedHash.clear();
const KUrl url = createUrl();
Q_EMIT resolvUrl(url);
if (!mNetworkAccessManager) {
mNetworkAccessManager = new QNetworkAccessManager(this);
connect(mNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotFinishLoadPixmap(QNetworkReply*)));
......@@ -77,11 +78,11 @@ void GravatarResolvUrlJob::slotFinishLoadPixmap(QNetworkReply *reply)
{
if (reply->error() == QNetworkReply::NoError) {
mPixmap.loadFromData(reply->readAll());
qDebug()<<" pix.isnull"<<mPixmap.isNull();
mHasGravatar = true;
}
reply->deleteLater();
Q_EMIT finished(this);
deleteLater();
}
void GravatarResolvUrlJob::slotError(QNetworkReply::NetworkError error)
......
......@@ -56,6 +56,7 @@ public:
Q_SIGNALS:
void finished(PimCommon::GravatarResolvUrlJob *);
void resolvUrl(const KUrl &url);
private Q_SLOTS:
void slotFinishLoadPixmap(QNetworkReply *reply);
......
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