summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2015-05-12 07:09:43 +0200
committerMontel Laurent <[email protected]>2015-05-12 07:09:43 +0200
commit1d427e91bc1e608515781a334c896fc4f73c97f9 (patch)
tree73cc562fdf0e6c63d74e09783768d769470aa959
parentab8ab2e7a78227d68dc43472bf0af40d904a3360 (diff)
Add support for define size
-rw-r--r--pimcommon/gravatar/autotests/gravatarresolvurljobtest.cpp33
-rw-r--r--pimcommon/gravatar/autotests/gravatarresolvurljobtest.h3
-rw-r--r--pimcommon/gravatar/gravatarresolvurljob.cpp21
-rw-r--r--pimcommon/gravatar/gravatarresolvurljob.h6
4 files changed, 61 insertions, 2 deletions
diff --git a/pimcommon/gravatar/autotests/gravatarresolvurljobtest.cpp b/pimcommon/gravatar/autotests/gravatarresolvurljobtest.cpp
index b4e4bbf..80d17a7 100644
--- a/pimcommon/gravatar/autotests/gravatarresolvurljobtest.cpp
+++ b/pimcommon/gravatar/autotests/gravatarresolvurljobtest.cpp
@@ -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("[email protected]"));
+ job.setSize(1024);
+ KUrl url = job.generateGravatarUrl();
+ QCOMPARE(url, KUrl("http://www.gravatar.com:80/avatar/89b4e14cf2fc6d426275c019c6dc9de6?d=404&s=1024"));
}
void GravatarResolvUrlJobTest::shouldNotStart()
diff --git a/pimcommon/gravatar/autotests/gravatarresolvurljobtest.h b/pimcommon/gravatar/autotests/gravatarresolvurljobtest.h
index 12728cd..2e8bddf 100644
--- a/pimcommon/gravatar/autotests/gravatarresolvurljobtest.h
+++ b/pimcommon/gravatar/autotests/gravatarresolvurljobtest.h
@@ -33,6 +33,9 @@ private Q_SLOTS:
void shouldGenerateGravatarUrl_data();
void shouldGenerateGravatarUrl();
+ void shouldChangeSize();
+
+ void shouldAddSizeInUrl();
};
#endif // GRAVATARRESOLVURLJOBTEST_H
diff --git a/pimcommon/gravatar/gravatarresolvurljob.cpp b/pimcommon/gravatar/gravatarresolvurljob.cpp
index 7e3b169..0779078 100644
--- a/pimcommon/gravatar/gravatarresolvurljob.cpp
+++ b/pimcommon/gravatar/gravatarresolvurljob.cpp
@@ -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;
}
diff --git a/pimcommon/gravatar/gravatarresolvurljob.h b/pimcommon/gravatar/gravatarresolvurljob.h
index d0be12d..8adeaca 100644
--- a/pimcommon/gravatar/gravatarresolvurljob.h
+++ b/pimcommon/gravatar/gravatarresolvurljob.h
@@ -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;
};
}