File indexing completed on 2024-09-15 04:49:45
0001 /* 0002 * SPDX-FileCopyrightText: 2007 Tobias Koenig <tokoe@kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QRunnable> 0010 0011 #include "potdprovider.h" 0012 0013 struct PotdProviderData { 0014 QUrl remoteUrl; 0015 QUrl infoUrl; 0016 QString localPath; 0017 QString title; 0018 QString author; 0019 QImage image; 0020 }; 0021 Q_DECLARE_METATYPE(PotdProviderData) 0022 0023 class LoadImageDataThread : public QObject, public QRunnable 0024 { 0025 Q_OBJECT 0026 0027 public: 0028 explicit LoadImageDataThread(const QString &filePath); 0029 void run() override; 0030 0031 Q_SIGNALS: 0032 void done(const PotdProviderData &data); 0033 0034 private: 0035 QString m_localPath; 0036 }; 0037 0038 /** 0039 * This class provides pictures from the local cache. 0040 */ 0041 class CachedProvider : public PotdProvider 0042 { 0043 Q_OBJECT 0044 0045 public: 0046 /** 0047 * Creates a new cached provider. 0048 * 0049 * @param identifier The identifier of the cached picture. 0050 * @param args The arguments of the identifier. 0051 * @param parent The parent object. 0052 */ 0053 CachedProvider(const QString &identifier, const QVariantList &args, QObject *parent); 0054 0055 /** 0056 * Returns the identifier of the picture request (name + date). 0057 */ 0058 QString identifier() const override; 0059 0060 QString localPath() const override; 0061 0062 /** 0063 * Returns whether a picture with the given @p identifier and @p args is cached. 0064 */ 0065 static bool isCached(const QString &identifier, const QVariantList &args, bool ignoreAge = false); 0066 0067 /** 0068 * Returns a path for the given identifier 0069 */ 0070 static QString identifierToPath(const QString &identifier, const QVariantList &args); 0071 0072 private Q_SLOTS: 0073 void slotFinished(const PotdProviderData &data); 0074 0075 private: 0076 QString mIdentifier; 0077 QVariantList m_args; 0078 QString m_localPath; 0079 }; 0080 0081 class SaveImageThread : public QObject, public QRunnable 0082 { 0083 Q_OBJECT 0084 0085 public: 0086 SaveImageThread(const QString &identifier, const QVariantList &args, const PotdProviderData &data); 0087 void run() override; 0088 0089 Q_SIGNALS: 0090 void done(const QString &localPath); 0091 0092 private: 0093 QString m_identifier; 0094 QVariantList m_args; 0095 PotdProviderData m_data; 0096 };