mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kio: handle compressed PDF documents in kfilemetadata_poppler plugin
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
886187c647
commit
410d0cdd30
4 changed files with 29 additions and 3 deletions
|
@ -16,6 +16,8 @@ include_directories(
|
|||
${CMAKE_BINARY_DIR}/kutils/kpasswdstore
|
||||
${CMAKE_SOURCE_DIR}/kutils/kexiv2
|
||||
${CMAKE_BINARY_DIR}/kutils/kexiv2
|
||||
${CMAKE_SOURCE_DIR}/kutils/karchive
|
||||
${CMAKE_BINARY_DIR}/kutils/karchive
|
||||
)
|
||||
|
||||
add_definitions(-DKDE_DEFAULT_DEBUG_AREA=7000)
|
||||
|
|
|
@ -91,6 +91,7 @@ if (POPPLER_FOUND)
|
|||
target_link_libraries(kfilemetadata_poppler
|
||||
${POPPLER_LIBRARIES}
|
||||
kio
|
||||
karchive
|
||||
)
|
||||
|
||||
install(
|
||||
|
|
|
@ -20,9 +20,11 @@
|
|||
#include "kpluginfactory.h"
|
||||
#include "kglobal.h"
|
||||
#include "klocale.h"
|
||||
#include "kdecompressor.h"
|
||||
#include "kdebug.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
|
||||
#include <poppler/cpp/poppler-document.h>
|
||||
#include <poppler/cpp/poppler-version.h>
|
||||
|
@ -62,8 +64,29 @@ KFileMetaDataPopplerPlugin::~KFileMetaDataPopplerPlugin()
|
|||
QList<KFileMetaInfoItem> KFileMetaDataPopplerPlugin::metaData(const KUrl &url)
|
||||
{
|
||||
QList<KFileMetaInfoItem> result;
|
||||
const QByteArray urlpath = url.toLocalFile().toLocal8Bit();
|
||||
poppler::document *popplerdocument = poppler::document::load_from_file(std::string(urlpath.constData(), urlpath.size()));
|
||||
const QString urlpath = url.toLocalFile();
|
||||
poppler::document* popplerdocument = nullptr;
|
||||
// NOTE: data has be kept for as long as the document is open
|
||||
QByteArray popplerbytes;
|
||||
const KDecompressor::KDecompressorType pathtype = KDecompressor::typeForFile(urlpath);
|
||||
if (pathtype != KDecompressor::TypeUnknown) {
|
||||
QFile pathfile(urlpath);
|
||||
if (!pathfile.open(QFile::ReadOnly)) {
|
||||
kWarning() << "Could not open" << urlpath;
|
||||
return result;
|
||||
}
|
||||
KDecompressor kdecompressor;
|
||||
kdecompressor.setType(pathtype);
|
||||
if (!kdecompressor.process(pathfile.readAll())) {
|
||||
kWarning() << "Could not decompress" << urlpath;
|
||||
return result;
|
||||
}
|
||||
popplerbytes = kdecompressor.result();
|
||||
popplerdocument = poppler::document::load_from_raw_data(popplerbytes.constData(), popplerbytes.size());
|
||||
} else {
|
||||
const QByteArray urlpathbytes = QFile::encodeName(urlpath);
|
||||
popplerdocument = poppler::document::load_from_file(std::string(urlpathbytes.constData(), urlpathbytes.size()));
|
||||
}
|
||||
if (!popplerdocument) {
|
||||
kWarning() << "Could not open" << urlpath;
|
||||
return result;
|
||||
|
|
|
@ -3,7 +3,7 @@ Type=Service
|
|||
Name=KFileMetaDataPopplerPlugin
|
||||
GenericName=Poppler
|
||||
Comment=Extracts metadata from Portable Document Format (PDF) documents
|
||||
MimeType=application/pdf;application/x-pdf
|
||||
MimeType=application/x-pdf;application/pdf;application/x-gzpdf;application/x-bzpdf;
|
||||
X-KDE-Library=kfilemetadata_poppler
|
||||
X-KDE-ServiceTypes=KFileMetaData/Plugin
|
||||
X-KDE-MetadataKeys=http://www.semanticdesktop.org/ontologies/2007/01/19/nie#title,http://www.semanticdesktop.org/ontologies/2007/01/19/nie#subject,http://www.semanticdesktop.org/ontologies/2007/01/19/nie#keyword,http://www.semanticdesktop.org/ontologies/2007/01/19/nie#generator,http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentCreated,http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentLastModified,http://www.semanticdesktop.org/ontologies/2007/03/22/nco#creator,http://www.semanticdesktop.org/ontologies/2007/05/10/nid3#textWriter,http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#pageCount
|
||||
|
|
Loading…
Add table
Reference in a new issue