mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kio: implement Postscript meta information extractor via libspectre
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
f875fea2ef
commit
48745abc86
7 changed files with 189 additions and 2 deletions
2
.github/workflows/codeql-analysis.yml
vendored
2
.github/workflows/codeql-analysis.yml
vendored
|
@ -42,7 +42,7 @@ jobs:
|
|||
sudo apt-get install -qq wget
|
||||
sudo wget https://raw.githubusercontent.com/fluxer/katana-ubuntu/master/katana.list -O /etc/apt/sources.list.d/katana.list
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install -qq cmake katie-dev libenchant-dev libmagick++-dev libmpv-dev xorg-dev mesa-common-dev libavahi-client-dev libepub-dev libpoppler-cpp-dev libtag1-dev libavcodec-dev libavutil-dev libavformat-dev libwebp-dev libudev-dev liblzma-dev libexiv2-dev libbz2-dev libattr1-dev libacl1-dev libcdio-dev libcurl4-openssl-dev libmicrohttpd-dev libdbusmenu-katie media-player-info shared-mime-info xdg-utils
|
||||
sudo apt-get install -qq cmake katie-dev libenchant-dev libmagick++-dev libmpv-dev xorg-dev mesa-common-dev libavahi-client-dev libepub-dev libpoppler-cpp-dev libtag1-dev libavcodec-dev libavutil-dev libavformat-dev libwebp-dev libudev-dev liblzma-dev libexiv2-dev libbz2-dev libattr1-dev libacl1-dev libcdio-dev libcurl4-openssl-dev libmicrohttpd-dev libspectre-dev libdbusmenu-katie media-player-info shared-mime-info xdg-utils
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
|
|
|
@ -231,6 +231,14 @@ set_package_properties(Poppler PROPERTIES
|
|||
PURPOSE "PDF metadata extraction"
|
||||
)
|
||||
|
||||
macro_optional_find_package(LibSpectre)
|
||||
set_package_properties(LibSpectre PROPERTIES
|
||||
DESCRIPTION "Small library for rendering Postscript documents"
|
||||
URL "https://www.freedesktop.org/wiki/Software/libspectre/"
|
||||
TYPE RECOMMENDED
|
||||
PURPOSE "Postscript metadata extraction"
|
||||
)
|
||||
|
||||
macro_optional_find_package(OpenSSL)
|
||||
set_package_properties(OpenSSL PROPERTIES
|
||||
DESCRIPTION "Robust, commercial-grade, full-featured toolkit for general-purpose cryptography and secure communication"
|
||||
|
|
|
@ -24,7 +24,8 @@ build_script:
|
|||
libexiv2-dev libcdio-dev libssl-dev libcurl4-openssl-dev \
|
||||
libdbusmenu-katie libavcodec-dev libavutil-dev libavformat-dev \
|
||||
libtag1-dev media-player-info shared-mime-info media-player-info \
|
||||
libepub-dev libpoppler-cpp-dev libmicrohttpd-dev xdg-utils ccache
|
||||
libepub-dev libpoppler-cpp-dev libmicrohttpd-dev libspectre-dev \
|
||||
xdg-utils ccache
|
||||
|
||||
export PATH="/usr/lib/ccache/:$PATH"
|
||||
|
||||
|
|
|
@ -103,3 +103,25 @@ if (POPPLER_FOUND)
|
|||
DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
|
||||
)
|
||||
endif()
|
||||
|
||||
if (LIBSPECTRE_FOUND)
|
||||
include_directories(${LIBSPECTRE_INCLUDE_DIR})
|
||||
|
||||
set(kfilemetadata_spectre_SRCS kfilemetadata_spectre.cpp)
|
||||
|
||||
kde4_add_plugin(kfilemetadata_spectre ${kfilemetadata_spectre_SRCS})
|
||||
target_link_libraries(kfilemetadata_spectre
|
||||
${KDE4_KIO_LIBS}
|
||||
${LIBSPECTRE_LIBRARY}
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS kfilemetadata_spectre
|
||||
DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}
|
||||
)
|
||||
|
||||
install(
|
||||
FILES kfilemetadata_spectre.desktop
|
||||
DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
|
||||
)
|
||||
endif()
|
||||
|
|
112
kio/metadata/kfilemetadata_spectre.cpp
Normal file
112
kio/metadata/kfilemetadata_spectre.cpp
Normal file
|
@ -0,0 +1,112 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2, as published by the Free Software Foundation.
|
||||
|
||||
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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "kfilemetadata_spectre.h"
|
||||
#include "kpluginfactory.h"
|
||||
#include "kdebug.h"
|
||||
|
||||
#include <libspectre/spectre.h>
|
||||
|
||||
KFileMetaDataSpectrePlugin::KFileMetaDataSpectrePlugin(QObject* parent, const QVariantList &args)
|
||||
: KFileMetaDataPlugin(parent)
|
||||
{
|
||||
Q_UNUSED(args);
|
||||
}
|
||||
|
||||
KFileMetaDataSpectrePlugin::~KFileMetaDataSpectrePlugin()
|
||||
{
|
||||
}
|
||||
|
||||
QStringList KFileMetaDataSpectrePlugin::keys() const
|
||||
{
|
||||
static const QStringList result = QStringList()
|
||||
<< QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#title")
|
||||
<< QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/03/22/nco#creator")
|
||||
<< QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentCreated")
|
||||
<< QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#pageCount");
|
||||
return result;
|
||||
}
|
||||
|
||||
QStringList KFileMetaDataSpectrePlugin::mimeTypes() const
|
||||
{
|
||||
static const QStringList result = QStringList()
|
||||
<< QString::fromLatin1("application/postscript");
|
||||
return result;
|
||||
}
|
||||
|
||||
QList<KFileMetaInfoItem> KFileMetaDataSpectrePlugin::metaData(const KUrl &url, const KFileMetaInfo::WhatFlags flags)
|
||||
{
|
||||
Q_UNUSED(flags);
|
||||
QList<KFileMetaInfoItem> result;
|
||||
const QByteArray urlpath = url.toLocalFile().toLocal8Bit();
|
||||
SpectreDocument *spectredocument = spectre_document_new();
|
||||
if (!spectredocument) {
|
||||
kWarning() << "Could not create document";
|
||||
return result;
|
||||
}
|
||||
spectre_document_load(spectredocument, urlpath.constData());
|
||||
SpectreStatus spectrestatus = spectre_document_status(spectredocument);
|
||||
if (spectrestatus != SPECTRE_STATUS_SUCCESS) {
|
||||
kWarning() << "Could not open" << urlpath;
|
||||
spectre_document_free(spectredocument);
|
||||
return result;
|
||||
}
|
||||
const QString spectretitle = QString::fromUtf8(spectre_document_get_title(spectredocument));
|
||||
if (!spectretitle.isEmpty()) {
|
||||
result.append(
|
||||
KFileMetaInfoItem(
|
||||
QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#title"),
|
||||
spectretitle
|
||||
)
|
||||
);
|
||||
}
|
||||
const QString spectrecreator = QString::fromUtf8(spectre_document_get_creator(spectredocument));
|
||||
if (!spectrecreator.isEmpty()) {
|
||||
result.append(
|
||||
KFileMetaInfoItem(
|
||||
QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/03/22/nco#creator"),
|
||||
spectrecreator
|
||||
)
|
||||
);
|
||||
}
|
||||
const QString spectrecreationdate = QString::fromUtf8(spectre_document_get_creation_date(spectredocument));
|
||||
if (!spectrecreationdate.isEmpty()) {
|
||||
result.append(
|
||||
KFileMetaInfoItem(
|
||||
QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#contentCreated"),
|
||||
spectrecreationdate
|
||||
)
|
||||
);
|
||||
}
|
||||
const uint spectrenpages = spectre_document_get_n_pages(spectredocument);
|
||||
if (spectrenpages > 0) {
|
||||
result.append(
|
||||
KFileMetaInfoItem(
|
||||
QString::fromLatin1("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#pageCount"),
|
||||
QString::number(spectrenpages)
|
||||
)
|
||||
);
|
||||
}
|
||||
spectre_document_free(spectredocument);
|
||||
return result;
|
||||
}
|
||||
|
||||
K_PLUGIN_FACTORY(KFileMetaDataSpectrePluginFactory, registerPlugin<KFileMetaDataSpectrePlugin>();)
|
||||
K_EXPORT_PLUGIN(KFileMetaDataSpectrePluginFactory("kfilemetadata_spectre"))
|
||||
|
||||
#include "moc_kfilemetadata_spectre.cpp"
|
7
kio/metadata/kfilemetadata_spectre.desktop
Normal file
7
kio/metadata/kfilemetadata_spectre.desktop
Normal file
|
@ -0,0 +1,7 @@
|
|||
[Desktop Entry]
|
||||
Type=Service
|
||||
Name=KFileMetaDataSpectrePlugin
|
||||
GenericName=Spectre metadata extractor
|
||||
X-KDE-Library=kfilemetadata_spectre
|
||||
X-KDE-ServiceTypes=KFileMetaData/Plugin
|
||||
InitialPreference=1
|
37
kio/metadata/kfilemetadata_spectre.h
Normal file
37
kio/metadata/kfilemetadata_spectre.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2, as published by the Free Software Foundation.
|
||||
|
||||
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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KFILEMETADATA_SPECTRE_H
|
||||
#define KFILEMETADATA_SPECTRE_H
|
||||
|
||||
#include "kfilemetadata.h"
|
||||
|
||||
class KFileMetaDataSpectrePlugin : public KFileMetaDataPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KFileMetaDataSpectrePlugin(QObject* parent, const QVariantList &args);
|
||||
~KFileMetaDataSpectrePlugin();
|
||||
|
||||
QStringList keys() const final;
|
||||
QStringList mimeTypes() const final;
|
||||
|
||||
QList<KFileMetaInfoItem> metaData(const KUrl &url, const KFileMetaInfo::WhatFlags flags) final;
|
||||
};
|
||||
|
||||
#endif // KFILEMETADATA_SPECTRE_H
|
Loading…
Add table
Reference in a new issue