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

improve gravatar support

parent fb50a730
......@@ -7,4 +7,4 @@ set(KDEPIMLIBS_RUN_ISOLATED_TESTS TRUE)
set(KDEPIMLIBS_RUN_SQLITE_ISOLATED_TESTS TRUE)
add_akonadi_isolated_test_advanced( gravatarcreatejobtest.cpp "../gravatarcreatejob.cpp" "kaddressbookprivate;pimcommon")
add_akonadi_isolated_test_advanced( gravatarupdatejobtest.cpp "../gravatarupdatejob.cpp" "kaddressbookprivate;pimcommon")
add_akonadi_isolated_test_advanced( gravatarupdatejobtest.cpp "../gravatarupdatejob.cpp" "kaddressbookprivate;pimcommon;kabc")
......@@ -41,9 +41,9 @@ bool GravatarCreateJob::canStart()
void GravatarCreateJob::start()
{
if (canStart()) {
PimCommon::GravatarResolvUrlJob *job = new PimCommon::GravatarResolvUrlJob(this);
job->setEmail(mEmail);
PimCommon::GravatarResolvUrlJob *job = new PimCommon::GravatarResolvUrlJob(this);
job->setEmail(mEmail);
if (job->canStart()) {
connect(job, SIGNAL(finished(PimCommon::GravatarResolvUrlJob*)), this, SLOT(slotGravatarResolvUrlFinished(PimCommon::GravatarResolvUrlJob*)));
connect(job, SIGNAL(resolvUrl(KUrl)), this, SIGNAL(resolvedUrl(KUrl)));
job->start();
......
......@@ -23,6 +23,10 @@
#include <gravatar/gravatarresolvurljob.h>
#include <KABC/Addressee>
#include <Akonadi/ItemModifyJob>
#include <QDebug>
using namespace KABGravatar;
GravatarUpdateJob::GravatarUpdateJob(QObject *parent)
......@@ -41,9 +45,13 @@ 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();
if (job->canStart()) {
connect(job, SIGNAL(finished(PimCommon::GravatarResolvUrlJob*)), this, SLOT(slotGravatarResolvUrlFinished(PimCommon::GravatarResolvUrlJob*)));
connect(job, SIGNAL(resolvUrl(KUrl)), this, SIGNAL(resolvedUrl(KUrl)));
job->start();
} else {
deleteLater();
}
} else {
deleteLater();
}
......@@ -90,6 +98,23 @@ void GravatarUpdateJob::slotGravatarResolvUrlFinished(PimCommon::GravatarResolvU
void GravatarUpdateJob::updatePixmap(const QPixmap &pix)
{
//TODO
if (mItem.hasPayload<KABC::Addressee>()) {
KABC::Addressee contact = mItem.payload<KABC::Addressee>();
contact.photo().setData(pix.toImage());
mItem.setPayload<KABC::Addressee>( contact );
// save the new item in akonadi storage
Akonadi::ItemModifyJob *modifyJob = new Akonadi::ItemModifyJob(mItem);
connect(modifyJob, SIGNAL(result(KJob*)), SLOT(slotUpdateGravatarDone(KJob*)));
} else {
deleteLater();
}
}
void GravatarUpdateJob::slotUpdateGravatarDone(KJob *job)
{
if (job->error()) {
qDebug() << "Error during modify item :"<<job->errorString();
}
deleteLater();
}
......@@ -51,6 +51,7 @@ Q_SIGNALS:
private Q_SLOTS:
void slotGravatarResolvUrlFinished(PimCommon::GravatarResolvUrlJob *job);
void slotUpdateGravatarDone(KJob *job);
private:
void updatePixmap(const QPixmap &pix);
QString mEmail;
......
......@@ -64,6 +64,7 @@ QPixmap GravatarCache::loadGravatarPixmap(const QString &hashStr, bool &gravatar
if (!hashStr.isEmpty()) {
if (mCachePixmap.contains(hashStr)) {
qDebug()<<" contains in cache "<< hashStr;
gravatarStored = true;
return mCachePixmap.value(hashStr);
} else {
const QString path = KGlobal::dirs()->locateLocal("data", QLatin1String("gravatar/") + hashStr + QLatin1String(".png"));
......
......@@ -46,10 +46,11 @@ GravatarResolvUrlJob::~GravatarResolvUrlJob()
bool GravatarResolvUrlJob::canStart() const
{
if ( Solid::Networking::status() == Solid::Networking::Unconnected ) {
if ( Solid::Networking::status() == Solid::Networking::Connected || Solid::Networking::status() == Solid::Networking::Unknown) {
return !mEmail.trimmed().isEmpty() && (mEmail.contains(QLatin1Char('@')));
} else {
return false;
}
return !mEmail.trimmed().isEmpty() && (mEmail.contains(QLatin1Char('@')));
}
KUrl GravatarResolvUrlJob::generateGravatarUrl()
......@@ -75,17 +76,18 @@ void GravatarResolvUrlJob::start()
Q_EMIT finished(this);
deleteLater();
} else {
if ( Solid::Networking::status() == Solid::Networking::Unconnected ) {
if ( Solid::Networking::status() == Solid::Networking::Connected || Solid::Networking::status() == Solid::Networking::Unknown) {
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 {
qDebug() <<" network is not connected";
deleteLater();
return;
}
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 {
qDebug() << "Gravatar can not start";
......
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