File indexing completed on 2024-11-24 04:49:03
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "gravatar_export.h" 0010 #include <QObject> 0011 #include <QPixmap> 0012 #include <QUrl> 0013 0014 #include <memory> 0015 0016 class QNetworkReply; 0017 class GravatarResolvUrlJobTest; 0018 namespace Gravatar 0019 { 0020 class GravatarResolvUrlJobPrivate; 0021 class Hash; 0022 0023 /** Avartar lookup job. */ 0024 class GRAVATAR_EXPORT GravatarResolvUrlJob : public QObject 0025 { 0026 Q_OBJECT 0027 public: 0028 explicit GravatarResolvUrlJob(QObject *parent = nullptr); 0029 ~GravatarResolvUrlJob() override; 0030 0031 [[nodiscard]] bool canStart() const; 0032 void start(); 0033 0034 [[nodiscard]] QString email() const; 0035 void setEmail(const QString &email); 0036 0037 [[nodiscard]] bool hasGravatar() const; 0038 0039 void setSize(int size); 0040 [[nodiscard]] int size() const; 0041 0042 [[nodiscard]] QPixmap pixmap() const; 0043 0044 [[nodiscard]] bool useDefaultPixmap() const; 0045 void setUseDefaultPixmap(bool useDefaultPixmap); 0046 0047 bool useLibravatar() const; 0048 void setUseLibravatar(bool useLibravatar); 0049 0050 bool fallbackGravatar() const; 0051 void setFallbackGravatar(bool fallbackGravatar); 0052 0053 Q_SIGNALS: 0054 void finished(Gravatar::GravatarResolvUrlJob *); 0055 void resolvUrl(const QUrl &url); 0056 0057 private: 0058 friend class ::GravatarResolvUrlJobTest; 0059 0060 void slotFinishLoadPixmap(QNetworkReply *reply); 0061 [[nodiscard]] QUrl generateGravatarUrl(bool useLibravatar); 0062 [[nodiscard]] Hash calculatedHash() const; 0063 GRAVATAR_NO_EXPORT void processNextBackend(); 0064 GRAVATAR_NO_EXPORT void startNetworkManager(const QUrl &url); 0065 [[nodiscard]] GRAVATAR_NO_EXPORT QUrl createUrl(bool useLibravatar); 0066 [[nodiscard]] GRAVATAR_NO_EXPORT Hash calculateHash(); 0067 [[nodiscard]] GRAVATAR_NO_EXPORT bool cacheLookup(const Hash &hash); 0068 0069 std::unique_ptr<GravatarResolvUrlJobPrivate> const d; 0070 }; 0071 }