gravatarresolvurljob.h 1.71 KB
Newer Older
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
   SPDX-FileCopyrightText: 2015-2021 Laurent Montel <montel@kde.org>
3
4

   SPDX-License-Identifier: LGPL-2.0-or-later
5
6
*/

7
#pragma once
8
9
10
11

#include "gravatar_export.h"
#include <QObject>
#include <QPixmap>
Laurent Montel's avatar
Laurent Montel committed
12
#include <QUrl>
Laurent Montel's avatar
Laurent Montel committed
13
class QNetworkReply;
14
class GravatarResolvUrlJobTest;
Laurent Montel's avatar
Laurent Montel committed
15
16
namespace Gravatar
{
17
class GravatarResolvUrlJobPrivate;
18
19
class Hash;

20
/** Avartar lookup job. */
21
22
23
24
class GRAVATAR_EXPORT GravatarResolvUrlJob : public QObject
{
    Q_OBJECT
public:
Laurent Montel's avatar
Laurent Montel committed
25
    explicit GravatarResolvUrlJob(QObject *parent = nullptr);
26
27
    ~GravatarResolvUrlJob();

Laurent Montel's avatar
Laurent Montel committed
28
    Q_REQUIRED_RESULT bool canStart() const;
29
30
    void start();

Laurent Montel's avatar
Laurent Montel committed
31
    Q_REQUIRED_RESULT QString email() const;
32
33
    void setEmail(const QString &email);

Laurent Montel's avatar
Laurent Montel committed
34
    Q_REQUIRED_RESULT bool hasGravatar() const;
35
36

    void setSize(int size);
Laurent Montel's avatar
Laurent Montel committed
37
    Q_REQUIRED_RESULT int size() const;
38

Laurent Montel's avatar
Laurent Montel committed
39
    Q_REQUIRED_RESULT QPixmap pixmap() const;
40

Laurent Montel's avatar
Laurent Montel committed
41
    Q_REQUIRED_RESULT bool useDefaultPixmap() const;
42
43
    void setUseDefaultPixmap(bool useDefaultPixmap);

Laurent Montel's avatar
Laurent Montel committed
44
45
46
47
48
49
    bool useLibravatar() const;
    void setUseLibravatar(bool useLibravatar);

    bool fallbackGravatar() const;
    void setFallbackGravatar(bool fallbackGravatar);

50
51
52
53
54
Q_SIGNALS:
    void finished(Gravatar::GravatarResolvUrlJob *);
    void resolvUrl(const QUrl &url);

private:
55
56
    friend class ::GravatarResolvUrlJobTest;

Laurent Montel's avatar
Laurent Montel committed
57
    void slotFinishLoadPixmap(QNetworkReply *reply);
Laurent Montel's avatar
Laurent Montel committed
58
59
    Q_REQUIRED_RESULT QUrl generateGravatarUrl(bool useLibravatar);
    Q_REQUIRED_RESULT Hash calculatedHash() const;
60
    void processNextBackend();
61
    void startNetworkManager(const QUrl &url);
Laurent Montel's avatar
Laurent Montel committed
62
63
64
    Q_REQUIRED_RESULT QUrl createUrl(bool useLibravatar);
    Q_REQUIRED_RESULT Hash calculateHash();
    Q_REQUIRED_RESULT bool cacheLookup(const Hash &hash);
65
66
67
68
    GravatarResolvUrlJobPrivate *const d;
};
}