Add back history view cover photos
This commit is contained in:
11 files changed
+476
-28
No files matched your search
@@ -4,6 +4,7 @@
|
||||
#include <QMutexLocker>
|
||||
#include <QQuickTextureFactory>
|
||||
#include <QThreadPool>
|
||||
#include <QUrl>
|
||||
|
||||
#include <minizip/unzip.h>
|
||||
|
||||
@@ -64,7 +65,20 @@ QQuickImageResponse *EpubImageProvider::requestImageResponse(const QString &id,
|
||||
displayWidth = m_displayWidth;
|
||||
}
|
||||
|
||||
auto *response = new EpubImageResponse(epubPath, id, displayWidth, requestedSize);
|
||||
// id may be "internal/path.jpg" (old format) or
|
||||
// "internal/path.jpg?epub=<percent-encoded-epub-path>" (new embedded format).
|
||||
QString internalPath = id;
|
||||
const int qmark = id.indexOf(QLatin1Char('?'));
|
||||
if (qmark >= 0) {
|
||||
internalPath = id.left(qmark);
|
||||
const QString query = id.mid(qmark + 1);
|
||||
// Parse epub=<value> from query string
|
||||
const QLatin1String key("epub=");
|
||||
if (query.startsWith(key))
|
||||
epubPath = QUrl::fromPercentEncoding(query.mid(key.size()).toUtf8());
|
||||
}
|
||||
|
||||
auto *response = new EpubImageResponse(epubPath, internalPath, displayWidth, requestedSize);
|
||||
QThreadPool::globalInstance()->start(response);
|
||||
return response;
|
||||
}
|
||||
@@ -119,16 +133,26 @@ QImage EpubImageProvider::load(const QUrl &url, int maxWidth) const
|
||||
{
|
||||
if (url.scheme() != QLatin1String("image"))
|
||||
return {};
|
||||
|
||||
QString zipPath = url.path();
|
||||
if (zipPath.startsWith(QLatin1Char('/')))
|
||||
zipPath = zipPath.mid(1);
|
||||
if (zipPath.isEmpty())
|
||||
return {};
|
||||
|
||||
QString epubPath;
|
||||
{
|
||||
if (url.hasQuery()) {
|
||||
// Embedded format: epub path is in the query string as epub=<encoded>
|
||||
const QString q = url.query();
|
||||
const QLatin1String key("epub=");
|
||||
if (q.startsWith(key))
|
||||
epubPath = QUrl::fromPercentEncoding(q.mid(key.size()).toUtf8());
|
||||
}
|
||||
if (epubPath.isEmpty()) {
|
||||
QMutexLocker lock(&m_mutex);
|
||||
epubPath = m_epubPath;
|
||||
}
|
||||
|
||||
return loadImageFromEpub(epubPath, zipPath, maxWidth, {});
|
||||
}
|
||||
|
||||
@@ -152,7 +176,11 @@ void EpubImageProvider::setFilePath(const QString &filePath)
|
||||
|
||||
QString EpubImageProvider::coverImageUrl(const QString &coverPath) const
|
||||
{
|
||||
return QStringLiteral("image://epub/") + coverPath;
|
||||
QString epubPath;
|
||||
{ QMutexLocker lock(&m_mutex); epubPath = m_epubPath; }
|
||||
return QStringLiteral("image://epub/") + coverPath
|
||||
+ QStringLiteral("?epub=")
|
||||
+ QString::fromUtf8(QUrl::toPercentEncoding(epubPath));
|
||||
}
|
||||
|
||||
QString EpubImageProvider::scheme() const
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "FileIconProvider.h"
|
||||
#include <QFileIconProvider>
|
||||
#include <QFileInfo>
|
||||
#include <QIcon>
|
||||
|
||||
FileIconProvider::FileIconProvider()
|
||||
: QQuickImageProvider(QQuickImageProvider::Image)
|
||||
{}
|
||||
|
||||
QImage FileIconProvider::requestImage(const QString &id, QSize *size,
|
||||
const QSize &requestedSize)
|
||||
{
|
||||
// QML strips the leading slash from the URL path component, so restore it on Unix.
|
||||
QString filePath = id.startsWith(QLatin1Char('/')) ? id : QLatin1Char('/') + id;
|
||||
|
||||
QFileIconProvider iconProvider;
|
||||
QIcon icon = iconProvider.icon(QFileInfo(filePath));
|
||||
if (icon.isNull())
|
||||
icon = iconProvider.icon(QFileIconProvider::File);
|
||||
|
||||
QSize target = (requestedSize.width() > 0 && requestedSize.height() > 0)
|
||||
? requestedSize : QSize(60, 80);
|
||||
|
||||
QImage image = icon.pixmap(target).toImage();
|
||||
if (size)
|
||||
*size = image.size();
|
||||
return image;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include <QQuickImageProvider>
|
||||
|
||||
// Serves OS file-type icons under image://fileicon/<absolute-file-path>
|
||||
class FileIconProvider : public QQuickImageProvider {
|
||||
public:
|
||||
FileIconProvider();
|
||||
QImage requestImage(const QString &id, QSize *size,
|
||||
const QSize &requestedSize) override;
|
||||
};
|
||||
Reference in new issue
Block a user