diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,10 +87,10 @@ PURPOSE "Extended attribute shared library") endif() -#find_package(QMobipocket) -#set_package_properties(QMobipocket PROPERTIES DESCRIPTION "Mobipocket epub reader" -# URL "https://projects.kde.org/projects/kde/kdegraphics/kdegraphics-mobipocket" -# TYPE OPTIONAL PURPOSE "Support for mobi metadata") +find_package(QMobipocket) +set_package_properties(QMobipocket PROPERTIES DESCRIPTION "Mobipocket epub reader" + URL "https://phabricator.kde.org/source/kdegraphics-mobipocket/" TYPE OPTIONAL + PURPOSE "Support for mobi metadata") add_definitions(-DTRANSLATION_DOMAIN=\"kfilemetadata5\") diff --git a/autotests/mobiextractortest.cpp b/autotests/mobiextractortest.cpp --- a/autotests/mobiextractortest.cpp +++ b/autotests/mobiextractortest.cpp @@ -21,11 +21,13 @@ #include "mobiextractortest.h" #include "simpleextractionresult.h" #include "indexerextractortestsconfig.h" -#include "extractors/epubextractor.h" +#include "extractors/mobiextractor.h" #include #include #include +#include +#include using namespace KFileMetaData; @@ -36,25 +38,24 @@ void MobiExtractorTest::test() { - EPubExtractor plugin{this}; + MobiExtractor plugin{this}; - SimpleExtractionResult result(testFilePath("test.mobi"), "application/epub+zip"); + QMimeDatabase mimeDB; + QString testFile = testFilePath("test.mobi"); + + SimpleExtractionResult result(testFile, "application/x-mobipocket-ebook"); plugin.extract(&result); + QVERIFY(plugin.mimetypes().contains(mimeDB.mimeTypeForFile(testFile).name())); + QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().first(), Type::Document); - // We're doing a contains instead of an exact check cause the epub file contains - // a ton of css and other garbage. - QVERIFY(result.text().contains(QStringLiteral("This is a sample PDF file for KFileMetaData."))); QCOMPARE(result.properties().value(Property::Author), QVariant(QStringLiteral("Happy Man"))); - QCOMPARE(result.properties().value(Property::Publisher), QVariant(QStringLiteral("Happy Publisher"))); QCOMPARE(result.properties().value(Property::Title), QVariant(QStringLiteral("The Big Brown Bear"))); QCOMPARE(result.properties().value(Property::Subject), QVariant(QStringLiteral("Baloo KFileMetaData"))); - - QDateTime dt(QDate(2014, 1, 1), QTime(1, 1, 1)); - dt.setTimeSpec(Qt::UTC); - QCOMPARE(result.properties().value(Property::CreationDate), QVariant(dt)); + QCOMPARE(result.properties().value(Property::Description), QVariant(QStringLiteral("Honey"))); + QCOMPARE(result.properties().value(Property::Copyright), QVariant(QStringLiteral("License"))); QCOMPARE(result.properties().size(), 5); } diff --git a/autotests/samplefiles/test.mobi b/autotests/samplefiles/test.mobi new file mode 100644 index 0000000000000000000000000000000000000000..cf9c11dff91882a49a1f2b1defb97419d2a53609 GIT binary patch literal 13653 zc%1E<2~bnl8h~$zEJ8qo0TIC2JWMVk*0p7h4ME)R)YG6|2kJRc%K!k@dNs}r25Naw?*KId)b5~GTFn8;2Vfgl8f*RkxawIN)fAY} zBt41$AYd#UO#L3z%Al-&Z}>8+z7II`JGNi(Uf&-AliV!;TkBtyO zC5M9N08o&t$u2~RAs7@>e_}9=6i(LKi8I7u4UP4+ys43q%m^zZqcsnPOkyzThW?BY zA8;f>Fh~6;m8=D>4y~2dp|!R;B=f)3ju^~fXgTet1(RLKk;J{kNFrzs17(+gpc#%B z=ugJruolJ`Q!@*53~4tp5JR#sGbWQPc9YCWI53X+-k_}hSPpDfvRL-nxjBJ42$bz6 z##mE~F%~?I8e^?i4g+IjD`R8O*#@kvET9Dx?pj;&9NO2~l9kr6+WvIwS{!2SF}1$e ze*9kUX;8M%X`unZWGiwAi5vi4$`}h8BiDkqfO6)&sj)9Eu*8NF`e){W$p%&hVNx+AYm{v?8 zg-i-36X`|-JW=ZmlSt4?a!qo<8=aXpTDh)d1mb^*p932Y?mw^}fWcru2KWKQeSke6 zCnF;(BP}N@E4zNZoIC=hh)_^KY*F5{0i~&q-lnOpp`rCRLp?3+T{;>XJ9q2vGRB&k znxgeAZ7fXihB#9b@jn3tIjLt-<}er%5H|u_0T=)W;IQ}Z9==W*CM6>aIx!nz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A4B?bk`M&OstJo#%{Yb77HY9CEil>awC%$=10 literal 0 Hc$@ +# Copyright (c) 2018, Alexander Stippich, +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + + +if (QMOBIPOCKET_INCLUDE_DIR AND QMOBIPOCKET_LIBRARIES) + + # Already in cache + set (QMOBIPOCKET_FOUND TRUE) + +else (QMOBIPOCKET_INCLUDE_DIR AND QMOBIPOCKET_LIBRARIES) + + find_library (QMOBIPOCKET_LIBRARIES + NAMES qmobipocket libqmobipocket + ) + + find_path (QMOBIPOCKET_INCLUDE_DIR + NAMES qmobipocket/mobipocket.h + ) + + include (FindPackageHandleStandardArgs) + find_package_handle_standard_args (QMobipocket DEFAULT_MSG QMOBIPOCKET_LIBRARIES QMOBIPOCKET_INCLUDE_DIR) + +endif (QMOBIPOCKET_INCLUDE_DIR AND QMOBIPOCKET_LIBRARIES) + +mark_as_advanced(QMOBIPOCKET_INCLUDE_DIR QMOBIPOCKET_LIBRARIES) diff --git a/src/extractors/mobiextractor.cpp b/src/extractors/mobiextractor.cpp --- a/src/extractors/mobiextractor.cpp +++ b/src/extractors/mobiextractor.cpp @@ -26,7 +26,6 @@ #include #include -#include using namespace KFileMetaData; @@ -36,10 +35,10 @@ QFileStream(const QString& name) : d(name) { d.open(QIODevice::ReadOnly); } - int read(char* buf, int size) { + int read(char* buf, int size) override { return d.read(buf, size); } - bool seek(int pos) { + bool seek(int pos) override { return d.seek(pos); } private: @@ -52,12 +51,14 @@ } -QStringList MobiExtractor::mimetypes() const +static const QStringList supportedMimeTypes = { - QStringList types; - types << QStringLiteral("application/x-mobipocket-ebook"); + QStringLiteral("application/x-mobipocket-ebook"), +}; - return types; +QStringList MobiExtractor::mimetypes() const +{ + return supportedMimeTypes; } void MobiExtractor::extract(ExtractionResult* result) @@ -67,6 +68,8 @@ if (!doc.isValid()) return; + result->addType(Type::Document); + QMapIterator it(doc.metadata()); while (it.hasNext()) { it.next(); @@ -79,12 +82,7 @@ break; } case Mobipocket::Document::Description: { - QTextDocument document; - document.setHtml(it.value()); - - QString plain = document.toPlainText(); - if (!plain.isEmpty()) - result->add(Property::Description, it.value()); + result->add(Property::Description, it.value()); break; } case Mobipocket::Document::Subject: @@ -96,14 +94,13 @@ } } - if (!doc.hasDRM()) { + /*if (!doc.hasDRM()) { QString html = doc.text(); QTextDocument document; document.setHtml(html); result->append(document.toPlainText()); - } + }*/ - result->addType(Type::Document); }