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

Return hash value

parent 538fc83b
......@@ -55,19 +55,22 @@ void GravatarResolvUrlJobTest::shouldNotStart()
void GravatarResolvUrlJobTest::shouldGenerateGravatarUrl_data()
{
QTest::addColumn<QString>("input");
QTest::addColumn<QString>("calculedhash");
QTest::addColumn<KUrl>("output");
QTest::newRow("empty") << QString() << KUrl();
QTest::newRow("no domain") << QString(QLatin1String("foo")) << KUrl();
QTest::newRow("validemail") << QString(QLatin1String("foo@kde.org")) << KUrl("http://www.gravatar.com:80/avatar/89b4e14cf2fc6d426275c019c6dc9de6?d=404");
QTest::newRow("empty") << QString() << QString() << KUrl();
QTest::newRow("no domain") << QString(QLatin1String("foo")) << QString() << KUrl();
QTest::newRow("validemail") << QString(QLatin1String("foo@kde.org")) << QString(QLatin1String("89b4e14cf2fc6d426275c019c6dc9de6")) << KUrl("http://www.gravatar.com:80/avatar/89b4e14cf2fc6d426275c019c6dc9de6?d=404");
}
void GravatarResolvUrlJobTest::shouldGenerateGravatarUrl()
{
QFETCH( QString, input );
QFETCH( QString, calculedhash);
QFETCH( KUrl, output );
PimCommon::GravatarResolvUrlJob job;
job.setEmail(input);
KUrl url = job.generateGravatarUrl();
QCOMPARE(calculedhash, job.calculatedHash());
QCOMPARE(url, output);
}
......
......@@ -55,6 +55,7 @@ bool GravatarResolvUrlJob::hasGravatar() const
void GravatarResolvUrlJob::start()
{
if (canStart()) {
mCalculatedHash.clear();
const KUrl url = createUrl();
} else {
//TODO return message Error.
......@@ -80,8 +81,15 @@ QString GravatarResolvUrlJob::calculateHash()
return QString::fromUtf8(hash.result().toHex());
}
QString GravatarResolvUrlJob::calculatedHash() const
{
return mCalculatedHash;
}
KUrl GravatarResolvUrlJob::createUrl()
{
mCalculatedHash.clear();
if (!canStart()) {
return KUrl();
}
......@@ -89,7 +97,8 @@ KUrl GravatarResolvUrlJob::createUrl()
url.setScheme(QLatin1String("http"));
url.setHost(QLatin1String("www.gravatar.com"));
url.setPort(80);
url.setPath(QLatin1String("/avatar/") + calculateHash());
mCalculatedHash = calculateHash();
url.setPath(QLatin1String("/avatar/") + mCalculatedHash);
//Add ?d=404
url.addQueryItem(QLatin1String("d"), QLatin1String("404"));
return url;
......
......@@ -41,6 +41,8 @@ public:
bool hasGravatar() const;
QString calculatedHash() const;
Q_SIGNALS:
void urlResolved(const KUrl &url);
......@@ -48,6 +50,7 @@ private:
KUrl createUrl();
QString calculateHash();
QString mEmail;
QString mCalculatedHash;
};
}
......
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