fb2 support
This commit is contained in:
18 files changed
+2352
-54
No files matched your search
@@ -4,9 +4,11 @@
|
||||
#include "backend/FormatReader.h"
|
||||
#include "backend/formats/comic/ComicReader.h"
|
||||
#include "backend/formats/EpubReader.h"
|
||||
#include "backend/formats/Fb2Reader.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QQmlEngine>
|
||||
#include <QSet>
|
||||
|
||||
FormatSpec FormatSpec::comic(const QString &ext, bool matchesDirectory, const QString &scheme,
|
||||
SourceFactory makeSource)
|
||||
@@ -31,6 +33,17 @@ FormatSpec FormatSpec::epub(SourceFactory makeSource)
|
||||
};
|
||||
}
|
||||
|
||||
FormatSpec FormatSpec::fb2(const QString &ext, SourceFactory makeSource)
|
||||
{
|
||||
return FormatSpec{
|
||||
ext,
|
||||
false,
|
||||
QStringLiteral("fb2"),
|
||||
[makeSource] { return std::make_unique<Fb2Reader>(makeSource, QStringLiteral("fb2")); },
|
||||
makeSource
|
||||
};
|
||||
}
|
||||
|
||||
FormatRegistry::FormatRegistry(QVector<FormatSpec> specs)
|
||||
: m_specs(std::move(specs))
|
||||
{
|
||||
@@ -40,11 +53,16 @@ const FormatSpec *FormatRegistry::specFor(const QString &filePath) const
|
||||
{
|
||||
const QFileInfo fi(filePath);
|
||||
const bool isDir = fi.isDir();
|
||||
const QString ext = fi.suffix().toLower();
|
||||
const QString lowerPath = filePath.toLower();
|
||||
|
||||
for (const FormatSpec &spec : m_specs) {
|
||||
if (isDir ? spec.matchesDirectory : (!spec.matchesDirectory && spec.extension == ext))
|
||||
return &spec;
|
||||
if (isDir) {
|
||||
if (spec.matchesDirectory)
|
||||
return &spec;
|
||||
} else if (!spec.matchesDirectory) {
|
||||
if (lowerPath.endsWith(QLatin1Char('.') + spec.extension.toLower()))
|
||||
return &spec;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -75,9 +93,12 @@ QStringList FormatRegistry::supportedExtensions() const
|
||||
|
||||
void FormatRegistry::registerImageProviders(QQmlEngine &engine) const
|
||||
{
|
||||
QSet<QString> registeredSchemes;
|
||||
for (const FormatSpec &spec : m_specs) {
|
||||
if (!spec.scheme.isEmpty() && spec.makeSource)
|
||||
if (!spec.scheme.isEmpty() && spec.makeSource && !registeredSchemes.contains(spec.scheme)) {
|
||||
registeredSchemes.insert(spec.scheme);
|
||||
engine.addImageProvider(spec.scheme,
|
||||
new EntryImageProvider(spec.makeSource, spec.scheme));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user