diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 626747f..ad02338 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,190 +1,204 @@ find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Test) find_package(PythonInterp) set_package_properties(PythonInterp PROPERTIES DESCRIPTION "Python Interpreter" URL "https://www.python.org" TYPE OPTIONAL PURPOSE "Python interpreter is needed to execute test for external extractors or writers") remove_definitions(-DQT_NO_CAST_FROM_ASCII) configure_file(indexerextractortestsconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/indexerextractortestsconfig.h @ONLY) set(KfileMetaDataAutotest_SRCS) ecm_qt_declare_logging_category(KfileMetaDataAutotest_SRCS HEADER kfilemetadata_debug.h IDENTIFIER KFILEMETADATA_LOG CATEGORY_NAME kf5.kfilemetadata) set(indexerextractor_SRCS indexerextractortests.cpp ../src/extractors/plaintextextractor.cpp ) ecm_add_test(${indexerextractor_SRCS} TEST_NAME "indexextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ) # # Office # if(KF5Archive_FOUND) ecm_add_test(odfextractortest.cpp ../src/extractors/odfextractor.cpp TEST_NAME "odfextractortest" LINK_LIBRARIES Qt5::Test Qt5::Xml KF5::FileMetaData KF5::Archive ) endif() if(KF5Archive_FOUND) ecm_add_test(office2007extractortest.cpp ../src/extractors/office2007extractor.cpp TEST_NAME "officeextractortest" LINK_LIBRARIES Qt5::Test Qt5::Xml KF5::FileMetaData KF5::Archive ) endif() # # Poppler # if(Poppler_Qt5_FOUND) ecm_add_test(popplerextractortest.cpp ../src/extractors/popplerextractor.cpp TEST_NAME "popplerextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData Poppler::Qt5 ) endif() # # EPub # if(EPUB_FOUND) include_directories(${EPUB_INCLUDE_DIR}) ecm_add_test(epubextractortest.cpp ../src/extractors/epubextractor.cpp TEST_NAME "epubextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ${EPUB_LIBRARIES} ) endif() # # Mobi # if (QMOBIPOCKET_FOUND) include_directories(${QMOBIPOCKET_INCLUDE_DIR}) ecm_add_test(mobiextractortest.cpp ../src/extractors/mobiextractor.cpp TEST_NAME "mobiextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ${QMOBIPOCKET_LIBRARIES} ) endif() # # Property Info # ecm_add_test(propertyinfotest.cpp TEST_NAME "propertyinfotest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ) # # Exiv2 # if(EXIV2_FOUND) include_directories(${EXIV2_INCLUDE_DIR}) kde_enable_exceptions() ecm_add_test(exiv2extractortest.cpp ../src/extractors/exiv2extractor.cpp TEST_NAME "exiv2extractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ${EXIV2_LIBRARIES} ) endif() # # TagLib # if(TAGLIB_FOUND) kde_enable_exceptions() ecm_add_test(taglibextractortest.cpp ../src/extractors/taglibextractor.cpp TEST_NAME "taglibextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ${TAGLIB_LIBRARIES} ) target_include_directories(taglibextractortest SYSTEM PRIVATE ${TAGLIB_INCLUDES}) ecm_add_test(embeddedimagedatatest.cpp TEST_NAME "embeddedimagedatatest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ${TAGLIB_LIBRARIES} ) target_include_directories(embeddedimagedatatest SYSTEM PRIVATE ${TAGLIB_INCLUDES}) endif() if(PYTHONINTERP_FOUND) configure_file(samplefiles/testexternalextractor/main.py samplefiles/testexternalextractor/main.py) configure_file(samplefiles/testexternalextractor/manifest.json samplefiles/testexternalextractor/manifest.json COPYONLY) ecm_add_test(externalextractortest.cpp ../src/externalextractor.cpp ${KfileMetaDataAutotest_SRCS} TEST_NAME "externalextractortest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData KF5::I18n ) endif() # # Collection # set(extractorcollection_SRCS extractorcollectiontest.cpp ) ecm_add_test(${extractorcollection_SRCS} TEST_NAME "extractorcollectiontest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ) # # XML # set(xmlextractor_SRCS xmlextractortest.cpp ../src/extractors/xmlextractor.cpp ../src/extractors/dublincoreextractor.cpp ../src/kfilemetadata_debug.cpp ) ecm_add_test(${xmlextractor_SRCS} TEST_NAME "xmlextractortest" LINK_LIBRARIES Qt5::Test Qt5::Xml KF5::FileMetaData ) +# +# Postscript DSC +# +set(postscriptdscextractor_SRCS + postscriptdscextractortest.cpp + ../src/extractors/postscriptdscextractor.cpp + ../src/kfilemetadata_debug.cpp +) + +ecm_add_test(${postscriptdscextractor_SRCS} + TEST_NAME "postscriptdscextractortest" + LINK_LIBRARIES Qt5::Test KF5::FileMetaData +) + ################ # Writer tests # ################ # # UserMetaData # if(CMAKE_SYSTEM_NAME MATCHES "Linux") kde_enable_exceptions() ecm_add_test(usermetadatawritertest.cpp ../src/usermetadata.cpp TEST_NAME "usermetadatawritertest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ) endif() # # TagLib # if(TAGLIB_FOUND) kde_enable_exceptions() ecm_add_test(taglibwritertest.cpp ../src/writers/taglibwriter.cpp TEST_NAME "taglibwritertest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData ${TAGLIB_LIBRARIES} ) target_include_directories(taglibwritertest SYSTEM PRIVATE ${TAGLIB_INCLUDES}) endif() if(PYTHONINTERP_FOUND) configure_file(samplefiles/testexternalwriter/main.py samplefiles/testexternalwriter/main.py) configure_file(samplefiles/testexternalwriter/manifest.json samplefiles/testexternalwriter/manifest.json COPYONLY) ecm_add_test(externalwritertest.cpp ../src/externalwriter.cpp ${KfileMetaDataAutotest_SRCS} TEST_NAME "externalwritertest" LINK_LIBRARIES Qt5::Test KF5::FileMetaData KF5::I18n ) endif() diff --git a/autotests/postscriptdscextractortest.cpp b/autotests/postscriptdscextractortest.cpp new file mode 100644 index 0000000..d6a2cf7 --- /dev/null +++ b/autotests/postscriptdscextractortest.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2018 Stefan Brüns + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "postscriptdscextractortest.h" +#include "simpleextractionresult.h" +#include "indexerextractortestsconfig.h" +#include "extractors/postscriptdscextractor.h" + +#include + +using namespace KFileMetaData; + +QString PostscriptDscExtractorTest::testFilePath(const QString& fileName) const +{ + return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QLatin1Char('/') + fileName; +} + +void PostscriptDscExtractorTest::testPS() +{ + DscExtractor plugin{this}; + + SimpleExtractionResult result(testFilePath("test.ps"), "application/postscript"); + plugin.extract(&result); + + QCOMPARE(result.types().size(), 1); + QCOMPARE(result.types().constFirst(), Type::Document); + + QCOMPARE(result.properties().value(Property::Title).toString(), QStringLiteral("The Big Brown Bear")); + QCOMPARE(result.properties().value(Property::PageCount).toInt(), 2); + + QDateTime dt(QDate(2018, 10, 28), QTime(21, 13, 39)); + dt.setOffsetFromUtc(+3600); + QCOMPARE(result.properties().value(Property::CreationDate), QVariant(dt)); + + QCOMPARE(result.properties().size(), 3); +} + +void PostscriptDscExtractorTest::testEPS() +{ + DscExtractor plugin{this}; + + SimpleExtractionResult result(testFilePath("test.eps"), "image/x-eps"); + plugin.extract(&result); + + QCOMPARE(result.types().size(), 1); + QCOMPARE(result.types().constFirst(), Type::Image); + + QCOMPARE(result.properties().value(Property::Title).toString(), QStringLiteral("The Big Brown Bear")); + QCOMPARE(result.properties().value(Property::PageCount).toInt(), 1); + + QDateTime dt(QDate(2018, 10, 28), QTime(21, 13, 39)); + dt.setOffsetFromUtc(-5400); + QCOMPARE(result.properties().value(Property::CreationDate), QVariant(dt)); + QCOMPARE(result.properties().size(), 3); +} + +QTEST_GUILESS_MAIN(PostscriptDscExtractorTest) diff --git a/autotests/postscriptdscextractortest.h b/autotests/postscriptdscextractortest.h new file mode 100644 index 0000000..8472f4c --- /dev/null +++ b/autotests/postscriptdscextractortest.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2018 Stefan Brüns + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef POSTSCRIPTDSCEXTRACTORTEST_H +#define POSTSCRIPTDSCEXTRACTORTEST_H + +#include + +class PostscriptDscExtractorTest : public QObject +{ + Q_OBJECT +private: + QString testFilePath(const QString& fileName) const; + +private Q_SLOTS: + void testPS(); + void testEPS(); +}; + +#endif // POSTSCRIPTDSCEXTRACTORTEST_H diff --git a/autotests/samplefiles/test.eps b/autotests/samplefiles/test.eps new file mode 100644 index 0000000..62fcf7c --- /dev/null +++ b/autotests/samplefiles/test.eps @@ -0,0 +1,21 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%BoundingBox: 0 0 100 140 +%%HiResBoundingBox: 0 0 100.00 140.00 +%%Creator: Vim +%%LanguageLevel: 2 +%%CreationDate: D:20181028211339-01'30' +%%Pages: 1 +%%Title: (The Big Brown Bear) +%%EndComments +%%BeginProlog +%%EndProlog +%%Page: 1 1 +newpath +10 10 moveto +90 70 lineto +10 130 lineto +2 setlinewidth +stroke + +%%Trailer +%%EOF diff --git a/autotests/samplefiles/test.ps b/autotests/samplefiles/test.ps new file mode 100644 index 0000000..c629698 --- /dev/null +++ b/autotests/samplefiles/test.ps @@ -0,0 +1,19 @@ +%!PS-Adobe-3.0 +%%BoundingBox: 0 0 612 792 +%%HiResBoundingBox: 0 0 612.00 792.00 +%%Creator: Vim +%%LanguageLevel: 2 +%%CreationDate: D:20181028211339+01'00' +%%Pages: 2 +%%Title: The Big Brown Bear +%%EndComments +%%BeginProlog +%%EndProlog +%%Page: 1 2 +%%PageBoundingBox: 0 0 612 792 +showpage +%%Page: 1 2 +%%PageBoundingBox: 0 0 612 792 +showpage +%%Trailer +%%EOF diff --git a/src/extractors/CMakeLists.txt b/src/extractors/CMakeLists.txt index 017cfec..b412dd6 100644 --- a/src/extractors/CMakeLists.txt +++ b/src/extractors/CMakeLists.txt @@ -1,199 +1,217 @@ if(Poppler_Qt5_FOUND) add_library(kfilemetadata_popplerextractor MODULE popplerextractor.cpp) target_link_libraries(kfilemetadata_popplerextractor KF5::FileMetaData Poppler::Qt5 ) set_target_properties(kfilemetadata_popplerextractor PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/kfilemetadata") install( TARGETS kfilemetadata_popplerextractor DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kfilemetadata) endif() if(TAGLIB_FOUND) add_library(kfilemetadata_taglibextractor MODULE taglibextractor.cpp ) target_include_directories(kfilemetadata_taglibextractor SYSTEM PRIVATE ${TAGLIB_INCLUDES}) target_link_libraries( kfilemetadata_taglibextractor KF5::FileMetaData ${TAGLIB_LIBRARIES} ) set_target_properties(kfilemetadata_taglibextractor PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/kfilemetadata") install( TARGETS kfilemetadata_taglibextractor DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kfilemetadata) endif() if(EXIV2_FOUND) add_library(kfilemetadata_exiv2extractor MODULE exiv2extractor.cpp) target_include_directories(kfilemetadata_exiv2extractor SYSTEM PRIVATE ${EXIV2_INCLUDE_DIR}) kde_target_enable_exceptions(kfilemetadata_exiv2extractor PRIVATE) target_link_libraries(kfilemetadata_exiv2extractor KF5::FileMetaData ${EXIV2_LIBRARIES} ) set_target_properties(kfilemetadata_exiv2extractor PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/kfilemetadata") install( TARGETS kfilemetadata_exiv2extractor DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kfilemetadata) endif() if(FFMPEG_FOUND) add_library(kfilemetadata_ffmpegextractor MODULE ffmpegextractor.cpp) target_include_directories(kfilemetadata_ffmpegextractor SYSTEM PRIVATE ${AVCODEC_INCLUDE_DIRS} ${AVFORMAT_INCLUDE_DIRS} ${AVUTIL_INCLUDE_DIRS}) target_link_libraries(kfilemetadata_ffmpegextractor KF5::FileMetaData ${AVCODEC_LIBRARIES} ${AVFORMAT_LIBRARIES} ${AVUTIL_LIBRARIES} ) set_target_properties(kfilemetadata_ffmpegextractor PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/kfilemetadata") install( TARGETS kfilemetadata_ffmpegextractor DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kfilemetadata) endif() if(EPUB_FOUND) add_library(kfilemetadata_epubextractor MODULE epubextractor.cpp) target_include_directories(kfilemetadata_epubextractor SYSTEM PRIVATE ${EPUB_INCLUDE_DIR}) target_link_libraries(kfilemetadata_epubextractor KF5::FileMetaData ${EPUB_LIBRARIES} ) set_target_properties(kfilemetadata_epubextractor PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/kfilemetadata") install( TARGETS kfilemetadata_epubextractor DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kfilemetadata) endif() # # Plain Text # add_library(kfilemetadata_plaintextextractor MODULE plaintextextractor.cpp) target_link_libraries( kfilemetadata_plaintextextractor KF5::FileMetaData ) set_target_properties(kfilemetadata_plaintextextractor PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/kfilemetadata") install( TARGETS kfilemetadata_plaintextextractor DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kfilemetadata) # # PO # add_library(kfilemetadata_poextractor MODULE poextractor.cpp) target_link_libraries( kfilemetadata_poextractor KF5::FileMetaData ) set_target_properties(kfilemetadata_poextractor PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/kfilemetadata") install( TARGETS kfilemetadata_poextractor DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kfilemetadata) # # XML # add_library(kfilemetadata_xmlextractor MODULE dublincoreextractor.cpp xmlextractor.cpp ../kfilemetadata_debug.cpp ) target_link_libraries( kfilemetadata_xmlextractor KF5::FileMetaData Qt5::Core Qt5::Xml ) set_target_properties(kfilemetadata_xmlextractor PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/kfilemetadata") install( TARGETS kfilemetadata_xmlextractor DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kfilemetadata ) +# +# Postscript DSC +# +add_library(kfilemetadata_postscriptdscextractor MODULE + postscriptdscextractor.cpp + ../kfilemetadata_debug.cpp +) +target_link_libraries( kfilemetadata_postscriptdscextractor + KF5::FileMetaData + Qt5::Core +) + +set_target_properties(kfilemetadata_postscriptdscextractor PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/kfilemetadata") +install( + TARGETS kfilemetadata_postscriptdscextractor + DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kfilemetadata +) + # # ODF # if(KF5Archive_FOUND) add_library(kfilemetadata_odfextractor MODULE odfextractor.cpp) target_link_libraries(kfilemetadata_odfextractor KF5::FileMetaData Qt5::Core Qt5::Xml KF5::Archive ) set_target_properties(kfilemetadata_odfextractor PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/kfilemetadata") install( TARGETS kfilemetadata_odfextractor DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kfilemetadata) endif() # # Office 2007 # if(KF5Archive_FOUND) add_library(kfilemetadata_office2007extractor MODULE office2007extractor.cpp) target_link_libraries(kfilemetadata_office2007extractor KF5::FileMetaData Qt5::Core Qt5::Xml KF5::Archive ) set_target_properties(kfilemetadata_office2007extractor PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/kfilemetadata") install( TARGETS kfilemetadata_office2007extractor DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kfilemetadata) endif() # # Office (binary formats) # add_library(kfilemetadata_officeextractor MODULE officeextractor.cpp) target_link_libraries(kfilemetadata_officeextractor KF5::FileMetaData ) set_target_properties(kfilemetadata_officeextractor PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/kfilemetadata") install( TARGETS kfilemetadata_officeextractor DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kfilemetadata) # # Mobipocket # if (QMOBIPOCKET_FOUND) add_library(kfilemetadata_mobiextractor MODULE mobiextractor.cpp) target_include_directories(kfilemetadata_mobiextractor SYSTEM PRIVATE ${QMOBIPOCKET_INCLUDE_DIR}) target_link_libraries(kfilemetadata_mobiextractor KF5::FileMetaData ${QMOBIPOCKET_LIBRARIES} ) set_target_properties(kfilemetadata_mobiextractor PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/kf5/kfilemetadata") install( TARGETS kfilemetadata_mobiextractor DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kfilemetadata) endif() diff --git a/src/extractors/postscriptdscextractor.cpp b/src/extractors/postscriptdscextractor.cpp new file mode 100644 index 0000000..cc1b5c9 --- /dev/null +++ b/src/extractors/postscriptdscextractor.cpp @@ -0,0 +1,121 @@ +/* + Copyright (C) 2018 Stefan Brüns + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + +#include "postscriptdscextractor.h" +#include "kfilemetadata_debug.h" + +#include +#include + +namespace KFileMetaData +{ + +DscExtractor::DscExtractor(QObject* parent) + : ExtractorPlugin(parent) +{ + +} + +QStringList DscExtractor::mimetypes() const +{ + QStringList list; + list << QStringLiteral("application/postscript") + << QStringLiteral("image/x-eps"); + + return list; +} + +void DscExtractor::extract(ExtractionResult* result) +{ + auto flags = result->inputFlags(); + if (!(flags & ExtractionResult::ExtractMetaData)) { + return; + } + + QFile file(result->inputUrl()); + if (!file.open(QIODevice::ReadOnly)) { + qCWarning(KFILEMETADATA_LOG) << "Document is not a valid file"; + return; + } + + // A little bit heuristic - assume EPS files are images, PS complete documents + if (result->inputMimetype() == QLatin1String("application/postscript")) { + result->addType(Type::Document); + } else { + result->addType(Type::Image); + } + + // Try to find some DSC (PostScript Language Document Structuring Conventions) conforming data + QTextStream stream(&file); + QString line; + + while (stream.readLineInto(&line)) { + if (!line.startsWith(QLatin1String("%%"))) { + continue; + } + + if (line.startsWith(QLatin1String("%%Pages:"))) { + bool ok = false; + int pages = line.midRef(8).toInt(&ok, 10); + if (ok) { + result->add(Property::PageCount, pages); + } + + } else if (line.startsWith(QLatin1String("%%Title:"))) { + QStringRef title = line.midRef(8); + title = title.trimmed(); + if (title.startsWith(QLatin1Char('(')) && title.endsWith(QLatin1Char(')'))) { + title = title.mid(1, title.size() - 2); + } + if (!title.isEmpty()) { + result->add(Property::Title, title.toString()); + } + + } else if (line.startsWith(QLatin1String("%%CreationDate:"))) { + // "Neither the date nor time need be in any standard format." + QStringRef date = line.midRef(15); + date = date.trimmed(); + if (date.startsWith(QLatin1Char('(')) && date.endsWith(QLatin1Char(')'))) { + date = date.mid(1, date.size() - 2); + date = date.trimmed(); + } + if (date.startsWith(QLatin1String("D:")) && date.size() >= 23) { + // Standard PDF date format, ASN.1 like - (D:YYYYMMDDHHmmSSOHH'mm') + auto dt = QDateTime::fromString(date.mid(2, 14).toString(), QLatin1String("yyyyMMddhhmmss")); + auto offset = QTime::fromString(date.mid(17, 5).toString(), QLatin1String("hh'\\''mm")); + if (date.mid(16,1) == QLatin1String("+")) { + dt.setOffsetFromUtc(QTime(0, 0).secsTo(offset)); + } else { + dt.setOffsetFromUtc(-1 * QTime(0, 0).secsTo(offset)); + } + result->add(Property::CreationDate, dt); + } else { + auto dt = QDateTime::fromString(date.toString()); + if (dt.isValid()) { + result->add(Property::CreationDate, dt); + } + } + + } else if (line.startsWith(QLatin1String("%%EndComments"))) { + break; + } + } +} + +} // namespace KFileMetaData diff --git a/src/extractors/postscriptdscextractor.h b/src/extractors/postscriptdscextractor.h new file mode 100644 index 0000000..39f22f2 --- /dev/null +++ b/src/extractors/postscriptdscextractor.h @@ -0,0 +1,45 @@ +/* + Copyright (C) 2018 Stefan Brüns + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + +#ifndef DSC_EXTRACTOR_H +#define DSC_EXTRACTOR_H + +#include "extractorplugin.h" + +namespace KFileMetaData +{ + +class DscExtractor : public ExtractorPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.kde.kf5.kfilemetadata.ExtractorPlugin") + Q_INTERFACES(KFileMetaData::ExtractorPlugin) + +public: + explicit DscExtractor(QObject* parent = nullptr); + + QStringList mimetypes() const override; + void extract(ExtractionResult* result) override; + +private: +}; + +} + +#endif // DSC_EXTRACTOR_H