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

Add support for define size

parent ab8ab2e7
......@@ -34,6 +34,39 @@ void GravatarResolvUrlJobTest::shouldHaveDefaultValue()
{
PimCommon::GravatarResolvUrlJob job;
QVERIFY(job.email().isEmpty());
QCOMPARE(job.size(), 80);
}
void GravatarResolvUrlJobTest::shouldChangeSize()
{
PimCommon::GravatarResolvUrlJob job;
int size = 50;
job.setSize(size);
QCOMPARE(job.size(), size);
size = 0;
job.setSize(size);
QCOMPARE(job.size(), 80);
size = 10;
job.setSize(size);
QCOMPARE(job.size(), size);
size = 2048;
job.setSize(size);
QCOMPARE(job.size(), size);
size = 4096;
job.setSize(size);
QCOMPARE(job.size(), 2048);
}
void GravatarResolvUrlJobTest::shouldAddSizeInUrl()
{
PimCommon::GravatarResolvUrlJob job;
job.setEmail(QLatin1String("foo@kde.org"));
job.setSize(1024);
KUrl url = job.generateGravatarUrl();
QCOMPARE(url, KUrl("http://www.gravatar.com:80/avatar/89b4e14cf2fc6d426275c019c6dc9de6?d=404&s=1024"));
}
void GravatarResolvUrlJobTest::shouldNotStart()
......
......@@ -33,6 +33,9 @@ private Q_SLOTS:
void shouldGenerateGravatarUrl_data();
void shouldGenerateGravatarUrl();
void shouldChangeSize();
void shouldAddSizeInUrl();
};
#endif // GRAVATARRESOLVURLJOBTEST_H
......@@ -26,7 +26,8 @@
using namespace PimCommon;
GravatarResolvUrlJob::GravatarResolvUrlJob(QObject *parent)
: QObject(parent)
: QObject(parent),
mSize(80)
{
}
......@@ -81,6 +82,21 @@ QString GravatarResolvUrlJob::calculateHash()
return QString::fromUtf8(hash.result().toHex());
}
int GravatarResolvUrlJob::size() const
{
return mSize;
}
void GravatarResolvUrlJob::setSize(int size)
{
if (size <= 0) {
size = 80;
} else if (size > 2048) {
size = 2048;
}
mSize = size;
}
QString GravatarResolvUrlJob::calculatedHash() const
{
return mCalculatedHash;
......@@ -101,5 +117,8 @@ KUrl GravatarResolvUrlJob::createUrl()
url.setPath(QLatin1String("/avatar/") + mCalculatedHash);
//Add ?d=404
url.addQueryItem(QLatin1String("d"), QLatin1String("404"));
if (mSize != 80) {
url.addQueryItem(QLatin1String("s"), QString::number(mSize));
}
return url;
}
......@@ -38,11 +38,14 @@ public:
KUrl generateGravatarUrl();
bool hasGravatar() const;
QString calculatedHash() const;
void setSize(int size);
int size() const;
Q_SIGNALS:
void urlResolved(const KUrl &url);
......@@ -51,6 +54,7 @@ private:
QString calculateHash();
QString mEmail;
QString mCalculatedHash;
int mSize;
};
}
......
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