reintroduced epub support
This commit is contained in:
49 files changed
+5048
-205
No files matched your search
@@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QImage>
|
||||
#include <QMutex>
|
||||
#include <QQuickAsyncImageProvider>
|
||||
#include <QString>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
class IWebImageStorage {
|
||||
public:
|
||||
virtual ~IWebImageStorage() = default;
|
||||
virtual bool contains(const QString &key) const = 0;
|
||||
virtual QByteArray read(const QString &key) const = 0;
|
||||
virtual bool write(const QString &key, const QByteArray &data) = 0;
|
||||
};
|
||||
|
||||
class DiskWebImageStorage : public IWebImageStorage {
|
||||
public:
|
||||
DiskWebImageStorage();
|
||||
explicit DiskWebImageStorage(QString baseDir);
|
||||
|
||||
bool contains(const QString &key) const override;
|
||||
QByteArray read(const QString &key) const override;
|
||||
bool write(const QString &key, const QByteArray &data) override;
|
||||
|
||||
QString cacheDir() const { return m_baseDir; }
|
||||
|
||||
private:
|
||||
QString filePathForKey(const QString &key) const;
|
||||
QString m_baseDir;
|
||||
mutable QMutex m_mutex;
|
||||
};
|
||||
|
||||
class WebImageProvider : public QQuickAsyncImageProvider {
|
||||
public:
|
||||
using HttpFetcher = std::function<QByteArray(const QString &url)>;
|
||||
|
||||
WebImageProvider();
|
||||
explicit WebImageProvider(std::shared_ptr<IWebImageStorage> storage,
|
||||
HttpFetcher fetcher = nullptr);
|
||||
|
||||
QQuickImageResponse *requestImageResponse(const QString &id,
|
||||
const QSize &requestedSize) override;
|
||||
|
||||
QString scheme() const { return QStringLiteral("web"); }
|
||||
|
||||
static QString cacheKey(const QString &url);
|
||||
|
||||
// Synchronous download or cache lookup (safe across threads)
|
||||
QImage fetchImage(const QString &url, const QSize &requestedSize = {});
|
||||
|
||||
// Set custom storage & fetcher (e.g. for unit tests)
|
||||
void setStorage(std::shared_ptr<IWebImageStorage> storage);
|
||||
void setFetcher(HttpFetcher fetcher);
|
||||
|
||||
// Global default instance for non-QML direct resolution
|
||||
static WebImageProvider *defaultInstance();
|
||||
|
||||
private:
|
||||
std::shared_ptr<IWebImageStorage> m_storage;
|
||||
HttpFetcher m_fetcher;
|
||||
mutable QMutex m_imageMutex;
|
||||
QHash<QString, QImage> m_memoryCache;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user