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

Allow to use default value

parent f8c97ce6
......@@ -37,6 +37,7 @@ void GravatarResolvUrlJobTest::shouldHaveDefaultValue()
QCOMPARE(job.size(), 80);
QCOMPARE(job.hasGravatar(), false);
QCOMPARE(job.pixmap().isNull(), true);
QCOMPARE(job.useDefaultPixmap(), false);
}
void GravatarResolvUrlJobTest::shouldChangeSize()
......@@ -71,6 +72,16 @@ void GravatarResolvUrlJobTest::shouldAddSizeInUrl()
QCOMPARE(url, KUrl("http://www.gravatar.com:80/avatar/89b4e14cf2fc6d426275c019c6dc9de6?d=404&s=1024"));
}
void GravatarResolvUrlJobTest::shouldUseDefaultPixmap()
{
PimCommon::GravatarResolvUrlJob job;
job.setEmail(QLatin1String("foo@kde.org"));
job.setSize(1024);
job.setUseDefaultPixmap(true);
KUrl url = job.generateGravatarUrl();
QCOMPARE(url, KUrl("http://www.gravatar.com:80/avatar/89b4e14cf2fc6d426275c019c6dc9de6?s=1024"));
}
void GravatarResolvUrlJobTest::shouldNotStart()
{
PimCommon::GravatarResolvUrlJob job;
......
......@@ -36,6 +36,8 @@ private Q_SLOTS:
void shouldChangeSize();
void shouldAddSizeInUrl();
void shouldUseDefaultPixmap();
};
#endif // GRAVATARRESOLVURLJOBTEST_H
......@@ -30,7 +30,8 @@ GravatarResolvUrlJob::GravatarResolvUrlJob(QObject *parent)
: QObject(parent),
mNetworkAccessManager(0),
mSize(80),
mHasGravatar(false)
mHasGravatar(false),
mUseDefaultPixmap(false)
{
}
......@@ -106,6 +107,16 @@ QString GravatarResolvUrlJob::calculateHash()
hash.addData(mEmail.toLower().toUtf8());
return QString::fromUtf8(hash.result().toHex());
}
bool GravatarResolvUrlJob::useDefaultPixmap() const
{
return mUseDefaultPixmap;
}
void GravatarResolvUrlJob::setUseDefaultPixmap(bool useDefaultPixmap)
{
mUseDefaultPixmap = useDefaultPixmap;
}
int GravatarResolvUrlJob::size() const
{
......@@ -145,8 +156,10 @@ KUrl GravatarResolvUrlJob::createUrl()
url.setPort(80);
mCalculatedHash = calculateHash();
url.setPath(QLatin1String("/avatar/") + mCalculatedHash);
//Add ?d=404
url.addQueryItem(QLatin1String("d"), QLatin1String("404"));
if (!mUseDefaultPixmap) {
//Add ?d=404
url.addQueryItem(QLatin1String("d"), QLatin1String("404"));
}
if (mSize != 80) {
url.addQueryItem(QLatin1String("s"), QString::number(mSize));
}
......
......@@ -50,6 +50,10 @@ public:
QPixmap pixmap() const;
bool useDefaultPixmap() const;
void setUseDefaultPixmap(bool useDefaultPixmap);
Q_SIGNALS:
void urlResolved(const KUrl &url);
......@@ -66,6 +70,7 @@ private:
QNetworkAccessManager *mNetworkAccessManager;
int mSize;
bool mHasGravatar;
bool mUseDefaultPixmap;
};
}
......
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