File indexing completed on 2024-05-12 16:59:41

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 <QImage>
0010 #include <QRunnable>
0011 
0012 #include "potdprovider.h"
0013 
0014 /**
0015  * This class provides pictures from the local cache.
0016  */
0017 class CachedProvider : public PotdProvider
0018 {
0019     Q_OBJECT
0020 
0021 public:
0022     /**
0023      * Creates a new cached provider.
0024      *
0025      * @param identifier The identifier of the cached picture.
0026      * @param args The arguments of the identifier.
0027      * @param parent The parent object.
0028      */
0029     CachedProvider(const QString &identifier, const QVariantList &args, QObject *parent);
0030 
0031     /**
0032      * Returns the identifier of the picture request (name + date).
0033      */
0034     QString identifier() const override;
0035 
0036     /**
0037      * Returns whether a picture with the given @p identifier and @p args is cached.
0038      */
0039     static bool isCached(const QString &identifier, const QVariantList &args, bool ignoreAge = false);
0040 
0041     /**
0042      * Returns a path for the given identifier
0043      */
0044     static QString identifierToPath(const QString &identifier, const QVariantList &args);
0045 
0046 private Q_SLOTS:
0047     void triggerFinished(const PotdProviderData &data);
0048 
0049 private:
0050     QString mIdentifier;
0051     QVariantList m_args;
0052 };
0053 
0054 class LoadImageThread : public QObject, public QRunnable
0055 {
0056     Q_OBJECT
0057 
0058 public:
0059     explicit LoadImageThread(const QString &filePath);
0060     void run() override;
0061 
0062 Q_SIGNALS:
0063     void done(const PotdProviderData &data);
0064 
0065 private:
0066     QString m_filePath;
0067 };
0068 
0069 class SaveImageThread : public QObject, public QRunnable
0070 {
0071     Q_OBJECT
0072 
0073 public:
0074     SaveImageThread(const QString &identifier, const QVariantList &args, const PotdProviderData &data);
0075     void run() override;
0076 
0077 Q_SIGNALS:
0078     void done(const QString &source, const PotdProviderData &data);
0079 
0080 private:
0081     QString m_identifier;
0082     QVariantList m_args;
0083     PotdProviderData m_data;
0084 };