summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-07-13 02:45:01 (GMT)
committerMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-07-13 02:45:01 (GMT)
commit7490f37291b3424ee08d2a19f330e173792803bf (patch)
treef2e71d2e48c7c3a1985e03ce76b0084d4ed895fc
parent89e5f175426aea6139c118d11e26386f60572c1b (diff)
Fix loading of embedded resources in epubs
This works with all the .epubs I have locally and from various bug reports.
-rw-r--r--generators/epub/epubdocument.cpp20
-rw-r--r--generators/epub/epubdocument.h2
2 files changed, 7 insertions, 15 deletions
diff --git a/generators/epub/epubdocument.cpp b/generators/epub/epubdocument.cpp
index c101159..c3f9506 100644
--- a/generators/epub/epubdocument.cpp
+++ b/generators/epub/epubdocument.cpp
@@ -16,18 +16,6 @@
Q_LOGGING_CATEGORY(OkularEpuDebug, "org.kde.okular.generators.epu")
using namespace Epub;
-namespace {
-
-QString resourceUrl(const QUrl &baseUrl, const QString &u)
-{
- QUrl newUrl(baseUrl.adjusted(QUrl::RemoveFilename).path() + QLatin1Char('/') + u);
- QString newDir = newUrl.toLocalFile();
- newDir.remove(0, 1);
- return newDir;
-}
-
-}
-
EpubDocument::EpubDocument(const QString &fileName) : QTextDocument(),
padding(20)
{
@@ -56,7 +44,11 @@ struct epub *EpubDocument::getEpub()
void EpubDocument::setCurrentSubDocument(const QString &doc)
{
- mCurrentSubDocument = QUrl::fromLocalFile(QLatin1Char('/') + doc);
+ mCurrentSubDocument.clear();
+ int index = doc.indexOf('/');
+ if (index > 0) {
+ mCurrentSubDocument = doc.left(index);
+ }
}
int EpubDocument::maxContentHeight() const
@@ -81,7 +73,7 @@ QVariant EpubDocument::loadResource(int type, const QUrl &name)
char *data;
// Get the data from the epub file
- size = epub_get_data(mEpub, resourceUrl(mCurrentSubDocument, name.toString()).toUtf8().constData(), &data);
+ size = epub_get_data(mEpub, (mCurrentSubDocument + name.toString()).toUtf8().constData(), &data);
QVariant resource;
diff --git a/generators/epub/epubdocument.h b/generators/epub/epubdocument.h
index d428fb3..132f067 100644
--- a/generators/epub/epubdocument.h
+++ b/generators/epub/epubdocument.h
@@ -39,7 +39,7 @@ namespace Epub {
void checkCSS(QString &css);
struct epub *mEpub;
- QUrl mCurrentSubDocument;
+ QString mCurrentSubDocument;
int padding;